Commit 1fdf18f4 authored by Justin Ruggles's avatar Justin Ruggles

mov: add support for reading and writing the 'chan' tag

This implements reading the tag in the demuxer and adds support for writing it
in the muxer. Some example channel layout tables for muxing are included for
ac3, aac, and alac, but they are not utilized yet.
parent b2890f5e
...@@ -132,9 +132,10 @@ OBJS-$(CONFIG_MLP_MUXER) += rawenc.o ...@@ -132,9 +132,10 @@ OBJS-$(CONFIG_MLP_MUXER) += rawenc.o
OBJS-$(CONFIG_MM_DEMUXER) += mm.o OBJS-$(CONFIG_MM_DEMUXER) += mm.o
OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o pcm.o OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o pcm.o
OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o
OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o mov_chan.o
OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o \ OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o \
movenchint.o rtpenc_chain.o movenchint.o rtpenc_chain.o \
mov_chan.o
OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o rawenc.o OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o rawenc.o
OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o
OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "isom.h" #include "isom.h"
#include "libavcodec/get_bits.h" #include "libavcodec/get_bits.h"
#include "id3v1.h" #include "id3v1.h"
#include "mov_chan.h"
#if CONFIG_ZLIB #if CONFIG_ZLIB
#include <zlib.h> #include <zlib.h>
...@@ -554,6 +555,51 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -554,6 +555,51 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0; return 0;
} }
static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
uint8_t version;
uint32_t flags, layout_tag, bitmap, num_descr;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
if (atom.size < 16)
return 0;
version = avio_r8(pb);
flags = avio_rb24(pb);
layout_tag = avio_rb32(pb);
bitmap = avio_rb32(pb);
num_descr = avio_rb32(pb);
if (atom.size < 16ULL + num_descr * 20ULL)
return 0;
av_dlog(c->fc, "chan: size=%ld version=%u flags=%u layout=%u bitmap=%u num_descr=%u\n",
atom.size, version, flags, layout_tag, bitmap, num_descr);
#if 0
/* TODO: use the channel descriptions if the layout tag is 0 */
int i;
for (i = 0; i < num_descr; i++) {
uint32_t label, cflags;
float coords[3];
label = avio_rb32(pb); // mChannelLabel
cflags = avio_rb32(pb); // mChannelFlags
AV_WN32(&coords[0], avio_rl32(pb)); // mCoordinates[0]
AV_WN32(&coords[1], avio_rl32(pb)); // mCoordinates[1]
AV_WN32(&coords[2], avio_rl32(pb)); // mCoordinates[2]
}
#endif
st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
return 0;
}
static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{ {
AVStream *st; AVStream *st;
...@@ -2329,6 +2375,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { ...@@ -2329,6 +2375,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */
{ MKTAG('w','f','e','x'), mov_read_wfex }, { MKTAG('w','f','e','x'), mov_read_wfex },
{ MKTAG('c','m','o','v'), mov_read_cmov }, { MKTAG('c','m','o','v'), mov_read_cmov },
{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */
{ 0, NULL } { 0, NULL }
}; };
......
This diff is collapsed.
/*
* Copyright (c) 2011 Justin Ruggles
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* mov 'chan' tag reading/writing.
* @author Justin Ruggles
*/
#ifndef AVFORMAT_MOV_CHAN_H
#define AVFORMAT_MOV_CHAN_H
#include <stdint.h>
#include "libavcodec/avcodec.h"
/**
* Get the channel layout for the specified channel layout tag.
*
* @param[in] tag channel layout tag
* @param[out] bitmap channel bitmap (only used if needed)
* @return channel layout
*/
uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap);
/**
* Get the channel layout tag for the specified codec id and channel layout.
* If the layout tag was not found, use a channel bitmap if possible.
*
* @param[in] codec_id codec id
* @param[in] channel_layout channel layout
* @param[out] bitmap channel bitmap
* @return channel layout tag
*/
uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id,
uint64_t channel_layout,
uint32_t *bitmap);
#endif /* AVFORMAT_MOV_CHAN_H */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "rtpenc.h" #include "rtpenc.h"
#include "mov_chan.h"
#undef NDEBUG #undef NDEBUG
#include <assert.h> #include <assert.h>
...@@ -338,6 +339,31 @@ static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track) ...@@ -338,6 +339,31 @@ static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track)
return updateSize(pb, pos); return updateSize(pb, pos);
} }
static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track)
{
uint32_t layout_tag, bitmap;
int64_t pos = avio_tell(pb);
layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id,
track->enc->channel_layout,
&bitmap);
if (!layout_tag) {
av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to "
"lack of channel information\n");
return 0;
}
avio_wb32(pb, 0); // Size
ffio_wfourcc(pb, "chan"); // Type
avio_w8(pb, 0); // Version
avio_wb24(pb, 0); // Flags
avio_wb32(pb, layout_tag); // mChannelLayoutTag
avio_wb32(pb, bitmap); // mChannelBitmap
avio_wb32(pb, 0); // mNumberChannelDescriptions
return updateSize(pb, pos);
}
static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track)
{ {
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment