gnomemm r1496 - in gstreamermm/trunk: . examples examples/element_link examples/init examples/media_player_gtkmm examples/ogg_player examples/ogg_player_gtkmm
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1496 - in gstreamermm/trunk: . examples examples/element_link examples/init examples/media_player_gtkmm examples/ogg_player examples/ogg_player_gtkmm
- Date: Fri, 16 May 2008 22:51:00 +0100 (BST)
Author: murrayc
Date: Fri May 16 21:50:59 2008
New Revision: 1496
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1496&view=rev
Log:
2008-05-16 Murray Cumming <murrayc murrayc com>
* configure.ac:
* examples/Makefile.am:
* examples/init/Makefile.am:
* examples/init/init.cc: Remove this example, because it does not
seem useful. All the other examples show how to initialize gstreamermm
already.
* examples/element_link/element_link.cc:
* examples/media_player_gtkmm/PlayerWindow.cc:
* examples/media_player_gtkmm/PlayerWindow.h:
* examples/media_player_gtkmm/main.cc:
* examples/ogg_player/main.cc:
* examples/ogg_player_gtkmm/PlayerWindow.cc:
* examples/ogg_player_gtkmm/PlayerWindow.h:
* examples/ogg_player_gtkmm/main.cc: Change the syntax/formatting to
be consistent with other *mm examples.
Removed:
gstreamermm/trunk/examples/init/
Modified:
gstreamermm/trunk/ChangeLog
gstreamermm/trunk/configure.ac
gstreamermm/trunk/examples/Makefile.am
gstreamermm/trunk/examples/element_link/element_link.cc
gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc
gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h
gstreamermm/trunk/examples/media_player_gtkmm/main.cc
gstreamermm/trunk/examples/ogg_player/main.cc
gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.cc
gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.h
gstreamermm/trunk/examples/ogg_player_gtkmm/main.cc
Modified: gstreamermm/trunk/configure.ac
==============================================================================
--- gstreamermm/trunk/configure.ac (original)
+++ gstreamermm/trunk/configure.ac Fri May 16 21:50:59 2008
@@ -242,7 +242,6 @@
EXAMPLE_SUBDIR="examples"
AC_CONFIG_FILES([
examples/Makefile
- examples/init/Makefile
examples/optiongroup/Makefile
examples/element_link/Makefile
examples/ogg_player/Makefile
Modified: gstreamermm/trunk/examples/Makefile.am
==============================================================================
--- gstreamermm/trunk/examples/Makefile.am (original)
+++ gstreamermm/trunk/examples/Makefile.am Fri May 16 21:50:59 2008
@@ -1,4 +1,4 @@
-example_dirs = init element_link media_player_gtkmm ogg_player ogg_player_gtkmm optiongroup
+example_dirs = element_link media_player_gtkmm ogg_player ogg_player_gtkmm optiongroup
SUBDIRS = $(example_dirs)
EXTRA_DIST = README Makefile.am_fragment
Modified: gstreamermm/trunk/examples/element_link/element_link.cc
==============================================================================
--- gstreamermm/trunk/examples/element_link/element_link.cc (original)
+++ gstreamermm/trunk/examples/element_link/element_link.cc Fri May 16 21:50:59 2008
@@ -25,38 +25,31 @@
int main(int argc, char** argv)
{
- Glib::RefPtr<Gst::Pipeline> m_Pipeline;
- Glib::RefPtr<Gst::Element> m_Element_Source, m_Element_Filter, m_Element_Sink;
+ Glib::RefPtr<Gst::Pipeline> pipeline;
+ Glib::RefPtr<Gst::Element> element_source, element_filter, element_sink;
- // init Gstreamermm
+ // Initialize Gstreamermm:
Gst::init(argc, argv);
- // create pipeline
- m_Pipeline = Gst::Pipeline::create("my-pipeline");
+ // Create pipeline:
+ pipeline = Gst::Pipeline::create("my-pipeline");
- // create elements
- try
- {
- m_Element_Source = Gst::ElementFactory::create_element("fakesrc");
- m_Element_Filter = Gst::ElementFactory::create_element("identity");
- m_Element_Sink = Gst::ElementFactory::create_element("fakesink");
- }
- catch(std::runtime_error& error)
- {
- std::cout << error.what();
- }
+ // Create elements:
+ element_source = Gst::ElementFactory::create_element("fakesrc");
+ element_filter = Gst::ElementFactory::create_element("identity");
+ element_sink = Gst::ElementFactory::create_element("fakesink");
- // we must add the elements to the pipeline before linking them
- m_Pipeline->add(m_Element_Source)->add(m_Element_Filter)->add(m_Element_Sink);
+ // We must add the elements to the pipeline before linking them:
+ pipeline->add(element_source)->add(element_filter)->add(element_sink);
- // link
+ // Link
try
{
- m_Element_Source->link(m_Element_Filter)->link(m_Element_Sink);
+ element_source->link(element_filter)->link(element_sink);
}
- catch(std::runtime_error& error)
+ catch(const std::runtime_error& error)
{
- std::cout << error.what();
+ std::cout << error.what() << std::endl;
}
return 0;
Modified: gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc
==============================================================================
--- gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc (original)
+++ gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.cc Fri May 16 21:50:59 2008
@@ -36,414 +36,383 @@
#include <iomanip>
#include "PlayerWindow.h"
-PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin,
- const Glib::RefPtr<Gst::Element>& videoSink) :
-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, Gtk::PACK_EXPAND_WIDGET);
- vBox.pack_start(progressLabel, Gtk::PACK_SHRINK);
- vBox.pack_start(progressScale, Gtk::PACK_SHRINK);
- vBox.pack_start(buttonBox, Gtk::PACK_SHRINK);
-
- 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 = playbin->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);
+PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& videoSink)
+: m_vbox(false, 6),
+ m_progress_label("000:00:00.000000000 / 000:00:00.000000000"),
+ m_play_button(Gtk::Stock::MEDIA_PLAY),
+ m_pause_button(Gtk::Stock::MEDIA_PAUSE),
+ m_stop_button(Gtk::Stock::MEDIA_STOP),
+ m_rewind_button(Gtk::Stock::MEDIA_REWIND),
+ m_forward_button(Gtk::Stock::MEDIA_FORWARD),
+ m_open_button(Gtk::Stock::OPEN)
+{
+ set_title("gstreamermm Media Player Example");
+
+ add(m_vbox);
+ m_vbox.pack_start(m_video_area, Gtk::PACK_EXPAND_WIDGET);
+ m_vbox.pack_start(m_progress_label, Gtk::PACK_SHRINK);
+ m_vbox.pack_start(m_progress_scale, Gtk::PACK_SHRINK);
+ m_vbox.pack_start(m_button_box, Gtk::PACK_SHRINK);
+
+ m_progress_label.set_alignment(Gtk::ALIGN_CENTER);
+
+ m_progress_scale.set_range(0, 1);
+ m_progress_scale.set_draw_value(false);
+ m_progress_scale.signal_change_value().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_scale_value_changed) );
+
+ m_button_box.pack_start(m_play_button);
+ m_button_box.pack_start(m_pause_button);
+ m_button_box.pack_start(m_stop_button);
+ m_button_box.pack_start(m_rewind_button);
+ m_button_box.pack_start(m_forward_button);
+ m_button_box.pack_start(m_open_button);
+
+ m_play_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_play));
+ m_pause_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_pause));
+ m_stop_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_stop));
+ m_rewind_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_rewind));
+ m_forward_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_forward));
+ m_open_button.signal_clicked().connect(sigc::mem_fun(*this,
+ &PlayerWindow::on_open));
+
+ // get the bus from the pipeline
+ Glib::RefPtr<Gst::Bus> bus = playbin->get_bus();
+
+ // Add a sync handler to receive synchronous messages from pipeline's
+ // bus (this is done so that m_video_area 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
+ m_watch_id = bus->add_watch(
+ sigc::mem_fun(*this, &PlayerWindow::on_bus_message) );
+
+ m_progress_scale.set_sensitive(false);
+ m_play_button.set_sensitive(false);
+ m_pause_button.set_sensitive(false);
+ m_stop_button.set_sensitive(false);
+ m_rewind_button.set_sensitive(false);
+ m_forward_button.set_sensitive(false);
- this->playbin = playbin;
- this->videoSink = videoSink;
+ m_play_bin = playbin;
+ m_video_sink = videoSink;
- show_all_children();
- pauseButton.hide();
+ show_all_children();
+ m_pause_button.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)
+ const Glib::RefPtr<Gst::Bus>& /* bus */,
+ 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;
+ // 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;
+ 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::Element> element =
+ Glib::RefPtr<Gst::Element>::cast_dynamic(message->get_source());
- Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
- Gst::Interface::cast <GstBase::XOverlay>(element);
+ Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
+ Gst::Interface::cast <GstBase::XOverlay>(element);
- if (xoverlay)
- {
- gulong xWindowId = GDK_WINDOW_XID(videoArea.get_window()->gobj());
- xoverlay->set_xwindow_id(xWindowId);
- }
+ if(xoverlay)
+ {
+ const gulong xWindowId = GDK_WINDOW_XID(m_video_area.get_window()->gobj());
+ xoverlay->set_xwindow_id(xWindowId);
+ }
- return Gst::BUS_DROP;
+ return Gst::BUS_DROP;
}
-// This function is used to receive asynchronous messages from playbin'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;
+// This function is used to receive asynchronous messages from play_bin's bus
+bool PlayerWindow::on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */,
+ const Glib::RefPtr<Gst::Message>& message)
{
- switch (message->get_message_type())
+ switch (message->get_message_type())
+ {
+ case Gst::MESSAGE_EOS:
{
- 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;
+ 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;
- return true;
-}
- on_stop();
- break;
- }
- default:
- {
- //std::cout << "debug: on_bus_message: unhandled message=" << G_OBJECT_TYPE_NAME(message->gobj()) << std::endl;
- }
- break;
+ on_stop();
+ break;
+ }
+ default:
+ {
+ //std::cout << "debug: on_bus_message: unhandled message=" << G_OBJECT_TYPE_NAME(message->gobj()) << std::endl;
}
+ }
- return true;
+ return true;
}
bool PlayerWindow::on_video_pad_got_buffer(const Glib::RefPtr<Gst::Pad>& pad,
- const Glib::RefPtr<Gst::MiniObject>& data)
+ const Glib::RefPtr<Gst::MiniObject>& data)
{
- Glib::RefPtr<Gst::Buffer> buffer = Glib::RefPtr<Gst::Buffer>::cast_dynamic(data);
+ Glib::RefPtr<Gst::Buffer> buffer = Glib::RefPtr<Gst::Buffer>::cast_dynamic(data);
- if (buffer) {
- Glib::Value<int> widthValue;
- Glib::Value<int> heightValue;
+ if(buffer) {
+ Glib::Value<int> widthValue;
+ Glib::Value<int> heightValue;
- Glib::RefPtr<Gst::Caps> caps = buffer->get_caps();
- caps->get_structure(0)->get_field("width", widthValue);
- caps->get_structure(0)->get_field("height", heightValue);
+ Glib::RefPtr<Gst::Caps> caps = buffer->get_caps();
+ caps->get_structure(0)->get_field("width", widthValue);
+ caps->get_structure(0)->get_field("height", heightValue);
- videoArea.set_size_request(widthValue.get(), heightValue.get());
- resize(1, 1); // Resize to minimum when first playing by making size
- check_resize(); // smallest then resizing according to video new size
- }
+ m_video_area.set_size_request(widthValue.get(), heightValue.get());
+ resize(1, 1); // Resize to minimum when first playing by making size
+ check_resize(); // smallest then resizing according to video new size
+ }
- pad->remove_buffer_probe(pad_probe_id);
- pad_probe_id = 0; // Clear probe id to indicate that it has been removed
+ pad->remove_buffer_probe(m_pad_probe_id);
+ m_pad_probe_id = 0; // Clear probe id to indicate that it has been removed
- return true; // Keep buffer in pipeline (do not throw away)
+ return true; // Keep buffer in pipeline (do not throw away)
}
void PlayerWindow::on_play()
{
- 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);
+ m_progress_scale.set_sensitive(true);
+ m_play_button.set_sensitive(false);
+ m_pause_button.set_sensitive(true);
+ m_stop_button.set_sensitive(true);
+ m_rewind_button.set_sensitive(true);
+ m_forward_button.set_sensitive(true);
+ m_open_button.set_sensitive(false);
+
+ m_play_button.hide();
+ m_pause_button.show();
+
+ // Call update_stream_progress function at a 200ms
+ // interval to regularly update the position of the stream
+ m_progress_connection = Glib::signal_timeout().connect(
+ sigc::mem_fun(*this, &PlayerWindow::update_stream_progress), 200);
- // set Gstmm pipeline to play mode
- playbin->set_state(Gst::STATE_PLAYING);
+ // set Gstmm pipeline to play mode
+ m_play_bin->set_state(Gst::STATE_PLAYING);
}
void PlayerWindow::on_pause()
{
- playButton.set_sensitive(true);
- pauseButton.set_sensitive(false);
+ m_play_button.set_sensitive(true);
+ m_pause_button.set_sensitive(false);
- pauseButton.hide();
- playButton.show();
+ m_pause_button.hide();
+ m_play_button.show();
- // disconnect progress callback
- progressConnection.disconnect();
-
- // set Gstmm pipeline to pause mode
- playbin->set_state(Gst::STATE_PAUSED);
+ // disconnect progress callback
+ m_progress_connection.disconnect();
+
+ // set Gstmm pipeline to pause mode
+ m_play_bin->set_state(Gst::STATE_PAUSED);
}
void PlayerWindow::on_stop()
{
- 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
- playbin->set_state(Gst::STATE_NULL);
-
- // reset display
- display_label_progress(0, duration);
- progressScale.set_value(0);
-
- // Remove video sink pad buffer probe if after playing, probe id is
- // not zero (means probe was not removed because media had no video and
- // video_pad_got_buffer method never got a chance to remove probe)
- if (pad_probe_id != 0)
- {
- videoSink->get_pad("sink")->remove_buffer_probe(pad_probe_id);
- pad_probe_id = 0;
- }
+ m_progress_scale.set_sensitive(false);
+ m_play_button.set_sensitive(true);
+ m_pause_button.set_sensitive(false);
+ m_stop_button.set_sensitive(false);
+ m_rewind_button.set_sensitive(false);
+ m_forward_button.set_sensitive(false);
+ m_open_button.set_sensitive(true);
+
+ m_pause_button.hide();
+ m_play_button.show();
+
+ // disconnect progress callback
+ m_progress_connection.disconnect();
+
+ // set Gstmm pipeline to inactive mode
+ m_play_bin->set_state(Gst::STATE_NULL);
+
+ // reset display
+ display_label_progress(0, m_duration);
+ m_progress_scale.set_value(0);
+
+ // Remove video sink pad buffer probe if after playing, probe id is
+ // not zero (means probe was not removed because media had no video and
+ // video_pad_got_buffer method never got a chance to remove probe)
+ if(m_pad_probe_id != 0)
+ {
+ m_video_sink->get_pad("sink")->remove_buffer_probe(m_pad_probe_id);
+ m_pad_probe_id = 0;
+ }
}
bool PlayerWindow::on_scale_value_changed(Gtk::ScrollType /* type_not_used */, double value)
{
- gint64 newPos = gint64(value * duration);
+ gint64 newPos = gint64(value * m_duration);
- if (playbin->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;
- }
+ if(m_play_bin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+ {
+ display_label_progress(newPos, m_duration);
+ return true;
+ }
+ else
+ {
+ std::cerr << "Could not seek!" << std::endl;
+ return false;
+ }
}
void PlayerWindow::on_rewind()
{
- static const gint64 skipAmount = GST_SECOND * 2;
-
- gint64 pos;
- Gst::Format fmt = Gst::FORMAT_TIME;
+ static const gint64 skipAmount = GST_SECOND * 2;
- if (playbin->query_position(fmt, pos))
- {
- gint64 newPos = (pos > skipAmount) ? (pos - skipAmount) : 0;
+ gint64 pos = 0;
+ Gst::Format fmt = Gst::FORMAT_TIME;
- if (playbin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos)) {
- progressScale.set_value(double(newPos) / duration);
- display_label_progress(newPos, duration);
- }
- else
- std::cerr << "Could not seek!" << std::endl;
+ if(m_play_bin->query_position(fmt, pos))
+ {
+ gint64 newPos = (pos > skipAmount) ? (pos - skipAmount) : 0;
+
+ if(m_play_bin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos)) {
+ m_progress_scale.set_value(double(newPos) / m_duration);
+ display_label_progress(newPos, m_duration);
}
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
}
void PlayerWindow::on_forward()
{
- static const gint64 skipAmount = GST_SECOND * 3;
+ static const gint64 skipAmount = GST_SECOND * 3;
- gint64 pos;
- Gst::Format fmt = Gst::FORMAT_TIME;
+ gint64 pos = 0;
+ Gst::Format fmt = Gst::FORMAT_TIME;
- Glib::RefPtr<Gst::Query> query = Gst::QueryPosition::create(fmt);
+ Glib::RefPtr<Gst::Query> query = Gst::QueryPosition::create(fmt);
- if (playbin->query(query))
- {
- Glib::RefPtr<Gst::QueryPosition> posQuery =
- Glib::RefPtr<Gst::QueryPosition>::cast_dynamic(query);
+ if(m_play_bin->query(query))
+ {
+ Glib::RefPtr<Gst::QueryPosition> posQuery =
+ Glib::RefPtr<Gst::QueryPosition>::cast_dynamic(query);
+
+ posQuery->parse(fmt, pos);
- posQuery->parse(fmt, pos);
+ gint64 newPos = ((pos + skipAmount) < m_duration) ? (pos + skipAmount) :
+ m_duration;
- 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::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 (playbin->send_event(seekEvent))
- {
- progressScale.set_value(double(newPos) / duration);
- display_label_progress(newPos, duration);
- }
- else
- std::cerr << "Could not seek!" << std::endl;
+ Glib::RefPtr<Gst::EventSeek> seekEvent =
+ Glib::RefPtr<Gst::EventSeek>::cast_dynamic(event);
+
+ if(m_play_bin->send_event(seekEvent))
+ {
+ m_progress_scale.set_value(double(newPos) / m_duration);
+ display_label_progress(newPos, m_duration);
}
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
}
void PlayerWindow::on_open()
{
- 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 uri property on the playbin.
- Glib::RefPtr<Gst::Element>::cast_dynamic(playbin)->
- set_property("uri", chooser.get_uri());
-
- // Resize videoArea and window to minimum when opening a file
- videoArea.set_size_request(0, 0);
- resize(1, 1);
-
- // Add buffer probe to video sink pad when file is opened which will
- // be removed after first buffer is received in on_video_pad_got_buffer
- // method (if there's video). When first buffer arrives, video
- // size can be extracted. If there's no video, probe will be
- // removed when media stops in on_stop method
- pad_probe_id = videoSink->get_pad("sink")->add_buffer_probe(
- sigc::mem_fun(*this, &PlayerWindow::on_video_pad_got_buffer));
-
- set_title(Glib::filename_display_basename(chooser.get_filename()));
-
- playButton.set_sensitive(true);
- display_label_progress(0, 0);
- }
+ 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 uri property on the playbin.
+ Glib::RefPtr<Gst::Element>::cast_dynamic(m_play_bin)->
+ set_property("uri", chooser.get_uri());
+
+ // Resize m_video_area and window to minimum when opening a file
+ m_video_area.set_size_request(0, 0);
+ resize(1, 1);
+
+ // Add buffer probe to video sink pad when file is opened which will
+ // be removed after first buffer is received in on_video_pad_got_buffer
+ // method (if there's video). When first buffer arrives, video
+ // size can be extracted. If there's no video, probe will be
+ // removed when media stops in on_stop method
+ m_pad_probe_id = m_video_sink->get_pad("sink")->add_buffer_probe(
+ sigc::mem_fun(*this, &PlayerWindow::on_video_pad_got_buffer));
+
+ set_title(Glib::filename_display_basename(chooser.get_filename()));
+
+ m_play_button.set_sensitive(true);
+ display_label_progress(0, 0);
+ }
}
bool PlayerWindow::update_stream_progress()
{
- Gst::Format fmt = Gst::FORMAT_TIME;
- gint64 pos = 0;
+ Gst::Format fmt = Gst::FORMAT_TIME;
+ gint64 pos = 0;
- if (playbin->query_position(fmt, pos)
- && playbin->query_duration(fmt, duration)) {
- progressScale.set_value(double(pos) / duration);
- display_label_progress(pos, duration);
- }
+ if(m_play_bin->query_position(fmt, pos)
+ && m_play_bin->query_duration(fmt, m_duration))
+ {
+ m_progress_scale.set_value(double(pos) / m_duration);
+ display_label_progress(pos, m_duration);
+ }
return true;
}
void PlayerWindow::display_label_progress(gint64 pos, gint64 len)
{
- std::ostringstream locationStream (std::ostringstream::out);
- std::ostringstream durationStream (std::ostringstream::out);
+ 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);
+ 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());
+ m_progress_label.set_text(locationStream.str() + " / " + durationStream.str());
}
PlayerWindow::~PlayerWindow()
{
- playbin->get_bus()->remove_watch(watch_id);
+ m_play_bin->get_bus()->remove_watch(m_watch_id);
}
Modified: gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h
==============================================================================
--- gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h (original)
+++ gstreamermm/trunk/examples/media_player_gtkmm/PlayerWindow.h Fri May 16 21:50:59 2008
@@ -35,50 +35,45 @@
class PlayerWindow : public Gtk::Window
{
public:
- PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin,
- const Glib::RefPtr<Gst::Element>& videoSink);
+ PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& videoSink);
+ virtual ~PlayerWindow();
- ~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 bool on_video_pad_got_buffer(const Glib::RefPtr<Gst::Pad>& pad,
- const Glib::RefPtr<Gst::MiniObject>& buffer);
-
- virtual void on_play();
- virtual void on_pause();
- virtual void on_stop();
- virtual bool on_scale_value_changed(Gtk::ScrollType type, double value);
- virtual void on_rewind();
- virtual void on_forward();
- virtual void on_open();
+
+ //Signal handlers:
+ Gst::BusSyncReply on_bus_message_sync(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message);
+ bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message);
+ bool on_video_pad_got_buffer(const Glib::RefPtr<Gst::Pad>& pad, const Glib::RefPtr<Gst::MiniObject>& buffer);
+ void on_play();
+ void on_pause();
+ void on_stop();
+ bool on_scale_value_changed(Gtk::ScrollType type, double value);
+ void on_rewind();
+ void on_forward();
+ void on_open();
+
+ bool update_stream_progress();
+ void display_label_progress(gint64 pos, gint64 len);
+
protected:
- bool update_stream_progress();
- void display_label_progress(gint64 pos, gint64 len);
-private:
- Glib::RefPtr<Gst::Pipeline> playbin;
- Glib::RefPtr<Gst::Element> videoSink;
- sigc::connection progressConnection;
- guint watch_id;
- gint64 duration;
- gulong pad_probe_id;
+ Gtk::VBox m_vbox;
+ Gtk::HButtonBox m_button_box;
+ Gtk::DrawingArea m_video_area;
+ Gtk::Label m_progress_label;
+ Gtk::HScale m_progress_scale;
+ Gtk::Button m_play_button;
+ Gtk::Button m_pause_button;
+ Gtk::Button m_stop_button;
+ Gtk::Button m_rewind_button;
+ Gtk::Button m_forward_button;
+ Gtk::Button m_open_button;
+
+ Glib::RefPtr<Gst::Pipeline> m_play_bin;
+ Glib::RefPtr<Gst::Element> m_video_sink;
+ sigc::connection m_progress_connection;
+ guint m_watch_id;
+ gint64 m_duration;
+ gulong m_pad_probe_id;
};
#endif /* _PLAYERWINDOW_H */
Modified: gstreamermm/trunk/examples/media_player_gtkmm/main.cc
==============================================================================
--- gstreamermm/trunk/examples/media_player_gtkmm/main.cc (original)
+++ gstreamermm/trunk/examples/media_player_gtkmm/main.cc Fri May 16 21:50:59 2008
@@ -31,34 +31,34 @@
int
main (int argc, char *argv[])
{
- Gtk::Main kit(argc, argv);
- Gst::init(argc, argv);
+ Gtk::Main kit(argc, argv);
+ Gst::init(argc, argv);
- // Create the elements
+ // 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_element("playbin");
- Glib::RefPtr<Gst::Pipeline> playbinPipeline = Glib::RefPtr<Gst::Pipeline>::cast_dynamic(playbin);
+ // 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_element("playbin");
+ Glib::RefPtr<Gst::Pipeline> playbinPipeline = Glib::RefPtr<Gst::Pipeline>::cast_dynamic(playbin);
- // Video sink where video (if any) will be drawn
- Glib::RefPtr<Gst::Element> videoSink = Gst::ElementFactory::create_element("ximagesink");
+ // Video sink where video (if any) will be drawn
+ Glib::RefPtr<Gst::Element> videoSink = Gst::ElementFactory::create_element("ximagesink");
- if (!playbinPipeline || !videoSink)
- {
- std::cerr << "One of the elements for media player could not be created." << std::endl;
- return -1;
- }
+ if (!playbinPipeline || !videoSink)
+ {
+ std::cerr << "One of the elements for media player could not be created." << std::endl;
+ return -1;
+ }
- // set the playbin's video-sink property so that videoSink is used for video display
- playbinPipeline->set_property("video-sink", videoSink);
+ // set the playbin's video-sink property so that videoSink is used for video display
+ playbinPipeline->set_property("video-sink", videoSink);
- PlayerWindow mainWindow(playbinPipeline, videoSink);
+ PlayerWindow mainWindow(playbinPipeline, videoSink);
- kit.run(mainWindow);
+ kit.run(mainWindow);
- // Clean up nicely:
- playbinPipeline->set_state(Gst::STATE_NULL);
+ // Clean up nicely:
+ playbinPipeline->set_state(Gst::STATE_NULL);
- return 0;
+ return 0;
}
Modified: gstreamermm/trunk/examples/ogg_player/main.cc
==============================================================================
--- gstreamermm/trunk/examples/ogg_player/main.cc (original)
+++ gstreamermm/trunk/examples/ogg_player/main.cc Fri May 16 21:50:59 2008
@@ -63,7 +63,7 @@
}
// This function is used to receive asynchronous messages in the main loop.
-bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus_not_used */, const Glib::RefPtr<Gst::Message>& message)
+bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */, const Glib::RefPtr<Gst::Message>& message)
{
switch (message->get_message_type()) {
case Gst::MESSAGE_EOS:
@@ -115,13 +115,15 @@
int main(int argc, char* argv[])
{
- // check input arguments
+ // Check input arguments:
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <Ogg/Vorbis filename>" << std::endl;
return -1;
}
+ const std::string filename = argv[1];
+
// Initialize Gstreamermm:
Gst::init(argc, argv);
@@ -129,51 +131,56 @@
// Create the pipeline:
pipeline = Gst::Pipeline::create("audio-player");
- std::cout << "pipeline=" << pipeline << std::endl;
// Create the elements:
// filsrc reads the file from disk:
Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("filesrc");
- std::cout << "source=" << source << std::endl;
+ if(!source)
+ std::cerr << "filesrc element could not be created." << std::endl;
// oggdemux parses the ogg streams into elementary streams (audio and video):
Glib::RefPtr<Gst::Element> parser = Gst::ElementFactory::create_element("oggdemux");
- std::cout << "parser=" << parser << std::endl;
+ if(!parser)
+ std::cerr << "oggdemux element could not be created." << std::endl;
// vorbisdec decodes a vorbis (audio) stream:
- decoder = Gst::ElementFactory::create_element("vorbisdec", "vorbis-decoder");
- std::cout << "decoder=" << decoder << std::endl;
+ decoder = Gst::ElementFactory::create_element("vorbisdec");
+ if(!decoder)
+ std::cerr << "vorbisdec element could not be created." << std::endl;
// audioconvert converts raw audio to a format which can be used by the next element
Glib::RefPtr<Gst::Element> conv = Gst::ElementFactory::create_element("audioconvert");
- std::cout << "conv=" << conv << std::endl;
+ if(!conv)
+ std::cerr << "audioconvert element could not be created." << std::endl;
// Outputs sound to an ALSA audio device
Glib::RefPtr<Gst::Element> sink = Gst::ElementFactory::create_element("alsasink");
- std::cout << "sink=" << sink << std::endl;
+ if(!sink)
+ std::cerr << "alsasink element could not be created." << std::endl;
+ //Check that the elements were created:
if (!pipeline || !source || !parser || !decoder || !conv || !sink)
{
std::cerr << "One element could not be created" << std::endl;
return -1;
}
- data_probe_id = sink->get_pad("sink")->add_data_probe(
- sigc::ptr_fun(&on_sink_pad_have_data));
- std::cout << "sink data probe id = " << data_probe_id << std::endl;
+ Glib::RefPtr<Gst::Pad> pad = sink->get_pad("sink");
+ if(pad)
+ data_probe_id = pad->add_data_probe( sigc::ptr_fun(&on_sink_pad_have_data) );
+ //std::cout << "sink data probe id = " << data_probe_id << std::endl;
- // Set filename property on the file source. Also add a message handler:
- source->set_property("location", std::string(argv[1]));
+ // Set the filename property on the file source.
+ source->set_property("location", filename);
- // get the bus from the pipeline
+ // Get the bus from the pipeline,
+ // and add a bus watch to the default main context with the default priority:
Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus();
-
- // Add a bus watch to the default main context with the default priority.
bus->add_watch( sigc::ptr_fun(&on_bus_message) );
- // Put all elements in a pipeline:
+ // Put all the elements in a pipeline, linked to each other:
try
{
pipeline->add(source)->add(parser)->add(decoder)->add(conv)->add(sink);
@@ -185,6 +192,7 @@
}
// Link together:
+ // TODO: Why isn't this done during add()?:
source->link(parser);
// We cannot link the parser and decoder yet,
@@ -198,7 +206,7 @@
// interval to regularly print the position of the stream
Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 200);
- // Now set to playing and iterate: TODO: What is iterated? Is the comment wrong?
+ // Now set to playing and start the main loop:
std::cout << "Setting to PLAYING." << std::endl;
pipeline->set_state(Gst::STATE_PLAYING);
std::cout << "Running." << std::endl;
Modified: gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.cc
==============================================================================
--- gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.cc (original)
+++ gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.cc Fri May 16 21:50:59 2008
@@ -31,306 +31,307 @@
#include <iomanip>
#include "PlayerWindow.h"
-PlayerWindow::PlayerWindow(Glib::RefPtr<Gst::Element> sourceElement,
- 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 Ogg Player Example");
-
- add(vBox);
- 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 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->sourceElement = sourceElement;
- this->mainPipeline = mainPipeline;
-
- show_all_children();
- pauseButton.hide();
-}
-
-// 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())
+PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::Element>& source_element, const Glib::RefPtr<Gst::Pipeline>& main_pipeline)
+: m_vbox(false, 5),
+ m_progress_label("000:00:00.000000000 / 000:00:00.000000000"),
+ m_play_button(Gtk::Stock::MEDIA_PLAY),
+ m_pause_button(Gtk::Stock::MEDIA_PAUSE),
+ m_stop_button(Gtk::Stock::MEDIA_STOP),
+ m_rewind_button(Gtk::Stock::MEDIA_REWIND),
+ m_forward_button(Gtk::Stock::MEDIA_FORWARD),
+ m_open_button(Gtk::Stock::OPEN)
+{
+ set_title("gstreamermm Ogg Player Example");
+
+ add(m_vbox);
+ m_vbox.pack_start(m_progress_label);
+ m_vbox.pack_start(m_progress_scale);
+ m_vbox.pack_start(m_button_box);
+
+ m_progress_label.set_alignment(Gtk::ALIGN_CENTER);
+
+ m_progress_scale.set_range(0, 1);
+ m_progress_scale.set_draw_value(false);
+ m_progress_scale.signal_change_value().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_scale_value_changed));
+
+ m_button_box.pack_start(m_play_button);
+ m_button_box.pack_start(m_pause_button);
+ m_button_box.pack_start(m_stop_button);
+ m_button_box.pack_start(m_rewind_button);
+ m_button_box.pack_start(m_forward_button);
+ m_button_box.pack_start(m_open_button);
+
+ m_play_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_play ));
+ m_pause_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_pause) );
+ m_stop_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_stop) );
+ m_rewind_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_rewind) );
+ m_forward_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_forward) );
+ m_open_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &PlayerWindow::on_open) );
+
+ // get the bus from the pipeline
+ Glib::RefPtr<Gst::Bus> bus = main_pipeline->get_bus();
+
+ // Add a bus watch to receive messages from pipeline's bus
+ m_watch_id = bus->add_watch(
+ sigc::mem_fun( *this, &PlayerWindow::on_bus_message) );
+
+ m_progress_scale.set_sensitive(false);
+ m_play_button.set_sensitive(false);
+ m_pause_button.set_sensitive(false);
+ m_stop_button.set_sensitive(false);
+ m_rewind_button.set_sensitive(false);
+ m_forward_button.set_sensitive(false);
+
+ m_source_element = source_element;
+ m_main_pipeline = main_pipeline;
+
+ show_all_children();
+ m_pause_button.hide();
+}
+
+// This function is used to receive asynchronous messages from main_pipeline's bus
+bool PlayerWindow::on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */, 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;
+
+ on_stop();
+ break;
+ }
+ default:
{
- 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;
+ //std::cout << "debug: on_bus_message: unhandled message=" << G_OBJECT_TYPE_NAME(message->gobj()) << std::endl;
}
+ break;
+ }
- return true;
+ return true;
}
void PlayerWindow::on_play()
{
- 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);
+ m_progress_scale.set_sensitive(true);
+ m_play_button.set_sensitive(false);
+ m_pause_button.set_sensitive(true);
+ m_stop_button.set_sensitive(true);
+ m_rewind_button.set_sensitive(true);
+ m_forward_button.set_sensitive(true);
+ m_open_button.set_sensitive(false);
+
+ m_play_button.hide();
+ m_pause_button.show();
+
+ // Call update_stream_progress function at a 200ms
+ // interval to regularly update the position of the stream
+ m_progress_connection = 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);
+ // set Gstmm pipeline to play mode
+ m_main_pipeline->set_state(Gst::STATE_PLAYING);
}
void PlayerWindow::on_pause()
{
- playButton.set_sensitive(true);
- pauseButton.set_sensitive(false);
+ m_play_button.set_sensitive(true);
+ m_pause_button.set_sensitive(false);
- pauseButton.hide();
- playButton.show();
+ m_pause_button.hide();
+ m_play_button.show();
- // disconnect progress callback
- progressConnection.disconnect();
-
- // set Gstmm pipeline to pause mode
- mainPipeline->set_state(Gst::STATE_PAUSED);
+ // disconnect progress callback
+ m_progress_connection.disconnect();
+
+ // set Gstmm pipeline to pause mode
+ m_main_pipeline->set_state(Gst::STATE_PAUSED);
}
void PlayerWindow::on_stop()
{
- 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);
+ m_progress_scale.set_sensitive(false);
+ m_play_button.set_sensitive(true);
+ m_pause_button.set_sensitive(false);
+ m_stop_button.set_sensitive(false);
+ m_rewind_button.set_sensitive(false);
+ m_forward_button.set_sensitive(false);
+ m_open_button.set_sensitive(true);
+
+ m_pause_button.hide();
+ m_play_button.show();
+
+ // disconnect progress callback
+ m_progress_connection.disconnect();
+
+ // set Gstmm pipeline to inactive mode
+ m_main_pipeline->set_state(Gst::STATE_NULL);
+ display_label_progress(0, m_duration);
+ m_progress_scale.set_value(0);
}
bool PlayerWindow::on_scale_value_changed(Gtk::ScrollType /* type_not_used */, double value)
{
- gint64 newPos = gint64(value * duration);
+ gint64 newPos = gint64(value * m_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;
- }
+ if(m_main_pipeline->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+ {
+ display_label_progress(newPos, m_duration);
+ return true;
+ }
+ else
+ {
+ std::cerr << "Could not seek!" << std::endl;
+ return false;
+ }
}
void PlayerWindow::on_rewind()
{
- static const gint64 skipAmount = GST_SECOND * 2;
+ static const gint64 skipAmount = GST_SECOND * 2;
- gint64 pos;
- Gst::Format fmt = Gst::FORMAT_TIME;
+ gint64 pos = 0;
+ Gst::Format fmt = Gst::FORMAT_TIME;
- if (mainPipeline->query_position(fmt, pos))
- {
- gint64 newPos = (pos > skipAmount) ? (pos - skipAmount) : 0;
+ if(m_main_pipeline->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;
+ if(m_main_pipeline->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+ {
+ display_label_progress(newPos, m_duration);
+ m_progress_scale.set_value(double(newPos) / m_duration);
}
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
}
void PlayerWindow::on_forward()
{
- static const gint64 skipAmount = GST_SECOND * 3;
+ static const gint64 skipAmount = GST_SECOND * 3;
- gint64 pos;
- Gst::Format fmt = Gst::FORMAT_TIME;
+ gint64 pos = 0;
+ Gst::Format fmt = Gst::FORMAT_TIME;
- Glib::RefPtr<Gst::Query> query = Gst::QueryPosition::create(fmt);
+ 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);
+ if(m_main_pipeline->query(query))
+ {
+ Glib::RefPtr<Gst::QueryPosition> posQuery =
+ Glib::RefPtr<Gst::QueryPosition>::cast_dynamic(query);
- posQuery->parse(fmt, pos);
+ posQuery->parse(fmt, pos);
- gint64 newPos = ((pos + skipAmount) < duration) ? (pos + skipAmount) :
- duration;
+ gint64 newPos = ((pos + skipAmount) < m_duration) ? (pos + skipAmount) :
+ m_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;
+ 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(m_main_pipeline->send_event(seekEvent))
+ {
+ m_progress_scale.set_value(double(newPos) / m_duration);
+ display_label_progress(newPos, m_duration);
}
+ else
+ std::cerr << "Could not seek!" << std::endl;
+ }
}
void PlayerWindow::on_open()
{
- static Glib::ustring workingDir = Glib::get_home_dir();
-
- Gtk::FileChooserDialog chooser(*this,
- "Select ogg file", Gtk::FILE_CHOOSER_ACTION_OPEN);
-
- Gtk::FileFilter filter;
- filter.add_mime_type("application/ogg");
- filter.set_name("Ogg files");
-
- chooser.set_filter(filter);
-
- 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:
- sourceElement->set_property("location", chooser.get_filename());
- set_title(Glib::filename_display_basename(chooser.get_filename()));
-
- playButton.set_sensitive(true);
- display_label_progress(0, 0);
- }
+ static Glib::ustring workingDir = Glib::get_home_dir();
+
+ Gtk::FileChooserDialog chooser(*this,
+ "Select ogg file", Gtk::FILE_CHOOSER_ACTION_OPEN);
+
+ Gtk::FileFilter filter;
+ filter.add_mime_type("application/ogg");
+ filter.set_name("Ogg files");
+
+ chooser.set_filter(filter);
+
+ chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ chooser.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
+
+ chooser.set_current_folder(workingDir);
+
+ const 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:
+ m_source_element->set_property("location", chooser.get_filename());
+ set_title(Glib::filename_display_basename(chooser.get_filename()));
+
+ m_play_button.set_sensitive(true);
+ display_label_progress(0, 0);
+ }
}
bool PlayerWindow::update_stream_progress()
{
- Gst::Format fmt = Gst::FORMAT_TIME;
- gint64 pos = 0;
+ 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);
- }
+ if(m_main_pipeline->query_position(fmt, pos)
+ && m_main_pipeline->query_duration(fmt, m_duration))
+ {
+ m_progress_scale.set_value(double(pos) / m_duration);
+ display_label_progress(pos, m_duration);
+ }
return true;
}
void PlayerWindow::display_label_progress(gint64 pos, gint64 len)
{
- std::ostringstream locationStream (std::ostringstream::out);
- std::ostringstream durationStream (std::ostringstream::out);
+ 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);
+ 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());
+ m_progress_label.set_text(locationStream.str() + " / " + durationStream.str());
}
PlayerWindow::~PlayerWindow()
{
- mainPipeline->get_bus()->remove_watch(watch_id);
+ m_main_pipeline->get_bus()->remove_watch(m_watch_id);
}
+
Modified: gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.h
==============================================================================
--- gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.h (original)
+++ gstreamermm/trunk/examples/ogg_player_gtkmm/PlayerWindow.h Fri May 16 21:50:59 2008
@@ -34,39 +34,40 @@
class PlayerWindow : public Gtk::Window
{
public:
- PlayerWindow(Glib::RefPtr<Gst::Element> sourceElement,
- Glib::RefPtr<Gst::Pipeline> mainPipeline);
- ~PlayerWindow();
-protected:
- Gtk::VBox vBox;
- Gtk::HButtonBox buttonBox;
- 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 bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus,
- const Glib::RefPtr<Gst::Message>& message);
- virtual void on_play();
- virtual void on_pause();
- virtual void on_stop();
- virtual bool on_scale_value_changed(Gtk::ScrollType type, double value);
- virtual void on_rewind();
- virtual void on_forward();
- virtual void on_open();
+ PlayerWindow(const Glib::RefPtr<Gst::Element>& sourceElement, const Glib::RefPtr<Gst::Pipeline>& mainPipeline);
+ virtual ~PlayerWindow();
+
protected:
- bool update_stream_progress();
- void display_label_progress(gint64 pos, gint64 len);
-private:
- Glib::RefPtr<Gst::Element> sourceElement;
- Glib::RefPtr<Gst::Pipeline> mainPipeline;
- sigc::connection progressConnection;
- unsigned int watch_id;
- gint64 duration;
+
+ //Signal handlers:
+ bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message);
+ void on_play();
+ void on_pause();
+ void on_stop();
+ bool on_scale_value_changed(Gtk::ScrollType type, double value);
+ void on_rewind();
+ void on_forward();
+ void on_open();
+
+ bool update_stream_progress();
+ void display_label_progress(gint64 pos, gint64 len);
+
+ Gtk::VBox m_vbox;
+ Gtk::HButtonBox m_button_box;
+ Gtk::Label m_progress_label;
+ Gtk::HScale m_progress_scale;
+ Gtk::Button m_play_button;
+ Gtk::Button m_pause_button;
+ Gtk::Button m_stop_button;
+ Gtk::Button m_rewind_button;
+ Gtk::Button m_forward_button;
+ Gtk::Button m_open_button;
+
+ Glib::RefPtr<Gst::Element> m_source_element;
+ Glib::RefPtr<Gst::Pipeline> m_main_pipeline;
+ sigc::connection m_progress_connection;
+ unsigned int m_watch_id;
+ gint64 m_duration;
};
#endif /* _PLAYERWINDOW_H */
Modified: gstreamermm/trunk/examples/ogg_player_gtkmm/main.cc
==============================================================================
--- gstreamermm/trunk/examples/ogg_player_gtkmm/main.cc (original)
+++ gstreamermm/trunk/examples/ogg_player_gtkmm/main.cc Fri May 16 21:50:59 2008
@@ -33,69 +33,69 @@
void on_parser_pad_added(const Glib::RefPtr<Gst::Pad>& newPad)
{
- // We can now link this pad with the audio decoder
- Glib::RefPtr<Gst::Pad> sinkPad = decoder->get_pad("sink");
- newPad->link(sinkPad);
+ // We can now link this pad with the audio decoder
+ Glib::RefPtr<Gst::Pad> sinkPad = decoder->get_pad("sink");
+ newPad->link(sinkPad);
}
int
main (int argc, char *argv[])
{
- Gtk::Main kit(argc, argv);
- Gst::init(argc, argv);
+ Gtk::Main kit(argc, argv);
+ Gst::init(argc, argv);
- // Create the pipeline
- pipeline = Gst::Pipeline::create("audio-player");
+ // Create the pipeline
+ pipeline = Gst::Pipeline::create("audio-player");
- // Create the elements
- // Reads file from disk
- Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("filesrc");
+ // Create the elements
+ // Reads file from disk
+ Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("filesrc");
- // Parses the ogg streams into elementary streams (note that an ogg file may contain a video stream too)
- Glib::RefPtr<Gst::Element> parser = Gst::ElementFactory::create_element("oggdemux");
+ // Parses the ogg streams into elementary streams (note that an ogg file may contain a video stream too)
+ Glib::RefPtr<Gst::Element> parser = Gst::ElementFactory::create_element("oggdemux");
- // Decodes a vorbis stream
- decoder = Gst::ElementFactory::create_element("vorbisdec", "vorbis-decoder");
+ // Decodes a vorbis stream
+ decoder = Gst::ElementFactory::create_element("vorbisdec", "vorbis-decoder");
- // Converts audio() to a format which can be used by the next element
- Glib::RefPtr<Gst::Element> conv = Gst::ElementFactory::create_element("audioconvert");
+ // Converts audio() to a format which can be used by the next element
+ Glib::RefPtr<Gst::Element> conv = Gst::ElementFactory::create_element("audioconvert");
- // Outputs sound to an ALSA audio device
- Glib::RefPtr<Gst::Element> sink = Gst::ElementFactory::create_element("alsasink");
+ // Outputs sound to an ALSA audio device
+ Glib::RefPtr<Gst::Element> sink = Gst::ElementFactory::create_element("alsasink");
- if (!pipeline || !source || !parser || !decoder || !conv || !sink)
- {
- std::cerr << "One element could not be created" << std::endl;
- return -1;
- }
+ if (!pipeline || !source || !parser || !decoder || !conv || !sink)
+ {
+ std::cerr << "One element could not be created" << std::endl;
+ return -1;
+ }
- // Put all elements in a pipeline:
- try
- {
- pipeline->add(source)->add(parser)->add(decoder)->add(conv)->add(sink);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << "Error while adding elements to the pipeline: " << ex.what() << std::endl;
- return -1;
- }
+ // Put all elements in a pipeline:
+ try
+ {
+ pipeline->add(source)->add(parser)->add(decoder)->add(conv)->add(sink);
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << "Error while adding elements to the pipeline: " << ex.what() << std::endl;
+ return -1;
+ }
- // Link together:
- source->link(parser);
+ // Link together:
+ source->link(parser);
- // We cannot link the parser and decoder yet,
- // because the parser uses dynamic pads. For that,
- // we set a pad-added signal handler:
- parser->signal_pad_added().connect( sigc::ptr_fun(&on_parser_pad_added) );
+ // We cannot link the parser and decoder yet,
+ // because the parser uses dynamic pads. For that,
+ // we set a pad-added signal handler:
+ parser->signal_pad_added().connect( sigc::ptr_fun(&on_parser_pad_added) );
- decoder->link(conv)->link(sink);
+ decoder->link(conv)->link(sink);
- PlayerWindow mainWindow(source, pipeline);
+ PlayerWindow mainWindow(source, pipeline);
- kit.run(mainWindow);
+ kit.run(mainWindow);
- // Clean up nicely:
- pipeline->set_state(Gst::STATE_NULL);
+ // Clean up nicely:
+ pipeline->set_state(Gst::STATE_NULL);
- return 0;
+ return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]