FFmpeg
av1.c
Go to the documentation of this file.
1 /*
2  * AV1 helper functions for muxers
3  * Copyright (c) 2018 James Almer <jamrial@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/mem.h"
24 #include "libavcodec/av1.h"
25 #include "libavcodec/av1_parse.h"
26 #include "libavcodec/profiles.h"
27 #include "libavcodec/put_bits.h"
28 #include "av1.h"
29 #include "avio.h"
30 #include "avio_internal.h"
31 
32 static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf,
33  int size, int *offset)
34 {
35  const uint8_t *start = buf, *end = buf + size;
36  int64_t obu_size;
37  int off, start_pos, type, temporal_id, spatial_id;
38  enum {
39  START_NOT_FOUND,
40  START_FOUND,
41  END_FOUND,
42  OFFSET_IMPOSSIBLE,
43  } state = START_NOT_FOUND;
44 
45  off = size = 0;
46  while (buf < end) {
47  int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
48  &type, &temporal_id, &spatial_id);
49  if (len < 0)
50  return len;
51 
52  switch (type) {
55  case AV1_OBU_TILE_LIST:
56  case AV1_OBU_PADDING:
57  if (state == START_FOUND)
58  state = END_FOUND;
59  break;
60  default:
61  if (state == START_NOT_FOUND) {
62  off = buf - start;
63  state = START_FOUND;
64  } else if (state == END_FOUND) {
65  state = OFFSET_IMPOSSIBLE;
66  }
67  if (pb)
68  avio_write(pb, buf, len);
69  size += len;
70  break;
71  }
72  buf += len;
73  }
74 
75  if (offset)
76  *offset = state != OFFSET_IMPOSSIBLE ? off : -1;
77 
78  return size;
79 }
80 
81 int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
82 {
83  return av1_filter_obus(pb, buf, size, NULL);
84 }
85 
87  int *size, int *offset)
88 {
89  AVIOContext pb;
90  uint8_t *buf;
91  int len, off, ret;
92 
93  len = ret = av1_filter_obus(NULL, in, *size, &off);
94  if (ret < 0) {
95  return ret;
96  }
97  if (off >= 0) {
98  *out = (uint8_t *)in;
99  *size = len;
100  *offset = off;
101 
102  return 0;
103  }
104 
106  if (!buf)
107  return AVERROR(ENOMEM);
108 
109  ffio_init_context(&pb, buf, len, 1, NULL, NULL, NULL, NULL);
110 
111  ret = av1_filter_obus(&pb, in, *size, NULL);
112  av_assert1(ret == len);
113 
114  memset(buf + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
115 
116  *out = buf;
117  *size = len;
118  *offset = 0;
119 
120  return 0;
121 }
122 
123 static inline void uvlc(GetBitContext *gb)
124 {
125  int leading_zeros = 0;
126 
127  while (get_bits_left(gb)) {
128  if (get_bits1(gb))
129  break;
130  leading_zeros++;
131  }
132 
133  if (leading_zeros >= 32)
134  return;
135 
136  skip_bits_long(gb, leading_zeros);
137 }
138 
140 {
141  int twelve_bit = 0;
142  int high_bitdepth = get_bits1(gb);
143  if (seq_params->profile == FF_PROFILE_AV1_PROFESSIONAL && high_bitdepth)
144  twelve_bit = get_bits1(gb);
145 
146  seq_params->bitdepth = 8 + (high_bitdepth * 2) + (twelve_bit * 2);
147 
148  if (seq_params->profile == FF_PROFILE_AV1_HIGH)
149  seq_params->monochrome = 0;
150  else
151  seq_params->monochrome = get_bits1(gb);
152 
153  seq_params->color_description_present_flag = get_bits1(gb);
154  if (seq_params->color_description_present_flag) {
155  seq_params->color_primaries = get_bits(gb, 8);
156  seq_params->transfer_characteristics = get_bits(gb, 8);
157  seq_params->matrix_coefficients = get_bits(gb, 8);
158  } else {
162  }
163 
164  if (seq_params->monochrome) {
165  seq_params->color_range = get_bits1(gb);
166  seq_params->chroma_subsampling_x = 1;
167  seq_params->chroma_subsampling_y = 1;
168  seq_params->chroma_sample_position = 0;
169  return 0;
170  } else if (seq_params->color_primaries == AVCOL_PRI_BT709 &&
172  seq_params->matrix_coefficients == AVCOL_SPC_RGB) {
173  seq_params->chroma_subsampling_x = 0;
174  seq_params->chroma_subsampling_y = 0;
175  } else {
176  seq_params->color_range = get_bits1(gb);
177 
178  if (seq_params->profile == FF_PROFILE_AV1_MAIN) {
179  seq_params->chroma_subsampling_x = 1;
180  seq_params->chroma_subsampling_y = 1;
181  } else if (seq_params->profile == FF_PROFILE_AV1_HIGH) {
182  seq_params->chroma_subsampling_x = 0;
183  seq_params->chroma_subsampling_y = 0;
184  } else {
185  if (twelve_bit) {
186  seq_params->chroma_subsampling_x = get_bits1(gb);
187  if (seq_params->chroma_subsampling_x)
188  seq_params->chroma_subsampling_y = get_bits1(gb);
189  else
190  seq_params->chroma_subsampling_y = 0;
191  } else {
192  seq_params->chroma_subsampling_x = 1;
193  seq_params->chroma_subsampling_y = 0;
194  }
195  }
196  if (seq_params->chroma_subsampling_x && seq_params->chroma_subsampling_y)
197  seq_params->chroma_sample_position = get_bits(gb, 2);
198  }
199 
200  skip_bits1(gb); // separate_uv_delta_q
201 
202  return 0;
203 }
204 
205 static int parse_sequence_header(AV1SequenceParameters *seq_params, const uint8_t *buf, int size)
206 {
207  GetBitContext gb;
208  int reduced_still_picture_header;
209  int frame_width_bits_minus_1, frame_height_bits_minus_1;
210  int size_bits, ret;
211 
213  if (size_bits < 0)
214  return size_bits;
215 
216  ret = init_get_bits(&gb, buf, size_bits);
217  if (ret < 0)
218  return ret;
219 
220  memset(seq_params, 0, sizeof(*seq_params));
221 
222  seq_params->profile = get_bits(&gb, 3);
223 
224  skip_bits1(&gb); // still_picture
225  reduced_still_picture_header = get_bits1(&gb);
226 
227  if (reduced_still_picture_header) {
228  seq_params->level = get_bits(&gb, 5);
229  seq_params->tier = 0;
230  } else {
231  int initial_display_delay_present_flag, operating_points_cnt_minus_1;
232  int decoder_model_info_present_flag, buffer_delay_length_minus_1;
233 
234  if (get_bits1(&gb)) { // timing_info_present_flag
235  skip_bits_long(&gb, 32); // num_units_in_display_tick
236  skip_bits_long(&gb, 32); // time_scale
237 
238  if (get_bits1(&gb)) // equal_picture_interval
239  uvlc(&gb); // num_ticks_per_picture_minus_1
240 
241  decoder_model_info_present_flag = get_bits1(&gb);
242  if (decoder_model_info_present_flag) {
243  buffer_delay_length_minus_1 = get_bits(&gb, 5);
244  skip_bits_long(&gb, 32); // num_units_in_decoding_tick
245  skip_bits(&gb, 10); // buffer_removal_time_length_minus_1 (5)
246  // frame_presentation_time_length_minus_1 (5)
247  }
248  } else
249  decoder_model_info_present_flag = 0;
250 
251  initial_display_delay_present_flag = get_bits1(&gb);
252 
253  operating_points_cnt_minus_1 = get_bits(&gb, 5);
254  for (int i = 0; i <= operating_points_cnt_minus_1; i++) {
255  int seq_level_idx, seq_tier;
256 
257  skip_bits(&gb, 12); // operating_point_idc
258  seq_level_idx = get_bits(&gb, 5);
259 
260  if (seq_level_idx > 7)
261  seq_tier = get_bits1(&gb);
262  else
263  seq_tier = 0;
264 
265  if (decoder_model_info_present_flag) {
266  if (get_bits1(&gb)) { // decoder_model_present_for_this_op
267  skip_bits_long(&gb, buffer_delay_length_minus_1 + 1); // decoder_buffer_delay
268  skip_bits_long(&gb, buffer_delay_length_minus_1 + 1); // encoder_buffer_delay
269  skip_bits1(&gb); // low_delay_mode_flag
270  }
271  }
272 
273  if (initial_display_delay_present_flag) {
274  if (get_bits1(&gb)) // initial_display_delay_present_for_this_op
275  skip_bits(&gb, 4); // initial_display_delay_minus_1
276  }
277 
278  if (i == 0) {
279  seq_params->level = seq_level_idx;
280  seq_params->tier = seq_tier;
281  }
282  }
283  }
284 
285  frame_width_bits_minus_1 = get_bits(&gb, 4);
286  frame_height_bits_minus_1 = get_bits(&gb, 4);
287 
288  skip_bits(&gb, frame_width_bits_minus_1 + 1); // max_frame_width_minus_1
289  skip_bits(&gb, frame_height_bits_minus_1 + 1); // max_frame_height_minus_1
290 
291  if (!reduced_still_picture_header) {
292  if (get_bits1(&gb)) // frame_id_numbers_present_flag
293  skip_bits(&gb, 7); // delta_frame_id_length_minus_2 (4), additional_frame_id_length_minus_1 (3)
294  }
295 
296  skip_bits(&gb, 3); // use_128x128_superblock (1), enable_filter_intra (1), enable_intra_edge_filter (1)
297 
298  if (!reduced_still_picture_header) {
299  int enable_order_hint, seq_force_screen_content_tools;
300 
301  skip_bits(&gb, 4); // enable_interintra_compound (1), enable_masked_compound (1)
302  // enable_warped_motion (1), enable_dual_filter (1)
303 
304  enable_order_hint = get_bits1(&gb);
305  if (enable_order_hint)
306  skip_bits(&gb, 2); // enable_jnt_comp (1), enable_ref_frame_mvs (1)
307 
308  if (get_bits1(&gb)) // seq_choose_screen_content_tools
309  seq_force_screen_content_tools = 2;
310  else
311  seq_force_screen_content_tools = get_bits1(&gb);
312 
313  if (seq_force_screen_content_tools) {
314  if (!get_bits1(&gb)) // seq_choose_integer_mv
315  skip_bits1(&gb); // seq_force_integer_mv
316  }
317 
318  if (enable_order_hint)
319  skip_bits(&gb, 3); // order_hint_bits_minus_1
320  }
321 
322  skip_bits(&gb, 3); // enable_superres (1), enable_cdef (1), enable_restoration (1)
323 
324  parse_color_config(seq_params, &gb);
325 
326  skip_bits1(&gb); // film_grain_params_present
327 
328  if (get_bits_left(&gb))
329  return AVERROR_INVALIDDATA;
330 
331  return 0;
332 }
333 
335 {
336  int64_t obu_size;
337  int start_pos, type, temporal_id, spatial_id;
338 
339  if (size <= 0)
340  return AVERROR_INVALIDDATA;
341 
342  while (size > 0) {
343  int len = parse_obu_header(buf, size, &obu_size, &start_pos,
344  &type, &temporal_id, &spatial_id);
345  if (len < 0)
346  return len;
347 
348  switch (type) {
350  if (!obu_size)
351  return AVERROR_INVALIDDATA;
352 
353  return parse_sequence_header(seq, buf + start_pos, obu_size);
354  default:
355  break;
356  }
357  size -= len;
358  buf += len;
359  }
360 
361  return AVERROR_INVALIDDATA;
362 }
363 
364 int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
365 {
366  AVIOContext *seq_pb = NULL, *meta_pb = NULL;
367  AV1SequenceParameters seq_params;
368  PutBitContext pbc;
369  uint8_t header[4];
370  uint8_t *seq, *meta;
371  int64_t obu_size;
372  int start_pos, type, temporal_id, spatial_id;
373  int ret, nb_seq = 0, seq_size, meta_size;
374 
375  if (size <= 0)
376  return AVERROR_INVALIDDATA;
377 
378  ret = avio_open_dyn_buf(&seq_pb);
379  if (ret < 0)
380  return ret;
381  ret = avio_open_dyn_buf(&meta_pb);
382  if (ret < 0)
383  goto fail;
384 
385  while (size > 0) {
386  int len = parse_obu_header(buf, size, &obu_size, &start_pos,
387  &type, &temporal_id, &spatial_id);
388  if (len < 0) {
389  ret = len;
390  goto fail;
391  }
392 
393  switch (type) {
395  nb_seq++;
396  if (!obu_size || nb_seq > 1) {
398  goto fail;
399  }
400  ret = parse_sequence_header(&seq_params, buf + start_pos, obu_size);
401  if (ret < 0)
402  goto fail;
403 
404  avio_write(seq_pb, buf, len);
405  break;
406  case AV1_OBU_METADATA:
407  if (!obu_size) {
409  goto fail;
410  }
411  avio_write(meta_pb, buf, len);
412  break;
413  default:
414  break;
415  }
416  size -= len;
417  buf += len;
418  }
419 
420  seq_size = avio_get_dyn_buf(seq_pb, &seq);
421  if (!seq_size) {
423  goto fail;
424  }
425 
426  init_put_bits(&pbc, header, sizeof(header));
427 
428  put_bits(&pbc, 1, 1); // marker
429  put_bits(&pbc, 7, 1); // version
430  put_bits(&pbc, 3, seq_params.profile);
431  put_bits(&pbc, 5, seq_params.level);
432  put_bits(&pbc, 1, seq_params.tier);
433  put_bits(&pbc, 1, seq_params.bitdepth > 8);
434  put_bits(&pbc, 1, seq_params.bitdepth == 12);
435  put_bits(&pbc, 1, seq_params.monochrome);
436  put_bits(&pbc, 1, seq_params.chroma_subsampling_x);
437  put_bits(&pbc, 1, seq_params.chroma_subsampling_y);
438  put_bits(&pbc, 2, seq_params.chroma_sample_position);
439  put_bits(&pbc, 8, 0); // padding
440  flush_put_bits(&pbc);
441 
442  avio_write(pb, header, sizeof(header));
443  avio_write(pb, seq, seq_size);
444 
445  meta_size = avio_get_dyn_buf(meta_pb, &meta);
446  if (meta_size)
447  avio_write(pb, meta, meta_size);
448 
449 fail:
450  ffio_free_dyn_buf(&seq_pb);
451  ffio_free_dyn_buf(&meta_pb);
452 
453  return ret;
454 }
parse_sequence_header
static int parse_sequence_header(AV1SequenceParameters *seq_params, const uint8_t *buf, int size)
Definition: av1.c:205
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
AV1_OBU_REDUNDANT_FRAME_HEADER
@ AV1_OBU_REDUNDANT_FRAME_HEADER
Definition: av1.h:36
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
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
out
FILE * out
Definition: movenc.c:54
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:208
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:483
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:510
ff_isom_write_av1c
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
Definition: av1.c:364
AV1_OBU_TEMPORAL_DELIMITER
@ AV1_OBU_TEMPORAL_DELIMITER
Definition: av1.h:31
avio_get_dyn_buf
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1368
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
AV1SequenceParameters::chroma_subsampling_y
uint8_t chroma_subsampling_y
Definition: av1.h:35
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
av1_filter_obus
static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size, int *offset)
Definition: av1.c:32
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
av1_parse.h
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:494
fail
#define fail()
Definition: checkasm.h:123
GetBitContext
Definition: get_bits.h:61
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV1SequenceParameters::color_description_present_flag
uint8_t color_description_present_flag
Definition: av1.h:37
avassert.h
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1356
parse_obu_header
static int parse_obu_header(const uint8_t *buf, int buf_size, int64_t *obu_size, int *start_pos, int *type, int *temporal_id, int *spatial_id)
Definition: av1_parse.h:100
ff_av1_filter_obus_buf
int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size, int *offset)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and return the result in a data bu...
Definition: av1.c:86
AV1SequenceParameters::color_range
uint8_t color_range
Definition: av1.h:41
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:458
PutBitContext
Definition: put_bits.h:35
AV1SequenceParameters::chroma_sample_position
uint8_t chroma_sample_position
Definition: av1.h:36
uvlc
static void uvlc(GetBitContext *gb)
Definition: av1.c:123
NULL
#define NULL
Definition: coverity.c:32
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:457
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
AV1SequenceParameters::transfer_characteristics
uint8_t transfer_characteristics
Definition: av1.h:39
profiles.h
AV1SequenceParameters::tier
uint8_t tier
Definition: av1.h:31
AV1SequenceParameters::monochrome
uint8_t monochrome
Definition: av1.h:33
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
ffio_init_context
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:76
FF_PROFILE_AV1_MAIN
#define FF_PROFILE_AV1_MAIN
Definition: avcodec.h:1952
AV1SequenceParameters::matrix_coefficients
uint8_t matrix_coefficients
Definition: av1.h:40
get_obu_bit_length
static int get_obu_bit_length(const uint8_t *buf, int size, int type)
Definition: av1_parse.h:144
size
int size
Definition: twinvq_data.h:11134
state
static struct @314 state
avio.h
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
av1.h
header
static const uint8_t header[24]
Definition: sdr2.c:67
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:213
parse_color_config
static int parse_color_config(AV1SequenceParameters *seq_params, GetBitContext *gb)
Definition: av1.c:139
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
AV1SequenceParameters::profile
uint8_t profile
Definition: av1.h:29
AV1SequenceParameters::color_primaries
uint8_t color_primaries
Definition: av1.h:38
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
AV1_OBU_PADDING
@ AV1_OBU_PADDING
Definition: av1.h:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
avio_internal.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
AV1SequenceParameters::level
uint8_t level
Definition: av1.h:30
uint8_t
uint8_t
Definition: audio_convert.c:194
len
int len
Definition: vorbis_enc_data.h:452
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:512
FF_PROFILE_AV1_PROFESSIONAL
#define FF_PROFILE_AV1_PROFESSIONAL
Definition: avcodec.h:1954
ff_av1_parse_seq_header
int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, int size)
Parses a Sequence Header from the the provided buffer.
Definition: av1.c:334
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1431
ret
ret
Definition: filter_design.txt:187
AV1_OBU_TILE_LIST
@ AV1_OBU_TILE_LIST
Definition: av1.h:37
ff_av1_filter_obus
int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and write the resulting bitstream ...
Definition: av1.c:81
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
AV1SequenceParameters::chroma_subsampling_x
uint8_t chroma_subsampling_x
Definition: av1.h:34
mem.h
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AV1SequenceParameters::bitdepth
uint8_t bitdepth
Definition: av1.h:32
FF_PROFILE_AV1_HIGH
#define FF_PROFILE_AV1_HIGH
Definition: avcodec.h:1953
AV1SequenceParameters
Definition: av1.h:28
put_bits.h
AV1_OBU_METADATA
@ AV1_OBU_METADATA
Definition: av1.h:34