[vlc-devel] [PATCH 4/6] decoder: add decoder_UpdateVideoFrameLatency
Thomas Guillem
thomas at gllm.fr
Thu Sep 26 16:38:12 CEST 2019
This function must be used by threaded decoders to notify the frame latency to
the decoder clock.
---
include/vlc_codec.h | 22 ++++++++++++++++++++++
src/input/decoder.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 28a65846d9..6e8b3f7998 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -65,6 +65,7 @@ struct decoder_owner_callbacks
/* Display rate
* cf. decoder_GetDisplayRate */
float (*get_display_rate)( decoder_t * );
+ int (*update_frame_latency)( decoder_t *, unsigned frame_count );
} video;
struct
{
@@ -474,6 +475,27 @@ static inline float decoder_GetDisplayRate( decoder_t *dec )
return dec->cbs->video.get_display_rate( dec );
}
+/**
+ * This function updates the frame latency of the video decoder
+ *
+ * It must be used when using threaded decoders in order to notify a higher
+ * delay to the decoder clock.
+ *
+ * @return 0 in case of success, -1 otherwise. In case of error, the decoder
+ * module should disable threaded decoding or abort.
+ */
+VLC_USED
+static inline int decoder_UpdateVideoFrameLatency(decoder_t *dec,
+ unsigned frame_count)
+{
+ vlc_assert(dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL);
+
+ if (!dec->cbs->video.update_frame_latency)
+ return -1;
+
+ return dec->cbs->video.update_frame_latency(dec, frame_count);
+}
+
/** @} */
/**
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 57c9de6a1e..609dd82026 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -741,6 +741,35 @@ static float ModuleThread_GetDisplayRate( decoder_t *p_dec )
return rate;
}
+static int ModuleThread_UpdateVideoFrameLatency(decoder_t *p_dec, unsigned frame_count)
+{
+ struct decoder_owner *p_owner = dec_get_owner(p_dec);
+ unsigned frame_rate, frame_rate_base;
+
+ if( !p_owner->p_clock )
+ return -1;
+
+ if (p_dec->fmt_out.video.i_frame_rate > 0
+ && p_dec->fmt_out.video.i_frame_rate_base > 0)
+ {
+ frame_rate = p_dec->fmt_out.video.i_frame_rate;
+ frame_rate_base = p_dec->fmt_out.video.i_frame_rate_base;
+ }
+ else if (p_dec->fmt_in.video.i_frame_rate > 0
+ && p_dec->fmt_in.video.i_frame_rate_base > 0)
+ {
+ frame_rate = p_dec->fmt_in.video.i_frame_rate;
+ frame_rate_base = p_dec->fmt_in.video.i_frame_rate_base;
+ }
+ else
+ return -1;
+
+ vlc_tick_t latency_us = VLC_TICK_FROM_SEC(1) * frame_count
+ * frame_rate_base / frame_rate;
+
+ return vlc_clock_SetDecoderLatency( p_owner->p_clock, latency_us );
+}
+
/*****************************************************************************
* Public functions
*****************************************************************************/
@@ -1707,6 +1736,7 @@ static const struct decoder_owner_callbacks dec_video_cbs =
.queue_cc = ModuleThread_QueueCc,
.get_display_date = ModuleThread_GetDisplayDate,
.get_display_rate = ModuleThread_GetDisplayRate,
+ .update_frame_latency = ModuleThread_UpdateVideoFrameLatency,
},
.get_attachments = InputThread_GetInputAttachments,
};
--
2.20.1
More information about the vlc-devel
mailing list