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.

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