diff options
author | Vittorio Giovara <vittorio.giovara@gmail.com> | 2017-03-31 17:49:17 +0200 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:35 -0300 |
commit | d219681a52c64a27c60b1395de9f3c01ba70d43b (patch) | |
tree | 2d63e2b77f450b348bd79d1514b8e75d0af8c7ee /libavformat/mxfdec.c | |
parent | cce7b9122a41e9824f85ea3fba41e26f97bf1bb3 (diff) | |
download | ffmpeg-d219681a52c64a27c60b1395de9f3c01ba70d43b.tar.gz |
mxf: 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/mxfdec.c')
-rw-r--r-- | libavformat/mxfdec.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index b85c10bf19..a32c1c55a4 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -591,18 +591,19 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, end_ptr = pkt->data + length; buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ - if (st->codecpar->channels > 8) + if (st->codecpar->ch_layout.nb_channels > 8) return AVERROR_INVALIDDATA; - for (; end_ptr - buf_ptr >= st->codecpar->channels * 4; ) { - for (i = 0; i < st->codecpar->channels; i++) { + for (; end_ptr - buf_ptr >= st->codecpar->ch_layout.nb_channels * 4; ) { + for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { uint32_t sample = bytestream_get_le32(&buf_ptr); if (st->codecpar->bits_per_coded_sample == 24) bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff); else bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff); } - buf_ptr += 32 - st->codecpar->channels*4; // always 8 channels stored SMPTE 331M + // always 8 channels stored SMPTE 331M + buf_ptr += 32 - st->codecpar->ch_layout.nb_channels * 4; } av_shrink_packet(pkt, data_ptr - pkt->data); return 0; @@ -2536,6 +2537,7 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript if (has_channel_label) { uint64_t channel_layout = 0; + int ret; for (int i = 0; i < descriptor->channels; i++) { if (!routing[i]) { @@ -2544,9 +2546,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript return 0; } if (channel_layout & routing[i]) { + char buf[32]; + av_channel_name(buf, sizeof(buf), routing[i]); av_log(mxf->fc, AV_LOG_WARNING, "%s audio channel is used multiple times in stream #%d, " "falling back to unknown channel layout\n", - av_get_channel_name(routing[i]), st->index); + buf, st->index); return 0; } if (routing[i] < channel_layout) { @@ -2557,9 +2561,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript channel_layout |= routing[i]; } - av_assert0(descriptor->channels == av_get_channel_layout_nb_channels(channel_layout)); + av_assert0(descriptor->channels == av_popcount64(channel_layout)); - st->codecpar->channel_layout = channel_layout; + ret = av_channel_layout_from_mask(&st->codecpar->ch_layout, channel_layout); + if (ret < 0) + return ret; } return 0; @@ -2927,7 +2933,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */ if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE)) st->codecpar->codec_id = (enum AVCodecID)container_ul->id; - st->codecpar->channels = descriptor->channels; + st->codecpar->ch_layout.nb_channels = descriptor->channels; if (descriptor->sample_rate.den > 0) { st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; @@ -3553,7 +3559,8 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st) return 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && is_pcm(st->codecpar->codec_id)) { - edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; + edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * + st->codecpar->ch_layout.nb_channels) >> 3; } else if (st->duration > 0 && p->first_essence_klv.length > 0 && p->first_essence_klv.length % st->duration == 0) { edit_unit_byte_count = p->first_essence_klv.length / st->duration; } @@ -3858,12 +3865,12 @@ static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par, pkt->pts = track->sample_count; - if ( par->channels <= 0 - || bits_per_sample <= 0 - || par->channels * (int64_t)bits_per_sample < 8) + if (par->ch_layout.nb_channels <= 0 || + bits_per_sample <= 0 || + par->ch_layout.nb_channels * (int64_t)bits_per_sample < 8) track->sample_count = mxf_compute_sample_count(mxf, st, av_rescale_q(track->sample_count, st->time_base, av_inv_q(track->edit_rate)) + 1); else - track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8); + track->sample_count += pkt->size / (par->ch_layout.nb_channels * (int64_t)bits_per_sample / 8); return 0; } |