[gst-devel] "Could not open audio device for playback" error if creating/destructing pipeline from multiple threads

segr segr at is-nn.ru
Thu Oct 22 15:28:58 CEST 2009


The test program:

<code>
#include "gst/gst.h"
#include <iostream>
#include <string.h>
#include <sys/time.h>
#include <sstream>
#include <gst/interfaces/xoverlay.h>

#include "assert.h"
static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data);

static void *create_pipe (void *el)
{
  GError *err = 0;
//  GstElement *pipe = (GstElement *)el;
  pipe = gst_parse_launch("filesrc location=\"/mnt/media/1/Sting -
Collection/Sting - Collection - 10.wav\" ! decodebin ! volume volume=10 !
audioconvert ! alsasink", &err);
  gst_object_ref(pipe);
    
  GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipe));

  int wid = gst_bus_add_watch(bus, bus_call, 0);
  gst_object_unref(bus);

  gst_element_set_state(pipe, GST_STATE_PLAYING);
  gst_element_get_state(pipe, 0, 0, GST_CLOCK_TIME_NONE);


  static int iter = 0;
  std::cout << iter++ << std::endl;

  g_source_remove(wid);
  gst_element_set_state(pipe, GST_STATE_NULL);

  gst_object_unref(pipe);
  pipe = 0;
}

static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{

  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
    {
      std::cout << "EOS" << std::endl;
      break;
    }
    case GST_MESSAGE_ERROR: 
    {
      gchar *debug;
      GError *err;

      gst_message_parse_error (msg, &err, &debug);
      g_free (debug);

      std::cout << "Error occured in gstreamer: " << err->code << ": " <<
err->message << std::endl;
      g_error_free (err);
      assert(0);
      return false;
    }
    case GST_MESSAGE_BUFFERING:
    {
      gint percent;

      gst_message_parse_buffering (msg, &percent);
      std::cout << "Buffering percent is: " << percent << std::endl;
    }
    case GST_MESSAGE_WARNING: {
      gchar *debug;
      GError *err;

      gst_message_parse_warning (msg, &err, &debug);
      g_free (debug);

      std::cout << "Warning occured in gstreamer: " << err->code << ": " <<
err->message << std::endl;
      g_error_free (err);
      break;
    }
    case GST_MESSAGE_TAG: {
      GstTagList *tag_list, *result;

      gst_message_parse_tag (msg, &tag_list);
    }
    case GST_MESSAGE_STATE_CHANGED:{
      break;
    }
    default:
      break;
  }
  return TRUE;
}

void *start_loop(void *data)
{
  GMainLoop *loop = g_main_loop_new(0, false);
  g_main_loop_run(loop);

}

int main(int argc, char *argv[])
{
  

  
  std::cout << "Hello World!" << std::endl;
  g_thread_init(0);
  gst_init(0, 0);
  
  GThread *loop = g_thread_create(start_loop, 0, false, 0);
  GstElement *pipe = 0;
  GError *err = 0;
  float sl_t = 0;
  while(1) {
    g_thread_create(create_pipe, pipe, false, 0);

    static int qw = 0;
    std::cout << qw++ << std::endl;

    if(sl_t > 1) sl_t = 0;
    sleep(sl_t);
    sl_t +=0.05;
  }
  sleep(10);
}

</code>
-- 
View this message in context: http://www.nabble.com/%22Could-not-open-audio-device-for-playback%22-error-if-creating-destructing-pipeline-from-multiple-threads-tp26009881p26009922.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.





More information about the gstreamer-devel mailing list