[gstreamermm] Gst::Bus: fix post method



commit 93ac4c76d86fcc79dccb995f224553cd8f79633f
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Fri Feb 27 19:31:21 2015 +0100

    Gst::Bus: fix post method
    
        * gstreamer/src/bus.{ccg|hg}: post method takes message argument,
          which is fully transfered to this method. User should be able to
          pass object with refcount equals 1, so message RefPtr is reseting
          inside this method. To access to object even after post method call,
          new RefPtr object should be created. E.g.:
    
              RefPtr<Message> msg = MessageEos::create(RefPtr<Object>());
              RefPtr<Message> msg2 = msg;
              bus->post(msg);
              msg2->get_refcount(); // still have access to msg gobj through
                                    // msg2 RefPtr. Refcount equals 1

 gstreamer/src/bus.ccg |    7 +++++++
 gstreamer/src/bus.hg  |   12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gstreamer/src/bus.ccg b/gstreamer/src/bus.ccg
index 74d3159..3aab995 100644
--- a/gstreamer/src/bus.ccg
+++ b/gstreamer/src/bus.ccg
@@ -86,6 +86,13 @@ bool Bus::remove_watch(guint id)
   return g_source_remove(id);
 }
 
+bool Bus::post(Glib::RefPtr<Gst::Message>& message)
+{
+  GstMessage* msg = message->gobj();
+  message->reference(); message.reset();
+  return gst_bus_post(gobj(), msg);
+}
+
 void Bus::set_sync_handler(const SlotMessageSync& slot)
 {
   // Clear a possibly existing sync handler by calling with 0 before setting
diff --git a/gstreamer/src/bus.hg b/gstreamer/src/bus.hg
index 99e2695..7edc7ee 100644
--- a/gstreamer/src/bus.hg
+++ b/gstreamer/src/bus.hg
@@ -111,7 +111,17 @@ public:
    */
   _WRAP_CREATE()
 
-  _WRAP_METHOD(bool post(const Glib::RefPtr<Gst::Message>& message), gst_bus_post)
+  /** Post a message on the given bus. Ownership of the message
+   * is taken by the bus.
+   *
+   * @param message The Gst::Message to post. RefPtr is reset inside method.
+   * @return <tt>true</tt> if the message could be posted, <tt>false</tt> if the bus is flushing.
+   *
+   * MT safe.
+   */
+  bool post(Glib::RefPtr<Gst::Message>& message);
+  _IGNORE(gst_bus_post)
+
   _WRAP_METHOD(bool have_pending() const, gst_bus_have_pending)
   _WRAP_METHOD(Glib::RefPtr<Gst::Message> peek(), gst_bus_peek)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Message> peek() const, gst_bus_peek)


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