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 "avformat.h"
00023 #include "bitstream.h"
00024 #include "oggdec.h"
00025
00026 #define FLAC_STREAMINFO_SIZE 0x22
00027
00028 static int
00029 flac_header (AVFormatContext * s, int idx)
00030 {
00031 ogg_t *ogg = s->priv_data;
00032 ogg_stream_t *os = ogg->streams + idx;
00033 AVStream *st = s->streams[idx];
00034 GetBitContext gb;
00035 int mdt;
00036
00037 if (os->buf[os->pstart] == 0xff)
00038 return 0;
00039
00040 init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
00041 get_bits(&gb, 1);
00042 mdt = get_bits(&gb, 7);
00043
00044 if (mdt == 0x7f) {
00045 skip_bits(&gb, 4*8);
00046 if(get_bits(&gb, 8) != 1)
00047 return -1;
00048 skip_bits(&gb, 8 + 16);
00049 skip_bits(&gb, 4*8);
00050
00051
00052 if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
00053 return -1;
00054
00055 skip_bits(&gb, 16*2+24*2);
00056
00057 st->codec->sample_rate = get_bits_long(&gb, 20);
00058 st->codec->channels = get_bits(&gb, 3) + 1;
00059
00060 st->codec->codec_type = CODEC_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, os->buf + os->pstart + 5 + 4 + 4 + 4,
00066 FLAC_STREAMINFO_SIZE);
00067 st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
00068
00069 st->time_base.num = 1;
00070 st->time_base.den = st->codec->sample_rate;
00071 } else if (mdt == 4) {
00072 vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4);
00073 }
00074
00075 return 1;
00076 }
00077
00078 static int
00079 old_flac_header (AVFormatContext * s, int idx)
00080 {
00081 AVStream *st = s->streams[idx];
00082 st->codec->codec_type = CODEC_TYPE_AUDIO;
00083 st->codec->codec_id = CODEC_ID_FLAC;
00084
00085 return 0;
00086 }
00087
00088 ogg_codec_t flac_codec = {
00089 .magic = "\177FLAC",
00090 .magicsize = 5,
00091 .header = flac_header
00092 };
00093
00094 ogg_codec_t old_flac_codec = {
00095 .magic = "fLaC",
00096 .magicsize = 4,
00097 .header = old_flac_header
00098 };