--- libavformat/cafdec.c | 6 +++++ libavformat/mov.c | 39 +------------------------------------ libavformat/mov_chan.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- libavformat/mov_chan.h | 19 ++++++++++------- 4 files changed, 65 insertions(+), 49 deletions(-)
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 15a1e22..6c40b1b 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -29,6 +29,7 @@ #include "internal.h" #include "riff.h" #include "isom.h" +#include "mov_chan.h" #include "libavutil/intreadwrite.h" #include "libavutil/intfloat.h" #include "libavutil/dict.h" @@ -266,6 +267,11 @@ static int read_header(AVFormatContext *s) found_data = 1; break; + case MKBETAG('c','h','a','n'): + if ((ret = ff_mov_read_chan(s, st, size)) < 0) + return ret; + break; + /* magic cookie chunk */ case MKBETAG('k','u','k','i'): if (read_kuki_chunk(s, size)) diff --git a/libavformat/mov.c b/libavformat/mov.c index 647fd0e..59d7b1a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -575,10 +575,6 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; - uint8_t av_unused version; - uint32_t av_unused flags; - uint32_t layout_tag, bitmap, num_descr, label_mask; - int i; if (c->fc->nb_streams < 1) return 0; @@ -587,40 +583,7 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) 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); - - 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 = ff_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); + ff_mov_read_chan(c->fc, st, atom.size - 4); return 0; } diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index edd5f6c..139d23e 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -477,7 +477,7 @@ 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; @@ -491,8 +491,8 @@ uint32_t ff_mov_get_channel_label(uint32_t label) } uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, - uint64_t channel_layout, - uint32_t *bitmap) + uint64_t channel_layout, + uint32_t *bitmap) { int i, j; uint32_t tag = 0; @@ -542,3 +542,47 @@ 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] + 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); + + return 0; +} diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index bd6adf6..0897cd9 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -29,6 +29,7 @@ #include <stdint.h> #include "libavcodec/avcodec.h" +#include "avformat.h" /** * Get the channel layout for the specified channel layout tag. @@ -40,14 +41,6 @@ uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap); /** - * Get the channel layout for the specified channel label. - * - * @param[in] label channel label - * @return channel layout mask fragment - */ -uint32_t ff_mov_get_channel_label(uint32_t label); - -/** * 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. * @@ -60,4 +53,14 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, uint64_t channel_layout, uint32_t *bitmap); +/** + * Read 'chan' tag from the input stream. + * + * @param s AVFormatContext + * @param st The stream to set codec values for + * @param size Remaining size in the 'chan' tag + * @return 0 if ok, or negative AVERROR code on failure + */ +int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size); + #endif /* AVFORMAT_MOV_CHAN_H */ -- 1.7.1 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel