diff --git a/configure.ac b/configure.ac index dcc35c9..578a5c9 100644 --- a/configure.ac +++ b/configure.ac @@ -50,7 +50,7 @@ AC_PROG_CC AM_MAINTAINER_MODE dnl -dnl We need gstreamer-0.10 or gstreamer-1.0 +dnl We need gstreamer-1.0 dnl AC_DEFUN([AC_GSTREAMER_REQUIREMENTS], [ @@ -62,15 +62,7 @@ AC_DEFUN([AC_GSTREAMER_REQUIREMENTS], PKG_CHECK_MODULES(GSTREAMER, gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0) else - dnl gstreamer-0.10 development package installed? - PKG_CHECK_MODULES(GSTREAMER_0_10, gstreamer-0.10, GST_0_10=1, GST_0_10=0) - - if test x$GST_0_10 = x1; then - AC_MSG_NOTICE([Building gst123 using gstreamer version 0.10]) - PKG_CHECK_MODULES(GSTREAMER, gstreamer-0.10 gstreamer-base-0.10 gstreamer-interfaces-0.10 gstreamer-video-0.10) - else - AC_MSG_ERROR([Neither gstreamer-0.10 nor gstreamer-1.0 was found using pkg-config.]) - fi + AC_MSG_ERROR([gstreamer-1.0 not found using pkg-config.]) fi AC_SUBST(GSTREAMER_CFLAGS) AC_SUBST(GSTREAMER_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index ffc6a03..d6a6a6b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,5 +8,5 @@ gst123_SOURCES = gst123.cc glib-extra.c glib-extra.h terminal.cc terminal.h gtki uri.cc playlist.cc m3uparser.cc plsparser.cc uri.h playlist.h m3uparser.h plsparser.h \ iostream.cc iostream.h networkstream.cc filestream.cc consolestream.cc \ httpstream.cc visualization.h visualization.cc msg.h msg.cc typefinder.h typefinder.cc \ - compat.h compat.cc utils.h utils.cc + utils.h utils.cc gst123_LDADD = $(GSTREAMER_LIBS) $(GSTREAMER_GTK_LIBS) $(NCURSES_LIBS) diff --git a/src/compat.cc b/src/compat.cc deleted file mode 100644 index 1f18c8a..0000000 --- a/src/compat.cc +++ /dev/null @@ -1,223 +0,0 @@ -/* GST123 - GStreamer based command line media player - * Copyright (C) 2013 Stefan Westerfeld - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "compat.h" - -#include - -#if GST_CHECK_VERSION(1,0,0) -#include -#else -#include -#endif - -using namespace Gst123; -using Compat::IteratorFunc; - -struct IteratorOp -{ - IteratorFunc func; - void *user_data; -}; - -#if GST_CHECK_VERSION(1,0,0) - -bool -Compat::element_query_position (GstElement *element, GstFormat format, gint64 *cur_pos) -{ - return gst_element_query_position (element, format, cur_pos); -} - -bool -Compat::element_query_duration (GstElement *element, GstFormat format, gint64 *cur_pos) -{ - return gst_element_query_duration (element, format, cur_pos); -} - -bool -Compat::video_get_size (GstPad *pad, int *width, int *height) -{ - bool result = false; - - if (GstCaps *caps = gst_pad_get_current_caps (pad)) - { - GstVideoInfo info; - - gst_video_info_init (&info); - // get video size (if any) - if (gst_video_info_from_caps (&info, caps)) - { - *width = info.width; - *height = info.height; - - result = true; - } - - gst_caps_unref (caps); - } - return result; -} - -static void -call_op_func (const GValue *evalue, gpointer user_data) -{ - GstElement *element = GST_ELEMENT (g_value_get_object (evalue)); - IteratorOp *op = (IteratorOp *) user_data; - op->func (element, op->user_data); -} - -void -Compat::iterator_foreach (GstIterator *iterator, IteratorFunc func, gpointer user_data) -{ - IteratorOp op; - op.func = func; - op.user_data = user_data; - gst_iterator_foreach (iterator, call_op_func, &op); -} - -void -Compat::video_overlay_set_window_handle (GstMessage *msg, guintptr id) -{ - gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (msg)), id); -} - -GstElement* -Compat::create_playbin (const char *name) -{ - return gst_element_factory_make ("playbin", name); -} - -bool -Compat::is_stream_start_message (GstMessage *msg) -{ - return GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_START; -} - -GstCaps* -Compat::pad_get_current_caps (GstPad *pad) -{ - return gst_pad_get_current_caps (pad); -} - -bool -Compat::is_video_overlay_prepare_window_handle_message (GstMessage *msg) -{ - return gst_is_video_overlay_prepare_window_handle_message (msg); -} - -GstRegistry* -Compat::registry_get() -{ - return gst_registry_get(); -} - -void -Compat::setup_bus_callbacks (GstPipeline *pipeline, GstBusSyncHandler sync_handler, GstBusFunc bus_func, void *user_data) -{ - GstBus *bus = gst_pipeline_get_bus (pipeline); - gst_bus_set_sync_handler (bus, sync_handler, user_data, NULL); - gst_bus_add_watch (bus, bus_func, user_data); - gst_object_unref (bus); -} - -#else - -bool -Compat::element_query_position (GstElement *element, GstFormat format, gint64 *cur_pos) -{ - return gst_element_query_position (element, &format, cur_pos); -} - -bool -Compat::element_query_duration (GstElement *element, GstFormat format, gint64 *cur_pos) -{ - return gst_element_query_duration (element, &format, cur_pos); -} - -bool -Compat::video_get_size (GstPad *pad, int *width, int *height) -{ - return gst_video_get_size (GST_PAD (pad), width, height); -} - -static void -call_op_func (gpointer eptr, gpointer user_data) -{ - GstElement *element = GST_ELEMENT (eptr); - IteratorOp *op = (IteratorOp *) user_data; - op->func (element, op->user_data); -} - -void -Compat::iterator_foreach (GstIterator *iterator, IteratorFunc func, gpointer user_data) -{ - IteratorOp op; - op.func = func; - op.user_data = user_data; - gst_iterator_foreach (iterator, call_op_func, &op); -} - -void -Compat::video_overlay_set_window_handle (GstMessage *msg, guintptr id) -{ - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (msg)), id); -} - -GstElement* -Compat::create_playbin (const char *name) -{ - return gst_element_factory_make ("playbin2", name); -} - -bool -Compat::is_stream_start_message (GstMessage *msg) -{ - return GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && - gst_structure_has_name (msg->structure, "playbin2-stream-changed"); -} - -GstCaps* -Compat::pad_get_current_caps (GstPad *pad) -{ - return gst_pad_get_negotiated_caps (pad); -} - -bool -Compat::is_video_overlay_prepare_window_handle_message (GstMessage *msg) -{ - return GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && - gst_structure_has_name (msg->structure, "prepare-xwindow-id"); -} - -GstRegistry* -Compat::registry_get() -{ - return gst_registry_get_default(); -} - -void -Compat::setup_bus_callbacks (GstPipeline *pipeline, GstBusSyncHandler sync_handler, GstBusFunc bus_func, void *user_data) -{ - GstBus *bus = gst_pipeline_get_bus (pipeline); - gst_bus_set_sync_handler (bus, sync_handler, user_data); - gst_bus_add_watch (bus, bus_func, user_data); - gst_object_unref (bus); -} - -#endif diff --git a/src/compat.h b/src/compat.h deleted file mode 100644 index f1c7cd9..0000000 --- a/src/compat.h +++ /dev/null @@ -1,51 +0,0 @@ -/* GST123 - GStreamer based command line media player - * Copyright (C) 2013 Stefan Westerfeld - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GST123_COMPAT__ -#define __GST123_COMPAT__ - -#include - -namespace Gst123 -{ - -namespace Compat -{ - -typedef void (*IteratorFunc) (GstElement *element, gpointer user_data); - -bool element_query_position (GstElement *element, GstFormat format, gint64 *cur_pos); -bool element_query_duration (GstElement *element, GstFormat format, gint64 *cur_pos); -bool video_get_size (GstPad *pad, int *width, int *height); -bool is_video_overlay_prepare_window_handle_message (GstMessage *msg); -bool is_stream_start_message (GstMessage *msg); - -void iterator_foreach (GstIterator *iterator, IteratorFunc func, gpointer user_data); -void video_overlay_set_window_handle (GstMessage *msg, guintptr id); - -GstElement* create_playbin (const char *name); -GstCaps *pad_get_current_caps (GstPad *pad); -GstRegistry *registry_get(); -void setup_bus_callbacks (GstPipeline *pipeline, GstBusSyncHandler sync_handler, GstBusFunc bus_func, void *user_data); - -} - -} - -#endif diff --git a/src/gst123.cc b/src/gst123.cc index 2a13af8..0213205 100644 --- a/src/gst123.cc +++ b/src/gst123.cc @@ -37,7 +37,6 @@ #include "visualization.h" #include "msg.h" #include "typefinder.h" -#include "compat.h" #include "utils.h" #include #include @@ -102,12 +101,19 @@ get_basename (const string& path) } void -force_aspect_ratio (GstElement *element, gpointer userdata) +force_aspect_ratio (GstElement *element) { if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (element)), "force-aspect-ratio")) g_object_set (G_OBJECT (element), "force-aspect-ratio", TRUE, NULL); } +void +aspect_iterfunc (const GValue *evalue, gpointer userdata) +{ + GstElement *element = GST_ELEMENT (g_value_get_object (evalue)); + force_aspect_ratio (element); +} + static bool filename2uri (string& uri) { @@ -466,7 +472,7 @@ struct Player : public KeyHandler relative_seek (double displacement) { gint64 cur_pos; - Compat::element_query_position (playbin, GST_FORMAT_TIME, &cur_pos); + gst_element_query_position (playbin, GST_FORMAT_TIME, &cur_pos); double new_pos_sec = cur_pos * (1.0 / GST_SECOND) + displacement; seek (new_pos_sec * GST_SECOND); @@ -629,28 +635,28 @@ caps_set_cb (GObject *pad, GParamSpec *pspec, Player* player) { // this callback doesn't occur in main thread - if (GstCaps *caps = Compat::pad_get_current_caps (GST_PAD (pad))) + if (GstCaps *caps = gst_pad_get_current_caps (GST_PAD (pad))) { - int width, height; + GstVideoInfo info; - if (Compat::video_get_size (GST_PAD (pad), &width, &height)) + gst_video_info_init(&info); + if (gst_video_info_from_caps (&info, caps)) { // resize window to match video size (must run in main thread, so we use an idle handler) - g_idle_add ((GSourceFunc) IdleResizeWindow::callback, - new IdleResizeWindow (width, height)); + new IdleResizeWindow (info.width, info.height)); } gst_caps_unref (caps); } } static void -collect_element (GstElement *element, - gpointer list_ptr) +collect_element (const GValue *evalue, gpointer list_ptr) { /* seems that if we use push_front, the pipeline gets displayed in the * right order; but I don't know if thats a guarantee of an accident */ + GstElement *element = GST_ELEMENT (g_value_get_object (evalue)); list& elements = *(list *)list_ptr; gst_object_ref (element); elements.push_front (element); @@ -683,9 +689,9 @@ my_sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data) switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ELEMENT: { - if (Compat::is_video_overlay_prepare_window_handle_message (message) && gtk_interface.init_ok()) + if (gst_is_video_overlay_prepare_window_handle_message (message) && gtk_interface.init_ok()) { - Compat::video_overlay_set_window_handle (message, gtk_interface.window_xid_nolock()); + gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), gtk_interface.window_xid_nolock()); } } break; @@ -738,7 +744,7 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data) list elements; GstIterator *iterator = gst_bin_iterate_recurse (GST_BIN (player.playbin)); - Compat::iterator_foreach (iterator, collect_element, &elements); + gst_iterator_foreach (iterator, collect_element, &elements); string print_elements = collect_print_elements (GST_ELEMENT (player.playbin), elements); player.overwrite_time_display(); @@ -756,7 +762,7 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data) break; } - if (Compat::is_stream_start_message (message)) + if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START) { // try to figure out the video size GstElement *videosink = NULL; @@ -768,16 +774,16 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data) // Find an sink element that has "force-aspect-ratio" property & set it // to TRUE: GstIterator *iterator = gst_bin_iterate_sinks (GST_BIN (videosink)); - Compat::iterator_foreach (iterator, force_aspect_ratio, NULL); + gst_iterator_foreach (iterator, aspect_iterfunc, NULL); } else { - force_aspect_ratio (videosink, NULL); + force_aspect_ratio (videosink); } if (GstPad* pad = gst_element_get_static_pad (videosink, "sink")) { - if (GstCaps *caps = Compat::pad_get_current_caps (pad)) + if (GstCaps *caps = gst_pad_get_current_caps (pad)) { caps_set_cb (G_OBJECT (pad), NULL, &player); gst_caps_unref (caps); @@ -853,8 +859,8 @@ cb_print_position (gpointer *data) player.display_tags(); - if (Compat::element_query_position (player.playbin, GST_FORMAT_TIME, &pos) && - Compat::element_query_duration (player.playbin, GST_FORMAT_TIME, &len)) + if (gst_element_query_position (player.playbin, GST_FORMAT_TIME, &pos) && + gst_element_query_duration (player.playbin, GST_FORMAT_TIME, &len)) { guint pos_ms = (pos % GST_SECOND) / 1000000; guint len_ms = (len % GST_SECOND) / 1000000; @@ -1171,7 +1177,7 @@ main (gint argc, printf ("%s", options.usage.c_str()); return -1; } - player.playbin = Compat::create_playbin ("play"); + player.playbin = gst_element_factory_make("playbin", "play"); if (options.novideo) { GstElement *fakesink = gst_element_factory_make ("fakesink", "novid"); @@ -1224,7 +1230,11 @@ main (gint argc, player.set_subtitle (options.subtitle); } - Compat::setup_bus_callbacks (GST_PIPELINE (player.playbin), my_sync_bus_callback, my_bus_callback, &player); + /* Setup callbacks */ + GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (player.playbin)); + gst_bus_set_sync_handler (bus, my_sync_bus_callback, &player, NULL); + gst_bus_add_watch (bus, my_bus_callback, &player); + gst_object_unref (bus); g_timeout_add (130, (GSourceFunc) cb_print_position, &player); g_idle_add ((GSourceFunc) idle_start_player, &player); diff --git a/src/visualization.cc b/src/visualization.cc index 7453102..db914c2 100644 --- a/src/visualization.cc +++ b/src/visualization.cc @@ -20,12 +20,9 @@ #include #include -#include "compat.h" #include "options.h" #include "visualization.h" -using namespace Gst123; - namespace Visualization { @@ -46,7 +43,7 @@ filter_features (GstPluginFeature * feature, gpointer data) static GList * get_visualization_features() { - return gst_registry_feature_filter (Compat::registry_get(), filter_features, FALSE, NULL); + return gst_registry_feature_filter (gst_registry_get(), filter_features, FALSE, NULL); } void