* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+//#define DEBUG
+
#include "avformat.h"
#include "internal.h"
#include "isom.h"
+#include "riff.h"
+#include "libavcodec/mpeg4audio.h"
+#include "libavcodec/mpegaudiodata.h"
/* http://www.mp4ra.org */
/* ordered by muxing preference */
{ CODEC_ID_RAWVIDEO, MKTAG('W', 'R', 'A', 'W') },
{ CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', '5') }, /* AVC Intra 50 / 1080 interlace */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', 'q') }, /* AVC Intra 50 / 720 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '5') }, /* AVC Intra 100 / 1080 interlace */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', 'q') }, /* AVC Intra 100 / 720 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '2') }, /* AVC Intra 100 / 1080 */
{ CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 Camcorder */
{ CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
- { CODEC_ID_MPEG2VIDEO, MKTAG('m', '2', 'v', '2') }, /* Apple MPEG-2 Camcorder */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', '2', 'v', '1') }, /* Apple MPEG-2 Camcorder */
{ CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') }, /* MPEG2 HDV 720p30 */
{ CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 HDV 1080i60 */
{ CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') }, /* MPEG2 HDV 1080i50 */
{ CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'p') }, /* MPEG2 IMX PAL 625/50 40mb/s produced by FCP */
{ CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'n') }, /* MPEG2 IMX NTSC 525/60 30mb/s produced by FCP */
{ CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'p') }, /* MPEG2 IMX PAL 625/50 30mb/s produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '4') }, /* XDCAM HD422 720p24 CBR */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '5') }, /* XDCAM HD422 720p25 CBR */
{ CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '9') }, /* XDCAM HD422 720p60 CBR */
{ CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'a') }, /* XDCAM HD422 720p50 CBR */
{ CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'b') }, /* XDCAM HD422 1080i60 CBR */
{ CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */
{ CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, /* DPX */
+ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'h') }, /* Apple ProRes 422 High Quality */
+ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'n') }, /* Apple ProRes 422 Standard Definition */
+ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 's') }, /* Apple ProRes 422 LT */
+ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'o') }, /* Apple ProRes 422 Proxy */
+ { CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'h') }, /* Apple ProRes 4444 */
+
{ CODEC_ID_NONE, 0 },
};
{ CODEC_ID_QCELP, MKTAG('Q','c','l','q') },
{ CODEC_ID_QCELP, MKTAG('s','q','c','p') }, /* ISO Media fourcc */
+ { CODEC_ID_QDMC, MKTAG('Q', 'D', 'M', 'C') }, /* QDMC */
{ CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, /* QDM2 */
{ CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') },
memcpy(to, mov_mdhd_language_map[code], 4);
return 1;
}
+
+int ff_mp4_read_descr_len(AVIOContext *pb)
+{
+ int len = 0;
+ int count = 4;
+ while (count--) {
+ int c = avio_r8(pb);
+ len = (len << 7) | (c & 0x7f);
+ if (!(c & 0x80))
+ break;
+ }
+ return len;
+}
+
+int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
+{
+ int len;
+ *tag = avio_r8(pb);
+ len = ff_mp4_read_descr_len(pb);
+ av_dlog(fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
+ return len;
+}
+
+static const AVCodecTag mp4_audio_types[] = {
+ { CODEC_ID_MP3ON4, AOT_PS }, /* old mp3on4 draft */
+ { CODEC_ID_MP3ON4, AOT_L1 }, /* layer 1 */
+ { CODEC_ID_MP3ON4, AOT_L2 }, /* layer 2 */
+ { CODEC_ID_MP3ON4, AOT_L3 }, /* layer 3 */
+ { CODEC_ID_MP4ALS, AOT_ALS }, /* MPEG-4 ALS */
+ { CODEC_ID_NONE, AOT_NULL },
+};
+
+int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
+{
+ int len, tag;
+ int object_type_id = avio_r8(pb);
+ avio_r8(pb); /* stream type */
+ avio_rb24(pb); /* buffer size db */
+ avio_rb32(pb); /* max bitrate */
+ avio_rb32(pb); /* avg bitrate */
+
+ st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
+ av_dlog(fc, "esds object type id 0x%02x\n", object_type_id);
+ len = ff_mp4_read_descr(fc, pb, &tag);
+ if (tag == MP4DecSpecificDescrTag) {
+ av_dlog(fc, "Specific MPEG4 header len=%d\n", len);
+ if((uint64_t)len > (1<<30))
+ return -1;
+ av_free(st->codec->extradata);
+ st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ avio_read(pb, st->codec->extradata, len);
+ st->codec->extradata_size = len;
+ if (st->codec->codec_id == CODEC_ID_AAC) {
+ MPEG4AudioConfig cfg;
+ ff_mpeg4audio_get_config(&cfg, st->codec->extradata,
+ st->codec->extradata_size);
+ st->codec->channels = cfg.channels;
+ if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4
+ st->codec->sample_rate = ff_mpa_freq_tab[cfg.sampling_index];
+ else if (cfg.ext_sample_rate)
+ st->codec->sample_rate = cfg.ext_sample_rate;
+ else
+ st->codec->sample_rate = cfg.sample_rate;
+ av_dlog(fc, "mp4a config channels %d obj %d ext obj %d "
+ "sample rate %d ext sample rate %d\n", st->codec->channels,
+ cfg.object_type, cfg.ext_object_type,
+ cfg.sample_rate, cfg.ext_sample_rate);
+ if (!(st->codec->codec_id = ff_codec_get_id(mp4_audio_types,
+ cfg.object_type)))
+ st->codec->codec_id = CODEC_ID_AAC;
+ }
+ }
+ return 0;
+}
+
+typedef struct MovChannelLayout {
+ int64_t channel_layout;
+ uint32_t layout_tag;
+} MovChannelLayout;
+
+static const MovChannelLayout mov_channel_layout[] = {
+ { AV_CH_LAYOUT_MONO, (100<<16) | 1}, //< kCAFChannelLayoutTag_Mono
+ { AV_CH_LAYOUT_STEREO, (101<<16) | 2}, //< kCAFChannelLayoutTag_Stereo
+ { AV_CH_LAYOUT_STEREO, (102<<16) | 2}, //< kCAFChannelLayoutTag_StereoHeadphones
+ { AV_CH_LAYOUT_2_1, (131<<16) | 3}, //< kCAFChannelLayoutTag_ITU_2_1
+ { AV_CH_LAYOUT_QUAD, (132<<16) | 4}, //< kCAFChannelLayoutTag_ITU_2_2
+ { AV_CH_LAYOUT_2_2, (132<<16) | 4}, //< kCAFChannelLayoutTag_ITU_2_2
+ { AV_CH_LAYOUT_QUAD, (108<<16) | 4}, //< kCAFChannelLayoutTag_Quadraphonic
+ { AV_CH_LAYOUT_SURROUND, (113<<16) | 3}, //< kCAFChannelLayoutTag_MPEG_3_0_A
+ { AV_CH_LAYOUT_4POINT0, (115<<16) | 4}, //< kCAFChannelLayoutTag_MPEG_4_0_A
+ { AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5}, //< kCAFChannelLayoutTag_MPEG_5_0_A
+ { AV_CH_LAYOUT_5POINT0, (117<<16) | 5}, //< kCAFChannelLayoutTag_MPEG_5_0_A
+ { AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6}, //< kCAFChannelLayoutTag_MPEG_5_1_A
+ { AV_CH_LAYOUT_5POINT1, (121<<16) | 6}, //< kCAFChannelLayoutTag_MPEG_5_1_A
+ { AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, //< kCAFChannelLayoutTag_MPEG_7_1_C
+ { AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8}, //< kCAFChannelLayoutTag_MPEG_7_1_A
+ { AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3}, //< kCAFChannelLayoutTag_DVD_4
+ { AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4}, //< kCAFChannelLayoutTag_DVD_5
+ { AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, //< kCAFChannelLayoutTag_DVD_6
+ { AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, //< kCAFChannelLayoutTag_DVD_6
+ { AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4}, //< kCAFChannelLayoutTag_DVD_10
+ { AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5}, //< kCAFChannelLayoutTag_DVD_11
+ { 0, 0},
+};
+
+void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec)
+{
+ uint32_t layout_tag;
+ AVIOContext *pb = s->pb;
+ const MovChannelLayout *layouts = mov_channel_layout;
+ if (size != 12) {
+ // Channel descriptions not implemented
+ av_log_ask_for_sample(s, "Unimplemented container channel layout.\n");
+ avio_skip(pb, size);
+ return;
+ }
+ layout_tag = avio_rb32(pb);
+ if (layout_tag == 0x10000) { //< kCAFChannelLayoutTag_UseChannelBitmap
+ codec->channel_layout = avio_rb32(pb);
+ avio_skip(pb, 4);
+ return;
+ }
+ while (layouts->channel_layout) {
+ if (layout_tag == layouts->layout_tag) {
+ codec->channel_layout = layouts->channel_layout;
+ break;
+ }
+ layouts++;
+ }
+ if (!codec->channel_layout)
+ av_log(s, AV_LOG_WARNING, "Unknown container channel layout.\n");
+ avio_skip(pb, 8);
+}
+