lavc/qsvdec: expose frame pic_type and key_frame
[libav.git] / libavcodec / qsvdec.c
CommitLineData
4e08c821
AK
1/*
2 * Intel MediaSDK QSV codec-independent code
3 *
4 * copyright (c) 2013 Luca Barbato
5 * copyright (c) 2015 Anton Khirnov <anton@khirnov.net>
6 *
7 * This file is part of Libav.
8 *
9 * Libav is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * Libav is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Libav; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <string.h>
25#include <sys/types.h>
26
27#include <mfx/mfxvideo.h>
28
29#include "libavutil/common.h"
a0524d9b
AK
30#include "libavutil/hwcontext.h"
31#include "libavutil/hwcontext_qsv.h"
4e08c821
AK
32#include "libavutil/mem.h"
33#include "libavutil/log.h"
92736c74 34#include "libavutil/pixdesc.h"
4e08c821
AK
35#include "libavutil/pixfmt.h"
36#include "libavutil/time.h"
37
38#include "avcodec.h"
39#include "internal.h"
96dca089 40#include "qsv.h"
d0a63d8b 41#include "qsv_internal.h"
b04d009b 42#include "qsvdec.h"
4e08c821 43
2fcb0090
MT
44const AVCodecHWConfigInternal *ff_qsv_hw_configs[] = {
45 &(const AVCodecHWConfigInternal) {
46 .public = {
47 .pix_fmt = AV_PIX_FMT_QSV,
48 .methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
49 AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
50 .device_type = AV_HWDEVICE_TYPE_QSV,
51 },
52 .hwaccel = NULL,
53 },
54 NULL
55};
56
a0524d9b 57static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
8848ba0b 58 AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
4e08c821 59{
a0524d9b
AK
60 int ret;
61
62 if (session) {
63 q->session = session;
64 } else if (hw_frames_ref) {
65 if (q->internal_session) {
66 MFXClose(q->internal_session);
67 q->internal_session = NULL;
68 }
69 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
70
71 q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
72 if (!q->frames_ctx.hw_frames_ctx)
73 return AVERROR(ENOMEM);
74
4936a48b
MT
75 ret = ff_qsv_init_session_frames(avctx, &q->internal_session,
76 &q->frames_ctx, q->load_plugins,
77 q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
a0524d9b
AK
78 if (ret < 0) {
79 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
80 return ret;
81 }
82
83 q->session = q->internal_session;
8848ba0b
MT
84 } else if (hw_device_ref) {
85 if (q->internal_session) {
86 MFXClose(q->internal_session);
87 q->internal_session = NULL;
88 }
89
90 ret = ff_qsv_init_session_device(avctx, &q->internal_session,
91 hw_device_ref, q->load_plugins);
92 if (ret < 0)
93 return ret;
94
95 q->session = q->internal_session;
a0524d9b 96 } else {
4e08c821 97 if (!q->internal_session) {
a0524d9b
AK
98 ret = ff_qsv_init_internal_session(avctx, &q->internal_session,
99 q->load_plugins);
d0a63d8b
AK
100 if (ret < 0)
101 return ret;
4e08c821
AK
102 }
103
104 q->session = q->internal_session;
4e08c821
AK
105 }
106
107 /* make sure the decoder is uninitialized */
108 MFXVideoDECODE_Close(q->session);
109
110 return 0;
111}
112
6f19bbcf 113static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
4e08c821 114{
92736c74 115 const AVPixFmtDescriptor *desc;
6f19bbcf 116 mfxSession session = NULL;
a0524d9b 117 int iopattern = 0;
76167140 118 mfxVideoParam param = { 0 };
924e2ecd
AK
119 int frame_width = avctx->coded_width;
120 int frame_height = avctx->coded_height;
4e08c821
AK
121 int ret;
122
92736c74
AK
123 desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
124 if (!desc)
125 return AVERROR_BUG;
126
22522d9c
AK
127 if (!q->async_fifo) {
128 q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
3c53627a 129 (sizeof(mfxSyncPoint*) + sizeof(QSVFrame*)));
22522d9c
AK
130 if (!q->async_fifo)
131 return AVERROR(ENOMEM);
132 }
f5c4d38c 133
e328178d 134 if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
6f19bbcf
AK
135 AVQSVContext *user_ctx = avctx->hwaccel_context;
136 session = user_ctx->session;
a0524d9b 137 iopattern = user_ctx->iopattern;
6f19bbcf
AK
138 q->ext_buffers = user_ctx->ext_buffers;
139 q->nb_ext_buffers = user_ctx->nb_ext_buffers;
140 }
141
a0524d9b
AK
142 if (avctx->hw_frames_ctx) {
143 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
144 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
145
146 if (!iopattern) {
147 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
148 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
149 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
150 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
151 }
152 }
153
154 if (!iopattern)
155 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
156 q->iopattern = iopattern;
157
8848ba0b 158 ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
4e08c821
AK
159 if (ret < 0) {
160 av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
161 return ret;
162 }
163
d0a63d8b 164 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
4e08c821
AK
165 if (ret < 0)
166 return ret;
167
168 param.mfx.CodecId = ret;
cd1047f3
MT
169 param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id, avctx->profile);
170 param.mfx.CodecLevel = avctx->level == FF_LEVEL_UNKNOWN ? MFX_LEVEL_UNKNOWN : avctx->level;
4e08c821 171
92736c74
AK
172 param.mfx.FrameInfo.BitDepthLuma = desc->comp[0].depth;
173 param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
174 param.mfx.FrameInfo.Shift = desc->comp[0].depth > 8;
536bb17e 175 param.mfx.FrameInfo.FourCC = q->fourcc;
924e2ecd
AK
176 param.mfx.FrameInfo.Width = frame_width;
177 param.mfx.FrameInfo.Height = frame_height;
4e08c821
AK
178 param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
179
030d84fa
MT
180 switch (avctx->field_order) {
181 case AV_FIELD_PROGRESSIVE:
182 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
183 break;
184 case AV_FIELD_TT:
185 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
186 break;
187 case AV_FIELD_BB:
188 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
189 break;
190 default:
191 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
192 break;
193 }
194
4e08c821
AK
195 param.IOPattern = q->iopattern;
196 param.AsyncDepth = q->async_depth;
197 param.ExtParam = q->ext_buffers;
198 param.NumExtParam = q->nb_ext_buffers;
199
200 ret = MFXVideoDECODE_Init(q->session, &param);
95414eb2
AK
201 if (ret < 0)
202 return ff_qsv_print_error(avctx, ret,
203 "Error initializing the MFX video decoder");
4e08c821 204
ce320cf1
AK
205 q->frame_info = param.mfx.FrameInfo;
206
4e08c821
AK
207 return 0;
208}
209
ce320cf1 210static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
4e08c821
AK
211{
212 int ret;
213
214 ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
215 if (ret < 0)
216 return ret;
217
218 if (frame->frame->format == AV_PIX_FMT_QSV) {
404e5147 219 frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
4e08c821 220 } else {
404e5147 221 frame->surface.Info = q->frame_info;
4e08c821 222
404e5147
AK
223 frame->surface.Data.PitchLow = frame->frame->linesize[0];
224 frame->surface.Data.Y = frame->frame->data[0];
225 frame->surface.Data.UV = frame->frame->data[1];
4e08c821
AK
226 }
227
00aeedd8
AK
228 if (q->frames_ctx.mids) {
229 ret = ff_qsv_find_surface_idx(&q->frames_ctx, frame);
230 if (ret < 0)
231 return ret;
232
233 frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
234 }
52ed83fa
ZL
235 frame->surface.Data.ExtParam = &frame->ext_param;
236 frame->surface.Data.NumExtParam = 1;
237 frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
238 frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
239 frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
00aeedd8 240
404e5147
AK
241 frame->used = 1;
242
4e08c821
AK
243 return 0;
244}
245
246static void qsv_clear_unused_frames(QSVContext *q)
247{
248 QSVFrame *cur = q->work_frames;
249 while (cur) {
404e5147
AK
250 if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
251 cur->used = 0;
4e08c821
AK
252 av_frame_unref(cur->frame);
253 }
254 cur = cur->next;
255 }
256}
257
258static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
259{
260 QSVFrame *frame, **last;
261 int ret;
262
263 qsv_clear_unused_frames(q);
264
265 frame = q->work_frames;
266 last = &q->work_frames;
267 while (frame) {
404e5147 268 if (!frame->used) {
ce320cf1 269 ret = alloc_frame(avctx, q, frame);
4e08c821
AK
270 if (ret < 0)
271 return ret;
404e5147 272 *surf = &frame->surface;
4e08c821
AK
273 return 0;
274 }
275
276 last = &frame->next;
277 frame = frame->next;
278 }
279
280 frame = av_mallocz(sizeof(*frame));
281 if (!frame)
282 return AVERROR(ENOMEM);
283 frame->frame = av_frame_alloc();
284 if (!frame->frame) {
285 av_freep(&frame);
286 return AVERROR(ENOMEM);
287 }
288 *last = frame;
289
ce320cf1 290 ret = alloc_frame(avctx, q, frame);
4e08c821
AK
291 if (ret < 0)
292 return ret;
293
404e5147 294 *surf = &frame->surface;
4e08c821
AK
295
296 return 0;
297}
298
f5c4d38c 299static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
4e08c821
AK
300{
301 QSVFrame *cur = q->work_frames;
302 while (cur) {
404e5147 303 if (surf == &cur->surface)
f5c4d38c 304 return cur;
4e08c821
AK
305 cur = cur->next;
306 }
307 return NULL;
308}
309
96dca089
AK
310static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
311 AVFrame *frame, int *got_frame,
312 AVPacket *avpkt)
4e08c821 313{
f5c4d38c 314 QSVFrame *out_frame;
4e08c821
AK
315 mfxFrameSurface1 *insurf;
316 mfxFrameSurface1 *outsurf;
3c53627a 317 mfxSyncPoint *sync;
4e08c821
AK
318 mfxBitstream bs = { { { 0 } } };
319 int ret;
320
321 if (avpkt->size) {
322 bs.Data = avpkt->data;
323 bs.DataLength = avpkt->size;
324 bs.MaxLength = bs.DataLength;
325 bs.TimeStamp = avpkt->pts;
326 }
327
3c53627a
AK
328 sync = av_mallocz(sizeof(*sync));
329 if (!sync) {
330 av_freep(&sync);
331 return AVERROR(ENOMEM);
332 }
333
4e08c821
AK
334 do {
335 ret = get_surface(avctx, q, &insurf);
d32bdadd
TG
336 if (ret < 0) {
337 av_freep(&sync);
4e08c821 338 return ret;
d32bdadd 339 }
4e08c821
AK
340
341 ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
3c53627a 342 insurf, &outsurf, sync);
4e08c821
AK
343 if (ret == MFX_WRN_DEVICE_BUSY)
344 av_usleep(1);
345
346 } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
347
348 if (ret != MFX_ERR_NONE &&
349 ret != MFX_ERR_MORE_DATA &&
350 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
351 ret != MFX_ERR_MORE_SURFACE) {
3c53627a 352 av_freep(&sync);
95414eb2
AK
353 return ff_qsv_print_error(avctx, ret,
354 "Error during QSV decoding.");
4e08c821
AK
355 }
356
aa9d15d8
AK
357 /* make sure we do not enter an infinite loop if the SDK
358 * did not consume any data and did not return anything */
3c53627a 359 if (!*sync && !bs.DataOffset) {
aa9d15d8 360 bs.DataOffset = avpkt->size;
0940b748
MT
361 ++q->zero_consume_run;
362 if (q->zero_consume_run > 1)
363 ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
364 } else {
365 q->zero_consume_run = 0;
aa9d15d8
AK
366 }
367
3c53627a 368 if (*sync) {
f5c4d38c 369 QSVFrame *out_frame = find_frame(q, outsurf);
4e08c821 370
f5c4d38c 371 if (!out_frame) {
4e08c821
AK
372 av_log(avctx, AV_LOG_ERROR,
373 "The returned surface does not correspond to any frame\n");
3c53627a 374 av_freep(&sync);
4e08c821
AK
375 return AVERROR_BUG;
376 }
377
f5c4d38c
AK
378 out_frame->queued = 1;
379 av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
380 av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
3c53627a
AK
381 } else {
382 av_freep(&sync);
f5c4d38c
AK
383 }
384
385 if (!av_fifo_space(q->async_fifo) ||
386 (!avpkt->size && av_fifo_size(q->async_fifo))) {
387 AVFrame *src_frame;
388
389 av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
390 av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
391 out_frame->queued = 0;
392
b68e3531
AK
393 if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
394 do {
395 ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
396 } while (ret == MFX_WRN_IN_EXECUTION);
397 }
f5c4d38c 398
3c53627a
AK
399 av_freep(&sync);
400
f5c4d38c
AK
401 src_frame = out_frame->frame;
402
4e08c821
AK
403 ret = av_frame_ref(frame, src_frame);
404 if (ret < 0)
405 return ret;
406
404e5147 407 outsurf = &out_frame->surface;
f5c4d38c 408
32c83590
AK
409#if FF_API_PKT_PTS
410FF_DISABLE_DEPRECATION_WARNINGS
411 frame->pkt_pts = outsurf->Data.TimeStamp;
412FF_ENABLE_DEPRECATION_WARNINGS
413#endif
414 frame->pts = outsurf->Data.TimeStamp;
4e08c821
AK
415
416 frame->repeat_pict =
417 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
418 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
419 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
420 frame->top_field_first =
421 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
422 frame->interlaced_frame =
423 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
52ed83fa
ZL
424 frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
425 //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
426 if (avctx->codec_id == AV_CODEC_ID_H264)
427 frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
4e08c821 428
404e5147
AK
429 /* update the surface properties */
430 if (avctx->pix_fmt == AV_PIX_FMT_QSV)
431 ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
432
4e08c821
AK
433 *got_frame = 1;
434 }
435
436 return bs.DataOffset;
437}
438
9ba27c23 439int ff_qsv_decode_close(QSVContext *q)
4e08c821
AK
440{
441 QSVFrame *cur = q->work_frames;
442
2c32eace
AK
443 if (q->session)
444 MFXVideoDECODE_Close(q->session);
445
3c53627a
AK
446 while (q->async_fifo && av_fifo_size(q->async_fifo)) {
447 QSVFrame *out_frame;
448 mfxSyncPoint *sync;
449
450 av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
451 av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
452
453 av_freep(&sync);
454 }
455
4e08c821
AK
456 while (cur) {
457 q->work_frames = cur->next;
458 av_frame_free(&cur->frame);
459 av_freep(&cur);
460 cur = q->work_frames;
461 }
462
f5c4d38c
AK
463 av_fifo_free(q->async_fifo);
464 q->async_fifo = NULL;
465
96dca089
AK
466 av_parser_close(q->parser);
467 avcodec_free_context(&q->avctx_internal);
468
4e08c821
AK
469 if (q->internal_session)
470 MFXClose(q->internal_session);
471
a0524d9b 472 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
4ab61cd9 473 av_buffer_unref(&q->frames_ctx.mids_buf);
a0524d9b 474
4e08c821
AK
475 return 0;
476}
96dca089
AK
477
478int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
479 AVFrame *frame, int *got_frame, AVPacket *pkt)
480{
481 uint8_t *dummy_data;
482 int dummy_size;
483 int ret;
cbe28bc0 484 const AVPixFmtDescriptor *desc;
96dca089
AK
485
486 if (!q->avctx_internal) {
487 q->avctx_internal = avcodec_alloc_context3(NULL);
488 if (!q->avctx_internal)
489 return AVERROR(ENOMEM);
490
491 if (avctx->extradata) {
059a9348 492 q->avctx_internal->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
96dca089
AK
493 if (!q->avctx_internal->extradata)
494 return AVERROR(ENOMEM);
495
496 memcpy(q->avctx_internal->extradata, avctx->extradata,
497 avctx->extradata_size);
498 q->avctx_internal->extradata_size = avctx->extradata_size;
499 }
500
501 q->parser = av_parser_init(avctx->codec_id);
502 if (!q->parser)
503 return AVERROR(ENOMEM);
504
505 q->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
506 q->orig_pix_fmt = AV_PIX_FMT_NONE;
507 }
508
509 if (!pkt->size)
510 return qsv_decode(avctx, q, frame, got_frame, pkt);
511
512 /* we assume the packets are already split properly and want
513 * just the codec parameters here */
514 av_parser_parse2(q->parser, q->avctx_internal,
515 &dummy_data, &dummy_size,
516 pkt->data, pkt->size, pkt->pts, pkt->dts,
517 pkt->pos);
518
519 /* TODO: flush delayed frames on reinit */
520 if (q->parser->format != q->orig_pix_fmt ||
cbe28bc0
MD
521 FFALIGN(q->parser->coded_width, 16) != FFALIGN(avctx->coded_width, 16) ||
522 FFALIGN(q->parser->coded_height, 16) != FFALIGN(avctx->coded_height, 16)) {
96dca089
AK
523 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
524 AV_PIX_FMT_NONE,
525 AV_PIX_FMT_NONE };
526 enum AVPixelFormat qsv_format;
527
536bb17e 528 qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
96dca089
AK
529 if (qsv_format < 0) {
530 av_log(avctx, AV_LOG_ERROR,
92736c74
AK
531 "Decoding pixel format '%s' is not supported\n",
532 av_get_pix_fmt_name(q->parser->format));
96dca089
AK
533 ret = AVERROR(ENOSYS);
534 goto reinit_fail;
535 }
536
537 q->orig_pix_fmt = q->parser->format;
538 avctx->pix_fmt = pix_fmts[1] = qsv_format;
539 avctx->width = q->parser->width;
540 avctx->height = q->parser->height;
cbe28bc0
MD
541 avctx->coded_width = FFALIGN(q->parser->coded_width, 16);
542 avctx->coded_height = FFALIGN(q->parser->coded_height, 16);
030d84fa 543 avctx->field_order = q->parser->field_order;
96dca089
AK
544 avctx->level = q->avctx_internal->level;
545 avctx->profile = q->avctx_internal->profile;
546
547 ret = ff_get_format(avctx, pix_fmts);
548 if (ret < 0)
549 goto reinit_fail;
550
551 avctx->pix_fmt = ret;
552
cbe28bc0
MD
553 desc = av_pix_fmt_desc_get(avctx->pix_fmt);
554 if (!desc)
555 goto reinit_fail;
556
557 if (desc->comp[0].depth > 8) {
558 avctx->coded_width = FFALIGN(q->parser->coded_width, 32);
559 avctx->coded_height = FFALIGN(q->parser->coded_height, 32);
560 }
561
6f19bbcf 562 ret = qsv_decode_init(avctx, q);
96dca089
AK
563 if (ret < 0)
564 goto reinit_fail;
565 }
566
567 return qsv_decode(avctx, q, frame, got_frame, pkt);
568
569reinit_fail:
570 q->orig_pix_fmt = q->parser->format = avctx->pix_fmt = AV_PIX_FMT_NONE;
571 return ret;
572}
573
574void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
575{
576 q->orig_pix_fmt = AV_PIX_FMT_NONE;
577}