diff --git a/sys/decklink/gstdecklinkvideosink.cpp b/sys/decklink/gstdecklinkvideosink.cpp index 8eaa54aba434a53095d6e66e7b3b5c962983fac4..59911338d6be7b81b1d1fd2b297a9d04a13ce011 100644 --- a/sys/decklink/gstdecklinkvideosink.cpp +++ b/sys/decklink/gstdecklinkvideosink.cpp @@ -640,20 +640,21 @@ gst_decklink_video_sink_convert_to_internal_clock (GstDecklinkVideoSink * self, GST_TIME_FORMAT, GST_TIME_ARGS (*timestamp)); } - if (GST_CLOCK_TIME_IS_VALID (self->paused_start_time)) { + if (GST_CLOCK_TIME_IS_VALID (self->paused_start_time) && + GST_CLOCK_TIME_IS_VALID (self->playing_base_time)) { + /* add the time since we were last playing. */ + *timestamp += self->paused_start_time + self->playing_base_time; + } else { /* only valid whil we're in PAUSED and most likely without a set clock, * we update based on our internal clock */ *timestamp += gst_clock_get_internal_time (self->output->clock); - } else { - /* add the time since we were last playing. */ - *timestamp += self->playing_start_time; } GST_LOG_OBJECT (self, "Output timestamp %" GST_TIME_FORMAT " using paused start at %" GST_TIME_FORMAT " playing start at %" GST_TIME_FORMAT, GST_TIME_ARGS (*timestamp), GST_TIME_ARGS (self->paused_start_time), - GST_TIME_ARGS (self->playing_start_time)); + GST_TIME_ARGS (self->playing_base_time)); } static GstFlowReturn @@ -1211,6 +1212,9 @@ gst_decklink_video_sink_change_state (GstElement * element, GST_STATE_CHANGE_FAILURE) ret = GST_STATE_CHANGE_FAILURE; break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + self->playing_exit_time = gst_clock_get_internal_time (self->output->clock); + break; default: break; } @@ -1259,12 +1263,11 @@ gst_decklink_video_sink_state_changed (GstElement * element, GstDecklinkVideoSink *self = GST_DECKLINK_VIDEO_SINK_CAST (element); if (new_state == GST_STATE_PLAYING) { - self->paused_start_time = GST_CLOCK_TIME_NONE; - self->playing_start_time = - gst_clock_get_internal_time (self->output->clock); - GST_DEBUG_OBJECT (self, - "playing entered, new playing start time %" GST_TIME_FORMAT, - GST_TIME_ARGS (self->playing_start_time)); + self->playing_base_time = gst_clock_get_internal_time (self->output->clock) - self->playing_exit_time; + GST_DEBUG_OBJECT (self, "playing entered paused start time %" + GST_TIME_FORMAT "playing base time %" GST_TIME_FORMAT, + GST_TIME_ARGS (self->paused_start_time), + GST_TIME_ARGS (self->playing_base_time)); } if (new_state == GST_STATE_PAUSED) { diff --git a/sys/decklink/gstdecklinkvideosink.h b/sys/decklink/gstdecklinkvideosink.h index a91775f26272076bdee50591a5b53baab7e95f3d..ddcec67ea2c26436ff2cd26eef0fb63ba88b3b72 100644 --- a/sys/decklink/gstdecklinkvideosink.h +++ b/sys/decklink/gstdecklinkvideosink.h @@ -63,9 +63,10 @@ struct _GstDecklinkVideoSink /* all in internal time of the decklink clock */ /* really an internal base time */ - GstClockTime playing_start_time; /* time that we entered playing */ + GstClockTime playing_base_time; /* time that we entered playing */ /* really an internal start time */ GstClockTime paused_start_time; /* time we entered paused, used to track how long we are in paused while the clock is running */ + GstClockTime playing_exit_time; /* time that we exit playing */ GstDecklinkOutput *output;