1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include <com/sun/star/awt/SystemPointer.hpp>
24 #include <com/sun/star/awt/PosSize.hpp>
25
26 #include "macavf_window.hxx"
27 #include "macavf_player.hxx"
28
29 using namespace ::com::sun::star;
30
31
32 namespace avmedia { namespace macavf {
33
34 // ---------------
35 // - Window -
36 // ---------------
37
Window(const uno::Reference<lang::XMultiServiceFactory> & i_rxMgr,Player & i_rPlayer,NSView * i_pParentView)38 Window::Window( const uno::Reference< lang::XMultiServiceFactory >& i_rxMgr, Player& i_rPlayer, NSView* i_pParentView )
39 : mxMgr( i_rxMgr )
40 , maListeners( maMutex )
41 , meZoomLevel( media::ZoomLevel_NOT_AVAILABLE )
42 , mrPlayer( i_rPlayer )
43 , mnPointerType( awt::SystemPointer::ARROW )
44 , mpView( i_pParentView )
45 , mpPlayerLayer( NULL )
46 {
47 OSL_TRACE ("Constructing an avmedia::macavf::Window");
48 if( !mpView ) // sanity check
49 return;
50
51 // check the media asset for video content
52 AVPlayer* pAVPlayer = mrPlayer.getAVPlayer();
53 AVAsset* pMovie = [[pAVPlayer currentItem] asset];
54 const int nVideoCount = [pMovie tracksWithMediaType:AVMediaTypeVideo].count;
55 const int nAudioCount = [pMovie tracksWithMediaType:AVMediaTypeAudio].count;
56 OSL_TRACE( "Found %d video and %d audio tracks.", nVideoCount, nAudioCount );
57 (void)nAudioCount;
58 if( nVideoCount <= 0 )
59 return;
60
61 // setup the AVPlayerLayer
62 [pAVPlayer retain];
63 [pAVPlayer pause];
64 mpPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:pAVPlayer];
65 [mpPlayerLayer retain];
66 [mpPlayerLayer setFrame:[mpView frame]];
67 [mpPlayerLayer setHidden:YES];
68 [mpPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
69 [mpPlayerLayer addObserver:getObserver() forKeyPath:@"readyForDisplay" options:0 context:this];
70
71 // setup the target view
72 [mpView setWantsLayer:YES];
73 [mpView.layer addSublayer:mpPlayerLayer];
74 }
75
76 // ------------------------------------------------------------------------------
77
~Window()78 Window::~Window()
79 {
80 [mpPlayerLayer removeObserver:getObserver() forKeyPath:@"readyForDisplay"];
81 [mpPlayerLayer release];
82 }
83
84 // ------------------------------------------------------------------------------
85
create(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aArguments)86 bool Window::create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
87 {
88 return true;
89 }
90
91 // ------------------------------------------------------------------------------
92
handleObservation(NSString * pKeyPath)93 bool Window::handleObservation( NSString* pKeyPath )
94 {
95 OSL_TRACE( "AVPlayer::handleObservation key=\"%s\"", [pKeyPath UTF8String]);
96 const BOOL bReadyForDisplay = [mpPlayerLayer isReadyForDisplay];
97 [mpPlayerLayer setHidden:!bReadyForDisplay];
98 return true;
99 }
100
101 // XPlayerWindow
102 // ------------------------------------------------------------------------------
103
update()104 void SAL_CALL Window::update()
105 throw (uno::RuntimeException)
106 {}
107
108 // ------------------------------------------------------------------------------
109
setZoomLevel(media::ZoomLevel eZoomLevel)110 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel )
111 throw (uno::RuntimeException)
112 {
113 return false;
114 }
115
116 // ------------------------------------------------------------------------------
117
getZoomLevel()118 media::ZoomLevel SAL_CALL Window::getZoomLevel( )
119 throw (uno::RuntimeException)
120 {
121 return meZoomLevel;
122 }
123
124 // ------------------------------------------------------------------------------
125
setPointerType(sal_Int32 nPointerType)126 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
127 throw (uno::RuntimeException)
128 {
129 mnPointerType = nPointerType;
130 }
131
132 // XWindow
133 // ------------------------------------------------------------------------------
134
setPosSize(sal_Int32 X,sal_Int32 Y,sal_Int32 Width,sal_Int32 Height,sal_Int16 Flags)135 void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags )
136 throw (uno::RuntimeException)
137 {
138 OSL_TRACE( "AVWindow::setPosSize( %dx%d%+d%+d)", (int)Width,(int)Height,(int)X,(int)Y);//######
139 if( !mpView )
140 return;
141 NSRect aRect = [mpView frame];
142 // NOTE: if( (Flags & awt::PosSize::WIDTH) )
143 aRect.size.width = Width;
144 // NOTE: if( (Flags & awt::PosSize::HEIGHT) )
145 aRect.size.height = Height;
146
147 [mpView setFrameSize: aRect.size];
148 [mpPlayerLayer setFrame: [mpView frame]];
149 }
150
151 // ------------------------------------------------------------------------------
152
getPosSize()153 awt::Rectangle SAL_CALL Window::getPosSize()
154 throw (uno::RuntimeException)
155 {
156 awt::Rectangle aRet;
157
158 NSRect aRect = [mpView frame];
159 aRet.X = aRet.Y = 0;
160 aRet.Width = aRect.size.width;
161 aRet.Height = aRect.size.height;
162
163 return aRet;
164 }
165
166 // ------------------------------------------------------------------------------
167
setVisible(sal_Bool bVisible)168 void SAL_CALL Window::setVisible( sal_Bool bVisible )
169 throw (uno::RuntimeException)
170 {
171 OSL_TRACE ("Window::setVisible(%d)", bVisible);
172 }
173
174 // ------------------------------------------------------------------------------
175
setEnable(sal_Bool bEnable)176 void SAL_CALL Window::setEnable( sal_Bool bEnable )
177 throw (uno::RuntimeException)
178 {
179 OSL_TRACE ("Window::setEnable(%d)", bEnable);
180 }
181
182 // ------------------------------------------------------------------------------
183
setFocus()184 void SAL_CALL Window::setFocus()
185 throw (uno::RuntimeException)
186 {
187 OSL_TRACE ("Window::setFocus");
188 }
189
190 // ------------------------------------------------------------------------------
191
addWindowListener(const uno::Reference<awt::XWindowListener> & xListener)192 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
193 throw (uno::RuntimeException)
194 {
195 maListeners.addInterface( getCppuType( &xListener ), xListener );
196 }
197
198 // ------------------------------------------------------------------------------
199
removeWindowListener(const uno::Reference<awt::XWindowListener> & xListener)200 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
201 throw (uno::RuntimeException)
202 {
203 maListeners.removeInterface( getCppuType( &xListener ), xListener );
204 }
205
206 // ------------------------------------------------------------------------------
207
addFocusListener(const uno::Reference<awt::XFocusListener> & xListener)208 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
209 throw (uno::RuntimeException)
210 {
211 maListeners.addInterface( getCppuType( &xListener ), xListener );
212 }
213
214 // ------------------------------------------------------------------------------
215
removeFocusListener(const uno::Reference<awt::XFocusListener> & xListener)216 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
217 throw (uno::RuntimeException)
218 {
219 maListeners.removeInterface( getCppuType( &xListener ), xListener );
220 }
221
222 // ------------------------------------------------------------------------------
223
addKeyListener(const uno::Reference<awt::XKeyListener> & xListener)224 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
225 throw (uno::RuntimeException)
226 {
227 maListeners.addInterface( getCppuType( &xListener ), xListener );
228 }
229
230 // ------------------------------------------------------------------------------
231
removeKeyListener(const uno::Reference<awt::XKeyListener> & xListener)232 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
233 throw (uno::RuntimeException)
234 {
235 maListeners.removeInterface( getCppuType( &xListener ), xListener );
236 }
237
238 // ------------------------------------------------------------------------------
239
addMouseListener(const uno::Reference<awt::XMouseListener> & xListener)240 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
241 throw (uno::RuntimeException)
242 {
243 maListeners.addInterface( getCppuType( &xListener ), xListener );
244 }
245
246 // ------------------------------------------------------------------------------
247
removeMouseListener(const uno::Reference<awt::XMouseListener> & xListener)248 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
249 throw (uno::RuntimeException)
250 {
251 maListeners.removeInterface( getCppuType( &xListener ), xListener );
252 }
253
254 // ------------------------------------------------------------------------------
255
addMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)256 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
257 throw (uno::RuntimeException)
258 {
259 maListeners.addInterface( getCppuType( &xListener ), xListener );
260 }
261
262 // ------------------------------------------------------------------------------
263
removeMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)264 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
265 throw (uno::RuntimeException)
266 {
267 maListeners.removeInterface( getCppuType( &xListener ), xListener );
268 }
269
270 // ------------------------------------------------------------------------------
271
addPaintListener(const uno::Reference<awt::XPaintListener> & xListener)272 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
273 throw (uno::RuntimeException)
274 {
275 maListeners.addInterface( getCppuType( &xListener ), xListener );
276 }
277
278 // ------------------------------------------------------------------------------
279
removePaintListener(const uno::Reference<awt::XPaintListener> & xListener)280 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
281 throw (uno::RuntimeException)
282 {
283 maListeners.removeInterface( getCppuType( &xListener ), xListener );
284 }
285
286
287 // XComponent
288 // ------------------------------------------------------------------------------
289
dispose()290 void SAL_CALL Window::dispose( )
291 throw (uno::RuntimeException)
292 {
293 }
294
295 // ------------------------------------------------------------------------------
296
addEventListener(const uno::Reference<lang::XEventListener> & xListener)297 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
298 throw (uno::RuntimeException)
299 {
300 maListeners.addInterface( getCppuType( &xListener ), xListener );
301 }
302
303 // ------------------------------------------------------------------------------
304
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)305 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
306 throw (uno::RuntimeException)
307 {
308 maListeners.removeInterface( getCppuType( &xListener ), xListener );
309 }
310
311 // XServiceInfo
312 // ------------------------------------------------------------------------------
313
getImplementationName()314 ::rtl::OUString SAL_CALL Window::getImplementationName( )
315 throw (uno::RuntimeException)
316 {
317 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_MACAVF_WINDOW_IMPLEMENTATIONNAME ) );
318 }
319
320 // ------------------------------------------------------------------------------
321
supportsService(const::rtl::OUString & ServiceName)322 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
323 throw (uno::RuntimeException)
324 {
325 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) );
326 }
327
328 // ------------------------------------------------------------------------------
329
getSupportedServiceNames()330 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( )
331 throw (uno::RuntimeException)
332 {
333 uno::Sequence< ::rtl::OUString > aRet(1);
334 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) );
335
336 return aRet;
337 }
338
339 } // namespace macavf
340 } // namespace avmedia
341
342