FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
liboapvenc.c
Go to the documentation of this file.
1 /*
2  * liboapv encoder
3  * Advanced Professional Video codec library
4  *
5  * Copyright (C) 2025 Dawid Kozinski <d.kozinski@samsung.com>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include <oapv/oapv.h>
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/pixfmt.h"
36 
37 #include "avcodec.h"
38 #include "apv.h"
39 #include "codec_internal.h"
40 #include "encode.h"
41 #include "packet_internal.h"
42 #include "profiles.h"
43 
44 #define MAX_BS_BUF (128 * 1024 * 1024)
45 #define MAX_NUM_FRMS (1) // supports only 1-frame in an access unit
46 #define FRM_IDX (0) // supports only 1-frame in an access unit
47 #define MAX_NUM_CC (OAPV_MAX_CC) // Max number of color componets (upto 4:4:4:4)
48 
49 /**
50  * The structure stores all the states associated with the instance of APV encoder
51  */
52 typedef struct ApvEncContext {
53  const AVClass *class;
54 
55  oapve_t id; // APV instance identifier
56  oapvm_t mid;
57  oapve_cdesc_t cdsc; // coding parameters i.e profile, width & height of input frame, num of therads, frame rate ...
58  oapv_bitb_t bitb; // bitstream buffer (output)
59  oapve_stat_t stat; // encoding status (output)
60 
61  oapv_frms_t ifrms; // frames for input
62 
63  int num_frames; // number of frames in an access unit
64 
65  int preset_id; // preset of apv ( fastest, fast, medium, slow, placebo)
66 
67  int qp; // quantization parameter (QP) [0,63]
68 
71 
72 static int apv_imgb_release(oapv_imgb_t *imgb)
73 {
74  int refcnt = --imgb->refcnt;
75  if (refcnt == 0) {
76  for (int i = 0; i < imgb->np; i++)
77  av_freep(&imgb->baddr[i]);
78  av_free(imgb);
79  }
80 
81  return refcnt;
82 }
83 
84 static int apv_imgb_addref(oapv_imgb_t * imgb)
85 {
86  int refcnt = ++imgb->refcnt;
87  return refcnt;
88 }
89 
90 static int apv_imgb_getref(oapv_imgb_t * imgb)
91 {
92  return imgb->refcnt;
93 }
94 
95 /**
96  * Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format
97  *
98  * @return APV pre-defined color format (@see oapv.h) on success, OAPV_CF_UNKNOWN on failure
99  */
100 static inline int get_color_format(enum AVPixelFormat pix_fmt)
101 {
102  int cf = OAPV_CF_UNKNOWN;
103 
104  switch (pix_fmt) {
106  cf = OAPV_CF_YCBCR422;
107  break;
108  default:
109  av_assert0(cf != OAPV_CF_UNKNOWN);
110  }
111 
112  return cf;
113 }
114 
115 static oapv_imgb_t *apv_imgb_create(AVCodecContext *avctx)
116 {
118  oapv_imgb_t *imgb;
119  int input_depth;
120  int cfmt; // color format
121  int cs;
122 
123  av_assert0(desc);
124 
125  imgb = av_mallocz(sizeof(oapv_imgb_t));
126  if (!imgb)
127  goto fail;
128 
129  input_depth = desc->comp[0].depth;
130  cfmt = get_color_format(avctx->pix_fmt);
131  cs = OAPV_CS_SET(cfmt, input_depth, AV_HAVE_BIGENDIAN);
132 
133  imgb->np = desc->nb_components;
134 
135  for (int i = 0; i < imgb->np; i++) {
136  imgb->w[i] = avctx->width >> ((i == 1 || i == 2) ? desc->log2_chroma_w : 0);
137  imgb->h[i] = avctx->height;
138  imgb->aw[i] = FFALIGN(imgb->w[i], OAPV_MB_W);
139  imgb->ah[i] = FFALIGN(imgb->h[i], OAPV_MB_H);
140  imgb->s[i] = imgb->aw[i] * OAPV_CS_GET_BYTE_DEPTH(cs);
141 
142  imgb->bsize[i] = imgb->e[i] = imgb->s[i] * imgb->ah[i];
143  imgb->a[i] = imgb->baddr[i] = av_mallocz(imgb->bsize[i]);
144  if (imgb->a[i] == NULL)
145  goto fail;
146  }
147 
148  imgb->cs = cs;
149  imgb->addref = apv_imgb_addref;
150  imgb->getref = apv_imgb_getref;
151  imgb->release = apv_imgb_release;
152  imgb->refcnt = 1;
153 
154  return imgb;
155 fail:
156  av_log(avctx, AV_LOG_ERROR, "cannot create image buffer\n");
157  if (imgb) {
158  for (int i = 0; i < imgb->np; i++)
159  av_freep(&imgb->a[i]);
160  av_freep(&imgb);
161  }
162  return NULL;
163 }
164 
165 /**
166  * The function returns a pointer to the object of the oapve_cdesc_t type.
167  * oapve_cdesc_t contains all encoder parameters that should be initialized before the encoder is used.
168  *
169  * The field values of the oapve_cdesc_t structure are populated based on:
170  * - the corresponding field values of the AvCodecConetxt structure,
171  * - the apv encoder specific option values,
172  *
173  * The order of processing input data and populating the apve_cdsc structure
174  * 1) first, the fields of the AVCodecContext structure corresponding to the provided input options are processed,
175  * (i.e -pix_fmt yuv422p -s:v 1920x1080 -r 30 -profile:v 0)
176  * 2) then apve-specific options added as AVOption to the apv AVCodec implementation
177  * (i.e -preset 0)
178  *
179  * Keep in mind that, there are options that can be set in different ways.
180  * In this case, please follow the above-mentioned order of processing.
181  * The most recent assignments overwrite the previous values.
182  *
183  * @param[in] avctx codec context (AVCodecContext)
184  * @param[out] cdsc contains all APV encoder encoder parameters that should be initialized before the encoder is use
185  *
186  * @return 0 on success, negative error code on failure
187  */
188 static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
189 {
190  ApvEncContext *apv = avctx->priv_data;
191 
192  /* initialize apv_param struct with default values */
193  int ret = oapve_param_default(&cdsc->param[FRM_IDX]);
194  if (OAPV_FAILED(ret)) {
195  av_log(avctx, AV_LOG_ERROR, "Cannot set default parameter\n");
196  return AVERROR_EXTERNAL;
197  }
198 
199  /* read options from AVCodecContext */
200  if (avctx->width > 0)
201  cdsc->param[FRM_IDX].w = avctx->width;
202 
203  if (avctx->height > 0)
204  cdsc->param[FRM_IDX].h = avctx->height;
205 
206  if (avctx->framerate.num > 0) {
207  cdsc->param[FRM_IDX].fps_num = avctx->framerate.num;
208  cdsc->param[FRM_IDX].fps_den = avctx->framerate.den;
209  } else if (avctx->time_base.num > 0) {
210  cdsc->param[FRM_IDX].fps_num = avctx->time_base.den;
211  cdsc->param[FRM_IDX].fps_den = avctx->time_base.num;
212  }
213 
214  cdsc->param[FRM_IDX].preset = apv->preset_id;
215  cdsc->param[FRM_IDX].qp = apv->qp;
216  if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) {
217  av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 is not supported\n", INT_MAX);
218  return AVERROR(EINVAL);
219  }
220  cdsc->param[FRM_IDX].bitrate = (int)(avctx->bit_rate / 1000);
221  if (cdsc->param[FRM_IDX].bitrate) {
222  if (cdsc->param[FRM_IDX].qp) {
223  av_log(avctx, AV_LOG_WARNING, "You cannot set both the bitrate and the QP parameter at the same time.\n"
224  "If the bitrate is set, the rate control type is set to ABR, which means that the QP value is ignored.\n");
225  }
226  cdsc->param[FRM_IDX].rc_type = OAPV_RC_ABR;
227  }
228 
229  cdsc->threads = avctx->thread_count;
230 
231  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) {
232  cdsc->param[FRM_IDX].color_primaries = avctx->color_primaries;
233  cdsc->param[FRM_IDX].color_description_present_flag = 1;
234  }
235 
236  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED) {
237  cdsc->param[FRM_IDX].transfer_characteristics = avctx->color_trc;
238  cdsc->param[FRM_IDX].color_description_present_flag = 1;
239  }
240 
241  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
242  cdsc->param[FRM_IDX].matrix_coefficients = avctx->colorspace;
243  cdsc->param[FRM_IDX].color_description_present_flag = 1;
244  }
245 
246  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) {
247  cdsc->param[FRM_IDX].full_range_flag = (avctx->color_range == AVCOL_RANGE_JPEG);
248  cdsc->param[FRM_IDX].color_description_present_flag = 1;
249  }
250 
251  cdsc->max_bs_buf_size = MAX_BS_BUF; /* maximum bitstream buffer size */
252  cdsc->max_num_frms = MAX_NUM_FRMS;
253 
254  const AVDictionaryEntry *en = NULL;
255  while (en = av_dict_iterate(apv->oapv_params, en)) {
256  ret = oapve_param_parse(&cdsc->param[FRM_IDX], en->key, en->value);
257  if (ret < 0)
258  av_log(avctx, AV_LOG_WARNING, "Error parsing option '%s = %s'.\n", en->key, en->value);
259  }
260 
261  return 0;
262 }
263 
264 /**
265  * @brief Initialize APV codec
266  * Create an encoder instance and allocate all the needed resources
267  *
268  * @param avctx codec context
269  * @return 0 on success, negative error code on failure
270  */
272 {
273  ApvEncContext *apv = avctx->priv_data;
274  oapve_cdesc_t *cdsc = &apv->cdsc;
275  unsigned char *bs_buf;
276  int ret;
277 
278  /* allocate bitstream buffer */
279  bs_buf = (unsigned char *)av_malloc(MAX_BS_BUF);
280  if (bs_buf == NULL) {
281  av_log(avctx, AV_LOG_ERROR, "Cannot allocate bitstream buffer, size=%d\n", MAX_BS_BUF);
282  return AVERROR(ENOMEM);
283  }
284  apv->bitb.addr = bs_buf;
285  apv->bitb.bsize = MAX_BS_BUF;
286 
287  /* read configurations and set values for created descriptor (APV_CDSC) */
288  ret = get_conf(avctx, cdsc);
289  if (ret < 0) {
290  av_log(avctx, AV_LOG_ERROR, "Cannot get OAPV configuration\n");
291  return ret;
292  }
293 
294  /* create encoder */
295  apv->id = oapve_create(cdsc, &ret);
296  if (apv->id == NULL) {
297  av_log(avctx, AV_LOG_ERROR, "Cannot create OAPV encoder\n");
298  if (ret == OAPV_ERR_INVALID_LEVEL)
299  av_log(avctx, AV_LOG_ERROR, "Invalid level idc: %d\n", cdsc->param[0].level_idc);
300  return AVERROR_EXTERNAL;
301  }
302 
303  /* create metadata handler */
304  apv->mid = oapvm_create(&ret);
305  if (apv->mid == NULL || OAPV_FAILED(ret)) {
306  av_log(avctx, AV_LOG_ERROR, "cannot create OAPV metadata handler\n");
307  return AVERROR_EXTERNAL;
308  }
309 
310  apv->ifrms.frm[FRM_IDX].imgb = apv_imgb_create(avctx);
311  if (apv->ifrms.frm[FRM_IDX].imgb == NULL)
312  return AVERROR(ENOMEM);
313  apv->ifrms.num_frms++;
314 
315  /* color description values */
316  if (cdsc->param[FRM_IDX].color_description_present_flag) {
317  avctx->color_primaries = cdsc->param[FRM_IDX].color_primaries;
318  avctx->color_trc = cdsc->param[FRM_IDX].transfer_characteristics;
319  avctx->colorspace = cdsc->param[FRM_IDX].matrix_coefficients;
320  avctx->color_range = (cdsc->param[FRM_IDX].full_range_flag) ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
321  }
322 
323  return 0;
324 }
325 
326 /**
327  * Encode raw data frame into APV packet
328  *
329  * @param[in] avctx codec context
330  * @param[out] avpkt output AVPacket containing encoded data
331  * @param[in] frame AVFrame containing the raw data to be encoded
332  * @param[out] got_packet encoder sets to 0 or 1 to indicate that a
333  * non-empty packet was returned in pkt
334  *
335  * @return 0 on success, negative error code on failure
336  */
337 static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt,
338  const AVFrame *frame, int *got_packet)
339 {
340  ApvEncContext *apv = avctx->priv_data;
341  const oapve_cdesc_t *cdsc = &apv->cdsc;
342  oapv_frm_t *frm = &apv->ifrms.frm[FRM_IDX];
343  oapv_imgb_t *imgb = frm->imgb;
344  int ret;
345 
346  if (avctx->width != frame->width || avctx->height != frame->height || avctx->pix_fmt != frame->format) {
347  av_log(avctx, AV_LOG_ERROR, "Dimension changes are not supported\n");
348  return AVERROR(EINVAL);
349  }
350 
351  av_image_copy((uint8_t **)imgb->a, imgb->s, (const uint8_t **)frame->data, frame->linesize,
352  frame->format, frame->width, frame->height);
353 
354  imgb->ts[0] = frame->pts;
355 
356  frm->group_id = 1; // @todo FIX-ME : need to set properly in case of multi-frame
357  frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
358 
359  ret = oapve_encode(apv->id, &apv->ifrms, apv->mid, &apv->bitb, &apv->stat, NULL);
360  if (OAPV_FAILED(ret)) {
361  av_log(avctx, AV_LOG_ERROR, "oapve_encode() failed\n");
362  return AVERROR_EXTERNAL;
363  }
364 
365  /* store bitstream */
366  if (OAPV_SUCCEEDED(ret) && apv->stat.write > 0) {
367  uint8_t *data = apv->bitb.addr;
368  int size = apv->stat.write;
369 
370  // The encoder may return a "Raw bitstream" formated AU, including au_size.
371  // Discard it as we only need the access_unit() structure.
372  if (size > 4 && AV_RB32(data) != APV_SIGNATURE) {
373  data += 4;
374  size -= 4;
375  }
376 
377  ret = ff_get_encode_buffer(avctx, avpkt, size, 0);
378  if (ret < 0)
379  return ret;
380 
381  memcpy(avpkt->data, data, size);
382  avpkt->pts = avpkt->dts = frame->pts;
383  avpkt->flags |= AV_PKT_FLAG_KEY;
384 
385  if (cdsc->param[FRM_IDX].qp)
387 
388  *got_packet = 1;
389  }
390 
391  return 0;
392 }
393 
394 /**
395  * Destroy the encoder and release all the allocated resources
396  *
397  * @param avctx codec context
398  * @return 0 on success, negative error code on failure
399  */
401 {
402  ApvEncContext *apv = avctx->priv_data;
403 
404  for (int i = 0; i < apv->num_frames; i++) {
405  if (apv->ifrms.frm[i].imgb != NULL)
406  apv->ifrms.frm[i].imgb->release(apv->ifrms.frm[i].imgb);
407  apv->ifrms.frm[i].imgb = NULL;
408  }
409 
410  if (apv->mid) {
411  oapvm_rem_all(apv->mid);
412  }
413 
414  if (apv->id) {
415  oapve_delete(apv->id);
416  apv->id = NULL;
417  }
418 
419  if (apv->mid) {
420  oapvm_delete(apv->mid);
421  apv->mid = NULL;
422  }
423 
424  av_freep(&apv->bitb.addr); /* release bitstream buffer */
425 
426  return 0;
427 }
428 
429 #define OFFSET(x) offsetof(ApvEncContext, x)
430 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
431 
432 static const enum AVPixelFormat supported_pixel_formats[] = {
435 };
436 
437 static const AVOption liboapv_options[] = {
438  { "preset", "Encoding preset for setting encoding speed (optimization level control)", OFFSET(preset_id), AV_OPT_TYPE_INT, { .i64 = OAPV_PRESET_DEFAULT }, OAPV_PRESET_FASTEST, OAPV_PRESET_PLACEBO, VE, .unit = "preset" },
439  { "fastest", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FASTEST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
440  { "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FAST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
441  { "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_MEDIUM }, INT_MIN, INT_MAX, VE, .unit = "preset" },
442  { "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_SLOW }, INT_MIN, INT_MAX, VE, .unit = "preset" },
443  { "placebo", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_PLACEBO }, INT_MIN, INT_MAX, VE, .unit = "preset" },
444  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "preset" },
445 
446  { "qp", "Quantization parameter value for CQP rate control mode", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63, VE },
447  { "oapv-params", "Override the apv configuration using a :-separated list of key=value parameters", OFFSET(oapv_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
448  { NULL }
449 };
450 
451 static const AVClass liboapve_class = {
452  .class_name = "liboapv",
453  .item_name = av_default_item_name,
454  .option = liboapv_options,
455  .version = LIBAVUTIL_VERSION_INT,
456 };
457 
459  { "b", "0" }, // bitrate in terms of kilo-bits per second (support for bit-rates from a few hundred Mbps to a few Gbps for 2K, 4K and 8K resolution content)
460  { NULL },
461 };
462 
464  .p.name = "liboapv",
465  .p.long_name = NULL_IF_CONFIG_SMALL("liboapv APV"),
466  .p.type = AVMEDIA_TYPE_VIDEO,
467  .p.id = AV_CODEC_ID_APV,
468  .init = liboapve_init,
470  .close = liboapve_close,
471  .priv_data_size = sizeof(ApvEncContext),
472  .p.priv_class = &liboapve_class,
473  .defaults = liboapve_defaults,
474  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS | AV_CODEC_CAP_DR1,
475  .p.wrapper_name = "liboapv",
476  .p.pix_fmts = supported_pixel_formats,
477  .p.profiles = NULL_IF_CONFIG_SMALL(ff_apv_profiles),
479 };
get_color_format
static int get_color_format(enum AVPixelFormat pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format.
Definition: liboapvenc.c:100
liboapv_options
static const AVOption liboapv_options[]
Definition: liboapvenc.c:437
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
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
ApvEncContext::stat
oapve_stat_t stat
Definition: liboapvenc.c:59
ApvEncContext
The structure stores all the states associated with the instance of APV encoder.
Definition: liboapvenc.c:52
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
APV_SIGNATURE
#define APV_SIGNATURE
Definition: apv.h:23
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
pixdesc.h
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:750
AVPacket::data
uint8_t * data
Definition: packet.h:535
AVOption
AVOption.
Definition: opt.h:429
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:647
data
const char data[16]
Definition: mxf.c:149
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
ApvEncContext::qp
int qp
Definition: liboapvenc.c:67
AVDictionary
Definition: dict.c:32
ApvEncContext::cdsc
oapve_cdesc_t cdsc
Definition: liboapvenc.c:57
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:590
ApvEncContext::bitb
oapv_bitb_t bitb
Definition: liboapvenc.c:58
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
liboapve_class
static const AVClass liboapve_class
Definition: liboapvenc.c:451
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:551
ApvEncContext::num_frames
int num_frames
Definition: liboapvenc.c:63
apv_imgb_release
static int apv_imgb_release(oapv_imgb_t *imgb)
Definition: liboapvenc.c:72
ff_apv_profiles
const AVProfile ff_apv_profiles[]
Definition: profiles.c:206
FFCodecDefault
Definition: codec_internal.h:96
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ApvEncContext::id
oapve_t id
Definition: liboapvenc.c:55
fail
#define fail()
Definition: checkasm.h:196
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1561
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:353
AVRational::num
int num
Numerator.
Definition: rational.h:59
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:645
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
ApvEncContext::ifrms
oapv_frms_t ifrms
Definition: liboapvenc.c:61
intreadwrite.h
liboapve_defaults
static const FFCodecDefault liboapve_defaults[]
Definition: liboapvenc.c:458
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
AVDictionaryEntry::key
char * key
Definition: dict.h:91
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:109
MAX_BS_BUF
#define MAX_BS_BUF
Definition: liboapvenc.c:44
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
liboapve_init
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
Definition: liboapvenc.c:271
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1270
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:622
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
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
apv_imgb_addref
static int apv_imgb_addref(oapv_imgb_t *imgb)
Definition: liboapvenc.c:84
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:481
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition: opt.h:290
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:240
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
profiles.h
liboapve_close
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
Definition: liboapvenc.c:400
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:529
apv_imgb_create
static oapv_imgb_t * apv_imgb_create(AVCodecContext *avctx)
Definition: liboapvenc.c:115
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:716
apv_imgb_getref
static int apv_imgb_getref(oapv_imgb_t *imgb)
Definition: liboapvenc.c:90
ApvEncContext::oapv_params
AVDictionary * oapv_params
Definition: liboapvenc.c:69
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
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
codec_internal.h
size
int size
Definition: twinvq_data.h:10344
VE
#define VE
Definition: liboapvenc.c:430
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
apv.h
supported_pixel_formats
static enum AVPixelFormat supported_pixel_formats[]
Definition: liboapvenc.c:432
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:534
OFFSET
#define OFFSET(x)
Definition: liboapvenc.c:429
FRM_IDX
#define FRM_IDX
Definition: liboapvenc.c:46
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:541
liboapve_encode
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
Definition: liboapvenc.c:337
MAX_NUM_FRMS
#define MAX_NUM_FRMS
Definition: liboapvenc.c:45
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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
ApvEncContext::preset_id
int preset_id
Definition: liboapvenc.c:65
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
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:676
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:733
avcodec.h
ff_liboapv_encoder
const FFCodec ff_liboapv_encoder
Definition: liboapvenc.c:463
ret
ret
Definition: filter_design.txt:187
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:332
pixfmt.h
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:264
AVCodecContext
main external API structure.
Definition: avcodec.h:431
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:106
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
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
mem.h
packet_internal.h
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:72
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:512
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_side_data_set_encoder_stats
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: packet.c:610
AVDictionaryEntry::value
char * value
Definition: dict.h:92
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:226
av_image_copy
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:422
get_conf
static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
The function returns a pointer to the object of the oapve_cdesc_t type.
Definition: liboapvenc.c:188
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
ApvEncContext::mid
oapvm_t mid
Definition: liboapvenc.c:56
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42