Commit 7bb4f93d authored by Mathieu Duponchelle's avatar Mathieu Duponchelle Committed by Edward Hervey

gstavviddec: Sanitize and fix qos handling.

gst_video_decoder_get_max_decding_time doesn't return a GstClockTime
but a GstClockTimeDiff, and thus one needs to compare it against
G_MAXINT_64.

The returning of a boolean and the extra subsequent code in _video_frame
was uselessly complicated.

The previous behaviour led to artefacts when the decoder tried to
hurry up.

https://bugzilla.gnome.org/show_bug.cgi?id=730075
parent 78b64cbd
......@@ -1066,10 +1066,8 @@ negotiate_failed:
* Sets the skip_frame flag and if things are really bad, skips to the next
* keyframe.
*
* Returns TRUE if the frame should be decoded, FALSE if the frame can be dropped
* entirely.
*/
static gboolean
static void
gst_ffmpegviddec_do_qos (GstFFMpegVidDec * ffmpegdec,
GstVideoCodecFrame * frame, gboolean * mode_switch)
{
......@@ -1078,47 +1076,29 @@ gst_ffmpegviddec_do_qos (GstFFMpegVidDec * ffmpegdec,
*mode_switch = FALSE;
if (frame == NULL)
goto no_qos;
return;
diff =
gst_video_decoder_get_max_decode_time (GST_VIDEO_DECODER (ffmpegdec),
frame);
/* if we don't have timing info, then we don't do QoS */
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (diff)))
goto no_qos;
GST_DEBUG_OBJECT (ffmpegdec, "decoding time %" GST_TIME_FORMAT,
GST_TIME_ARGS (diff));
if (G_UNLIKELY(diff == G_MAXINT64))
return;
if (diff > 0)
goto normal_mode;
GST_DEBUG_OBJECT (ffmpegdec, "decoding time %" G_GINT64_FORMAT, diff);
if (diff <= 0) {
goto skip_frame;
if (diff > 0 && ffmpegdec->context->skip_frame != AVDISCARD_DEFAULT) {
ffmpegdec->context->skip_frame = AVDISCARD_DEFAULT;
*mode_switch = TRUE;
GST_DEBUG_OBJECT (ffmpegdec, "QOS: normal mode");
}
no_qos:
return TRUE;
normal_mode:
{
if (ffmpegdec->context->skip_frame != AVDISCARD_DEFAULT) {
ffmpegdec->context->skip_frame = AVDISCARD_DEFAULT;
*mode_switch = TRUE;
GST_DEBUG_OBJECT (ffmpegdec, "QOS: normal mode");
}
return TRUE;
}
skip_frame:
{
if (ffmpegdec->context->skip_frame != AVDISCARD_NONREF) {
ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
*mode_switch = TRUE;
GST_DEBUG_OBJECT (ffmpegdec,
"QOS: hurry up, diff %" G_GINT64_FORMAT " >= 0", diff);
}
return FALSE;
else if (diff <= 0 && ffmpegdec->context->skip_frame != AVDISCARD_NONREF) {
ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
*mode_switch = TRUE;
GST_DEBUG_OBJECT (ffmpegdec,
"QOS: hurry up, diff %" G_GINT64_FORMAT " >= 0", diff);
}
}
......@@ -1206,8 +1186,6 @@ gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
gint len = -1;
gint have_data;
gboolean mode_switch;
gboolean decode;
gint skip_frame = AVDISCARD_DEFAULT;
GstVideoCodecFrame *out_frame;
GstFFMpegVidDecVideoFrame *out_dframe;
AVPacket packet;
......@@ -1219,7 +1197,7 @@ gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
/* run QoS code, we don't stop decoding the frame when we are late because
* else we might skip a reference frame */
decode = gst_ffmpegviddec_do_qos (ffmpegdec, frame, &mode_switch);
gst_ffmpegviddec_do_qos (ffmpegdec, frame, &mode_switch);
if (ffmpegdec->is_realvideo && data != NULL) {
gint slice_count;
......@@ -1239,13 +1217,6 @@ gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
}
}
if (!decode) {
/* no decoding needed, save previous skip_frame value and brutely skip
* decoding everything */
skip_frame = ffmpegdec->context->skip_frame;
ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
}
if (frame) {
/* save reference to the timing info */
ffmpegdec->context->reordered_opaque = (gint64) frame->system_frame_number;
......@@ -1270,10 +1241,6 @@ gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
len = avcodec_decode_video2 (ffmpegdec->context,
ffmpegdec->picture, &have_data, &packet);
/* restore previous state */
if (!decode)
ffmpegdec->context->skip_frame = skip_frame;
GST_DEBUG_OBJECT (ffmpegdec, "after decode: len %d, have_data %d",
len, have_data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment