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 
24 #ifndef _GSTPLAYER_HXX
25 #define _GSTPLAYER_HXX
26 
27 #include "gstcommon.hxx"
28 #include <glib.h>
29 
30 // necessary for mixed environments with GStreamer-0.10 and GLib versions < 2.8
31 #ifndef G_GNUC_NULL_TERMINATED
32 #if __GNUC__ >= 4
33 #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
34 #else
35 #define G_GNUC_NULL_TERMINATED
36 #endif
37 #endif
38 
39 struct _GOptionGroup;
40 typedef struct _GOptionGroup GOptionGroup;
41 
42 #include <gst/gst.h>
43 #include "com/sun/star/media/XPlayer.hdl"
44 #include <cppuhelper/compbase2.hxx>
45 #include <cppuhelper/basemutex.hxx>
46 
47 namespace avmedia
48 {
49 namespace gst
50 {
51 class Window;
52 
53 // ---------------
54 // - Player_Impl -
55 // ---------------
56 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::media::XPlayer,
57                                           ::com::sun::star::lang::XServiceInfo > Player_BASE;
58 
59 class Player :  public cppu::BaseMutex,
60                 public Player_BASE
61 {
62 public:
63 
64     // static create method instead of public Ctor
65     static Player* create( const ::rtl::OUString& rURL );
66 
67     ~Player();
68 //protected:
69     // XPlayer
70     virtual void SAL_CALL start()
71      throw( ::com::sun::star::uno::RuntimeException );
72 
73     virtual void SAL_CALL stop()
74      throw( ::com::sun::star::uno::RuntimeException );
75 
76     virtual sal_Bool SAL_CALL isPlaying()
77      throw( ::com::sun::star::uno::RuntimeException );
78 
79     virtual double SAL_CALL getDuration()
80      throw( ::com::sun::star::uno::RuntimeException );
81 
82     virtual void SAL_CALL setMediaTime( double fTime )
83      throw( ::com::sun::star::uno::RuntimeException );
84 
85     virtual double SAL_CALL getMediaTime()
86      throw( ::com::sun::star::uno::RuntimeException );
87 
88     virtual void SAL_CALL setStopTime( double fTime )
89      throw( ::com::sun::star::uno::RuntimeException );
90 
91     virtual double SAL_CALL getStopTime()
92      throw( ::com::sun::star::uno::RuntimeException );
93 
94     virtual void SAL_CALL setRate( double fRate )
95      throw( ::com::sun::star::uno::RuntimeException );
96 
97     virtual double SAL_CALL getRate()
98      throw( ::com::sun::star::uno::RuntimeException );
99 
100     virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet )
101      throw( ::com::sun::star::uno::RuntimeException );
102 
103     virtual sal_Bool SAL_CALL isPlaybackLoop()
104      throw( ::com::sun::star::uno::RuntimeException );
105 
106     virtual void SAL_CALL setMute( sal_Bool bSet )
107      throw( ::com::sun::star::uno::RuntimeException );
108 
109     virtual sal_Bool SAL_CALL isMute()
110      throw( ::com::sun::star::uno::RuntimeException );
111 
112     virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB )
113      throw( ::com::sun::star::uno::RuntimeException );
114 
115     virtual sal_Int16 SAL_CALL getVolumeDB()
116      throw( ::com::sun::star::uno::RuntimeException );
117 
118     virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize()
119      throw( ::com::sun::star::uno::RuntimeException );
120 
121     virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow(
122         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
123      throw( ::com::sun::star::uno::RuntimeException );
124 
125     virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber()
126      throw( ::com::sun::star::uno::RuntimeException );
127 
128     // XServiceInfo
129     virtual ::rtl::OUString SAL_CALL getImplementationName()
130      throw( ::com::sun::star::uno::RuntimeException );
131 
132     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
133      throw( ::com::sun::star::uno::RuntimeException );
134 
135     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
136      throw( ::com::sun::star::uno::RuntimeException );
137 
138 // these are public because the C callbacks call them
139 
140     virtual gboolean busCallback( GstBus* pBus,
141                                   GstMessage* pMsg );
142 
143     virtual gboolean idle();
144 
145     virtual gpointer run();
146 
147     virtual GstBusSyncReply handleCreateWindow( GstBus* pBus,
148                                                 GstMessage* pMsg );
149 
150 protected:
151 
152     // ::cppu::OComponentHelper
153 	virtual void SAL_CALL disposing(void);
154 
155     Player( GString* pURI = NULL );
156 
157     void implQuitThread();
158 
159     bool implInitPlayer();
160 
implIsInitialized() const161     bool implIsInitialized() const
162     {
163         return( g_atomic_int_get( &mnInitialized ) > 0 );
164     }
165 
166 private:
167 
168     Player( const Player& );
169 
170     Player& operator=( const Player& );
171 
172     static void implHandleNewElementFunc( GstBin* pBin,
173                                           GstElement* pElement,
174                                           gpointer pData );
175 
176     static void implHandleNewPadFunc( GstElement* pElem,
177                                       GstPad* pPad,
178                                       gpointer pData );
179 
180 protected:
181 
182     GMutex* mpMutex;
183     GCond* mpCond;
184     GThread* mpThread;
185     GMainContext* mpContext;
186     GMainLoop* mpLoop;
187     GstElement* mpPlayer;
188     GString* mpURI;
189 
190 private:
191 
192     ::avmedia::gst::Window* mpPlayerWindow;
193     gint mnIsVideoSource;
194     gint mnVideoWidth;
195     gint mnVideoHeight;
196     gint mnInitialized;
197     gint mnVolumeDB;
198     gint mnLooping;
199     gint mnQuit;
200     gint mnVideoWindowSet;
201 	gint mnInitFail;
202 };
203 }     // namespace gst
204 } // namespace avmedia
205 
206 #endif // _GSTPLAYER_HXX
207