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

libavformat/flacdec.c

Go to the documentation of this file.
00001 /*
00002  * Raw FLAC demuxer
00003  * Copyright (c) 2001 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "raw.h"
00024 #include "id3v2.h"
00025 
00026 static int flac_read_header(AVFormatContext *s,
00027                              AVFormatParameters *ap)
00028 {
00029     uint8_t buf[ID3v2_HEADER_SIZE];
00030     int ret;
00031     AVStream *st = av_new_stream(s, 0);
00032     if (!st)
00033         return AVERROR(ENOMEM);
00034     st->codec->codec_type = CODEC_TYPE_AUDIO;
00035     st->codec->codec_id = CODEC_ID_FLAC;
00036     st->need_parsing = AVSTREAM_PARSE_FULL;
00037     /* the parameters will be extracted from the compressed bitstream */
00038 
00039     /* skip ID3v2 header if found */
00040     ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
00041     if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
00042         int len = ff_id3v2_tag_len(buf);
00043         url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
00044     } else {
00045         url_fseek(s->pb, 0, SEEK_SET);
00046     }
00047     return 0;
00048 }
00049 
00050 static int flac_probe(AVProbeData *p)
00051 {
00052     uint8_t *bufptr = p->buf;
00053     uint8_t *end    = p->buf + p->buf_size;
00054 
00055     if(ff_id3v2_match(bufptr))
00056         bufptr += ff_id3v2_tag_len(bufptr);
00057 
00058     if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
00059     else                                            return AVPROBE_SCORE_MAX/2;
00060 }
00061 
00062 AVInputFormat flac_demuxer = {
00063     "flac",
00064     NULL_IF_CONFIG_SMALL("raw FLAC"),
00065     0,
00066     flac_probe,
00067     flac_read_header,
00068     ff_raw_read_partial_packet,
00069     .flags= AVFMT_GENERIC_INDEX,
00070     .extensions = "flac",
00071     .value = CODEC_ID_FLAC,
00072 };

Generated on Tue Nov 4 2014 12:59:21 for ffmpeg by  doxygen 1.7.1