xref: /trunk/main/avmedia/source/gstreamer/gstplayer.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
72     virtual void SAL_CALL stop();
73 
74     virtual sal_Bool SAL_CALL isPlaying();
75 
76     virtual double SAL_CALL getDuration();
77 
78     virtual void SAL_CALL setMediaTime( double fTime );
79 
80     virtual double SAL_CALL getMediaTime();
81 
82     virtual void SAL_CALL setStopTime( double fTime );
83 
84     virtual double SAL_CALL getStopTime();
85 
86     virtual void SAL_CALL setRate( double fRate );
87 
88     virtual double SAL_CALL getRate();
89 
90     virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet );
91 
92     virtual sal_Bool SAL_CALL isPlaybackLoop();
93 
94     virtual void SAL_CALL setMute( sal_Bool bSet );
95 
96     virtual sal_Bool SAL_CALL isMute();
97 
98     virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB );
99 
100     virtual sal_Int16 SAL_CALL getVolumeDB();
101 
102     virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize();
103 
104     virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow(
105         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments );
106 
107     virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber();
108 
109     // XServiceInfo
110     virtual ::rtl::OUString SAL_CALL getImplementationName();
111 
112     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
113 
114     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
115 
116 // these are public because the C callbacks call them
117 
118     virtual gboolean busCallback( GstBus* pBus,
119                                   GstMessage* pMsg );
120 
121     virtual gboolean idle();
122 
123     virtual gpointer run();
124 
125     virtual GstBusSyncReply handleCreateWindow( GstBus* pBus,
126                                                 GstMessage* pMsg );
127 
128 protected:
129 
130     // ::cppu::OComponentHelper
131     virtual void SAL_CALL disposing(void);
132 
133     Player( GString* pURI = NULL );
134 
135     void implQuitThread();
136 
137     bool implInitPlayer();
138 
implIsInitialized() const139     bool implIsInitialized() const
140     {
141         return( g_atomic_int_get( &mnInitialized ) > 0 );
142     }
143 
144 private:
145 
146     Player( const Player& );
147 
148     Player& operator=( const Player& );
149 
150     static void implHandleNewElementFunc( GstBin* pBin,
151                                           GstElement* pElement,
152                                           gpointer pData );
153 
154     static void implHandleNewPadFunc( GstElement* pElem,
155                                       GstPad* pPad,
156                                       gpointer pData );
157 
158 protected:
159 
160     GMutex* mpMutex;
161     GCond* mpCond;
162     GThread* mpThread;
163     GMainContext* mpContext;
164     GMainLoop* mpLoop;
165     GstElement* mpPlayer;
166     GString* mpURI;
167 
168 private:
169 
170     ::avmedia::gst::Window* mpPlayerWindow;
171     gint mnIsVideoSource;
172     gint mnVideoWidth;
173     gint mnVideoHeight;
174     gint mnInitialized;
175     gint mnVolumeDB;
176     gint mnLooping;
177     gint mnQuit;
178     gint mnVideoWindowSet;
179     gint mnInitFail;
180 };
181 }     // namespace gst
182 } // namespace avmedia
183 
184 #endif // _GSTPLAYER_HXX
185