FFmpeg
rkmppdec.c
Go to the documentation of this file.
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 
22 #include <drm_fourcc.h>
23 #include <pthread.h>
24 #include <rockchip/mpp_buffer.h>
25 #include <rockchip/rk_mpi.h>
26 #include <time.h>
27 #include <unistd.h>
28 
29 #include "avcodec.h"
30 #include "codec_internal.h"
31 #include "decode.h"
32 #include "hwconfig.h"
33 #include "libavutil/buffer.h"
34 #include "libavutil/common.h"
35 #include "libavutil/frame.h"
36 #include "libavutil/hwcontext.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/log.h"
40 
41 #define RECEIVE_FRAME_TIMEOUT 100
42 #define FRAMEGROUP_MAX_FRAMES 16
43 #define INPUT_MAX_PACKETS 4
44 
45 typedef struct {
46  MppCtx ctx;
47  MppApi *mpi;
48  MppBufferGroup frame_group;
49 
52 
55 } RKMPPDecoder;
56 
57 typedef struct {
61 
62 typedef struct {
63  MppFrame frame;
66 
67 static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx)
68 {
69  switch (avctx->codec_id) {
70  case AV_CODEC_ID_H264: return MPP_VIDEO_CodingAVC;
71  case AV_CODEC_ID_HEVC: return MPP_VIDEO_CodingHEVC;
72  case AV_CODEC_ID_VP8: return MPP_VIDEO_CodingVP8;
73  case AV_CODEC_ID_VP9: return MPP_VIDEO_CodingVP9;
74  default: return MPP_VIDEO_CodingUnused;
75  }
76 }
77 
78 static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat)
79 {
80  switch (mppformat) {
81  case MPP_FMT_YUV420SP: return DRM_FORMAT_NV12;
82 #ifdef DRM_FORMAT_NV12_10
83  case MPP_FMT_YUV420SP_10BIT: return DRM_FORMAT_NV12_10;
84 #endif
85  default: return 0;
86  }
87 }
88 
89 static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts)
90 {
91  RKMPPDecodeContext *rk_context = avctx->priv_data;
93  int ret;
94  MppPacket packet;
95 
96  // create the MPP packet
97  ret = mpp_packet_init(&packet, buffer, size);
98  if (ret != MPP_OK) {
99  av_log(avctx, AV_LOG_ERROR, "Failed to init MPP packet (code = %d)\n", ret);
100  return AVERROR_UNKNOWN;
101  }
102 
103  mpp_packet_set_pts(packet, pts);
104 
105  if (!buffer)
106  mpp_packet_set_eos(packet);
107 
108  ret = decoder->mpi->decode_put_packet(decoder->ctx, packet);
109  if (ret != MPP_OK) {
110  if (ret == MPP_ERR_BUFFER_FULL) {
111  av_log(avctx, AV_LOG_DEBUG, "Buffer full writing %d bytes to decoder\n", size);
112  ret = AVERROR(EAGAIN);
113  } else
115  }
116  else
117  av_log(avctx, AV_LOG_DEBUG, "Wrote %d bytes to decoder\n", size);
118 
119  mpp_packet_deinit(&packet);
120 
121  return ret;
122 }
123 
125 {
126  RKMPPDecodeContext *rk_context = avctx->priv_data;
127  av_buffer_unref(&rk_context->decoder_ref);
128  return 0;
129 }
130 
131 static void rkmpp_release_decoder(void *opaque, uint8_t *data)
132 {
134 
135  if (decoder->mpi) {
136  decoder->mpi->reset(decoder->ctx);
137  mpp_destroy(decoder->ctx);
138  decoder->ctx = NULL;
139  }
140 
141  if (decoder->frame_group) {
142  mpp_buffer_group_put(decoder->frame_group);
143  decoder->frame_group = NULL;
144  }
145 
146  av_buffer_unref(&decoder->frames_ref);
147  av_buffer_unref(&decoder->device_ref);
148 
149  av_free(decoder);
150 }
151 
153 {
154  RKMPPDecodeContext *rk_context = avctx->priv_data;
156  MppCodingType codectype = MPP_VIDEO_CodingUnused;
157  int ret;
158  RK_S64 paramS64;
159  RK_S32 paramS32;
160 
161  avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME;
162 
163  // create a decoder and a ref to it
164  decoder = av_mallocz(sizeof(RKMPPDecoder));
165  if (!decoder) {
166  ret = AVERROR(ENOMEM);
167  goto fail;
168  }
169 
170  rk_context->decoder_ref = av_buffer_create((uint8_t *)decoder, sizeof(*decoder), rkmpp_release_decoder,
172  if (!rk_context->decoder_ref) {
173  av_free(decoder);
174  ret = AVERROR(ENOMEM);
175  goto fail;
176  }
177 
178  av_log(avctx, AV_LOG_DEBUG, "Initializing RKMPP decoder.\n");
179 
180  codectype = rkmpp_get_codingtype(avctx);
181  if (codectype == MPP_VIDEO_CodingUnused) {
182  av_log(avctx, AV_LOG_ERROR, "Unknown codec type (%d).\n", avctx->codec_id);
184  goto fail;
185  }
186 
187  ret = mpp_check_support_format(MPP_CTX_DEC, codectype);
188  if (ret != MPP_OK) {
189  av_log(avctx, AV_LOG_ERROR, "Codec type (%d) unsupported by MPP\n", avctx->codec_id);
191  goto fail;
192  }
193 
194  // Create the MPP context
195  ret = mpp_create(&decoder->ctx, &decoder->mpi);
196  if (ret != MPP_OK) {
197  av_log(avctx, AV_LOG_ERROR, "Failed to create MPP context (code = %d).\n", ret);
199  goto fail;
200  }
201 
202  // initialize mpp
203  ret = mpp_init(decoder->ctx, MPP_CTX_DEC, codectype);
204  if (ret != MPP_OK) {
205  av_log(avctx, AV_LOG_ERROR, "Failed to initialize MPP context (code = %d).\n", ret);
207  goto fail;
208  }
209 
210  // make decode calls blocking with a timeout
211  paramS32 = MPP_POLL_BLOCK;
212  ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK, &paramS32);
213  if (ret != MPP_OK) {
214  av_log(avctx, AV_LOG_ERROR, "Failed to set blocking mode on MPI (code = %d).\n", ret);
216  goto fail;
217  }
218 
219  paramS64 = RECEIVE_FRAME_TIMEOUT;
220  ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK_TIMEOUT, &paramS64);
221  if (ret != MPP_OK) {
222  av_log(avctx, AV_LOG_ERROR, "Failed to set block timeout on MPI (code = %d).\n", ret);
224  goto fail;
225  }
226 
227  ret = mpp_buffer_group_get_internal(&decoder->frame_group, MPP_BUFFER_TYPE_ION);
228  if (ret) {
229  av_log(avctx, AV_LOG_ERROR, "Failed to retrieve buffer group (code = %d)\n", ret);
231  goto fail;
232  }
233 
234  ret = decoder->mpi->control(decoder->ctx, MPP_DEC_SET_EXT_BUF_GROUP, decoder->frame_group);
235  if (ret) {
236  av_log(avctx, AV_LOG_ERROR, "Failed to assign buffer group (code = %d)\n", ret);
238  goto fail;
239  }
240 
241  ret = mpp_buffer_group_limit_config(decoder->frame_group, 0, FRAMEGROUP_MAX_FRAMES);
242  if (ret) {
243  av_log(avctx, AV_LOG_ERROR, "Failed to set buffer group limit (code = %d)\n", ret);
245  goto fail;
246  }
247 
248  decoder->first_packet = 1;
249 
250  av_log(avctx, AV_LOG_DEBUG, "RKMPP decoder initialized successfully.\n");
251 
253  if (!decoder->device_ref) {
254  ret = AVERROR(ENOMEM);
255  goto fail;
256  }
257  ret = av_hwdevice_ctx_init(decoder->device_ref);
258  if (ret < 0)
259  goto fail;
260 
261  return 0;
262 
263 fail:
264  av_log(avctx, AV_LOG_ERROR, "Failed to initialize RKMPP decoder.\n");
265  rkmpp_close_decoder(avctx);
266  return ret;
267 }
268 
269 static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
270 {
271  RKMPPDecodeContext *rk_context = avctx->priv_data;
272  RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
273  int ret;
274 
275  // handle EOF
276  if (!avpkt->size) {
277  av_log(avctx, AV_LOG_DEBUG, "End of stream.\n");
278  decoder->eos_reached = 1;
279  ret = rkmpp_write_data(avctx, NULL, 0, 0);
280  if (ret)
281  av_log(avctx, AV_LOG_ERROR, "Failed to send EOS to decoder (code = %d)\n", ret);
282  return ret;
283  }
284 
285  // on first packet, send extradata
286  if (decoder->first_packet) {
287  if (avctx->extradata_size) {
288  ret = rkmpp_write_data(avctx, avctx->extradata,
289  avctx->extradata_size,
290  avpkt->pts);
291  if (ret) {
292  av_log(avctx, AV_LOG_ERROR, "Failed to write extradata to decoder (code = %d)\n", ret);
293  return ret;
294  }
295  }
296  decoder->first_packet = 0;
297  }
298 
299  // now send packet
300  ret = rkmpp_write_data(avctx, avpkt->data, avpkt->size, avpkt->pts);
301  if (ret && ret!=AVERROR(EAGAIN))
302  av_log(avctx, AV_LOG_ERROR, "Failed to write data to decoder (code = %d)\n", ret);
303 
304  return ret;
305 }
306 
307 static void rkmpp_release_frame(void *opaque, uint8_t *data)
308 {
310  AVBufferRef *framecontextref = (AVBufferRef *)opaque;
311  RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data;
312 
313  mpp_frame_deinit(&framecontext->frame);
314  av_buffer_unref(&framecontext->decoder_ref);
315  av_buffer_unref(&framecontextref);
316 
317  av_free(desc);
318 }
319 
321 {
322  RKMPPDecodeContext *rk_context = avctx->priv_data;
323  RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
324  RKMPPFrameContext *framecontext = NULL;
325  AVBufferRef *framecontextref = NULL;
326  int ret;
327  MppFrame mppframe = NULL;
328  MppBuffer buffer = NULL;
330  AVDRMLayerDescriptor *layer = NULL;
331  int mode;
332  MppFrameFormat mppformat;
333  uint32_t drmformat;
334 
335  ret = decoder->mpi->decode_get_frame(decoder->ctx, &mppframe);
336  if (ret != MPP_OK && ret != MPP_ERR_TIMEOUT) {
337  av_log(avctx, AV_LOG_ERROR, "Failed to get a frame from MPP (code = %d)\n", ret);
338  goto fail;
339  }
340 
341  if (mppframe) {
342  // Check whether we have a special frame or not
343  if (mpp_frame_get_info_change(mppframe)) {
344  AVHWFramesContext *hwframes;
345 
346  av_log(avctx, AV_LOG_INFO, "Decoder noticed an info change (%dx%d), format=%d\n",
347  (int)mpp_frame_get_width(mppframe), (int)mpp_frame_get_height(mppframe),
348  (int)mpp_frame_get_fmt(mppframe));
349 
350  avctx->width = mpp_frame_get_width(mppframe);
351  avctx->height = mpp_frame_get_height(mppframe);
352 
353  decoder->mpi->control(decoder->ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
354 
355  av_buffer_unref(&decoder->frames_ref);
356 
357  decoder->frames_ref = av_hwframe_ctx_alloc(decoder->device_ref);
358  if (!decoder->frames_ref) {
359  ret = AVERROR(ENOMEM);
360  goto fail;
361  }
362 
363  mppformat = mpp_frame_get_fmt(mppframe);
364  drmformat = rkmpp_get_frameformat(mppformat);
365 
366  hwframes = (AVHWFramesContext*)decoder->frames_ref->data;
367  hwframes->format = AV_PIX_FMT_DRM_PRIME;
368  hwframes->sw_format = drmformat == DRM_FORMAT_NV12 ? AV_PIX_FMT_NV12 : AV_PIX_FMT_NONE;
369  hwframes->width = avctx->width;
370  hwframes->height = avctx->height;
371  ret = av_hwframe_ctx_init(decoder->frames_ref);
372  if (ret < 0)
373  goto fail;
374 
375  // here decoder is fully initialized, we need to feed it again with data
376  ret = AVERROR(EAGAIN);
377  goto fail;
378  } else if (mpp_frame_get_eos(mppframe)) {
379  av_log(avctx, AV_LOG_DEBUG, "Received a EOS frame.\n");
380  decoder->eos_reached = 1;
381  ret = AVERROR_EOF;
382  goto fail;
383  } else if (mpp_frame_get_discard(mppframe)) {
384  av_log(avctx, AV_LOG_DEBUG, "Received a discard frame.\n");
385  ret = AVERROR(EAGAIN);
386  goto fail;
387  } else if (mpp_frame_get_errinfo(mppframe)) {
388  av_log(avctx, AV_LOG_ERROR, "Received a errinfo frame.\n");
390  goto fail;
391  }
392 
393  // here we should have a valid frame
394  av_log(avctx, AV_LOG_DEBUG, "Received a frame.\n");
395 
396  // setup general frame fields
398  frame->width = mpp_frame_get_width(mppframe);
399  frame->height = mpp_frame_get_height(mppframe);
400  frame->pts = mpp_frame_get_pts(mppframe);
401  frame->color_range = mpp_frame_get_color_range(mppframe);
402  frame->color_primaries = mpp_frame_get_color_primaries(mppframe);
403  frame->color_trc = mpp_frame_get_color_trc(mppframe);
404  frame->colorspace = mpp_frame_get_colorspace(mppframe);
405 
406  mode = mpp_frame_get_mode(mppframe);
407  if ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_DEINTERLACED)
409  if ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_TOP_FIRST)
411 
412  mppformat = mpp_frame_get_fmt(mppframe);
413  drmformat = rkmpp_get_frameformat(mppformat);
414 
415  // now setup the frame buffer info
416  buffer = mpp_frame_get_buffer(mppframe);
417  if (buffer) {
419  if (!desc) {
420  ret = AVERROR(ENOMEM);
421  goto fail;
422  }
423 
424  desc->nb_objects = 1;
425  desc->objects[0].fd = mpp_buffer_get_fd(buffer);
426  desc->objects[0].size = mpp_buffer_get_size(buffer);
427 
428  desc->nb_layers = 1;
429  layer = &desc->layers[0];
430  layer->format = drmformat;
431  layer->nb_planes = 2;
432 
433  layer->planes[0].object_index = 0;
434  layer->planes[0].offset = 0;
435  layer->planes[0].pitch = mpp_frame_get_hor_stride(mppframe);
436 
437  layer->planes[1].object_index = 0;
438  layer->planes[1].offset = layer->planes[0].pitch * mpp_frame_get_ver_stride(mppframe);
439  layer->planes[1].pitch = layer->planes[0].pitch;
440 
441  // we also allocate a struct in buf[0] that will allow to hold additionnal information
442  // for releasing properly MPP frames and decoder
443  framecontextref = av_buffer_allocz(sizeof(*framecontext));
444  if (!framecontextref) {
445  ret = AVERROR(ENOMEM);
446  goto fail;
447  }
448 
449  // MPP decoder needs to be closed only when all frames have been released.
450  framecontext = (RKMPPFrameContext *)framecontextref->data;
451  framecontext->decoder_ref = av_buffer_ref(rk_context->decoder_ref);
452  framecontext->frame = mppframe;
453 
454  frame->data[0] = (uint8_t *)desc;
455  frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), rkmpp_release_frame,
456  framecontextref, AV_BUFFER_FLAG_READONLY);
457 
458  if (!frame->buf[0]) {
459  ret = AVERROR(ENOMEM);
460  goto fail;
461  }
462 
463  frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref);
464  if (!frame->hw_frames_ctx) {
465  ret = AVERROR(ENOMEM);
466  goto fail;
467  }
468 
469  return 0;
470  } else {
471  av_log(avctx, AV_LOG_ERROR, "Failed to retrieve the frame buffer, frame is dropped (code = %d)\n", ret);
472  mpp_frame_deinit(&mppframe);
473  }
474  } else if (decoder->eos_reached) {
475  return AVERROR_EOF;
476  } else if (ret == MPP_ERR_TIMEOUT) {
477  av_log(avctx, AV_LOG_DEBUG, "Timeout when trying to get a frame from MPP\n");
478  }
479 
480  return AVERROR(EAGAIN);
481 
482 fail:
483  if (mppframe)
484  mpp_frame_deinit(&mppframe);
485 
486  if (framecontext)
487  av_buffer_unref(&framecontext->decoder_ref);
488 
489  if (framecontextref)
490  av_buffer_unref(&framecontextref);
491 
492  if (desc)
493  av_free(desc);
494 
495  return ret;
496 }
497 
499 {
500  RKMPPDecodeContext *rk_context = avctx->priv_data;
501  RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
502  int ret = MPP_NOK;
503  AVPacket pkt = {0};
504  RK_S32 usedslots, freeslots;
505 
506  if (!decoder->eos_reached) {
507  // we get the available slots in decoder
508  ret = decoder->mpi->control(decoder->ctx, MPP_DEC_GET_STREAM_COUNT, &usedslots);
509  if (ret != MPP_OK) {
510  av_log(avctx, AV_LOG_ERROR, "Failed to get decoder used slots (code = %d).\n", ret);
511  return ret;
512  }
513 
514  freeslots = INPUT_MAX_PACKETS - usedslots;
515  if (freeslots > 0) {
516  ret = ff_decode_get_packet(avctx, &pkt);
517  if (ret < 0 && ret != AVERROR_EOF) {
518  return ret;
519  }
520 
521  ret = rkmpp_send_packet(avctx, &pkt);
523 
524  if (ret < 0) {
525  av_log(avctx, AV_LOG_ERROR, "Failed to send packet to decoder (code = %d)\n", ret);
526  return ret;
527  }
528  }
529 
530  // make sure we keep decoder full
531  if (freeslots > 1)
532  return AVERROR(EAGAIN);
533  }
534 
535  return rkmpp_retrieve_frame(avctx, frame);
536 }
537 
538 static void rkmpp_flush(AVCodecContext *avctx)
539 {
540  RKMPPDecodeContext *rk_context = avctx->priv_data;
541  RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data;
542  int ret = MPP_NOK;
543 
544  av_log(avctx, AV_LOG_DEBUG, "Flush.\n");
545 
546  ret = decoder->mpi->reset(decoder->ctx);
547  if (ret == MPP_OK) {
548  decoder->first_packet = 1;
549  } else
550  av_log(avctx, AV_LOG_ERROR, "Failed to reset MPI (code = %d)\n", ret);
551 }
552 
553 static const AVCodecHWConfigInternal *const rkmpp_hw_configs[] = {
554  HW_CONFIG_INTERNAL(DRM_PRIME),
555  NULL
556 };
557 
558 #define RKMPP_DEC_CLASS(NAME) \
559  static const AVClass rkmpp_##NAME##_dec_class = { \
560  .class_name = "rkmpp_" #NAME "_dec", \
561  .version = LIBAVUTIL_VERSION_INT, \
562  };
563 
564 #define RKMPP_DEC(NAME, ID, BSFS) \
565  RKMPP_DEC_CLASS(NAME) \
566  const FFCodec ff_##NAME##_rkmpp_decoder = { \
567  .p.name = #NAME "_rkmpp", \
568  CODEC_LONG_NAME(#NAME " (rkmpp)"), \
569  .p.type = AVMEDIA_TYPE_VIDEO, \
570  .p.id = ID, \
571  .priv_data_size = sizeof(RKMPPDecodeContext), \
572  .init = rkmpp_init_decoder, \
573  .close = rkmpp_close_decoder, \
574  FF_CODEC_RECEIVE_FRAME_CB(rkmpp_receive_frame), \
575  .flush = rkmpp_flush, \
576  .p.priv_class = &rkmpp_##NAME##_dec_class, \
577  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
578  .hw_configs = rkmpp_hw_configs, \
579  .bsfs = BSFS, \
580  .p.wrapper_name = "rkmpp", \
581  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
582  };
583 
584 RKMPP_DEC(h264, AV_CODEC_ID_H264, "h264_mp4toannexb")
585 RKMPP_DEC(hevc, AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:627
hwconfig.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:220
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:623
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
int64_t
long long int64_t
Definition: coverity.c:34
rkmpp_init_decoder
static int rkmpp_init_decoder(AVCodecContext *avctx)
Definition: rkmppdec.c:152
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:625
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:634
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:322
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:456
AVFrame::width
int width
Definition: frame.h:416
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:248
AVPacket::data
uint8_t * data
Definition: packet.h:522
AV_PIX_FMT_DRM_PRIME
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
Definition: pixfmt.h:351
data
const char data[16]
Definition: mxf.c:148
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
RKMPPDecodeContext::decoder_ref
AVBufferRef * decoder_ref
Definition: rkmppdec.c:59
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVDRMFrameDescriptor
DRM frame descriptor.
Definition: hwcontext_drm.h:133
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
av_hwdevice_ctx_init
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
Definition: hwcontext.c:208
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:557
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:608
rkmpp_get_frameformat
static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat)
Definition: rkmppdec.c:78
decoder
static const chunk_decoder decoder[8]
Definition: dfa.c:331
fail
#define fail()
Definition: checkasm.h:179
pts
static int64_t pts
Definition: transcode_aac.c:643
AVDRMLayerDescriptor
DRM layer descriptor.
Definition: hwcontext_drm.h:96
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
av_hwdevice_ctx_alloc
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
Definition: hwcontext.c:161
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
INPUT_MAX_PACKETS
#define INPUT_MAX_PACKETS
Definition: rkmppdec.c:43
AV_BUFFER_FLAG_READONLY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:114
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
decode.h
RKMPPDecoder::first_packet
char first_packet
Definition: rkmppdec.c:50
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
if
if(ret)
Definition: filter_design.txt:179
rkmpp_send_packet
static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: rkmppdec.c:269
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
RKMPPDecoder
Definition: rkmppdec.c:45
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
RKMPPDecoder::ctx
MppCtx ctx
Definition: rkmppdec.c:46
rkmpp_release_decoder
static void rkmpp_release_decoder(void *opaque, uint8_t *data)
Definition: rkmppdec.c:131
RKMPPDecoder::mpi
MppApi * mpi
Definition: rkmppdec.c:47
time.h
rkmpp_release_frame
static void rkmpp_release_frame(void *opaque, uint8_t *data)
Definition: rkmppdec.c:307
rkmpp_close_decoder
static int rkmpp_close_decoder(AVCodecContext *avctx)
Definition: rkmppdec.c:124
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
RKMPPDecodeContext::av_class
AVClass * av_class
Definition: rkmppdec.c:58
rkmpp_get_codingtype
static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx)
Definition: rkmppdec.c:67
AVPacket::size
int size
Definition: packet.h:523
rkmpp_receive_frame
static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: rkmppdec.c:498
codec_internal.h
RKMPPDecoder::device_ref
AVBufferRef * device_ref
Definition: rkmppdec.c:54
size
int size
Definition: twinvq_data.h:10344
FRAMEGROUP_MAX_FRAMES
#define FRAMEGROUP_MAX_FRAMES
Definition: rkmppdec.c:42
HW_CONFIG_INTERNAL
#define HW_CONFIG_INTERNAL(format)
Definition: hwconfig.h:54
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:431
AVCodecHWConfigInternal
Definition: hwconfig.h:25
RKMPPFrameContext::decoder_ref
AVBufferRef * decoder_ref
Definition: rkmppdec.c:64
frame.h
buffer.h
RKMPP_DEC
#define RKMPP_DEC(NAME, ID, BSFS)
Definition: rkmppdec.c:564
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
log.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
common.h
packet
enum AVPacketSideDataType packet
Definition: decode.c:1381
RKMPPDecoder::frames_ref
AVBufferRef * frames_ref
Definition: rkmppdec.c:53
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
hwcontext_drm.h
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:603
RKMPPDecoder::frame_group
MppBufferGroup frame_group
Definition: rkmppdec.c:48
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
rkmpp_write_data
static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts)
Definition: rkmppdec.c:89
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:695
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFrame::height
int height
Definition: frame.h:416
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
RKMPPFrameContext::frame
MppFrame frame
Definition: rkmppdec.c:63
RKMPPDecodeContext
Definition: rkmppdec.c:57
desc
const char * desc
Definition: libsvtav1.c:75
RECEIVE_FRAME_TIMEOUT
#define RECEIVE_FRAME_TIMEOUT
Definition: rkmppdec.c:41
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
RKMPPFrameContext
Definition: rkmppdec.c:62
rkmpp_hw_configs
static const AVCodecHWConfigInternal *const rkmpp_hw_configs[]
Definition: rkmppdec.c:553
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
RKMPPDecoder::eos_reached
char eos_reached
Definition: rkmppdec.c:51
rkmpp_flush
static void rkmpp_flush(AVCodecContext *avctx)
Definition: rkmppdec.c:538
AV_HWDEVICE_TYPE_DRM
@ AV_HWDEVICE_TYPE_DRM
Definition: hwcontext.h:36
rkmpp_retrieve_frame
static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: rkmppdec.c:320