Input-Selector briefly freezes on switching pads
Describe your issue
Switching input-selector feeds causes the output to be glitchy right after the switch. The brief freezing corrects itself after about 500ms-1s and video plays back fine after that. This issue was observed in 1.22.2 version. This problem was not present in 1.20.3.
Expected Behavior
Video switching should be without glitches/freeze.
Observed Behavior
Setup
- 22.04.1-Ubuntu
- 1.22.2
- Need to input switch on the input-selector; so command line doesn't work.
Steps to reproduce the bug
Run this code and you can notice that the ball is glitchy after the switch. It shows one of the earlier frames followed by a pause followed by the new location where it should be and then it unfreezes and continues smoothly.
#include <unistd.h>
#include <gst/gst.h>
#define PIPELINE_STR \
"input-selector name=sel sync-mode=1 cache-buffers=true "\
"videotestsrc is-live=true pattern=18 ! video/x-raw,width=960,height=540,framerate=30/1 ! sel.sink_0 "\
"videotestsrc is-live=true pattern=0 ! video/x-raw,width=960,height=540,framerate=30/1 ! sel.sink_1 "\
"sel. ! timeoverlay ! autovideosink sync=true"
int main (int argc, char *argv[])
{
gst_init (&argc, &argv);
gchar* pipelineStr = PIPELINE_STR;
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
GstPipeline *pipeline = GST_PIPELINE(gst_parse_launch(pipelineStr, NULL));
GstElement *selector = gst_bin_get_by_name (GST_BIN (pipeline), "sel");
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
while(1){
sleep(3);
GstPad *newPad = gst_element_get_static_pad (selector, "sink_1");
g_print("switching to sink_1 pad\n");
g_object_set (G_OBJECT (selector), "active-pad", newPad, NULL);
sleep(3);
newPad = gst_element_get_static_pad (selector, "sink_0");
g_print("switching to sink_0 pad\n");
g_object_set (G_OBJECT (selector), "active-pad", newPad, NULL);
}
g_main_loop_run (loop);
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}
How reproducible is the bug?
Problem reproducible 100% of the time. Problem is more obvious if you save the output from the input-selector to a file (say after encoding it as h264/mp4). Playing back that file using ffmpeg would show all sorts of weirdness and complaints about DTS being incorrect. It feels like the input selector is buffering up the video even when the stream has been switched to a different one.
Screenshots if relevant
The one on the left is gstreamer 1.20.3 and the one on the right is gstreamer 1.22.2. The stutter and jump backwards in time is observable in the newer one on the right.
Solutions you have tried
This problem arose when I upgraded from 1.20.3 to 1.22.2. I tried going to main
and it still happens. Also, it happens with 1.22.0 I believe. I haven't been able to nail down which commit caused the issue.