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