2018-07-07 21:35:32 +02:00
|
|
|
/*
|
|
|
|
* AV1 helper functions for muxers
|
|
|
|
* Copyright (c) 2018 James Almer <jamrial@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-01-23 18:08:32 +02:00
|
|
|
#include "libavutil/avassert.h"
|
2018-07-07 21:35:32 +02:00
|
|
|
#include "libavutil/mem.h"
|
|
|
|
#include "libavcodec/av1.h"
|
|
|
|
#include "libavcodec/av1_parse.h"
|
2018-08-16 23:01:44 +02:00
|
|
|
#include "libavcodec/profiles.h"
|
|
|
|
#include "libavcodec/put_bits.h"
|
2018-07-07 21:35:32 +02:00
|
|
|
#include "av1.h"
|
|
|
|
#include "avio.h"
|
2019-11-21 08:17:19 +02:00
|
|
|
#include "avio_internal.h"
|
2018-07-07 21:35:32 +02:00
|
|
|
|
2020-01-25 00:48:33 +02:00
|
|
|
static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf,
|
|
|
|
int size, int *offset)
|
2018-07-07 21:35:32 +02:00
|
|
|
{
|
2020-01-25 00:48:33 +02:00
|
|
|
const uint8_t *start = buf, *end = buf + size;
|
2018-07-07 21:35:32 +02:00
|
|
|
int64_t obu_size;
|
2020-01-25 00:48:33 +02:00
|
|
|
int off, start_pos, type, temporal_id, spatial_id;
|
|
|
|
enum {
|
|
|
|
START_NOT_FOUND,
|
|
|
|
START_FOUND,
|
|
|
|
END_FOUND,
|
|
|
|
OFFSET_IMPOSSIBLE,
|
|
|
|
} state = START_NOT_FOUND;
|
|
|
|
|
|
|
|
off = size = 0;
|
2018-07-07 21:35:32 +02:00
|
|
|
while (buf < end) {
|
2018-07-30 20:14:24 +02:00
|
|
|
int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
|
2018-07-07 21:35:32 +02:00
|
|
|
&type, &temporal_id, &spatial_id);
|
2018-07-30 20:14:24 +02:00
|
|
|
if (len < 0)
|
|
|
|
return len;
|
2018-07-07 21:35:32 +02:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case AV1_OBU_TEMPORAL_DELIMITER:
|
|
|
|
case AV1_OBU_REDUNDANT_FRAME_HEADER:
|
2018-08-17 20:26:05 +02:00
|
|
|
case AV1_OBU_TILE_LIST:
|
2018-07-07 21:35:32 +02:00
|
|
|
case AV1_OBU_PADDING:
|
2020-01-25 00:48:33 +02:00
|
|
|
if (state == START_FOUND)
|
|
|
|
state = END_FOUND;
|
2018-07-07 21:35:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-01-25 00:48:33 +02:00
|
|
|
if (state == START_NOT_FOUND) {
|
|
|
|
off = buf - start;
|
|
|
|
state = START_FOUND;
|
|
|
|
} else if (state == END_FOUND) {
|
|
|
|
state = OFFSET_IMPOSSIBLE;
|
|
|
|
}
|
2020-01-23 18:08:32 +02:00
|
|
|
if (pb)
|
|
|
|
avio_write(pb, buf, len);
|
2018-07-30 20:14:24 +02:00
|
|
|
size += len;
|
2018-07-07 21:35:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-07-30 20:14:24 +02:00
|
|
|
buf += len;
|
2018-07-07 21:35:32 +02:00
|
|
|
}
|
|
|
|
|
2020-01-25 00:48:33 +02:00
|
|
|
if (offset)
|
|
|
|
*offset = state != OFFSET_IMPOSSIBLE ? off : -1;
|
|
|
|
|
2018-07-07 21:35:32 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-01-25 00:48:33 +02:00
|
|
|
int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
return av1_filter_obus(pb, buf, size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out,
|
|
|
|
int *size, int *offset)
|
2018-07-07 21:35:32 +02:00
|
|
|
{
|
2020-01-23 18:08:32 +02:00
|
|
|
AVIOContext pb;
|
|
|
|
uint8_t *buf;
|
2020-01-25 00:48:33 +02:00
|
|
|
int len, off, ret;
|
2018-07-07 21:35:32 +02:00
|
|
|
|
2020-01-25 00:48:33 +02:00
|
|
|
len = ret = av1_filter_obus(NULL, in, *size, &off);
|
2019-11-21 08:17:19 +02:00
|
|
|
if (ret < 0) {
|
2018-07-07 21:35:32 +02:00
|
|
|
return ret;
|
2019-11-21 08:17:19 +02:00
|
|
|
}
|
2020-01-25 00:48:33 +02:00
|
|
|
if (off >= 0) {
|
|
|
|
*out = (uint8_t *)in;
|
|
|
|
*size = len;
|
|
|
|
*offset = off;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-07 21:35:32 +02:00
|
|
|
|
2020-01-23 18:08:32 +02:00
|
|
|
buf = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!buf)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
ffio_init_context(&pb, buf, len, 1, NULL, NULL, NULL, NULL);
|
|
|
|
|
2020-01-25 00:48:33 +02:00
|
|
|
ret = av1_filter_obus(&pb, in, *size, NULL);
|
2020-01-23 18:08:32 +02:00
|
|
|
av_assert1(ret == len);
|
|
|
|
|
|
|
|
memset(buf + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
|
|
|
|
*out = buf;
|
|
|
|
*size = len;
|
2020-01-25 00:48:33 +02:00
|
|
|
*offset = 0;
|
2018-07-07 21:35:32 +02:00
|
|
|
|
2020-01-23 18:08:30 +02:00
|
|
|
return 0;
|
2018-07-07 21:35:32 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 23:01:44 +02:00
|
|
|
static inline void uvlc(GetBitContext *gb)
|
|
|
|
{
|
|
|
|
int leading_zeros = 0;
|
|
|
|
|
|
|
|
while (get_bits_left(gb)) {
|
|
|
|
if (get_bits1(gb))
|
|
|
|
break;
|
|
|
|
leading_zeros++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leading_zeros >= 32)
|
|
|
|
return;
|
|
|
|
|
|
|
|
skip_bits_long(gb, leading_zeros);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_color_config(AV1SequenceParameters *seq_params, GetBitContext *gb)
|
|
|
|
{
|
2019-07-30 16:55:26 +02:00
|
|
|
int twelve_bit = 0;
|
|
|
|
int high_bitdepth = get_bits1(gb);
|
|
|
|
if (seq_params->profile == FF_PROFILE_AV1_PROFESSIONAL && high_bitdepth)
|
|
|
|
twelve_bit = get_bits1(gb);
|
|
|
|
|
|
|
|
seq_params->bitdepth = 8 + (high_bitdepth * 2) + (twelve_bit * 2);
|
2018-08-16 23:01:44 +02:00
|
|
|
|
2019-07-30 16:48:38 +02:00
|
|
|
if (seq_params->profile == FF_PROFILE_AV1_HIGH)
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->monochrome = 0;
|
|
|
|
else
|
|
|
|
seq_params->monochrome = get_bits1(gb);
|
|
|
|
|
2019-07-30 16:43:02 +02:00
|
|
|
seq_params->color_description_present_flag = get_bits1(gb);
|
|
|
|
if (seq_params->color_description_present_flag) {
|
|
|
|
seq_params->color_primaries = get_bits(gb, 8);
|
|
|
|
seq_params->transfer_characteristics = get_bits(gb, 8);
|
|
|
|
seq_params->matrix_coefficients = get_bits(gb, 8);
|
2018-08-16 23:01:44 +02:00
|
|
|
} else {
|
2019-07-30 16:43:02 +02:00
|
|
|
seq_params->color_primaries = AVCOL_PRI_UNSPECIFIED;
|
|
|
|
seq_params->transfer_characteristics = AVCOL_TRC_UNSPECIFIED;
|
|
|
|
seq_params->matrix_coefficients = AVCOL_SPC_UNSPECIFIED;
|
2018-08-16 23:01:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (seq_params->monochrome) {
|
2019-07-30 16:43:02 +02:00
|
|
|
seq_params->color_range = get_bits1(gb);
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->chroma_subsampling_x = 1;
|
|
|
|
seq_params->chroma_subsampling_y = 1;
|
|
|
|
seq_params->chroma_sample_position = 0;
|
|
|
|
return 0;
|
2019-07-30 16:43:02 +02:00
|
|
|
} else if (seq_params->color_primaries == AVCOL_PRI_BT709 &&
|
|
|
|
seq_params->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 &&
|
|
|
|
seq_params->matrix_coefficients == AVCOL_SPC_RGB) {
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->chroma_subsampling_x = 0;
|
|
|
|
seq_params->chroma_subsampling_y = 0;
|
|
|
|
} else {
|
2019-07-30 16:43:02 +02:00
|
|
|
seq_params->color_range = get_bits1(gb);
|
2018-08-16 23:01:44 +02:00
|
|
|
|
2019-07-30 16:48:38 +02:00
|
|
|
if (seq_params->profile == FF_PROFILE_AV1_MAIN) {
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->chroma_subsampling_x = 1;
|
|
|
|
seq_params->chroma_subsampling_y = 1;
|
2019-07-30 16:48:38 +02:00
|
|
|
} else if (seq_params->profile == FF_PROFILE_AV1_HIGH) {
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->chroma_subsampling_x = 0;
|
|
|
|
seq_params->chroma_subsampling_y = 0;
|
|
|
|
} else {
|
2019-07-30 16:55:26 +02:00
|
|
|
if (twelve_bit) {
|
2018-08-16 23:01:44 +02:00
|
|
|
seq_params->chroma_subsampling_x = get_bits1(gb);
|
|
|
|
if (seq_params->chroma_subsampling_x)
|
|
|
|
seq_params->chroma_subsampling_y = get_bits1(gb);
|
|
|
|
else
|
|
|
|
seq_params->chroma_subsampling_y = 0;
|
|
|
|
} else {
|
|
|
|
seq_params->chroma_subsampling_x = 1;
|
|
|
|
seq_params->chroma_subsampling_y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seq_params->chroma_subsampling_x && seq_params->chroma_subsampling_y)
|
|
|
|
seq_params->chroma_sample_position = get_bits(gb, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_bits1(gb); // separate_uv_delta_q
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_sequence_header(AV1SequenceParameters *seq_params, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
GetBitContext gb;
|
|
|
|
int reduced_still_picture_header;
|
|
|
|
int frame_width_bits_minus_1, frame_height_bits_minus_1;
|
|
|
|
int size_bits, ret;
|
|
|
|
|
|
|
|
size_bits = get_obu_bit_length(buf, size, AV1_OBU_SEQUENCE_HEADER);
|
|
|
|
if (size_bits < 0)
|
|
|
|
return size_bits;
|
|
|
|
|
|
|
|
ret = init_get_bits(&gb, buf, size_bits);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2018-09-03 04:27:51 +02:00
|
|
|
memset(seq_params, 0, sizeof(*seq_params));
|
|
|
|
|
2019-07-30 16:48:38 +02:00
|
|
|
seq_params->profile = get_bits(&gb, 3);
|
2018-08-16 23:01:44 +02:00
|
|
|
|
|
|
|
skip_bits1(&gb); // still_picture
|
|
|
|
reduced_still_picture_header = get_bits1(&gb);
|
|
|
|
|
|
|
|
if (reduced_still_picture_header) {
|
2019-07-30 16:48:38 +02:00
|
|
|
seq_params->level = get_bits(&gb, 5);
|
|
|
|
seq_params->tier = 0;
|
2018-08-16 23:01:44 +02:00
|
|
|
} else {
|
|
|
|
int initial_display_delay_present_flag, operating_points_cnt_minus_1;
|
|
|
|
int decoder_model_info_present_flag, buffer_delay_length_minus_1;
|
|
|
|
|
|
|
|
if (get_bits1(&gb)) { // timing_info_present_flag
|
|
|
|
skip_bits_long(&gb, 32); // num_units_in_display_tick
|
|
|
|
skip_bits_long(&gb, 32); // time_scale
|
|
|
|
|
|
|
|
if (get_bits1(&gb)) // equal_picture_interval
|
|
|
|
uvlc(&gb); // num_ticks_per_picture_minus_1
|
|
|
|
|
|
|
|
decoder_model_info_present_flag = get_bits1(&gb);
|
|
|
|
if (decoder_model_info_present_flag) {
|
|
|
|
buffer_delay_length_minus_1 = get_bits(&gb, 5);
|
|
|
|
skip_bits_long(&gb, 32); // num_units_in_decoding_tick
|
|
|
|
skip_bits(&gb, 10); // buffer_removal_time_length_minus_1 (5)
|
|
|
|
// frame_presentation_time_length_minus_1 (5)
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
decoder_model_info_present_flag = 0;
|
|
|
|
|
|
|
|
initial_display_delay_present_flag = get_bits1(&gb);
|
|
|
|
|
|
|
|
operating_points_cnt_minus_1 = get_bits(&gb, 5);
|
|
|
|
for (int i = 0; i <= operating_points_cnt_minus_1; i++) {
|
|
|
|
int seq_level_idx, seq_tier;
|
|
|
|
|
|
|
|
skip_bits(&gb, 12); // operating_point_idc
|
|
|
|
seq_level_idx = get_bits(&gb, 5);
|
|
|
|
|
|
|
|
if (seq_level_idx > 7)
|
|
|
|
seq_tier = get_bits1(&gb);
|
|
|
|
else
|
|
|
|
seq_tier = 0;
|
|
|
|
|
|
|
|
if (decoder_model_info_present_flag) {
|
|
|
|
if (get_bits1(&gb)) { // decoder_model_present_for_this_op
|
|
|
|
skip_bits_long(&gb, buffer_delay_length_minus_1 + 1); // decoder_buffer_delay
|
|
|
|
skip_bits_long(&gb, buffer_delay_length_minus_1 + 1); // encoder_buffer_delay
|
|
|
|
skip_bits1(&gb); // low_delay_mode_flag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initial_display_delay_present_flag) {
|
|
|
|
if (get_bits1(&gb)) // initial_display_delay_present_for_this_op
|
|
|
|
skip_bits(&gb, 4); // initial_display_delay_minus_1
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
2019-07-30 16:48:38 +02:00
|
|
|
seq_params->level = seq_level_idx;
|
|
|
|
seq_params->tier = seq_tier;
|
2018-08-16 23:01:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_width_bits_minus_1 = get_bits(&gb, 4);
|
|
|
|
frame_height_bits_minus_1 = get_bits(&gb, 4);
|
|
|
|
|
|
|
|
skip_bits(&gb, frame_width_bits_minus_1 + 1); // max_frame_width_minus_1
|
|
|
|
skip_bits(&gb, frame_height_bits_minus_1 + 1); // max_frame_height_minus_1
|
|
|
|
|
|
|
|
if (!reduced_still_picture_header) {
|
|
|
|
if (get_bits1(&gb)) // frame_id_numbers_present_flag
|
|
|
|
skip_bits(&gb, 7); // delta_frame_id_length_minus_2 (4), additional_frame_id_length_minus_1 (3)
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_bits(&gb, 3); // use_128x128_superblock (1), enable_filter_intra (1), enable_intra_edge_filter (1)
|
|
|
|
|
|
|
|
if (!reduced_still_picture_header) {
|
|
|
|
int enable_order_hint, seq_force_screen_content_tools;
|
|
|
|
|
2019-12-11 03:54:54 +02:00
|
|
|
skip_bits(&gb, 4); // enable_interintra_compound (1), enable_masked_compound (1)
|
2018-08-16 23:01:44 +02:00
|
|
|
// enable_warped_motion (1), enable_dual_filter (1)
|
|
|
|
|
|
|
|
enable_order_hint = get_bits1(&gb);
|
|
|
|
if (enable_order_hint)
|
|
|
|
skip_bits(&gb, 2); // enable_jnt_comp (1), enable_ref_frame_mvs (1)
|
|
|
|
|
|
|
|
if (get_bits1(&gb)) // seq_choose_screen_content_tools
|
|
|
|
seq_force_screen_content_tools = 2;
|
|
|
|
else
|
|
|
|
seq_force_screen_content_tools = get_bits1(&gb);
|
|
|
|
|
|
|
|
if (seq_force_screen_content_tools) {
|
|
|
|
if (!get_bits1(&gb)) // seq_choose_integer_mv
|
|
|
|
skip_bits1(&gb); // seq_force_integer_mv
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable_order_hint)
|
|
|
|
skip_bits(&gb, 3); // order_hint_bits_minus_1
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_bits(&gb, 3); // enable_superres (1), enable_cdef (1), enable_restoration (1)
|
|
|
|
|
|
|
|
parse_color_config(seq_params, &gb);
|
|
|
|
|
|
|
|
skip_bits1(&gb); // film_grain_params_present
|
|
|
|
|
|
|
|
if (get_bits_left(&gb))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-30 17:08:44 +02:00
|
|
|
int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
int64_t obu_size;
|
|
|
|
int start_pos, type, temporal_id, spatial_id;
|
|
|
|
|
|
|
|
if (size <= 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
int len = parse_obu_header(buf, size, &obu_size, &start_pos,
|
|
|
|
&type, &temporal_id, &spatial_id);
|
|
|
|
if (len < 0)
|
|
|
|
return len;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case AV1_OBU_SEQUENCE_HEADER:
|
|
|
|
if (!obu_size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
return parse_sequence_header(seq, buf + start_pos, obu_size);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size -= len;
|
|
|
|
buf += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2018-07-07 21:35:32 +02:00
|
|
|
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
|
|
|
|
{
|
2020-06-21 12:58:21 +02:00
|
|
|
AVIOContext *meta_pb;
|
2018-08-16 23:01:44 +02:00
|
|
|
AV1SequenceParameters seq_params;
|
|
|
|
PutBitContext pbc;
|
2020-06-21 12:58:21 +02:00
|
|
|
uint8_t header[4], *meta;
|
|
|
|
const uint8_t *seq;
|
2018-07-07 21:35:32 +02:00
|
|
|
int64_t obu_size;
|
|
|
|
int start_pos, type, temporal_id, spatial_id;
|
2018-07-30 20:15:43 +02:00
|
|
|
int ret, nb_seq = 0, seq_size, meta_size;
|
2018-07-07 21:35:32 +02:00
|
|
|
|
2018-07-23 18:15:06 +02:00
|
|
|
if (size <= 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2020-11-23 18:00:44 +02:00
|
|
|
if (buf[0] & 0x80) {
|
|
|
|
// first bit is nonzero, the passed data does not consist purely of
|
|
|
|
// OBUs. Expect that the data is already in AV1CodecConfigurationRecord
|
|
|
|
// format.
|
|
|
|
int config_record_version = buf[0] & 0x7f;
|
|
|
|
if (config_record_version != 1 || size < 4) {
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
avio_write(pb, buf, size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-30 20:15:43 +02:00
|
|
|
ret = avio_open_dyn_buf(&meta_pb);
|
|
|
|
if (ret < 0)
|
2020-06-21 12:58:21 +02:00
|
|
|
return ret;
|
2018-07-30 20:15:43 +02:00
|
|
|
|
2018-07-07 21:35:32 +02:00
|
|
|
while (size > 0) {
|
2018-07-30 20:14:24 +02:00
|
|
|
int len = parse_obu_header(buf, size, &obu_size, &start_pos,
|
2018-07-07 21:35:32 +02:00
|
|
|
&type, &temporal_id, &spatial_id);
|
2018-07-30 20:15:43 +02:00
|
|
|
if (len < 0) {
|
|
|
|
ret = len;
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-07-07 21:35:32 +02:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case AV1_OBU_SEQUENCE_HEADER:
|
2018-07-30 20:15:43 +02:00
|
|
|
nb_seq++;
|
|
|
|
if (!obu_size || nb_seq > 1) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-08-16 23:01:44 +02:00
|
|
|
ret = parse_sequence_header(&seq_params, buf + start_pos, obu_size);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2020-06-21 12:58:21 +02:00
|
|
|
seq = buf;
|
|
|
|
seq_size = len;
|
2018-07-30 20:15:43 +02:00
|
|
|
break;
|
2018-07-07 21:35:32 +02:00
|
|
|
case AV1_OBU_METADATA:
|
2018-07-30 20:15:43 +02:00
|
|
|
if (!obu_size) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
avio_write(meta_pb, buf, len);
|
2018-07-07 21:35:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-07-30 20:14:24 +02:00
|
|
|
size -= len;
|
|
|
|
buf += len;
|
2018-07-07 21:35:32 +02:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:58:21 +02:00
|
|
|
if (!nb_seq) {
|
2018-07-30 20:15:43 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-08-16 23:01:44 +02:00
|
|
|
|
|
|
|
init_put_bits(&pbc, header, sizeof(header));
|
|
|
|
|
|
|
|
put_bits(&pbc, 1, 1); // marker
|
|
|
|
put_bits(&pbc, 7, 1); // version
|
2019-07-30 16:48:38 +02:00
|
|
|
put_bits(&pbc, 3, seq_params.profile);
|
|
|
|
put_bits(&pbc, 5, seq_params.level);
|
|
|
|
put_bits(&pbc, 1, seq_params.tier);
|
2019-07-30 16:55:26 +02:00
|
|
|
put_bits(&pbc, 1, seq_params.bitdepth > 8);
|
|
|
|
put_bits(&pbc, 1, seq_params.bitdepth == 12);
|
2018-08-16 23:01:44 +02:00
|
|
|
put_bits(&pbc, 1, seq_params.monochrome);
|
|
|
|
put_bits(&pbc, 1, seq_params.chroma_subsampling_x);
|
|
|
|
put_bits(&pbc, 1, seq_params.chroma_subsampling_y);
|
|
|
|
put_bits(&pbc, 2, seq_params.chroma_sample_position);
|
2019-04-08 14:14:27 +02:00
|
|
|
put_bits(&pbc, 8, 0); // padding
|
2018-08-16 23:01:44 +02:00
|
|
|
flush_put_bits(&pbc);
|
|
|
|
|
|
|
|
avio_write(pb, header, sizeof(header));
|
2018-07-30 20:15:43 +02:00
|
|
|
avio_write(pb, seq, seq_size);
|
|
|
|
|
2019-11-27 14:22:07 +02:00
|
|
|
meta_size = avio_get_dyn_buf(meta_pb, &meta);
|
2018-07-30 20:15:43 +02:00
|
|
|
if (meta_size)
|
|
|
|
avio_write(pb, meta, meta_size);
|
|
|
|
|
|
|
|
fail:
|
2019-11-27 14:22:07 +02:00
|
|
|
ffio_free_dyn_buf(&meta_pb);
|
2018-07-30 20:15:43 +02:00
|
|
|
|
|
|
|
return ret;
|
2018-07-07 21:35:32 +02:00
|
|
|
}
|