diff options
author | Vittorio Giovara <vittorio.giovara@gmail.com> | 2017-03-31 17:14:42 +0200 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:34 -0300 |
commit | b828c3954e61145957b60653a1e0957072221923 (patch) | |
tree | 5795738b51ae455a150eed2520549a5e2a6b6546 /libavformat/mov.c | |
parent | 3654db79f4b912c1a4c3d16700c341628e40de3c (diff) | |
download | ffmpeg-b828c3954e61145957b60653a1e0957072221923.tar.gz |
mov: convert to new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r-- | libavformat/mov.c | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c index a842bf4464..62744a1961 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -799,6 +799,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; enum AVAudioServiceType *ast; int ac3info, acmod, lfeon, bsmod; + uint64_t mask; if (c->fc->nb_streams < 1) return 0; @@ -813,12 +814,15 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (ac3info >> 14) & 0x7; acmod = (ac3info >> 11) & 0x7; lfeon = (ac3info >> 10) & 0x1; - st->codecpar->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; - st->codecpar->channel_layout = ff_ac3_channel_layout_tab[acmod]; + + mask = ff_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; + mask |= AV_CH_LOW_FREQUENCY; + av_channel_layout_uninit(&st->codecpar->ch_layout); + av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); + *ast = bsmod; - if (st->codecpar->channels > 1 && bsmod == 0x7) + if (st->codecpar->ch_layout.nb_channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; return 0; @@ -829,6 +833,7 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; enum AVAudioServiceType *ast; int eac3info, acmod, lfeon, bsmod; + uint64_t mask; if (c->fc->nb_streams < 1) return 0; @@ -847,12 +852,15 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (eac3info >> 12) & 0x1f; acmod = (eac3info >> 9) & 0x7; lfeon = (eac3info >> 8) & 0x1; - st->codecpar->channel_layout = ff_ac3_channel_layout_tab[acmod]; + + mask = ff_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; - st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); + mask |= AV_CH_LOW_FREQUENCY; + av_channel_layout_uninit(&st->codecpar->ch_layout); + av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); + *ast = bsmod; - if (st->codecpar->channels > 1 && bsmod == 0x7) + if (st->codecpar->ch_layout.nb_channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; return 0; @@ -899,15 +907,14 @@ static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (channel_layout_code > 0xff) { av_log(c->fc, AV_LOG_WARNING, "Unsupported DTS audio channel layout\n"); } - st->codecpar->channel_layout = + av_channel_layout_uninit(&st->codecpar->ch_layout); + av_channel_layout_from_mask(&st->codecpar->ch_layout, ((channel_layout_code & 0x1) ? AV_CH_FRONT_CENTER : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_LEFT : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_RIGHT : 0) | ((channel_layout_code & 0x4) ? AV_CH_SIDE_LEFT : 0) | ((channel_layout_code & 0x4) ? AV_CH_SIDE_RIGHT : 0) | - ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0); - - st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); + ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0)); return 0; } @@ -2163,14 +2170,18 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, uint16_t version = avio_rb16(pb); uint32_t id = 0; AVDictionaryEntry *compatible_brands = av_dict_get(c->fc->metadata, "compatible_brands", NULL, AV_DICT_MATCH_CASE); + int channel_count; avio_rb16(pb); /* revision level */ id = avio_rl32(pb); /* vendor */ av_dict_set(&st->metadata, "vendor_id", av_fourcc2str(id), 0); - st->codecpar->channels = avio_rb16(pb); /* channel count */ + channel_count = avio_rb16(pb); + + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = channel_count; st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* sample size */ - av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codecpar->channels); + av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", channel_count); sc->audio_cid = avio_rb16(pb); avio_rb16(pb); /* packet size = 0 */ @@ -2190,7 +2201,9 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, } else if (version == 2) { avio_rb32(pb); /* sizeof struct only */ st->codecpar->sample_rate = av_int2double(avio_rb64(pb)); - st->codecpar->channels = avio_rb32(pb); + channel_count = avio_rb32(pb); + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = channel_count; avio_rb32(pb); /* always 0x7F000000 */ st->codecpar->bits_per_coded_sample = avio_rb32(pb); @@ -2242,15 +2255,15 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, /* set values for old format before stsd version 1 appeared */ case AV_CODEC_ID_MACE3: sc->samples_per_frame = 6; - sc->bytes_per_frame = 2 * st->codecpar->channels; + sc->bytes_per_frame = 2 * st->codecpar->ch_layout.nb_channels; break; case AV_CODEC_ID_MACE6: sc->samples_per_frame = 6; - sc->bytes_per_frame = 1 * st->codecpar->channels; + sc->bytes_per_frame = 1 * st->codecpar->ch_layout.nb_channels; break; case AV_CODEC_ID_ADPCM_IMA_QT: sc->samples_per_frame = 64; - sc->bytes_per_frame = 34 * st->codecpar->channels; + sc->bytes_per_frame = 34 * st->codecpar->ch_layout.nb_channels; break; case AV_CODEC_ID_GSM: sc->samples_per_frame = 160; @@ -2261,9 +2274,9 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, } bits_per_sample = av_get_bits_per_sample(st->codecpar->codec_id); - if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->codecpar->channels <= INT_MAX) { + if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->codecpar->ch_layout.nb_channels <= INT_MAX) { st->codecpar->bits_per_coded_sample = bits_per_sample; - sc->sample_size = (bits_per_sample >> 3) * st->codecpar->channels; + sc->sample_size = (bits_per_sample >> 3) * st->codecpar->ch_layout.nb_channels; } } @@ -2403,7 +2416,8 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, #endif /* no ifdef since parameters are always those */ case AV_CODEC_ID_QCELP: - st->codecpar->channels = 1; + av_channel_layout_uninit(&st->codecpar->ch_layout); + st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; // force sample rate for qcelp when not stored in mov if (st->codecpar->codec_tag != MKTAG('Q','c','l','p')) st->codecpar->sample_rate = 8000; @@ -2413,12 +2427,14 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, sc->bytes_per_frame = 35; break; case AV_CODEC_ID_AMR_NB: - st->codecpar->channels = 1; + av_channel_layout_uninit(&st->codecpar->ch_layout); + st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; /* force sample rate for amr, stsd in 3gp does not store sample rate */ st->codecpar->sample_rate = 8000; break; case AV_CODEC_ID_AMR_WB: - st->codecpar->channels = 1; + av_channel_layout_uninit(&st->codecpar->ch_layout); + st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; st->codecpar->sample_rate = 16000; break; case AV_CODEC_ID_MP2: @@ -2437,7 +2453,12 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, break; case AV_CODEC_ID_ALAC: if (st->codecpar->extradata_size == 36) { - st->codecpar->channels = AV_RB8 (st->codecpar->extradata + 21); + int channel_count = AV_RB8(st->codecpar->extradata + 21); + if (st->codecpar->ch_layout.nb_channels != channel_count) { + av_channel_layout_uninit(&st->codecpar->ch_layout); + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = channel_count; + } st->codecpar->sample_rate = AV_RB32(st->codecpar->extradata + 32); } break; @@ -2544,8 +2565,8 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate); return AVERROR_INVALIDDATA; } - if (st->codecpar->channels < 0) { - av_log(c->fc, AV_LOG_ERROR, "Invalid channels %d\n", st->codecpar->channels); + if (st->codecpar->ch_layout.nb_channels < 0) { + av_log(c->fc, AV_LOG_ERROR, "Invalid channels %d\n", st->codecpar->ch_layout.nb_channels); return AVERROR_INVALIDDATA; } } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){ @@ -7175,6 +7196,7 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext *pb, MOVAtom atom) unsigned format_info; int channel_assignment, channel_assignment1, channel_assignment2; int ratebits; + uint64_t chmask; if (c->fc->nb_streams < 1) return 0; @@ -7195,8 +7217,10 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codecpar->frame_size = 40 << (ratebits & 0x7); st->codecpar->sample_rate = mlp_samplerate(ratebits); - st->codecpar->channels = truehd_channels(channel_assignment); - st->codecpar->channel_layout = truehd_layout(channel_assignment); + + av_channel_layout_uninit(&st->codecpar->ch_layout); + chmask = truehd_layout(channel_assignment); + av_channel_layout_from_mask(&st->codecpar->ch_layout, chmask); return 0; } |