wxMediaCtrl unix port with gstreamer usable version :)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31888 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -60,12 +60,21 @@
|
|||||||
#include <string.h> //strstr
|
#include <string.h> //strstr
|
||||||
|
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
|
#include "wx/msgdlg.h"
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
//for <gdk/gdkx.h>/related for GDK_WINDOW_XWINDOW
|
//for <gdk/gdkx.h>/related for GDK_WINDOW_XWINDOW
|
||||||
# include "wx/gtk/win_gtk.h"
|
# include "wx/gtk/win_gtk.h"
|
||||||
|
# include <gtk/gtksignal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//FIXME:
|
||||||
|
//FIXME: This is really not the best way to play-stop -
|
||||||
|
//FIXME: it should just have one playbin and stick with it the whole
|
||||||
|
//FIXME: instance of wxGStreamerMediaBackend - but stopping appears
|
||||||
|
//FIXME: to invalidate the playbin object...
|
||||||
|
//FIXME:
|
||||||
|
|
||||||
class WXDLLIMPEXP_MEDIA wxGStreamerMediaBackend : public wxMediaBackend
|
class WXDLLIMPEXP_MEDIA wxGStreamerMediaBackend : public wxMediaBackend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -106,10 +115,29 @@ public:
|
|||||||
static void OnError (GstElement *play, GstElement *src,
|
static void OnError (GstElement *play, GstElement *src,
|
||||||
GError *err, gchar *debug,
|
GError *err, gchar *debug,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
static void OnVideoCapsReady(GstPad* pad, GParamSpec* pspec, gpointer data);
|
||||||
|
|
||||||
|
static bool TransCapsToVideoSize(wxGStreamerMediaBackend* be, GstPad* caps);
|
||||||
|
void PostRecalcSize();
|
||||||
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
static gint OnGTKRealize(GtkWidget* theWidget, wxGStreamerMediaBackend* be);
|
||||||
|
#endif
|
||||||
|
|
||||||
GstElement* m_player; //GStreamer media element
|
GstElement* m_player; //GStreamer media element
|
||||||
GstElement* m_audiosink;
|
GstElement* m_audiosink;
|
||||||
GstElement* m_videosink;
|
GstElement* m_videosink;
|
||||||
|
|
||||||
|
wxSize m_videoSize;
|
||||||
|
wxControl* m_ctrl;
|
||||||
|
|
||||||
|
//FIXME:
|
||||||
|
//FIXME: In lue of the last big FIXME, when you pause and seek gstreamer
|
||||||
|
//FIXME: doesn't update the position sometimes, so we need to keep track of whether
|
||||||
|
//FIXME: we have paused or not and keep track of the time after the pause
|
||||||
|
//FIXME: and whenever the user seeks while paused
|
||||||
|
//FIXME:
|
||||||
|
wxLongLong m_nPausedPos;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxGStreamerMediaBackend);
|
DECLARE_DYNAMIC_CLASS(wxGStreamerMediaBackend);
|
||||||
};
|
};
|
||||||
@@ -123,16 +151,67 @@ public:
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGStreamerMediaBackend, wxMediaBackend);
|
IMPLEMENT_DYNAMIC_CLASS(wxGStreamerMediaBackend, wxMediaBackend);
|
||||||
|
|
||||||
wxGStreamerMediaBackend::wxGStreamerMediaBackend()
|
wxGStreamerMediaBackend::wxGStreamerMediaBackend() : m_player(NULL), m_videoSize(0,0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGStreamerMediaBackend::~wxGStreamerMediaBackend()
|
wxGStreamerMediaBackend::~wxGStreamerMediaBackend()
|
||||||
{
|
{
|
||||||
gst_element_set_state (m_player, GST_STATE_NULL);
|
Cleanup();
|
||||||
gst_object_unref (GST_OBJECT (m_player));
|
}
|
||||||
gst_object_unref (GST_OBJECT (m_videosink));
|
|
||||||
gst_object_unref (GST_OBJECT (m_audiosink));
|
#ifdef __WXGTK__
|
||||||
|
|
||||||
|
#ifdef __WXDEBUG__
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
|
# define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
|
||||||
|
#else
|
||||||
|
# define DEBUG_MAIN_THREAD
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DEBUG_MAIN_THREAD
|
||||||
|
#endif // Debug
|
||||||
|
|
||||||
|
extern void wxapp_install_idle_handler();
|
||||||
|
extern bool g_isIdle;
|
||||||
|
extern bool g_mainThreadLocked;
|
||||||
|
|
||||||
|
gint wxGStreamerMediaBackend::OnGTKRealize(GtkWidget* theWidget,
|
||||||
|
wxGStreamerMediaBackend* be)
|
||||||
|
{
|
||||||
|
DEBUG_MAIN_THREAD
|
||||||
|
|
||||||
|
if (g_isIdle)
|
||||||
|
wxapp_install_idle_handler();
|
||||||
|
|
||||||
|
wxYield(); //X Server gets an error if I don't do this or a messagebox beforehand?!?!??
|
||||||
|
|
||||||
|
GdkWindow *window = GTK_PIZZA(theWidget)->bin_window;
|
||||||
|
wxASSERT(window);
|
||||||
|
|
||||||
|
gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(be->m_videosink),
|
||||||
|
GDK_WINDOW_XWINDOW( window )
|
||||||
|
);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void wxGStreamerMediaBackend::Cleanup()
|
||||||
|
{
|
||||||
|
if(m_player && GST_IS_OBJECT(m_player))
|
||||||
|
{
|
||||||
|
// wxASSERT(GST_IS_OBJECT(m_audiosink));
|
||||||
|
// wxASSERT(GST_IS_OBJECT(m_videosink));
|
||||||
|
|
||||||
|
gst_element_set_state (m_player, GST_STATE_NULL);
|
||||||
|
gst_object_unref (GST_OBJECT (m_player));
|
||||||
|
//gst_object_unref (GST_OBJECT (m_videosink));
|
||||||
|
//gst_object_unref (GST_OBJECT (m_audiosink));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
|
bool wxGStreamerMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
|
||||||
@@ -145,45 +224,57 @@ bool wxGStreamerMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
|
|||||||
{
|
{
|
||||||
//init gstreamer
|
//init gstreamer
|
||||||
gst_init(NULL, NULL);
|
gst_init(NULL, NULL);
|
||||||
|
|
||||||
|
m_ctrl = ctrl;
|
||||||
|
|
||||||
//
|
return m_ctrl->wxControl::Create(parent, id, pos, size,
|
||||||
// Create window
|
|
||||||
// By default wxWindow(s) is created with a border -
|
|
||||||
// so we need to get rid of those return Load(
|
|
||||||
//
|
|
||||||
// Since we don't have a child window like most other
|
|
||||||
// backends, we don't need wxCLIP_CHILDREN
|
|
||||||
//
|
|
||||||
if ( !
|
|
||||||
ctrl->wxControl::Create(parent, id, pos, size,
|
|
||||||
style, //remove borders???
|
style, //remove borders???
|
||||||
validator, name)
|
validator, name);
|
||||||
)
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
m_player = gst_element_factory_make ("playbin", "play");
|
bool wxGStreamerMediaBackend::TransCapsToVideoSize(wxGStreamerMediaBackend* be, GstPad* pad)
|
||||||
m_audiosink = gst_element_factory_make ("alsasink", "audiosink");
|
{
|
||||||
m_videosink = gst_element_factory_make ("xvimagesink", "videosink");
|
const GstCaps* caps = GST_PAD_CAPS (pad);
|
||||||
|
if(caps)
|
||||||
|
{
|
||||||
|
|
||||||
g_object_set (G_OBJECT (m_player),
|
const GstStructure *s;
|
||||||
"video-sink", m_videosink,
|
s = gst_caps_get_structure (caps, 0);
|
||||||
"audio-sink", m_audiosink,
|
wxASSERT(s);
|
||||||
NULL);
|
|
||||||
|
|
||||||
g_signal_connect (m_player, "eos", G_CALLBACK (OnError), this);
|
gst_structure_get_int (s, "width", &be->m_videoSize.x);
|
||||||
g_signal_connect (m_player, "error", G_CALLBACK (OnFinish), this);
|
gst_structure_get_int (s, "height", &be->m_videoSize.y);
|
||||||
|
|
||||||
if ( ! GST_IS_X_OVERLAY(m_videosink) )
|
const GValue *par;
|
||||||
return false;
|
par = gst_structure_get_value (s, "pixel-aspect-ratio");
|
||||||
|
|
||||||
gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(m_videosink),
|
if (par)
|
||||||
#ifdef __WXGTK__
|
{
|
||||||
GDK_WINDOW_XWINDOW(ctrl->GetHandle())
|
int num = gst_value_get_fraction_numerator (par),
|
||||||
#else
|
den = gst_value_get_fraction_denominator (par);
|
||||||
ctrl->GetHandle()
|
|
||||||
#endif
|
//TODO: maybe better fraction normalization...
|
||||||
);
|
if (num > den)
|
||||||
return true;
|
be->m_videoSize.x = (int) ((float) num * be->m_videoSize.x / den);
|
||||||
|
else
|
||||||
|
be->m_videoSize.y = (int) ((float) den * be->m_videoSize.y / num);
|
||||||
|
}
|
||||||
|
|
||||||
|
be->PostRecalcSize();
|
||||||
|
return true;
|
||||||
|
}//end if caps
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//forces parent to recalc its layout if it has sizers to update
|
||||||
|
//to the new video size
|
||||||
|
void wxGStreamerMediaBackend::PostRecalcSize()
|
||||||
|
{
|
||||||
|
m_ctrl->InvalidateBestSize();
|
||||||
|
m_ctrl->GetParent()->Layout();
|
||||||
|
m_ctrl->GetParent()->Refresh();
|
||||||
|
m_ctrl->GetParent()->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGStreamerMediaBackend::OnFinish(GstElement *play, gpointer data)
|
void wxGStreamerMediaBackend::OnFinish(GstElement *play, gpointer data)
|
||||||
@@ -212,109 +303,97 @@ void wxGStreamerMediaBackend::OnError(GstElement *play,
|
|||||||
gchar *debug,
|
gchar *debug,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
wxLogSysError(wxString::Format(wxT("Error in GStreamer Playback!\nError Message:%s"), wxString(err->message).c_str()));
|
wxMessageBox(wxString::Format(wxT("Error in wxMediaCtrl!\nError Message:%s"), wxString(err->message, wxConvLocal).c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::Load(const wxString& fileName)
|
bool wxGStreamerMediaBackend::Load(const wxString& fileName)
|
||||||
{
|
{
|
||||||
return Load(
|
return Load(
|
||||||
wxURI(
|
wxURI(
|
||||||
wxString( wxT("file://") ) + fileName
|
wxString( wxT("file://") ) + fileName
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGStreamerMediaBackend::OnVideoCapsReady(GstPad* pad, GParamSpec* pspec, gpointer data)
|
||||||
|
{
|
||||||
|
wxGStreamerMediaBackend::TransCapsToVideoSize((wxGStreamerMediaBackend*) data, pad);
|
||||||
|
}
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::Load(const wxURI& location)
|
bool wxGStreamerMediaBackend::Load(const wxURI& location)
|
||||||
{
|
{
|
||||||
Cleanup();
|
Cleanup();
|
||||||
wxString locstring = location.BuildURI();
|
|
||||||
|
m_player = gst_element_factory_make ("playbin", "play");
|
||||||
|
m_audiosink = gst_element_factory_make ("alsasink", "audiosink");
|
||||||
|
m_videosink = gst_element_factory_make ("xvimagesink", "videosink");
|
||||||
|
|
||||||
|
//no playbin -- outta here :)
|
||||||
if ( GST_STATE(m_player) > GST_STATE_READY )
|
if (!m_player)
|
||||||
gst_element_set_state(m_player, GST_STATE_READY);
|
|
||||||
|
|
||||||
g_object_set (G_OBJECT (m_player), "uri", locstring.c_str(), NULL);
|
|
||||||
|
|
||||||
gst_x_overlay_expose(GST_X_OVERLAY(m_videosink));
|
|
||||||
|
|
||||||
return GST_STATE(m_player) == GST_STATE_READY;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::Play()
|
|
||||||
{
|
|
||||||
if (gst_element_set_state (m_player, GST_STATE_PLAYING)
|
|
||||||
!= GST_STATE_SUCCESS)
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
//have alsa?
|
||||||
|
if (GST_IS_OBJECT(m_audiosink) == false)
|
||||||
bool wxGStreamerMediaBackend::Pause()
|
|
||||||
{
|
|
||||||
if (gst_element_set_state (m_player, GST_STATE_PAUSED)
|
|
||||||
!= GST_STATE_SUCCESS)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::Stop()
|
|
||||||
{
|
|
||||||
if (gst_element_set_state (m_player,
|
|
||||||
GST_STATE_READY) != GST_STATE_SUCCESS)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMediaState wxGStreamerMediaBackend::GetState()
|
|
||||||
{
|
|
||||||
switch(GST_STATE(m_player))
|
|
||||||
{
|
{
|
||||||
case GST_STATE_PLAYING:
|
//nope, try OSS
|
||||||
return wxMEDIASTATE_PLAYING;
|
m_audiosink = gst_element_factory_make ("osssink", "audiosink");
|
||||||
case GST_STATE_PAUSED:
|
wxASSERT_MSG(GST_IS_OBJECT(m_audiosink), wxT("WARNING: Alsa and OSS drivers for gstreamer not found - audio will be unavailable for wxMediaCtrl"));
|
||||||
return wxMEDIASTATE_PAUSED;
|
|
||||||
default://case GST_STATE_READY:
|
|
||||||
return wxMEDIASTATE_STOPPED;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
wxASSERT_MSG(GST_IS_OBJECT(m_videosink), wxT("WARNING: No X video driver for gstreamer not found - video will be unavailable for wxMediaCtrl"));
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::SetPosition(wxLongLong where)
|
g_object_set (G_OBJECT (m_player),
|
||||||
{
|
"video-sink", m_videosink,
|
||||||
return gst_element_seek (play, (GstSeekType) (GST_SEEK_METHOD_SET |
|
"audio-sink", m_audiosink,
|
||||||
GST_FORMAT_TIME | GST_SEEK_FLAG_FLUSH),
|
NULL);
|
||||||
where * GST_MSECOND );
|
|
||||||
}
|
|
||||||
|
|
||||||
wxLongLong wxGStreamerMediaBackend::GetPosition()
|
g_signal_connect (m_player, "eos", G_CALLBACK (OnError), this);
|
||||||
{
|
g_signal_connect (m_player, "error", G_CALLBACK (OnFinish), this);
|
||||||
gint64 pos;
|
|
||||||
GstFormat fmtTime = GST_FORMAT_TIME;
|
|
||||||
|
|
||||||
if (!gst_element_query (play, GST_QUERY_POSITION, &fmtTime, &pos))
|
wxASSERT( GST_IS_X_OVERLAY(m_videosink) );
|
||||||
return 0;
|
if ( ! GST_IS_X_OVERLAY(m_videosink) )
|
||||||
return pos / GST_MSECOND ;
|
return false;
|
||||||
}
|
|
||||||
|
wxString locstring = location.BuildUnescapedURI();
|
||||||
|
wxASSERT(gst_uri_protocol_is_valid("file"));
|
||||||
|
wxASSERT(gst_uri_is_valid(locstring.mb_str()));
|
||||||
|
|
||||||
wxLongLong wxGStreamerMediaBackend::GetDuration()
|
g_object_set (G_OBJECT (m_player), "uri", (const char*)locstring.mb_str(), NULL);
|
||||||
{
|
|
||||||
gint64 length;
|
#ifdef __WXGTK__
|
||||||
GstFormat fmtTime = GST_FORMAT_TIME;
|
if(!GTK_WIDGET_REALIZED(m_ctrl->m_wxwindow))
|
||||||
|
{
|
||||||
|
//Not realized yet - set to connect at realization time
|
||||||
|
gtk_signal_connect( GTK_OBJECT(m_ctrl->m_wxwindow),
|
||||||
|
"realize",
|
||||||
|
GTK_SIGNAL_FUNC(wxGStreamerMediaBackend::OnGTKRealize),
|
||||||
|
(gpointer) this );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxYield(); //see realize callback...
|
||||||
|
GdkWindow *window = GTK_PIZZA(m_ctrl->m_wxwindow)->bin_window;
|
||||||
|
wxASSERT(window);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!gst_element_query(m_player, GST_QUERY_TOTAL, &fmtTime, &length))
|
|
||||||
return 0;
|
gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(m_videosink),
|
||||||
return length / GST_MSECOND ;
|
#ifdef __WXGTK__
|
||||||
}
|
GDK_WINDOW_XWINDOW( window )
|
||||||
|
#else
|
||||||
|
ctrl->GetHandle()
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
void wxGStreamerMediaBackend::Move(int x, int y, int w, int h)
|
#ifdef __WXGTK__
|
||||||
{
|
} //end else block
|
||||||
}
|
#endif
|
||||||
|
|
||||||
wxSize wxGStreamerMediaBackend::GetVideoSize() const
|
|
||||||
{
|
|
||||||
//TODO: check state
|
|
||||||
//TODO: maybe cache size
|
|
||||||
wxSize retSize = wxSize(0,0);
|
|
||||||
|
|
||||||
|
wxASSERT(gst_element_set_state (m_player,
|
||||||
|
GST_STATE_PAUSED) == GST_STATE_SUCCESS);
|
||||||
|
|
||||||
const GList *list = NULL;
|
const GList *list = NULL;
|
||||||
g_object_get (G_OBJECT (m_player), "stream-info", &list, NULL);
|
g_object_get (G_OBJECT (m_player), "stream-info", &list, NULL);
|
||||||
|
|
||||||
@@ -333,52 +412,158 @@ wxSize wxGStreamerMediaBackend::GetVideoSize() const
|
|||||||
|
|
||||||
if (strstr (val->value_name, "VIDEO"))
|
if (strstr (val->value_name, "VIDEO"))
|
||||||
{
|
{
|
||||||
g_object_get (info, "object", &pad, NULL);
|
//Newer gstreamer 0.8+ is SUPPOSED to have "object"...
|
||||||
|
//but a lot of old plugins still use "pad" :)
|
||||||
|
pspec = g_object_class_find_property (
|
||||||
|
G_OBJECT_GET_CLASS (info), "object");
|
||||||
|
|
||||||
|
if (!pspec)
|
||||||
|
g_object_get (info, "pad", &pad, NULL);
|
||||||
|
else
|
||||||
|
g_object_get (info, "object", &pad, NULL);
|
||||||
|
|
||||||
pad = (GstPad *) GST_PAD_REALIZE (pad);
|
pad = (GstPad *) GST_PAD_REALIZE (pad);
|
||||||
wxAssert(pad);
|
wxASSERT(pad);
|
||||||
|
|
||||||
GstCaps* caps = GST_PAD_CAPS (pad);
|
if(!wxGStreamerMediaBackend::TransCapsToVideoSize(this, pad));
|
||||||
wxAssert(caps);
|
|
||||||
|
|
||||||
const GstStructure *s;
|
|
||||||
s = gst_caps_get_structure (caps, 0);
|
|
||||||
wxAssert(s);
|
|
||||||
|
|
||||||
gst_structure_get_int (s, "width", &retSize.x);
|
|
||||||
gst_structure_get_int (s, "height", &retSize.y);
|
|
||||||
|
|
||||||
const GValue *par;
|
|
||||||
par = gst_structure_get_value (s, "pixel-aspect-ratio"));
|
|
||||||
|
|
||||||
if (par)
|
|
||||||
{
|
{
|
||||||
int num = gst_value_get_fraction_numerator (par),
|
//wait for those caps to get ready
|
||||||
den = gst_value_get_fraction_denominator (par);
|
g_signal_connect(
|
||||||
|
pad,
|
||||||
//TODO: maybe better fraction normalization...
|
"notify::caps",
|
||||||
if (num > den)
|
G_CALLBACK(wxGStreamerMediaBackend::OnVideoCapsReady),
|
||||||
retSize.x = (int) ((float) num * retSize.x / den);
|
this);
|
||||||
else
|
|
||||||
retSize.y = (int) ((float) den * retSize.y / num);
|
|
||||||
}
|
}
|
||||||
|
}//end if video
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_videoSize = wxSize(0,0);
|
||||||
|
PostRecalcSize();
|
||||||
}
|
}
|
||||||
|
}//end searching through info list
|
||||||
|
|
||||||
|
m_nPausedPos = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGStreamerMediaBackend::Play()
|
||||||
|
{
|
||||||
|
if (gst_element_set_state (m_player, GST_STATE_PLAYING)
|
||||||
|
!= GST_STATE_SUCCESS)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGStreamerMediaBackend::Pause()
|
||||||
|
{
|
||||||
|
m_nPausedPos = GetPosition();
|
||||||
|
if (gst_element_set_state (m_player, GST_STATE_PAUSED)
|
||||||
|
!= GST_STATE_SUCCESS)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGStreamerMediaBackend::Stop()
|
||||||
|
{
|
||||||
|
//FIXME: GStreamer won't update the position for getposition for some reason
|
||||||
|
//until it is played again...
|
||||||
|
if (gst_element_set_state (m_player,
|
||||||
|
GST_STATE_PAUSED) != GST_STATE_SUCCESS)
|
||||||
|
return false;
|
||||||
|
return wxGStreamerMediaBackend::SetPosition(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMediaState wxGStreamerMediaBackend::GetState()
|
||||||
|
{
|
||||||
|
switch(GST_STATE(m_player))
|
||||||
|
{
|
||||||
|
case GST_STATE_PLAYING:
|
||||||
|
return wxMEDIASTATE_PLAYING;
|
||||||
|
case GST_STATE_PAUSED:
|
||||||
|
if (m_nPausedPos == 0)
|
||||||
|
return wxMEDIASTATE_STOPPED;
|
||||||
|
else
|
||||||
|
return wxMEDIASTATE_PAUSED;
|
||||||
|
default://case GST_STATE_READY:
|
||||||
|
return wxMEDIASTATE_STOPPED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxGStreamerMediaBackend::SetPosition(wxLongLong where)
|
||||||
|
{
|
||||||
|
if( gst_element_seek (m_player, (GstSeekType) (GST_SEEK_METHOD_SET |
|
||||||
|
GST_FORMAT_TIME | GST_SEEK_FLAG_FLUSH),
|
||||||
|
where.GetValue() * GST_MSECOND ) )
|
||||||
|
{
|
||||||
|
if (GetState() != wxMEDIASTATE_PLAYING)
|
||||||
|
m_nPausedPos = where;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLongLong wxGStreamerMediaBackend::GetPosition()
|
||||||
|
{
|
||||||
|
if(GetState() != wxMEDIASTATE_PLAYING)
|
||||||
|
return m_nPausedPos;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gint64 pos;
|
||||||
|
GstFormat fmtTime = GST_FORMAT_TIME;
|
||||||
|
|
||||||
|
if (!gst_element_query (m_player, GST_QUERY_POSITION, &fmtTime, &pos))
|
||||||
|
return 0;
|
||||||
|
return pos / GST_MSECOND ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLongLong wxGStreamerMediaBackend::GetDuration()
|
||||||
|
{
|
||||||
|
gint64 length;
|
||||||
|
GstFormat fmtTime = GST_FORMAT_TIME;
|
||||||
|
|
||||||
|
if(!gst_element_query(m_player, GST_QUERY_TOTAL, &fmtTime, &length))
|
||||||
|
return 0;
|
||||||
|
return length / GST_MSECOND ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGStreamerMediaBackend::Move(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxGStreamerMediaBackend::GetVideoSize() const
|
||||||
|
{
|
||||||
|
return m_videoSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//PlaybackRate not currently supported via playbin directly -
|
||||||
|
// Ronald S. Bultje noted on gstreamer-devel:
|
||||||
|
//
|
||||||
|
// Like "play at twice normal speed"? Or "play at 25 fps and 44,1 kHz"? As
|
||||||
|
// for the first, yes, we have elements for that, btu they"re not part of
|
||||||
|
// playbin. You can create a bin (with a ghost pad) containing the actual
|
||||||
|
// video/audiosink and the speed-changing element for this, and set that
|
||||||
|
// element as video-sink or audio-sink property in playbin. The
|
||||||
|
// audio-element is called "speed", the video-element is called "videodrop"
|
||||||
|
// (although that appears to be deprecated in favour of "videorate", which
|
||||||
|
// again cannot do this, so this may not work at all in the end). For
|
||||||
|
// forcing frame/samplerates, see audioscale and videorate. Audioscale is
|
||||||
|
// part of playbin.
|
||||||
|
//
|
||||||
|
|
||||||
double wxGStreamerMediaBackend::GetPlaybackRate()
|
double wxGStreamerMediaBackend::GetPlaybackRate()
|
||||||
{
|
{
|
||||||
//guess...
|
//not currently supported via playbin
|
||||||
GstClock* theClock = gst_element_get_clock(m_player);
|
return 1.0;
|
||||||
wxAssert(theClock);
|
|
||||||
return gst_clock_get_speed(theClock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGStreamerMediaBackend::SetPlaybackRate(double dRate)
|
bool wxGStreamerMediaBackend::SetPlaybackRate(double dRate)
|
||||||
{
|
{
|
||||||
//guess...
|
//not currently supported via playbin
|
||||||
GstClock* theClock = gst_element_get_clock(m_player);
|
return false;
|
||||||
wxAssert(theClock);
|
|
||||||
return gst_clock_change_speed(theClock, GetPlaybackRate(), dRate)==dRate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //wxUSE_GSTREAMER
|
#endif //wxUSE_GSTREAMER
|
||||||
|
Reference in New Issue
Block a user