mirror of https://git.ffmpeg.org/ffmpeg.git
libavcodec/qsvdec: remove redundant decodeHeader()
Since ffmpeg-qsv uses return value to reinit decoder, it doesn't need to decode header each time. Move qsv_decode_header's position so that it will be called only if codec needed to be reinitialized. Rearrange the code of flushing decoder and re-init decoder operation. Remove the buffer_count and use the got_frame to decide whether the decoder is drain. Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
This commit is contained in:
parent
40f38659d7
commit
4a633eb36f
|
@ -83,7 +83,6 @@ typedef struct QSVContext {
|
||||||
|
|
||||||
AVFifo *async_fifo;
|
AVFifo *async_fifo;
|
||||||
int zero_consume_run;
|
int zero_consume_run;
|
||||||
int buffered_count;
|
|
||||||
int reinit_flag;
|
int reinit_flag;
|
||||||
|
|
||||||
enum AVPixelFormat orig_pix_fmt;
|
enum AVPixelFormat orig_pix_fmt;
|
||||||
|
@ -654,8 +653,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
|
||||||
++q->zero_consume_run;
|
++q->zero_consume_run;
|
||||||
if (q->zero_consume_run > 1)
|
if (q->zero_consume_run > 1)
|
||||||
ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
|
ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
|
||||||
} else if (!*sync && bs.DataOffset) {
|
|
||||||
++q->buffered_count;
|
|
||||||
} else {
|
} else {
|
||||||
q->zero_consume_run = 0;
|
q->zero_consume_run = 0;
|
||||||
}
|
}
|
||||||
|
@ -788,20 +785,24 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
|
||||||
if (!avctx->coded_height)
|
if (!avctx->coded_height)
|
||||||
avctx->coded_height = 720;
|
avctx->coded_height = 720;
|
||||||
|
|
||||||
ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
|
/* decode zero-size pkt to flush the buffered pkt before reinit */
|
||||||
|
if (q->reinit_flag) {
|
||||||
if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
|
|
||||||
avctx->coded_width != param.mfx.FrameInfo.Width ||
|
|
||||||
avctx->coded_height != param.mfx.FrameInfo.Height))) {
|
|
||||||
AVPacket zero_pkt = {0};
|
AVPacket zero_pkt = {0};
|
||||||
|
ret = qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
|
||||||
|
if (ret < 0 || *got_frame)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (q->buffered_count) {
|
if (q->reinit_flag || !q->session || !q->initialized) {
|
||||||
q->reinit_flag = 1;
|
|
||||||
/* decode zero-size pkt to flush the buffered pkt before reinit */
|
|
||||||
q->buffered_count--;
|
|
||||||
return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
|
|
||||||
}
|
|
||||||
q->reinit_flag = 0;
|
q->reinit_flag = 0;
|
||||||
|
ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (ret == AVERROR(EAGAIN))
|
||||||
|
av_log(avctx, AV_LOG_INFO, "More data is required to decode header\n");
|
||||||
|
else
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
|
||||||
|
goto reinit_fail;
|
||||||
|
}
|
||||||
|
|
||||||
q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
|
q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue