Re: gstmm add element to pipeline test



Murray Cumming wrote:
On Fri, 2007-11-30 at 12:20 -0500, José Alburquerque wrote:
José Alburquerque wrote:
I'm not able to check this patch in (if it's good).

-Jose
I thought I should also include a test to link several elements so if you check this in, would you use this new patch instead? Thanks.

Committed. Thanks.

Thanks.

Milosz, could you give svn write access to José? He clearly knows what
he's doing.

BTW, I just finished adding the message signal of the Gst::Bus class. I was able to run the neat vorbis player in section 10.1 of the GStreamer Application Development Manual <http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/index.html> (written in C++ and included with this e-mail) successfully. These are the changes I've made (from the changelog) which I'll check in as soon as you enable access (unless you want to check these in, in which case I've included the patch):

   * gst/src/bus.hg: added signal "message"
   * gst/src/gst_signals.defs: sync-message and message had wrong
   parameter type (GstMessage instead of GstMessage*)
   * gst/src/message.hg: changed get_type() to be public
   * gst/src/pipeline.ccg: modified Gst::Pipeline::create() to call
   gst_bus_add_signal_watch() so Bus transmits "message" signal
   * tests/Makefile.am: modified to include test-create-bin
   * tests/test-create-bin.cc: added this test to create a bin and add
   elements to it (to "catch" errors as API changes)
   * tests/test-link-elements.cc: Removed a blank line
   * tools/m4/convert_gst.m4: Added conversion from GstMessageType to
   Gst::MessageType (for Gst::Message::get_type())

Thanks.

-Jose
#include <iostream>
#include <gstmm.h>

using namespace Glib;
using namespace Gst;
using namespace std;

void bus_message_received(const RefPtr<Message>& message,
RefPtr<MainLoop> mainLoop)
{
  switch (message->get_type()) {
    case MESSAGE_EOS:
      cout << "End of stream" << endl;
      mainLoop->quit();
      break;
    case MESSAGE_ERROR:
      cerr << "Error." << endl;
      mainLoop->quit();
      break;
    default:
      break;
  }
}

void parser_pad_added(const RefPtr<Pad>& newPad, RefPtr<Element> decoder)
{
  cout << "Dynamic pad created, linking parser/decoder." << endl;
  RefPtr<Pad> sinkPad = decoder->get_pad("sink");
  newPad->link(sinkPad);
}

int main(int argc, char* argv[]) {
  if (argc != 2) {
    cout << "Usage: " << argv[0] << " <Ogg/Vorbis filename>" << endl;
    return -1;
  }

  Gst::init(argc, argv);
  RefPtr<MainLoop> mainLoop = Glib::MainLoop::create();

  /* create elements */
  RefPtr<Pipeline> pipeline = Gst::Pipeline::create("audio-player");
  RefPtr<Element> source = Gst::Element::create("filesrc", "file-source");
  RefPtr<Element> parser = Gst::Element::create("oggdemux", "ogg-parser");
  RefPtr<Element> decoder = Gst::Element::create("vorbisdec", "vorbis-decoder");
  RefPtr<Element> conv = Gst::Element::create("audioconvert", "converter");
  RefPtr<Element> sink = Gst::Element::create("alsasink", "alsa-output");

  if (!pipeline || !source || !parser || !decoder || !conv || !sink) {
    cerr << "One element could not be created." << endl;
    return -1;
  }

  /* set filename property on the file source. Also add a message
   * handler. */
  source->set_property("location", (string) argv[1]);

  RefPtr<Bus> bus = pipeline->get_bus();
  bus->signal_message().connect(sigc::bind< RefPtr<MainLoop> >(
    sigc::ptr_fun(&bus_message_received), mainLoop) );

  /* put all elements in a bin */
  pipeline->add(source)->add(parser)->add(decoder)->add(conv)->add(sink);

  /* link together - note that we cannot link the parser and
   * decoder yet, becuse the parser uses dynamic pads. For that,
   * we set a pad-added signal handler. */
  source->link(parser);
  decoder->link(conv)->link(sink);

  parser->signal_pad_added().connect(sigc::bind< RefPtr<Element> >(
    sigc::ptr_fun(&parser_pad_added), decoder) );

  /* Now set to playing and iterate. */
  cout << "Setting to PLAYING." << endl;
  pipeline->set_state(STATE_PLAYING);
  cout << "Running." << endl;
  mainLoop->run();

  /* clean up nicely */
  cout << "Returned, stopping playback." << endl;
  pipeline->set_state(STATE_NULL);

  return 0;
}
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 95)
+++ ChangeLog	(working copy)
@@ -1,3 +1,18 @@
+2007-12-03  José Alburquerque  <jaalburquerque yahoo com>
+
+	* gst/src/bus.hg: added signal "message"
+	* gst/src/gst_signals.defs: sync-message and message had wrong
+	parameter type (GstMessage instead of GstMessage*)
+	* gst/src/message.hg: changed get_type() to be public
+	* gst/src/pipeline.ccg: modified Gst::Pipeline::create() to call
+	gst_bus_add_signal_watch() so Bus transmits "message" signal
+	* tests/Makefile.am: modified to include test-create-bin
+	* tests/test-create-bin.cc: added this test to create a bin and add
+	elements to it (to "catch" errors as API changes)
+	* tests/test-link-elements.cc: Removed a blank line
+	* tools/m4/convert_gst.m4: Added conversion from GstMessageType to
+	Gst::MessageType (for Gst::Message::get_type())
+
 2007-12-03  Murray Cumming  <murrayc murrayc com>
 
 	* gst/src/element.ccg: get_compatible_pad((): Clarify 
Index: gst/src/gst_signals.defs
===================================================================
--- gst/src/gst_signals.defs	(revision 95)
+++ gst/src/gst_signals.defs	(working copy)
@@ -5,7 +5,7 @@
   (return-type "void")
   (when "last")
   (parameters
-    '("GstMessage" "p0")
+    '("GstMessage*" "p0")
   )
 )
 
@@ -14,7 +14,7 @@
   (return-type "void")
   (when "last")
   (parameters
-    '("GstMessage" "p0")
+    '("GstMessage*" "p0")
   )
 )
 
Index: gst/src/pipeline.ccg
===================================================================
--- gst/src/pipeline.ccg	(revision 95)
+++ gst/src/pipeline.ccg	(working copy)
@@ -5,8 +5,12 @@
 
 Glib::RefPtr<Pipeline> Pipeline::create(const std::string& name)
 {
-  GstElement* pipeline = gst_pipeline_new(name.c_str());
-  return Glib::wrap((GstPipeline*) pipeline);
+  GstElement* gstPipeline = gst_pipeline_new(name.c_str());
+  Glib::RefPtr<Pipeline> pipeline = Glib::wrap((GstPipeline*) gstPipeline);
+  Glib::RefPtr<Bus> bus = pipeline->get_bus();
+  gst_bus_add_signal_watch(bus->gobj());
+  bus->unreference();
+  return pipeline;
 }
 
 } //namespace Gst
Index: gst/src/message.hg
===================================================================
--- gst/src/message.hg	(revision 95)
+++ gst/src/message.hg	(working copy)
@@ -138,9 +138,11 @@
       _CLASS_OPAQUE_REFCOUNTED(Message, GstMessage, NONE, gst_message_ref, gst_message_unref)
       _IGNORE(gst_message_ref, gst_message_unref)
 
-      MessageType get_type();
       const Structure& get_structure();
 
+    public:
+      _MEMBER_GET(type, type, MessageType, GstMessageType)
+
     protected: 
 
       GstMessage * cobj_;
Index: gst/src/bus.hg
===================================================================
--- gst/src/bus.hg	(revision 95)
+++ gst/src/bus.hg	(working copy)
@@ -15,11 +15,9 @@
   _CLASS_GOBJECT(Bus, GstBus, GST_BUS, Object, GstObject)
 
 protected:
-
   _CTOR_DEFAULT()
 
 public:
-
   static Glib::RefPtr<Bus> create();
   _WRAP_METHOD(bool post(const Glib::RefPtr<Message>& message), gst_bus_post)
   _WRAP_METHOD(bool have_pending() const, gst_bus_have_pending)
@@ -36,7 +34,7 @@
   _WRAP_METHOD(void enable_sync_message_emission(), gst_bus_enable_sync_message_emission)
 
 #m4 _CONVERSION(`GstMessage*',`const Glib::RefPtr<Message>&', `Glib::wrap($3, true)')
-  //TODO: _WRAP_SIGNAL(void message(const Glib::RefPtr<Message>& message), "message")
+  _WRAP_SIGNAL(void message(const Glib::RefPtr<Message>& message), "message")
   //TODO: _WRAP_SIGNAL(void sync_message(const Glib::RefPtr<Message>& message), "sync-message")
 };
 
Index: tools/m4/convert_gst.m4
===================================================================
--- tools/m4/convert_gst.m4	(revision 95)
+++ tools/m4/convert_gst.m4	(working copy)
@@ -55,6 +55,7 @@
 _CONVERSION(`const gint64&',`gint64',`$3')
 _CONVERSION(`gint64&',`gint64*',`&($3)')
 _CONVERSION(`const double&',`gdouble',`$3')
+_CONVERSION(`GstMessageType',`MessageType',`MessageType($3)')
 
 _CONV_ENUM(Gst,State)
 _CONV_ENUM(Gst,StateChangeReturn)
Index: tests/test-link-elements.cc
===================================================================
--- tests/test-link-elements.cc	(revision 95)
+++ tests/test-link-elements.cc	(working copy)
@@ -8,7 +8,6 @@
   Glib::RefPtr<Gst::Pipeline> pipeline;
   Glib::RefPtr<Gst::Element> source, filter, sink;
 
-
   pipeline = Gst::Pipeline::create("my-pipeline");
 
   source = Gst::Element::create("fakesrc", "source");
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 95)
+++ tests/Makefile.am	(working copy)
@@ -2,7 +2,7 @@
 
 LDADD=$(top_builddir)/gst/gstmm/libgstmm-1.0.la
 
-noinst_PROGRAMS = test-create-element test-pipeline-add-element test-link-elements
+noinst_PROGRAMS = test-create-element test-pipeline-add-element test-link-elements test-create-bin
 
 test_create_element_SOURCES=test-create-element.cc
 test_create_element_LDFLAGS= GSTMM_LIBS@
@@ -13,6 +13,9 @@
 test_link_elements_SOURCES=test-link-elements.cc
 test_link_elements_LDFLAGS= GSTMM_LIBS@
 
+test_create_bin_SOURCES=test-create-bin.cc
+test_create_bin_LDFLAGS= GSTMM_LIBS@
+
 #runtestbasic runtestlangs \
 #runtestsearch runtestmimetypes \
 #runtestgetbuffer
Index: tests/test-create-bin.cc
===================================================================
--- tests/test-create-bin.cc	(revision 0)
+++ tests/test-create-bin.cc	(revision 0)
@@ -0,0 +1,26 @@
+#include <gstmm.h>
+#include <iostream>
+
+int main (int argc, char* argv[])
+{
+  Gst::init(argc, argv);
+
+  Glib::RefPtr<Gst::Pipeline> pipeline;
+  Glib::RefPtr<Gst::Bin> bin;
+  Glib::RefPtr<Gst::Element> source, sink;
+
+  pipeline = Gst::Pipeline::create("my-pipeline");
+  bin = Gst::Bin::create("my-bin");
+
+  source = Gst::Element::create("fakesrc", "source");
+  sink = Gst::Element::create("fakesink", "sink");
+
+  bin->add(source)->add(sink);
+
+  pipeline->add(bin);
+  source->link(sink);
+
+  std::cout << "Successfully added elements '" << source->get_name() <<
+    "' and '" << sink->get_name() << "' to bin '" <<
+      bin->get_name() << "'." << std::endl;
+}


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