Video freezes when switching between cameras using input-selector on iOS iPad
I'm having trouble switching back and forth between the front-facing camera and the back-facing camera on an iOS iPad Pro. I'm using the input-selector
element to switch between camera sources. When it switches from the first camera source to the second camera source, the video freezes on the camera, and then unfreezes when it switches to the original camera source. I'm on iOS 12.3 and gstreamer 1.16.1. This is my pipeline.
pipeline = gst_parse_launch("avfvideosrc device-index=1 name=back_camera_src ! videoconvert ! identity name=sink0_sync sync=TRUE ! input-selector name=input_selector ! identity name=identity_segment silent=TRUE ! autovideosink name=video_sink sync=FALSE
avfvideosrc device-index=0 name=front_camera_src ! videoflip video-direction=180 ! identity name=sink1_sync sync=TRUE ! input_selector.
autoaudiosrc ! audioconvert ! audioresample ! audioconvert ! autoaudiosink", &error);
When I change the second source to the test source as in this second pipeline switching works fine.
pipeline = gst_parse_launch("avfvideosrc device-index=1 name=back_camera_src ! videoconvert ! identity name=sink0_sync sync=TRUE ! input-selector name=input_selector ! identity name=identity_segment silent=TRUE ! autovideosink name=video_sink sync=FALSE
videotestsrc is-live=true pattern=ball ! videoflip video-direction=180 ! identity name=sink1_sync sync=TRUE ! input_selector.
autoaudiosrc ! audioconvert ! audioresample ! audioconvert ! autoaudiosink", &error);
This is my code to switch sources with the input selector
-(void) switchVideoSrc
{
GstElement *inputSelector = self->inputSelector;
gint nb_sources;
GstPad *active_pad, *new_pad;
gchar *active_name;
g_message ("switching");
g_object_get (G_OBJECT (inputSelector), "n-pads", &nb_sources, nil);
g_object_get (G_OBJECT (inputSelector), "active-pad", &active_pad, nil);
active_name = gst_pad_get_name (active_pad);
g_message(active_name);
if (strcmp (active_name, "sink_0") == 0) {
new_pad = gst_element_get_static_pad (inputSelector, "sink_1");
} else {
new_pad = gst_element_get_static_pad (inputSelector, "sink_0");
}
g_object_set (G_OBJECT (inputSelector), "active-pad", new_pad, NULL);
g_free (active_name);
gst_object_unref (new_pad);
}
I looked at the logs up until GST_DEBUG level 4 and didn't find anything unusual. Any ideas what could be the problem or how to go about debugging this?