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 "refstruct.h"
34 #include "libavutil/buffer.h"
35 #include "libavutil/common.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/hwcontext.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/log.h"
41 #include "libavutil/mem.h"
42 
43 #define RECEIVE_FRAME_TIMEOUT 100
44 #define FRAMEGROUP_MAX_FRAMES 16
45 #define INPUT_MAX_PACKETS 4
46 
47 typedef struct {
48  MppCtx ctx;
49  MppApi *mpi;
50  MppBufferGroup frame_group;
51 
54 
57 } RKMPPDecoder;
58 
59 typedef struct {
61  RKMPPDecoder *decoder; ///< RefStruct reference
63 
64 typedef struct {
65  MppFrame frame;
66  const RKMPPDecoder *decoder_ref; ///< RefStruct reference
68 
69 static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx)
70 {
71  switch (avctx->codec_id) {
72  case AV_CODEC_ID_H264: return MPP_VIDEO_CodingAVC;
73  case AV_CODEC_ID_HEVC: return MPP_VIDEO_CodingHEVC;
74  case AV_CODEC_ID_VP8: return MPP_VIDEO_CodingVP8;
75  case AV_CODEC_ID_VP9: return MPP_VIDEO_CodingVP9;
76  default: return MPP_VIDEO_CodingUnused;
77  }
78 }
79 
80 static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat)
81 {
82  switch (mppformat) {
83  case MPP_FMT_YUV420SP: return DRM_FORMAT_NV12;
84 #ifdef DRM_FORMAT_NV12_10
85  case MPP_FMT_YUV420SP_10BIT: return DRM_FORMAT_NV12_10;
86 #endif
87  default: return 0;
88  }
89 }
90 
91 static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts)
92 {
93  RKMPPDecodeContext *rk_context = avctx->priv_data;
94  RKMPPDecoder *decoder = rk_context->decoder;
95  int ret;
96  MppPacket packet;
97 
98  // create the MPP packet
99  ret = mpp_packet_init(&packet, buffer, size);
100  if (ret != MPP_OK) {
101  av_log(avctx, AV_LOG_ERROR, "Failed to init MPP packet (code = %d)\n", ret);
102  return AVERROR_UNKNOWN;
103  }
104 
105  mpp_packet_set_pts(packet, pts);
106 
107  if (!buffer)
108  mpp_packet_set_eos(packet);
109 
110  ret = decoder->mpi->decode_put_packet(decoder->ctx, packet);
111  if (ret != MPP_OK) {
112  if (ret == MPP_ERR_BUFFER_FULL) {
113  av_log(avctx, AV_LOG_DEBUG, "Buffer full writing %d bytes to decoder\n", size);
114  ret = AVERROR(EAGAIN);
115  } else
117  }
118  else
119  av_log(avctx, AV_LOG_DEBUG, "Wrote %d bytes to decoder\n", size);
120 
121  mpp_packet_deinit(&packet);
122 
123  return ret;
124 }
125 
127 {
128  RKMPPDecodeContext *rk_context = avctx->priv_data;
129  ff_refstruct_unref(&rk_context->decoder);
130  return 0;
131 }
132 
133 static void rkmpp_release_decoder(FFRefStructOpaque unused, void *obj)
134 {
135  RKMPPDecoder *decoder = obj;
136 
137  if (decoder->mpi) {
138  decoder->mpi->reset(decoder->ctx);
139  mpp_destroy(decoder->ctx);
140  decoder->ctx = NULL;
141  }
142 
143  if (decoder->frame_group) {
144  mpp_buffer_group_put(decoder->frame_group);
145  decoder->frame_group = NULL;
146  }
147 
148  av_buffer_unref(&decoder->frames_ref);
149  av_buffer_unref(&decoder->device_ref);
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 = ff_refstruct_alloc_ext(sizeof(*decoder), 0,
166  if (!decoder) {
167  ret = AVERROR(ENOMEM);
168  goto fail;
169  }
170  rk_context->decoder = decoder;
171 
172  av_log(avctx, AV_LOG_DEBUG, "Initializing RKMPP decoder.\n");
173 
174  codectype = rkmpp_get_codingtype(avctx);
175  if (codectype == MPP_VIDEO_CodingUnused) {
176  av_log(avctx, AV_LOG_ERROR, "Unknown codec type (%d).\n", avctx->codec_id);
178  goto fail;
179  }
180 
181  ret = mpp_check_support_format(MPP_CTX_DEC, codectype);
182  if (ret != MPP_OK) {
183  av_log(avctx, AV_LOG_ERROR, "Codec type (%d) unsupported by MPP\n", avctx->codec_id);
185  goto fail;
186  }
187 
188  // Create the MPP context
189  ret = mpp_create(&decoder->ctx, &decoder->mpi);
190  if (ret != MPP_OK) {
191  av_log(avctx, AV_LOG_ERROR, "Failed to create MPP context (code = %d).\n", ret);
193  goto fail;
194  }
195 
196  // initialize mpp
197  ret = mpp_init(decoder->ctx, MPP_CTX_DEC, codectype);
198  if (ret != MPP_OK) {
199  av_log(avctx, AV_LOG_ERROR, "Failed to initialize MPP context (code = %d).\n", ret);
201  goto fail;
202  }
203 
204  // make decode calls blocking with a timeout
205  paramS32 = MPP_POLL_BLOCK;
206  ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK, &paramS32);
207  if (ret != MPP_OK) {
208  av_log(avctx, AV_LOG_ERROR, "Failed to set blocking mode on MPI (code = %d).\n", ret);
210  goto fail;
211  }
212 
213  paramS64 = RECEIVE_FRAME_TIMEOUT;
214  ret = decoder->mpi->control(decoder->ctx, MPP_SET_OUTPUT_BLOCK_TIMEOUT, &paramS64);
215  if (ret != MPP_OK) {
216  av_log(avctx, AV_LOG_ERROR, "Failed to set block timeout on MPI (code = %d).\n", ret);
218  goto fail;
219  }
220 
221  ret = mpp_buffer_group_get_internal(&decoder->frame_group, MPP_BUFFER_TYPE_ION);
222  if (ret) {
223  av_log(avctx, AV_LOG_ERROR, "Failed to retrieve buffer group (code = %d)\n", ret);
225  goto fail;
226  }
227 
228  ret = decoder->mpi->control(decoder->ctx, MPP_DEC_SET_EXT_BUF_GROUP, decoder->frame_group);
229  if (ret) {
230  av_log(avctx, AV_LOG_ERROR, "Failed to assign buffer group (code = %d)\n", ret);
232  goto fail;
233  }
234 
235  ret = mpp_buffer_group_limit_config(decoder->frame_group, 0, FRAMEGROUP_MAX_FRAMES);
236  if (ret) {
237  av_log(avctx, AV_LOG_ERROR, "Failed to set buffer group limit (code = %d)\n", ret);
239  goto fail;
240  }
241 
242  decoder->first_packet = 1;
243 
244  av_log(avctx, AV_LOG_DEBUG, "RKMPP decoder initialized successfully.\n");
245 
247  if (!decoder->device_ref) {
248  ret = AVERROR(ENOMEM);
249  goto fail;
250  }
251  ret = av_hwdevice_ctx_init(decoder->device_ref);
252  if (ret < 0)
253  goto fail;
254 
255  return 0;
256 
257 fail:
258  av_log(avctx, AV_LOG_ERROR, "Failed to initialize RKMPP decoder.\n");
259  rkmpp_close_decoder(avctx);
260  return ret;
261 }
262 
263 static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
264 {
265  RKMPPDecodeContext *rk_context = avctx->priv_data;
266  RKMPPDecoder *decoder = rk_context->decoder;
267  int ret;
268 
269  // handle EOF
270  if (!avpkt->size) {
271  av_log(avctx, AV_LOG_DEBUG, "End of stream.\n");
272  decoder->eos_reached = 1;
273  ret = rkmpp_write_data(avctx, NULL, 0, 0);
274  if (ret)
275  av_log(avctx, AV_LOG_ERROR, "Failed to send EOS to decoder (code = %d)\n", ret);
276  return ret;
277  }
278 
279  // on first packet, send extradata
280  if (decoder->first_packet) {
281  if (avctx->extradata_size) {
282  ret = rkmpp_write_data(avctx, avctx->extradata,
283  avctx->extradata_size,
284  avpkt->pts);
285  if (ret) {
286  av_log(avctx, AV_LOG_ERROR, "Failed to write extradata to decoder (code = %d)\n", ret);
287  return ret;
288  }
289  }
290  decoder->first_packet = 0;
291  }
292 
293  // now send packet
294  ret = rkmpp_write_data(avctx, avpkt->data, avpkt->size, avpkt->pts);
295  if (ret && ret!=AVERROR(EAGAIN))
296  av_log(avctx, AV_LOG_ERROR, "Failed to write data to decoder (code = %d)\n", ret);
297 
298  return ret;
299 }
300 
301 static void rkmpp_release_frame(void *opaque, uint8_t *data)
302 {
304  RKMPPFrameContext *framecontext = opaque;
305 
306  mpp_frame_deinit(&framecontext->frame);
307  ff_refstruct_unref(&framecontext->decoder_ref);
308 
309  av_free(desc);
310 }
311 
313 {
314  RKMPPDecodeContext *rk_context = avctx->priv_data;
315  RKMPPDecoder *decoder = rk_context->decoder;
316  int ret;
317  MppFrame mppframe = NULL;
318  MppBuffer buffer = NULL;
319  AVDRMLayerDescriptor *layer = NULL;
320  int mode;
321  MppFrameFormat mppformat;
322  uint32_t drmformat;
323 
324  ret = decoder->mpi->decode_get_frame(decoder->ctx, &mppframe);
325  if (ret != MPP_OK && ret != MPP_ERR_TIMEOUT) {
326  av_log(avctx, AV_LOG_ERROR, "Failed to get a frame from MPP (code = %d)\n", ret);
327  goto fail;
328  }
329 
330  if (mppframe) {
331  // Check whether we have a special frame or not
332  if (mpp_frame_get_info_change(mppframe)) {
333  AVHWFramesContext *hwframes;
334 
335  av_log(avctx, AV_LOG_INFO, "Decoder noticed an info change (%dx%d), format=%d\n",
336  (int)mpp_frame_get_width(mppframe), (int)mpp_frame_get_height(mppframe),
337  (int)mpp_frame_get_fmt(mppframe));
338 
339  avctx->width = mpp_frame_get_width(mppframe);
340  avctx->height = mpp_frame_get_height(mppframe);
341 
342  decoder->mpi->control(decoder->ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
343 
344  av_buffer_unref(&decoder->frames_ref);
345 
346  decoder->frames_ref = av_hwframe_ctx_alloc(decoder->device_ref);
347  if (!decoder->frames_ref) {
348  ret = AVERROR(ENOMEM);
349  goto fail;
350  }
351 
352  mppformat = mpp_frame_get_fmt(mppframe);
353  drmformat = rkmpp_get_frameformat(mppformat);
354 
355  hwframes = (AVHWFramesContext*)decoder->frames_ref->data;
356  hwframes->format = AV_PIX_FMT_DRM_PRIME;
357  hwframes->sw_format = drmformat == DRM_FORMAT_NV12 ? AV_PIX_FMT_NV12 : AV_PIX_FMT_NONE;
358  hwframes->width = avctx->width;
359  hwframes->height = avctx->height;
360  ret = av_hwframe_ctx_init(decoder->frames_ref);
361  if (ret < 0)
362  goto fail;
363 
364  // here decoder is fully initialized, we need to feed it again with data
365  ret = AVERROR(EAGAIN);
366  goto fail;
367  } else if (mpp_frame_get_eos(mppframe)) {
368  av_log(avctx, AV_LOG_DEBUG, "Received a EOS frame.\n");
369  decoder->eos_reached = 1;
370  ret = AVERROR_EOF;
371  goto fail;
372  } else if (mpp_frame_get_discard(mppframe)) {
373  av_log(avctx, AV_LOG_DEBUG, "Received a discard frame.\n");
374  ret = AVERROR(EAGAIN);
375  goto fail;
376  } else if (mpp_frame_get_errinfo(mppframe)) {
377  av_log(avctx, AV_LOG_ERROR, "Received a errinfo frame.\n");
379  goto fail;
380  }
381 
382  // here we should have a valid frame
383  av_log(avctx, AV_LOG_DEBUG, "Received a frame.\n");
384 
385  // setup general frame fields
386  frame->format = AV_PIX_FMT_DRM_PRIME;
387  frame->width = mpp_frame_get_width(mppframe);
388  frame->height = mpp_frame_get_height(mppframe);
389  frame->pts = mpp_frame_get_pts(mppframe);
390  frame->color_range = mpp_frame_get_color_range(mppframe);
391  frame->color_primaries = mpp_frame_get_color_primaries(mppframe);
392  frame->color_trc = mpp_frame_get_color_trc(mppframe);
393  frame->colorspace = mpp_frame_get_colorspace(mppframe);
394 
395  mode = mpp_frame_get_mode(mppframe);
396  if ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_DEINTERLACED)
398  if ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) == MPP_FRAME_FLAG_TOP_FIRST)
400 
401  mppformat = mpp_frame_get_fmt(mppframe);
402  drmformat = rkmpp_get_frameformat(mppformat);
403 
404  // now setup the frame buffer info
405  buffer = mpp_frame_get_buffer(mppframe);
406  if (buffer) {
407  RKMPPFrameContext *framecontext;
409  // We allocate the descriptor in buf[0] jointly with a structure
410  // that will allow to hold additional information
411  // for properly releasing MPP frames and decoder.
412  struct {
414  RKMPPFrameContext framecontext;
415  } *combined_desc = av_mallocz(sizeof(*combined_desc));
416  if (!combined_desc) {
417  ret = AVERROR(ENOMEM);
418  goto fail;
419  }
420  desc = &combined_desc->desc;
421  framecontext = &combined_desc->framecontext;
422 
423  desc->nb_objects = 1;
424  desc->objects[0].fd = mpp_buffer_get_fd(buffer);
425  desc->objects[0].size = mpp_buffer_get_size(buffer);
426 
427  desc->nb_layers = 1;
428  layer = &desc->layers[0];
429  layer->format = drmformat;
430  layer->nb_planes = 2;
431 
432  layer->planes[0].object_index = 0;
433  layer->planes[0].offset = 0;
434  layer->planes[0].pitch = mpp_frame_get_hor_stride(mppframe);
435 
436  layer->planes[1].object_index = 0;
437  layer->planes[1].offset = layer->planes[0].pitch * mpp_frame_get_ver_stride(mppframe);
438  layer->planes[1].pitch = layer->planes[0].pitch;
439 
440  // MPP decoder needs to be closed only when all frames have been released.
441  framecontext->frame = mppframe;
442 
443  frame->data[0] = (uint8_t *)desc;
444  frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), rkmpp_release_frame,
445  framecontext, AV_BUFFER_FLAG_READONLY);
446 
447  if (!frame->buf[0]) {
448  av_free(combined_desc);
449  ret = AVERROR(ENOMEM);
450  goto fail;
451  }
452  framecontext->decoder_ref = ff_refstruct_ref(rk_context->decoder);
453 
454  frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref);
455  if (!frame->hw_frames_ctx) {
457  return AVERROR(ENOMEM);
458  }
459 
460  return 0;
461  } else {
462  av_log(avctx, AV_LOG_ERROR, "Failed to retrieve the frame buffer, frame is dropped (code = %d)\n", ret);
463  mpp_frame_deinit(&mppframe);
464  }
465  } else if (decoder->eos_reached) {
466  return AVERROR_EOF;
467  } else if (ret == MPP_ERR_TIMEOUT) {
468  av_log(avctx, AV_LOG_DEBUG, "Timeout when trying to get a frame from MPP\n");
469  }
470 
471  return AVERROR(EAGAIN);
472 
473 fail:
474  if (mppframe)
475  mpp_frame_deinit(&mppframe);
476 
477  return ret;
478 }
479 
481 {
482  RKMPPDecodeContext *rk_context = avctx->priv_data;
483  RKMPPDecoder *decoder = rk_context->decoder;
484  int ret = MPP_NOK;
485  AVPacket pkt = {0};
486  RK_S32 usedslots, freeslots;
487 
488  if (!decoder->eos_reached) {
489  // we get the available slots in decoder
490  ret = decoder->mpi->control(decoder->ctx, MPP_DEC_GET_STREAM_COUNT, &usedslots);
491  if (ret != MPP_OK) {
492  av_log(avctx, AV_LOG_ERROR, "Failed to get decoder used slots (code = %d).\n", ret);
493  return ret;
494  }
495 
496  freeslots = INPUT_MAX_PACKETS - usedslots;
497  if (freeslots > 0) {
498  ret = ff_decode_get_packet(avctx, &pkt);
499  if (ret < 0 && ret != AVERROR_EOF) {
500  return ret;
501  }
502 
503  ret = rkmpp_send_packet(avctx, &pkt);
505 
506  if (ret < 0) {
507  av_log(avctx, AV_LOG_ERROR, "Failed to send packet to decoder (code = %d)\n", ret);
508  return ret;
509  }
510  }
511 
512  // make sure we keep decoder full
513  if (freeslots > 1)
514  return AVERROR(EAGAIN);
515  }
516 
517  return rkmpp_retrieve_frame(avctx, frame);
518 }
519 
520 static void rkmpp_flush(AVCodecContext *avctx)
521 {
522  RKMPPDecodeContext *rk_context = avctx->priv_data;
523  RKMPPDecoder *decoder = rk_context->decoder;
524  int ret = MPP_NOK;
525 
526  av_log(avctx, AV_LOG_DEBUG, "Flush.\n");
527 
528  ret = decoder->mpi->reset(decoder->ctx);
529  if (ret == MPP_OK) {
530  decoder->first_packet = 1;
531  } else
532  av_log(avctx, AV_LOG_ERROR, "Failed to reset MPI (code = %d)\n", ret);
533 }
534 
535 static const AVCodecHWConfigInternal *const rkmpp_hw_configs[] = {
536  HW_CONFIG_INTERNAL(DRM_PRIME),
537  NULL
538 };
539 
540 #define RKMPP_DEC_CLASS(NAME) \
541  static const AVClass rkmpp_##NAME##_dec_class = { \
542  .class_name = "rkmpp_" #NAME "_dec", \
543  .version = LIBAVUTIL_VERSION_INT, \
544  };
545 
546 #define RKMPP_DEC(NAME, ID, BSFS) \
547  RKMPP_DEC_CLASS(NAME) \
548  const FFCodec ff_##NAME##_rkmpp_decoder = { \
549  .p.name = #NAME "_rkmpp", \
550  CODEC_LONG_NAME(#NAME " (rkmpp)"), \
551  .p.type = AVMEDIA_TYPE_VIDEO, \
552  .p.id = ID, \
553  .priv_data_size = sizeof(RKMPPDecodeContext), \
554  .init = rkmpp_init_decoder, \
555  .close = rkmpp_close_decoder, \
556  FF_CODEC_RECEIVE_FRAME_CB(rkmpp_receive_frame), \
557  .flush = rkmpp_flush, \
558  .p.priv_class = &rkmpp_##NAME##_dec_class, \
559  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
560  .hw_configs = rkmpp_hw_configs, \
561  .bsfs = BSFS, \
562  .p.wrapper_name = "rkmpp", \
563  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
564  };
565 
566 RKMPP_DEC(h264, AV_CODEC_ID_H264, "h264_mp4toannexb")
567 RKMPP_DEC(hevc, AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
hwconfig.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:429
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:247
ff_refstruct_ref
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
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
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
ff_refstruct_alloc_ext
static void * ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
A wrapper around ff_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:94
int64_t
long long int64_t
Definition: coverity.c:34
RKMPPDecodeContext::decoder
RKMPPDecoder * decoder
RefStruct reference.
Definition: rkmppdec.c:61
rkmpp_init_decoder
static int rkmpp_init_decoder(AVCodecContext *avctx)
Definition: rkmppdec.c:152
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:389
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:539
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
FFRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
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
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:653
RKMPPFrameContext::decoder_ref
const RKMPPDecoder * decoder_ref
RefStruct reference.
Definition: rkmppdec.c:66
rkmpp_get_frameformat
static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat)
Definition: rkmppdec.c:80
decoder
static const chunk_decoder decoder[8]
Definition: dfa.c:331
fail
#define fail()
Definition: checkasm.h:188
AVDRMLayerDescriptor::nb_planes
int nb_planes
Number of planes in the layer.
Definition: hwcontext_drm.h:106
AVDRMLayerDescriptor::planes
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
Definition: hwcontext_drm.h:110
rkmpp_release_decoder
static void rkmpp_release_decoder(FFRefStructOpaque unused, void *obj)
Definition: rkmppdec.c:133
pts
static int64_t pts
Definition: transcode_aac.c:644
refstruct.h
AVDRMPlaneDescriptor::offset
ptrdiff_t offset
Offset within that object of this plane.
Definition: hwcontext_drm.h:83
AVDRMLayerDescriptor
DRM layer descriptor.
Definition: hwcontext_drm.h:96
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
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:530
INPUT_MAX_PACKETS
#define INPUT_MAX_PACKETS
Definition: rkmppdec.c:45
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:230
decode.h
RKMPPDecoder::first_packet
char first_packet
Definition: rkmppdec.c:52
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
rkmpp_send_packet
static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: rkmppdec.c:263
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
RKMPPDecoder
Definition: rkmppdec.c:47
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:48
RKMPPDecoder::mpi
MppApi * mpi
Definition: rkmppdec.c:49
time.h
rkmpp_release_frame
static void rkmpp_release_frame(void *opaque, uint8_t *data)
Definition: rkmppdec.c:301
rkmpp_close_decoder
static int rkmpp_close_decoder(AVCodecContext *avctx)
Definition: rkmppdec.c:126
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:60
rkmpp_get_codingtype
static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx)
Definition: rkmppdec.c:69
AVPacket::size
int size
Definition: packet.h:540
rkmpp_receive_frame
static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: rkmppdec.c:480
codec_internal.h
RKMPPDecoder::device_ref
AVBufferRef * device_ref
Definition: rkmppdec.c:56
size
int size
Definition: twinvq_data.h:10344
FRAMEGROUP_MAX_FRAMES
#define FRAMEGROUP_MAX_FRAMES
Definition: rkmppdec.c:44
HW_CONFIG_INTERNAL
#define HW_CONFIG_INTERNAL(format)
Definition: hwconfig.h:54
AVCodecHWConfigInternal
Definition: hwconfig.h:25
frame.h
buffer.h
RKMPP_DEC
#define RKMPP_DEC(NAME, ID, BSFS)
Definition: rkmppdec.c:546
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
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:532
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:529
common.h
RKMPPDecoder::frames_ref
AVBufferRef * frames_ref
Definition: rkmppdec.c:55
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:610
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:256
hwcontext_drm.h
AVDRMPlaneDescriptor::object_index
int object_index
Index of the object containing this plane in the objects array of the enclosing frame descriptor.
Definition: hwcontext_drm.h:79
AVCodecContext::height
int height
Definition: avcodec.h:624
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:663
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:648
RKMPPDecoder::frame_group
MppBufferGroup frame_group
Definition: rkmppdec.c:50
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
AVDRMLayerDescriptor::format
uint32_t format
Format of the layer (DRM_FORMAT_*).
Definition: hwcontext_drm.h:100
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
rkmpp_write_data
static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts)
Definition: rkmppdec.c:91
AVCodecContext
main external API structure.
Definition: avcodec.h:451
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:65
RKMPPDecodeContext
Definition: rkmppdec.c:59
desc
const char * desc
Definition: libsvtav1.c:79
mem.h
RECEIVE_FRAME_TIMEOUT
#define RECEIVE_FRAME_TIMEOUT
Definition: rkmppdec.c:43
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
RKMPPFrameContext
Definition: rkmppdec.c:64
rkmpp_hw_configs
static const AVCodecHWConfigInternal *const rkmpp_hw_configs[]
Definition: rkmppdec.c:535
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:624
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
hwcontext.h
AVDRMPlaneDescriptor::pitch
ptrdiff_t pitch
Pitch (linesize) of this plane.
Definition: hwcontext_drm.h:87
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
RKMPPDecoder::eos_reached
char eos_reached
Definition: rkmppdec.c:53
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
rkmpp_flush
static void rkmpp_flush(AVCodecContext *avctx)
Definition: rkmppdec.c:520
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:312