Re: Fixing the Gst::Message classes



Murray Cumming wrote:
On Wed, 2007-12-12 at 10:35 -0500, José Alburquerque wrote:
Oops, my mistake.  I re-tested, modifying the ogg player version in
svn to use signals (attached as ogg-player-signal.cc) and it works.

Help me out. What has changed in this example? How are you using signals
in some new way?

Here's the original. AFAICT, the only change is in the error message parsing. The e-mail I submitted in is: http://mail.gnome.org/archives/gtkmm-list/2007-December/msg00034.html Would this be a problem?

-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->add_signal_watch();
  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);

  bus->remove_signal_watch();

  return 0;
}


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