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.

597 lines
20KB

  1. /*
  2. * RockChip MPP Video Decoder
  3. * Copyright (c) 2017 Lionel CHAZALLON
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <drm_fourcc.h>
  22. #include <pthread.h>
  23. #include <rockchip/mpp_buffer.h>
  24. #include <rockchip/rk_mpi.h>
  25. #include <time.h>
  26. #include <unistd.h>
  27. #include "avcodec.h"
  28. #include "decode.h"
  29. #include "internal.h"
  30. #include "libavutil/buffer.h"
  31. #include "libavutil/common.h"
  32. #include "libavutil/frame.h"
  33. #include "libavutil/hwcontext.h"
  34. #include "libavutil/hwcontext_drm.h"
  35. #include "libavutil/imgutils.h"
  36. #include "libavutil/log.h"
  37. #define RECEIVE_FRAME_TIMEOUT 100
  38. #define FRAMEGROUP_MAX_FRAMES 16
  39. typedef struct {
  40. MppCtx ctx;
  41. MppApi *mpi;
  42. MppBufferGroup frame_group;
  43. char first_frame;
  44. char first_packet;
  45. char eos_reached;
  46. AVBufferRef *frames_ref;
  47. AVBufferRef *device_ref;
  48. } RKMPPDecoder;
  49. typedef struct {
  50. AVClass *av_class;
  51. AVBufferRef *decoder_ref;
  52. } RKMPPDecodeContext;
  53. typedef struct {
  54. MppFrame frame;
  55. AVBufferRef *decoder_ref;
  56. } RKMPPFrameContext;
  57. static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx)
  58. {
  59. switch (avctx->codec_id) {
  60. case AV_CODEC_ID_H264: return MPP_VIDEO_CodingAVC;
  61. case AV_CODEC_ID_HEVC: return MPP_VIDEO_CodingHEVC;
  62. case AV_CODEC_ID_VP8: return MPP_VIDEO_CodingVP8;
  63. case AV_CODEC_ID_VP9: return MPP_VIDEO_CodingVP9;
  64. default: return MPP_VIDEO_CodingUnused;
  65. }
  66. }
  67. static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat)
  68. {
  69. switch (mppformat) {
  70. case MPP_FMT_YUV420SP: return DRM_FORMAT_NV12;
  71. #ifdef DRM_FORMAT_NV12_10
  72. case MPP_FMT_YUV420SP_10BIT: return DRM_FORMAT_NV12_10;
  73. #endif
  74. default: return 0;
  75. }
  76. }
  77. static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts)
  78. {
  79. RKMPPDecodeContext *rk_context = avctx->priv_data;
  80. RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
  81. int ret;
  82. MppPacket packet;
  83. // create the MPP packet
  84. ret = mpp_packet_init(&packet, buffer, size);
  85. if (ret != MPP_OK) {
  86. av_log(avctx, AV_LOG_ERROR, "Failed to init MPP packet (code = %d)\n", ret);
  87. return AVERROR_UNKNOWN;
  88. }
  89. mpp_packet_set_pts(packet, pts);
  90. if (!buffer)
  91. mpp_packet_set_eos(packet);
  92. ret = decoder->mpi->decode_put_packet(decoder->ctx, packet);
  93. if (ret != MPP_OK) {
  94. if (ret == MPP_ERR_BUFFER_FULL) {
  95. av_log(avctx, AV_LOG_DEBUG, "Buffer full writing %d bytes to decoder\n", size);
  96. ret = AVERROR(EAGAIN);
  97. } else
  98. ret = AVERROR_UNKNOWN;
  99. }
  100. else
  101. av_log(avctx, AV_LOG_DEBUG, "Wrote %d bytes to decoder\n", size);
  102. mpp_packet_deinit(&packet);
  103. return ret;
  104. }
  105. static int rkmpp_close_decoder(AVCodecContext *avctx)
  106. {
  107. RKMPPDecodeContext *rk_context = avctx->priv_data;
  108. av_buffer_unref(&rk_context->decoder_ref);
  109. return 0;
  110. }
  111. static void rkmpp_release_decoder(void *opaque, uint8_t *data)
  112. {
  113. RKMPPDecoder *decoder = (RKMPPDecoder *)data;
  114. if (decoder->mpi) {
  115. decoder->mpi->reset(decoder->ctx);
  116. mpp_destroy(decoder->ctx);
  117. decoder->ctx = NULL;
  118. }
  119. if (decoder->frame_group) {
  120. mpp_buffer_group_put(decoder->frame_group);
  121. decoder->frame_group = NULL;
  122. }
  123. av_buffer_unref(&decoder->frames_ref);
  124. av_buffer_unref(&decoder->device_ref);
  125. av_free(decoder);
  126. }
  127. static int rkmpp_init_decoder(AVCodecContext *avctx)
  128. {
  129. RKMPPDecodeContext *rk_context = avctx->priv_data;
  130. RKMPPDecoder *decoder = NULL;
  131. MppCodingType codectype = MPP_VIDEO_CodingUnused;
  132. int ret;
  133. RK_S64 paramS64;
  134. RK_S32 paramS32;
  135. avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME;
  136. // create a decoder and a ref to it
  137. decoder = av_mallocz(sizeof(RKMPPDecoder));
  138. if (!decoder) {
  139. ret = AVERROR(ENOMEM);
  140. goto fail;
  141. }
  142. rk_context->decoder_ref = av_buffer_create((uint8_t *)decoder, sizeof(*decoder), rkmpp_release_decoder,
  143. NULL, AV_BUFFER_FLAG_READONLY);
  144. if (!rk_context->decoder_ref) {
  145. av_free(decoder);
  146. ret = AVERROR(ENOMEM);
  147. goto fail;
  148. }
  149. av_log(avctx, AV_LOG_DEBUG, "Initializing RKMPP decoder.\n");
  150. codectype = rkmpp_get_codingtype(avctx);
  151. if (codectype == MPP_VIDEO_CodingUnused) {
  152. av_log(avctx, AV_LOG_ERROR, "Unknown codec type (%d).\n", avctx->codec_id);
  153. ret = AVERROR_UNKNOWN;
  154. goto fail;
  155. }
  156. ret = mpp_check_support_format(MPP_CTX_DEC, codectype);
  157. if (ret != MPP_OK) {
  158. av_log(avctx, AV_LOG_ERROR, "Codec type (%d) unsupported by MPP\n", avctx->codec_id);
  159. ret = AVERROR_UNKNOWN;
  160. goto fail;
  161. }
  162. // Create the MPP context
  163. ret = mpp_create(&decoder->ctx, &decoder->mpi);
  164. if (ret != MPP_OK) {
  165. av_log(avctx, AV_LOG_ERROR, "Failed to create MPP context (code = %d).\n", ret);
  166. ret = AVERROR_UNKNOWN;
  167. goto fail;
  168. }
  169. // initialize mpp
  170. ret = mpp_init(decoder->ctx, MPP_CTX_DEC, codectype);
  171. if (ret != MPP_OK) {
  172. av_log(avctx, AV_LOG_ERROR, "Failed to initialize MPP context (code = %d).\n", ret);
  173. ret = AVERROR_UNKNOWN;
  174. goto fail;
  175. }
  176. // make decode calls blocking with a timeout
  177. paramS32 = MPP_POLL_BLOCK;
  178. ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK, &paramS32);
  179. if (ret != MPP_OK) {
  180. av_log(avctx, AV_LOG_ERROR, "Failed to set blocking mode on MPI (code = %d).\n", ret);
  181. ret = AVERROR_UNKNOWN;
  182. goto fail;
  183. }
  184. paramS64 = RECEIVE_FRAME_TIMEOUT;
  185. ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK_TIMEOUT, &paramS64);
  186. if (ret != MPP_OK) {
  187. av_log(avctx, AV_LOG_ERROR, "Failed to set block timeout on MPI (code = %d).\n", ret);
  188. ret = AVERROR_UNKNOWN;
  189. goto fail;
  190. }
  191. ret = mpp_buffer_group_get_internal(&decoder->frame_group, MPP_BUFFER_TYPE_ION);
  192. if (ret) {
  193. av_log(avctx, AV_LOG_ERROR, "Failed to retrieve buffer group (code = %d)\n", ret);
  194. ret = AVERROR_UNKNOWN;
  195. goto fail;
  196. }
  197. ret = decoder->mpi->control(decoder->ctx, MPP_DEC_SET_EXT_BUF_GROUP, decoder->frame_group);
  198. if (ret) {
  199. av_log(avctx, AV_LOG_ERROR, "Failed to assign buffer group (code = %d)\n", ret);
  200. ret = AVERROR_UNKNOWN;
  201. goto fail;
  202. }
  203. ret = mpp_buffer_group_limit_config(decoder->frame_group, 0, FRAMEGROUP_MAX_FRAMES);
  204. if (ret) {
  205. av_log(avctx, AV_LOG_ERROR, "Failed to set buffer group limit (code = %d)\n", ret);
  206. ret = AVERROR_UNKNOWN;
  207. goto fail;
  208. }
  209. decoder->first_packet = 1;
  210. av_log(avctx, AV_LOG_DEBUG, "RKMPP decoder initialized successfully.\n");
  211. decoder->device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DRM);
  212. if (!decoder->device_ref) {
  213. ret = AVERROR(ENOMEM);
  214. goto fail;
  215. }
  216. ret = av_hwdevice_ctx_init(decoder->device_ref);
  217. if (ret < 0)
  218. goto fail;
  219. return 0;
  220. fail:
  221. av_log(avctx, AV_LOG_ERROR, "Failed to initialize RKMPP decoder.\n");
  222. rkmpp_close_decoder(avctx);
  223. return ret;
  224. }
  225. static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
  226. {
  227. RKMPPDecodeContext *rk_context = avctx->priv_data;
  228. RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
  229. int ret;
  230. // handle EOF
  231. if (!avpkt->size) {
  232. av_log(avctx, AV_LOG_DEBUG, "End of stream.\n");
  233. decoder->eos_reached = 1;
  234. ret = rkmpp_write_data(avctx, NULL, 0, 0);
  235. if (ret)
  236. av_log(avctx, AV_LOG_ERROR, "Failed to send EOS to decoder (code = %d)\n", ret);
  237. return ret;
  238. }
  239. // on first packet, send extradata
  240. if (decoder->first_packet) {
  241. if (avctx->extradata_size) {
  242. ret = rkmpp_write_data(avctx, avctx->extradata,
  243. avctx->extradata_size,
  244. avpkt->pts);
  245. if (ret) {
  246. av_log(avctx, AV_LOG_ERROR, "Failed to write extradata to decoder (code = %d)\n", ret);
  247. return ret;
  248. }
  249. }
  250. decoder->first_packet = 0;
  251. }
  252. // now send packet
  253. ret = rkmpp_write_data(avctx, avpkt->data, avpkt->size, avpkt->pts);
  254. if (ret && ret!=AVERROR(EAGAIN))
  255. av_log(avctx, AV_LOG_ERROR, "Failed to write data to decoder (code = %d)\n", ret);
  256. return ret;
  257. }
  258. static void rkmpp_release_frame(void *opaque, uint8_t *data)
  259. {
  260. AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)data;
  261. AVBufferRef *framecontextref = (AVBufferRef *)opaque;
  262. RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data;
  263. mpp_frame_deinit(&framecontext->frame);
  264. av_buffer_unref(&framecontext->decoder_ref);
  265. av_buffer_unref(&framecontextref);
  266. av_free(desc);
  267. }
  268. static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame)
  269. {
  270. RKMPPDecodeContext *rk_context = avctx->priv_data;
  271. RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
  272. RKMPPFrameContext *framecontext = NULL;
  273. AVBufferRef *framecontextref = NULL;
  274. int ret;
  275. MppFrame mppframe = NULL;
  276. MppBuffer buffer = NULL;
  277. AVDRMFrameDescriptor *desc = NULL;
  278. AVDRMLayerDescriptor *layer = NULL;
  279. int retrycount = 0;
  280. int mode;
  281. MppFrameFormat mppformat;
  282. uint32_t drmformat;
  283. // on start of decoding, MPP can return -1, which is supposed to be expected
  284. // this is due to some internal MPP init which is not completed, that will
  285. // only happen in the first few frames queries, but should not be interpreted
  286. // as an error, Therefore we need to retry a couple times when we get -1
  287. // in order to let it time to complete it's init, then we sleep a bit between retries.
  288. retry_get_frame:
  289. ret = decoder->mpi->decode_get_frame(decoder->ctx, &mppframe);
  290. if (ret != MPP_OK && ret != MPP_ERR_TIMEOUT && !decoder->first_frame) {
  291. if (retrycount < 5) {
  292. av_log(avctx, AV_LOG_DEBUG, "Failed to get a frame, retrying (code = %d, retrycount = %d)\n", ret, retrycount);
  293. usleep(10000);
  294. retrycount++;
  295. goto retry_get_frame;
  296. } else {
  297. av_log(avctx, AV_LOG_ERROR, "Failed to get a frame from MPP (code = %d)\n", ret);
  298. goto fail;
  299. }
  300. }
  301. if (mppframe) {
  302. // Check wether we have a special frame or not
  303. if (mpp_frame_get_info_change(mppframe)) {
  304. AVHWFramesContext *hwframes;
  305. av_log(avctx, AV_LOG_INFO, "Decoder noticed an info change (%dx%d), format=%d\n",
  306. (int)mpp_frame_get_width(mppframe), (int)mpp_frame_get_height(mppframe),
  307. (int)mpp_frame_get_fmt(mppframe));
  308. avctx->width = mpp_frame_get_width(mppframe);
  309. avctx->height = mpp_frame_get_height(mppframe);
  310. decoder->mpi->control(decoder->ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
  311. decoder->first_frame = 1;
  312. av_buffer_unref(&decoder->frames_ref);
  313. decoder->frames_ref = av_hwframe_ctx_alloc(decoder->device_ref);
  314. if (!decoder->frames_ref) {
  315. ret = AVERROR(ENOMEM);
  316. goto fail;
  317. }
  318. mppformat = mpp_frame_get_fmt(mppframe);
  319. drmformat = rkmpp_get_frameformat(mppformat);
  320. hwframes = (AVHWFramesContext*)decoder->frames_ref->data;
  321. hwframes->format = AV_PIX_FMT_DRM_PRIME;
  322. hwframes->sw_format = drmformat == DRM_FORMAT_NV12 ? AV_PIX_FMT_NV12 : AV_PIX_FMT_NONE;
  323. hwframes->width = avctx->width;
  324. hwframes->height = avctx->height;
  325. ret = av_hwframe_ctx_init(decoder->frames_ref);
  326. if (ret < 0)
  327. goto fail;
  328. // here decoder is fully initialized, we need to feed it again with data
  329. ret = AVERROR(EAGAIN);
  330. goto fail;
  331. } else if (mpp_frame_get_eos(mppframe)) {
  332. av_log(avctx, AV_LOG_DEBUG, "Received a EOS frame.\n");
  333. decoder->eos_reached = 1;
  334. ret = AVERROR_EOF;
  335. goto fail;
  336. } else if (mpp_frame_get_discard(mppframe)) {
  337. av_log(avctx, AV_LOG_DEBUG, "Received a discard frame.\n");
  338. ret = AVERROR(EAGAIN);
  339. goto fail;
  340. } else if (mpp_frame_get_errinfo(mppframe)) {
  341. av_log(avctx, AV_LOG_ERROR, "Received a errinfo frame.\n");
  342. ret = AVERROR_UNKNOWN;
  343. goto fail;
  344. }
  345. // here we should have a valid frame
  346. av_log(avctx, AV_LOG_DEBUG, "Received a frame.\n");
  347. // setup general frame fields
  348. frame->format = AV_PIX_FMT_DRM_PRIME;
  349. frame->width = mpp_frame_get_width(mppframe);
  350. frame->height = mpp_frame_get_height(mppframe);
  351. frame->pts = mpp_frame_get_pts(mppframe);
  352. frame->color_range = mpp_frame_get_color_range(mppframe);
  353. frame->color_primaries = mpp_frame_get_color_primaries(mppframe);
  354. frame->color_trc = mpp_frame_get_color_trc(mppframe);
  355. frame->colorspace = mpp_frame_get_colorspace(mppframe);
  356. mode = mpp_frame_get_mode(mppframe);
  357. frame->interlaced_frame = ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_DEINTERLACED);
  358. frame->top_field_first = ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_TOP_FIRST);
  359. mppformat = mpp_frame_get_fmt(mppframe);
  360. drmformat = rkmpp_get_frameformat(mppformat);
  361. // now setup the frame buffer info
  362. buffer = mpp_frame_get_buffer(mppframe);
  363. if (buffer) {
  364. desc = av_mallocz(sizeof(AVDRMFrameDescriptor));
  365. if (!desc) {
  366. ret = AVERROR(ENOMEM);
  367. goto fail;
  368. }
  369. desc->nb_objects = 1;
  370. desc->objects[0].fd = mpp_buffer_get_fd(buffer);
  371. desc->objects[0].size = mpp_buffer_get_size(buffer);
  372. desc->nb_layers = 1;
  373. layer = &desc->layers[0];
  374. layer->format = drmformat;
  375. layer->nb_planes = 2;
  376. layer->planes[0].object_index = 0;
  377. layer->planes[0].offset = 0;
  378. layer->planes[0].pitch = mpp_frame_get_hor_stride(mppframe);
  379. layer->planes[1].object_index = 0;
  380. layer->planes[1].offset = layer->planes[0].pitch * mpp_frame_get_ver_stride(mppframe);
  381. layer->planes[1].pitch = layer->planes[0].pitch;
  382. // we also allocate a struct in buf[0] that will allow to hold additionnal information
  383. // for releasing properly MPP frames and decoder
  384. framecontextref = av_buffer_allocz(sizeof(*framecontext));
  385. if (!framecontextref) {
  386. ret = AVERROR(ENOMEM);
  387. goto fail;
  388. }
  389. // MPP decoder needs to be closed only when all frames have been released.
  390. framecontext = (RKMPPFrameContext *)framecontextref->data;
  391. framecontext->decoder_ref = av_buffer_ref(rk_context->decoder_ref);
  392. framecontext->frame = mppframe;
  393. frame->data[0] = (uint8_t *)desc;
  394. frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), rkmpp_release_frame,
  395. framecontextref, AV_BUFFER_FLAG_READONLY);
  396. if (!frame->buf[0]) {
  397. ret = AVERROR(ENOMEM);
  398. goto fail;
  399. }
  400. frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref);
  401. if (!frame->hw_frames_ctx) {
  402. ret = AVERROR(ENOMEM);
  403. goto fail;
  404. }
  405. decoder->first_frame = 0;
  406. return 0;
  407. } else {
  408. av_log(avctx, AV_LOG_ERROR, "Failed to retrieve the frame buffer, frame is dropped (code = %d)\n", ret);
  409. mpp_frame_deinit(&mppframe);
  410. }
  411. } else if (decoder->eos_reached) {
  412. return AVERROR_EOF;
  413. } else if (ret == MPP_ERR_TIMEOUT) {
  414. av_log(avctx, AV_LOG_DEBUG, "Timeout when trying to get a frame from MPP\n");
  415. }
  416. return AVERROR(EAGAIN);
  417. fail:
  418. if (mppframe)
  419. mpp_frame_deinit(&mppframe);
  420. if (framecontext)
  421. av_buffer_unref(&framecontext->decoder_ref);
  422. if (framecontextref)
  423. av_buffer_unref(&framecontextref);
  424. if (desc)
  425. av_free(desc);
  426. return ret;
  427. }
  428. static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame)
  429. {
  430. RKMPPDecodeContext *rk_context = avctx->priv_data;
  431. RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
  432. int ret = MPP_NOK;
  433. AVPacket pkt = {0};
  434. RK_S32 freeslots;
  435. if (!decoder->eos_reached) {
  436. // we get the available slots in decoder
  437. ret = decoder->mpi->control(decoder->ctx, MPP_DEC_GET_FREE_PACKET_SLOT_COUNT, &freeslots);
  438. if (ret != MPP_OK) {
  439. av_log(avctx, AV_LOG_ERROR, "Failed to get decoder free slots (code = %d).\n", ret);
  440. return ret;
  441. }
  442. if (freeslots > 0) {
  443. ret = ff_decode_get_packet(avctx, &pkt);
  444. if (ret < 0 && ret != AVERROR_EOF) {
  445. return ret;
  446. }
  447. ret = rkmpp_send_packet(avctx, &pkt);
  448. av_packet_unref(&pkt);
  449. if (ret < 0) {
  450. av_log(avctx, AV_LOG_ERROR, "Failed to send packet to decoder (code = %d)\n", ret);
  451. return ret;
  452. }
  453. }
  454. // make sure we keep decoder full
  455. if (freeslots > 1 && decoder->first_frame)
  456. return AVERROR(EAGAIN);
  457. }
  458. return rkmpp_retrieve_frame(avctx, frame);
  459. }
  460. static void rkmpp_flush(AVCodecContext *avctx)
  461. {
  462. RKMPPDecodeContext *rk_context = avctx->priv_data;
  463. RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
  464. int ret = MPP_NOK;
  465. av_log(avctx, AV_LOG_DEBUG, "Flush.\n");
  466. ret = decoder->mpi->reset(decoder->ctx);
  467. if (ret == MPP_OK) {
  468. decoder->first_frame = 1;
  469. decoder->first_packet = 1;
  470. } else
  471. av_log(avctx, AV_LOG_ERROR, "Failed to reset MPI (code = %d)\n", ret);
  472. }
  473. #define RKMPP_DEC_CLASS(NAME) \
  474. static const AVClass rkmpp_##NAME##_dec_class = { \
  475. .class_name = "rkmpp_" #NAME "_dec", \
  476. .version = LIBAVUTIL_VERSION_INT, \
  477. };
  478. #define RKMPP_DEC(NAME, ID, BSFS) \
  479. RKMPP_DEC_CLASS(NAME) \
  480. AVCodec ff_##NAME##_rkmpp_decoder = { \
  481. .name = #NAME "_rkmpp", \
  482. .long_name = NULL_IF_CONFIG_SMALL(#NAME " (rkmpp)"), \
  483. .type = AVMEDIA_TYPE_VIDEO, \
  484. .id = ID, \
  485. .priv_data_size = sizeof(RKMPPDecodeContext), \
  486. .init = rkmpp_init_decoder, \
  487. .close = rkmpp_close_decoder, \
  488. .receive_frame = rkmpp_receive_frame, \
  489. .flush = rkmpp_flush, \
  490. .priv_class = &rkmpp_##NAME##_dec_class, \
  491. .capabilities = AV_CODEC_CAP_DELAY, \
  492. .caps_internal = AV_CODEC_CAP_AVOID_PROBING, \
  493. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_DRM_PRIME, \
  494. AV_PIX_FMT_NONE}, \
  495. .bsfs = BSFS, \
  496. };
  497. RKMPP_DEC(h264, AV_CODEC_ID_H264, "h264_mp4toannexb")
  498. RKMPP_DEC(hevc, AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
  499. RKMPP_DEC(vp8, AV_CODEC_ID_VP8, NULL)
  500. RKMPP_DEC(vp9, AV_CODEC_ID_VP9, NULL)