From 3cca7e09f69c5b7faa558074e12c3a53a86dd05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Fri, 11 Mar 2016 02:21:44 +0100 Subject: Add GStreamer 1.0 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit da6d8b0b34a10f7510d2054dbb059570a9194ab3) --- src/Makefile.am | 2 +- src/gstplayer.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 6db915f..6278004 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,7 +53,7 @@ kxvplayer_LDADD= libkmplayerbackend.la -lDCOP -lXv kxvplayer_LDFLAGS= $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor kxvplayer_SOURCES= xvplayer.cpp -kgstplayer_LDADD= libkmplayerbackend.la $(LIB_GST) $(LIB_GST_PLUGINS) -lgstinterfaces-0.10 -lDCOP +kgstplayer_LDADD= libkmplayerbackend.la $(LIB_GST) $(LIB_GST_PLUGINS) $(LIB_GST_OVERLAY) -lDCOP kgstplayer_LDFLAGS= $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor kgstplayer_SOURCES= gstplayer.cpp diff --git a/src/gstplayer.cpp b/src/gstplayer.cpp index 0585ac9..74bcee0 100644 --- a/src/gstplayer.cpp +++ b/src/gstplayer.cpp @@ -39,8 +39,13 @@ #include #include #include +#if GST_CHECK_VERSION(1,0,0) +#include +#include +#else #include #include +#endif static char configfile[2048]; @@ -76,7 +81,11 @@ static const char *vcd_device; static GstElement *gst_elm_play; static GstBus *gst_bus; static unsigned int /*GstMessageType*/ ignore_messages_mask; +#if GST_CHECK_VERSION(1,0,0) +static GstVideoOverlay *xoverlay; +#else static GstXOverlay *xoverlay; +#endif static GstColorBalance *color_balance; static gulong gst_bus_sync; static gulong gst_bus_async; @@ -121,7 +130,11 @@ gstCapsSet (GstPad *pad, GParamSpec * /*pspec*/, gpointer /*data*/) { +#if GST_CHECK_VERSION(1,0,0) + GstCaps *caps = gst_pad_get_current_caps (pad); +#else GstCaps *caps = gst_pad_get_negotiated_caps (pad); +#endif if (!caps) return; TQApplication::postEvent (gstapp, new TQEvent ((TQEvent::Type) event_video)); @@ -200,7 +213,13 @@ static void gstSource (GObject *, GParamSpec *, gpointer /*data*/) { static void gstGetDuration () { GstFormat fmt = GST_FORMAT_TIME; gint64 len = -1; // usec - if (gst_element_query_duration (gst_elm_play, &fmt, &len)) + if (gst_element_query_duration (gst_elm_play, +#if GST_CHECK_VERSION(1,0,0) + fmt, +#else + &fmt, +#endif + &len)) if (movie_length != len / (GST_MSECOND * 100)) { movie_length = len / (GST_MSECOND * 100); fprintf (stderr, "new length %d\n", movie_length); @@ -245,13 +264,23 @@ static void gstBusMessage (GstBus *, GstMessage * message, gpointer) { break; case GST_MESSAGE_BUFFERING: { gint percent = 0; - gst_structure_get_int (message->structure, "buffer-percent", &percent); + gst_structure_get_int ( +#if GST_CHECK_VERSION(1,0,0) + gst_message_get_structure(message), +#else + message->structure, +#endif + "buffer-percent", &percent); TQApplication::postEvent (gstapp, new GstProgressEvent (percent)); //fprintf (stderr, "Buffering message (%u%%)\n", percent); break; } case GST_MESSAGE_APPLICATION: { +#if GST_CHECK_VERSION(1,0,0) + const char * msg = gst_structure_get_name (gst_message_get_structure(message)); +#else const char * msg = gst_structure_get_name (message->structure); +#endif fprintf (stderr, "app msg %s\n", msg ? msg : ""); //gst_structure_foreach (message->structure, gstStructure, 0L); break; @@ -297,10 +326,21 @@ static void gstBusMessage (GstBus *, GstMessage * message, gpointer) { } static void gstMessageElement (GstBus *, GstMessage *msg, gpointer /*data*/) { - if (gst_structure_has_name (msg->structure, "prepare-xwindow-id")) { + if (gst_structure_has_name ( +#if GST_CHECK_VERSION(1,0,0) + gst_message_get_structure(msg), +#else + msg->structure, +#endif + "prepare-xwindow-id")) { fprintf (stderr, "prepare-xwindow-id\n"); - if (xoverlay) + if (xoverlay) { +#if GST_CHECK_VERSION(1,0,0) + gst_video_overlay_set_window_handle (xoverlay, wid); +#else gst_x_overlay_set_xwindow_id (xoverlay, wid); +#endif + } } } @@ -598,13 +638,25 @@ void KGStreamerPlayer::play (int repeat) { goto fail; if (GST_IS_BIN (videosink)) element = gst_bin_get_by_interface (GST_BIN (videosink), - GST_TYPE_X_OVERLAY); +#if GST_CHECK_VERSION(1,0,0) + GST_TYPE_VIDEO_OVERLAY +#else + GST_TYPE_X_OVERLAY +#endif + ); else element = videosink; +#if GST_CHECK_VERSION(1,0,0) + if (GST_IS_VIDEO_OVERLAY (element)) { + xoverlay = GST_VIDEO_OVERLAY (element); + gst_video_overlay_set_window_handle (xoverlay, wid); + } +#else if (GST_IS_X_OVERLAY (element)) { xoverlay = GST_X_OVERLAY (element); gst_x_overlay_set_xwindow_id (xoverlay, wid); } +#endif gst_element_set_bus (videosink, gst_bus); gst_element_set_state (videosink, GST_STATE_READY); success = gstPollForStateChange (videosink, GST_STATE_READY); @@ -621,7 +673,11 @@ void KGStreamerPlayer::play (int repeat) { "video-sink", videosink, "audio-sink", audiosink, NULL); +#if GST_CHECK_VERSION(1,0,0) + gst_bus_set_sync_handler (gst_bus, gst_bus_sync_signal_handler, 0L, 0L); +#else gst_bus_set_sync_handler (gst_bus, gst_bus_sync_signal_handler, 0L); +#endif gst_bus_sync = g_signal_connect (gst_bus, "sync-message::element", G_CALLBACK (gstMessageElement), 0L); g_signal_connect (gst_elm_play, "notify::source", @@ -766,7 +822,13 @@ void KGStreamerPlayer::updatePosition () { if (gst_elm_play && callback) { GstFormat fmt = GST_FORMAT_TIME; gint64 val = 0; // usec - if (gst_element_query_position (gst_elm_play, &fmt, &val)) + if (gst_element_query_position (gst_elm_play, +#if GST_CHECK_VERSION(1,0,0) + fmt, +#else + &fmt, +#endif + &val)) callback->moviePosition (int (val / (GST_MSECOND * 100))); } mutex.unlock (); @@ -888,11 +950,19 @@ protected: if (gst_elm_play) { GstElement *videosink; g_object_get (gst_elm_play, "video-sink", &videosink, NULL); +#if GST_CHECK_VERSION(1,0,0) + if (videosink && GST_IS_VIDEO_OVERLAY (videosink)) { + gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (videosink), wid); + gst_video_overlay_expose (GST_VIDEO_OVERLAY (videosink)); + gst_object_unref (videosink); + } +#else if (videosink && GST_IS_X_OVERLAY (videosink)) { gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), wid); gst_x_overlay_expose (GST_X_OVERLAY (videosink)); gst_object_unref (videosink); } +#endif } mutex.unlock (); } @@ -900,8 +970,15 @@ protected: case ConfigureNotify: mutex.lock (); - if (xoverlay && GST_IS_X_OVERLAY (xoverlay)) +#if GST_CHECK_VERSION(1,0,0) + if (xoverlay && GST_IS_VIDEO_OVERLAY (xoverlay)) { + gst_video_overlay_expose (xoverlay); + } +#else + if (xoverlay && GST_IS_X_OVERLAY (xoverlay)) { gst_x_overlay_expose (xoverlay); + } +#endif mutex.unlock (); break; case ButtonPress: { -- cgit v1.2.1