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

libavformat/oggparsecelt.c

Go to the documentation of this file.
00001 /*
00002  * Xiph CELT / Opus 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 #include "avformat.h"
00024 #include "oggdec.h"
00025 #include "libavutil/intreadwrite.h"
00026 
00027 struct oggcelt_private {
00028     int extra_headers_left;
00029 };
00030 
00031 static int celt_header(AVFormatContext *s, int idx)
00032 {
00033     struct ogg *ogg = s->priv_data;
00034     struct ogg_stream *os = ogg->streams + idx;
00035     AVStream *st = s->streams[idx];
00036     struct oggcelt_private *priv = os->private;
00037     uint8_t *p = os->buf + os->pstart;
00038 
00039     if (os->psize == 60 &&
00040         !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
00041 
00042         /* Main header */
00043 
00044         uint32_t version, header_size av_unused, sample_rate, nb_channels, frame_size;
00045         uint32_t overlap, bytes_per_packet av_unused, extra_headers;
00046         uint8_t *extradata;
00047 
00048         extradata = av_malloc(2 * sizeof(uint32_t) +
00049                               FF_INPUT_BUFFER_PADDING_SIZE);
00050         priv = av_malloc(sizeof(struct oggcelt_private));
00051         if (!extradata || !priv) {
00052             av_free(extradata);
00053             av_free(priv);
00054             return AVERROR(ENOMEM);
00055         }
00056         version          = AV_RL32(p + 28);
00057         header_size      = AV_RL32(p + 32); /* unused */
00058         sample_rate      = AV_RL32(p + 36);
00059         nb_channels      = AV_RL32(p + 40);
00060         frame_size       = AV_RL32(p + 44);
00061         overlap          = AV_RL32(p + 48);
00062         bytes_per_packet = AV_RL32(p + 52); /* unused */
00063         extra_headers    = AV_RL32(p + 56);
00064         st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
00065         st->codec->codec_id       = CODEC_ID_CELT;
00066         st->codec->sample_rate    = sample_rate;
00067         st->codec->channels       = nb_channels;
00068         st->codec->frame_size     = frame_size;
00069         st->codec->sample_fmt     = AV_SAMPLE_FMT_S16;
00070         av_set_pts_info(st, 64, 1, sample_rate);
00071         priv->extra_headers_left  = 1 + extra_headers;
00072         av_free(os->private);
00073         os->private = priv;
00074         AV_WL32(extradata + 0, overlap);
00075         AV_WL32(extradata + 4, version);
00076         av_free(st->codec->extradata);
00077         st->codec->extradata = extradata;
00078         st->codec->extradata_size = 2 * sizeof(uint32_t);
00079         return 1;
00080 
00081     } else if(priv && priv->extra_headers_left) {
00082 
00083         /* Extra headers (vorbiscomment) */
00084 
00085         ff_vorbis_comment(s, &st->metadata, p, os->psize);
00086         priv->extra_headers_left--;
00087         return 1;
00088 
00089     } else {
00090         return 0;
00091     }
00092 }
00093 
00094 const struct ogg_codec ff_celt_codec = {
00095     .magic     = "CELT    ",
00096     .magicsize = 8,
00097     .header    = celt_header,
00098 };

Generated on Wed Apr 11 2012 07:31:36 for FFmpeg by  doxygen 1.7.1