[gstreamermm] Examples: Fix the media player example for MinGW.



commit 1b92757df2cf1180c5acb25fa88f4598afcaa885
Author: Josà Alburquerque <jaalburqu svn gnome org>
Date:   Wed Aug 15 23:06:58 2012 -0400

    Examples: Fix the media player example for MinGW.
    
    	* examples/media_player_gtkmm/main.cc:
    	* examples/media_player_gtkmm/player_window.cc:
    	* examples/media_player_gtkmm/player_window.h: Modify the code to not
    	use the XImageSink plugin (which is is specific to the Linux
    	Platform).  Also include gdk/gdkwin32.h instead of gdk/gdkx.h when
    	compiling for the Windows platform.

 ChangeLog                                    |   11 ++++
 examples/media_player_gtkmm/main.cc          |   18 +------
 examples/media_player_gtkmm/player_window.cc |   76 +++++++++++++++-----------
 examples/media_player_gtkmm/player_window.h  |    7 +--
 4 files changed, 58 insertions(+), 54 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 33a35c8..a739ecc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-08-15  Josà Alburquerque  <jaalburquerque gmail com>
+
+	Examples: Fix the media player example for MinGW.
+
+	* examples/media_player_gtkmm/main.cc:
+	* examples/media_player_gtkmm/player_window.cc:
+	* examples/media_player_gtkmm/player_window.h: Modify the code to not
+	use the XImageSink plugin (which is is specific to the Linux
+	Platform).  Also include gdk/gdkwin32.h instead of gdk/gdkx.h when
+	compiling for the Windows platform.
+
 2012-07-30  Josà Alburquerque  <jaalburquerque gmail com>
 
 	Object: Add getter methods for the GMutex lock member.
diff --git a/examples/media_player_gtkmm/main.cc b/examples/media_player_gtkmm/main.cc
index b52b9fa..4df0f8d 100644
--- a/examples/media_player_gtkmm/main.cc
+++ b/examples/media_player_gtkmm/main.cc
@@ -19,12 +19,9 @@
 #include <gtkmm/main.h>
 #include <gstreamermm/init.h>
 #include <gstreamermm/element.h>
-#include <gstreamermm/pad.h>
-#include <gstreamermm/pipeline.h>
 
 // Plug-ins:
 #include <gstreamermm/playbin2.h>
-#include <gstreamermm/ximagesink.h>
 
 #include <iostream>
 #include "player_window.h"
@@ -46,21 +43,8 @@ int main(int argc, char** argv)
     return 1;
   }
 
-  // Create a video sink where video (if any) will be drawn:
-  Glib::RefPtr<Gst::XImageSink> video_sink =
-                        Gst::XImageSink::create("ximagesink");
-  if(!video_sink)
-  {
-    std::cerr << "The ximagesink could not be created." << std::endl;
-    return 1;
-  }
-
-  // Set the playbin's video-sink property so that our video sink is used
-  // for video display:
-  playbin->property_video_sink() = video_sink;
-
   //Create our player window and give it the pipeline and video sink:
-  PlayerWindow mainWindow(playbin, video_sink);
+  PlayerWindow mainWindow(playbin);
   kit.run(mainWindow);
 
   // Clean up nicely:
diff --git a/examples/media_player_gtkmm/player_window.cc b/examples/media_player_gtkmm/player_window.cc
index 37b467d..719594f 100644
--- a/examples/media_player_gtkmm/player_window.cc
+++ b/examples/media_player_gtkmm/player_window.cc
@@ -18,7 +18,14 @@
 
 #include <gtkmm/stock.h>
 #include <gtkmm/filechooserdialog.h>
+
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_WIN32
+#include <gdk/gdkwin32.h>
+#endif
+
 #include <gstreamermm/bus.h>
 #include <gstreamermm/caps.h>
 #include <gstreamermm/clock.h>
@@ -36,8 +43,7 @@
 #include <iomanip>
 #include "player_window.h"
 
-PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::PlayBin2>& playbin,
-  const Glib::RefPtr<Gst::Element>& video_sink)
+PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::PlayBin2>& playbin)
 : m_vbox(false, 6),
   m_progress_label("000:00:00.000000000 / 000:00:00.000000000"),
   m_play_button(Gtk::Stock::MEDIA_PLAY),
@@ -108,8 +114,10 @@ PlayerWindow::PlayerWindow(const Glib::RefPtr<Gst::PlayBin2>& playbin,
   m_rewind_button.set_sensitive(false);
   m_forward_button.set_sensitive(false);
 
-  m_play_bin = playbin;
-  m_video_sink = video_sink;
+  m_playbin = playbin;
+
+  m_playbin->signal_video_changed().connect(
+    sigc::mem_fun(*this, &PlayerWindow::on_video_changed) );
 
   show_all_children();
   m_pause_button.hide();
@@ -120,7 +128,12 @@ void PlayerWindow::on_video_area_realize()
   // When the video area (the drawing area) is realized, Get its X Window
   // ID and save it for when the Gst::XOverlay is ready to accept an ID in
   // which to draw the video.
+#ifdef GDK_WINDOWING_X11
   m_x_window_id = GDK_WINDOW_XID(m_video_area.get_window()->gobj());
+#endif
+#ifdef GDK_WINDOWING_WIN32
+  m_x_window_id = GDK_WINDOW_HWND(m_video_area.get_window()->gobj());
+#endif
 }
 
 // This function is used to receive asynchronous messages from mainPipeline's
@@ -183,6 +196,20 @@ bool PlayerWindow::on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */,
   return true;
 }
 
+void PlayerWindow::on_video_changed()
+{
+  Glib::RefPtr<Gst::Pad> pad = m_playbin->get_video_pad(0);
+  if(pad)
+  {
+    // Add a buffer probe to the video sink pad which will be removed after
+    // the first buffer is received in the on_video_pad_got_buffer method.
+    // When the first buffer arrives, the video size can be extracted.
+    m_pad_probe_id = pad->add_buffer_probe(
+      sigc::mem_fun(*this, &PlayerWindow::on_video_pad_got_buffer));
+    std::cout << "There is no pad available." << std::endl;
+  }
+}
+
 bool PlayerWindow::on_video_pad_got_buffer(const Glib::RefPtr<Gst::Pad>& pad,
     const Glib::RefPtr<Gst::MiniObject>& data)
 {
@@ -236,7 +263,7 @@ void PlayerWindow::on_button_play()
     sigc::mem_fun(*this, &PlayerWindow::on_timeout), 200);
 
   // set the pipeline to play mode:
-  m_play_bin->set_state(Gst::STATE_PLAYING);
+  m_playbin->set_state(Gst::STATE_PLAYING);
 }
  
 void PlayerWindow::on_button_pause()
@@ -251,7 +278,7 @@ void PlayerWindow::on_button_pause()
   m_timeout_connection.disconnect();
   
   // Set the pipeline to pause mode:
-  m_play_bin->set_state(Gst::STATE_PAUSED);
+  m_playbin->set_state(Gst::STATE_PAUSED);
 }
  
 void PlayerWindow::on_button_stop()
@@ -271,27 +298,18 @@ void PlayerWindow::on_button_stop()
   m_timeout_connection.disconnect();
 
   // Set the pipeline to inactive mode:
-  m_play_bin->set_state(Gst::STATE_NULL);
+  m_playbin->set_state(Gst::STATE_NULL);
 
   // Reset the 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_static_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)
 {
   const gint64 newPos = gint64(value * m_duration);
 
-  if(m_play_bin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+  if(m_playbin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
   {
     display_label_progress(newPos, m_duration);
     return true;
@@ -310,11 +328,11 @@ void PlayerWindow::on_button_rewind()
   gint64 pos = 0;
   Gst::Format fmt = Gst::FORMAT_TIME;
 
-  if(m_play_bin->query_position(fmt, pos))
+  if(m_playbin->query_position(fmt, pos))
   {
     gint64 newPos = (pos > skipAmount) ? (pos - skipAmount) : 0;
 
-    if(m_play_bin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
+    if(m_playbin->seek(Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH, newPos))
     {
       m_progress_scale.set_value(double(newPos) / m_duration);
       display_label_progress(newPos, m_duration);
@@ -332,7 +350,7 @@ void PlayerWindow::on_button_forward()
 
   Glib::RefPtr<Gst::Query> query = Gst::QueryPosition::create(fmt);
 
-  if(m_play_bin->query(query))
+  if(m_playbin->query(query))
   {
     Glib::RefPtr<Gst::QueryPosition> posQuery =
       Glib::RefPtr<Gst::QueryPosition>::cast_dynamic(query);
@@ -349,7 +367,7 @@ void PlayerWindow::on_button_forward()
     Glib::RefPtr<Gst::EventSeek> seekEvent =
       Glib::RefPtr<Gst::EventSeek>::cast_dynamic(event);
 
-    if(Glib::RefPtr<Gst::Element>::cast_static(m_play_bin)->send_event(event))
+    if(Glib::RefPtr<Gst::Element>::cast_static(m_playbin)->send_event(event))
     {
       m_progress_scale.set_value(double(newPos) / m_duration);
       display_label_progress(newPos, m_duration);
@@ -376,20 +394,12 @@ void PlayerWindow::on_button_open()
     working_dir = chooser.get_current_folder();
 
     // Set uri property on the playbin.
-    m_play_bin->property_uri() = chooser.get_uri();
+    m_playbin->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_button_stop method
-    m_pad_probe_id = m_video_sink->get_static_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();
@@ -402,8 +412,8 @@ bool PlayerWindow::on_timeout()
   Gst::Format fmt = Gst::FORMAT_TIME;
   gint64 pos = 0;
 
-  if(m_play_bin->query_position(fmt, pos)
-    && m_play_bin->query_duration(fmt, m_duration))
+  if(m_playbin->query_position(fmt, pos)
+    && m_playbin->query_duration(fmt, m_duration))
   {
     m_progress_scale.set_value(double(pos) / m_duration);
     display_label_progress(pos, m_duration);
@@ -434,5 +444,5 @@ void PlayerWindow::display_label_progress(gint64 pos, gint64 len)
 
 PlayerWindow::~PlayerWindow()
 {
-  m_play_bin->get_bus()->remove_watch(m_watch_id);
+  m_playbin->get_bus()->remove_watch(m_watch_id);
 }
diff --git a/examples/media_player_gtkmm/player_window.h b/examples/media_player_gtkmm/player_window.h
index aeaf17e..b93e16a 100644
--- a/examples/media_player_gtkmm/player_window.h
+++ b/examples/media_player_gtkmm/player_window.h
@@ -35,9 +35,8 @@ class PlayerWindow : public Gtk::Window
 public:
   /**
    * @param playbin The pipeline that can play media files.
-   * @param video_sink The video sink to use to display stream video (if any).
    */
-  PlayerWindow(const Glib::RefPtr<Gst::PlayBin2>& playbin, const Glib::RefPtr<Gst::Element>& video_sink);
+  PlayerWindow(const Glib::RefPtr<Gst::PlayBin2>& playbin);
   virtual ~PlayerWindow();
 
 protected:
@@ -46,6 +45,7 @@ protected:
   void on_video_area_realize();
   void on_bus_message_sync(const Glib::RefPtr<Gst::Message>& message);
   bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message);
+  void on_video_changed();
   bool on_video_pad_got_buffer(const Glib::RefPtr<Gst::Pad>& pad, const Glib::RefPtr<Gst::MiniObject>& buffer);
 
   void on_button_play();
@@ -72,8 +72,7 @@ protected:
   Gtk::Button m_forward_button;
   Gtk::Button m_open_button;
 
-  Glib::RefPtr<Gst::PlayBin2> m_play_bin;
-  Glib::RefPtr<Gst::Element> m_video_sink;
+  Glib::RefPtr<Gst::PlayBin2> m_playbin;
   sigc::connection m_timeout_connection;
   guint m_watch_id;
   gint64 m_duration;



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