gnomemm r1500 - gstreamermm/trunk/gstreamer/src



Author: murrayc
Date: Sat May 17 14:22:18 2008
New Revision: 1500
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1500&view=rev

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

* gstreamer/src/bin.ccg:
* gstreamer/src/bin.hg: Make add() throw an exception, needed for 
chaining. The examples already try/catch this, assuming that it did 
already throw.
* gstreamer/src/element.ccg:
* gstreamer/src/element.hg: Document that link() throws an exception.
Include <stdexcept> so applications can catch runtime_error.

* examples/element_link/element_link.cc?
* examples/media_player_gtkmm/player_window.c:
* examples/ogg_player/main.cc:
* examples/ogg_player_gtkmm/player_window.cc: try/catch when using 
link(), because it throws an exception.

Modified:
   gstreamermm/trunk/gstreamer/src/bin.ccg
   gstreamermm/trunk/gstreamer/src/bin.hg
   gstreamermm/trunk/gstreamer/src/element.ccg
   gstreamermm/trunk/gstreamer/src/element.hg
   gstreamermm/trunk/gstreamer/src/message.hg

Modified: gstreamermm/trunk/gstreamer/src/bin.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/bin.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/bin.ccg	Sat May 17 14:22:18 2008
@@ -32,38 +32,34 @@
 
 Glib::RefPtr<Bin> Bin::add(const Glib::RefPtr<Element>& element)
 {
-  bool result = gst_bin_add(gobj(), element->gobj());
+  const bool result = gst_bin_add(gobj(), element->gobj());
 
   // If addition successful, return RefPtr<..> to this bin, otherwise return
   // NULL RefPtr<...>
-  if(result) {
-
+  if(result)
+  {
     // When adding an element to a bin, an extra ref is needed because bin
     // takes ownership of element and wants to unref the element itself when
-    // the bin is destroyed.  Without ref, when RefPtr tries to unref the last
-    // reference a warning is issued.  Even with extra ref, element is
-    // destroyed when bin unrefs the element when the bin is completely
-    // unreffed and all RefPtrs unref element.  Removing element from the bin
-    // will also get rid of the extra ref (gst_bin_remove() does this)
+    // the bin is destroyed.
     element->reference();
 
     return Glib::wrap(gobj(), true);
   }
   else
-    return Glib::RefPtr<Bin>(0);
+    throw std::runtime_error("Failed to add " + element->get_name() + " element");
 }
 
 Glib::RefPtr<Bin> Bin::remove(const Glib::RefPtr<Element>& element)
 {
-  bool result = gst_bin_remove(gobj(), element->gobj());
+  const bool result = gst_bin_remove(gobj(), element->gobj());
 
   // If removal successful, return RefPtr<..> to this bin, otherwise return
   // NULL RefPtr<...>
-  if(result) {
+  if(result)
     return Glib::wrap(gobj(), true);
-  }
   else
     return Glib::RefPtr<Bin>(0);
 }
 
 } //namespace Gst
+

Modified: gstreamermm/trunk/gstreamer/src/bin.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/bin.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/bin.hg	Sat May 17 14:22:18 2008
@@ -22,6 +22,7 @@
 #include <gstreamermm/element.h>
 #include <gstreamermm/childproxy.h>
 #include <gstreamermm/pad.h>
+#include <stdexcept> //Because add() throws std::runtime_error.
 
 _DEFS(gstreamermm,gst)
 
@@ -139,17 +140,19 @@
    */
   _WRAP_CREATE(const Glib::ustring& name)
 
-  /** Adds the given element to the bin. Sets the element's parent, and thus
-   * takes ownership of the element. An element can only be added to one bin.
+  /** Adds the given element to the bin.
+   * This sets the element's parent, and thus takes ownership of the element.
+   * An element can only be added to one bin.
    *
-   * If the element's pads are linked to other pads, the pads will be unlinked
+   * If the element's pads are linked to other pads then the pads will be unlinked
    * before the element is added to the bin.
    *
    * MT safe.
    *
-   * @param element the Gst::Element to add
-   * @return this Gst::Bin if successful (for further adding if wanted), NULL
-   * otherwise
+   * @param element The Gst::Element to add.
+   * @return this Gst::Bin if successful, for chained calls to add().
+   *
+   * @throws std::runtime_error if the Bin does not want to accept the Element.
    */
   Glib::RefPtr<Bin> add(const Glib::RefPtr<Element>& element);
 

Modified: gstreamermm/trunk/gstreamer/src/element.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/element.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/element.ccg	Sat May 17 14:22:18 2008
@@ -54,15 +54,14 @@
   return gst_element_state_change_return_get_name(GstStateChangeReturn(s));
 }
 
-Glib::RefPtr<Element>
-Element::link(const Glib::RefPtr<Element>& other_element)
+Glib::RefPtr<Element> Element::link(const Glib::RefPtr<Element>& other_element)
 {
   bool result = gst_element_link(gobj(), other_element->gobj());
 
   if(result)
     return other_element;
   else
-    throw std::runtime_error("failed to link: " + get_name() + "->" + other_element->get_name() + "!\n");
+    throw std::runtime_error("failed to link: " + get_name() + "->" + other_element->get_name());
 }
 
 Glib::RefPtr<Pad> Element::get_compatible_pad(const Glib::RefPtr<Pad>& pad, const Glib::RefPtr<Caps>& caps)

Modified: gstreamermm/trunk/gstreamer/src/element.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/element.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/element.hg	Sat May 17 14:22:18 2008
@@ -26,6 +26,7 @@
 #include <gstreamermm/event.h>
 #include <gstreamermm/message.h>
 #include <gstreamermm/query.h>
+#include <stdexcept> //Because link() throws std::runtime_error
 
 _DEFS(gstreamermm,gst)
 
@@ -124,7 +125,10 @@
   _CTOR_DEFAULT
 
 public:
-  //TODO Add const version?
+  /** TODO: Documentation
+   *
+   * @throws std::runtime_error
+   */
   Glib::RefPtr<Element> link(const Glib::RefPtr<Element>& other_element);
 
   _WRAP_METHOD(bool add_pad(const Glib::RefPtr<Pad>& pad), gst_element_add_pad)

Modified: gstreamermm/trunk/gstreamer/src/message.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/message.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/message.hg	Sat May 17 14:22:18 2008
@@ -91,6 +91,8 @@
   explicit MessageClockProvide(GstMessage *message);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, const Glib::RefPtr<Clock>& clock, bool ready);
+
+  //TODO: Use clock as return type?
   void parse(Glib::RefPtr<Clock>& clock, bool& ready);
 };
 
@@ -100,6 +102,8 @@
   explicit MessageClockLost(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, const Glib::RefPtr<Clock>& clock);
+
+  //TODO: Use clock as return type?
   void parse(Glib::RefPtr<Clock>& clock);
 };
 
@@ -133,6 +137,8 @@
   explicit MessageError(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Glib::Error& error, const std::string& debug);
+
+  //TODO: Use error as return type?
   void parse(Glib::Error& error, std::string& debug);
   void parse(Glib::Error& error);
 };
@@ -143,6 +149,8 @@
   explicit MessageInfo(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Glib::Error& error, const std::string& debug);
+
+  //TODO: Use error as return type?
   void parse(Glib::Error& error, std::string& debug);
   void parse(Glib::Error& error);
 };
@@ -153,6 +161,8 @@
   explicit MessageNewClock(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, const Glib::RefPtr<Clock>& clock);
+
+  //TODO: Use clock as return type?
   void parse(Glib::RefPtr<Clock>& clock);
 };
 
@@ -162,6 +172,8 @@
   explicit MessageSegmentDone(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Format format, gint64 position);
+
+  //TODO: Use something as return type?
   void parse(Format& format, gint64& position);
 };
 
@@ -171,6 +183,8 @@
   explicit MessageSegmentStart(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Format format, gint64 position);
+
+  //TODO: Use something as return type?
   void parse(Format& format, gint64& position);
 };
 
@@ -180,6 +194,8 @@
   explicit MessageStateChanged(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, State oldstate, State newstate, State pending);
+
+  //TODO: Use something as return type?
   void parse(State& oldstate, State& newstate, State& pending);
 };
 
@@ -189,6 +205,8 @@
   explicit MessageTag(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, TagList& taglist);
+
+  //TODO: Use something as return type?
   void parse(TagList& taglist);
 };
 
@@ -198,6 +216,8 @@
   explicit MessageBuffering(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, int percent);
+
+  //TODO: Use percent as return type?
   void parse(int& percent);
 };
 
@@ -207,6 +227,8 @@
   explicit MessageWarning(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Glib::Error& error, const std::string& debug);
+
+  //TODO: Use error as return type?
   void parse(Glib::Error& error, std::string& debug);
 };
 
@@ -216,6 +238,8 @@
   explicit MessageDuration(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, Format format, gint64 position);
+
+  //TODO: Use something as return type?
   void parse(Format& format, gint64& position);
 };
 
@@ -233,6 +257,8 @@
   explicit MessageAsyncStart(GstMessage* castitem);
 
   static Glib::RefPtr<Message> create(const Glib::RefPtr<Object>& src, bool new_base_time);
+
+  //TODO: Use new_base_time as return type?
   void parse(bool& new_base_time);
 };
 



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