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