mirror of https://git.ffmpeg.org/ffmpeg.git
lavc/qsvdec: flush buffered data before reinit
Flush the buffered data in libmfx before video param reinit in case the frames drop. Cache the first frame causing the reinit and decode zero-size pkt to flush the buffered pkt before reinit. After all the buffered pkts being flushed, resume to reinit and decode. Fix the issue in ticket #7399. [V2]: Move the definition of zero_pkt to where it is exactly used. Signed-off-by: Linjie Fu <linjie.fu@intel.com> Signed-off-by: Zhong Li <zhong.li@intel.com>
This commit is contained in:
parent
beaa350e24
commit
87368884a5
|
@ -372,6 +372,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -526,6 +528,16 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
|
||||||
AV_PIX_FMT_NONE,
|
AV_PIX_FMT_NONE,
|
||||||
AV_PIX_FMT_NONE };
|
AV_PIX_FMT_NONE };
|
||||||
enum AVPixelFormat qsv_format;
|
enum AVPixelFormat qsv_format;
|
||||||
|
AVPacket zero_pkt = {0};
|
||||||
|
|
||||||
|
if (q->buffered_count) {
|
||||||
|
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;
|
||||||
|
|
||||||
qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
|
qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
|
||||||
if (qsv_format < 0) {
|
if (qsv_format < 0) {
|
||||||
|
|
|
@ -53,6 +53,8 @@ typedef struct QSVContext {
|
||||||
|
|
||||||
AVFifoBuffer *async_fifo;
|
AVFifoBuffer *async_fifo;
|
||||||
int zero_consume_run;
|
int zero_consume_run;
|
||||||
|
int buffered_count;
|
||||||
|
int reinit_flag;
|
||||||
|
|
||||||
// the internal parser and codec context for parsing the data
|
// the internal parser and codec context for parsing the data
|
||||||
AVCodecParserContext *parser;
|
AVCodecParserContext *parser;
|
||||||
|
|
|
@ -146,10 +146,11 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
/* no more data */
|
/* no more data */
|
||||||
if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
|
if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
|
||||||
return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
|
return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
|
||||||
|
/* in progress of reinit, no read from fifo and keep the buffer_pkt */
|
||||||
av_packet_unref(&s->buffer_pkt);
|
if (!s->qsv.reinit_flag) {
|
||||||
|
av_packet_unref(&s->buffer_pkt);
|
||||||
av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
|
av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
|
ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
|
||||||
|
@ -159,6 +160,8 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
av_packet_unref(&s->buffer_pkt);
|
av_packet_unref(&s->buffer_pkt);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
if (s->qsv.reinit_flag)
|
||||||
|
continue;
|
||||||
|
|
||||||
s->buffer_pkt.size -= ret;
|
s->buffer_pkt.size -= ret;
|
||||||
s->buffer_pkt.data += ret;
|
s->buffer_pkt.data += ret;
|
||||||
|
|
|
@ -132,9 +132,11 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
/* no more data */
|
/* no more data */
|
||||||
if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
|
if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
|
||||||
return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
|
return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
|
||||||
|
/* in progress of reinit, no read from fifo and keep the buffer_pkt */
|
||||||
av_packet_unref(&s->input_ref);
|
if (!s->qsv.reinit_flag) {
|
||||||
av_fifo_generic_read(s->packet_fifo, &s->input_ref, sizeof(s->input_ref), NULL);
|
av_packet_unref(&s->input_ref);
|
||||||
|
av_fifo_generic_read(s->packet_fifo, &s->input_ref, sizeof(s->input_ref), NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->input_ref);
|
ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->input_ref);
|
||||||
|
@ -145,6 +147,8 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
if (s->qsv.reinit_flag)
|
||||||
|
continue;
|
||||||
|
|
||||||
s->input_ref.size -= ret;
|
s->input_ref.size -= ret;
|
||||||
s->input_ref.data += ret;
|
s->input_ref.data += ret;
|
||||||
|
|
Loading…
Reference in New Issue