Reputation: 129
I've got an application reading a movie file, and I would like to reset the stream to its initial position when it reaches the end of the stream.
So I've got the usual structure, I added a bus to watch the events
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
And here is a snipet of the bus_call function
static gboolean bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
default:
break;
}
return TRUE;
}
So for now when I reach the end of the stream I just quit the loop. Can I access my pipeline throught the loop? Thanks for reading, please let me know if I'm trying to do something impossible
ps: I want to avoid setting my pipeline as a global variable, or pass to bus_call a structure containing my pipeline and loop, because it feels wrong.
Upvotes: 1
Views: 462
Reputation: 129
My goal was to auto rewind when the end of the stream was reached. The user could then hit the play button, to play it again.
So I skirted the problem and modified the callback function of my play button. Now it detect the current stream position, and compare it to the length of the stream.
gint64 streamPosition, streamLength;
GstFormat format = GST_FORMAT_TIME;
gst_element_query_position (pipeline, &format, &streamPosition);
gst_element_query_duration (pipeline, &format, &streamLength);
if (streamPosition==streamLength)
stopIt(widget,pipeline);
and if the current stream position equals the stream length, it means we are at the end of the stream. and so I call a function to rewind the stream....
Feels really jerky, but that's the "best" solution I have for now.
I'm still open to suggestions.
Upvotes: 1