Commit cfe22033 authored by James Almer's avatar James Almer

avcodec/cbs_av1: add support for Scalability Metadata

Reviewed-by: 's avatarMark Thompson <sw@jkqxz.net>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 5ba76921
......@@ -127,4 +127,37 @@ enum {
AV1_CSP_COLOCATED = 2, // -> AVCHROMA_LOC_TOPLEFT.
};
// Scalability modes (section 6.7.5)
enum {
AV1_SCALABILITY_L1T2 = 0,
AV1_SCALABILITY_L1T3 = 1,
AV1_SCALABILITY_L2T1 = 2,
AV1_SCALABILITY_L2T2 = 3,
AV1_SCALABILITY_L2T3 = 4,
AV1_SCALABILITY_S2T1 = 5,
AV1_SCALABILITY_S2T2 = 6,
AV1_SCALABILITY_S2T3 = 7,
AV1_SCALABILITY_L2T1h = 8,
AV1_SCALABILITY_L2T2h = 9,
AV1_SCALABILITY_L2T3h = 10,
AV1_SCALABILITY_S2T1h = 11,
AV1_SCALABILITY_S2T2h = 12,
AV1_SCALABILITY_S2T3h = 13,
AV1_SCALABILITY_SS = 14,
AV1_SCALABILITY_L3T1 = 15,
AV1_SCALABILITY_L3T2 = 16,
AV1_SCALABILITY_L3T3 = 17,
AV1_SCALABILITY_S3T1 = 18,
AV1_SCALABILITY_S3T2 = 19,
AV1_SCALABILITY_S3T3 = 20,
AV1_SCALABILITY_L3T2_KEY = 21,
AV1_SCALABILITY_L3T3_KEY = 22,
AV1_SCALABILITY_L4T5_KEY = 23,
AV1_SCALABILITY_L4T7_KEY = 24,
AV1_SCALABILITY_L3T2_KEY_SHIFT = 25,
AV1_SCALABILITY_L3T3_KEY_SHIFT = 26,
AV1_SCALABILITY_L4T5_KEY_SHIFT = 27,
AV1_SCALABILITY_L4T7_KEY_SHIFT = 28,
};
#endif /* AVCODEC_AV1_H */
......@@ -325,7 +325,20 @@ typedef struct AV1RawMetadataHDRMDCV {
typedef struct AV1RawMetadataScalability {
uint8_t scalability_mode_idc;
// TODO: more stuff.
uint8_t spatial_layers_cnt_minus_1;
uint8_t spatial_layer_dimensions_present_flag;
uint8_t spatial_layer_description_present_flag;
uint8_t temporal_group_description_present_flag;
uint8_t scalability_structure_reserved_3bits;
uint16_t spatial_layer_max_width[4];
uint16_t spatial_layer_max_height[4];
uint8_t spatial_layer_ref_id[4];
uint8_t temporal_group_size;
uint8_t temporal_group_temporal_id[255];
uint8_t temporal_group_temporal_switching_up_point_flag[255];
uint8_t temporal_group_spatial_switching_up_point_flag[255];
uint8_t temporal_group_ref_cnt[255];
uint8_t temporal_group_ref_pic_diff[255][7];
} AV1RawMetadataScalability;
typedef struct AV1RawMetadataITUTT35 {
......
......@@ -1653,12 +1653,64 @@ static int FUNC(metadata_hdr_mdcv)(CodedBitstreamContext *ctx, RWContext *rw,
return 0;
}
static int FUNC(scalability_structure)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawMetadataScalability *current)
{
CodedBitstreamAV1Context *priv = ctx->priv_data;
const AV1RawSequenceHeader *seq;
int err, i, j;
if (!priv->sequence_header) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
"unable to parse scalability metadata.\n");
return AVERROR_INVALIDDATA;
}
seq = priv->sequence_header;
fb(2, spatial_layers_cnt_minus_1);
flag(spatial_layer_dimensions_present_flag);
flag(spatial_layer_description_present_flag);
flag(temporal_group_description_present_flag);
fc(3, scalability_structure_reserved_3bits, 0, 0);
if (current->spatial_layer_dimensions_present_flag) {
for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) {
fcs(16, spatial_layer_max_width[i],
0, seq->max_frame_width_minus_1 + 1, 1, i);
fcs(16, spatial_layer_max_height[i],
0, seq->max_frame_height_minus_1 + 1, 1, i);
}
}
if (current->spatial_layer_description_present_flag) {
for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++)
fbs(8, spatial_layer_ref_id[i], 1, i);
}
if (current->temporal_group_description_present_flag) {
fb(8, temporal_group_size);
for (i = 0; i < current->temporal_group_size; i++) {
fbs(3, temporal_group_temporal_id[i], 1, i);
flags(temporal_group_temporal_switching_up_point_flag[i], 1, i);
flags(temporal_group_spatial_switching_up_point_flag[i], 1, i);
fbs(3, temporal_group_ref_cnt[i], 1, i);
for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) {
fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j);
}
}
}
return 0;
}
static int FUNC(metadata_scalability)(CodedBitstreamContext *ctx, RWContext *rw,
AV1RawMetadataScalability *current)
{
// TODO: scalability metadata.
int err;
return AVERROR_PATCHWELCOME;
fb(8, scalability_mode_idc);
if (current->scalability_mode_idc == AV1_SCALABILITY_SS)
CHECK(FUNC(scalability_structure)(ctx, rw, current));
return 0;
}
static int FUNC(metadata_itut_t35)(CodedBitstreamContext *ctx, RWContext *rw,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment