00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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);
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);
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
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 };