#include <stdint.h>
-#include "libavutil/audioconvert.h"
+#include "libavutil/channel_layout.h"
#include "libavcodec/avcodec.h"
#include "mov_chan.h"
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[] = {
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)
return layout_map[i].layout;
}
-uint32_t ff_mov_get_channel_label(uint32_t label)
+static uint32_t mov_get_channel_label(uint32_t label)
{
if (label == 0)
return 0;
return 0;
}
-uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id,
+uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
uint64_t channel_layout,
uint32_t *bitmap)
{
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) {
/* 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] &&
return tag;
}
+
+int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
+ int64_t size)
+{
+ 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]
+ 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) {
+ if (label_mask)
+ st->codec->channel_layout = label_mask;
+ } else
+ st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
+
+ return 0;
+}