gnomemm r1498 - in gstreamermm/trunk: . examples/media_player_gtkmm examples/ogg_player examples/ogg_player_gtkmm



Author: murrayc
Date: Sat May 17 08:25:02 2008
New Revision: 1498
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1498&view=rev

Log:
2008-05-17  Murray Cumming  <murrayc murrayc com>

* examples/media_player_gtkmm/main.cc:
* examples/media_player_gtkmm/player_window.cc:
* examples/media_player_gtkmm/player_window.h:
* examples/ogg_player/main.cc:
* examples/ogg_player_gtkmm/player_window.cc:
* examples/ogg_player_gtkmm/player_window.h: More cleaning up of 
examples.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/examples/media_player_gtkmm/main.cc
   gstreamermm/trunk/examples/media_player_gtkmm/player_window.cc
   gstreamermm/trunk/examples/media_player_gtkmm/player_window.h
   gstreamermm/trunk/examples/ogg_player/main.cc
   gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.cc
   gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.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	Sat May 17 08:25:02 2008
@@ -34,31 +34,40 @@
   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
+  // playbin plays any media type, choosing an appropriate set of elements
+  // and linking them together.
+  // playbin implements GstBase::XOverlay so it 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");
-
-  if (!playbinPipeline || !videoSink)
+  //The playbin element is actually a pipeline:
+  Glib::RefPtr<Gst::Pipeline> pipeline = Glib::RefPtr<Gst::Pipeline>::cast_dynamic(playbin);
+  if(!pipeline)
   {
-    std::cerr << "One of the elements for media player could not be created." << std::endl;
+    std::cerr << "The playbin 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);
+  // Create a video sink where video (if any) will be drawn:
+  Glib::RefPtr<Gst::Element> video_sink = Gst::ElementFactory::create_element("ximagesink");
+  if (!video_sink)
+  {
+    std::cerr << "The ximagesink could not be created." << std::endl;
+    return -1;
+  }
 
-  PlayerWindow mainWindow(playbinPipeline, videoSink);
+  // Set the playbin's video-sink property so that our video sink is used for video display:
+  // TODO: Create a PlayBin class that we can dynamic_cast<> to, so we can use property_video_sink()?
+  pipeline->set_property("video-sink", video_sink);
 
+  //Create our player window and give it the pipeline and video sink:
+  PlayerWindow mainWindow(pipeline, video_sink);
   kit.run(mainWindow);
 
   // Clean up nicely:
-  playbinPipeline->set_state(Gst::STATE_NULL);
+  pipeline->set_state(Gst::STATE_NULL);
 
   return 0;
 }

Modified: gstreamermm/trunk/examples/media_player_gtkmm/player_window.cc
==============================================================================
--- gstreamermm/trunk/examples/media_player_gtkmm/player_window.cc	(original)
+++ gstreamermm/trunk/examples/media_player_gtkmm/player_window.cc	Sat May 17 08:25:02 2008
@@ -36,7 +36,7 @@
 #include <iomanip>
 #include "player_window.h"
 
-PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& videoSink)
+PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& video_sink)
 : m_vbox(false, 6),
   m_progress_label("000:00:00.000000000 / 000:00:00.000000000"),
   m_play_button(Gtk::Stock::MEDIA_PLAY),
@@ -69,28 +69,28 @@
   m_button_box.pack_start(m_open_button);
 
   m_play_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_play));
+                      &PlayerWindow::on_button_play));
   m_pause_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_pause));
+                      &PlayerWindow::on_button_pause));
   m_stop_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_stop));
+                      &PlayerWindow::on_button_stop));
   m_rewind_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_rewind));
+                      &PlayerWindow::on_button_rewind));
   m_forward_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_forward));
+                      &PlayerWindow::on_button_forward));
   m_open_button.signal_clicked().connect(sigc::mem_fun(*this,
-                      &PlayerWindow::on_open));
+                      &PlayerWindow::on_button_open));
 
-  // get the bus from the pipeline
+  // 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
+  // Add a sync handler to receive synchronous messages from the pipeline's
   // bus (this is done so that m_video_area can be set up for drawing at an
-  // exact appropriate time
+  // 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
+  // Add a bus watch to receive messages from the pipeline's bus:
   m_watch_id = bus->add_watch(
     sigc::mem_fun(*this, &PlayerWindow::on_bus_message) );
 
@@ -102,7 +102,7 @@
   m_forward_button.set_sensitive(false);
 
   m_play_bin = playbin;
-  m_video_sink = videoSink;
+  m_video_sink = video_sink;
 
   show_all_children();
   m_pause_button.hide();
@@ -143,7 +143,7 @@
   {
     case Gst::MESSAGE_EOS:
     {
-      on_stop();
+      on_button_stop();
       break;
     }
     case Gst::MESSAGE_ERROR:
@@ -159,7 +159,7 @@
       else
         std::cerr << "Error." << std::endl;
 
-      on_stop();
+      on_button_stop();
       break;
     }
     default:
@@ -195,14 +195,15 @@
   return true; // Keep buffer in pipeline (do not throw away)
 }
 
-void PlayerWindow::on_play()
+void PlayerWindow::on_button_play()
 {
-  m_progress_scale.set_sensitive(true);
+  //Change the UI appropriately:
+  m_progress_scale.set_sensitive();
   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_pause_button.set_sensitive();
+  m_stop_button.set_sensitive();
+  m_rewind_button.set_sensitive();
+  m_forward_button.set_sensitive();
   m_open_button.set_sensitive(false);
 
   m_play_button.hide();
@@ -210,48 +211,48 @@
 
   // Call update_stream_progress function at a 200ms
   // interval to regularly update the position of the stream
-  m_progress_connection = Glib::signal_timeout().connect(
+  m_timeout_connection = Glib::signal_timeout().connect(
     sigc::mem_fun(*this, &PlayerWindow::update_stream_progress), 200);
 
-  // set Gstmm pipeline to play mode
+  // set the pipeline to play mode:
   m_play_bin->set_state(Gst::STATE_PLAYING);
 }
  
-void PlayerWindow::on_pause()
+void PlayerWindow::on_button_pause()
 {
-  m_play_button.set_sensitive(true);
+  m_play_button.set_sensitive();
   m_pause_button.set_sensitive(false);
 
   m_pause_button.hide();
   m_play_button.show();
 
-  // disconnect progress callback
-  m_progress_connection.disconnect();
+  // Disconnect the progress callback:
+  m_timeout_connection.disconnect();
   
-  // set Gstmm pipeline to pause mode
+  // Set the pipeline to pause mode:
   m_play_bin->set_state(Gst::STATE_PAUSED);
 }
  
-void PlayerWindow::on_stop()
+void PlayerWindow::on_button_stop()
 {
+  //Change the UI appropriately:
   m_progress_scale.set_sensitive(false);
-  m_play_button.set_sensitive(true);
+  m_play_button.set_sensitive();
   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_open_button.set_sensitive();
   m_pause_button.hide();
   m_play_button.show();
 
-  // disconnect progress callback
-  m_progress_connection.disconnect();
+  // Disconnect the progress signal handler:
+  m_timeout_connection.disconnect();
 
-  // set Gstmm pipeline to inactive mode
+  // Set the pipeline to inactive mode:
   m_play_bin->set_state(Gst::STATE_NULL);
 
-  // reset display
+  // Reset the display:
   display_label_progress(0, m_duration);
   m_progress_scale.set_value(0);
 
@@ -281,7 +282,7 @@
   }
 }
 
-void PlayerWindow::on_rewind()
+void PlayerWindow::on_button_rewind()
 {
   static const gint64 skipAmount = GST_SECOND * 2;
 
@@ -301,7 +302,7 @@
   }
 }
 
-void PlayerWindow::on_forward()
+void PlayerWindow::on_button_forward()
 {
   static const gint64 skipAmount = GST_SECOND * 3;
 
@@ -337,26 +338,25 @@
   }
 }
 
-void PlayerWindow::on_open()
+void PlayerWindow::on_button_open()
 {
-  static Glib::ustring workingDir = Glib::get_home_dir();
+  static Glib::ustring working_dir = Glib::get_home_dir();
   
   Gtk::FileChooserDialog chooser(*this,
-            "Select a media file", Gtk::FILE_CHOOSER_ACTION_OPEN);
-
+    "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);
+  chooser.set_current_folder(working_dir);
   
-  int response = chooser.run();
-  
-  if(response == Gtk::RESPONSE_OK) {
-    workingDir = chooser.get_current_folder();
+  const int response = chooser.run();
+  if(response == Gtk::RESPONSE_OK)
+  {
+    working_dir = 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());
+    // TODO: Create a PlayBin class that we can dynamic_cast<> to, so we can use property_uri()?
+    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);
@@ -366,13 +366,13 @@
     // 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
+    // removed when media stops in on_button_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()));
+    set_title( Glib::filename_display_basename(chooser.get_filename()) );
 
-    m_play_button.set_sensitive(true);
+    m_play_button.set_sensitive();
     display_label_progress(0, 0);
   }
 }

Modified: gstreamermm/trunk/examples/media_player_gtkmm/player_window.h
==============================================================================
--- gstreamermm/trunk/examples/media_player_gtkmm/player_window.h	(original)
+++ gstreamermm/trunk/examples/media_player_gtkmm/player_window.h	Sat May 17 08:25:02 2008
@@ -35,7 +35,11 @@
 class PlayerWindow : public Gtk::Window
 {
 public:
-  PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& videoSink);
+  /**
+   * @param playbin The pipeline that can play media files.
+   * @param video_sink
+   */
+  PlayerWindow(const Glib::RefPtr<Gst::Pipeline>& playbin, const Glib::RefPtr<Gst::Element>& video_sink);
   virtual ~PlayerWindow();
 
 protected:
@@ -44,13 +48,15 @@
   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();
+
+  void on_button_play();
+  void on_button_pause();
+  void on_button_stop();
+  void on_button_rewind();
+  void on_button_forward();
+  void on_button_open();
   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);
@@ -70,7 +76,7 @@
 
   Glib::RefPtr<Gst::Pipeline> m_play_bin;
   Glib::RefPtr<Gst::Element> m_video_sink;
-  sigc::connection m_progress_connection;
+  sigc::connection m_timeout_connection;
   guint m_watch_id;
   gint64 m_duration;
   gulong m_pad_probe_id;

Modified: gstreamermm/trunk/examples/ogg_player/main.cc
==============================================================================
--- gstreamermm/trunk/examples/ogg_player/main.cc	(original)
+++ gstreamermm/trunk/examples/ogg_player/main.cc	Sat May 17 08:25:02 2008
@@ -173,6 +173,7 @@
 
 
   // Set the filename property on the file source.
+  // TODO: Create a FileSrc class that we can dynamic_cast<> to, so we can use property_location()?
   source->set_property("location", filename);
 
   // Get the bus from the pipeline, 

Modified: gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.cc
==============================================================================
--- gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.cc	(original)
+++ gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.cc	Sat May 17 08:25:02 2008
@@ -63,17 +63,17 @@
   m_button_box.pack_start(m_open_button);
 
   m_play_button.signal_clicked().connect(
-    sigc::mem_fun(*this, &PlayerWindow::on_play ));
+    sigc::mem_fun(*this, &PlayerWindow::on_button_play ));
   m_pause_button.signal_clicked().connect(
-    sigc::mem_fun(*this, &PlayerWindow::on_pause) );
+    sigc::mem_fun(*this, &PlayerWindow::on_button_pause) );
   m_stop_button.signal_clicked().connect(
-    sigc::mem_fun(*this, &PlayerWindow::on_stop) );
+    sigc::mem_fun(*this, &PlayerWindow::on_button_stop) );
   m_rewind_button.signal_clicked().connect(
-    sigc::mem_fun(*this, &PlayerWindow::on_rewind) );
+    sigc::mem_fun(*this, &PlayerWindow::on_button_rewind) );
   m_forward_button.signal_clicked().connect(
-    sigc::mem_fun(*this,  &PlayerWindow::on_forward) );
+    sigc::mem_fun(*this,  &PlayerWindow::on_button_forward) );
   m_open_button.signal_clicked().connect(
-    sigc::mem_fun(*this, &PlayerWindow::on_open) );
+    sigc::mem_fun(*this, &PlayerWindow::on_button_open) );
 
   // get the bus from the pipeline
   Glib::RefPtr<Gst::Bus> bus = main_pipeline->get_bus();
@@ -102,7 +102,7 @@
   switch (message->get_message_type())
   {
     case Gst::MESSAGE_EOS:
-      on_stop();
+      on_button_stop();
       break;
     case Gst::MESSAGE_ERROR:
     {
@@ -118,7 +118,7 @@
       else
         std::cerr << "Error." << std::endl;
 
-      on_stop();
+      on_button_stop();
       break;
     }
     default:
@@ -131,7 +131,7 @@
   return true;
 }
 
-void PlayerWindow::on_play()
+void PlayerWindow::on_button_play()
 {
   m_progress_scale.set_sensitive(true);
   m_play_button.set_sensitive(false);
@@ -153,7 +153,7 @@
   m_main_pipeline->set_state(Gst::STATE_PLAYING);
 }
  
-void PlayerWindow::on_pause()
+void PlayerWindow::on_button_pause()
 {
   m_play_button.set_sensitive(true);
   m_pause_button.set_sensitive(false);
@@ -168,7 +168,7 @@
   m_main_pipeline->set_state(Gst::STATE_PAUSED);
 }
  
-void PlayerWindow::on_stop()
+void PlayerWindow::on_button_stop()
 {
   m_progress_scale.set_sensitive(false);
   m_play_button.set_sensitive(true);
@@ -206,7 +206,7 @@
   }
 }
 
-void PlayerWindow::on_rewind()
+void PlayerWindow::on_button_rewind()
 {
   static const gint64 skipAmount = GST_SECOND * 2;
 
@@ -227,7 +227,7 @@
   }
 }
 
-void PlayerWindow::on_forward()
+void PlayerWindow::on_button_forward()
 {
   static const gint64 skipAmount = GST_SECOND * 3;
 
@@ -263,9 +263,9 @@
   }
 }
 
-void PlayerWindow::on_open()
+void PlayerWindow::on_button_open()
 {
-  static Glib::ustring workingDir = Glib::get_home_dir();
+  Glib::ustring workingDir = Glib::get_home_dir();
   
   Gtk::FileChooserDialog chooser(*this,
             "Select ogg file", Gtk::FILE_CHOOSER_ACTION_OPEN);
@@ -286,9 +286,10 @@
   {
     workingDir = chooser.get_current_folder();
 
-    // Set filename property on the file source. Also add a message handler:
+    // Set filename property on the file source. 
+    // TODO: Create a FileSrc class that we can dynamic_cast<> to, so we can use property_location()?
     m_source_element->set_property("location", chooser.get_filename());
-    set_title(Glib::filename_display_basename(chooser.get_filename()));
+    set_title( Glib::filename_display_basename(chooser.get_filename()) );
 
     m_play_button.set_sensitive(true);
     display_label_progress(0, 0);

Modified: gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.h
==============================================================================
--- gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.h	(original)
+++ gstreamermm/trunk/examples/ogg_player_gtkmm/player_window.h	Sat May 17 08:25:02 2008
@@ -41,13 +41,13 @@
 
   //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();
+  void on_button_play();
+  void on_button_pause();
+  void on_button_stop();
   bool on_scale_value_changed(Gtk::ScrollType type, double value);
-  void on_rewind();
-  void on_forward();
-  void on_open();
+  void on_button_rewind();
+  void on_button_forward();
+  void on_button_open();
 
   bool update_stream_progress();
   void display_label_progress(gint64 pos, gint64 len);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]