<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Hi All,</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> 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?</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">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.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Let me know if you need any further information.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><code></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">#include <gst/gst.h><BR>#include <stdio.h><BR>#include <pthread.h></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">#define GSTCOREELEMENTS_LIB "/gst_core/release/export/i686/lib/gstreamer-0.10/libgstcoreelements.so"<BR>#define GSTWAVPARSER_LIB "/gst_core/release/export/i686/lib/gstreamer-0.10/libgstwavparse.so"<BR>#define MEDIAFILE "a.wav"<BR>#define NUM_THREADS 2</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">pthread_mutex_t count_mutex;<BR>int i =0;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">static void<BR>new_pad (GstElement *element,<BR> GstPad *pad,<BR> gpointer data)<BR>{<BR> GstPad *sinkpad;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_print("%p : New Pad Thread Id \n\n", pthread_self());<BR> <BR> /* We can now link this pad with the audio decoder */<BR> g_print ("Dynamic pad created, linking parser/sink\n");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> sinkpad = gst_element_get_pad ( GST_ELEMENT(data), "sink");<BR> gst_pad_link (pad, sinkpad);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> gst_object_unref (sinkpad);<BR>}</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>static void load_plugin_libs(void)<BR>{<BR> if( NULL == gst_plugin_load_file(GSTCOREELEMENTS_LIB, NULL) )<BR> {<BR> printf("Failed to load %s\n",GSTCOREELEMENTS_LIB);<BR> exit (1);<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if( NULL == gst_plugin_load_file(GSTWAVPARSER_LIB, NULL) )<BR> {<BR> printf("Failed to load %s\n",GSTWAVPARSER_LIB);<BR> exit (1);<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">}</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">static gboolean<BR>bus_call (GstBus *bus,<BR> GstMessage *msg,<BR> gpointer data)<BR>{<BR> GMainLoop *loop = data;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> switch (GST_MESSAGE_TYPE (msg)) {<BR> case GST_MESSAGE_EOS:<BR> g_print ( __FILE__ " - End-of-stream\n");<BR> g_main_loop_quit (loop);<BR> break;<BR> case GST_MESSAGE_ERROR: {<BR> gchar *debug;<BR> GError *err;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> gst_message_parse_error (msg, &err, &debug);<BR> g_free (debug);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_print ( __FILE__ " - Error: %s\n", err->message);<BR> g_error_free (err);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_main_loop_quit (loop);<BR> break;<BR> }<BR> default:<BR> break;<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> return TRUE;<BR>}</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>int<BR>mainloop (void *threadarg)<BR>{<BR> GMainLoop *loop;<BR> GstBus *bus;<BR> <BR> int argc = 0;<BR> char *argv[] = {0};</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> GstElement *pipeline, *source, *parser, *sink ;<BR> <BR> int randomnumber, rnum ;<BR> char tmpfile[50] ;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_print("Thread number is %d\n\n", (int)threadarg);<BR> g_print("%p : is the Thread Id \n\n",pthread_self());</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* initialize GStreamer */<BR> gst_init (&argc, &argv);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> loop = g_main_loop_new (NULL, FALSE);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* Load Plugin libraries */<BR> load_plugin_libs();</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* create a pipeline */<BR> pipeline = gst_pipeline_new ("my-player");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if (!pipeline) {<BR> g_print ( __FILE__ " - Pipeline could not be created\n");<BR> return -1;<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* create a element for the PSS source element */<BR> source = gst_element_factory_make ("filesrc", "File Source");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if (!source) {<BR> g_print ( __FILE__ " - File source could not be created\n");<BR> return -1;<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_object_set (G_OBJECT (source), "location", MEDIAFILE, NULL);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> parser = gst_element_factory_make ("wavparse", "Wav Parser");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if (!parser) {<BR> g_print ( __FILE__ " - AU Parser could not be created\n");<BR> return -1;<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> sink = gst_element_factory_make ("filesink", "Fake Sink");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if (!sink) {<BR> g_print ( __FILE__ " - Fake sink could not be created\n");<BR> return -1;<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> randomnumber = rand();<BR> rnum = Randomizenumber(randomnumber, 0,100);<BR> {<BR> sprintf(tmpfile, "%s%d","temp",rnum);<BR> g_print("%p : %s is the string \n\n",pthread_self(),tmpfile); <BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_object_set (G_OBJECT (sink), "location", tmpfile, NULL);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* Add means for communication */<BR> bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));<BR> gst_bus_add_watch (bus, bus_call, loop);<BR> gst_object_unref (bus);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* put the source element into the bin */<BR> gst_bin_add (GST_BIN (pipeline), source); </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* put the sink element into the bin */<BR> gst_bin_add (GST_BIN (pipeline), parser); </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* put the sink element into the bin */<BR> gst_bin_add (GST_BIN (pipeline), sink); </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* Link the elements */<BR> gst_element_link (source, parser);<BR> <BR> /* Handle new padded signal */ <BR> g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad), sink);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* Now set to playing and iterate. */<BR> g_print ( __FILE__ " - Setting to PLAYING\n");<BR> gst_element_set_state (pipeline, GST_STATE_PLAYING);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_print ( __FILE__ " - Running\n");<BR> <BR> g_main_loop_run (loop);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> /* clean up nicely */<BR> g_print ( __FILE__ " - Returned, stopping playback\n");</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> gst_element_set_state (pipeline, GST_STATE_NULL);<BR> <BR> g_print ( __FILE__ " - Deleting pipeline\n");<BR> gst_object_unref (GST_OBJECT (pipeline));</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> return 0;<BR>}</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">int main(int argc, char *argv[])<BR>{</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> pthread_t threads[NUM_THREADS];<BR> int *taskids[NUM_THREADS], i,j;<BR> int rc, t, sum;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> g_print("%p: Main Thread ID\n",pthread_self());</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> for(t=0;t<NUM_THREADS;t++) {</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> printf("Creating thread %d\n", t);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> rc = pthread_create(&threads[t], NULL, mainloop, (void *)t);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> if (rc) {<BR> printf("ERROR; return code from pthread_create() is %d\n", rc);<BR> exit(-1);<BR> }<BR> /*for (i = 0; i < 1000 ; i++)<BR> {<BR> for (j = 0; j < 65533 ;j++ )<BR> {<BR> printf("");<BR> }<BR> }*/<BR> }</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> while(1);</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> return 0;<BR>}</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">=================================</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">The output is of the following format</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">=================================</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">> ./app <BR>0xb7e11a80: Main Thread ID<BR>Creating thread 0<BR>Creating thread 1<BR>Thread number is 0</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb7e10bb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Thread number is 1</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb740fbb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb740fbb0 : temp82 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>0xb7e10bb0 : temp86 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>app.c - Running<BR>=========================================<BR>This Id and the Id below is same<BR>=========================================<BR>0xb6593bb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Dynamic pad created, linking parser/sink<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>=========================================<BR>The above Id and this Id is same<BR>=========================================<BR>0xb6593bb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Dynamic pad created, linking parser/sink<BR>app.c - Running<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>app.c - Deleting pipeline<BR>app.c - Deleting pipeline</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">> ./app <BR>0xb7e11a80: Main Thread ID<BR>Creating thread 0<BR>Creating thread 1<BR>Thread number is 0</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb7e10bb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Thread number is 1</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb740fbb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb7e10bb0 : temp82 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>0xb740fbb0 : temp86 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>app.c - Running<BR>0xb6593bb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Dynamic pad created, linking parser/sink<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>app.c - Running<BR>0xb6593bb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Dynamic pad created, linking parser/sink<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>app.c - Deleting pipeline<BR>app.c - Deleting pipeline</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">> ./app <BR>0xb7e11a80: Main Thread ID<BR>Creating thread 0<BR>Creating thread 1<BR>Thread number is 1</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb740fbb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Thread number is 0</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb7e10bb0 : is the Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">0xb7e10bb0 : temp82 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>0xb740fbb0 : temp86 is the string </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Setting to PLAYING<BR>app.c - Running<BR>0xb6593bb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">app.c - Running<BR>Dynamic pad created, linking parser/sink<BR>0xb578abb0 : New Pad Thread Id </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Dynamic pad created, linking parser/sink<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>app.c - End-of-stream<BR>app.c - Returned, stopping playback<BR>app.c - Deleting pipeline<BR>app.c - Deleting pipeline</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"></code></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Thank you for your patience.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Regards,</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Sid</DIV></div><br>
<hr size=1>Be a better Globetrotter. <a href="http://us.rd.yahoo.com/evt=48254/*http://answers.yahoo.com/dir/_ylc=X3oDMTI5MGx2aThyBF9TAzIxMTU1MDAzNTIEX3MDMzk2NTQ1MTAzBHNlYwNCQUJwaWxsYXJfTklfMzYwBHNsawNQcm9kdWN0X3F1ZXN0aW9uX3BhZ2U-?link=list&sid=396545469">Get better travel answers </a>from someone who knows.<br>Yahoo! Answers - Check it out.
</body></html>