VLCVideoView.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*****************************************************************************
  2. * VLCVideoView.h: VLC.framework VLCVideoView implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 the VideoLAN team
  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
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 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 General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, 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. #include <vlc/vlc.h>
  30. #include <vlc/libvlc.h>
  31. #import <QuartzCore/QuartzCore.h>
  32. /******************************************************************************
  33. * Soon deprecated stuff
  34. */
  35. /* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
  36. library. We could get rid of this, but it prevents warnings from the
  37. compiler. (Scheduled to deletion) */
  38. @interface VLCOpenGLVoutView : NSView
  39. - (void)detachFromVout;
  40. @end
  41. /* Depreacted methods */
  42. @interface VLCVideoView (Deprecated)
  43. - (void)setStretchesVideo:(BOOL)value;
  44. - (BOOL)stretchesVideo;
  45. - (void)addVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
  46. - (void)removeVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
  47. @end
  48. /******************************************************************************
  49. * VLCVideoView (Private)
  50. */
  51. @interface VLCVideoView (Private)
  52. /* Method */
  53. - (void)addVoutLayer:(CALayer *)aLayer;
  54. @end
  55. /******************************************************************************
  56. * Implementation VLCVideoView
  57. */
  58. @implementation VLCVideoView
  59. - (id)initWithFrame:(NSRect)rect
  60. {
  61. if (self = [super initWithFrame:rect])
  62. {
  63. delegate = nil;
  64. [self setBackColor:[NSColor blackColor]];
  65. [self setStretchesVideo:NO];
  66. [self setAutoresizesSubviews:YES];
  67. [self setFillScreen: NO];
  68. layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
  69. }
  70. return self;
  71. }
  72. - (void)dealloc
  73. {
  74. [layoutManager release];
  75. delegate = nil;
  76. [backColor release];
  77. [super dealloc];
  78. }
  79. - (void)drawRect:(NSRect)aRect
  80. {
  81. [self lockFocus];
  82. [backColor set];
  83. NSRectFill(aRect);
  84. [self unlockFocus];
  85. }
  86. - (BOOL)isOpaque
  87. {
  88. return YES;
  89. }
  90. @synthesize delegate;
  91. @synthesize backColor;
  92. - (BOOL)fillScreen
  93. {
  94. return [layoutManager fillScreenEntirely];
  95. }
  96. - (void)setFillScreen:(BOOL)fillScreen
  97. {
  98. [layoutManager setFillScreenEntirely:fillScreen];
  99. [[self layer] setNeedsLayout];
  100. }
  101. @end
  102. /******************************************************************************
  103. * Implementation VLCVideoView (Private)
  104. */
  105. @implementation VLCVideoView (Private)
  106. /* This is called by the libvlc module 'opengllayer' as soon as there is one
  107. * vout available
  108. */
  109. - (void)addVoutLayer:(CALayer *)aLayer
  110. {
  111. [CATransaction begin];
  112. [self setWantsLayer: YES];
  113. CALayer * rootLayer = [self layer];
  114. aLayer.name = @"vlcopengllayer";
  115. [layoutManager setOriginalVideoSize:aLayer.bounds.size];
  116. [rootLayer setLayoutManager:layoutManager];
  117. [rootLayer insertSublayer:aLayer atIndex:0];
  118. [aLayer setNeedsLayout];
  119. [aLayer setNeedsDisplay];
  120. [rootLayer setNeedsDisplay];
  121. [rootLayer layoutIfNeeded];
  122. [CATransaction commit];
  123. }
  124. - (void)removeVoutLayer:(CALayer*)voutLayer
  125. {
  126. [CATransaction begin];
  127. [voutLayer removeFromSuperlayer];
  128. [CATransaction commit];
  129. }
  130. @end
  131. /******************************************************************************
  132. * Implementation VLCVideoView (Deprecated)
  133. */
  134. @implementation VLCVideoView (Deprecated)
  135. - (void)setStretchesVideo:(BOOL)value
  136. {
  137. stretchesVideo = value;
  138. }
  139. - (BOOL)stretchesVideo
  140. {
  141. return stretchesVideo;
  142. }
  143. /* This is called by the libvlc module 'minimal_macosx' as soon as there is one
  144. * vout available
  145. */
  146. - (void)addVoutSubview:(NSView *)aView /* (Scheduled to deletion) */
  147. {
  148. /* This is where the real video comes from */
  149. if( [[self subviews] count] )
  150. {
  151. /* XXX: This is a hack until core gets fixed */
  152. int i;
  153. for( i = 0; i < [[self subviews] count]; i++ )
  154. {
  155. [[[self subviews] objectAtIndex:i] detachFromVout];
  156. [[[self subviews] objectAtIndex:i] retain];
  157. [[[self subviews] objectAtIndex:i] removeFromSuperview];
  158. }
  159. }
  160. [aView setFrame:[self bounds]];
  161. [self addSubview:aView];
  162. // TODO: Should we let the media player specify these values?
  163. [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
  164. }
  165. - (void)removeVoutSubview:(NSView *)view /* (Scheduled to deletion) */
  166. {
  167. // Should we do something? I don't know, however the protocol requires
  168. // this to be implemented
  169. }
  170. @end