X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmov_chan.c;h=475a66ba8232d19a78eb471adff0fcb4ba545dbf;hb=7427d1ca4ab202def24fc3cefc4401a351d7248c;hp=a8e6b94c51433096013d1bc464cc7b5463bb1e20;hpb=7d8f1158436c261d2d1657c33e731f9bec650c51;p=ffmpeg diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index a8e6b94c514..475a66ba823 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -155,6 +155,7 @@ static const struct MovChannelLayoutMap mov_ch_layout_map_misc[] = { static const struct MovChannelLayoutMap mov_ch_layout_map_1ch[] = { { MOV_CH_LAYOUT_MONO, AV_CH_LAYOUT_MONO }, // C + { 0, 0 }, }; static const struct MovChannelLayoutMap mov_ch_layout_map_2ch[] = { @@ -413,14 +414,40 @@ static const enum MovChannelLayoutTag mov_ch_layouts_alac[] = { 0, }; +static const enum MovChannelLayoutTag mov_ch_layouts_wav[] = { + MOV_CH_LAYOUT_MONO, + MOV_CH_LAYOUT_STEREO, + MOV_CH_LAYOUT_MATRIXSTEREO, + MOV_CH_LAYOUT_MPEG_3_0_A, + MOV_CH_LAYOUT_QUADRAPHONIC, + MOV_CH_LAYOUT_MPEG_5_0_A, + MOV_CH_LAYOUT_MPEG_5_1_A, + MOV_CH_LAYOUT_MPEG_6_1_A, + MOV_CH_LAYOUT_MPEG_7_1_A, + MOV_CH_LAYOUT_MPEG_7_1_C, + MOV_CH_LAYOUT_SMPTE_DTV, +}; + static const struct { - enum CodecID codec_id; + enum AVCodecID codec_id; const enum MovChannelLayoutTag *layouts; } mov_codec_ch_layouts[] = { - { CODEC_ID_AAC, mov_ch_layouts_aac }, - { CODEC_ID_AC3, mov_ch_layouts_ac3 }, - { CODEC_ID_ALAC, mov_ch_layouts_alac }, - { CODEC_ID_NONE, NULL }, + { AV_CODEC_ID_AAC, mov_ch_layouts_aac }, + { AV_CODEC_ID_AC3, mov_ch_layouts_ac3 }, + { AV_CODEC_ID_ALAC, mov_ch_layouts_alac }, + { AV_CODEC_ID_PCM_U8, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S8, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S16LE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S16BE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S24LE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S24BE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S32LE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_S32BE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_F32LE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_F32BE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_F64LE, mov_ch_layouts_wav }, + { AV_CODEC_ID_PCM_F64BE, mov_ch_layouts_wav }, + { AV_CODEC_ID_NONE, NULL }, }; uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) @@ -428,8 +455,7 @@ uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) int i, channels; const struct MovChannelLayoutMap *layout_map; - /* handle the use of the channel descriptions */ - /* TODO: map MOV channel labels to FFmpeg channels */ + /* use ff_mov_get_channel_label() to build a layout instead */ if (tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS) return 0; @@ -451,7 +477,20 @@ uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) return layout_map[i].layout; } -uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, +static uint32_t mov_get_channel_label(uint32_t label) +{ + if (label == 0) + return 0; + if (label <= 18) + return 1U << (label - 1); + if (label == 38) + return AV_CH_STEREO_LEFT; + if (label == 39) + return AV_CH_STEREO_RIGHT; + return 0; +} + +uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id, uint64_t channel_layout, uint32_t *bitmap) { @@ -460,11 +499,11 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, const enum MovChannelLayoutTag *layouts = NULL; /* find the layout list for the specified codec */ - for (i = 0; mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE; i++) { + for (i = 0; mov_codec_ch_layouts[i].codec_id != AV_CODEC_ID_NONE; i++) { if (mov_codec_ch_layouts[i].codec_id == codec_id) break; } - if (mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE) + if (mov_codec_ch_layouts[i].codec_id != AV_CODEC_ID_NONE) layouts = mov_codec_ch_layouts[i].layouts; if (layouts) { @@ -479,7 +518,7 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, /* find the layout tag for the specified channel layout */ for (i = 0; layouts[i] != 0; i++) { - if (layouts[i] & 0xFFFF != channels) + if ((layouts[i] & 0xFFFF) != channels) continue; for (j = 0; layout_map[j].tag != 0; j++) { if (layout_map[j].tag == layouts[i] && @@ -503,3 +542,49 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, return tag; } + +int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size) +{ + AVIOContext *pb = s->pb; + uint32_t layout_tag, bitmap, num_descr, label_mask; + int i; + + if (size < 12) + return AVERROR_INVALIDDATA; + + layout_tag = avio_rb32(pb); + bitmap = avio_rb32(pb); + num_descr = avio_rb32(pb); + + av_dlog(s, "chan: layout=%u bitmap=%u num_descr=%u\n", + layout_tag, bitmap, num_descr); + + if (size < 12ULL + num_descr * 20ULL) + return 0; + + label_mask = 0; + for (i = 0; i < num_descr; i++) { + uint32_t label; + label = avio_rb32(pb); // mChannelLabel + avio_rb32(pb); // mChannelFlags + avio_rl32(pb); // mCoordinates[0] + avio_rl32(pb); // mCoordinates[1] + avio_rl32(pb); // mCoordinates[2] + size -= 20; + if (layout_tag == 0) { + uint32_t mask_incr = mov_get_channel_label(label); + if (mask_incr == 0) { + label_mask = 0; + break; + } + label_mask |= mask_incr; + } + } + if (layout_tag == 0) + st->codec->channel_layout = label_mask; + else + st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); + avio_skip(pb, size - 12); + + return 0; +}