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

libavformat/oggparseflac.c

Go to the documentation of this file.
00001 /*
00002  *    Copyright (C) 2005  Matthieu CASTET
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <stdlib.h>
00022 #include "libavcodec/get_bits.h"
00023 #include "libavcodec/flac.h"
00024 #include "avformat.h"
00025 #include "internal.h"
00026 #include "oggdec.h"
00027 
00028 #define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
00029 
00030 static int
00031 flac_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     GetBitContext gb;
00037     FLACStreaminfo si;
00038     int mdt;
00039 
00040     if (os->buf[os->pstart] == 0xff)
00041         return 0;
00042 
00043     init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
00044     skip_bits1(&gb); /* metadata_last */
00045     mdt = get_bits(&gb, 7);
00046 
00047     if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
00048         uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
00049         skip_bits_long(&gb, 4*8); /* "FLAC" */
00050         if(get_bits(&gb, 8) != 1) /* unsupported major version */
00051             return -1;
00052         skip_bits_long(&gb, 8 + 16); /* minor version + header count */
00053         skip_bits_long(&gb, 4*8); /* "fLaC" */
00054 
00055         /* METADATA_BLOCK_HEADER */
00056         if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
00057             return -1;
00058 
00059         avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
00060 
00061         st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00062         st->codec->codec_id = CODEC_ID_FLAC;
00063 
00064         st->codec->extradata =
00065             av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
00066         memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);
00067         st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
00068 
00069         avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
00070     } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
00071         ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4);
00072     }
00073 
00074     return 1;
00075 }
00076 
00077 static int
00078 old_flac_header (AVFormatContext * s, int idx)
00079 {
00080     AVStream *st = s->streams[idx];
00081     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00082     st->codec->codec_id = CODEC_ID_FLAC;
00083 
00084     return 0;
00085 }
00086 
00087 const struct ogg_codec ff_flac_codec = {
00088     .magic = "\177FLAC",
00089     .magicsize = 5,
00090     .header = flac_header
00091 };
00092 
00093 const struct ogg_codec ff_old_flac_codec = {
00094     .magic = "fLaC",
00095     .magicsize = 4,
00096     .header = old_flac_header
00097 };
Generated on Thu Jan 24 2013 17:08:55 for Libav by doxygen 1.7.1