00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include "libavcodec/get_bits.h"
00023 #include "libavcodec/flac.h"
00024 #include "avformat.h"
00025 #include "oggdec.h"
00026
00027 #define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
00028
00029 static int
00030 flac_header (AVFormatContext * s, int idx)
00031 {
00032 struct ogg *ogg = s->priv_data;
00033 struct ogg_stream *os = ogg->streams + idx;
00034 AVStream *st = s->streams[idx];
00035 GetBitContext gb;
00036 FLACStreaminfo si;
00037 int mdt;
00038
00039 if (os->buf[os->pstart] == 0xff)
00040 return 0;
00041
00042 init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
00043 skip_bits1(&gb);
00044 mdt = get_bits(&gb, 7);
00045
00046 if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
00047 uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
00048 skip_bits_long(&gb, 4*8);
00049 if(get_bits(&gb, 8) != 1)
00050 return -1;
00051 skip_bits_long(&gb, 8 + 16);
00052 skip_bits_long(&gb, 4*8);
00053
00054
00055 if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
00056 return -1;
00057
00058 ff_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
00059
00060 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00061 st->codec->codec_id = CODEC_ID_FLAC;
00062
00063 st->codec->extradata =
00064 av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
00065 memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);
00066 st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
00067
00068 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
00069 } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
00070 ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4);
00071 }
00072
00073 return 1;
00074 }
00075
00076 static int
00077 old_flac_header (AVFormatContext * s, int idx)
00078 {
00079 AVStream *st = s->streams[idx];
00080 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00081 st->codec->codec_id = CODEC_ID_FLAC;
00082
00083 return 0;
00084 }
00085
00086 const struct ogg_codec ff_flac_codec = {
00087 .magic = "\177FLAC",
00088 .magicsize = 5,
00089 .header = flac_header
00090 };
00091
00092 const struct ogg_codec ff_old_flac_codec = {
00093 .magic = "fLaC",
00094 .magicsize = 4,
00095 .header = old_flac_header
00096 };