From 6c272aafa7c0843f582f8d33921b2b823cfb890d Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Sun, 21 Aug 2011 14:41:28 -0300 Subject: [PATCH] camerabin2: Prevent audiosrc from sending undesired eos Basesrc derived classes send an eos when they change state from paused to ready and that breaks video recordings on camerabin2 as it makes the whole audio branch pads flushing. Prevent it by using a pad probe that only allows the eos to pass when it is caused by a stop-capture action. --- gst/camerabin2/gstcamerabin2.c | 33 +++++++++++++++++++++++++++++++++ gst/camerabin2/gstcamerabin2.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index b12dc9c33a..a176bf086e 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -439,6 +439,7 @@ gst_camera_bin_stop_capture (GstCameraBin2 * camerabin) g_signal_emit_by_name (camerabin->src, "stop-capture", NULL); if (camerabin->mode == MODE_VIDEO && camerabin->audio_src) { + camerabin->audio_drop_eos = FALSE; gst_element_send_event (camerabin->audio_src, gst_event_new_eos ()); } } @@ -1213,6 +1214,25 @@ gst_camera_bin_image_sink_event_probe (GstPad * pad, GstEvent * event, return TRUE; } +static gboolean +gst_camera_bin_audio_src_event_probe (GstPad * pad, GstEvent * event, + gpointer data) +{ + GstCameraBin2 *camera = data; + gboolean ret = TRUE; + + if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { + /* we only let an EOS pass when the user is stopping a capture */ + if (camera->audio_drop_eos) { + ret = FALSE; + } else { + camera->audio_drop_eos = TRUE; + } + } + + return ret; +} + /** * gst_camera_bin_create_elements: * @param camera: the #GstCameraBin2 @@ -1529,6 +1549,8 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera) } if (new_audio_src) { + GstPad *srcpad; + if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->audio_src), "provide-clock")) { g_object_set (camera->audio_src, "provide-clock", FALSE, NULL); @@ -1540,6 +1562,15 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera) gst_element_link_many (camera->audio_src, camera->audio_volume, camera->audio_capsfilter, NULL); + + srcpad = gst_element_get_static_pad (camera->audio_src, "src"); + + /* drop EOS for audiosrc elements that push them on state_changes + * (basesrc does this) */ + gst_pad_add_event_probe (srcpad, + (GCallback) gst_camera_bin_audio_src_event_probe, camera); + + gst_object_unref (srcpad); } if (has_audio) { gst_camera_bin_check_and_replace_filter (camera, &camera->audio_filter, @@ -1578,6 +1609,7 @@ gst_camera_bin_change_state (GstElement * element, GstStateChange trans) GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element); + switch (trans) { case GST_STATE_CHANGE_NULL_TO_READY: if (!gst_camera_bin_create_elements (camera)) { @@ -1586,6 +1618,7 @@ gst_camera_bin_change_state (GstElement * element, GstStateChange trans) break; case GST_STATE_CHANGE_READY_TO_PAUSED: GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera); + camera->audio_drop_eos = TRUE; break; case GST_STATE_CHANGE_PAUSED_TO_READY: if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED) diff --git a/gst/camerabin2/gstcamerabin2.h b/gst/camerabin2/gstcamerabin2.h index e8611a8774..df52de6473 100644 --- a/gst/camerabin2/gstcamerabin2.h +++ b/gst/camerabin2/gstcamerabin2.h @@ -92,6 +92,8 @@ struct _GstCameraBin2 gboolean video_profile_switch; gboolean image_profile_switch; + gboolean audio_drop_eos; + /* properties */ gint mode; gchar *location;