[gst-devel] Problem running a test app

Syed Ahmed towkmail at yahoo.com
Fri Jul 13 16:59:29 CEST 2007


Hi All,

        I am new to GST and I am trying to run a multithreaded program to run multiple gst players. I am using a filesink to store the buffers. I am trying with 2 thread initially. The problem is when I connect a pad creator function (new_pad) to link to new pad, the function gets called from one single thread irrespective of two threads being initiated. This behaviour is not always as I can see the pad creation function in two different functions also. Can anyone tell me why is this behaviour?
The other problem is that the first file from the first thread contains the output data and the other one does not in either case of the new_pad function being run in same or unique thread. Can anyone suggest what is happening here.
Let me know if you need any further information.

<code>

#include <gst/gst.h>
#include <stdio.h>
#include <pthread.h>
#define GSTCOREELEMENTS_LIB "/gst_core/release/export/i686/lib/gstreamer-0.10/libgstcoreelements.so"
#define GSTWAVPARSER_LIB    "/gst_core/release/export/i686/lib/gstreamer-0.10/libgstwavparse.so"
#define MEDIAFILE "a.wav"
#define NUM_THREADS     2
pthread_mutex_t count_mutex;
int i =0;
static void
new_pad (GstElement *element,
         GstPad     *pad,
         gpointer    data)
{
  GstPad *sinkpad;
  g_print("%p :  New Pad Thread Id \n\n", pthread_self());
  
  /* We can now link this pad with the audio decoder */
  g_print ("Dynamic pad created, linking parser/sink\n");
  sinkpad = gst_element_get_pad ( GST_ELEMENT(data), "sink");
  gst_pad_link (pad, sinkpad);
  gst_object_unref (sinkpad);
}

static void load_plugin_libs(void)
{
    if( NULL == gst_plugin_load_file(GSTCOREELEMENTS_LIB, NULL) )
    {
        printf("Failed to load %s\n",GSTCOREELEMENTS_LIB);
        exit (1);
    }
    if( NULL == gst_plugin_load_file(GSTWAVPARSER_LIB, NULL) )
    {
        printf("Failed to load %s\n",GSTWAVPARSER_LIB);
        exit (1);
    }
}
static gboolean
bus_call (GstBus     *bus,
   GstMessage *msg,
   gpointer    data)
{
  GMainLoop *loop = data;
  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
      g_print ( __FILE__ " - End-of-stream\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_ERROR: {
      gchar *debug;
      GError *err;
      gst_message_parse_error (msg, &err, &debug);
      g_free (debug);
      g_print (  __FILE__ " - Error: %s\n", err->message);
      g_error_free (err);
      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
  return TRUE;
}

int
mainloop (void *threadarg)
{
    GMainLoop *loop;
    GstBus *bus;
 
 int argc = 0;
 char *argv[] = {0};
    GstElement *pipeline, *source, *parser, *sink ;
 
    int randomnumber, rnum ;
 char tmpfile[50] ;
 g_print("Thread number is %d\n\n", (int)threadarg);
    g_print("%p :  is the Thread Id \n\n",pthread_self());
    /* initialize GStreamer */
    gst_init (&argc, &argv);
    loop = g_main_loop_new (NULL, FALSE);
    /* Load Plugin libraries */
    load_plugin_libs();
    /* create a pipeline */
    pipeline = gst_pipeline_new ("my-player");
    if (!pipeline) {
        g_print ( __FILE__ " - Pipeline could not be created\n");
        return -1;
    }
    /* create a element for the PSS source element */
    source   = gst_element_factory_make ("filesrc", "File Source");
    if (!source) {
        g_print ( __FILE__ " - File source could not be created\n");
        return -1;
    }
    g_object_set (G_OBJECT (source), "location", MEDIAFILE, NULL);
    parser   = gst_element_factory_make ("wavparse", "Wav Parser");
 if (!parser) {
        g_print ( __FILE__ " - AU Parser could not be created\n");
        return -1;
    }
    sink   = gst_element_factory_make ("filesink", "Fake Sink");
 if (!sink) {
        g_print ( __FILE__ " - Fake sink could not be created\n");
        return -1;
    }
    randomnumber = rand();
 rnum = Randomizenumber(randomnumber, 0,100);
 {
        sprintf(tmpfile, "%s%d","temp",rnum);
  g_print("%p : %s is the string \n\n",pthread_self(),tmpfile); 
 }
    g_object_set (G_OBJECT (sink), "location", tmpfile, NULL);
    /* Add means for communication */
    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);
    /* put the source element into the bin */
    gst_bin_add (GST_BIN (pipeline), source); 
    /* put the sink element into the bin */
    gst_bin_add (GST_BIN (pipeline), parser); 
    /* put the sink element into the bin */
    gst_bin_add (GST_BIN (pipeline), sink); 
 /* Link the elements */
 gst_element_link (source, parser);
    
 /* Handle new padded signal */ 
    g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad), sink);
    /* Now set to playing and iterate. */
    g_print (  __FILE__ " - Setting to PLAYING\n");
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_print ( __FILE__ " - Running\n");
 
    g_main_loop_run (loop);
    /* clean up nicely */
    g_print (  __FILE__ " - Returned, stopping playback\n");
    gst_element_set_state (pipeline, GST_STATE_NULL);
 
 g_print ( __FILE__ " - Deleting pipeline\n");
    gst_object_unref (GST_OBJECT (pipeline));
    return 0;
}
int main(int argc, char *argv[])
{
  pthread_t threads[NUM_THREADS];
  int *taskids[NUM_THREADS], i,j;
  int rc, t, sum;
  g_print("%p: Main Thread ID\n",pthread_self());
  for(t=0;t<NUM_THREADS;t++) {
  printf("Creating thread %d\n", t);
  rc = pthread_create(&threads[t], NULL, mainloop, (void *)t);
  if (rc) {
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }
 /*for (i = 0; i < 1000 ; i++)
 {
  for (j = 0; j < 65533 ;j++ )
  {
   printf("");
  }
 }*/
  }
  while(1);
  return 0;
}

=================================
The output is of the following format
=================================

> ./app 
0xb7e11a80: Main Thread ID
Creating thread 0
Creating thread 1
Thread number is 0
0xb7e10bb0 :  is the Thread Id 
Thread number is 1
0xb740fbb0 :  is the Thread Id 
0xb740fbb0 : temp82 is the string 
app.c - Setting to PLAYING
0xb7e10bb0 : temp86 is the string 
app.c - Setting to PLAYING
app.c - Running
=========================================
This Id and the Id below is same
=========================================
0xb6593bb0 :  New Pad Thread Id 
Dynamic pad created, linking parser/sink
app.c - End-of-stream
app.c - Returned, stopping playback
=========================================
The above Id and this Id is same
=========================================
0xb6593bb0 :  New Pad Thread Id 
Dynamic pad created, linking parser/sink
app.c - Running
app.c - End-of-stream
app.c - Returned, stopping playback
app.c - Deleting pipeline
app.c - Deleting pipeline
> ./app 
0xb7e11a80: Main Thread ID
Creating thread 0
Creating thread 1
Thread number is 0
0xb7e10bb0 :  is the Thread Id 
Thread number is 1
0xb740fbb0 :  is the Thread Id 
0xb7e10bb0 : temp82 is the string 
app.c - Setting to PLAYING
0xb740fbb0 : temp86 is the string 
app.c - Setting to PLAYING
app.c - Running
0xb6593bb0 :  New Pad Thread Id 
Dynamic pad created, linking parser/sink
app.c - End-of-stream
app.c - Returned, stopping playback
app.c - Running
0xb6593bb0 :  New Pad Thread Id 
Dynamic pad created, linking parser/sink
app.c - End-of-stream
app.c - Returned, stopping playback
app.c - Deleting pipeline
app.c - Deleting pipeline
> ./app 
0xb7e11a80: Main Thread ID
Creating thread 0
Creating thread 1
Thread number is 1
0xb740fbb0 :  is the Thread Id 
Thread number is 0
0xb7e10bb0 :  is the Thread Id 
0xb7e10bb0 : temp82 is the string 
app.c - Setting to PLAYING
0xb740fbb0 : temp86 is the string 
app.c - Setting to PLAYING
app.c - Running
0xb6593bb0 :  New Pad Thread Id 
app.c - Running
Dynamic pad created, linking parser/sink
0xb578abb0 :  New Pad Thread Id 
Dynamic pad created, linking parser/sink
app.c - End-of-stream
app.c - Returned, stopping playback
app.c - End-of-stream
app.c - Returned, stopping playback
app.c - Deleting pipeline
app.c - Deleting pipeline

</code>

Thank you for your patience.

Regards,
Sid


      ____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070713/c881d93e/attachment.htm>


More information about the gstreamer-devel mailing list