summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>2011-02-01 11:19:29 -0300
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>2011-02-03 19:09:20 -0300
commit1a62d9374b228dc5bd3fb8c7da2212ceb5506430 (patch)
treec3a4047e8737a54ffdb77ae1a5fca5444634a76a
parent4a7dc8178207b00ee43f7071fa43ff1581a6199d (diff)
wrappercamerabinsrc: Handle src state change to avoid losing timestamps
Camerabin2 uses state changes to force the source to renegotiate its caps to the capture formats. The state changes makes the source lose its clock and base_time, causing it to stop timestamping the buffers. We still need a proper way to make sources renegotiate its caps, so this patch is a hack to make the source continue timestamping buffers even after changing state. The patch works by getting the clock and base time before doing the state change to NULL and setting them back after putting it to PLAYING again. It also cares to drop the first new segment after this state change.
-rw-r--r--gst/camerabin2/gstwrappercamerabinsrc.c67
-rw-r--r--gst/camerabin2/gstwrappercamerabinsrc.h3
2 files changed, 69 insertions, 1 deletions
diff --git a/gst/camerabin2/gstwrappercamerabinsrc.c b/gst/camerabin2/gstwrappercamerabinsrc.c
index c35fe8d77..0f2e6090a 100644
--- a/gst/camerabin2/gstwrappercamerabinsrc.c
+++ b/gst/camerabin2/gstwrappercamerabinsrc.c
@@ -167,8 +167,46 @@ gst_wrapper_camera_bin_reset_video_src_caps (GstWrapperCameraBinSrc * self,
{
+ GstClock *clock;
+ gint64 base_time;
+
GST_DEBUG_OBJECT (self, "Resetting src caps to %" GST_PTR_FORMAT, caps);
if (self->src_vid_src) {
+ clock = gst_element_get_clock (self->src_vid_src);
+ base_time = gst_element_get_base_time (self->src_vid_src);
+
gst_element_set_state (self->src_vid_src, GST_STATE_NULL);
set_capsfilter_caps (self, caps);
+
+ self->drop_newseg = TRUE;
+
GST_DEBUG_OBJECT (self, "Bringing source up");
gst_element_sync_state_with_parent (self->src_vid_src);
+
+ gst_element_set_clock (self->src_vid_src, clock);
+ gst_element_set_base_time (self->src_vid_src, base_time);
+
+ if (GST_IS_BIN (self->src_vid_src)) {
+ GstIterator *it = gst_bin_iterate_elements (GST_BIN (self->src_vid_src));
+ gpointer item = NULL;
+ gboolean done = FALSE;
+ while (!done) {
+ switch (gst_iterator_next (it, &item)) {
+ case GST_ITERATOR_OK:
+ gst_element_set_base_time (GST_ELEMENT (item), base_time);
+ gst_object_unref (item);
+ break;
+ case GST_ITERATOR_RESYNC:
+ gst_iterator_resync (it);
+ break;
+ case GST_ITERATOR_ERROR:
+ done = TRUE;
+ break;
+ case GST_ITERATOR_DONE:
+ done = TRUE;
+ break;
+ }
+ }
+ gst_iterator_free (it);
+ }
+
+ gst_object_unref (clock);
}
@@ -288,2 +326,26 @@ gst_wrapper_camera_bin_src_event (GstPad * pad, GstEvent * event)
+static gboolean
+gst_wrapper_camera_src_src_event_probe (GstPad * pad, GstEvent * evt,
+ gpointer udata)
+{
+ gboolean ret = TRUE;
+ GstWrapperCameraBinSrc *self = udata;
+
+ switch (GST_EVENT_TYPE (evt)) {
+ case GST_EVENT_EOS:
+ /* drop */
+ ret = FALSE;
+ break;
+ case GST_EVENT_NEWSEGMENT:
+ if (self->drop_newseg) {
+ ret = FALSE;
+ self->drop_newseg = FALSE;
+ }
+ break;
+ default:
+ break;
+ }
+ return ret;
+}
+
/**
@@ -336,3 +398,3 @@ gst_wrapper_camera_bin_src_construct_pipeline (GstBaseCameraSrc * bcamsrc)
self->src_event_probe_id = gst_pad_add_event_probe (pad,
- (GCallback) gst_camerabin_drop_eos_probe, NULL);
+ (GCallback) gst_wrapper_camera_src_src_event_probe, self);
gst_object_unref (pad);
@@ -993,2 +1055,5 @@ gst_wrapper_camera_bin_src_change_state (GstElement * element,
switch (trans) {
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ self->drop_newseg = FALSE;
+ break;
case GST_STATE_CHANGE_READY_TO_NULL:
diff --git a/gst/camerabin2/gstwrappercamerabinsrc.h b/gst/camerabin2/gstwrappercamerabinsrc.h
index b2f4c7ae6..d937321a8 100644
--- a/gst/camerabin2/gstwrappercamerabinsrc.h
+++ b/gst/camerabin2/gstwrappercamerabinsrc.h
@@ -90,2 +90,5 @@ struct _GstWrapperCameraBinSrc
+ /* For changing caps without losing timestamps */
+ gboolean drop_newseg;
+
/* Application configurable elements */