1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/mediactrl.cpp
3 // Purpose: GStreamer backend for Unix
4 // Author: Ryan Norton <wxprojects@comcast.net>
8 // Copyright: (c) 2004-2005 Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/mediactrl.h"
21 #include <gst/gst.h> // main gstreamer header
23 // xoverlay/video stuff, gst-gconf for 0.8
24 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
25 # include <gst/interfaces/xoverlay.h>
27 # include <gst/xoverlay/xoverlay.h>
28 # include <gst/gconf/gconf.h> // gstreamer glib configuration
32 #include "wx/log.h" // wxLogDebug/wxLogSysError/wxLogTrace
33 #include "wx/app.h" // wxTheApp->argc, wxTheApp->argv
34 #include "wx/timer.h" // wxTimer
37 #include "wx/thread.h" // wxMutex/wxMutexLocker
42 #include "wx/gtk/private/gtk2-compat.h"
45 //-----------------------------------------------------------------------------
46 // Discussion of internals
47 //-----------------------------------------------------------------------------
50 This is the GStreamer backend for unix. Currently we require 0.8 or
51 0.10. Here we use the "playbin" GstElement for ease of use.
53 Note that now we compare state change functions to GST_STATE_FAILURE
54 now rather than GST_STATE_SUCCESS as newer gstreamer versions return
55 non-success values for returns that are otherwise successful but not
58 Also this probably doesn't work with anything other than wxGTK at the
59 moment but with a tad bit of work it could theorectically work in
62 One last note is that resuming from pausing/seeking can result
63 in erratic video playback (GStreamer-based bug, happens in totem as well)
64 - this is better in 0.10, however. One thing that might make it worse
65 here is that we don't preserve the aspect ratio of the video and stretch
66 it to the whole window.
68 Note that there are some things used here that could be undocumented -
69 for reference see the media player Kiss and Totem as well as some
70 other sources. There was a backend for a kde media player as well
71 that attempted thread-safety...
73 Then there is the issue of m_asynclock. This serves several purposes:
74 1) It prevents the C callbacks from sending wx state change events
75 so that we don't get duplicate ones in 0.8
76 2) It makes the sync and async handlers in 0.10 not drop any
77 messages so that while we are polling it we get the messages in
78 SyncStateChange instead of the queue.
79 3) Keeps the pausing in Stop() synchronous
81 RN: Note that I've tried to follow the wxGTK conventions here as close
82 as possible. In the implementation the C Callbacks come first, then
83 the internal functions, then the public ones. Set your vi to 80
87 //=============================================================================
89 //=============================================================================
91 //-----------------------------------------------------------------------------
92 // GStreamer (most version compatibility) macros
93 //-----------------------------------------------------------------------------
95 // In 0.9 there was a HUGE change to GstQuery and the
96 // gst_element_query function changed dramatically and split off
97 // into two separate ones
98 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR <= 8
99 # define wxGst_element_query_duration(e, f, p) \
100 gst_element_query(e, GST_QUERY_TOTAL, f, p)
101 # define wxGst_element_query_position(e, f, p) \
102 gst_element_query(e, GST_QUERY_POSITION, f, p)
103 #elif GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR == 9
104 // However, the actual 0.9 version has a slightly different definition
105 // and instead of gst_element_query_duration it has two parameters to
106 // gst_element_query_position instead
107 # define wxGst_element_query_duration(e, f, p) \
108 gst_element_query_position(e, f, 0, p)
109 # define wxGst_element_query_position(e, f, p) \
110 gst_element_query_position(e, f, p, 0)
112 # define wxGst_element_query_duration \
113 gst_element_query_duration
114 # define wxGst_element_query_position \
115 gst_element_query_position
119 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
120 # define GST_STATE_FAILURE GST_STATE_CHANGE_FAILURE
121 # define GST_STATE_SUCCESS GST_STATE_CHANGE_SUCCESS
122 # define GstElementState GstState
123 # define gst_gconf_get_default_video_sink() \
124 gst_element_factory_make ("gconfvideosink", "video-sink");
125 # define gst_gconf_get_default_audio_sink() \
126 gst_element_factory_make ("gconfaudiosink", "audio-sink");
129 // Max wait time for element state waiting - GST_CLOCK_TIME_NONE for inf
130 #define wxGSTREAMER_TIMEOUT (100 * GST_MSECOND) // Max 100 milliseconds
132 //-----------------------------------------------------------------------------
133 // wxLogTrace mask string
134 //-----------------------------------------------------------------------------
135 #define wxTRACE_GStreamer wxT("GStreamer")
137 //-----------------------------------------------------------------------------
139 // wxGStreamerMediaBackend
141 //-----------------------------------------------------------------------------
142 class WXDLLIMPEXP_MEDIA
143 wxGStreamerMediaBackend
: public wxMediaBackendCommonBase
147 wxGStreamerMediaBackend();
148 virtual ~wxGStreamerMediaBackend();
150 virtual bool CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
155 const wxValidator
& validator
,
156 const wxString
& name
);
159 virtual bool Pause();
162 virtual bool Load(const wxString
& fileName
);
163 virtual bool Load(const wxURI
& location
);
164 virtual bool Load(const wxURI
& location
,
166 { return wxMediaBackendCommonBase::Load(location
, proxy
); }
169 virtual wxMediaState
GetState();
171 virtual bool SetPosition(wxLongLong where
);
172 virtual wxLongLong
GetPosition();
173 virtual wxLongLong
GetDuration();
175 virtual void Move(int x
, int y
, int w
, int h
);
176 wxSize
GetVideoSize() const;
178 virtual double GetPlaybackRate();
179 virtual bool SetPlaybackRate(double dRate
);
181 virtual wxLongLong
GetDownloadProgress();
182 virtual wxLongLong
GetDownloadTotal();
184 virtual bool SetVolume(double dVolume
);
185 virtual double GetVolume();
187 //------------implementation from now on-----------------------------------
188 bool DoLoad(const wxString
& locstring
);
189 wxMediaCtrl
* GetControl() { return m_ctrl
; } // for C Callbacks
190 void HandleStateChange(GstElementState oldstate
, GstElementState newstate
);
191 bool QueryVideoSizeFromElement(GstElement
* element
);
192 bool QueryVideoSizeFromPad(GstPad
* caps
);
193 void SetupXOverlay();
194 bool SyncStateChange(GstElement
* element
, GstElementState state
,
195 gint64 llTimeout
= wxGSTREAMER_TIMEOUT
);
196 bool TryAudioSink(GstElement
* audiosink
);
197 bool TryVideoSink(GstElement
* videosink
);
199 GstElement
* m_playbin
; // GStreamer media element
200 wxSize m_videoSize
; // Cached actual video size
201 double m_dRate
; // Current playback rate -
202 // see GetPlaybackRate for notes
203 wxLongLong m_llPausedPos
; // Paused position - see Pause()
204 GstXOverlay
* m_xoverlay
; // X Overlay that contains the GST video
205 wxMutex m_asynclock
; // See "discussion of internals"
206 class wxGStreamerMediaEventHandler
* m_eventHandler
; // see below
208 friend class wxGStreamerMediaEventHandler
;
209 friend class wxGStreamerLoadWaitTimer
;
210 DECLARE_DYNAMIC_CLASS(wxGStreamerMediaBackend
)
213 //-----------------------------------------------------------------------------
214 // wxGStreamerMediaEventHandler
216 // OK, this will take an explanation - basically gstreamer callbacks
217 // are issued in a separate thread, and in this thread we may not set
218 // the state of the playbin, so we need to send a wx event in that
219 // callback so that we set the state of the media and other stuff
221 //-----------------------------------------------------------------------------
222 class wxGStreamerMediaEventHandler
: public wxEvtHandler
225 wxGStreamerMediaEventHandler(wxGStreamerMediaBackend
* be
) : m_be(be
)
227 this->Connect(wxID_ANY
, wxEVT_MEDIA_FINISHED
,
228 wxMediaEventHandler(wxGStreamerMediaEventHandler::OnMediaFinish
));
231 void OnMediaFinish(wxMediaEvent
& event
);
233 wxGStreamerMediaBackend
* m_be
;
236 //=============================================================================
238 //=============================================================================
240 IMPLEMENT_DYNAMIC_CLASS(wxGStreamerMediaBackend
, wxMediaBackend
)
242 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
249 // "expose_event" from m_ctrl->m_wxwindow
251 // Handle GTK expose event from our window - here we hopefully
252 // redraw the video in the case of pausing and other instances...
253 // (Returns TRUE to pass to other handlers, FALSE if not)
255 // TODO: Do a DEBUG_MAIN_THREAD/install_idle_handler here?
256 //-----------------------------------------------------------------------------
261 draw(GtkWidget
* widget
, cairo_t
* cr
, wxGStreamerMediaBackend
* be
)
263 expose_event(GtkWidget
* widget
, GdkEventExpose
* event
, wxGStreamerMediaBackend
* be
)
266 // I've seen this recommended somewhere...
267 // TODO: Is this needed? Maybe it is just cruft...
268 // gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(be->m_xoverlay),
269 // GDK_WINDOW_XWINDOW( window ) );
271 // If we have actual video.....
272 if(!(be
->m_videoSize
.x
==0&&be
->m_videoSize
.y
==0) &&
273 GST_STATE(be
->m_playbin
) >= GST_STATE_PAUSED
)
275 // GST Doesn't redraw automatically while paused
276 // Plus, the video sometimes doesn't redraw when it looses focus
277 // or is painted over so we just tell it to redraw...
278 gst_x_overlay_expose(be
->m_xoverlay
);
282 // draw a black background like some other backends do....
285 gtk_widget_get_allocation(widget
, &a
);
286 cairo_rectangle(cr
, 0, 0, a
.width
, a
.height
);
287 cairo_set_source_rgb(cr
, 0, 0, 0);
290 gdk_draw_rectangle (event
->window
, widget
->style
->black_gc
, TRUE
, 0, 0,
291 widget
->allocation
.width
,
292 widget
->allocation
.height
);
301 //-----------------------------------------------------------------------------
302 // "realize" from m_ctrl->m_wxwindow
304 // If the window wasn't realized when Load was called, this is the
305 // callback for when it is - the purpose of which is to tell
306 // GStreamer to play the video in our control
307 //-----------------------------------------------------------------------------
310 static gint
gtk_window_realize_callback(GtkWidget
* widget
,
311 wxGStreamerMediaBackend
* be
)
315 GdkWindow
* window
= gtk_widget_get_window(widget
);
318 gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(be
->m_xoverlay
),
319 GDK_WINDOW_XID(window
)
321 g_signal_connect (be
->GetControl()->m_wxwindow
,
323 "draw", G_CALLBACK(draw
),
325 "expose_event", G_CALLBACK(expose_event
),
333 //-----------------------------------------------------------------------------
334 // "state-change" from m_playbin/GST_MESSAGE_STATE_CHANGE
336 // Called by gstreamer when the state changes - here we
337 // send the appropriate corresponding wx event.
339 // 0.8 only as HandleStateChange does this in both versions
340 //-----------------------------------------------------------------------------
341 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR < 10
343 static void gst_state_change_callback(GstElement
*play
,
344 GstElementState oldstate
,
345 GstElementState newstate
,
346 wxGStreamerMediaBackend
* be
)
348 if(be
->m_asynclock
.TryLock() == wxMUTEX_NO_ERROR
)
350 be
->HandleStateChange(oldstate
, newstate
);
351 be
->m_asynclock
.Unlock();
357 //-----------------------------------------------------------------------------
358 // "eos" from m_playbin/GST_MESSAGE_EOS
360 // Called by gstreamer when the media is done playing ("end of stream")
361 //-----------------------------------------------------------------------------
363 static void gst_finish_callback(GstElement
*WXUNUSED(play
),
364 wxGStreamerMediaBackend
* be
)
366 wxLogTrace(wxTRACE_GStreamer
, wxT("gst_finish_callback"));
367 wxMediaEvent
event(wxEVT_MEDIA_FINISHED
);
368 be
->m_eventHandler
->AddPendingEvent(event
);
372 //-----------------------------------------------------------------------------
373 // "error" from m_playbin/GST_MESSAGE_ERROR
375 // Called by gstreamer when an error is encountered playing the media -
376 // We call wxLogTrace in addition wxLogSysError so that we can get it
377 // on the command line as well for those who want extra traces.
378 //-----------------------------------------------------------------------------
380 static void gst_error_callback(GstElement
*WXUNUSED(play
),
381 GstElement
*WXUNUSED(src
),
384 wxGStreamerMediaBackend
* WXUNUSED(be
))
387 sError
.Printf(wxT("gst_error_callback\n")
388 wxT("Error Message:%s\nDebug:%s\n"),
389 (const wxChar
*)wxConvUTF8
.cMB2WX(err
->message
),
390 (const wxChar
*)wxConvUTF8
.cMB2WX(debug
));
391 wxLogTrace(wxTRACE_GStreamer
, sError
);
392 wxLogSysError(sError
);
396 //-----------------------------------------------------------------------------
397 // "notify::caps" from the videopad inside "stream-info" of m_playbin
399 // Called by gstreamer when the video caps for the media is ready - currently
400 // we use the caps to get the natural size of the video
403 //-----------------------------------------------------------------------------
405 static void gst_notify_caps_callback(GstPad
* pad
,
406 GParamSpec
* WXUNUSED(pspec
),
407 wxGStreamerMediaBackend
* be
)
409 wxLogTrace(wxTRACE_GStreamer
, wxT("gst_notify_caps_callback"));
410 be
->QueryVideoSizeFromPad(pad
);
414 //-----------------------------------------------------------------------------
415 // "notify::stream-info" from m_playbin
417 // Run through the stuff in "stream-info" of m_playbin for a valid
418 // video pad, and then attempt to query the video size from it - if not
419 // set up an event to do so when ready.
421 // Currently unused - now we just query it directly using
422 // QueryVideoSizeFromElement.
425 //-----------------------------------------------------------------------------
426 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
428 static void gst_notify_stream_info_callback(GstElement
* WXUNUSED(element
),
429 GParamSpec
* WXUNUSED(pspec
),
430 wxGStreamerMediaBackend
* be
)
432 wxLogTrace(wxTRACE_GStreamer
, wxT("gst_notify_stream_info_callback"));
433 be
->QueryVideoSizeFromElement(be
->m_playbin
);
438 //-----------------------------------------------------------------------------
439 // "desired-size-changed" from m_xoverlay
441 // 0.8-specific this provides us with the video size when it changes -
442 // even though we get the caps as well this seems to come before the
443 // caps notification does...
445 // Note it will return 16,16 for an early-bird value or for audio
446 //-----------------------------------------------------------------------------
447 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR < 10
449 static void gst_desired_size_changed_callback(GstElement
* play
,
450 guint width
, guint height
,
451 wxGStreamerMediaBackend
* be
)
453 if(!(width
== 16 && height
== 16))
455 be
->m_videoSize
.x
= width
;
456 be
->m_videoSize
.y
= height
;
459 be
->QueryVideoSizeFromElement(be
->m_playbin
);
464 //-----------------------------------------------------------------------------
465 // gst_bus_async_callback [static]
466 // gst_bus_sync_callback [static]
468 // Called by m_playbin for notifications such as end-of-stream in 0.10 -
469 // in previous versions g_signal notifications were used. Because everything
470 // in centered in one switch statement though it reminds one of old WinAPI
473 // gst_bus_sync_callback is that sync version that is called on the main GUI
474 // thread before the async version that we use to set the xwindow id of the
475 // XOverlay (NB: This isn't currently used - see CreateControl()).
476 //-----------------------------------------------------------------------------
477 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
479 static gboolean
gst_bus_async_callback(GstBus
* WXUNUSED(bus
),
481 wxGStreamerMediaBackend
* be
)
483 if(((GstElement
*)GST_MESSAGE_SRC(message
)) != be
->m_playbin
)
485 if(be
->m_asynclock
.TryLock() != wxMUTEX_NO_ERROR
)
488 switch(GST_MESSAGE_TYPE(message
))
490 case GST_MESSAGE_STATE_CHANGED
:
492 GstState oldstate
, newstate
, pendingstate
;
493 gst_message_parse_state_changed(message
, &oldstate
,
494 &newstate
, &pendingstate
);
495 be
->HandleStateChange(oldstate
, newstate
);
498 case GST_MESSAGE_EOS
:
500 gst_finish_callback(NULL
, be
);
503 case GST_MESSAGE_ERROR
:
507 gst_message_parse_error(message
, &error
, &debug
);
508 gst_error_callback(NULL
, NULL
, error
, debug
, be
);
515 be
->m_asynclock
.Unlock();
516 return FALSE
; // remove the message from Z queue
519 static GstBusSyncReply
gst_bus_sync_callback(GstBus
* bus
,
521 wxGStreamerMediaBackend
* be
)
523 // Pass a non-xwindowid-setting event on to the async handler where it
525 if (GST_MESSAGE_TYPE (message
) != GST_MESSAGE_ELEMENT
||
526 !gst_structure_has_name (message
->structure
, "prepare-xwindow-id"))
529 // NB: Unfortunately, the async callback can be quite
530 // buggy at times and often doesn't get called at all,
531 // so here we are processing it right here in the calling
532 // thread instead of the GUI one...
534 if(gst_bus_async_callback(bus
, message
, be
))
540 wxLogTrace(wxTRACE_GStreamer
, wxT("Got prepare-xwindow-id"));
542 return GST_BUS_DROP
; // We handled this message - drop from the queue
547 //-----------------------------------------------------------------------------
549 // Private (although not in the C++ sense) methods
551 //-----------------------------------------------------------------------------
553 //-----------------------------------------------------------------------------
554 // wxGStreamerMediaBackend::HandleStateChange
556 // Handles a state change event from our C Callback for "state-change" or
557 // the async queue in 0.10. (Mostly this is here to avoid locking the
558 // the mutex twice...)
559 //-----------------------------------------------------------------------------
560 void wxGStreamerMediaBackend::HandleStateChange(GstElementState oldstate
,
561 GstElementState newstate
)
565 case GST_STATE_PLAYING
:
566 wxLogTrace(wxTRACE_GStreamer
, wxT("Play event"));
569 case GST_STATE_PAUSED
:
570 // For some reason .10 sends a lot of oldstate == newstate
571 // messages - most likely for pending ones - also
572 // !<GST_STATE_PAUSED as we are only concerned
573 if(oldstate
< GST_STATE_PAUSED
|| oldstate
== newstate
)
575 if(wxGStreamerMediaBackend::GetPosition() != 0)
577 wxLogTrace(wxTRACE_GStreamer
, wxT("Pause event"));
582 wxLogTrace(wxTRACE_GStreamer
, wxT("Stop event"));
586 default: // GST_STATE_NULL etc.
591 //-----------------------------------------------------------------------------
592 // wxGStreamerMediaBackend::QueryVideoSizeFromElement
594 // Run through the stuff in "stream-info" of element for a valid
595 // video pad, and then attempt to query the video size from it - if not
596 // set up an event to do so when ready. Return true
597 // if we got a valid video pad.
598 //-----------------------------------------------------------------------------
599 bool wxGStreamerMediaBackend::QueryVideoSizeFromElement(GstElement
* element
)
601 const GList
*list
= NULL
;
602 g_object_get (G_OBJECT (element
), "stream-info", &list
, NULL
);
604 for ( ; list
!= NULL
; list
= list
->next
)
606 GObject
*info
= (GObject
*) list
->data
;
612 g_object_get (info
, "type", &type
, NULL
);
613 pspec
= g_object_class_find_property (
614 G_OBJECT_GET_CLASS (info
), "type");
615 val
= g_enum_get_value (G_PARAM_SPEC_ENUM (pspec
)->enum_class
, type
);
617 if (!strncasecmp(val
->value_name
, "video", 5) ||
618 !strncmp(val
->value_name
, "GST_STREAM_TYPE_VIDEO", 21))
620 // Newer gstreamer 0.8+ plugins are SUPPOSED to have "object"...
621 // but a lot of old plugins still use "pad" :)
622 pspec
= g_object_class_find_property (
623 G_OBJECT_GET_CLASS (info
), "object");
626 g_object_get (info
, "pad", &pad
, NULL
);
628 g_object_get (info
, "object", &pad
, NULL
);
630 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR <= 8
631 // Killed in 0.9, presumely because events and such
632 // should be pushed on pads regardless of whether they
633 // are currently linked
634 pad
= (GstPad
*) GST_PAD_REALIZE (pad
);
638 if(!QueryVideoSizeFromPad(pad
))
640 // wait for those caps to get ready
644 G_CALLBACK(gst_notify_caps_callback
),
649 }// end searching through info list
651 // no video (or extremely delayed stream-info)
654 m_videoSize
= wxSize(0,0);
661 //-----------------------------------------------------------------------------
662 // wxGStreamerMediaBackend::QueryVideoSizeFromPad
664 // Gets the size of our video (in wxSize) from a GstPad
665 //-----------------------------------------------------------------------------
666 bool wxGStreamerMediaBackend::QueryVideoSizeFromPad(GstPad
* pad
)
668 const GstCaps
* caps
= GST_PAD_CAPS(pad
);
671 const GstStructure
*s
= gst_caps_get_structure (caps
, 0);
674 gst_structure_get_int (s
, "width", &m_videoSize
.x
);
675 gst_structure_get_int (s
, "height", &m_videoSize
.y
);
678 par
= gst_structure_get_value (s
, "pixel-aspect-ratio");
682 wxLogTrace(wxTRACE_GStreamer
,
683 wxT("pixel-aspect-ratio found in pad"));
684 int num
= par
->data
[0].v_int
,
685 den
= par
->data
[1].v_int
;
687 // TODO: maybe better fraction normalization...
689 m_videoSize
.x
= (int) ((float) num
* m_videoSize
.x
/ den
);
691 m_videoSize
.y
= (int) ((float) den
* m_videoSize
.y
/ num
);
694 wxLogTrace(wxTRACE_GStreamer
, wxT("Adjusted video size: [%i,%i]"),
695 m_videoSize
.x
, m_videoSize
.y
);
699 return false; // not ready/massive failure
702 //-----------------------------------------------------------------------------
703 // wxGStreamerMediaBackend::SetupXOverlay
705 // Attempts to set the XWindow id of our GstXOverlay to tell it which
706 // window to play video in.
707 //-----------------------------------------------------------------------------
708 void wxGStreamerMediaBackend::SetupXOverlay()
710 // Use the xoverlay extension to tell gstreamer to play in our window
712 if (!gtk_widget_get_realized(m_ctrl
->m_wxwindow
))
714 // Not realized yet - set to connect at realization time
715 g_signal_connect (m_ctrl
->m_wxwindow
,
717 G_CALLBACK (gtk_window_realize_callback
),
724 GdkWindow
* window
= gtk_widget_get_window(m_ctrl
->m_wxwindow
);
727 gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_xoverlay
),
729 GDK_WINDOW_XID(window
)
735 g_signal_connect(m_ctrl
->m_wxwindow
,
737 "draw", G_CALLBACK(draw
),
739 "expose_event", G_CALLBACK(expose_event
),
742 } // end if GtkPizza realized
746 //-----------------------------------------------------------------------------
747 // wxGStreamerMediaBackend::SyncStateChange
749 // This function is rather complex - basically the idea is that we
750 // poll the GstBus of m_playbin until it has reached desiredstate, an error
751 // is reached, or there are no more messages left in the GstBus queue.
753 // Returns true if there are no messages left in the queue or
754 // the current state reaches the disired state.
756 // PRECONDITION: Assumes m_asynclock is Lock()ed
757 //-----------------------------------------------------------------------------
758 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
759 bool wxGStreamerMediaBackend::SyncStateChange(GstElement
* element
,
760 GstElementState desiredstate
,
763 GstBus
* bus
= gst_element_get_bus(element
);
767 gint64 llTimeWaited
= 0;
772 // NB: The GStreamer gst_bus_poll is unfortunately broken and
773 // throws silly critical internal errors (for instance
774 // "message != NULL" when the whole point of it is to
775 // poll for the message in the first place!) so we implement
776 // our own "waiting mechinism"
777 if(gst_bus_have_pending(bus
) == FALSE
)
779 if(llTimeWaited
>= llTimeout
)
780 return true; // Reached timeout... assume success
781 llTimeWaited
+= 10*GST_MSECOND
;
786 message
= gst_bus_pop(bus
);
788 message
= gst_bus_poll(bus
, (GstMessageType
)
789 (GST_MESSAGE_STATE_CHANGED
|
791 GST_MESSAGE_EOS
), llTimeout
);
795 if(((GstElement
*)GST_MESSAGE_SRC(message
)) == element
)
797 switch(GST_MESSAGE_TYPE(message
))
799 case GST_MESSAGE_STATE_CHANGED
:
801 GstState oldstate
, newstate
, pendingstate
;
802 gst_message_parse_state_changed(message
, &oldstate
,
803 &newstate
, &pendingstate
);
804 if(newstate
== desiredstate
)
806 bSuccess
= bBreak
= true;
810 case GST_MESSAGE_ERROR
:
814 gst_message_parse_error(message
, &error
, &debug
);
815 gst_error_callback(NULL
, NULL
, error
, debug
, this);
819 case GST_MESSAGE_EOS
:
820 wxLogSysError(wxT("Reached end of stream prematurely"));
824 break; // not handled
828 gst_message_unref(message
);
833 #else // 0.8 implementation
834 bool wxGStreamerMediaBackend::SyncStateChange(GstElement
* element
,
835 GstElementState desiredstate
,
838 gint64 llTimeWaited
= 0;
839 while(GST_STATE(element
) != desiredstate
)
841 if(llTimeWaited
>= llTimeout
)
843 llTimeWaited
+= 10*GST_MSECOND
;
847 return llTimeWaited
!= llTimeout
;
851 //-----------------------------------------------------------------------------
852 // wxGStreamerMediaBackend::TryAudioSink
853 // wxGStreamerMediaBackend::TryVideoSink
855 // Uses various means to determine whether a passed in video/audio sink
856 // if suitable for us - if it is not we return false and unref the
857 // inappropriate sink.
858 //-----------------------------------------------------------------------------
859 bool wxGStreamerMediaBackend::TryAudioSink(GstElement
* audiosink
)
861 if( !GST_IS_ELEMENT(audiosink
) )
863 if(G_IS_OBJECT(audiosink
))
864 g_object_unref(audiosink
);
871 bool wxGStreamerMediaBackend::TryVideoSink(GstElement
* videosink
)
873 // Check if the video sink either is an xoverlay or might contain one...
874 if( !GST_IS_BIN(videosink
) && !GST_IS_X_OVERLAY(videosink
) )
876 if(G_IS_OBJECT(videosink
))
877 g_object_unref(videosink
);
881 // Make our video sink and make sure it supports the x overlay interface
882 // the x overlay enables us to put the video in our control window
883 // (i.e. we NEED it!) - also connect to the natural video size change event
884 if( GST_IS_BIN(videosink
) )
885 m_xoverlay
= (GstXOverlay
*)
886 gst_bin_get_by_interface (GST_BIN (videosink
),
889 m_xoverlay
= (GstXOverlay
*) videosink
;
891 if ( !GST_IS_X_OVERLAY(m_xoverlay
) )
893 g_object_unref(videosink
);
900 //-----------------------------------------------------------------------------
901 // wxGStreamerMediaEventHandler::OnMediaFinish
903 // Called when the media is about to stop
904 //-----------------------------------------------------------------------------
905 void wxGStreamerMediaEventHandler::OnMediaFinish(wxMediaEvent
& WXUNUSED(event
))
907 // (RN - I have no idea why I thought this was good behaviour....
908 // maybe it made sense for streaming/nonseeking data but
909 // generally it seems like a really bad idea) -
910 if(m_be
->SendStopEvent())
912 // Stop the media (we need to set it back to paused
913 // so that people can get the duration et al.
914 // and send the finish event (luckily we can "Sync" it out... LOL!)
915 // (We don't check return values here because we can't really do
917 wxMutexLocker
lock(m_be
->m_asynclock
);
919 // Set element to ready+sync it
920 gst_element_set_state (m_be
->m_playbin
, GST_STATE_READY
);
921 m_be
->SyncStateChange(m_be
->m_playbin
, GST_STATE_READY
);
923 // Now set it to paused + update pause pos to 0 and
924 // Sync that as well (note that we don't call Stop() here
925 // due to mutex issues)
926 gst_element_set_state (m_be
->m_playbin
, GST_STATE_PAUSED
);
927 m_be
->SyncStateChange(m_be
->m_playbin
, GST_STATE_PAUSED
);
928 m_be
->m_llPausedPos
= 0;
930 // Finally, queue the finish event
931 m_be
->QueueFinishEvent();
935 //-----------------------------------------------------------------------------
939 //-----------------------------------------------------------------------------
941 //-----------------------------------------------------------------------------
942 // wxGStreamerMediaBackend Constructor
944 // Sets m_playbin to NULL signifying we havn't loaded anything yet
945 //-----------------------------------------------------------------------------
946 wxGStreamerMediaBackend::wxGStreamerMediaBackend()
952 //-----------------------------------------------------------------------------
953 // wxGStreamerMediaBackend Destructor
955 // Stops/cleans up memory
957 // NB: This could trigger a critical warning but doing a SyncStateChange
958 // here is just going to slow down quitting of the app, which is bad.
959 //-----------------------------------------------------------------------------
960 wxGStreamerMediaBackend::~wxGStreamerMediaBackend()
962 // Dispose of the main player and related objects
965 wxASSERT( GST_IS_OBJECT(m_playbin
) );
966 gst_element_set_state (m_playbin
, GST_STATE_NULL
);
967 gst_object_unref (GST_OBJECT (m_playbin
));
968 delete m_eventHandler
;
972 //-----------------------------------------------------------------------------
973 // wxGStreamerMediaBackend::CreateControl
975 // Initializes GStreamer and creates the wx side of our media control
976 //-----------------------------------------------------------------------------
977 bool wxGStreamerMediaBackend::CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
982 const wxValidator
& validator
,
983 const wxString
& name
)
989 //Convert arguments to unicode if enabled
992 char **argvGST
= new char*[wxTheApp
->argc
+ 1];
993 for ( i
= 0; i
< wxTheApp
->argc
; i
++ )
995 argvGST
[i
] = wxStrdupA(wxTheApp
->argv
[i
].utf8_str());
998 argvGST
[wxTheApp
->argc
] = NULL
;
1000 int argcGST
= wxTheApp
->argc
;
1002 #define argcGST wxTheApp->argc
1003 #define argvGST wxTheApp->argv
1006 //Really init gstreamer
1008 GError
* error
= NULL
;
1009 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
1010 bInited
= gst_init_check(&argcGST
, &argvGST
, &error
);
1012 bInited
= gst_init_check(&argcGST
, &argvGST
);
1015 // Cleanup arguments for unicode case
1017 for ( i
= 0; i
< argcGST
; i
++ )
1025 if(!bInited
) //gst_init_check fail?
1029 wxLogSysError(wxT("Could not initialize GStreamer\n")
1030 wxT("Error Message:%s"),
1031 (const wxChar
*) wxConvUTF8
.cMB2WX(error
->message
)
1033 g_error_free(error
);
1036 wxLogSysError(wxT("Could not initialize GStreamer"));
1042 // wxControl creation
1044 m_ctrl
= wxStaticCast(ctrl
, wxMediaCtrl
);
1047 // We handle our own GTK expose events
1048 m_ctrl
->m_noExpose
= true;
1051 if( !m_ctrl
->wxControl::Create(parent
, id
, pos
, size
,
1052 style
, // TODO: remove borders???
1055 wxFAIL_MSG(wxT("Could not create wxControl!!!"));
1060 // Turn off double-buffering so that
1061 // so it doesn't draw over the video and cause sporadic
1062 // disappearances of the video
1063 gtk_widget_set_double_buffered(m_ctrl
->m_wxwindow
, FALSE
);
1066 // don't erase the background of our control window
1067 // so that resizing is a bit smoother
1068 m_ctrl
->SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1070 // Create our playbin object
1071 m_playbin
= gst_element_factory_make ("playbin", "play");
1072 if (!GST_IS_ELEMENT(m_playbin
))
1074 if(G_IS_OBJECT(m_playbin
))
1075 g_object_unref(m_playbin
);
1076 wxLogSysError(wxT("Got an invalid playbin"));
1080 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR < 10
1081 // Connect the glib events/callbacks we want to our playbin
1082 g_signal_connect(m_playbin
, "eos",
1083 G_CALLBACK(gst_finish_callback
), this);
1084 g_signal_connect(m_playbin
, "error",
1085 G_CALLBACK(gst_error_callback
), this);
1086 g_signal_connect(m_playbin
, "state-change",
1087 G_CALLBACK(gst_state_change_callback
), this);
1089 // GStreamer 0.10+ uses GstBus for this now, connect to the sync
1090 // handler as well so we can set the X window id of our xoverlay
1091 gst_bus_add_watch (gst_element_get_bus(m_playbin
),
1092 (GstBusFunc
) gst_bus_async_callback
, this);
1093 gst_bus_set_sync_handler(gst_element_get_bus(m_playbin
),
1094 (GstBusSyncHandler
) gst_bus_sync_callback
, this);
1095 g_signal_connect(m_playbin
, "notify::stream-info",
1096 G_CALLBACK(gst_notify_stream_info_callback
), this);
1099 // Get the audio sink
1100 GstElement
* audiosink
= gst_gconf_get_default_audio_sink();
1101 if( !TryAudioSink(audiosink
) )
1103 // fallback to autodetection, then alsa, then oss as a stopgap
1104 audiosink
= gst_element_factory_make ("autoaudiosink", "audio-sink");
1105 if( !TryAudioSink(audiosink
) )
1107 audiosink
= gst_element_factory_make ("alsasink", "alsa-output");
1108 if( !TryAudioSink(audiosink
) )
1110 audiosink
= gst_element_factory_make ("osssink", "play_audio");
1111 if( !TryAudioSink(audiosink
) )
1113 wxLogSysError(wxT("Could not find a valid audiosink"));
1120 // Setup video sink - first try gconf, then auto, then xvimage and
1121 // then finally plain ximage
1122 GstElement
* videosink
= gst_gconf_get_default_video_sink();
1123 if( !TryVideoSink(videosink
) )
1125 videosink
= gst_element_factory_make ("autovideosink", "video-sink");
1126 if( !TryVideoSink(videosink
) )
1128 videosink
= gst_element_factory_make ("xvimagesink", "video-sink");
1129 if( !TryVideoSink(videosink
) )
1131 // finally, do a final fallback to ximagesink
1133 gst_element_factory_make ("ximagesink", "video-sink");
1134 if( !TryVideoSink(videosink
) )
1136 g_object_unref(audiosink
);
1137 wxLogSysError(wxT("Could not find a suitable video sink"));
1144 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR < 10
1145 // Not on 0.10... called when video size changes
1146 g_signal_connect(m_xoverlay
, "desired-size-changed",
1147 G_CALLBACK(gst_desired_size_changed_callback
), this);
1149 // Tell GStreamer which window to draw to in 0.8 - 0.10
1150 // sometimes needs this too...
1153 // Now that we know (or, rather think) our video and audio sink
1154 // are valid set our playbin to use them
1155 g_object_set (G_OBJECT (m_playbin
),
1156 "video-sink", videosink
,
1157 "audio-sink", audiosink
,
1160 m_eventHandler
= new wxGStreamerMediaEventHandler(this);
1164 //-----------------------------------------------------------------------------
1165 // wxGStreamerMediaBackend::Load (File version)
1167 // Just calls DoLoad() with a prepended file scheme
1168 //-----------------------------------------------------------------------------
1169 bool wxGStreamerMediaBackend::Load(const wxString
& fileName
)
1171 return DoLoad(wxString( wxT("file://") ) + fileName
);
1174 //-----------------------------------------------------------------------------
1175 // wxGStreamerMediaBackend::Load (URI version)
1177 // In the case of a file URI passes it unencoded -
1178 // also, as of 0.10.3 and earlier GstURI (the uri parser for gstreamer)
1179 // is sort of broken and only accepts uris with at least two slashes
1180 // after the scheme (i.e. file: == not ok, file:// == ok)
1181 //-----------------------------------------------------------------------------
1182 bool wxGStreamerMediaBackend::Load(const wxURI
& location
)
1184 if(location
.GetScheme().CmpNoCase(wxT("file")) == 0)
1186 wxString uristring
= location
.BuildUnescapedURI();
1188 //Workaround GstURI leading "//" problem and make sure it leads
1190 return DoLoad(wxString(wxT("file://")) +
1191 uristring
.Right(uristring
.length() - 5)
1195 return DoLoad(location
.BuildURI());
1198 //-----------------------------------------------------------------------------
1199 // wxGStreamerMediaBackend::DoLoad
1202 // 1) Reset member variables and set playbin back to ready state
1203 // 2) Check URI for validity and then tell the playbin to load it
1204 // 3) Set the playbin to the pause state
1206 // NB: Even after this function is over with we probably don't have the
1207 // video size or duration - no amount of clever hacking is going to get
1208 // around that, unfortunately.
1209 //-----------------------------------------------------------------------------
1210 bool wxGStreamerMediaBackend::DoLoad(const wxString
& locstring
)
1212 wxMutexLocker
lock(m_asynclock
); // lock state events and async callbacks
1214 // Reset positions & rate
1217 m_videoSize
= wxSize(0,0);
1219 // Set playbin to ready to stop the current media...
1220 if( gst_element_set_state (m_playbin
,
1221 GST_STATE_READY
) == GST_STATE_FAILURE
||
1222 !SyncStateChange(m_playbin
, GST_STATE_READY
))
1224 wxLogSysError(wxT("wxGStreamerMediaBackend::Load - ")
1225 wxT("Could not set initial state to ready"));
1229 // free current media resources
1230 gst_element_set_state (m_playbin
, GST_STATE_NULL
);
1232 // Make sure the passed URI is valid and tell playbin to load it
1233 // non-file uris are encoded
1234 wxASSERT(gst_uri_protocol_is_valid("file"));
1235 wxASSERT(gst_uri_is_valid(locstring
.mb_str()));
1237 g_object_set (G_OBJECT (m_playbin
), "uri",
1238 (const char*)locstring
.mb_str(), NULL
);
1240 // Try to pause media as gstreamer won't let us query attributes
1241 // such as video size unless it is paused or playing
1242 if( gst_element_set_state (m_playbin
,
1243 GST_STATE_PAUSED
) == GST_STATE_FAILURE
||
1244 !SyncStateChange(m_playbin
, GST_STATE_PAUSED
))
1246 return false; // no real error message needed here as this is
1247 // generic failure 99% of the time (i.e. no
1248 // source etc.) and has an error message
1252 NotifyMovieLoaded(); // Notify the user - all we can do for now
1257 //-----------------------------------------------------------------------------
1258 // wxGStreamerMediaBackend::Play
1260 // Sets the stream to a playing state
1262 // THREAD-UNSAFE in 0.8, maybe in 0.10 as well
1263 //-----------------------------------------------------------------------------
1264 bool wxGStreamerMediaBackend::Play()
1266 if (gst_element_set_state (m_playbin
,
1267 GST_STATE_PLAYING
) == GST_STATE_FAILURE
)
1272 //-----------------------------------------------------------------------------
1273 // wxGStreamerMediaBackend::Pause
1275 // Marks where we paused and pauses the stream
1277 // THREAD-UNSAFE in 0.8, maybe in 0.10 as well
1278 //-----------------------------------------------------------------------------
1279 bool wxGStreamerMediaBackend::Pause()
1281 m_llPausedPos
= wxGStreamerMediaBackend::GetPosition();
1282 if (gst_element_set_state (m_playbin
,
1283 GST_STATE_PAUSED
) == GST_STATE_FAILURE
)
1288 //-----------------------------------------------------------------------------
1289 // wxGStreamerMediaBackend::Stop
1291 // Pauses the stream and sets the position to 0. Note that this is
1292 // synchronous (!) pausing.
1294 // Due to the mutex locking this is probably thread-safe actually.
1295 //-----------------------------------------------------------------------------
1296 bool wxGStreamerMediaBackend::Stop()
1298 { // begin state lock
1299 wxMutexLocker
lock(m_asynclock
);
1300 if(gst_element_set_state (m_playbin
,
1301 GST_STATE_PAUSED
) == GST_STATE_FAILURE
||
1302 !SyncStateChange(m_playbin
, GST_STATE_PAUSED
))
1304 wxLogSysError(wxT("Could not set state to paused for Stop()"));
1309 bool bSeekedOK
= wxGStreamerMediaBackend::SetPosition(0);
1313 wxLogSysError(wxT("Could not seek to initial position in Stop()"));
1317 QueueStopEvent(); // Success
1321 //-----------------------------------------------------------------------------
1322 // wxGStreamerMediaBackend::GetState
1324 // Gets the state of the media
1325 //-----------------------------------------------------------------------------
1326 wxMediaState
wxGStreamerMediaBackend::GetState()
1328 switch(GST_STATE(m_playbin
))
1330 case GST_STATE_PLAYING
:
1331 return wxMEDIASTATE_PLAYING
;
1332 case GST_STATE_PAUSED
:
1333 if (m_llPausedPos
== 0)
1334 return wxMEDIASTATE_STOPPED
;
1336 return wxMEDIASTATE_PAUSED
;
1337 default://case GST_STATE_READY:
1338 return wxMEDIASTATE_STOPPED
;
1342 //-----------------------------------------------------------------------------
1343 // wxGStreamerMediaBackend::GetPosition
1345 // If paused, returns our marked position - otherwise it queries the
1346 // GStreamer playbin for the position and returns that
1349 // NB: At least in 0.8, when you pause and seek gstreamer
1350 // NB: doesn't update the position sometimes, so we need to keep track of
1351 // NB: whether we have paused or not and keep track of the time after the
1352 // NB: pause and whenever the user seeks while paused
1355 // THREAD-UNSAFE, at least if not paused. Requires media to be at least paused.
1356 //-----------------------------------------------------------------------------
1357 wxLongLong
wxGStreamerMediaBackend::GetPosition()
1359 if(GetState() != wxMEDIASTATE_PLAYING
)
1360 return m_llPausedPos
;
1364 GstFormat fmtTime
= GST_FORMAT_TIME
;
1366 if (!wxGst_element_query_position(m_playbin
, &fmtTime
, &pos
) ||
1367 fmtTime
!= GST_FORMAT_TIME
|| pos
== -1)
1369 return pos
/ GST_MSECOND
;
1373 //-----------------------------------------------------------------------------
1374 // wxGStreamerMediaBackend::SetPosition
1376 // Sets the position of the stream
1377 // Note that GST_MSECOND is 1000000 (GStreamer uses nanoseconds - so
1378 // there is 1000000 nanoseconds in a millisecond)
1380 // If we are paused we update the cached pause position.
1382 // This is also an exceedingly ugly function due to the three implementations
1383 // (or, rather two plus one implementation without a seek function).
1385 // This is asynchronous and thread-safe on both 0.8 and 0.10.
1387 // NB: This fires both a stop and play event if the media was previously
1388 // playing... which in some ways makes sense. And yes, this makes the video
1389 // go all haywire at times - a gstreamer bug...
1390 //-----------------------------------------------------------------------------
1391 bool wxGStreamerMediaBackend::SetPosition(wxLongLong where
)
1393 #if GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR == 8 \
1394 && GST_VERSION_MICRO == 0
1395 // 0.8.0 has no gst_element_seek according to official docs!!!
1396 wxLogSysError(wxT("GStreamer 0.8.0 does not have gst_element_seek")
1397 wxT(" according to official docs"));
1401 # if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
1402 gst_element_seek (m_playbin
, m_dRate
, GST_FORMAT_TIME
,
1403 (GstSeekFlags
)(GST_SEEK_FLAG_FLUSH
| GST_SEEK_FLAG_KEY_UNIT
),
1404 GST_SEEK_TYPE_SET
, where
.GetValue() * GST_MSECOND
,
1405 GST_SEEK_TYPE_NONE
, GST_CLOCK_TIME_NONE
);
1407 // NB: Some gstreamer versions return false basically all the time
1408 // here - even totem doesn't bother to check the return value here
1409 // so I guess we'll just assume it worked -
1410 // TODO: maybe check the gst error callback???
1411 gst_element_seek (m_playbin
, (GstSeekType
) (GST_SEEK_METHOD_SET
|
1412 GST_FORMAT_TIME
| GST_SEEK_FLAG_FLUSH
),
1413 where
.GetValue() * GST_MSECOND
);
1415 # endif // GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
1418 m_llPausedPos
= where
;
1425 //-----------------------------------------------------------------------------
1426 // wxGStreamerMediaBackend::GetDuration
1428 // Obtains the total time of our stream
1429 // THREAD-UNSAFE, requires media to be paused or playing
1430 //-----------------------------------------------------------------------------
1431 wxLongLong
wxGStreamerMediaBackend::GetDuration()
1434 GstFormat fmtTime
= GST_FORMAT_TIME
;
1436 if(!wxGst_element_query_duration(m_playbin
, &fmtTime
, &length
) ||
1437 fmtTime
!= GST_FORMAT_TIME
|| length
== -1)
1439 return length
/ GST_MSECOND
;
1442 //-----------------------------------------------------------------------------
1443 // wxGStreamerMediaBackend::Move
1445 // Called when the window is moved - GStreamer takes care of this
1446 // for us so nothing is needed
1447 //-----------------------------------------------------------------------------
1448 void wxGStreamerMediaBackend::Move(int WXUNUSED(x
),
1455 //-----------------------------------------------------------------------------
1456 // wxGStreamerMediaBackend::GetVideoSize
1458 // Returns our cached video size from Load/gst_notify_caps_callback
1459 // gst_x_overlay_get_desired_size also does this in 0.8...
1460 //-----------------------------------------------------------------------------
1461 wxSize
wxGStreamerMediaBackend::GetVideoSize() const
1466 //-----------------------------------------------------------------------------
1467 // wxGStreamerMediaBackend::GetPlaybackRate
1468 // wxGStreamerMediaBackend::SetPlaybackRate
1470 // Obtains/Sets the playback rate of the stream
1472 //TODO: PlaybackRate not currently supported via playbin directly -
1473 //TODO: Ronald S. Bultje noted on gstreamer-devel:
1475 //TODO: Like "play at twice normal speed"? Or "play at 25 fps and 44,1 kHz"? As
1476 //TODO: for the first, yes, we have elements for that, btu they"re not part of
1477 //TODO: playbin. You can create a bin (with a ghost pad) containing the actual
1478 //TODO: video/audiosink and the speed-changing element for this, and set that
1479 //TODO: element as video-sink or audio-sink property in playbin. The
1480 //TODO: audio-element is called "speed", the video-element is called "videodrop"
1481 //TODO: (although that appears to be deprecated in favour of "videorate", which
1482 //TODO: again cannot do this, so this may not work at all in the end). For
1483 //TODO: forcing frame/samplerates, see audioscale and videorate. Audioscale is
1484 //TODO: part of playbin.
1486 // In 0.10 GStreamer has new gst_element_seek API that might
1487 // support this - and I've got an attempt to do so but it is untested
1488 // but it would appear to work...
1489 //-----------------------------------------------------------------------------
1490 double wxGStreamerMediaBackend::GetPlaybackRate()
1492 return m_dRate
; // Could use GST_QUERY_RATE but the API doesn't seem
1493 // final on that yet and there may not be any actual
1494 // plugins that support it...
1497 bool wxGStreamerMediaBackend::SetPlaybackRate(double dRate
)
1499 #if GST_VERSION_MAJOR > 0 || GST_VERSION_MINOR >= 10
1500 #if 0 // not tested enough
1501 if( gst_element_seek (m_playbin
, dRate
, GST_FORMAT_TIME
,
1502 (GstSeekFlags
)(GST_SEEK_FLAG_FLUSH
| GST_SEEK_FLAG_KEY_UNIT
),
1503 GST_SEEK_TYPE_CUR
, 0,
1504 GST_SEEK_TYPE_NONE
, GST_CLOCK_TIME_NONE
) )
1518 //-----------------------------------------------------------------------------
1519 // wxGStreamerMediaBackend::GetDownloadProgress
1521 // Not really outwardly possible - have been suggested that one could
1522 // get the information from the component that "downloads"
1523 //-----------------------------------------------------------------------------
1524 wxLongLong
wxGStreamerMediaBackend::GetDownloadProgress()
1529 //-----------------------------------------------------------------------------
1530 // wxGStreamerMediaBackend::GetDownloadTotal
1532 // TODO: Cache this?
1533 // NB: The length changes every call for some reason due to
1534 // GStreamer implementation issues
1535 // THREAD-UNSAFE, requires media to be paused or playing
1536 //-----------------------------------------------------------------------------
1537 wxLongLong
wxGStreamerMediaBackend::GetDownloadTotal()
1540 GstFormat fmtBytes
= GST_FORMAT_BYTES
;
1542 if (!wxGst_element_query_duration(m_playbin
, &fmtBytes
, &length
) ||
1543 fmtBytes
!= GST_FORMAT_BYTES
|| length
== -1)
1548 //-----------------------------------------------------------------------------
1549 // wxGStreamerMediaBackend::SetVolume
1550 // wxGStreamerMediaBackend::GetVolume
1552 // Sets/Gets the volume through the playbin object.
1553 // Note that this requires a relatively recent gst-plugins so we
1554 // check at runtime to see whether it is available or not otherwise
1555 // GST spits out an error on the command line
1556 //-----------------------------------------------------------------------------
1557 bool wxGStreamerMediaBackend::SetVolume(double dVolume
)
1559 if(g_object_class_find_property(
1560 G_OBJECT_GET_CLASS(G_OBJECT(m_playbin
)),
1563 g_object_set(G_OBJECT(m_playbin
), "volume", dVolume
, NULL
);
1568 wxLogTrace(wxTRACE_GStreamer
,
1569 wxT("SetVolume: volume prop not found - 0.8.5 of ")
1570 wxT("gst-plugins probably needed"));
1575 double wxGStreamerMediaBackend::GetVolume()
1577 double dVolume
= 1.0;
1579 if(g_object_class_find_property(
1580 G_OBJECT_GET_CLASS(G_OBJECT(m_playbin
)),
1583 g_object_get(G_OBJECT(m_playbin
), "volume", &dVolume
, NULL
);
1587 wxLogTrace(wxTRACE_GStreamer
,
1588 wxT("GetVolume: volume prop not found - 0.8.5 of ")
1589 wxT("gst-plugins probably needed"));
1595 #endif //wxUSE_GSTREAMER
1597 // Force link into main library so this backend can be loaded
1598 #include "wx/html/forcelnk.h"
1599 FORCE_LINK_ME(basewxmediabackends
)
1601 #endif //wxUSE_MEDIACTRL