VLCVideoLayer.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*****************************************************************************
  2. * VLCVideoLayer.m: VLCKit.framework VLCVideoLayer implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import "VLCVideoLayer.h"
  25. #import "VLCLibrary.h"
  26. #import "VLCEventManager.h"
  27. #import "VLCVideoCommon.h"
  28. /* Libvlc */
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. #include <vlc/vlc.h>
  33. #include <vlc/libvlc.h>
  34. #import <QuartzCore/QuartzCore.h>
  35. /******************************************************************************
  36. * VLCVideoLayer (Private)
  37. */
  38. @interface VLCVideoLayer ()
  39. @property (nonatomic, readwrite) BOOL hasVideo;
  40. - (void)addVoutLayer:(CALayer *)aLayer;
  41. @end
  42. /******************************************************************************
  43. * Implementation VLCVideoLayer
  44. */
  45. @implementation VLCVideoLayer
  46. - (BOOL)fillScreen
  47. {
  48. return [(VLCVideoLayoutManager *)self.layoutManager fillScreenEntirely];
  49. }
  50. - (void)setFillScreen:(BOOL)fillScreen
  51. {
  52. [(VLCVideoLayoutManager*)self.layoutManager setFillScreenEntirely:fillScreen];
  53. [self setNeedsLayout];
  54. }
  55. /******************************************************************************
  56. * Implementation VLCVideoLayer (Private)
  57. */
  58. /* This is called by the libvlc module 'opengllayer' as soon as there is one
  59. * vout available
  60. */
  61. - (void)addVoutLayer:(CALayer *)voutLayer
  62. {
  63. [CATransaction begin];
  64. voutLayer.name = @"vlcopengllayer";
  65. VLCVideoLayoutManager * layoutManager = [VLCVideoLayoutManager layoutManager];
  66. layoutManager.originalVideoSize = voutLayer.bounds.size;
  67. self.layoutManager = layoutManager;
  68. [self insertSublayer:voutLayer atIndex:0];
  69. [self setNeedsDisplayOnBoundsChange:YES];
  70. [CATransaction commit];
  71. /* Trigger by hand, as it doesn't go through else. Assumed bug from Cocoa */
  72. [self willChangeValueForKey:@"hasVideo"];
  73. self.hasVideo = YES;
  74. [self didChangeValueForKey:@"hasVideo"];
  75. }
  76. - (void)removeVoutLayer:(CALayer*)voutLayer
  77. {
  78. [CATransaction begin];
  79. [voutLayer removeFromSuperlayer];
  80. [CATransaction commit];
  81. /* Trigger by hand, as it doesn't go through else. Assumed bug from Cocoa */
  82. [self willChangeValueForKey:@"hasVideo"];
  83. _hasVideo = NO;
  84. [self didChangeValueForKey:@"hasVideo"];
  85. }
  86. @end