FFmpeg
rkmppenc.c
Go to the documentation of this file.
1 /*
2  * RockChip MPP Video Encoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * Copyright (c) 2025 Zhao Zhili <quinkblack@foxmail.com>
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config_components.h"
24 
25 #include <assert.h>
26 #include <stdbool.h>
27 
28 #include <rockchip/mpp_frame.h>
29 #include <rockchip/mpp_packet.h>
30 #include <rockchip/rk_mpi.h>
31 
32 #include "libavutil/avassert.h"
33 #include "libavutil/hwcontext.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/log.h"
37 #include "libavutil/mem.h"
38 #include "libavutil/opt.h"
39 
40 #include "avcodec.h"
41 #include "codec_internal.h"
42 #include "encode.h"
43 #include "hwconfig.h"
44 
45 #define RKMPP_TIME_BASE AV_TIME_BASE_Q
46 #define RKMPP_ALIGN_SIZE 16
47 
48 typedef struct RKMPPEncoderContext {
49  const AVClass *av_class;
50 
51  MppCtx enc;
52  MppApi *mpi;
53  MppEncCfg cfg;
55 
56  MppFrameFormat pix_fmt;
59  // When pix_fmt isn't hardware pixel format
60  MppBufferGroup buf_group;
61  MppBuffer frame_buf;
62 
63  MppEncRcMode rc_mode;
64  bool eof_sent;
66 
67 static const enum AVPixelFormat rkmpp_pix_fmts[] = {
72 };
73 
75 {
77 
78  if (ctx->enc) {
79  ctx->mpi->reset(ctx->enc);
80  mpp_destroy(ctx->enc);
81  ctx->enc = NULL;
82  }
83 
84  if (ctx->cfg) {
85  mpp_enc_cfg_deinit(ctx->cfg);
86  ctx->cfg = NULL;
87  }
88 
89  if (ctx->frame_buf) {
90  mpp_buffer_put(ctx->frame_buf);
91  ctx->frame_buf = NULL;
92  }
93 
94  if (ctx->buf_group) {
95  mpp_buffer_group_put(ctx->buf_group);
96  ctx->buf_group = NULL;
97  }
98 
99  av_frame_free(&ctx->frame);
100 
101  return 0;
102 }
103 
105 {
107 
108  ctx->frame = av_frame_alloc();
109  if (!ctx->frame)
110  return AVERROR(ENOMEM);
111 
112  if (avctx->pix_fmt == AV_PIX_FMT_DRM_PRIME)
113  return 0;
114 
115  int ret = mpp_buffer_group_get_internal(&ctx->buf_group,
116  MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CACHABLE);
117  if (ret != MPP_OK) {
118  av_log(avctx, AV_LOG_ERROR, "Failed to create buffer group, %d\n",
119  ret);
120  return AVERROR_EXTERNAL;
121  }
122 
123  int n = av_image_get_buffer_size(avctx->pix_fmt, ctx->mpp_stride,
124  ctx->mpp_height, 1);
125  if (n < 0)
126  return ret;
127  ret = mpp_buffer_get(ctx->buf_group, &ctx->frame_buf, n);
128  if (ret != MPP_OK) {
129  av_log(avctx, AV_LOG_ERROR, "Failed to get frame buffer, %d\n",
130  ret);
131  return AVERROR_EXTERNAL;
132  }
133 
134  return 0;
135 }
136 
138 {
140  MppEncHeaderMode mode = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ?
141  MPP_ENC_HEADER_MODE_DEFAULT : MPP_ENC_HEADER_MODE_EACH_IDR;
142 
143  int ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_HEADER_MODE, &mode);
144  if (ret != MPP_OK) {
145  av_log(avctx, AV_LOG_ERROR, "Failed to set header mode: %d\n", ret);
146  return AVERROR_EXTERNAL;
147  }
148 
149  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
150  return 0;
151 
152  size_t size = 4096;
154  if (!avctx->extradata)
155  return AVERROR(ENOMEM);
156 
157  MppPacket packet = NULL;
158  mpp_packet_init(&packet, avctx->extradata, size);
159  mpp_packet_set_length(packet, 0);
160  ret = ctx->mpi->control(ctx->enc, MPP_ENC_GET_HDR_SYNC, packet);
161  if (ret != MPP_OK) {
162  av_log(avctx, AV_LOG_ERROR, "Failed to get header: %d\n", ret);
164  goto out;
165  }
166 
167  avctx->extradata_size = mpp_packet_get_length(packet);
168  if (avctx->extradata_size == 0 || avctx->extradata_size > size) {
169  av_log(avctx, AV_LOG_ERROR, "Invalid extradata size %d\n",
170  avctx->extradata_size);
172  goto out;
173  }
174 
175  ret = 0;
176 out:
177  mpp_packet_deinit(&packet);
178 
179  return ret;
180 }
181 
183 {
185  int ret;
186 
187  MppCodingType codectype;
188  switch (avctx->codec_id) {
189  case AV_CODEC_ID_H264:
190  codectype = MPP_VIDEO_CodingAVC;
191  break;
192  case AV_CODEC_ID_HEVC:
193  codectype = MPP_VIDEO_CodingHEVC;
194  break;
195  default:
196  av_unreachable("Invalid codec_id");
197  }
198 
199  ret = mpp_check_support_format(MPP_CTX_ENC, codectype);
200  if (ret != MPP_OK) {
201  av_log(avctx, AV_LOG_ERROR, "The device doesn't support %s\n",
202  avcodec_get_name(avctx->codec_id));
203  return AVERROR_EXTERNAL;
204  }
205 
206  ret = mpp_create(&ctx->enc, &ctx->mpi);
207  if (ret != MPP_OK) {
208  av_log(avctx, AV_LOG_ERROR, "Failed to create MPP context (%d).\n", ret);
209  return AVERROR_EXTERNAL;
210  }
211 
212  ret = mpp_init(ctx->enc, MPP_CTX_ENC, codectype);
213  if (ret != MPP_OK) {
214  av_log(avctx, AV_LOG_ERROR, "Failed to initialize MPP context (%d).\n", ret);
215  return AVERROR_EXTERNAL;
216  }
217 
218  ret = mpp_enc_cfg_init(&ctx->cfg);
219  if (ret != MPP_OK) {
220  av_log(avctx, AV_LOG_ERROR, "Failed to initialize config (%d).\n", ret);
221  return AVERROR_EXTERNAL;
222  }
223 
224  MppEncCfg cfg = ctx->cfg;
225  ret = ctx->mpi->control(ctx->enc, MPP_ENC_GET_CFG, cfg);
226  if (ret != MPP_OK) {
227  av_log(avctx, AV_LOG_ERROR, "Failed to get encoder config: %d\n", ret);
228  return AVERROR_EXTERNAL;
229  }
230 
231  mpp_enc_cfg_set_s32(cfg, "prep:width", avctx->width);
232  mpp_enc_cfg_set_s32(cfg, "prep:height", avctx->height);
233  ctx->mpp_stride = FFALIGN(avctx->width, RKMPP_ALIGN_SIZE);
234  ctx->mpp_height = FFALIGN(avctx->height, RKMPP_ALIGN_SIZE);
235  mpp_enc_cfg_set_s32(cfg, "prep:hor_stride", ctx->mpp_stride);
236  mpp_enc_cfg_set_s32(cfg, "prep:ver_stride", ctx->mpp_height);
237 
238  if (avctx->pix_fmt == AV_PIX_FMT_DRM_PRIME || avctx->pix_fmt == AV_PIX_FMT_NV12)
239  ctx->pix_fmt = MPP_FMT_YUV420SP;
240  else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
241  ctx->pix_fmt = MPP_FMT_YUV420P;
242  else // Can only happen during development
243  return AVERROR_BUG;
244  mpp_enc_cfg_set_s32(cfg, "prep:format", ctx->pix_fmt);
245 
246  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
247  mpp_enc_cfg_set_s32(cfg, "prep:colorspace", avctx->colorspace);
249  mpp_enc_cfg_set_s32(cfg, "prep:colorprim", avctx->color_primaries);
250  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
251  mpp_enc_cfg_set_s32(cfg, "prep:colortrc", avctx->color_trc);
252  static_assert((int)AVCOL_RANGE_MPEG == (int)MPP_FRAME_RANGE_MPEG &&
253  (int)AVCOL_RANGE_JPEG == (int)MPP_FRAME_RANGE_JPEG &&
254  (int)AVCOL_RANGE_UNSPECIFIED == (int) MPP_FRAME_RANGE_UNSPECIFIED,
255  "MppFrameColorRange not equal to AVColorRange");
256  mpp_enc_cfg_set_s32(cfg, "prep:colorrange", avctx->color_range);
257 
258  /* These two options sound like variable frame rate from the doc, but they
259  * are not. When they are false, bitrate control is based on frame numbers
260  * and framerate. But when they are true, bitrate control is based on wall
261  * clock time, not based on frame timestamps, which makes these options
262  * almost useless, except in certain rare realtime case.
263  */
264  mpp_enc_cfg_set_s32(cfg, "rc:fps_in_flex", 0);
265  mpp_enc_cfg_set_s32(cfg, "rc:fps_out_flex", 0);
266  if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
267  mpp_enc_cfg_set_s32(cfg, "rc:fps_in_num", avctx->framerate.num);
268  mpp_enc_cfg_set_s32(cfg, "rc:fps_in_denom", avctx->framerate.den);
269  mpp_enc_cfg_set_s32(cfg, "rc:fps_out_num", avctx->framerate.num);
270  mpp_enc_cfg_set_s32(cfg, "rc:fps_out_denom", avctx->framerate.den);
271  }
272 
273  if (avctx->gop_size >= 0)
274  mpp_enc_cfg_set_s32(cfg, "rc:gop", avctx->gop_size);
275 
276  mpp_enc_cfg_set_u32(cfg, "rc:mode", ctx->rc_mode);
277  if (avctx->bit_rate > 0) {
278  mpp_enc_cfg_set_s32(cfg, "rc:bps_target", avctx->bit_rate);
279  if (avctx->rc_buffer_size >= avctx->bit_rate) {
280  int seconds = round((double)avctx->rc_buffer_size / avctx->bit_rate);
281  // 60 is the upper bound from the doc
282  seconds = FFMIN(seconds, 60);
283  mpp_enc_cfg_set_s32(cfg, "rc:stats_time", seconds);
284  }
285  }
286  if (avctx->rc_max_rate > 0)
287  mpp_enc_cfg_set_s32(cfg, "rc:bps_max", avctx->rc_max_rate);
288  if (avctx->rc_min_rate > 0)
289  mpp_enc_cfg_set_s32(cfg, "rc:bps_min", avctx->rc_min_rate);
290 
291  mpp_enc_cfg_set_u32(cfg, "rc:drop_mode", MPP_ENC_RC_DROP_FRM_DISABLED);
292 
293  ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_CFG, cfg);
294  if (ret != MPP_OK) {
295  av_log(avctx, AV_LOG_ERROR, "Failed to set config: %d\n", ret);
296  return AVERROR_EXTERNAL;
297  }
298 
299  ret = rkmpp_create_frame_buf(avctx);
300  if (ret < 0)
301  return ret;
302 
303  ret = rkmpp_export_extradata(avctx);
304  if (ret < 0)
305  return ret;
306 
307  return 0;
308 }
309 
310 static int rkmpp_output_pkt(AVCodecContext *avctx, AVPacket *pkt, MppPacket packet)
311 {
312  if (mpp_packet_get_eos(packet)) {
313  av_log(avctx, AV_LOG_INFO, "Receive eos packet\n");
314  return AVERROR_EOF;
315  }
316 
317  size_t size = mpp_packet_get_length(packet);
318  void *data = mpp_packet_get_pos(packet);
319 
320  if (!size || !data) {
321  av_log(avctx, AV_LOG_ERROR, "Encoder return empty packet\n");
322  return AVERROR_EXTERNAL;
323  }
324 
325  int ret = ff_get_encode_buffer(avctx, pkt, size, 0);
326  if (ret < 0)
327  return ret;
328  memcpy(pkt->data, data, size);
329 
330  int64_t pts = mpp_packet_get_pts(packet);
331  int64_t dts = mpp_packet_get_dts(packet);
332 
334  /* dts is always zero currently, since rkmpp copy dts from MppFrame to
335  * MppPacket, and we don't set dts for MppFrame (it make no sense for
336  * encoder). rkmpp encoder doesn't support reordering, so we can just
337  * set dts as pts.
338  *
339  * TODO: remove this workaround once rkmpp fixed the issue.
340  */
341  if (dts)
342  pkt->dts = av_rescale_q(dts, RKMPP_TIME_BASE, avctx->time_base);
343  else
344  pkt->dts = pkt->pts;
345 
346  MppMeta meta = mpp_packet_get_meta(packet);
347  if (!meta) {
348  av_log(avctx, AV_LOG_ERROR, "Failed to get meta from mpp packet\n");
349  return AVERROR_EXTERNAL;
350  }
351 
352  int key_frame = 0;
353  ret = mpp_meta_get_s32(meta, KEY_OUTPUT_INTRA, &key_frame);
354  if (ret != MPP_OK) {
355  av_log(avctx, AV_LOG_ERROR, "Failed to get key frame info\n");
356  return AVERROR_EXTERNAL;
357  }
358 
359  if (key_frame)
361 
362  return 0;
363 }
364 
365 static int rkmpp_set_hw_frame(AVCodecContext *avctx, MppFrame frame)
366 {
368  AVBufferRef *hw_ref = ctx->frame->hw_frames_ctx;
369  int ret;
370 
371  if (!hw_ref)
372  return AVERROR(EINVAL);
373 
374  AVHWFramesContext *hwframes = (AVHWFramesContext *)hw_ref->data;
375  if (hwframes->sw_format != AV_PIX_FMT_NV12)
376  return AVERROR(EINVAL);
377 
378 
379  const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)ctx->frame->data[0];
380  const AVDRMLayerDescriptor *layer = &desc->layers[0];
381 
382  int stride = layer->planes[0].pitch;
383  int vertical = layer->planes[1].offset / stride;
384  if (stride != ctx->mpp_stride || vertical != ctx->mpp_height) {
385  // Update stride info
386  ctx->mpp_stride = stride;
387  ctx->mpp_height = vertical;
388  mpp_enc_cfg_set_s32(ctx->cfg, "prep:hor_stride", ctx->mpp_stride);
389  mpp_enc_cfg_set_s32(ctx->cfg, "prep:ver_stride", ctx->mpp_height);
390  ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_CFG, ctx->cfg);
391  if (ret != MPP_OK) {
392  av_log(avctx, AV_LOG_ERROR, "Failed to set config: %d\n", ret);
393  return AVERROR_EXTERNAL;
394  }
395  }
396  mpp_frame_set_hor_stride(frame, stride);
397  mpp_frame_set_ver_stride(frame, vertical);
398 
399  MppBuffer buffer = {0};
400  MppBufferInfo info = {
401  .type = MPP_BUFFER_TYPE_DRM,
402  .size = desc->objects[0].size,
403  .fd = desc->objects[0].fd,
404  };
405  ret = mpp_buffer_import(&buffer, &info);
406  if (ret != MPP_OK)
407  return AVERROR_EXTERNAL;
408 
409  mpp_frame_set_buffer(frame, buffer);
410  mpp_buffer_put(buffer);
411 
412  return 0;
413 }
414 
415 static int rkmpp_set_sw_frame(AVCodecContext *avctx, MppFrame frame)
416 {
418  AVFrame *f = ctx->frame;
419 
420  mpp_buffer_sync_begin(ctx->frame_buf);
421  void *buf = mpp_buffer_get_ptr(ctx->frame_buf);
422 
423  uint8_t *dst[4] = {NULL};
424  int dst_linesizes[4] = {0};
425  int ret = av_image_fill_linesizes(dst_linesizes, f->format, ctx->mpp_stride);
426  if (ret < 0)
427  goto out;
428  ret = av_image_fill_pointers(dst, f->format, ctx->mpp_height, buf,
429  dst_linesizes);
430  if (ret < 0)
431  goto out;
432 
433  av_image_copy2(dst, dst_linesizes, f->data, f->linesize,
434  f->format, f->width, f->height);
435  mpp_frame_set_hor_stride(frame, ctx->mpp_stride);
436  mpp_frame_set_ver_stride(frame, ctx->mpp_height);
437 
438  ret = 0;
439 
440 out:
441  mpp_buffer_sync_end(ctx->frame_buf);
442  if (!ret)
443  mpp_frame_set_buffer(frame, ctx->frame_buf);
444 
445  return ret;
446 }
447 
449 {
451  MppFrame frame = NULL;
452  int ret = 0;
453 
454  ret = mpp_frame_init(&frame);
455  if (ret != MPP_OK) {
457  goto out;
458  }
459 
460  if (ctx->frame->buf[0]) {
461  if (ctx->frame->format == AV_PIX_FMT_DRM_PRIME)
462  ret = rkmpp_set_hw_frame(avctx, frame);
463  else
464  ret = rkmpp_set_sw_frame(avctx, frame);
465 
466  if (ret < 0)
467  goto out;
468 
469  mpp_frame_set_fmt(frame, ctx->pix_fmt);
470  mpp_frame_set_width(frame, ctx->frame->width);
471  mpp_frame_set_height(frame, ctx->frame->height);
472  mpp_frame_set_pts(frame, av_rescale_q(ctx->frame->pts,
473  avctx->time_base, RKMPP_TIME_BASE));
474  } else {
475  mpp_frame_set_buffer(frame, NULL);
476  mpp_frame_set_eos(frame, 1);
477  }
478 
479  ret = ctx->mpi->encode_put_frame(ctx->enc, frame);
480  if (ret != MPP_OK)
482 
483 out:
484  if (frame)
485  mpp_frame_deinit(&frame);
486 
487  return ret;
488 }
489 
491 {
493 
494  while (true) {
495  MppPacket packet = NULL;
496  int ret = ctx->mpi->encode_get_packet(ctx->enc, &packet);
497 
498  if (ret == MPP_OK && packet) {
499  ret = rkmpp_output_pkt(avctx, pkt, packet);
500  mpp_packet_deinit(&packet);
501  return ret;
502  }
503 
504  if (ctx->eof_sent)
505  continue;
506 
507  if (!ctx->frame->buf[0]) {
508  ret = ff_encode_get_frame(avctx, ctx->frame);
509  if (ret < 0 && ret != AVERROR_EOF)
510  return ret;
511  }
512 
513  ret = rkmpp_send_frame(avctx);
514  if (ret < 0)
515  return ret;
516 
517  if (!ctx->frame->buf[0])
518  ctx->eof_sent = true;
519  else
520  av_frame_unref(ctx->frame);
521  }
522 }
523 
524 static av_cold void rkmpp_flush(AVCodecContext *avctx)
525 {
527  ctx->mpi->reset(ctx->enc);
528  ctx->eof_sent = true;
529 }
530 
531 static const AVCodecHWConfigInternal *const rkmpp_hw_configs[] = {
532  HW_CONFIG_ENCODER_FRAMES(DRM_PRIME, DRM),
533  NULL
534 };
535 
536 #define OFFSET(x) offsetof(RKMPPEncoderContext, x)
537 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
538 static const AVOption rkmpp_options[] = {
539  {"rc", "rate-control mode",
540  OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = MPP_ENC_RC_MODE_VBR }, MPP_ENC_RC_MODE_VBR, INT_MAX, VE, .unit = "rc"},
541  {"vbr", "Variable bitrate mode",
542  0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_VBR}, 0, 0, VE, .unit = "rc"},
543  {"cbr", "Constant bitrate mode",
544  0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_CBR}, 0, 0, VE, .unit = "rc"},
545  {"avbr", "Adaptive bit rate mode",
546  0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_AVBR}, 0, 0, VE, .unit = "rc"},
547  {NULL},
548 };
549 
550 static const AVClass rkmpp_enc_class = {
551  .class_name = "rkmpp_enc",
552  .item_name = av_default_item_name,
553  .version = LIBAVUTIL_VERSION_INT,
554  .option = rkmpp_options,
555 };
556 
557 #define RKMPP_ENC(NAME, ID) \
558  const FFCodec ff_##NAME##_rkmpp_encoder = { \
559  .p.name = #NAME "_rkmpp", \
560  CODEC_LONG_NAME(#NAME " (rkmpp)"), \
561  .p.type = AVMEDIA_TYPE_VIDEO, \
562  .p.id = ID, \
563  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
564  AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_ENCODER_FLUSH, \
565  .priv_data_size = sizeof(RKMPPEncoderContext), \
566  CODEC_PIXFMTS_ARRAY(rkmpp_pix_fmts), \
567  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
568  .init = rkmpp_init_encoder, \
569  FF_CODEC_RECEIVE_PACKET_CB(rkmpp_receive), \
570  .close = rkmpp_close_encoder, \
571  .flush = rkmpp_flush, \
572  .p.priv_class = &rkmpp_enc_class, \
573  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
574  .p.wrapper_name = "rkmpp", \
575  .hw_configs = rkmpp_hw_configs, \
576  };
577 
578 #if CONFIG_H264_RKMPP_ENCODER
580 #endif
581 
582 #if CONFIG_HEVC_RKMPP_ENCODER
584 #endif
hwconfig.h
rkmpp_flush
static av_cold void rkmpp_flush(AVCodecContext *avctx)
Definition: rkmppenc.c:524
OFFSET
#define OFFSET(x)
Definition: rkmppenc.c:536
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
opt.h
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:659
out
FILE * out
Definition: movenc.c:55
rkmpp_hw_configs
static const AVCodecHWConfigInternal *const rkmpp_hw_configs[]
Definition: rkmppenc.c:531
AVCodecContext::rc_min_rate
int64_t rc_min_rate
minimum bitrate
Definition: avcodec.h:1277
RKMPPEncoderContext::mpi
MppApi * mpi
Definition: rkmppenc.c:52
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
RKMPPEncoderContext::av_class
const AVClass * av_class
Definition: rkmppenc.c:49
int64_t
long long int64_t
Definition: coverity.c:34
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
mode
Definition: swscale.c:56
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:652
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
AVPacket::data
uint8_t * data
Definition: packet.h:588
AV_PIX_FMT_DRM_PRIME
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
Definition: pixfmt.h:351
AVOption
AVOption.
Definition: opt.h:429
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
rkmpp_receive
static int rkmpp_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition: rkmppenc.c:490
data
const char data[16]
Definition: mxf.c:149
AVDRMFrameDescriptor
DRM frame descriptor.
Definition: hwcontext_drm.h:133
RKMPPEncoderContext::cfg
MppEncCfg cfg
Definition: rkmppenc.c:53
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:643
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:318
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:551
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
av_image_fill_pointers
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:145
pts
static int64_t pts
Definition: transcode_aac.c:644
AVRational::num
int num
Numerator.
Definition: rational.h:59
rkmpp_pix_fmts
static enum AVPixelFormat rkmpp_pix_fmts[]
Definition: rkmppenc.c:67
AVDRMLayerDescriptor
DRM layer descriptor.
Definition: hwcontext_drm.h:96
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:645
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:106
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
rkmpp_send_frame
static int rkmpp_send_frame(AVCodecContext *avctx)
Definition: rkmppenc.c:448
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
RKMPPEncoderContext::pix_fmt
MppFrameFormat pix_fmt
Definition: rkmppenc.c:56
rkmpp_close_encoder
static av_cold int rkmpp_close_encoder(AVCodecContext *avctx)
Definition: rkmppenc.c:74
info
MIPS optimizations info
Definition: mips.txt:2
ctx
AVFormatContext * ctx
Definition: movenc.c:49
rkmpp_create_frame_buf
static int rkmpp_create_frame_buf(AVCodecContext *avctx)
Definition: rkmppenc.c:104
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1270
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:441
if
if(ret)
Definition: filter_design.txt:179
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1255
rkmpp_set_hw_frame
static int rkmpp_set_hw_frame(AVCodecContext *avctx, MppFrame frame)
Definition: rkmppenc.c:365
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
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:213
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
RKMPPEncoderContext::mpp_height
int mpp_height
Definition: rkmppenc.c:58
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:108
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:481
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:241
rkmpp_enc_class
static const AVClass rkmpp_enc_class
Definition: rkmppenc.c:550
RKMPPEncoderContext::frame
AVFrame * frame
Definition: rkmppenc.c:54
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:535
f
f
Definition: af_crystalizer.c:122
RKMPP_TIME_BASE
#define RKMPP_TIME_BASE
Definition: rkmppenc.c:45
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1005
codec_internal.h
rkmpp_options
static const AVOption rkmpp_options[]
Definition: rkmppenc.c:538
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
RKMPPEncoderContext::frame_buf
MppBuffer frame_buf
Definition: rkmppenc.c:61
size
int size
Definition: twinvq_data.h:10344
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
av_image_get_buffer_size
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition: imgutils.c:466
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
HW_CONFIG_ENCODER_FRAMES
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition: hwconfig.h:98
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:406
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:581
round
static av_always_inline av_const double round(double x)
Definition: libm.h:446
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:514
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
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
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
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
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
rkmpp_export_extradata
static int rkmpp_export_extradata(AVCodecContext *avctx)
Definition: rkmppenc.c:137
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
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
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:265
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:431
RKMPPEncoderContext::mpp_stride
int mpp_stride
Definition: rkmppenc.c:57
RKMPP_ALIGN_SIZE
#define RKMPP_ALIGN_SIZE
Definition: rkmppenc.c:46
VE
#define VE
Definition: rkmppenc.c:537
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
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
rkmpp_init_encoder
static av_cold int rkmpp_init_encoder(AVCodecContext *avctx)
Definition: rkmppenc.c:182
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
rkmpp_set_sw_frame
static int rkmpp_set_sw_frame(AVCodecContext *avctx, MppFrame frame)
Definition: rkmppenc.c:415
rkmpp_output_pkt
static int rkmpp_output_pkt(AVCodecContext *avctx, AVPacket *pkt, MppPacket packet)
Definition: rkmppenc.c:310
desc
const char * desc
Definition: libsvtav1.c:78
mem.h
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:204
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
RKMPPEncoderContext
Definition: rkmppenc.c:48
RKMPP_ENC
#define RKMPP_ENC(NAME, ID)
Definition: rkmppenc.c:557
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
imgutils.h
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
RKMPPEncoderContext::rc_mode
MppEncRcMode rc_mode
Definition: rkmppenc.c:63
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
stride
#define stride
Definition: h264pred_template.c:536
rc_mode
mfxU16 rc_mode
Definition: qsvenc.c:141
RKMPPEncoderContext::buf_group
MppBufferGroup buf_group
Definition: rkmppenc.c:60
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
RKMPPEncoderContext::eof_sent
bool eof_sent
Definition: rkmppenc.c:64
RKMPPEncoderContext::enc
MppCtx enc
Definition: rkmppenc.c:51