From 1c8e1722eb14b0a6ac509c513d0cc223e0d78e9a Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 28 Apr 2011 14:37:22 -0300 Subject: [PATCH] camerabin2: encodebin might not have the requested pad handle the case where encodebin doesn't have the pad camerabin2 is requesting, either because of its current profile or because of missing elements, making it fail to provide the pad --- gst/camerabin2/gstcamerabin2.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index 4b313d6f11..034c545fe8 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -901,10 +901,16 @@ gst_camera_bin_link_encodebin (GstCameraBin * camera, GstElement * element, GstPad *sinkpad = NULL; srcpad = gst_element_get_static_pad (element, "src"); + g_assert (srcpad != NULL); + sinkpad = encodebin_find_pad (camera, padtype); - g_assert (srcpad != NULL); - g_assert (sinkpad != NULL); + /* there may be no available sink pad for encodebin in some situations: + * e.g. missing elements or incompatible padtype */ + if (sinkpad == NULL) { + gst_object_unref (srcpad); + return GST_PAD_LINK_REFUSED; + } ret = gst_pad_link (srcpad, sinkpad); gst_object_unref (sinkpad); @@ -1037,8 +1043,10 @@ gst_camera_bin_create_elements (GstCameraBin * camera) if (camera->profile_switch) { GST_DEBUG_OBJECT (camera, "Switching encodebin's profile"); g_object_set (camera->encodebin, "profile", camera->video_profile, NULL); - gst_camera_bin_link_encodebin (camera, camera->videobin_capsfilter, - VIDEO_PAD); + if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera, + camera->videobin_capsfilter, VIDEO_PAD))) { + goto fail; + } camera->profile_switch = FALSE; /* used to trigger relinking further down */ @@ -1147,11 +1155,18 @@ gst_camera_bin_create_elements (GstCameraBin * camera) } if ((profile_switched && has_audio) || new_audio_src) { - gst_camera_bin_link_encodebin (camera, camera->audio_convert, AUDIO_PAD); + if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera, + camera->audio_convert, AUDIO_PAD))) { + goto fail; + } } camera->elements_created = TRUE; return TRUE; + +fail: + /* FIXME properly clean up */ + return FALSE; } static GstStateChangeReturn