FFmpeg
apv_decode.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stdatomic.h>
20 
21 #include "libavutil/attributes.h"
23 #include "libavutil/mem_internal.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/thread.h"
26 
27 #include "apv.h"
28 #include "apv_decode.h"
29 #include "apv_dsp.h"
30 #include "avcodec.h"
31 #include "cbs.h"
32 #include "cbs_apv.h"
33 #include "codec_internal.h"
34 #include "decode.h"
35 #include "internal.h"
36 #include "thread.h"
37 
38 
39 typedef struct APVDerivedTileInfo {
40  uint8_t tile_cols;
41  uint8_t tile_rows;
42  uint16_t num_tiles;
43  // The spec uses an extra element on the end of these arrays
44  // not corresponding to any tile.
48 
49 typedef struct APVDecodeContext {
52 
55 
59 
60  int nb_unit;
61 
65 
66 static const enum AVPixelFormat apv_format_table[5][5] = {
68  { 0 }, // 4:2:0 is not valid.
72 };
73 
75 
78 {
79  int err, bit_depth;
80 
81  avctx->profile = header->frame_info.profile_idc;
82  avctx->level = header->frame_info.level_idc;
83 
84  bit_depth = header->frame_info.bit_depth_minus8 + 8;
85  if (bit_depth < 8 || bit_depth > 16 || bit_depth % 2) {
86  avpriv_request_sample(avctx, "Bit depth %d", bit_depth);
87  return AVERROR_PATCHWELCOME;
88  }
89  avctx->pix_fmt =
90  apv_format_table[header->frame_info.chroma_format_idc][bit_depth - 4 >> 2];
91 
92  if (!avctx->pix_fmt) {
93  avpriv_request_sample(avctx, "YUVA444P14");
94  return AVERROR_PATCHWELCOME;
95  }
96 
97  err = ff_set_dimensions(avctx,
98  FFALIGN(header->frame_info.frame_width, 16),
99  FFALIGN(header->frame_info.frame_height, 16));
100  if (err < 0) {
101  // Unsupported frame size.
102  return err;
103  }
104  avctx->width = header->frame_info.frame_width;
105  avctx->height = header->frame_info.frame_height;
106 
107  avctx->sample_aspect_ratio = (AVRational){ 1, 1 };
108 
109  avctx->color_primaries = header->color_primaries;
110  avctx->color_trc = header->transfer_characteristics;
111  avctx->colorspace = header->matrix_coefficients;
112  avctx->color_range = header->full_range_flag ? AVCOL_RANGE_JPEG
115 
116  avctx->refs = 0;
117  avctx->has_b_frames = 0;
118 
119  return 0;
120 }
121 
125 };
126 
128 
130 {
132 }
133 
135 {
136  APVDecodeContext *apv = avctx->priv_data;
137  int err;
138 
140 
141  err = ff_cbs_init(&apv->cbc, AV_CODEC_ID_APV, avctx);
142  if (err < 0)
143  return err;
144 
145  apv->cbc->decompose_unit_types =
149 
150  // Extradata could be set here, but is ignored by the decoder.
151 
152  apv->pkt = avctx->internal->in_pkt;
153  ff_apv_dsp_init(&apv->dsp);
154 
155  atomic_init(&apv->tile_errors, 0);
156 
157  return 0;
158 }
159 
161 {
162  APVDecodeContext *apv = avctx->priv_data;
163 
164  apv->nb_unit = 0;
165  av_packet_unref(apv->pkt);
166  ff_cbs_fragment_reset(&apv->au);
167  ff_cbs_flush(apv->cbc);
168 }
169 
171 {
172  APVDecodeContext *apv = avctx->priv_data;
173 
174  ff_cbs_fragment_free(&apv->au);
175  ff_cbs_close(&apv->cbc);
176 
177  return 0;
178 }
179 
181  void *output,
182  ptrdiff_t pitch,
183  GetBitContext *gbc,
184  APVEntropyState *entropy_state,
185  int bit_depth,
186  int qp_shift,
187  const uint16_t *qmatrix)
188 {
189  APVDecodeContext *apv = avctx->priv_data;
190  int err;
191 
192  LOCAL_ALIGNED_32(int16_t, coeff, [64]);
193  memset(coeff, 0, 64 * sizeof(int16_t));
194 
195  err = ff_apv_entropy_decode_block(coeff, gbc, entropy_state);
196  if (err < 0)
197  return err;
198 
199  apv->dsp.decode_transquant(output, pitch,
200  coeff, qmatrix,
201  bit_depth, qp_shift);
202 
203  return 0;
204 }
205 
207  int job, int thread)
208 {
210  APVDecodeContext *apv = avctx->priv_data;
211  const APVDerivedTileInfo *tile_info = &apv->tile_info;
212  const AVPixFmtDescriptor *pix_fmt_desc =
214  int nb_components = pix_fmt_desc->nb_components;
215 
216  int tile_index = job / nb_components;
217  int comp_index = job % nb_components;
218 
219  int sub_w_shift = comp_index == 0 ? 0 : pix_fmt_desc->log2_chroma_w;
220  int sub_h_shift = comp_index == 0 ? 0 : pix_fmt_desc->log2_chroma_h;
221 
222  APVRawTile *tile = &input->tile[tile_index];
223 
224  int tile_y = tile_index / tile_info->tile_cols;
225  int tile_x = tile_index % tile_info->tile_cols;
226 
227  int tile_start_x = tile_info->col_starts[tile_x];
228  int tile_start_y = tile_info->row_starts[tile_y];
229 
230  int tile_width = tile_info->col_starts[tile_x + 1] - tile_start_x;
231  int tile_height = tile_info->row_starts[tile_y + 1] - tile_start_y;
232 
233  int tile_mb_width = tile_width / APV_MB_WIDTH;
234  int tile_mb_height = tile_height / APV_MB_HEIGHT;
235 
236  int blk_mb_width = 2 >> sub_w_shift;
237  int blk_mb_height = 2 >> sub_h_shift;
238 
239  int bit_depth;
240  int qp_shift;
241  LOCAL_ALIGNED_32(uint16_t, qmatrix_scaled, [64]);
242 
243  GetBitContext gbc;
244 
245  APVEntropyState entropy_state = {
246  .log_ctx = avctx,
247  .decode_lut = &decode_lut,
248  .prev_dc = 0,
249  .prev_k_dc = 5,
250  .prev_k_level = 0,
251  };
252 
253  int err;
254 
255  err = init_get_bits8(&gbc, tile->tile_data[comp_index],
256  tile->tile_header.tile_data_size[comp_index]);
257  if (err < 0)
258  goto fail;
259 
260  // Combine the bitstream quantisation matrix with the qp scaling
261  // in advance. (Including qp_shift as well would overflow 16 bits.)
262  // Fix the row ordering at the same time.
263  {
264  static const uint8_t apv_level_scale[6] = { 40, 45, 51, 57, 64, 71 };
265  int qp = tile->tile_header.tile_qp[comp_index];
266  int level_scale = apv_level_scale[qp % 6];
267 
268  bit_depth = input->frame_header.frame_info.bit_depth_minus8 + 8;
269  qp_shift = qp / 6;
270 
271  for (int y = 0; y < 8; y++) {
272  for (int x = 0; x < 8; x++)
273  qmatrix_scaled[y * 8 + x] = level_scale *
274  input->frame_header.quantization_matrix.q_matrix[comp_index][x][y];
275  }
276  }
277 
278  for (int mb_y = 0; mb_y < tile_mb_height; mb_y++) {
279  for (int mb_x = 0; mb_x < tile_mb_width; mb_x++) {
280  for (int blk_y = 0; blk_y < blk_mb_height; blk_y++) {
281  for (int blk_x = 0; blk_x < blk_mb_width; blk_x++) {
282  int frame_y = (tile_start_y +
283  APV_MB_HEIGHT * mb_y +
284  APV_TR_SIZE * blk_y) >> sub_h_shift;
285  int frame_x = (tile_start_x +
286  APV_MB_WIDTH * mb_x +
287  APV_TR_SIZE * blk_x) >> sub_w_shift;
288 
289  ptrdiff_t frame_pitch = apv->output_frame->linesize[comp_index];
290  uint8_t *block_start = apv->output_frame->data[comp_index] +
291  frame_y * frame_pitch + 2 * frame_x;
292 
293  err = apv_decode_block(avctx,
294  block_start, frame_pitch,
295  &gbc, &entropy_state,
296  bit_depth,
297  qp_shift,
298  qmatrix_scaled);
299  if (err < 0) {
300  // Error in block decode means entropy desync,
301  // so this is not recoverable.
302  goto fail;
303  }
304  }
305  }
306  }
307  }
308 
309  av_log(avctx, AV_LOG_DEBUG,
310  "Decoded tile %d component %d: %dx%d MBs starting at (%d,%d)\n",
311  tile_index, comp_index, tile_mb_width, tile_mb_height,
312  tile_start_x, tile_start_y);
313 
314  return 0;
315 
316 fail:
317  av_log(avctx, AV_LOG_VERBOSE,
318  "Decode error in tile %d component %d.\n",
319  tile_index, comp_index);
320  atomic_fetch_add_explicit(&apv->tile_errors, 1, memory_order_relaxed);
321  return err;
322 }
323 
325  const APVRawFrameHeader *fh)
326 {
327  int frame_width_in_mbs = (fh->frame_info.frame_width + (APV_MB_WIDTH - 1)) >> 4;
328  int frame_height_in_mbs = (fh->frame_info.frame_height + (APV_MB_HEIGHT - 1)) >> 4;
329  int start_mb, i;
330 
331  start_mb = 0;
332  for (i = 0; start_mb < frame_width_in_mbs; i++) {
333  ti->col_starts[i] = start_mb * APV_MB_WIDTH;
334  start_mb += fh->tile_info.tile_width_in_mbs;
335  }
336  ti->col_starts[i] = frame_width_in_mbs * APV_MB_WIDTH;
337  ti->tile_cols = i;
338 
339  start_mb = 0;
340  for (i = 0; start_mb < frame_height_in_mbs; i++) {
341  ti->row_starts[i] = start_mb * APV_MB_HEIGHT;
342  start_mb += fh->tile_info.tile_height_in_mbs;
343  }
344  ti->row_starts[i] = frame_height_in_mbs * APV_MB_HEIGHT;
345  ti->tile_rows = i;
346 
347  ti->num_tiles = ti->tile_cols * ti->tile_rows;
348 }
349 
352 {
353  APVDecodeContext *apv = avctx->priv_data;
354  const AVPixFmtDescriptor *desc = NULL;
356  int err, job_count;
357 
358  err = apv_decode_check_format(avctx, &input->frame_header);
359  if (err < 0) {
360  av_log(avctx, AV_LOG_ERROR, "Unsupported format parameters.\n");
361  return err;
362  }
363 
364  if (avctx->skip_frame == AVDISCARD_ALL)
365  return 0;
366 
367  desc = av_pix_fmt_desc_get(avctx->pix_fmt);
368  av_assert0(desc);
369 
370  err = ff_thread_get_buffer(avctx, output, 0);
371  if (err < 0)
372  return err;
373 
374  apv->output_frame = output;
375  atomic_store_explicit(&apv->tile_errors, 0, memory_order_relaxed);
376 
377  apv_derive_tile_info(tile_info, &input->frame_header);
378 
379  // Each component within a tile is independent of every other,
380  // so we can decode all in parallel.
381  job_count = tile_info->num_tiles * desc->nb_components;
382 
383  avctx->execute2(avctx, apv_decode_tile_component,
384  input, NULL, job_count);
385 
386  err = atomic_load_explicit(&apv->tile_errors, memory_order_relaxed);
387  if (err > 0) {
388  av_log(avctx, AV_LOG_ERROR,
389  "Decode errors in %d tile components.\n", err);
390  if (avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) {
391  // Output the frame anyway.
392  output->flags |= AV_FRAME_FLAG_CORRUPT;
393  } else {
394  return AVERROR_INVALIDDATA;
395  }
396  }
397 
398  return 0;
399 }
400 
402  const APVRawMetadata *md)
403 {
404  int err;
405 
406  for (int i = 0; i < md->metadata_count; i++) {
407  const APVRawMetadataPayload *pl = &md->payloads[i];
408 
409  switch (pl->payload_type) {
410  case APV_METADATA_MDCV:
411  {
412  const APVRawMetadataMDCV *mdcv = &pl->mdcv;
414 
415  err = ff_decode_mastering_display_new(avctx, frame, &mdm);
416  if (err < 0)
417  return err;
418 
419  if (mdm) {
420  for (int j = 0; j < 3; j++) {
421  mdm->display_primaries[j][0] =
422  av_make_q(mdcv->primary_chromaticity_x[j], 1 << 16);
423  mdm->display_primaries[j][1] =
424  av_make_q(mdcv->primary_chromaticity_y[j], 1 << 16);
425  }
426 
427  mdm->white_point[0] =
428  av_make_q(mdcv->white_point_chromaticity_x, 1 << 16);
429  mdm->white_point[1] =
430  av_make_q(mdcv->white_point_chromaticity_y, 1 << 16);
431 
432  mdm->max_luminance =
433  av_make_q(mdcv->max_mastering_luminance, 1 << 8);
434  mdm->min_luminance =
435  av_make_q(mdcv->min_mastering_luminance, 1 << 14);
436 
437  mdm->has_primaries = 1;
438  mdm->has_luminance = 1;
439  }
440  }
441  break;
442  case APV_METADATA_CLL:
443  {
444  const APVRawMetadataCLL *cll = &pl->cll;
446 
447  err = ff_decode_content_light_new(avctx, frame, &clm);
448  if (err < 0)
449  return err;
450 
451  if (clm) {
452  clm->MaxCLL = cll->max_cll;
453  clm->MaxFALL = cll->max_fall;
454  }
455  }
456  break;
457  default:
458  // Ignore other types of metadata.
459  break;
460  }
461  }
462 
463  return 0;
464 }
465 
467 {
468  APVDecodeContext *apv = avctx->priv_data;
469  CodedBitstreamFragment *au = &apv->au;
470  int i, err;
471 
472  for (i = apv->nb_unit; i < au->nb_units; i++) {
473  CodedBitstreamUnit *pbu = &au->units[i];
474 
475  switch (pbu->type) {
477  err = apv_decode(avctx, frame, pbu->content);
478  i++;
479  goto end;
480  case APV_PBU_METADATA:
481  apv_decode_metadata(avctx, frame, pbu->content);
482  break;
485  case APV_PBU_DEPTH_FRAME:
486  case APV_PBU_ALPHA_FRAME:
487  if (!avctx->internal->is_copy &&
488  !apv->warned_additional_frames) {
489  av_log(avctx, AV_LOG_WARNING,
490  "Stream contains additional non-primary frames "
491  "which will be ignored by the decoder.\n");
492  apv->warned_additional_frames = 1;
493  }
494  break;
496  case APV_PBU_FILLER:
497  // Not relevant to the decoder.
498  break;
499  default:
500  if (!avctx->internal->is_copy &&
501  !apv->warned_unknown_pbu_types) {
502  av_log(avctx, AV_LOG_WARNING,
503  "Stream contains PBUs with unknown types "
504  "which will be ignored by the decoder.\n");
505  apv->warned_unknown_pbu_types = 1;
506  }
507  break;
508  }
509  }
510 
511  err = AVERROR(EAGAIN);
512 end:
513  av_assert0(i <= apv->au.nb_units);
514  apv->nb_unit = i;
515 
516  if ((err < 0 && err != AVERROR(EAGAIN)) || apv->au.nb_units == i) {
517  av_packet_unref(apv->pkt);
518  ff_cbs_fragment_reset(&apv->au);
519  apv->nb_unit = 0;
520  }
521  if (!err && !frame->buf[0])
522  err = AVERROR(EAGAIN);
523 
524  return err;
525 }
526 
528 {
529  APVDecodeContext *apv = avctx->priv_data;
530  int err;
531 
532  do {
533  if (!apv->au.nb_units) {
534  err = ff_decode_get_packet(avctx, apv->pkt);
535  if (err < 0)
536  return err;
537 
538  err = ff_cbs_read_packet(apv->cbc, &apv->au, apv->pkt);
539  if (err < 0) {
540  ff_cbs_fragment_reset(&apv->au);
541  av_packet_unref(apv->pkt);
542  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
543  return err;
544  }
545 
546  apv->nb_unit = 0;
547  av_log(avctx, AV_LOG_DEBUG, "Total PBUs on this packet: %d.\n",
548  apv->au.nb_units);
549  }
550 
551  err = apv_receive_frame_internal(avctx, frame);
552  } while (err == AVERROR(EAGAIN));
553 
554  return err;
555 }
556 
558  .p.name = "apv",
559  CODEC_LONG_NAME("Advanced Professional Video"),
560  .p.type = AVMEDIA_TYPE_VIDEO,
561  .p.id = AV_CODEC_ID_APV,
562  .priv_data_size = sizeof(APVDecodeContext),
567  .p.capabilities = AV_CODEC_CAP_DR1 |
570  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
571 };
APV_MAX_TILE_COLS
@ APV_MAX_TILE_COLS
Definition: apv.h:75
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
APV_MB_HEIGHT
@ APV_MB_HEIGHT
Definition: apv.h:41
cbs.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
APVRawMetadataCLL
Definition: cbs_apv.h:142
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:251
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
APVDecodeContext::dsp
APVDSPContext dsp
Definition: apv_decode.c:51
APVDerivedTileInfo::tile_cols
uint8_t tile_cols
Definition: apv_decode.c:40
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
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:667
mem_internal.h
APVDecodeContext::output_frame
AVFrame * output_frame
Definition: apv_decode.c:57
thread.h
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
apv_receive_frame_internal
static int apv_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: apv_decode.c:466
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:114
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:226
APVDecodeContext
Definition: apv_decode.c:49
md
#define md
Definition: vf_colormatrix.c:101
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
apv_decode.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:660
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
level_scale
const static int level_scale[2][6]
Definition: intra.c:336
APV_PBU_DEPTH_FRAME
@ APV_PBU_DEPTH_FRAME
Definition: apv.h:30
internal.h
apv_receive_frame
static int apv_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: apv_decode.c:527
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
APVRawFrameInfo::frame_width
uint32_t frame_width
Definition: cbs_apv.h:48
data
const char data[16]
Definition: mxf.c:149
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
FFCodec
Definition: codec_internal.h:127
apv_decode_block
static int apv_decode_block(AVCodecContext *avctx, void *output, ptrdiff_t pitch, GetBitContext *gbc, APVEntropyState *entropy_state, int bit_depth, int qp_shift, const uint16_t *qmatrix)
Definition: apv_decode.c:180
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:81
APVRawTileInfo::tile_width_in_mbs
uint32_t tile_width_in_mbs
Definition: cbs_apv.h:61
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:91
thread.h
APVDecodeContext::tile_info
APVDerivedTileInfo tile_info
Definition: apv_decode.c:54
APVRawMetadataMDCV::max_mastering_luminance
uint32_t max_mastering_luminance
Definition: cbs_apv.h:138
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:448
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
AVCodecInternal::is_copy
int is_copy
When using frame-threaded decoding, this field is set for the first worker thread (e....
Definition: internal.h:54
AV_CODEC_FLAG_OUTPUT_CORRUPT
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
Definition: avcodec.h:221
APVDecodeContext::tile_errors
atomic_int tile_errors
Definition: apv_decode.c:58
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
apv_entropy_once
static AVOnce apv_entropy_once
Definition: apv_decode.c:127
tile_info
static int FUNC() tile_info(CodedBitstreamContext *ctx, RWContext *rw, APVRawTileInfo *current, const APVRawFrameHeader *fh)
Definition: cbs_apv_syntax_template.c:111
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1674
fail
#define fail()
Definition: checkasm.h:219
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:597
GetBitContext
Definition: get_bits.h:109
apv_decode_init
static av_cold int apv_decode_init(AVCodecContext *avctx)
Definition: apv_decode.c:134
APVDecodeContext::nb_unit
int nb_unit
Definition: apv_decode.c:60
AVCodecContext::refs
int refs
number of reference frames
Definition: avcodec.h:697
apv_entropy_build_decode_lut
static av_cold void apv_entropy_build_decode_lut(void)
Definition: apv_decode.c:129
APVRawMetadataMDCV::primary_chromaticity_y
uint16_t primary_chromaticity_y[3]
Definition: cbs_apv.h:135
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:496
APVRawFrameHeader::frame_info
APVRawFrameInfo frame_info
Definition: cbs_apv.h:68
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:522
apv_decode_tile_component
static int apv_decode_tile_component(AVCodecContext *avctx, void *data, int job, int thread)
Definition: apv_decode.c:206
decode_lut
static APVVLCLUT decode_lut
Definition: apv_decode.c:74
APVDSPContext
Definition: apv_dsp.h:26
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:175
APVRawMetadataPayload::cll
APVRawMetadataCLL cll
Definition: cbs_apv.h:171
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:653
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:111
APV_PBU_METADATA
@ APV_PBU_METADATA
Definition: apv.h:33
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:551
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
apv_dsp.h
apv_decode
static int apv_decode(AVCodecContext *avctx, AVFrame *output, APVRawFrame *input)
Definition: apv_decode.c:350
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:705
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:552
APV_PBU_PRIMARY_FRAME
@ APV_PBU_PRIMARY_FRAME
Definition: apv.h:27
APV_METADATA_MDCV
@ APV_METADATA_MDCV
Definition: apv.h:83
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1045
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
APVRawTileInfo::tile_height_in_mbs
uint32_t tile_height_in_mbs
Definition: cbs_apv.h:62
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:54
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:594
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
APVDecodeContext::au
CodedBitstreamFragment au
Definition: apv_decode.c:53
decode.h
APVRawMetadataMDCV::white_point_chromaticity_y
uint16_t white_point_chromaticity_y
Definition: cbs_apv.h:137
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:521
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
apv_decode_flush
static av_cold void apv_decode_flush(AVCodecContext *avctx)
Definition: apv_decode.c:160
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:2226
APVRawMetadataMDCV::white_point_chromaticity_x
uint16_t white_point_chromaticity_x
Definition: cbs_apv.h:136
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:519
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:95
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
APVRawMetadataCLL::max_cll
uint16_t max_cll
Definition: cbs_apv.h:143
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
APVRawMetadata
Definition: cbs_apv.h:178
NULL
#define NULL
Definition: coverity.c:32
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:132
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:677
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:800
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:474
APV_METADATA_CLL
@ APV_METADATA_CLL
Definition: apv.h:84
apv.h
APVRawMetadataCLL::max_fall
uint16_t max_fall
Definition: cbs_apv.h:144
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:580
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:540
ff_apv_entropy_build_decode_lut
void ff_apv_entropy_build_decode_lut(APVVLCLUT *decode_lut)
Build the decoder VLC look-up tables.
Definition: apv_entropy.c:62
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
apv_derive_tile_info
static void apv_derive_tile_info(APVDerivedTileInfo *ti, const APVRawFrameHeader *fh)
Definition: apv_decode.c:324
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1640
atomic_load_explicit
#define atomic_load_explicit(object, order)
Definition: stdatomic.h:96
AVOnce
#define AVOnce
Definition: thread.h:202
APVRawFrame
Definition: cbs_apv.h:101
APVRawMetadataPayload
Definition: cbs_apv.h:165
APVRawFrameInfo::frame_height
uint32_t frame_height
Definition: cbs_apv.h:49
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:578
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
codec_internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
APVRawFrameHeader
Definition: cbs_apv.h:67
apv_decode_check_format
static int apv_decode_check_format(AVCodecContext *avctx, const APVRawFrameHeader *header)
Definition: apv_decode.c:76
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
APV_PBU_PREVIEW_FRAME
@ APV_PBU_PREVIEW_FRAME
Definition: apv.h:29
atomic_fetch_add_explicit
#define atomic_fetch_add_explicit(object, operand, order)
Definition: stdatomic.h:149
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
APVEntropyState
Definition: apv_decode.h:71
ff_apv_dsp_init
av_cold void ff_apv_dsp_init(APVDSPContext *dsp)
Definition: apv_dsp.c:133
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: codec_internal.h:54
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
APVEntropyState::log_ctx
void * log_ctx
Definition: apv_decode.h:72
APVRawMetadataPayload::payload_type
uint32_t payload_type
Definition: cbs_apv.h:166
APV_TR_SIZE
@ APV_TR_SIZE
Definition: apv.h:42
header
static const uint8_t header[24]
Definition: sdr2.c:68
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
APVRawFrameHeader::tile_info
APVRawTileInfo tile_info
Definition: cbs_apv.h:80
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:99
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:592
APVDecodeContext::warned_unknown_pbu_types
uint8_t warned_unknown_pbu_types
Definition: apv_decode.c:63
attributes.h
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
APVDerivedTileInfo::row_starts
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
Definition: apv_decode.c:46
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:638
apv_decode_close
static av_cold int apv_decode_close(AVCodecContext *avctx)
Definition: apv_decode.c:170
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:83
apv_format_table
static enum AVPixelFormat apv_format_table[5][5]
Definition: apv_decode.c:66
atomic_store_explicit
#define atomic_store_explicit(object, desired, order)
Definition: stdatomic.h:90
APVRawMetadataPayload::mdcv
APVRawMetadataMDCV mdcv
Definition: cbs_apv.h:170
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:684
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
AVCodecContext::height
int height
Definition: avcodec.h:600
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:639
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
APV_MB_WIDTH
@ APV_MB_WIDTH
Definition: apv.h:40
APVRawMetadataMDCV::primary_chromaticity_x
uint16_t primary_chromaticity_x[3]
Definition: cbs_apv.h:134
avcodec.h
APVDerivedTileInfo
Definition: apv_decode.c:39
APV_PBU_ALPHA_FRAME
@ APV_PBU_ALPHA_FRAME
Definition: apv.h:31
APV_PBU_FILLER
@ APV_PBU_FILLER
Definition: apv.h:34
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:332
APVDecodeContext::pkt
AVPacket * pkt
Definition: apv_decode.c:56
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
ff_apv_decoder
const FFCodec ff_apv_decoder
Definition: apv_decode.c:557
tile
static int FUNC() tile(CodedBitstreamContext *ctx, RWContext *rw, APVRawTile *current, int tile_idx, uint32_t tile_size)
Definition: cbs_apv_syntax_template.c:224
APVVLCLUT
Definition: apv_decode.h:59
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:2271
APVDerivedTileInfo::tile_rows
uint8_t tile_rows
Definition: apv_decode.c:41
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:548
AVCodecContext
main external API structure.
Definition: avcodec.h:439
FF_CODEC_RECEIVE_FRAME_CB
#define FF_CODEC_RECEIVE_FRAME_CB(func)
Definition: codec_internal.h:355
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1630
APVDerivedTileInfo::col_starts
uint16_t col_starts[APV_MAX_TILE_COLS+1]
Definition: apv_decode.c:45
APVRawMetadataMDCV
Definition: cbs_apv.h:133
APV_MAX_TILE_ROWS
@ APV_MAX_TILE_ROWS
Definition: apv.h:76
APVDecodeContext::warned_additional_frames
uint8_t warned_additional_frames
Definition: apv_decode.c:62
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
APV_PBU_NON_PRIMARY_FRAME
@ APV_PBU_NON_PRIMARY_FRAME
Definition: apv.h:28
desc
const char * desc
Definition: libsvtav1.c:82
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
apv_decompose_unit_types
static const CodedBitstreamUnitType apv_decompose_unit_types[]
Definition: apv_decode.c:122
mastering_display_metadata.h
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
APVDecodeContext::cbc
CodedBitstreamContext * cbc
Definition: apv_decode.c:50
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
APV_PBU_ACCESS_UNIT_INFORMATION
@ APV_PBU_ACCESS_UNIT_INFORMATION
Definition: apv.h:32
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
AVPacket
This structure stores compressed data.
Definition: packet.h:565
CodedBitstreamContext::nb_decompose_unit_types
int nb_decompose_unit_types
Length of the decompose_unit_types array.
Definition: cbs.h:259
CodedBitstreamContext::decompose_unit_types
const CodedBitstreamUnitType * decompose_unit_types
Array of unit types which should be decomposed when reading.
Definition: cbs.h:255
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:472
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
apv_decode_metadata
static int apv_decode_metadata(AVCodecContext *avctx, AVFrame *frame, const APVRawMetadata *md)
Definition: apv_decode.c:401
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:549
ff_apv_entropy_decode_block
int ff_apv_entropy_decode_block(int16_t *restrict coeff, GetBitContext *restrict gbc, APVEntropyState *restrict state)
Entropy decode a single 8x8 block to coefficients.
Definition: apv_entropy.c:208
APVRawMetadataMDCV::min_mastering_luminance
uint32_t min_mastering_luminance
Definition: cbs_apv.h:139
atomic_init
#define atomic_init(obj, value)
Definition: stdatomic.h:33
APVDerivedTileInfo::num_tiles
uint16_t num_tiles
Definition: apv_decode.c:42
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:520
APVRawTile
Definition: cbs_apv.h:93
cbs_apv.h
AVCodecContext::execute2
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1622
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:624
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:160
APVDSPContext::decode_transquant
void(* decode_transquant)(void *output, ptrdiff_t pitch, const int16_t *input, const int16_t *qmatrix, int bit_depth, int qp_shift)
Definition: apv_dsp.h:27