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