Source code
Revision control
Copy as Markdown
Other Tools
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
static int FUNC(obu_header)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawOBUHeader *current)
{
CodedBitstreamAV1Context *priv = ctx->priv_data;
int err;
HEADER("OBU header");
fc(1, obu_forbidden_bit, 0, 0);
fc(4, obu_type, 0, AV1_OBU_PADDING);
flag(obu_extension_flag);
flag(obu_has_size_field);
fc(1, obu_reserved_1bit, 0, 0);
if (current->obu_extension_flag) {
fb(3, temporal_id);
fb(2, spatial_id);
fc(3, extension_header_reserved_3bits, 0, 0);
} else {
infer(temporal_id, 0);
infer(spatial_id, 0);
}
priv->temporal_id = current->temporal_id;
priv->spatial_id = current->spatial_id;
return 0;
}
static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
{
int err;
av_assert0(nb_bits > 0);
fixed(1, trailing_one_bit, 1);
--nb_bits;
while (nb_bits > 0) {
fixed(1, trailing_zero_bit, 0);
--nb_bits;
}
return 0;
}
static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
{
int err;
while (byte_alignment(rw) != 0)
fixed(1, zero_bit, 0);
return 0;
}
static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawColorConfig *current, int seq_profile)
{
CodedBitstreamAV1Context *priv = ctx->priv_data;
int err;
flag(high_bitdepth);
if (seq_profile == AV_PROFILE_AV1_PROFESSIONAL &&
current->high_bitdepth) {
flag(twelve_bit);
priv->bit_depth = current->twelve_bit ? 12 : 10;
} else {
priv->bit_depth = current->high_bitdepth ? 10 : 8;
}
if (seq_profile == AV_PROFILE_AV1_HIGH)
infer(mono_chrome, 0);
else
flag(mono_chrome);
priv->num_planes = current->mono_chrome ? 1 : 3;
flag(color_description_present_flag);
if (current->color_description_present_flag) {
fb(8, color_primaries);
fb(8, transfer_characteristics);
fb(8, matrix_coefficients);
} else {
infer(color_primaries, AVCOL_PRI_UNSPECIFIED);
infer(transfer_characteristics, AVCOL_TRC_UNSPECIFIED);
infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED);
}
if (current->mono_chrome) {
flag(color_range);
infer(subsampling_x, 1);
infer(subsampling_y, 1);
infer(chroma_sample_position, AV1_CSP_UNKNOWN);
infer(separate_uv_delta_q, 0);
} else if (current->color_primaries == AVCOL_PRI_BT709 &&
current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 &&
current->matrix_coefficients == AVCOL_SPC_RGB) {
infer(color_range, 1);
infer(subsampling_x, 0);
infer(subsampling_y, 0);
flag(separate_uv_delta_q);
} else {
flag(color_range);
if (seq_profile == AV_PROFILE_AV1_MAIN) {
infer(subsampling_x, 1);
infer(subsampling_y, 1);
} else if (seq_profile == AV_PROFILE_AV1_HIGH) {
infer(subsampling_x, 0);
infer(subsampling_y, 0);
} else {
if (priv->bit_depth == 12) {
fb(1, subsampling_x);
if (current->subsampling_x)
fb(1, subsampling_y);
else
infer(subsampling_y, 0);
} else {
infer(subsampling_x, 1);
infer(subsampling_y, 0);
}
}
if (current->subsampling_x && current->subsampling_y) {
fc(2, chroma_sample_position, AV1_CSP_UNKNOWN,
AV1_CSP_COLOCATED);
}
flag(separate_uv_delta_q);
}
return 0;
}
static int FUNC(timing_info)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawTimingInfo *current)
{
int err;
fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32));
fc(32, time_scale, 1, MAX_UINT_BITS(32));
flag(equal_picture_interval);
if (current->equal_picture_interval)
uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1);
return 0;
}
static int FUNC(decoder_model_info)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawDecoderModelInfo *current)
{
int err;
fb(5, buffer_delay_length_minus_1);
fc(32, num_units_in_decoding_tick, 1, MAX_UINT_BITS(32));
fb(5, buffer_removal_time_length_minus_1);
fb(5, frame_presentation_time_length_minus_1);
return 0;
}
static int FUNC(sequence_header_obu)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawSequenceHeader *current)
{
int i, err;
HEADER("Sequence Header");
fc(3, seq_profile, AV_PROFILE_AV1_MAIN,
AV_PROFILE_AV1_PROFESSIONAL);
flag(still_picture);
flag(reduced_still_picture_header);
if (current->reduced_still_picture_header) {
infer(timing_info_present_flag, 0);
infer(decoder_model_info_present_flag, 0);
infer(initial_display_delay_present_flag, 0);
infer(operating_points_cnt_minus_1, 0);
infer(operating_point_idc[0], 0);
fb(5, seq_level_idx[0]);
infer(seq_tier[0], 0);
infer(decoder_model_present_for_this_op[0], 0);
infer(initial_display_delay_present_for_this_op[0], 0);
} else {
flag(timing_info_present_flag);
if (current->timing_info_present_flag) {
CHECK(FUNC(timing_info)(ctx, rw, ¤t->timing_info));
flag(decoder_model_info_present_flag);
if (current->decoder_model_info_present_flag) {
CHECK(FUNC(decoder_model_info)
(ctx, rw, ¤t->decoder_model_info));
}
} else {
infer(decoder_model_info_present_flag, 0);
}
flag(initial_display_delay_present_flag);
fb(5, operating_points_cnt_minus_1);
for (i = 0; i <= current->operating_points_cnt_minus_1; i++) {
fbs(12, operating_point_idc[i], 1, i);
fbs(5, seq_level_idx[i], 1, i);
if (current->seq_level_idx[i] > 7)
flags(seq_tier[i], 1, i);
else
infer(seq_tier[i], 0);
if (current->decoder_model_info_present_flag) {
flags(decoder_model_present_for_this_op[i], 1, i);
if (current->decoder_model_present_for_this_op[i]) {
int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1;
fbs(n, decoder_buffer_delay[i], 1, i);
fbs(n, encoder_buffer_delay[i], 1, i);
flags(low_delay_mode_flag[i], 1, i);
}
} else {
infer(decoder_model_present_for_this_op[i], 0);
}
if (current->initial_display_delay_present_flag) {
flags(initial_display_delay_present_for_this_op[i], 1, i);
if (current->initial_display_delay_present_for_this_op[i])
fbs(4, initial_display_delay_minus_1[i], 1, i);
}
}
}
fb(4, frame_width_bits_minus_1);
fb(4, frame_height_bits_minus_1);
fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1);
fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1);
if (current->reduced_still_picture_header)
infer(frame_id_numbers_present_flag, 0);
else
flag(frame_id_numbers_present_flag);
if (current->frame_id_numbers_present_flag) {
fb(4, delta_frame_id_length_minus_2);
fb(3, additional_frame_id_length_minus_1);
}
flag(use_128x128_superblock);