Skip to content

Commit b53462a

Browse files
Improve MCA processor
1 parent c4beb01 commit b53462a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

libavformat/mxfdec.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,14 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
28792879

28802880
while (channel_ordering_ptr->uid[0]) {
28812881
if (IS_KLV_KEY(channel_ordering_ptr->uid, mca_sub_descriptor->mca_label_dictionary_id)) {
2882+
if (current_channel >= FF_SANE_NB_CHANNELS) {
2883+
av_log(mxf->fc, AV_LOG_ERROR, "max number of channels %d reached\n", FF_SANE_NB_CHANNELS);
2884+
return AVERROR_INVALIDDATA;
2885+
}
2886+
if (channel_ordering_ptr->index >= FF_SANE_NB_CHANNELS) {
2887+
av_log(mxf->fc, AV_LOG_ERROR, "mapping to channel index %d out of range, maximum is %d\n", channel_ordering_ptr->index, FF_SANE_NB_CHANNELS);
2888+
return AVERROR_INVALIDDATA;
2889+
}
28822890
source_track->channel_ordering[current_channel] = channel_ordering_ptr->index;
28832891

28842892
if(channel_ordering_ptr->service_type != AV_AUDIO_SERVICE_TYPE_NB) {
@@ -2906,7 +2914,12 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
29062914
source_track->require_reordering = 0;
29072915
for (j = 0; j < descriptor->channels; ++j) {
29082916
if (source_track->channel_ordering[j] != j) {
2909-
source_track->require_reordering = 1;
2917+
if (!is_pcm(st->codecpar->codec_id) || mxf->skip_audio_reordering) {
2918+
av_log(mxf->fc, AV_LOG_WARNING, "Skipping channel reordering!\n");
2919+
st->codecpar->channel_layout = 0;
2920+
} else {
2921+
source_track->require_reordering = 1;
2922+
}
29102923
break;
29112924
}
29122925
}
@@ -3867,9 +3880,7 @@ static int mxf_audio_remapping(int* channel_ordering, uint8_t* data, int size, i
38673880
memcpy(tmp, data_ptr, sample_offset);
38683881

38693882
for (int channel = 0; channel < channels; ++channel) {
3870-
for (int sample_index = 0; sample_index < sample_size; ++sample_index) {
3871-
data_ptr[sample_size * channel_ordering[channel] + sample_index] = tmp[sample_size * channel + sample_index];
3872-
}
3883+
memcpy(&data_ptr[sample_size * channel_ordering[channel]], &tmp[sample_size * channel], sample_size);
38733884
}
38743885

38753886
data_ptr += sample_offset;
@@ -3992,8 +4003,8 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
39924003
return ret;
39934004
}
39944005

3995-
// for audio, process audio remapping if MCA label requires it
3996-
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && track->require_reordering && !mxf->skip_audio_reordering) {
4006+
// for audio, process audio remapping if MCA label requires it
4007+
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && track->require_reordering) {
39974008
int byte_per_sample = st->codecpar->bits_per_coded_sample / 8;
39984009
ret = mxf_audio_remapping(track->channel_ordering, pkt->data, pkt->size, byte_per_sample, st->codecpar->channels);
39994010
if (ret < 0) {

0 commit comments

Comments
 (0)