annotate ffmpeg/libavformat/oggparsecelt.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Xiph CELT parser for Ogg
yading@11 3 * Copyright (c) 2011 Nicolas George
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include <string.h>
yading@11 23
yading@11 24 #include "libavutil/intreadwrite.h"
yading@11 25 #include "avformat.h"
yading@11 26 #include "internal.h"
yading@11 27 #include "oggdec.h"
yading@11 28
yading@11 29 struct oggcelt_private {
yading@11 30 int extra_headers_left;
yading@11 31 };
yading@11 32
yading@11 33 static int celt_header(AVFormatContext *s, int idx)
yading@11 34 {
yading@11 35 struct ogg *ogg = s->priv_data;
yading@11 36 struct ogg_stream *os = ogg->streams + idx;
yading@11 37 AVStream *st = s->streams[idx];
yading@11 38 struct oggcelt_private *priv = os->private;
yading@11 39 uint8_t *p = os->buf + os->pstart;
yading@11 40
yading@11 41 if (os->psize == 60 &&
yading@11 42 !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
yading@11 43 /* Main header */
yading@11 44
yading@11 45 uint32_t version, sample_rate, nb_channels, frame_size;
yading@11 46 uint32_t overlap, extra_headers;
yading@11 47 uint8_t *extradata;
yading@11 48
yading@11 49 extradata = av_malloc(2 * sizeof(uint32_t) +
yading@11 50 FF_INPUT_BUFFER_PADDING_SIZE);
yading@11 51 priv = av_malloc(sizeof(struct oggcelt_private));
yading@11 52 if (!extradata || !priv) {
yading@11 53 av_free(extradata);
yading@11 54 av_free(priv);
yading@11 55 return AVERROR(ENOMEM);
yading@11 56 }
yading@11 57 version = AV_RL32(p + 28);
yading@11 58 /* unused header size field skipped */
yading@11 59 sample_rate = AV_RL32(p + 36);
yading@11 60 nb_channels = AV_RL32(p + 40);
yading@11 61 frame_size = AV_RL32(p + 44);
yading@11 62 overlap = AV_RL32(p + 48);
yading@11 63 /* unused bytes per packet field skipped */
yading@11 64 extra_headers = AV_RL32(p + 56);
yading@11 65 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 66 st->codec->codec_id = AV_CODEC_ID_CELT;
yading@11 67 st->codec->sample_rate = sample_rate;
yading@11 68 st->codec->channels = nb_channels;
yading@11 69 st->codec->frame_size = frame_size;
yading@11 70 av_free(st->codec->extradata);
yading@11 71 st->codec->extradata = extradata;
yading@11 72 st->codec->extradata_size = 2 * sizeof(uint32_t);
yading@11 73 if (sample_rate)
yading@11 74 avpriv_set_pts_info(st, 64, 1, sample_rate);
yading@11 75 priv->extra_headers_left = 1 + extra_headers;
yading@11 76 av_free(os->private);
yading@11 77 os->private = priv;
yading@11 78 AV_WL32(extradata + 0, overlap);
yading@11 79 AV_WL32(extradata + 4, version);
yading@11 80 return 1;
yading@11 81 } else if (priv && priv->extra_headers_left) {
yading@11 82 /* Extra headers (vorbiscomment) */
yading@11 83
yading@11 84 ff_vorbis_comment(s, &st->metadata, p, os->psize);
yading@11 85 priv->extra_headers_left--;
yading@11 86 return 1;
yading@11 87 } else {
yading@11 88 return 0;
yading@11 89 }
yading@11 90 }
yading@11 91
yading@11 92 const struct ogg_codec ff_celt_codec = {
yading@11 93 .magic = "CELT ",
yading@11 94 .magicsize = 8,
yading@11 95 .header = celt_header,
yading@11 96 .nb_header = 2,
yading@11 97 };