[gstreamermm] BaseSrc: Wrap the virtual functions.



commit 96c2a371bf2758fbed0c66de1a6a3c28860f8278
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Wed May 4 23:49:44 2011 -0400

    BaseSrc: Wrap the virtual functions.
    
    	* gstreamer/src/basesrc.hg: Wrap the boolean virtual functions that
    	were commented out.
    
    	* tests/Makefile.am:
    	* tests/test-base-src.cc: Added a small test to make sure that the
    	newly wrapped virtual functions do not cause execution errors.  The
    	AlsaSrc element derives from BaseSrc and if there were problems with
    	the virtual functions they would most likely show up while using that
    	element.  Carlo Wood should be thanked for providing a similar example
    	on the list.  This test was adapted from his sources.  Thanks Carlo.

 ChangeLog                |   15 +++++++
 gstreamer/src/basesrc.hg |   96 ++++++++++++++++++++--------------------------
 tests/Makefile.am        |    3 +-
 tests/test-base-src.cc   |   96 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ed571ad..38b83e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2011-05-04  José Alburquerque  <jaalburqu svn gnome org>
+
+	BaseSrc: Wrap the virtual functions.
+
+	* gstreamer/src/basesrc.hg: Wrap the boolean virtual functions that
+	were commented out.
+
+	* tests/Makefile.am:
+	* tests/test-base-src.cc: Added a small test to make sure that the
+	newly wrapped virtual functions do not cause execution errors.  The
+	AlsaSrc element derives from BaseSrc and if there were problems with
+	the virtual functions they would most likely show up while using that
+	element.  Carlo Wood should be thanked for providing a similar example
+	on the list.  This test was adapted from his sources.  Thanks Carlo.
+
 2011-04-28  José Alburquerque  <jaalburqu svn gnome org>
 
 	Mixer: Use std::vector<> instead of Glib::[Array|List]Handle<>.
diff --git a/gstreamer/src/basesrc.hg b/gstreamer/src/basesrc.hg
index 380d8cf..01fb823 100644
--- a/gstreamer/src/basesrc.hg
+++ b/gstreamer/src/basesrc.hg
@@ -174,31 +174,26 @@ public:
   _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> get_caps() const, "get_caps")
 
 #m4 _CONVERSION(`GstCaps*', `const Glib::RefPtr<Gst::Caps>&', `Glib::wrap($3, true)')
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Notify subclass of changed output caps.
-   //*/
-  //_WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
+  /** Notify subclass of changed output caps.
+   */
+  _WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Negotiated the caps with the peer.
-   //*/
-  //_WRAP_VFUNC(bool negotiate(), "negotiate")
+  /** Negotiated the caps with the peer.
+   */
+  _WRAP_VFUNC(bool negotiate(), "negotiate")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Generate and send a new_segment event (UNUSED).
-   //*/
-  //_WRAP_VFUNC(bool new_segment(), "newsegment")
+  /** Generate and send a new_segment event (UNUSED).
+   */
+  _WRAP_VFUNC(bool new_segment(), "newsegment")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Start processing. Subclasses should open resources and prepare to produce
-   //* data.
-   //*/
-  //_WRAP_VFUNC(bool start(), "start")
+  /** Start processing. Subclasses should open resources and prepare to produce
+   * data.
+   */
+  _WRAP_VFUNC(bool start(), "start")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Stop processing. Subclasses should use this to close resources.
-   //*/
-  //_WRAP_VFUNC(bool stop(), "stop")
+  /** Stop processing. Subclasses should use this to close resources.
+   */
+  _WRAP_VFUNC(bool stop(), "stop")
 
 #m4 _CONVERSION(`GstBuffer*', `const Glib::RefPtr<Gst::Buffer>&', `Gst::wrap($3, true)')
 #m4 _CONVERSION(`GstClockTime*', `ClockTime&', `*($3)')
@@ -209,27 +204,23 @@ public:
 
 #m4 _CONVERSION(`guint64&', `guint64*', `&($3)')
 #m4 _CONVERSION(`guint64*', `guint64&', `*($3)')
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Return the total size of the resource, in the configured format.
-   //*/
-  //_WRAP_VFUNC(bool get_size(guint64& size) const, "get_size")
+  /** Return the total size of the resource, in the configured format.
+   */
+  _WRAP_VFUNC(bool get_size(guint64& size) const, "get_size")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Check if the source can seek.
-   //*/
-  //_WRAP_VFUNC(bool is_seekable() const, "is_seekable")
+  /** Check if the source can seek.
+   */
+  _WRAP_VFUNC(bool is_seekable() const, "is_seekable")
 
-  ///** Unlock any pending access to the resource. Subclasses should unblock any
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-   //* blocked function ASAP.
-   //*/
-  //_WRAP_VFUNC(bool unlock(), "unlock")
+  /** Unlock any pending access to the resource. Subclasses should unblock any
+   * blocked function ASAP.
+   */
+  _WRAP_VFUNC(bool unlock(), "unlock")
 
 #m4 _CONVERSION(`GstEvent*', `const Glib::RefPtr<Gst::Event>&', `Gst::wrap($3, true)')
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Override this to implement custom event handling.
-   //*/
-  //_WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
+  /** Override this to implement custom event handling.
+   */
+  _WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
 
   virtual FlowReturn create_vfunc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer);
 
@@ -238,30 +229,27 @@ public:
   virtual bool do_seek_vfunc(Gst::Segment& segment); 
 
 #m4 _CONVERSION(`GstQuery*', `const Glib::RefPtr<Gst::Query>&', `Gst::wrap($3, true)')
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Handle a requested query.
-   //*/
+  /** Handle a requested query.
+   */
   //_WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query) const, "query")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Check whether the source would support pull-based operation if it were to
-   //* be opened now. This vfunc is optional, but should be implemented if
-   //* possible to avoid unnecessary start/stop cycles. The default
-   //* implementation will open and close the resource to find out whether
-   //* get_range() is supported, and that is usually undesirable.
-   //*/
-  //_WRAP_VFUNC(bool check_get_range(), "check_get_range")
+  /** Check whether the source would support pull-based operation if it were to
+   * be opened now. This vfunc is optional, but should be implemented if
+   * possible to avoid unnecessary start/stop cycles. The default
+   * implementation will open and close the resource to find out whether
+   * get_range() is supported, and that is usually undesirable.
+   */
+  _WRAP_VFUNC(bool check_get_range(), "check_get_range")
 
   /** Called during negotiation if caps need fixating. Implement instead of
    * setting a fixate function on the source pad.
    */
   _WRAP_VFUNC(void fixate(const Glib::RefPtr<Gst::Caps>& caps), "fixate")
 
-  //TODO: Make sure this bool vfunc does not cause execution problems.
-  ///** Clear the previous unlock request. Subclasses should clear any state they
-   //* set during unlock_vfunc(), such as clearing command queues.
-   //*/
-  //_WRAP_VFUNC(bool unlock_stop(), "unlock_stop")
+  /** Clear the previous unlock request. Subclasses should clear any state they
+   * set during unlock_vfunc(), such as clearing command queues.
+   */
+  _WRAP_VFUNC(bool unlock_stop(), "unlock_stop")
 
   /** Prepare the Gst::Segment that will be passed to the do_seek_vfunc()
    * vmethod for executing a seek request. Sub-classes should override this if
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0f04966..6957365 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@ check_PROGRAMS = test-caps test-create-element test-pipeline-add-element \
                  test-ghost-pad test-init-check test-init \
                  test-init-check-noargs test-init-noargs test-iterator \
                  test-property-caps test-plugin-gen test-plugin-signals \
-                 test-buffer-list-iterator
+                 test-buffer-list-iterator test-base-src
 
 # Include run of test programs in check:
 TESTS = $(check_PROGRAMS)
@@ -59,3 +59,4 @@ test_property_caps_SOURCES		= test-property-caps.cc
 test_plugin_gen_SOURCES			= test-plugin-gen.cc
 test_plugin_signals_SOURCES		= test-plugin-signals.cc
 test_buffer_list_iterator_SOURCES	= test-buffer-list-iterator.cc
+test_base_src_SOURCES			= test-base-src.cc
diff --git a/tests/test-base-src.cc b/tests/test-base-src.cc
new file mode 100644
index 0000000..3f9f1ec
--- /dev/null
+++ b/tests/test-base-src.cc
@@ -0,0 +1,96 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2011 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm.h>
+#include <iostream>
+
+void print_info(const Glib::RefPtr<Gst::Mixer>& mixer)
+{
+  typedef std::vector< Glib::RefPtr<Gst::MixerTrack> > tracks_type;
+
+  tracks_type tracks = mixer->list_tracks();
+
+  for(tracks_type::iterator iter = tracks.begin(); iter != tracks.end();
+    ++iter)
+  {
+    Glib::RefPtr<const Gst::MixerTrack> track = *iter;
+
+    Glib::ustring label = track->get_label();
+
+    bool const is_microphone = !label.compare("Mic") ||
+      !label.compare(0, 4, "Mic ") || !label.compare(0, 10, "Microphone");
+
+    bool const has_channels = track->get_num_channels() > 0;
+
+    std::cout << label;
+
+    if (is_microphone)
+      std::cout << " [MICROPHONE]";
+
+    if (has_channels)
+    {
+      std::vector<int> volumes = mixer->get_volume(track);
+
+      for (std::vector<int>::iterator volume_iter = volumes.begin();
+        volume_iter != volumes.end(); ++volume_iter)
+      {
+        std::cout << ' ' << *volume_iter;
+      }
+    }
+
+    guint flags = track->property_flags();
+
+    if ((flags & Gst::MIXER_TRACK_INPUT))
+      std::cout << " [input]";
+
+    if ((flags & Gst::MIXER_TRACK_OUTPUT))
+      std::cout << " [output]";
+
+    if ((flags & Gst::MIXER_TRACK_MUTE))
+      std::cout << " [muted]";
+
+    if ((flags & Gst::MIXER_TRACK_RECORD))
+      std::cout << " [CAPTURE]";
+
+    std::cout << std::endl;
+  }
+}
+
+int main(int argc, char** argv)
+{
+  Gst::init(argc, argv);
+
+  Glib::RefPtr<Gst::AlsaSrc> alsasrc = Gst::AlsaSrc::create("alsasrc");
+
+  if(!alsasrc)
+  {
+    std::cout << "Could not create the alsarc element." << std::endl;
+    return 1;
+  }
+
+  // Must set the state of the alsasrc to ready before using it.
+  alsasrc->set_state(Gst::STATE_READY);
+
+  print_info(alsasrc);
+
+  // Also go back to the NULL state before it is freed.
+  alsasrc->set_state(Gst::STATE_NULL);
+
+  return 0;
+}



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