gnomemm r1439 - in gstreamermm/trunk: . examples examples/media_player_gtkmm gstreamer/gstreamermm gstreamer/src
- From: jaalburqu svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1439 - in gstreamermm/trunk: . examples examples/media_player_gtkmm gstreamer/gstreamermm gstreamer/src
- Date: Wed, 2 Apr 2008 06:54:26 +0100 (BST)
Author: jaalburqu
Date: Wed Apr 2 06:54:25 2008
New Revision: 1439
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1439&view=rev
Log:
2008-04-02 Josà Alburquerque <jaalburqu svn gnome org>
* gstreamer/src/interface.hg: Modified cast() to return NULL RefPtr if
element is NULL
* examples/media_player_gtkmm/Makefile.am:
* examples/media_player_gtkmm/PlayerWindow.cc:
* examples/media_player_gtkmm/PlayerWindow.h:
* examples/media_player_gtkmm/main.cc: Added new media player example
which uses GStreamer playbin plugin (from gst-plugins-base) to play
any supported media (including video). At present it's crude (window
doesn't resize, etc.), but it does successfully insert video in
window!
* configure.ac: Added examples/media_player_gtkmm/Makefile to
AC_CONFIG_FILES to generate
* examples/Makefile.am: Added media_player-gtkmm directory to build
directories
* examples/Makefile.am_fragment: Modified to allow build to use
gstreamerbase branch (from gtkmm -- Thanks)
Added:
gstreamermm/trunk/examples/media_player_gtkmm/
gstreamermm/trunk/examples/media_player_gtkmm/Makefile.am
gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc
gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h
gstreamermm/trunk/examples/media_player_gtkmm/main.cc
Modified:
gstreamermm/trunk/ChangeLog
gstreamermm/trunk/configure.ac
gstreamermm/trunk/examples/Makefile.am
gstreamermm/trunk/examples/Makefile.am_fragment
gstreamermm/trunk/gstreamer/gstreamermm/ (props changed)
gstreamermm/trunk/gstreamer/src/interface.hg
Modified: gstreamermm/trunk/configure.ac
==============================================================================
--- gstreamermm/trunk/configure.ac (original)
+++ gstreamermm/trunk/configure.ac Wed Apr 2 06:54:25 2008
@@ -247,6 +247,7 @@
examples/element_link/Makefile
examples/ogg_player/Makefile
examples/ogg_player_gtkmm/Makefile
+ examples/media_player_gtkmm/Makefile
])
AC_SUBST(EXAMPLE_SUBDIR)
else
Modified: gstreamermm/trunk/examples/Makefile.am
==============================================================================
--- gstreamermm/trunk/examples/Makefile.am (original)
+++ gstreamermm/trunk/examples/Makefile.am Wed Apr 2 06:54:25 2008
@@ -1,4 +1,4 @@
-example_dirs = init element_link ogg_player ogg_player_gtkmm optiongroup
+example_dirs = init element_link media_player_gtkmm ogg_player ogg_player_gtkmm optiongroup
SUBDIRS = $(example_dirs)
EXTRA_DIST = README Makefile.am_fragment
Modified: gstreamermm/trunk/examples/Makefile.am_fragment
==============================================================================
--- gstreamermm/trunk/examples/Makefile.am_fragment (original)
+++ gstreamermm/trunk/examples/Makefile.am_fragment Wed Apr 2 06:54:25 2008
@@ -1,9 +1,11 @@
local_gstreamermm_lib = $(top_builddir)/gstreamer/gstreamermm/libgstreamermm-0.10.la
+local_gstreamerbasemm_lib = $(top_builddir)/gstreamerbase/gstreamerbasemm/libgstreamerbasemm-0.10.la
-LIBS = $(local_gstreamermm_lib) $(GSTREAMERMM_LIBS) $(GSTREAMERMM_EXAMPLES_LIBS)
+LIBS = $(local_gstreamermm_lib) $(local_gstreamerbasemm_lib) $(GSTREAMERMM_LIBS) $(GSTREAMERBASEMM_LIBS) $(GSTREAMERMM_EXAMPLES_LIBS)
all_includes = \
-I$(top_builddir)/gstreamer -I$(top_srcdir)/gstreamer \
+ -I$(top_builddir)/gstreamerbase -I$(top_srcdir)/gstreamerbase \
$(GSTREAMERMM_CFLAGS) $(GSTREAMERMM_EXAMPLES_CFLAGS)
DEFS = @DEFS@
Added: gstreamermm/trunk/examples/media_player_gtkmm/Makefile.am
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/examples/media_player_gtkmm/Makefile.am Wed Apr 2 06:54:25 2008
@@ -0,0 +1,6 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = mediaplayer
+mediaplayer_SOURCES = main.cc PlayerWindow.cc PlayerWindow.h
+
Added: gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc Wed Apr 2 06:54:25 2008
@@ -0,0 +1,398 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gtkmm/stock.h>
+#include <gtkmm/filechooserdialog.h>
+#include <gdk/gdkx.h>
+#include <gstreamermm/bus.h>
+#include <gstreamermm/clock.h>
+#include <gstreamermm/event.h>
+#include <gstreamermm/message.h>
+#include <gstreamermm/query.h>
+#include <gstreamermm/interface.h>
+#include <gstreamerbasemm/xoverlay.h>
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include "PlayerWindow.h"
+
+PlayerWindow::PlayerWindow(Glib::RefPtr<Gst::Element> playbin,
+ Glib::RefPtr<Gst::Pipeline> mainPipeline) :
+vBox(false, 5),
+progressLabel("000:00:00.000000000 / 000:00:00.000000000"),
+playButton(Gtk::Stock::MEDIA_PLAY),
+pauseButton(Gtk::Stock::MEDIA_PAUSE),
+stopButton(Gtk::Stock::MEDIA_STOP),
+rewindButton(Gtk::Stock::MEDIA_REWIND),
+forwardButton(Gtk::Stock::MEDIA_FORWARD),
+openButton(Gtk::Stock::OPEN)
+{
+ set_title("gstreamermm Media Player Example");
+
+ add(vBox);
+ vBox.pack_start(videoArea);
+ vBox.pack_start(progressLabel);
+ vBox.pack_start(progressScale);
+ vBox.pack_start(buttonBox);
+
+ progressLabel.set_alignment(Gtk::ALIGN_CENTER);
+
+ progressScale.set_range(0, 1);
+ progressScale.set_draw_value(false);
+ progressScale.signal_change_value().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_scale_value_changed));
+
+ buttonBox.pack_start(playButton);
+ buttonBox.pack_start(pauseButton);
+ buttonBox.pack_start(stopButton);
+ buttonBox.pack_start(rewindButton);
+ buttonBox.pack_start(forwardButton);
+ buttonBox.pack_start(openButton);
+
+ playButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_play));
+ pauseButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_pause));
+ stopButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_stop));
+ rewindButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_rewind));
+ forwardButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_forward));
+ openButton.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_open));
+
+ // get the bus from the pipeline
+ Glib::RefPtr<Gst::Bus> bus = mainPipeline->get_bus();
+
+ // Add a sync handler to receive synchronous messages from pipeline's
+ // bus (this is done so that videoArea can be set up for drawing at an
+ // exact appropriate time
+ bus->set_sync_handler(
+ sigc::mem_fun(*this, &PlayerWindow::on_bus_message_sync));
+
+ // Add a bus watch to receive messages from pipeline's bus
+ watch_id = bus->add_watch(
+ sigc::mem_fun(*this, &PlayerWindow::on_bus_message) );
+
+ progressScale.set_sensitive(false);
+ playButton.set_sensitive(false);
+ pauseButton.set_sensitive(false);
+ stopButton.set_sensitive(false);
+ rewindButton.set_sensitive(false);
+ forwardButton.set_sensitive(false);
+
+ this->playbin = playbin;
+ this->mainPipeline = mainPipeline;
+
+ show_all_children();
+ pauseButton.hide();
+}
+
+// This function is used to receive asynchronous messages from mainPipeline's bus
+Gst::BusSyncReply PlayerWindow::on_bus_message_sync(
+ const Glib::RefPtr<Gst::Bus>& /* bus_not_used */,
+ const Glib::RefPtr<Gst::Message>& message)
+{
+ // ignore anything but 'prepare-xwindow-id' element messages
+ if (message->get_message_type() != Gst::MESSAGE_ELEMENT)
+ return Gst::BUS_PASS;
+
+ if (!message->get_structure()->has_name("prepare-xwindow-id"))
+ return Gst::BUS_PASS;
+
+ Glib::RefPtr<Gst::Element> element =
+ Glib::RefPtr<Gst::Element>::cast_dynamic(message->get_source());
+
+ Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
+ Gst::Interface::cast <GstBase::XOverlay>(element);
+
+ if (xoverlay)
+ {
+ gulong xWindowId = GDK_WINDOW_XID(Glib::unwrap(videoArea.get_window()));
+ xoverlay->set_xwindow_id(xWindowId);
+ }
+
+ return Gst::BUS_DROP;
+}
+
+// This function is used to receive asynchronous messages from mainPipeline's bus
+bool PlayerWindow::on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus_not_used */,
+ const Glib::RefPtr<Gst::Message>& message)
+{
+ switch (message->get_message_type())
+ {
+ case Gst::MESSAGE_EOS:
+ on_stop();
+ break;
+ case Gst::MESSAGE_ERROR:
+ {
+ Glib::RefPtr<Gst::MessageError> msgError =
+ Glib::RefPtr<Gst::MessageError>::cast_dynamic(message);
+ if(msgError)
+ {
+ Glib::Error err;
+ std::string debug; //TODO: Maybe this should be an optional parameter.
+ msgError->parse(err, debug);
+ std::cerr << "Error: " << err.what() << std::endl;
+ }
+ else
+ std::cerr << "Error." << std::endl;
+{
+ switch (message->get_message_type())
+ {
+ case Gst::MESSAGE_EOS:
+ on_stop();
+ break;
+ case Gst::MESSAGE_ERROR:
+ {
+ Glib::RefPtr<Gst::MessageError> msgError =
+ Glib::RefPtr<Gst::MessageError>::cast_dynamic(message);
+ if(msgError)
+ {
+ Glib::Error err;
+ std::string debug; //TODO: Maybe this should be an optional parameter.
+ msgError->parse(err, debug);
+ std::cerr << "Error: " << err.what() << std::endl;
+ }
+ else
+ std::cerr << "Error." << std::endl;
+
+ on_stop();
+ break;
+ }
+ default:
+ {
+ //std::cout << "debug: on_bus_message: unhandled message=" << G_OBJECT_TYPE_NAME(message->gobj()) << std::endl;
+ }
+ break;
+ }
+
+ return true;
+}
+ on_stop();
+ break;
+ }
+ default:
+ {
+ //std::cout << "debug: on_bus_message: unhandled message=" << G_OBJECT_TYPE_NAME(message->gobj()) << std::endl;
+ }
+ break;
+ }
+
+ return true;
+}
+
+void PlayerWindow::on_play(void)
+{
+ progressScale.set_sensitive(true);
+ playButton.set_sensitive(false);
+ pauseButton.set_sensitive(true);
+ stopButton.set_sensitive(true);
+ rewindButton.set_sensitive(true);
+ forwardButton.set_sensitive(true);
+ openButton.set_sensitive(false);
+
+ playButton.hide();
+ pauseButton.show();
+
+ // Call update_stream_progress function at a 200ms
+ // interval to regularly update the position of the stream
+ progressConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this,
+ &PlayerWindow::update_stream_progress), 200);
+
+ // set Gstmm pipeline to play mode
+ mainPipeline->set_state(Gst::STATE_PLAYING);
+}
+
+void PlayerWindow::on_pause(void)
+{
+ playButton.set_sensitive(true);
+ pauseButton.set_sensitive(false);
+
+ pauseButton.hide();
+ playButton.show();
+
+ // disconnect progress callback
+ progressConnection.disconnect();
+
+ // set Gstmm pipeline to pause mode
+ mainPipeline->set_state(Gst::STATE_PAUSED);
+}
+
+void PlayerWindow::on_stop(void)
+{
+ progressScale.set_sensitive(false);
+ playButton.set_sensitive(true);
+ pauseButton.set_sensitive(false);
+ stopButton.set_sensitive(false);
+ rewindButton.set_sensitive(false);
+ forwardButton.set_sensitive(false);
+ openButton.set_sensitive(true);
+
+ pauseButton.hide();
+ playButton.show();
+
+ // disconnect progress callback
+ progressConnection.disconnect();
+
+ // set Gstmm pipeline to inactive mode
+ mainPipeline->set_state(Gst::STATE_NULL);
+ display_label_progress(0, duration);
+ progressScale.set_value(0);
+}
+
+bool PlayerWindow::on_scale_value_changed(Gtk::ScrollType /* type_not_used */, double value)
+{
+ gint64 newPos = gint64(value * duration);
+
+ if (mainPipeline->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+ {
+ display_label_progress(newPos, duration);
+ return true;
+ }
+ else
+ {
+ std::cerr << "Could not seek!" << std::endl;
+ return false;
+ }
+}
+
+void PlayerWindow::on_rewind(void)
+{
+ static const gint64 skipAmount = GST_SECOND * 2;
+
+ gint64 pos;
+ Gst::Format fmt = Gst::FORMAT_TIME;
+
+ if (mainPipeline->query_position(fmt, pos))
+ {
+ gint64 newPos = (pos > skipAmount) ? (pos - skipAmount) : 0;
+
+ if (mainPipeline->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos)) {
+ display_label_progress(newPos, duration);
+ progressScale.set_value(double(newPos) / duration);
+ }
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
+}
+
+void PlayerWindow::on_forward(void)
+{
+ static const gint64 skipAmount = GST_SECOND * 3;
+
+ gint64 pos;
+ Gst::Format fmt = Gst::FORMAT_TIME;
+
+ Glib::RefPtr<Gst::Query> query = Gst::QueryPosition::create(fmt);
+
+ if (mainPipeline->query(query))
+ {
+ Glib::RefPtr<Gst::QueryPosition> posQuery =
+ Glib::RefPtr<Gst::QueryPosition>::cast_dynamic(query);
+
+ posQuery->parse(fmt, pos);
+
+ gint64 newPos = ((pos + skipAmount) < duration) ? (pos + skipAmount) :
+ duration;
+
+ Glib::RefPtr<Gst::Event> event = Gst::EventSeek::create(1.0, fmt,
+ Gst::SEEK_FLAG_FLUSH, Gst::SEEK_TYPE_SET, newPos,
+ Gst::SEEK_TYPE_NONE, -1);
+
+ Glib::RefPtr<Gst::EventSeek> seekEvent =
+ Glib::RefPtr<Gst::EventSeek>::cast_dynamic(event);
+
+ if (mainPipeline->send_event(seekEvent))
+ {
+ progressScale.set_value(double(newPos) / duration);
+ display_label_progress(newPos, duration);
+ }
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
+}
+
+void PlayerWindow::on_open(void)
+{
+ static Glib::ustring workingDir = Glib::get_home_dir();
+
+ Gtk::FileChooserDialog chooser(*this,
+ "Select a media file", Gtk::FILE_CHOOSER_ACTION_OPEN);
+
+ chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ chooser.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
+
+ chooser.set_current_folder(workingDir);
+
+ int response = chooser.run();
+
+ if (response == Gtk::RESPONSE_OK) {
+ workingDir = chooser.get_current_folder();
+
+ // Set filename property on the file source. Also add a message handler:
+ playbin->set_property("uri", chooser.get_uri());
+ set_title(Glib::filename_display_basename(chooser.get_filename()));
+
+ playButton.set_sensitive(true);
+ display_label_progress(0, 0);
+ }
+}
+
+bool PlayerWindow::update_stream_progress(void)
+{
+ Gst::Format fmt = Gst::FORMAT_TIME;
+ gint64 pos = 0;
+
+ if (mainPipeline->query_position(fmt, pos)
+ && mainPipeline->query_duration(fmt, duration)) {
+ progressScale.set_value(double(pos) / duration);
+ display_label_progress(pos, duration);
+ }
+
+ return true;
+}
+
+void PlayerWindow::display_label_progress(gint64 pos, gint64 len)
+{
+ std::ostringstream locationStream (std::ostringstream::out);
+ std::ostringstream durationStream (std::ostringstream::out);
+
+ locationStream << std::right << std::setfill('0') <<
+ std::setw(3) << Gst::get_hours(pos) << ":" <<
+ std::setw(2) << Gst::get_minutes(pos) << ":" <<
+ std::setw(2) << Gst::get_seconds(pos) << "." <<
+ std::setw(9) << std::left << Gst::get_fractional_seconds(pos);
+
+ durationStream << std::right << std::setfill('0') <<
+ std::setw(3) << Gst::get_hours(len) << ":" <<
+ std::setw(2) << Gst::get_minutes(len) << ":" <<
+ std::setw(2) << Gst::get_seconds(len) << "." <<
+ std::setw(9) << std::left << Gst::get_fractional_seconds(len);
+
+ progressLabel.set_text(locationStream.str() + " / " + durationStream.str());
+}
+
+PlayerWindow::~PlayerWindow()
+{
+ mainPipeline->get_bus()->remove_watch(watch_id);
+}
Added: gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h Wed Apr 2 06:54:25 2008
@@ -0,0 +1,81 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _PLAYERWINDOW_H
+#define _PLAYERWINDOW_H
+
+#include <gtkmm/window.h>
+#include <gtkmm/drawingarea.h>
+#include <gtkmm/buttonbox.h>
+#include <gtkmm/label.h>
+#include <gtkmm/button.h>
+#include <gtkmm/scale.h>
+#include <gstreamermm/element.h>
+#include <gstreamermm/pipeline.h>
+#include <gstreamermm/bus.h>
+
+class PlayerWindow : public Gtk::Window
+{
+public:
+ PlayerWindow(Glib::RefPtr<Gst::Element> playbin,
+ Glib::RefPtr<Gst::Pipeline> mainPipeline);
+ ~PlayerWindow();
+protected:
+ Gtk::VBox vBox;
+ Gtk::HButtonBox buttonBox;
+ Gtk::DrawingArea videoArea;
+ Gtk::Label progressLabel;
+ Gtk::HScale progressScale;
+ Gtk::Button playButton;
+ Gtk::Button pauseButton;
+ Gtk::Button stopButton;
+ Gtk::Button rewindButton;
+ Gtk::Button forwardButton;
+ Gtk::Button openButton;
+protected:
+ virtual Gst::BusSyncReply on_bus_message_sync(
+ const Glib::RefPtr<Gst::Bus>& bus,
+ const Glib::RefPtr<Gst::Message>& message);
+
+ virtual bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus,
+ const Glib::RefPtr<Gst::Message>& message);
+
+ virtual void on_play(void);
+ virtual void on_pause(void);
+ virtual void on_stop(void);
+ virtual bool on_scale_value_changed(Gtk::ScrollType type, double value);
+ virtual void on_rewind(void);
+ virtual void on_forward(void);
+ virtual void on_open(void);
+protected:
+ bool update_stream_progress(void);
+ void display_label_progress(gint64 pos, gint64 len);
+private:
+ Glib::RefPtr<Gst::Element> playbin;
+ Glib::RefPtr<Gst::Pipeline> mainPipeline;
+ sigc::connection progressConnection;
+ unsigned int watch_id;
+ gint64 duration;
+};
+
+#endif /* _PLAYERWINDOW_H */
+
+
Added: gstreamermm/trunk/examples/media_player_gtkmm/main.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/examples/media_player_gtkmm/main.cc Wed Apr 2 06:54:25 2008
@@ -0,0 +1,71 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gtkmm/main.h>
+#include <gstreamermm/init.h>
+#include <gstreamermm/element.h>
+#include <gstreamermm/elementfactory.h>
+#include <gstreamermm/pad.h>
+#include <gstreamermm/pipeline.h>
+#include <iostream>
+#include "PlayerWindow.h"
+
+int
+main (int argc, char *argv[])
+{
+ Gtk::Main kit(argc, argv);
+ Gst::init(argc, argv);
+
+ // Create the pipeline
+ Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("media-player");
+
+ // Create the elements
+
+ // Autoplays any media type. Implements GstBase::XOverlay so accepts
+ // a window id in which to draw video
+ Glib::RefPtr<Gst::Element> playbin = Gst::ElementFactory::create("playbin", "media-playbin");
+
+ if (!pipeline || !playbin)
+ {
+ std::cerr << "One element could not be created" << std::endl;
+ return -1;
+ }
+
+ // Put elements in a pipeline:
+ try
+ {
+ pipeline->add(playbin);
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << "Error while adding elements to the pipeline: " << ex.what() << std::endl;
+ return -1;
+ }
+
+ PlayerWindow mainWindow(playbin, pipeline);
+
+ kit.run(mainWindow);
+
+ // Clean up nicely:
+ pipeline->set_state(Gst::STATE_NULL);
+
+ return 0;
+}
Modified: gstreamermm/trunk/gstreamer/src/interface.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/interface.hg (original)
+++ gstreamermm/trunk/gstreamer/src/interface.hg Wed Apr 2 06:54:25 2008
@@ -105,7 +105,7 @@
template <class T_CastTo>
Glib::RefPtr< Gst::ElementInterfaced<T_CastTo> > Interface::cast(const Glib::RefPtr<Element>& element)
{
- if (gst_element_implements_interface(element->gobj(), T_CastTo::get_type()))
+ if (element && gst_element_implements_interface(element->gobj(), T_CastTo::get_type()))
{
void* result =
gst_implements_interface_cast(element->gobj(), T_CastTo::get_type());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]