[gstreamermm: 115/167] improved {add|remove}_probe methods in pads, improved ogg_player example



commit 3b15234505116dadafbb449b5bc17242ca9b26b3
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Thu Aug 1 17:29:44 2013 +0200

    improved {add|remove}_probe methods in pads, improved ogg_player example

 examples/ogg_player/main.cc |   10 +++++-----
 gstreamer/src/pad.ccg       |   40 ++++++++++++----------------------------
 gstreamer/src/pad.hg        |   12 +++---------
 3 files changed, 20 insertions(+), 42 deletions(-)
---
diff --git a/examples/ogg_player/main.cc b/examples/ogg_player/main.cc
index b86572f..e217dc1 100644
--- a/examples/ogg_player/main.cc
+++ b/examples/ogg_player/main.cc
@@ -111,12 +111,12 @@ void on_parser_pad_added(const Glib::RefPtr<Gst::Pad>& newPad)
   }
 }
 
-GstPadProbeReturn on_sink_pad_have_data(GstPad *pad, GstPadProbeInfo* info, gpointer user_date)
+Gst::PadProbeReturn on_sink_pad_have_data(const Glib::RefPtr<Gst::Pad>& pad, GstPadProbeInfo* info)
 {
-  std::cout << "Sink pad has received data;";
+  std::cout << "Sink pad '" << pad->get_name() << "' has received data;";
   std::cout << " will now remove sink data probe id: " << data_probe_id << std::endl;
-  gst_pad_remove_probe(pad, data_probe_id);
-  return GST_PAD_PROBE_OK;
+  pad->remove_probe(data_probe_id);
+  return Gst::PAD_PROBE_OK;
 }
 
 } // anonymous namespace
@@ -176,7 +176,7 @@ int main(int argc, char** argv)
 
   Glib::RefPtr<Gst::Pad> pad = sink->get_static_pad("sink");
   if(pad)
-    data_probe_id = pad->add_probe(Gst::PAD_PROBE_TYPE_DATA_DOWNSTREAM, on_sink_pad_have_data, 0, 0);
+    data_probe_id = pad->add_probe(Gst::PAD_PROBE_TYPE_DATA_DOWNSTREAM, 
sigc::ptr_fun(&on_sink_pad_have_data));
 
   std::cout << "sink data probe id = " << data_probe_id << std::endl;
 
diff --git a/gstreamer/src/pad.ccg b/gstreamer/src/pad.ccg
index 66ef3db..a318acc 100644
--- a/gstreamer/src/pad.ccg
+++ b/gstreamer/src/pad.ccg
@@ -33,46 +33,25 @@ namespace
 
 extern "C"
 {
-
-static void Pad_Block_gstreamermm_callback(GstPad* pad, gboolean blocked, void* data)
+static GstPadProbeReturn Pad_Probe_gstreamermm_callback(GstPad* pad, GstPadProbeInfo* probe_info, void* data)
 {
-  Gst::Pad::SlotBlock * the_slot = static_cast<Gst::Pad::SlotBlock*>(data);
+  Gst::Pad::SlotProbe* the_slot = static_cast<Gst::Pad::SlotProbe*>(data);
 
   try
   {
-    (*the_slot)(Glib::wrap(pad), blocked);
-    delete the_slot;
+      return static_cast<GstPadProbeReturn>((*the_slot)(Glib::wrap(pad, true), probe_info));
   }
   catch(...)
   {
     Glib::exception_handlers_invoke();
   }
-}
 
-static void Pad_Block_gstreamermm_callback_destroy(void* data)
-{
-  delete static_cast<Gst::Pad::SlotBlock*>(data);
+  return GST_PAD_PROBE_DROP;
 }
 
-static gboolean Pad_Data_gstreamermm_callback(GstPad* pad, GstMiniObject* mini_obj, void* data)
+static void Pad_Probe_gstreamermm_callback_disconnect(void* data)
 {
-  Gst::Pad::SlotData* the_slot = static_cast<Gst::Pad::SlotData*>(data);
-
-  try
-  {
-    return (*the_slot)(Glib::wrap(pad, true), Glib::wrap(mini_obj, true));
-  }
-  catch(...)
-  {
-    Glib::exception_handlers_invoke();
-  }
-
-  return false;
-}
-
-static void Pad_Data_gstreamermm_callback_disconnect(void* data)
-{
-  Gst::Pad::SlotData* the_slot = static_cast<Gst::Pad::SlotData*>(data);
+  Gst::Pad::SlotProbe* the_slot = static_cast<Gst::Pad::SlotProbe*>(data);
 
   if(the_slot)
     delete the_slot;
@@ -115,6 +94,12 @@ Pad::Pad(const Glib::RefPtr<const Gst::PadTemplate>& templ)
       "construct pad from null template.");
 }
 
+gulong Pad::add_probe(PadProbeType mask, const SlotProbe& slot)
+{
+    SlotProbe* slot_copy = new SlotProbe(slot);
+    return gst_pad_add_probe(gobj(), static_cast<GstPadProbeType>(mask), &Pad_Probe_gstreamermm_callback, 
slot_copy, &Pad_Probe_gstreamermm_callback_disconnect);
+}
+
 // This is handcoded because the documentation tells us that we need to copy
 // the Caps
 Glib::RefPtr<const Gst::Caps> Pad::get_pad_template_caps() const
@@ -176,7 +161,6 @@ bool Pad::query_duration(Format& format) const
 
 FlowReturn Pad::chain(Glib::RefPtr<Gst::Buffer>& buffer)
 {
-  GstBuffer *buffer_gobj = buffer->gobj();
   buffer->reference();  //hold reference for gst_pad_chain()
   buffer.reset();       //free caller's reference
   return FlowReturn(gst_pad_chain(gobj(), buffer->gobj()));
diff --git a/gstreamer/src/pad.hg b/gstreamer/src/pad.hg
index a58dccb..3db833f 100644
--- a/gstreamer/src/pad.hg
+++ b/gstreamer/src/pad.hg
@@ -47,6 +47,7 @@ _WRAP_ENUM(PadFlags, GstPadFlags)
 _WRAP_ENUM(PadLinkReturn, GstPadLinkReturn)
 _WRAP_ENUM(PadLinkCheck, GstPadLinkCheck)
 _WRAP_ENUM(PadProbeType, GstPadProbeType)
+_WRAP_ENUM(PadProbeReturn, GstPadProbeReturn)
 
 /** A class that represents objects contained by elements that allows links to
  * other elements.
@@ -112,17 +113,10 @@ protected:
 
 public:
   /** For example,
-   * void on_block(const Glib::RefPtr<Gst::Pad>& pad, bool blocked);.
-   */
-  typedef sigc::slot<void, const Glib::RefPtr<Gst::Pad>&, bool> SlotBlock;
-
-  /** For example,
    * bool on_have_data(const Glib::RefPtr<Gst::Pad>& pad, const
    * Glib::RefPtr<Gst::MiniObjec>& data);.
-   * The data method should return true to keep the data in the pipeline, false
-   * to drop it (throw it away).
    */
-  typedef sigc::slot< bool, const Glib::RefPtr<Gst::Pad>&, const Glib::RefPtr<Gst::MiniObject>& > SlotData;
+  typedef sigc::slot< PadProbeReturn, const Glib::RefPtr<Gst::Pad>&, GstPadProbeInfo* > SlotProbe;
 
   typedef sigc::slot< Gst::FlowReturn, const Glib::RefPtr<Gst::Pad>&, Glib::RefPtr<Gst::Buffer>& > SlotChain;
 
@@ -187,7 +181,7 @@ public:
   Glib::RefPtr<const Gst::Caps> get_pad_template_caps() const;
   _IGNORE(gst_pad_get_pad_template_caps)
 
-  _WRAP_METHOD(gulong add_probe(PadProbeType mask, GstPadProbeCallback callback, gpointer userdata, 
GDestroyNotify notify), gst_pad_add_probe)
+  gulong add_probe(PadProbeType mask, const SlotProbe& slot);
   _WRAP_METHOD(void remove_probe(gulong id), gst_pad_remove_probe)
 
 


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