• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/oggparsecelt.c

Go to the documentation of this file.
00001 /*
00002  * Xiph CELT parser for Ogg
00003  * Copyright (c) 2011 Nicolas George
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include <string.h>
00023 
00024 #include "libavutil/intreadwrite.h"
00025 #include "avformat.h"
00026 #include "internal.h"
00027 #include "oggdec.h"
00028 
00029 struct oggcelt_private {
00030     int extra_headers_left;
00031 };
00032 
00033 static int celt_header(AVFormatContext *s, int idx)
00034 {
00035     struct ogg *ogg = s->priv_data;
00036     struct ogg_stream *os = ogg->streams + idx;
00037     AVStream *st = s->streams[idx];
00038     struct oggcelt_private *priv = os->private;
00039     uint8_t *p = os->buf + os->pstart;
00040 
00041     if (os->psize == 60 &&
00042         !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
00043         /* Main header */
00044 
00045         uint32_t version, sample_rate, nb_channels, frame_size;
00046         uint32_t overlap, extra_headers;
00047         uint8_t *extradata;
00048 
00049         extradata = av_malloc(2 * sizeof(uint32_t) +
00050                               FF_INPUT_BUFFER_PADDING_SIZE);
00051         priv = av_malloc(sizeof(struct oggcelt_private));
00052         if (!extradata || !priv) {
00053             av_free(extradata);
00054             av_free(priv);
00055             return AVERROR(ENOMEM);
00056         }
00057         version          = AV_RL32(p + 28);
00058         /* unused header size field skipped */
00059         sample_rate      = AV_RL32(p + 36);
00060         nb_channels      = AV_RL32(p + 40);
00061         frame_size       = AV_RL32(p + 44);
00062         overlap          = AV_RL32(p + 48);
00063         /* unused bytes per packet field skipped */
00064         extra_headers    = AV_RL32(p + 56);
00065         st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
00066         st->codec->codec_id       = CODEC_ID_CELT;
00067         st->codec->sample_rate    = sample_rate;
00068         st->codec->channels       = nb_channels;
00069         st->codec->frame_size     = frame_size;
00070         av_free(st->codec->extradata);
00071         st->codec->extradata      = extradata;
00072         st->codec->extradata_size = 2 * sizeof(uint32_t);
00073         if (sample_rate)
00074             avpriv_set_pts_info(st, 64, 1, sample_rate);
00075         priv->extra_headers_left  = 1 + extra_headers;
00076         av_free(os->private);
00077         os->private = priv;
00078         AV_WL32(extradata + 0, overlap);
00079         AV_WL32(extradata + 4, version);
00080         return 1;
00081     } else if (priv && priv->extra_headers_left) {
00082         /* Extra headers (vorbiscomment) */
00083 
00084         ff_vorbis_comment(s, &st->metadata, p, os->psize);
00085         priv->extra_headers_left--;
00086         return 1;
00087     } else {
00088         return 0;
00089     }
00090 }
00091 
00092 const struct ogg_codec ff_celt_codec = {
00093     .magic     = "CELT    ",
00094     .magicsize = 8,
00095     .header    = celt_header,
00096 };
Generated on Fri Feb 1 2013 14:34:53 for FFmpeg by doxygen 1.7.1