LibreOffice Module avmedia (master) 1
window.mm
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <com/sun/star/awt/SystemPointer.hpp>
21#include <com/sun/star/awt/PosSize.hpp>
22
23#include "window.hxx"
24#include "player.hxx"
25
26using namespace ::com::sun::star;
27
28
29namespace avmedia::macavf {
30
31Window::Window( Player& i_rPlayer, NSView* i_pParentView )
32: maListeners( maMutex )
33, meZoomLevel( media::ZoomLevel_NOT_AVAILABLE )
34, mrPlayer( i_rPlayer )
35, mnPointerType( awt::SystemPointer::ARROW )
36, mpView( i_pParentView )
37, mpPlayerLayer( nullptr )
38{
39 if( !mpView ) // sanity check
40 return;
41
42 // check the media asset for video content
43 AVPlayer* pAVPlayer = mrPlayer.getAVPlayer();
44 AVAsset* pMovie = [[pAVPlayer currentItem] asset];
45 const int nVideoCount = [pMovie tracksWithMediaType:AVMediaTypeVideo].count;
46 if( nVideoCount <= 0 )
47 return;
48
49 // setup the AVPlayerLayer
50 [pAVPlayer retain];
51 [pAVPlayer pause];
52 mpPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:pAVPlayer];
53 [mpPlayerLayer retain];
54 NSRect viewFrame = [mpView frame];
55 [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
56 [mpPlayerLayer setHidden:YES];
57 [mpPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
58 [mpPlayerLayer addObserver:getObserver() forKeyPath:@"readyForDisplay" options:0 context:this];
59
60 // setup the target view
61 [mpView setWantsLayer:YES];
62 [mpView.layer addSublayer:mpPlayerLayer];
63}
64
65
67{
68 [mpPlayerLayer removeObserver:getObserver() forKeyPath:@"readyForDisplay"];
69 [mpPlayerLayer release];
70}
71
72
73bool Window::handleObservation( NSString* /*pKeyPath*/ )
74{
75 const bool bReadyForDisplay = [mpPlayerLayer isReadyForDisplay];
76 [mpPlayerLayer setHidden:!bReadyForDisplay];
77 return true;
78}
79
80// XPlayerWindow
81
82void SAL_CALL Window::update()
83{}
84
85
86sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel /* eZoomLevel */ )
87{
88 return false;
89}
90
91
92media::ZoomLevel SAL_CALL Window::getZoomLevel( )
93{
94 return meZoomLevel;
95}
96
97
98void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
99{
100 mnPointerType = nPointerType;
101}
102
103// XWindow
104
105void SAL_CALL Window::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 Width, sal_Int32 Height, sal_Int16 /* Flags */ )
106{
107 if( !mpView )
108 return;
109 NSRect aRect = [mpView frame];
110 // NOTE: if( (Flags & awt::PosSize::WIDTH) )
111 aRect.size.width = Width;
112 // NOTE: if( (Flags & awt::PosSize::HEIGHT) )
113 aRect.size.height = Height;
114
115 [mpView setFrameSize: aRect.size];
116 NSRect viewFrame = [mpView frame];
117 [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
118}
119
120
121awt::Rectangle SAL_CALL Window::getPosSize()
122{
123 awt::Rectangle aRet;
124
125 NSRect aRect = [mpView frame];
126 aRet.X = aRet.Y = 0;
127 aRet.Width = aRect.size.width;
128 aRet.Height = aRect.size.height;
129
130 return aRet;
131}
132
133
134void SAL_CALL Window::setVisible( sal_Bool /*bVisible*/ )
135{
136}
137
138
139void SAL_CALL Window::setEnable( sal_Bool /*bEnable*/ )
140{
141}
142
143
144void SAL_CALL Window::setFocus()
145{
146}
147
148
149void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
150{
151 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
152}
153
154
155void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
156{
157 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
158}
159
160
161void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
162{
163 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
164}
165
166
167void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
168{
169 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
170}
171
172
173void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
174{
175 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
176}
177
178
179void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
180{
181 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
182}
183
184
185void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
186{
187 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
188}
189
190
191void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
192{
193 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
194}
195
196
197void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
198{
199 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
200}
201
202
203void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
204{
205 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
206}
207
208
209void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
210{
211 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
212}
213
214
215void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
216{
217 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
218}
219
220
221// XComponent
222
223void SAL_CALL Window::dispose( )
224{
225}
226
227
228void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
229{
230 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
231}
232
233
234void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
235{
236 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
237}
238
239// XServiceInfo
240
242{
244}
245
246
247sal_Bool SAL_CALL Window::supportsService( const OUString& ServiceName )
248{
250}
251
252
253uno::Sequence< OUString > SAL_CALL Window::getSupportedServiceNames( )
254{
256}
257
258} // namespace avmedia::macavf
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::mutex maMutex
static MacAVObserverObject * getObserver()
Definition: player.mm:64
AVPlayer * getAVPlayer() const
virtual css::media::ZoomLevel SAL_CALL getZoomLevel() override
Definition: window.mm:92
virtual void SAL_CALL addPaintListener(const css::uno::Reference< css::awt::XPaintListener > &xListener) override
virtual bool handleObservation(NSString *pKeyPath) override
Definition: window.mm:73
virtual css::awt::Rectangle SAL_CALL getPosSize() override
Definition: window.mm:121
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: window.mm:247
virtual ~Window() override
Definition: window.mm:66
virtual OUString SAL_CALL getImplementationName() override
Definition: window.mm:241
virtual void SAL_CALL removeMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &xListener) override
virtual void SAL_CALL setVisible(sal_Bool Visible) override
Definition: window.mm:134
virtual void SAL_CALL setEnable(sal_Bool Enable) override
Definition: window.mm:139
virtual void SAL_CALL update() override
Definition: window.mm:82
virtual void SAL_CALL removeMouseListener(const css::uno::Reference< css::awt::XMouseListener > &xListener) override
virtual void SAL_CALL addWindowListener(const css::uno::Reference< css::awt::XWindowListener > &xListener) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL setFocus() override
Definition: window.mm:144
virtual void SAL_CALL setPosSize(sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags) override
Definition: window.mm:105
css::media::ZoomLevel meZoomLevel
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL removeWindowListener(const css::uno::Reference< css::awt::XWindowListener > &xListener) override
virtual void SAL_CALL dispose() override
Definition: window.mm:223
virtual void SAL_CALL addMouseListener(const css::uno::Reference< css::awt::XMouseListener > &xListener) override
virtual sal_Bool SAL_CALL setZoomLevel(css::media::ZoomLevel ZoomLevel) override
virtual void SAL_CALL removeFocusListener(const css::uno::Reference< css::awt::XFocusListener > &xListener) override
virtual void SAL_CALL setPointerType(sal_Int32 nPointerType) override
Definition: window.mm:98
comphelper::OMultiTypeInterfaceContainerHelper2 maListeners
Window(Player &i_rPlayer, NSView *i_pParentView)
Definition: window.mm:31
virtual void SAL_CALL addKeyListener(const css::uno::Reference< css::awt::XKeyListener > &xListener) override
virtual void SAL_CALL addMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &xListener) override
virtual void SAL_CALL addFocusListener(const css::uno::Reference< css::awt::XFocusListener > &xListener) override
virtual void SAL_CALL removePaintListener(const css::uno::Reference< css::awt::XPaintListener > &xListener) override
virtual void SAL_CALL removeKeyListener(const css::uno::Reference< css::awt::XKeyListener > &xListener) override
AVPlayerLayer * mpPlayerLayer
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: window.mm:253
sal_Int32 removeInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &r)
ARROW
#define AVMEDIA_MACAVF_WINDOW_SERVICENAME
#define AVMEDIA_MACAVF_WINDOW_IMPLEMENTATIONNAME
UnoViewSharedPtr mpView
unsigned char sal_Bool