You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

636 lines
19KB

  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 FFmpeg.
  8. *
  9. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <string.h>
  24. #include <sys/types.h>
  25. #include <mfx/mfxvideo.h>
  26. #include "libavutil/common.h"
  27. #include "libavutil/hwcontext.h"
  28. #include "libavutil/hwcontext_qsv.h"
  29. #include "libavutil/mem.h"
  30. #include "libavutil/log.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "libavutil/pixfmt.h"
  33. #include "libavutil/time.h"
  34. #include "libavutil/imgutils.h"
  35. #include "avcodec.h"
  36. #include "internal.h"
  37. #include "decode.h"
  38. #include "qsv.h"
  39. #include "qsv_internal.h"
  40. #include "qsvdec.h"
  41. const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = {
  42. &(const AVCodecHWConfigInternal) {
  43. .public = {
  44. .pix_fmt = AV_PIX_FMT_QSV,
  45. .methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
  46. AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
  47. .device_type = AV_HWDEVICE_TYPE_QSV,
  48. },
  49. .hwaccel = NULL,
  50. },
  51. NULL
  52. };
  53. static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
  54. {
  55. int ret = 0;
  56. ff_decode_frame_props(avctx, frame);
  57. frame->width = avctx->width;
  58. frame->height = avctx->height;
  59. switch (avctx->pix_fmt) {
  60. case AV_PIX_FMT_NV12:
  61. frame->linesize[0] = FFALIGN(avctx->width, 128);
  62. break;
  63. case AV_PIX_FMT_P010:
  64. frame->linesize[0] = 2 * FFALIGN(avctx->width, 128);
  65. break;
  66. default:
  67. av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
  68. return AVERROR(EINVAL);
  69. }
  70. frame->linesize[1] = frame->linesize[0];
  71. frame->buf[0] = av_buffer_pool_get(pool);
  72. if (!frame->buf[0])
  73. return AVERROR(ENOMEM);
  74. frame->data[0] = frame->buf[0]->data;
  75. frame->data[1] = frame->data[0] +
  76. frame->linesize[0] * FFALIGN(avctx->height, 64);
  77. ret = ff_attach_decode_data(frame);
  78. if (ret < 0)
  79. return ret;
  80. return 0;
  81. }
  82. static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
  83. AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
  84. {
  85. int ret;
  86. if (q->gpu_copy == MFX_GPUCOPY_ON &&
  87. !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
  88. av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
  89. "only works in system memory mode.\n");
  90. q->gpu_copy = MFX_GPUCOPY_OFF;
  91. }
  92. if (session) {
  93. q->session = session;
  94. } else if (hw_frames_ref) {
  95. if (q->internal_qs.session) {
  96. MFXClose(q->internal_qs.session);
  97. q->internal_qs.session = NULL;
  98. }
  99. av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
  100. q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
  101. if (!q->frames_ctx.hw_frames_ctx)
  102. return AVERROR(ENOMEM);
  103. ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
  104. &q->frames_ctx, q->load_plugins,
  105. q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
  106. q->gpu_copy);
  107. if (ret < 0) {
  108. av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
  109. return ret;
  110. }
  111. q->session = q->internal_qs.session;
  112. } else if (hw_device_ref) {
  113. if (q->internal_qs.session) {
  114. MFXClose(q->internal_qs.session);
  115. q->internal_qs.session = NULL;
  116. }
  117. ret = ff_qsv_init_session_device(avctx, &q->internal_qs.session,
  118. hw_device_ref, q->load_plugins, q->gpu_copy);
  119. if (ret < 0)
  120. return ret;
  121. q->session = q->internal_qs.session;
  122. } else {
  123. if (!q->internal_qs.session) {
  124. ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
  125. q->load_plugins, q->gpu_copy);
  126. if (ret < 0)
  127. return ret;
  128. }
  129. q->session = q->internal_qs.session;
  130. }
  131. /* make sure the decoder is uninitialized */
  132. MFXVideoDECODE_Close(q->session);
  133. return 0;
  134. }
  135. static inline unsigned int qsv_fifo_item_size(void)
  136. {
  137. return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
  138. }
  139. static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
  140. {
  141. return av_fifo_size(fifo) / qsv_fifo_item_size();
  142. }
  143. static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
  144. {
  145. mfxSession session = NULL;
  146. int iopattern = 0;
  147. int ret;
  148. enum AVPixelFormat pix_fmts[3] = {
  149. AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
  150. pix_fmt, /* system memory format obtained from bitstream parser */
  151. AV_PIX_FMT_NONE };
  152. ret = ff_get_format(avctx, pix_fmts);
  153. if (ret < 0) {
  154. q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
  155. return ret;
  156. }
  157. if (!q->async_fifo) {
  158. q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
  159. if (!q->async_fifo)
  160. return AVERROR(ENOMEM);
  161. }
  162. if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
  163. AVQSVContext *user_ctx = avctx->hwaccel_context;
  164. session = user_ctx->session;
  165. iopattern = user_ctx->iopattern;
  166. q->ext_buffers = user_ctx->ext_buffers;
  167. q->nb_ext_buffers = user_ctx->nb_ext_buffers;
  168. }
  169. if (avctx->hw_frames_ctx) {
  170. AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
  171. AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
  172. if (!iopattern) {
  173. if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
  174. iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
  175. else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
  176. iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
  177. }
  178. }
  179. if (!iopattern)
  180. iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
  181. q->iopattern = iopattern;
  182. ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
  183. ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
  184. if (ret < 0) {
  185. av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
  186. return ret;
  187. }
  188. param->IOPattern = q->iopattern;
  189. param->AsyncDepth = q->async_depth;
  190. param->ExtParam = q->ext_buffers;
  191. param->NumExtParam = q->nb_ext_buffers;
  192. return 0;
  193. }
  194. static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
  195. {
  196. int ret;
  197. avctx->width = param->mfx.FrameInfo.CropW;
  198. avctx->height = param->mfx.FrameInfo.CropH;
  199. avctx->coded_width = param->mfx.FrameInfo.Width;
  200. avctx->coded_height = param->mfx.FrameInfo.Height;
  201. avctx->level = param->mfx.CodecLevel;
  202. avctx->profile = param->mfx.CodecProfile;
  203. avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
  204. avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
  205. ret = MFXVideoDECODE_Init(q->session, param);
  206. if (ret < 0)
  207. return ff_qsv_print_error(avctx, ret,
  208. "Error initializing the MFX video decoder");
  209. q->frame_info = param->mfx.FrameInfo;
  210. if (!avctx->hw_frames_ctx)
  211. q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx->pix_fmt,
  212. FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1), av_buffer_allocz);
  213. return 0;
  214. }
  215. static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
  216. {
  217. int ret;
  218. mfxBitstream bs = { 0 };
  219. if (avpkt->size) {
  220. bs.Data = avpkt->data;
  221. bs.DataLength = avpkt->size;
  222. bs.MaxLength = bs.DataLength;
  223. bs.TimeStamp = avpkt->pts;
  224. if (avctx->field_order == AV_FIELD_PROGRESSIVE)
  225. bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
  226. } else
  227. return AVERROR_INVALIDDATA;
  228. if(!q->session) {
  229. ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
  230. if (ret < 0)
  231. return ret;
  232. }
  233. ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
  234. if (ret < 0)
  235. return ret;
  236. param->mfx.CodecId = ret;
  237. ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
  238. if (MFX_ERR_MORE_DATA == ret) {
  239. return AVERROR(EAGAIN);
  240. }
  241. if (ret < 0)
  242. return ff_qsv_print_error(avctx, ret,
  243. "Error decoding stream header");
  244. return 0;
  245. }
  246. static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
  247. {
  248. int ret;
  249. if (q->pool)
  250. ret = ff_qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
  251. else
  252. ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
  253. if (ret < 0)
  254. return ret;
  255. if (frame->frame->format == AV_PIX_FMT_QSV) {
  256. frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
  257. } else {
  258. frame->surface.Info = q->frame_info;
  259. frame->surface.Data.PitchLow = frame->frame->linesize[0];
  260. frame->surface.Data.Y = frame->frame->data[0];
  261. frame->surface.Data.UV = frame->frame->data[1];
  262. }
  263. if (q->frames_ctx.mids) {
  264. ret = ff_qsv_find_surface_idx(&q->frames_ctx, frame);
  265. if (ret < 0)
  266. return ret;
  267. frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
  268. }
  269. frame->surface.Data.ExtParam = &frame->ext_param;
  270. frame->surface.Data.NumExtParam = 1;
  271. frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
  272. frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
  273. frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
  274. frame->used = 1;
  275. return 0;
  276. }
  277. static void qsv_clear_unused_frames(QSVContext *q)
  278. {
  279. QSVFrame *cur = q->work_frames;
  280. while (cur) {
  281. if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
  282. cur->used = 0;
  283. av_frame_unref(cur->frame);
  284. }
  285. cur = cur->next;
  286. }
  287. }
  288. static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
  289. {
  290. QSVFrame *frame, **last;
  291. int ret;
  292. qsv_clear_unused_frames(q);
  293. frame = q->work_frames;
  294. last = &q->work_frames;
  295. while (frame) {
  296. if (!frame->used) {
  297. ret = alloc_frame(avctx, q, frame);
  298. if (ret < 0)
  299. return ret;
  300. *surf = &frame->surface;
  301. return 0;
  302. }
  303. last = &frame->next;
  304. frame = frame->next;
  305. }
  306. frame = av_mallocz(sizeof(*frame));
  307. if (!frame)
  308. return AVERROR(ENOMEM);
  309. frame->frame = av_frame_alloc();
  310. if (!frame->frame) {
  311. av_freep(&frame);
  312. return AVERROR(ENOMEM);
  313. }
  314. *last = frame;
  315. ret = alloc_frame(avctx, q, frame);
  316. if (ret < 0)
  317. return ret;
  318. *surf = &frame->surface;
  319. return 0;
  320. }
  321. static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
  322. {
  323. QSVFrame *cur = q->work_frames;
  324. while (cur) {
  325. if (surf == &cur->surface)
  326. return cur;
  327. cur = cur->next;
  328. }
  329. return NULL;
  330. }
  331. static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
  332. AVFrame *frame, int *got_frame,
  333. AVPacket *avpkt)
  334. {
  335. QSVFrame *out_frame;
  336. mfxFrameSurface1 *insurf;
  337. mfxFrameSurface1 *outsurf;
  338. mfxSyncPoint *sync;
  339. mfxBitstream bs = { { { 0 } } };
  340. int ret;
  341. if (avpkt->size) {
  342. bs.Data = avpkt->data;
  343. bs.DataLength = avpkt->size;
  344. bs.MaxLength = bs.DataLength;
  345. bs.TimeStamp = avpkt->pts;
  346. if (avctx->field_order == AV_FIELD_PROGRESSIVE)
  347. bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
  348. }
  349. sync = av_mallocz(sizeof(*sync));
  350. if (!sync) {
  351. av_freep(&sync);
  352. return AVERROR(ENOMEM);
  353. }
  354. do {
  355. ret = get_surface(avctx, q, &insurf);
  356. if (ret < 0) {
  357. av_freep(&sync);
  358. return ret;
  359. }
  360. ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
  361. insurf, &outsurf, sync);
  362. if (ret == MFX_WRN_DEVICE_BUSY)
  363. av_usleep(500);
  364. } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
  365. if (ret != MFX_ERR_NONE &&
  366. ret != MFX_ERR_MORE_DATA &&
  367. ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
  368. ret != MFX_ERR_MORE_SURFACE) {
  369. av_freep(&sync);
  370. return ff_qsv_print_error(avctx, ret,
  371. "Error during QSV decoding.");
  372. }
  373. /* make sure we do not enter an infinite loop if the SDK
  374. * did not consume any data and did not return anything */
  375. if (!*sync && !bs.DataOffset) {
  376. bs.DataOffset = avpkt->size;
  377. ++q->zero_consume_run;
  378. if (q->zero_consume_run > 1)
  379. ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
  380. } else if (!*sync && bs.DataOffset) {
  381. ++q->buffered_count;
  382. } else {
  383. q->zero_consume_run = 0;
  384. }
  385. if (*sync) {
  386. QSVFrame *out_frame = find_frame(q, outsurf);
  387. if (!out_frame) {
  388. av_log(avctx, AV_LOG_ERROR,
  389. "The returned surface does not correspond to any frame\n");
  390. av_freep(&sync);
  391. return AVERROR_BUG;
  392. }
  393. out_frame->queued = 1;
  394. av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
  395. av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
  396. } else {
  397. av_freep(&sync);
  398. }
  399. if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
  400. (!avpkt->size && av_fifo_size(q->async_fifo))) {
  401. AVFrame *src_frame;
  402. av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
  403. av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
  404. out_frame->queued = 0;
  405. if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
  406. do {
  407. ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
  408. } while (ret == MFX_WRN_IN_EXECUTION);
  409. }
  410. av_freep(&sync);
  411. src_frame = out_frame->frame;
  412. ret = av_frame_ref(frame, src_frame);
  413. if (ret < 0)
  414. return ret;
  415. outsurf = &out_frame->surface;
  416. #if FF_API_PKT_PTS
  417. FF_DISABLE_DEPRECATION_WARNINGS
  418. frame->pkt_pts = outsurf->Data.TimeStamp;
  419. FF_ENABLE_DEPRECATION_WARNINGS
  420. #endif
  421. frame->pts = outsurf->Data.TimeStamp;
  422. frame->repeat_pict =
  423. outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
  424. outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
  425. outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
  426. frame->top_field_first =
  427. outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
  428. frame->interlaced_frame =
  429. !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
  430. frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
  431. //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
  432. if (avctx->codec_id == AV_CODEC_ID_H264)
  433. frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
  434. /* update the surface properties */
  435. if (avctx->pix_fmt == AV_PIX_FMT_QSV)
  436. ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
  437. *got_frame = 1;
  438. }
  439. return bs.DataOffset;
  440. }
  441. int ff_qsv_decode_close(QSVContext *q)
  442. {
  443. QSVFrame *cur = q->work_frames;
  444. if (q->session)
  445. MFXVideoDECODE_Close(q->session);
  446. while (q->async_fifo && av_fifo_size(q->async_fifo)) {
  447. QSVFrame *out_frame;
  448. mfxSyncPoint *sync;
  449. av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
  450. av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
  451. av_freep(&sync);
  452. }
  453. while (cur) {
  454. q->work_frames = cur->next;
  455. av_frame_free(&cur->frame);
  456. av_freep(&cur);
  457. cur = q->work_frames;
  458. }
  459. av_fifo_free(q->async_fifo);
  460. q->async_fifo = NULL;
  461. ff_qsv_close_internal_session(&q->internal_qs);
  462. av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
  463. av_buffer_unref(&q->frames_ctx.mids_buf);
  464. av_buffer_pool_uninit(&q->pool);
  465. return 0;
  466. }
  467. int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
  468. AVFrame *frame, int *got_frame, AVPacket *pkt)
  469. {
  470. int ret;
  471. mfxVideoParam param = { 0 };
  472. enum AVPixelFormat pix_fmt = AV_PIX_FMT_NV12;
  473. if (!pkt->size)
  474. return qsv_decode(avctx, q, frame, got_frame, pkt);
  475. /* TODO: flush delayed frames on reinit */
  476. // sw_pix_fmt, coded_width/height should be set for ff_get_format(),
  477. // assume sw_pix_fmt is NV12 and coded_width/height to be 1280x720,
  478. // the assumption may be not corret but will be updated after header decoded if not true.
  479. if (q->orig_pix_fmt != AV_PIX_FMT_NONE)
  480. pix_fmt = q->orig_pix_fmt;
  481. if (!avctx->coded_width)
  482. avctx->coded_width = 1280;
  483. if (!avctx->coded_height)
  484. avctx->coded_height = 720;
  485. ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
  486. if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
  487. avctx->coded_width != param.mfx.FrameInfo.Width ||
  488. avctx->coded_height != param.mfx.FrameInfo.Height)) {
  489. AVPacket zero_pkt = {0};
  490. if (q->buffered_count) {
  491. q->reinit_flag = 1;
  492. /* decode zero-size pkt to flush the buffered pkt before reinit */
  493. q->buffered_count--;
  494. return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
  495. }
  496. q->reinit_flag = 0;
  497. q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
  498. avctx->coded_width = param.mfx.FrameInfo.Width;
  499. avctx->coded_height = param.mfx.FrameInfo.Height;
  500. ret = qsv_decode_preinit(avctx, q, pix_fmt, &param);
  501. if (ret < 0)
  502. goto reinit_fail;
  503. q->initialized = 0;
  504. }
  505. if (!q->initialized) {
  506. ret = qsv_decode_init(avctx, q, &param);
  507. if (ret < 0)
  508. goto reinit_fail;
  509. q->initialized = 1;
  510. }
  511. return qsv_decode(avctx, q, frame, got_frame, pkt);
  512. reinit_fail:
  513. q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
  514. return ret;
  515. }
  516. void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
  517. {
  518. q->orig_pix_fmt = AV_PIX_FMT_NONE;
  519. q->initialized = 0;
  520. }