From 7b979703f8c2d4485d9cde071e0e63c026e1132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 14 Jan 2015 15:54:28 +0100 Subject: [PATCH] decklinkvideosink: Keep track of the time when we went to PLAYING for the external clock too Otherwise we're adding an offset of the time the pipeline was in PLAYING already to the running time when converting it to our internal clock. --- sys/decklink/gstdecklinkvideosink.cpp | 14 ++++++++++++-- sys/decklink/gstdecklinkvideosink.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sys/decklink/gstdecklinkvideosink.cpp b/sys/decklink/gstdecklinkvideosink.cpp index 8c9c73f942..69f8f3a698 100644 --- a/sys/decklink/gstdecklinkvideosink.cpp +++ b/sys/decklink/gstdecklinkvideosink.cpp @@ -209,12 +209,12 @@ convert_to_internal_clock (GstDecklinkVideoSink * self, gst_clock_get_calibration (self->output->clock, &internal, &external, &rate_n, &rate_d); - if (rate_n != rate_d) { + if (rate_n != rate_d && self->internal_base_time != GST_CLOCK_TIME_NONE) { GstClockTime external_timestamp = *timestamp; // Convert to the running time corresponding to both clock times internal -= self->internal_base_time; - external -= gst_element_get_base_time (GST_ELEMENT_CAST (self)); + external -= self->external_base_time; // Get the difference in the external time, note // that the running time is external time. @@ -568,6 +568,8 @@ gst_decklink_video_sink_change_state (GstElement * element, (NULL), ("Failed to stop scheduled playback: 0x%08x", res)); ret = GST_STATE_CHANGE_FAILURE; } + self->internal_base_time = GST_CLOCK_TIME_NONE; + self->external_base_time = GST_CLOCK_TIME_NONE; break; } case GST_STATE_CHANGE_PAUSED_TO_PLAYING:{ @@ -584,8 +586,16 @@ gst_decklink_video_sink_change_state (GstElement * element, if (start_time == GST_CLOCK_TIME_NONE) start_time = 0; + // Current times of internal and external clock when we go to + // playing. We need this to convert the pipeline running time + // to the running time of the hardware + // + // We can't use the normal base time for the external clock + // because we might go to PLAYING later than the pipeline self->internal_base_time = gst_clock_get_internal_time (self->output->clock); + self->external_base_time = + gst_clock_get_internal_time (GST_ELEMENT_CLOCK (self)); convert_to_internal_clock (self, &start_time, NULL); diff --git a/sys/decklink/gstdecklinkvideosink.h b/sys/decklink/gstdecklinkvideosink.h index 6052feb5a7..16b2fbb3fe 100644 --- a/sys/decklink/gstdecklinkvideosink.h +++ b/sys/decklink/gstdecklinkvideosink.h @@ -55,6 +55,7 @@ struct _GstDecklinkVideoSink GstVideoInfo info; GstClockTime internal_base_time; + GstClockTime external_base_time; GstDecklinkOutput *output; };