VLCVideoView.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*****************************************************************************
  2. * VLCVideoView.m: VLCKit.framework VLCVideoView 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 "VLCVideoView.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. * Soon deprecated stuff
  37. */
  38. /* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
  39. library. We could get rid of this, but it prevents warnings from the
  40. compiler. (Scheduled to deletion) */
  41. @interface VLCOpenGLVoutView : NSView
  42. - (void)detachFromVout;
  43. @end
  44. /* Depreacted methods */
  45. @interface VLCVideoView (Deprecated)
  46. - (void)setStretchesVideo:(BOOL)value;
  47. - (BOOL)stretchesVideo;
  48. - (void)addVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
  49. - (void)removeVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
  50. @end
  51. /******************************************************************************
  52. * VLCVideoView (Private)
  53. */
  54. @interface VLCVideoView (Private)
  55. /* Method */
  56. - (void)addVoutLayer:(CALayer *)aLayer;
  57. @end
  58. @interface VLCVideoView ()
  59. /* Proeprties */
  60. @property (readwrite) BOOL hasVideo;
  61. @end
  62. /******************************************************************************
  63. * Implementation VLCVideoView
  64. */
  65. @implementation VLCVideoView
  66. /* Initializers */
  67. - (id)initWithFrame:(NSRect)rect
  68. {
  69. if (self = [super initWithFrame:rect])
  70. {
  71. self.delegate = nil;
  72. self.backColor = [NSColor blackColor];
  73. self.fillScreen = NO;
  74. self.hasVideo = NO;
  75. [self setStretchesVideo:NO];
  76. [self setAutoresizesSubviews:YES];
  77. layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
  78. }
  79. return self;
  80. }
  81. - (void)dealloc
  82. {
  83. self.delegate = nil;
  84. self.backColor = nil;
  85. [layoutManager release];
  86. [super dealloc];
  87. }
  88. /* NSView Overrides */
  89. - (void)drawRect:(NSRect)aRect
  90. {
  91. [self lockFocus];
  92. [backColor set];
  93. NSRectFill(aRect);
  94. [self unlockFocus];
  95. }
  96. - (BOOL)isOpaque
  97. {
  98. return YES;
  99. }
  100. /* Properties */
  101. @synthesize delegate;
  102. @synthesize backColor;
  103. @synthesize hasVideo;
  104. - (BOOL)fillScreen
  105. {
  106. return [layoutManager fillScreenEntirely];
  107. }
  108. - (void)setFillScreen:(BOOL)fillScreen
  109. {
  110. [(VLCVideoLayoutManager *)layoutManager setFillScreenEntirely:fillScreen];
  111. [[self layer] setNeedsLayout];
  112. }
  113. @end
  114. /******************************************************************************
  115. * Implementation VLCVideoView (Private)
  116. */
  117. @implementation VLCVideoView (Private)
  118. /* This is called by the libvlc module 'opengllayer' as soon as there is one
  119. * vout available
  120. */
  121. - (void)addVoutLayer:(CALayer *)aLayer
  122. {
  123. [CATransaction begin];
  124. [self setWantsLayer: YES];
  125. CALayer * rootLayer = [self layer];
  126. aLayer.name = @"vlcopengllayer";
  127. [layoutManager setOriginalVideoSize:aLayer.bounds.size];
  128. [rootLayer setLayoutManager:layoutManager];
  129. [rootLayer insertSublayer:aLayer atIndex:0];
  130. [aLayer setNeedsDisplayOnBoundsChange:YES];
  131. [CATransaction commit];
  132. self.hasVideo = YES;
  133. }
  134. - (void)removeVoutLayer:(CALayer *)voutLayer
  135. {
  136. [CATransaction begin];
  137. [voutLayer removeFromSuperlayer];
  138. [CATransaction commit];
  139. self.hasVideo = NO;
  140. }
  141. @end
  142. /******************************************************************************
  143. * Implementation VLCVideoView (Deprecated)
  144. */
  145. @implementation VLCVideoView (Deprecated)
  146. - (void)setStretchesVideo:(BOOL)value
  147. {
  148. stretchesVideo = value;
  149. }
  150. - (BOOL)stretchesVideo
  151. {
  152. return stretchesVideo;
  153. }
  154. /* This is called by the libvlc module 'minimal_macosx' as soon as there is one
  155. * vout available
  156. */
  157. - (void)addVoutSubview:(NSView *)aView /* (Scheduled to deletion) */
  158. {
  159. [aView setFrame:[self bounds]];
  160. [self addSubview:aView];
  161. // TODO: Should we let the media player specify these values?
  162. [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
  163. }
  164. - (void)removeVoutSubview:(NSView *)view /* (Scheduled to deletion) */
  165. {
  166. // Should we do something? I don't know, however the protocol requires
  167. // this to be implemented
  168. }
  169. @end