Hello All,<br><br>I have a basic understanding of gstreamer, the problem i am facing may be trivial , please bear with me. <br>What I am trying to make use of playbin2 for playing a non-seekable file (I am using pipe & doing "cat *.mp3 > /home/my_pipe after running my app)<br>
<br>Here is my app<br>-------------------------------------------------------<br><br>include <gst/gst.h><br><br>static int cnt = 0;<br>static gboolean<br>cb_print_position (GstElement *pipeline)<br>{<br> GstFormat fmt = GST_FORMAT_TIME;<br>
gint64 pos, len;<br><br> if (gst_element_query_position (pipeline, &fmt, &pos) && gst_element_query_duration (pipeline, &fmt, &len))<br> {<br> GTimeVal tv_pos, tv_len;<br> GST_TIME_TO_TIMEVAL (pos, tv_pos);<br>
GST_TIME_TO_TIMEVAL (len, tv_len);<br> glong pos_min = tv_pos.tv_sec / 60;<br> glong len_min = tv_len.tv_sec / 60;<br> g_print ("\rCount %d) : Time: %01lu:%02lu:%02lu.%02lu", cnt++ , pos_min / 60, pos_min % 60, tv_pos.tv_sec % 60, tv_pos.tv_usec / 10000);<br>
if (len > 0) /* streams have len == -1 */<br> g_print (" of %01lu:%02lu:%02lu.%02lu", len_min / 60, len_min % 60, tv_len.tv_sec % 60, tv_len.tv_usec / 10000);<br> }<br><br> if(cnt == 50)<br> {<br>
printf("Going to Seek for 10 sec \n");<br> GstFormat fmt = GST_FORMAT_TIME;<br> gint64 cur_pos;<br><br> if (!(gst_element_query_position (pipeline, &fmt, &cur_pos)))<br> printf("[player] : gst_element_query_position failed \n");<br>
<br> g_print("The cur_pos %" G_GINT64_FORMAT , cur_pos);<br><br> double new_pos_sec = cur_pos * (1.0 / GST_SECOND) + 10; // 10 sec<br> gint64 new_pos = new_pos_sec * GST_SECOND ;<br> printf("new_pos = %" G_GINT64_FORMAT , new_pos);<br>
if(!(gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET,<br> new_pos , GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)))<br> printf("\n[player] Seek failed!! \n");<br>
else<br> printf("\n[Player] Seek successful \n");<br> }<br> return TRUE;<br>}<br><br>static gboolean<br>my_bus_callback (GstBus *bus,<br> GstMessage *msg,<br> gpointer data)<br>
{<br> GMainLoop *loop = (GMainLoop *) data;<br> switch (GST_MESSAGE_TYPE (msg)) {<br> case GST_MESSAGE_EOS:<br> g_print ("End of stream\n");<br> g_main_loop_quit (loop);<br> break;<br> case GST_MESSAGE_ERROR: {<br>
gchar *debug;<br> GError *error;<br> gst_message_parse_error (msg, &error, &debug);<br> g_free (debug);<br> g_printerr ("Error: %s\n", error->message);<br> g_error_free (error);<br>
g_main_loop_quit (loop);<br> break;<br> }<br> default:<br> break;<br> }<br> return TRUE;<br>}<br><br>gint<br>main (gint argc,<br> gchar *argv[])<br>{<br> GMainLoop *loop;<br> GstElement *play;<br>
GstBus *bus;<br> /* init GStreamer */<br> gst_init (&argc, &argv);<br> loop = g_main_loop_new (NULL, FALSE);<br> /* make sure we have a URI */<br> if (argc != 2) {<br> g_print ("Usage: %s <URI>\n", argv[0]);<br>
return -1;<br> }<br> /* set up */<br> play = gst_element_factory_make ("playbin2", "play");<br> g_object_set (G_OBJECT (play), "uri", argv[1], NULL);<br> bus = gst_pipeline_get_bus (GST_PIPELINE (play));<br>
gst_bus_add_watch (bus, my_bus_callback, loop);<br> gst_object_unref (bus);<br> gst_element_set_state (play, GST_STATE_PLAYING);<br> g_timeout_add (200, (GSourceFunc) cb_print_position, play);<br> /* now run */<br> g_main_loop_run (loop);<br>
/* also clean up */<br> gst_element_set_state (play, GST_STATE_NULL);<br> gst_object_unref (GST_OBJECT (play));<br> return 0;<br>}<br> <br>--------------------------------- End --------------------------------<br>run:<br>
<my_app> my_pipe<br><br>o/p:<br>Count 49) : Time: 0:00:09.85<br>Going to Seek for 10 sec <br>
The cur_pos 9852113000<br>new_pos = 19852112999<br>
[player] Seek failed!! <br>
Count 118) : Time: 0:00:23.63<br>
<br>--------------------------------<br>observation:<br><br><br>1) Playback successfuly between count 1- 49. <br>2) At count= 50 i.e., when seek called , the seek fails. & there was no sound though player is in PLAYING state between count <50 to 100><br>
3) After count = 100 , resumed normal playback.<br><br>Why there is no sound after seek failed though player was in PLAYING state.<br><br>The same behavior I observed with my own pipeline [ filesrc ! decodebon2 ! autoaudiosink ]<br>
<br>Appreciate your input.<br><br><br>-- <br>Thanks & Regards,<br><br>Satish Pattar<br><br>