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
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
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
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
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
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 };