Gstreamer: Pausing/resuming video in RTP streams

时光总嘲笑我的痴心妄想 提交于 2019-12-01 00:58:29
enthusiasticgeek

I present a simple function for pause resume by changing bins. In the following example I provide the logic to change destination bin on the fly dynamically. This shall not completely stop the pipeline which is what you seek I believe. A similar logic could be used for src bins. Here you may remove your network source bin and related decoder/demux bins and add videotestsrc bins.

private static void dynamic_bin_replacement(Pipeline pipe, Element src_bin, Element dst_bin_new, Element dst_bin_old) {
pipe.pause();
src_bin.unlink(dst_bin_old);                     
pipe.remove(dst_bin_old);
pipe.add(dst_bin_new);
dst_bin_new.syncStateWithParent();
src_bin.link(dst_bin_new);
pipe.ready();                    
pipe.play();
}

The other logic you may want to try is "PADLOCKING". Please take a look at the following posts

http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-block.txt

and

http://web.archiveorange.com/archive/v/8yxpz7FmOlGqxVYtkPb4

and

Adding and removing audio sources to/from GStreamer pipeline on-the-go

UPDATE

  1. Try output-selector and input-selector bins as they seem to be better alternative. I found them most reliable and have had immense luck with them. I use fakesink or fakesrc respectively as the other end of the selector.

  2. valve bin is another alternative that I found doesn't even need fakesink or fakesrc bins. It is also extremely reliable.

Also the correct state transition order for media file source

NULL -> READY -> PAUSED -> PLAYING (Upwards)

PLAYING -> PAUSED -> READY -> NULL (Downwards)

My order in the above example should be corrected where ready() should come before pause(). Also I would tend to think un-linking should be performed after null() state and not after pause(). I haven't tried these changes but theoretically they should work.

See the following link for detailed info

http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-states.txt?h=BRANCH-RELEASE-0_10_19

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!