Separate the raw FLAC demuxer from raw.c and put in a new file,

flacdec.c.

Originally committed as revision 17660 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Justin Ruggles 2009-02-28 17:24:46 +00:00
parent 2d243fb3fc
commit 81f052cb7d
5 changed files with 94 additions and 58 deletions

View File

@ -247,6 +247,7 @@ Muxers/Demuxers:
dv.c Roman Shaposhnik
dxa.c Kostya Shishkov
ffm* Baptiste Coudurier
flac* Justin Ruggles
flic.c Mike Melanson
flvdec.c, flvenc.c Michael Niedermayer
gxf.c Reimar Doeffinger

View File

@ -53,7 +53,7 @@ OBJS-$(CONFIG_EAC3_DEMUXER) += raw.o id3v2.o
OBJS-$(CONFIG_EAC3_MUXER) += raw.o
OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o
OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o
OBJS-$(CONFIG_FLAC_DEMUXER) += raw.o id3v2.o
OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o raw.o id3v2.o
OBJS-$(CONFIG_FLAC_MUXER) += flacenc.o
OBJS-$(CONFIG_FLIC_DEMUXER) += flic.o
OBJS-$(CONFIG_FLV_DEMUXER) += flvdec.o

72
libavformat/flacdec.c Normal file
View File

@ -0,0 +1,72 @@
/*
* Raw FLAC demuxer
* Copyright (c) 2001 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "raw.h"
#include "id3v2.h"
static int flac_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
uint8_t buf[ID3v2_HEADER_SIZE];
int ret;
AVStream *st = av_new_stream(s, 0);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = CODEC_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_FLAC;
st->need_parsing = AVSTREAM_PARSE_FULL;
/* the parameters will be extracted from the compressed bitstream */
/* skip ID3v2 header if found */
ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
int len = ff_id3v2_tag_len(buf);
url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
} else {
url_fseek(s->pb, 0, SEEK_SET);
}
return 0;
}
static int flac_probe(AVProbeData *p)
{
uint8_t *bufptr = p->buf;
uint8_t *end = p->buf + p->buf_size;
if(ff_id3v2_match(bufptr))
bufptr += ff_id3v2_tag_len(bufptr);
if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
else return AVPROBE_SCORE_MAX/2;
}
AVInputFormat flac_demuxer = {
"flac",
NULL_IF_CONFIG_SMALL("raw FLAC"),
0,
flac_probe,
flac_read_header,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "flac",
.value = CODEC_ID_FLAC,
};

View File

@ -130,7 +130,7 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
@ -258,17 +258,6 @@ static int audio_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL;
/* the parameters will be extracted from the compressed bitstream */
if(st->codec->codec_id == CODEC_ID_FLAC) {
/* skip ID3v2 header if found */
uint8_t buf[ID3v2_HEADER_SIZE];
int ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
int len = ff_id3v2_tag_len(buf);
url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
} else {
url_fseek(s->pb, 0, SEEK_SET);
}
}
return 0;
}
@ -593,20 +582,6 @@ static int eac3_probe(AVProbeData *p)
}
#endif
#if CONFIG_FLAC_DEMUXER
static int flac_probe(AVProbeData *p)
{
uint8_t *bufptr = p->buf;
uint8_t *end = p->buf + p->buf_size;
if(ff_id3v2_match(bufptr))
bufptr += ff_id3v2_tag_len(bufptr);
if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
else return AVPROBE_SCORE_MAX/2;
}
#endif
#if CONFIG_AAC_DEMUXER
static int adts_aac_probe(AVProbeData *p)
{
@ -655,7 +630,7 @@ AVInputFormat aac_demuxer = {
0,
adts_aac_probe,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "aac",
.value = CODEC_ID_AAC,
@ -669,7 +644,7 @@ AVInputFormat ac3_demuxer = {
0,
ac3_probe,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "ac3",
.value = CODEC_ID_AC3,
@ -698,7 +673,7 @@ AVInputFormat dirac_demuxer = {
0,
dirac_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.value = CODEC_ID_DIRAC,
};
@ -726,7 +701,7 @@ AVInputFormat dnxhd_demuxer = {
0,
dnxhd_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.value = CODEC_ID_DNXHD,
};
@ -754,7 +729,7 @@ AVInputFormat dts_demuxer = {
0,
dts_probe,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "dts",
.value = CODEC_ID_DTS,
@ -783,7 +758,7 @@ AVInputFormat eac3_demuxer = {
0,
eac3_probe,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "eac3",
.value = CODEC_ID_EAC3,
@ -805,20 +780,6 @@ AVOutputFormat eac3_muxer = {
};
#endif
#if CONFIG_FLAC_DEMUXER
AVInputFormat flac_demuxer = {
"flac",
NULL_IF_CONFIG_SMALL("raw FLAC"),
0,
flac_probe,
audio_read_header,
raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "flac",
.value = CODEC_ID_FLAC,
};
#endif
#if CONFIG_GSM_DEMUXER
AVInputFormat gsm_demuxer = {
"gsm",
@ -826,7 +787,7 @@ AVInputFormat gsm_demuxer = {
0,
NULL,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "gsm",
.value = CODEC_ID_GSM,
@ -840,7 +801,7 @@ AVInputFormat h261_demuxer = {
0,
h261_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "h261",
.value = CODEC_ID_H261,
@ -869,7 +830,7 @@ AVInputFormat h263_demuxer = {
0,
h263_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
// .extensions = "h263", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_H263,
@ -898,7 +859,7 @@ AVInputFormat h264_demuxer = {
0,
h264_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_H264,
@ -941,7 +902,7 @@ AVInputFormat m4v_demuxer = {
0,
mpeg4video_probe, /** probing for MPEG-4 data */
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "m4v",
.value = CODEC_ID_MPEG4,
@ -970,7 +931,7 @@ AVInputFormat mjpeg_demuxer = {
0,
NULL,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "mjpg,mjpeg",
.value = CODEC_ID_MJPEG,
@ -999,7 +960,7 @@ AVInputFormat mlp_demuxer = {
0,
NULL,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "mlp",
.value = CODEC_ID_MLP,
@ -1043,7 +1004,7 @@ AVInputFormat mpegvideo_demuxer = {
0,
mpegvideo_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.value = CODEC_ID_MPEG1VIDEO,
};
@ -1056,7 +1017,7 @@ AVInputFormat cavsvideo_demuxer = {
0,
cavsvideo_probe,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.value = CODEC_ID_CAVS,
};
@ -1132,7 +1093,7 @@ AVInputFormat shorten_demuxer = {
0,
NULL,
audio_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "shn",
.value = CODEC_ID_SHORTEN,
@ -1146,7 +1107,7 @@ AVInputFormat vc1_demuxer = {
0,
NULL /* vc1_probe */,
video_read_header,
raw_read_partial_packet,
ff_raw_read_partial_packet,
.extensions = "vc1",
.value = CODEC_ID_VC1,
};

View File

@ -27,4 +27,6 @@
int pcm_read_seek(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags);
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt);
#endif /* AVFORMAT_RAW_H */