VLCVideoView.m 5.3 KB

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