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 38 Window::Window( const uno::Reference< uno::XComponentContext >& i_rxContext, Player& i_rPlayer, NSView* i_pParentView ) 39 : mxContext( i_rxContext ) 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 78 Window::~Window() 79 { 80 [mpPlayerLayer removeObserver:getObserver() forKeyPath:@"readyForDisplay"]; 81 [mpPlayerLayer release]; 82 } 83 84 // ------------------------------------------------------------------------------ 85 86 bool Window::create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 87 { 88 return true; 89 } 90 91 // ------------------------------------------------------------------------------ 92 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 104 void SAL_CALL Window::update() 105 {} 106 107 // ------------------------------------------------------------------------------ 108 109 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) 110 { 111 return false; 112 } 113 114 // ------------------------------------------------------------------------------ 115 116 media::ZoomLevel SAL_CALL Window::getZoomLevel( ) 117 { 118 return meZoomLevel; 119 } 120 121 // ------------------------------------------------------------------------------ 122 123 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) 124 { 125 mnPointerType = nPointerType; 126 } 127 128 // XWindow 129 // ------------------------------------------------------------------------------ 130 131 void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) 132 { 133 OSL_TRACE( "AVWindow::setPosSize( %dx%d%+d%+d)", (int)Width,(int)Height,(int)X,(int)Y);//###### 134 if( !mpView ) 135 return; 136 NSRect aRect = [mpView frame]; 137 // NOTE: if( (Flags & awt::PosSize::WIDTH) ) 138 aRect.size.width = Width; 139 // NOTE: if( (Flags & awt::PosSize::HEIGHT) ) 140 aRect.size.height = Height; 141 142 [mpView setFrameSize: aRect.size]; 143 [mpPlayerLayer setFrame: [mpView frame]]; 144 } 145 146 // ------------------------------------------------------------------------------ 147 148 awt::Rectangle SAL_CALL Window::getPosSize() 149 { 150 awt::Rectangle aRet; 151 152 NSRect aRect = [mpView frame]; 153 aRet.X = aRet.Y = 0; 154 aRet.Width = aRect.size.width; 155 aRet.Height = aRect.size.height; 156 157 return aRet; 158 } 159 160 // ------------------------------------------------------------------------------ 161 162 void SAL_CALL Window::setVisible( sal_Bool bVisible ) 163 { 164 OSL_TRACE ("Window::setVisible(%d)", bVisible); 165 } 166 167 // ------------------------------------------------------------------------------ 168 169 void SAL_CALL Window::setEnable( sal_Bool bEnable ) 170 { 171 OSL_TRACE ("Window::setEnable(%d)", bEnable); 172 } 173 174 // ------------------------------------------------------------------------------ 175 176 void SAL_CALL Window::setFocus() 177 { 178 OSL_TRACE ("Window::setFocus"); 179 } 180 181 // ------------------------------------------------------------------------------ 182 183 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) 184 { 185 maListeners.addInterface( getCppuType( &xListener ), xListener ); 186 } 187 188 // ------------------------------------------------------------------------------ 189 190 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) 191 { 192 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 193 } 194 195 // ------------------------------------------------------------------------------ 196 197 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) 198 { 199 maListeners.addInterface( getCppuType( &xListener ), xListener ); 200 } 201 202 // ------------------------------------------------------------------------------ 203 204 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) 205 { 206 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 207 } 208 209 // ------------------------------------------------------------------------------ 210 211 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) 212 { 213 maListeners.addInterface( getCppuType( &xListener ), xListener ); 214 } 215 216 // ------------------------------------------------------------------------------ 217 218 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) 219 { 220 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 221 } 222 223 // ------------------------------------------------------------------------------ 224 225 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) 226 { 227 maListeners.addInterface( getCppuType( &xListener ), xListener ); 228 } 229 230 // ------------------------------------------------------------------------------ 231 232 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) 233 { 234 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 235 } 236 237 // ------------------------------------------------------------------------------ 238 239 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) 240 { 241 maListeners.addInterface( getCppuType( &xListener ), xListener ); 242 } 243 244 // ------------------------------------------------------------------------------ 245 246 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) 247 { 248 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 249 } 250 251 // ------------------------------------------------------------------------------ 252 253 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) 254 { 255 maListeners.addInterface( getCppuType( &xListener ), xListener ); 256 } 257 258 // ------------------------------------------------------------------------------ 259 260 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) 261 { 262 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 263 } 264 265 266 // XComponent 267 // ------------------------------------------------------------------------------ 268 269 void SAL_CALL Window::dispose( ) 270 { 271 } 272 273 // ------------------------------------------------------------------------------ 274 275 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) 276 { 277 maListeners.addInterface( getCppuType( &xListener ), xListener ); 278 } 279 280 // ------------------------------------------------------------------------------ 281 282 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) 283 { 284 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 285 } 286 287 // XServiceInfo 288 // ------------------------------------------------------------------------------ 289 290 ::rtl::OUString SAL_CALL Window::getImplementationName( ) 291 { 292 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_MACAVF_WINDOW_IMPLEMENTATIONNAME ) ); 293 } 294 295 // ------------------------------------------------------------------------------ 296 297 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) 298 { 299 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) ); 300 } 301 302 // ------------------------------------------------------------------------------ 303 304 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( ) 305 { 306 uno::Sequence< ::rtl::OUString > aRet(1); 307 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) ); 308 309 return aRet; 310 } 311 312 } // namespace macavf 313 } // namespace avmedia 314