diff --git a/libavcodec/av3a.h b/libavcodec/av3a.h index 493a61f45d..14dc349894 100644 --- a/libavcodec/av3a.h +++ b/libavcodec/av3a.h @@ -2,7 +2,7 @@ * AV3A Common Header File * * Copyright (c) 2024 Shuai Liu - * + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -56,17 +56,17 @@ typedef enum { /* Content Type */ typedef enum { - AV3A_CHANNEL_BASED_TYPE = 0, - AV3A_OBJECT_BASED_TYPE = 1, - AV3A_CHANNEL_OBJECT_TYPE = 2, - AV3A_AMBISONIC_TYPE = 3 + AV3A_CHANNEL_BASED_TYPE = 0, + AV3A_OBJECT_BASED_TYPE = 1, + AV3A_CHANNEL_OBJECT_TYPE = 2, + AV3A_AMBISONIC_TYPE = 3 } Av3aContentType; /* Internal Coding Profile */ typedef enum { - AV3A_BASE_PROFILE = 0, - AV3A_OBJECT_METADATA_PROFILE = 1, - AV3A_AMBISONIC_PROFILE = 2 + AV3A_BASE_PROFILE = 0, + AV3A_OBJECT_METADATA_PROFILE = 1, + AV3A_AMBISONIC_PROFILE = 2 } Av3aCodingProfile; /* NN Type */ @@ -159,8 +159,7 @@ static const int64_t ff_av3a_mc4p0_bitrate_table[AV3A_BITRATE_TABLE_SIZE] = { /* bitrate table for MC 5.1.2 */ static const int64_t ff_av3a_mc5p1p2_bitrate_table[AV3A_BITRATE_TABLE_SIZE] = { - 152000, 320000, 480000, 576000, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 + 152000, 320000, 480000, 576000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* bitrate table for MC 5.1.4 */ @@ -228,27 +227,27 @@ static const enum AVChannel ff_av3a_channel_layout_mc_4_0[4] = { }; static const enum AVChannel ff_av3a_default_channel_layout_mc_5_1[6] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT }; static const enum AVChannel ff_av3a_default_channel_layout_mc_5_1_2[8] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_TOP_SIDE_LEFT, AV_CHAN_TOP_SIDE_RIGHT }; static const enum AVChannel ff_av3a_default_channel_layout_mc_7_1[8] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT }; static const enum AVChannel ff_av3a_default_channel_layout_mc_5_1_4[10] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_TOP_FRONT_LEFT, AV_CHAN_TOP_FRONT_RIGHT, @@ -256,7 +255,7 @@ static const enum AVChannel ff_av3a_default_channel_layout_mc_5_1_4[10] = { }; static const enum AVChannel ff_av3a_default_channel_layout_mc_7_1_2[10] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT, @@ -264,7 +263,7 @@ static const enum AVChannel ff_av3a_default_channel_layout_mc_7_1_2[10] = { }; static const enum AVChannel ff_av3a_default_channel_layout_mc_7_1_4[12] = { - AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, + AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, AV_CHAN_LOW_FREQUENCY, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT, @@ -273,21 +272,21 @@ static const enum AVChannel ff_av3a_default_channel_layout_mc_7_1_4[12] = { }; static const Av3aChannelConfigMap ff_av3a_channels_map_table[AV3A_CHANNEL_LAYOUT_SIZE] = { - { CHANNEL_CONFIG_MONO, 1, ff_av3a_default_channel_layout_mono, AV3A_CH_LAYOUT_MONO }, - { CHANNEL_CONFIG_STEREO, 2, ff_av3a_default_channel_layout_stereo, AV3A_CH_LAYOUT_STEREO }, - { CHANNEL_CONFIG_MC_5_1, 6, ff_av3a_default_channel_layout_mc_5_1, AV3A_CH_LAYOUT_5POINT1 }, - { CHANNEL_CONFIG_MC_7_1, 8, ff_av3a_default_channel_layout_mc_7_1, AV3A_CH_LAYOUT_7POINT1 }, - { CHANNEL_CONFIG_MC_10_2, 12, NULL, 0L }, /* reserved */ - { CHANNEL_CONFIG_MC_22_2, 24, NULL, 0L }, /* reserved */ - { CHANNEL_CONFIG_MC_4_0, 4, ff_av3a_channel_layout_mc_4_0, AV3A_CH_LAYOUT_4POINT0 }, + { CHANNEL_CONFIG_MONO, 1, ff_av3a_default_channel_layout_mono, AV3A_CH_LAYOUT_MONO }, + { CHANNEL_CONFIG_STEREO, 2, ff_av3a_default_channel_layout_stereo, AV3A_CH_LAYOUT_STEREO }, + { CHANNEL_CONFIG_MC_5_1, 6, ff_av3a_default_channel_layout_mc_5_1, AV3A_CH_LAYOUT_5POINT1 }, + { CHANNEL_CONFIG_MC_7_1, 8, ff_av3a_default_channel_layout_mc_7_1, AV3A_CH_LAYOUT_7POINT1 }, + { CHANNEL_CONFIG_MC_10_2, 12, NULL, 0L }, /* reserved */ + { CHANNEL_CONFIG_MC_22_2, 24, NULL, 0L }, /* reserved */ + { CHANNEL_CONFIG_MC_4_0, 4, ff_av3a_channel_layout_mc_4_0, AV3A_CH_LAYOUT_4POINT0 }, { CHANNEL_CONFIG_MC_5_1_2, 8, ff_av3a_default_channel_layout_mc_5_1_2, AV3A_CH_LAYOUT_5POINT1POINT2 }, { CHANNEL_CONFIG_MC_5_1_4, 10, ff_av3a_default_channel_layout_mc_5_1_4, AV3A_CH_LAYOUT_5POINT1POINT4 }, { CHANNEL_CONFIG_MC_7_1_2, 10, ff_av3a_default_channel_layout_mc_7_1_2, AV3A_CH_LAYOUT_7POINT1POINT2 }, { CHANNEL_CONFIG_MC_7_1_4, 12, ff_av3a_default_channel_layout_mc_7_1_4, AV3A_CH_LAYOUT_7POINT1POINT4 }, - { CHANNEL_CONFIG_HOA_ORDER1, 4, NULL, 0L }, - { CHANNEL_CONFIG_HOA_ORDER2, 9, NULL, 0L }, - { CHANNEL_CONFIG_HOA_ORDER3, 16, NULL, 0L }, - { CHANNEL_CONFIG_UNKNOWN, 0, NULL, 0L }, + { CHANNEL_CONFIG_HOA_ORDER1, 4, NULL, 0L }, + { CHANNEL_CONFIG_HOA_ORDER2, 9, NULL, 0L }, + { CHANNEL_CONFIG_HOA_ORDER3, 16, NULL, 0L }, + { CHANNEL_CONFIG_UNKNOWN, 0, NULL, 0L }, }; typedef struct { @@ -296,20 +295,20 @@ typedef struct { } Av3aBitrateMap; static const Av3aBitrateMap ff_av3a_bitrate_map_table[15] = { - {CHANNEL_CONFIG_MONO, ff_av3a_mono_bitrate_table }, - {CHANNEL_CONFIG_STEREO, ff_av3a_stereo_bitrate_table }, - {CHANNEL_CONFIG_MC_5_1, ff_av3a_mc5p1_bitrate_table }, - {CHANNEL_CONFIG_MC_7_1, ff_av3a_mc7p1_bitrate_table }, - {CHANNEL_CONFIG_MC_10_2, NULL }, /* reserved */ - {CHANNEL_CONFIG_MC_22_2, NULL }, /* reserved */ - {CHANNEL_CONFIG_MC_4_0, ff_av3a_mc4p0_bitrate_table }, - {CHANNEL_CONFIG_MC_5_1_2, ff_av3a_mc5p1p2_bitrate_table }, - {CHANNEL_CONFIG_MC_5_1_4, ff_av3a_mc5p1p4_bitrate_table }, - {CHANNEL_CONFIG_MC_7_1_2, ff_av3a_mc7p1p2_bitrate_table }, - {CHANNEL_CONFIG_MC_7_1_4, ff_av3a_mc7p1p4_bitrate_table }, - {CHANNEL_CONFIG_HOA_ORDER1, ff_av3a_foa_bitrate_table }, - {CHANNEL_CONFIG_HOA_ORDER2, ff_av3a_hoa2_bitrate_table }, - {CHANNEL_CONFIG_HOA_ORDER3, ff_av3a_hoa3_bitrate_table }, - {CHANNEL_CONFIG_UNKNOWN, NULL }, + {CHANNEL_CONFIG_MONO, ff_av3a_mono_bitrate_table }, + {CHANNEL_CONFIG_STEREO, ff_av3a_stereo_bitrate_table }, + {CHANNEL_CONFIG_MC_5_1, ff_av3a_mc5p1_bitrate_table }, + {CHANNEL_CONFIG_MC_7_1, ff_av3a_mc7p1_bitrate_table }, + {CHANNEL_CONFIG_MC_10_2, NULL }, /* reserved */ + {CHANNEL_CONFIG_MC_22_2, NULL }, /* reserved */ + {CHANNEL_CONFIG_MC_4_0, ff_av3a_mc4p0_bitrate_table }, + {CHANNEL_CONFIG_MC_5_1_2, ff_av3a_mc5p1p2_bitrate_table }, + {CHANNEL_CONFIG_MC_5_1_4, ff_av3a_mc5p1p4_bitrate_table }, + {CHANNEL_CONFIG_MC_7_1_2, ff_av3a_mc7p1p2_bitrate_table }, + {CHANNEL_CONFIG_MC_7_1_4, ff_av3a_mc7p1p4_bitrate_table }, + {CHANNEL_CONFIG_HOA_ORDER1, ff_av3a_foa_bitrate_table }, + {CHANNEL_CONFIG_HOA_ORDER2, ff_av3a_hoa2_bitrate_table }, + {CHANNEL_CONFIG_HOA_ORDER3, ff_av3a_hoa3_bitrate_table }, + {CHANNEL_CONFIG_UNKNOWN, NULL }, }; #endif /* AVCODEC_AV3A_H */ diff --git a/libavcodec/av3a_parser.c b/libavcodec/av3a_parser.c index 2c4e6d385e..745889a4d8 100644 --- a/libavcodec/av3a_parser.c +++ b/libavcodec/av3a_parser.c @@ -42,8 +42,8 @@ typedef struct { int16_t total_channels; } Av3aParseContext; -static int ff_read_av3a_header_parse(GetBitContext *gb, AATFHeaderInfo *hdf) -{ +static int ff_read_av3a_header_parse(GetBitContext *gb, AATFHeaderInfo *hdf) +{ int64_t soundbed_bitrate = 0L; int64_t object_bitrate = 0L; @@ -159,7 +159,7 @@ static int ff_read_av3a_header_parse(GetBitContext *gb, AATFHeaderInfo *hdf) hdf->total_channels = hdf->nb_channels + hdf->nb_objects; hdf->resolution_index = get_bits(gb, 2); - if((hdf->resolution_index >= AV3A_RESOLUTION_TABLE_SIZE) || (hdf->resolution_index < 0)) { + if ((hdf->resolution_index >= AV3A_RESOLUTION_TABLE_SIZE) || (hdf->resolution_index < 0)) { return AVERROR_INVALIDDATA; } hdf->resolution = ff_av3a_sample_format_map_table[hdf->resolution_index].resolution; diff --git a/libavformat/av3adec.c b/libavformat/av3adec.c index abb828cfee..51f7ec9f8a 100644 --- a/libavformat/av3adec.c +++ b/libavformat/av3adec.c @@ -2,7 +2,7 @@ * AV3A Demuxer * * Copyright (c) 2024 Shuai Liu - * + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -101,7 +101,7 @@ static int av3a_read_aatf_frame_header(AATFHeaderInfo *hdf, const uint8_t *buf) } else if (hdf->coding_profile == AV3A_OBJECT_METADATA_PROFILE) { hdf->soundbed_type = get_bits(&gb, 2); if (hdf->soundbed_type == 0) { - hdf->content_type = AV3A_OBJECT_BASED_TYPE; + hdf->content_type = AV3A_OBJECT_BASED_TYPE; hdf->object_channel_number = get_bits(&gb, 7); if (hdf->object_channel_number < 0) { return AVERROR_INVALIDDATA; @@ -137,7 +137,7 @@ static int av3a_read_aatf_frame_header(AATFHeaderInfo *hdf, const uint8_t *buf) return AVERROR_INVALIDDATA; } - hdf->total_bitrate = ff_av3a_bitrate_map_table[hdf->channel_number_index].bitrate_table[hdf->bitrate_index] + + hdf->total_bitrate = ff_av3a_bitrate_map_table[hdf->channel_number_index].bitrate_table[hdf->bitrate_index] + ff_av3a_bitrate_map_table[CHANNEL_CONFIG_MONO].bitrate_table[hdf->bitrate_index_per_channel] * hdf->nb_objects; } else { return AVERROR_INVALIDDATA; @@ -169,7 +169,7 @@ static int av3a_read_aatf_frame_header(AATFHeaderInfo *hdf, const uint8_t *buf) /* resolution */ hdf->resolution_index = get_bits(&gb, 2); - if((hdf->resolution_index >= AV3A_RESOLUTION_TABLE_SIZE) || (hdf->resolution_index < 0)) { + if ((hdf->resolution_index >= AV3A_RESOLUTION_TABLE_SIZE) || (hdf->resolution_index < 0)) { return AVERROR_INVALIDDATA; } hdf->resolution = ff_av3a_sample_format_map_table[hdf->resolution_index].resolution; @@ -177,7 +177,7 @@ static int av3a_read_aatf_frame_header(AATFHeaderInfo *hdf, const uint8_t *buf) if (hdf->coding_profile != AV3A_OBJECT_METADATA_PROFILE) { hdf->bitrate_index = get_bits(&gb, 4); - if ((hdf->bitrate_index >= AV3A_BITRATE_TABLE_SIZE) || (hdf->bitrate_index < 0)){ + if ((hdf->bitrate_index >= AV3A_BITRATE_TABLE_SIZE) || (hdf->bitrate_index < 0)) { return AVERROR_INVALIDDATA; } hdf->total_bitrate = ff_av3a_bitrate_map_table[hdf->channel_number_index].bitrate_table[hdf->bitrate_index]; @@ -188,7 +188,7 @@ static int av3a_read_aatf_frame_header(AATFHeaderInfo *hdf, const uint8_t *buf) return 0; } -static int av3a_get_packet_size(AVFormatContext *s) +static int av3a_get_packet_size(AVFormatContext *s) { int ret = 0; int read_bytes = 0; @@ -333,9 +333,8 @@ static int av3a_get_packet_size(AVFormatContext *s) return payload_bytes; } -static int av3a_probe(const AVProbeData *p) +static int av3a_probe(const AVProbeData *p) { - uint16_t frame_sync_word; uint16_t lval = ((uint16_t)(p->buf[0])); uint16_t rval = ((uint16_t)(p->buf[1])); @@ -348,7 +347,7 @@ static int av3a_probe(const AVProbeData *p) return 0; } -static int av3a_read_header(AVFormatContext *s) +static int av3a_read_header(AVFormatContext *s) { int ret = 0; uint8_t header[AV3A_MAX_NBYTES_HEADER]; @@ -367,7 +366,7 @@ static int av3a_read_header(AVFormatContext *s) stream->start_time = 0; ffstream(stream)->need_parsing = AVSTREAM_PARSE_FULL_RAW; stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - stream->codecpar->codec_id = s->iformat->raw_codec_id; + stream->codecpar->codec_id = s->iformat->raw_codec_id; stream->codecpar->codec_tag = MKTAG('a', 'v', '3', 'a'); if ((ret = avio_read(s->pb, header, AV3A_MAX_NBYTES_HEADER)) != AV3A_MAX_NBYTES_HEADER) { @@ -399,7 +398,7 @@ static int av3a_read_header(AVFormatContext *s) av3afmtctx.resolution_index = hdf.resolution_index; av3afmtctx.total_bitrate_kbps = (int) (hdf.total_bitrate / 1000); - if((ret = ff_alloc_extradata(stream->codecpar, sizeof(Av3aFormatContext))) < 0) { + if ((ret = ff_alloc_extradata(stream->codecpar, sizeof(Av3aFormatContext))) < 0) { return ret; } memcpy(stream->codecpar->extradata, &av3afmtctx, sizeof(Av3aFormatContext)); @@ -411,8 +410,8 @@ static int av3a_read_header(AVFormatContext *s) return 0; } -static int av3a_read_packet(AVFormatContext *s, AVPacket *pkt) { - +static int av3a_read_packet(AVFormatContext *s, AVPacket *pkt) +{ int64_t pos; int packet_size = 0; int read_bytes = 0; @@ -440,7 +439,7 @@ static int av3a_read_packet(AVFormatContext *s, AVPacket *pkt) { } if (!s->streams[0]) { - return AVERROR(ENOMEM); + return AVERROR(ENOMEM); } if (!s->streams[0]->codecpar) { diff --git a/libavformat/mov.c b/libavformat/mov.c index 0e24eb0af6..9a9144679b 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7949,7 +7949,7 @@ static int mov_read_dca3(MOVContext *c, AVIOContext *pb, MOVAtom atom) } st = c->fc->streams[c->fc->nb_streams - 1]; - if ((ret = avio_read(pb, buffer, sizeof(buffer))) < 0){ + if ((ret = avio_read(pb, buffer, sizeof(buffer))) < 0) { return ret; } @@ -7972,7 +7972,6 @@ static int mov_read_dca3(MOVContext *c, AVIOContext *pb, MOVAtom atom) reserved = get_bits(&gb, 1); content_type = get_bits(&gb, 4); - if (content_type == AV3A_CHANNEL_BASED_TYPE) { channel_number_index = get_bits(&gb, 7); reserved = get_bits(&gb, 1); @@ -8007,7 +8006,7 @@ static int mov_read_dca3(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_INVALIDDATA; } } else if (content_type == AV3A_AMBISONIC_TYPE) { - hoa_order = get_bits(&gb , 4); + hoa_order = get_bits(&gb, 4); if ((hoa_order < AV3A_AMBISONIC_FIRST_ORDER) || (hoa_order > AV3A_AMBISONIC_THIRD_ORDER)) { return AVERROR_INVALIDDATA; } @@ -8036,7 +8035,7 @@ static int mov_read_dca3(MOVContext *c, AVIOContext *pb, MOVAtom atom) } if (content_type != AV3A_OBJECT_BASED_TYPE) { - for(i = 0; i < nb_channels; i ++) { + for (i = 0; i < nb_channels; i ++) { st->codecpar->ch_layout.u.map[i].id = ff_av3a_channels_map_table[channel_number_index].channel_layout[i]; } } diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 7a6789ecb0..2bedfb573d 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -941,10 +941,10 @@ static int mov_write_dca3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra if (content_type == AV3A_CHANNEL_BASED_TYPE) { put_bits(&pb_dca3, 7, channel_number_index); put_bits(&pb_dca3, 1, 0); /* reserved */ - } else if (content_type == AV3A_OBJECT_BASED_TYPE){ + } else if (content_type == AV3A_OBJECT_BASED_TYPE) { put_bits(&pb_dca3, 7, number_objects); put_bits(&pb_dca3, 1, 0); /* reserved */ - } else if (content_type == AV3A_CHANNEL_OBJECT_TYPE){ + } else if (content_type == AV3A_CHANNEL_OBJECT_TYPE) { put_bits(&pb_dca3, 7, channel_number_index); put_bits(&pb_dca3, 1, 0); /* reserved */ put_bits(&pb_dca3, 7, number_objects);