dynamically replacing elements in a playing gstreamer pipeline

Olivier Crête olivier.crete at collabora.com
Fri Aug 24 11:02:06 PDT 2012


Hi,

On Fri, 2012-08-24 at 10:45 -0700, markymark wrote:
> souphttpsrc location="http://localhost/local.ts" ! mpegtsdemux name=d !
> queue ! mpeg2dec ! xvimagesink d. ! queue ! a52dec ! pulsesink
> 
> During the middle of playback (i.e. GST_STATE_PLAYING is the pipeline state
> and the user is happily watching video), I need to remove souphttpsrc from
> the pipeline and create a new souphttpsrc, or even a new neonhttpsource, and
> then immediately add that back into the pipeline and continue playback of
> the same uri source stream at the same time position where playback was
> before we performed this operation. The user might see a small delay and
> that is fine.
> 
> We've barely figured out how to remove and replace the source, and we need
> more understanding. Here's our best attempt thus far:
> 
> gst_element_unlink(source, demuxer);
> gst_element_set_state(source, GST_STATE_NULL);
> gst_bin_remove(GST_BIN(pipeline), source);
> source = gst_element_factory_make("souphttpsrc", "src");
> g_object_set(G_OBJECT(source), "location", url, NULL);
> gst_bin_add(GST_BIN(pipeline), source);
> gst_element_link(source, demuxer);
> gst_element_sync_state_with_parent(source);
> 
> This doesn't work perfectly because the source is playing back from the
> beginning and the rest of the pipeline is waiting for the correct
> timestamped buffers (I assume) because after several seconds, playback picks
> back up. I tried seeking the source in multiple ways but nothing has worked.
> 
> I need to know the correct way to do this. It would be nice to know a
> general technique, if one exists, as well, in case we wanted to dynamically
> replace the decoder or some other element.

This is more or less the correct way, yes.
In 0.10, you need to do one further trick for the timestamps problems:
After removing the old source, but before linking the new source, send a
FLUSH_STOP event down the demuxer., this should reset the timestamps,
etc. 

-- 
Olivier Crête
olivier.crete at collabora.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20120824/5327589f/attachment-0001.pgp>


More information about the gstreamer-devel mailing list