gnomemm r1948 - in gstreamermm/trunk: . tests



Author: jaalburqu
Date: Tue Jan  6 02:31:56 2009
New Revision: 1948
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1948&view=rev

Log:
2009-01-05  Josà Alburquerque  <jaalburqu svn gnome org>

	* tests/test-plugin-signals.cc: Modified test so that Gst::FakeSrc is
	used instead of Gst::FileSrc.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/tests/test-plugin-signals.cc

Modified: gstreamermm/trunk/tests/test-plugin-signals.cc
==============================================================================
--- gstreamermm/trunk/tests/test-plugin-signals.cc	(original)
+++ gstreamermm/trunk/tests/test-plugin-signals.cc	Tue Jan  6 02:31:56 2009
@@ -1,32 +1,58 @@
 #include <gstreamermm.h>
-#include <gstreamermm/filesrc.h>
+#include <gstreamermm/fakesrc.h>
 #include <gstreamermm/fakesink.h>
 #include <iostream>
 
+Glib::RefPtr<Glib::MainLoop> mainloop;
+
+// This function is used to receive asynchronous messages in the main loop.
+bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */, const Glib::RefPtr<Gst::Message>& message)
+{
+  switch (message->get_message_type()) {
+    case Gst::MESSAGE_EOS:
+      std::cout << "End of stream." << std::endl;
+      mainloop->quit();
+      return false;
+    case Gst::MESSAGE_ERROR:
+    {
+
+      Glib::RefPtr<Gst::MessageError> msgError =
+              Glib::RefPtr<Gst::MessageError>::cast_dynamic(message);
+
+      if(msgError)
+      {
+        Glib::Error err;
+        err = msgError->parse();
+        std::cerr << "Error: " << err.what() << std::endl;
+      }
+      else
+        std::cerr << "Error." << std::endl;
+
+      mainloop->quit();
+      return false;
+    }
+    default:
+      break;
+  }
+
+  return true;
+}
+
 void on_handoff(const Glib::RefPtr<Gst::Buffer>& buffer,
                 const Glib::RefPtr<Gst::Pad>& pad)
 {
-  std::cout << "Gst::FakeSink's handoff signal triggered." << std::endl <<
-    "Exiting abruptly to stop execution." << std::endl;
-
-  exit(0);
+  std::cout << "Gst::FakeSrc's handoff signal triggered." << std::endl;
 }
 
 int main(int argc, char* argv[])
 {
   Gst::init(argc, argv);
 
-  if (argc != 2)
-  {
-    std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
-    return -1;
-  }
-
-  Glib::RefPtr<Glib::MainLoop>  mainloop = Glib::MainLoop::create();
+  mainloop = Glib::MainLoop::create();
 
   // Create elements:
-  Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("audio-player");
-  Glib::RefPtr<Gst::FileSrc> source = Gst::FileSrc::create();
+  Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("pipeline");
+  Glib::RefPtr<Gst::FakeSrc> source = Gst::FakeSrc::create();
   Glib::RefPtr<Gst::FakeSink> sink = Gst::FakeSink::create();
 
   if (!pipeline || !source || !sink) {
@@ -34,9 +60,6 @@
     return -1;
   }
 
-  // Set filename property on the file source.
-  source->property_location() = argv[1];
-
   // Put all elements in a bin:
   try
   {
@@ -53,9 +76,15 @@
   // Link together:
   source->link(sink);
 
-  // Enable the handoff signal emition and connect slot:
-  sink->property_signal_handoffs() = true;
-  sink->signal_handoff().connect(sigc::ptr_fun(on_handoff));
+  // Add bus watch to pipeline bus to receive messages:
+  pipeline->get_bus()->add_watch(sigc::ptr_fun(&on_bus_message));
+
+  // Set number of buffers fakesink creates to low number:
+  source->property_num_buffers() = 5;
+
+  // Enable the fakesink handoff signal emition and connect slot:
+  source->property_signal_handoffs() = true;
+  source->signal_handoff().connect(sigc::ptr_fun(on_handoff));
 
   // Now set to playing and iterate:
   std::cout << "Setting to PLAYING." << std::endl;



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