[FFmpeg-cvslog] lavf: stop using avpriv_flac_parse_streaminfo()
Anton Khirnov
git at videolan.org
Thu Nov 6 13:53:29 CET 2014
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Aug 28 10:13:25 2014 +0000| [7784f47762d59e859b4d0f74b3e021ad9368ee2c] | committer: Anton Khirnov
lavf: stop using avpriv_flac_parse_streaminfo()
The only parameters needed by the demuxers are the sample rate and sample
count, which can be trivially extracted manually, without resorting to
an avpriv function.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7784f47762d59e859b4d0f74b3e021ad9368ee2c
---
libavcodec/Makefile | 4 +---
libavformat/flacdec.c | 19 +++++++++++--------
libavformat/oggparseflac.c | 11 +++++++----
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b6a0c36..6270997 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -567,8 +567,6 @@ OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o
OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o \
ac3tab.o
-OBJS-$(CONFIG_FLAC_DEMUXER) += flac.o flacdata.o \
- xiph.o
OBJS-$(CONFIG_FLAC_MUXER) += flac.o flacdata.o
OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o
OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o
@@ -588,7 +586,7 @@ OBJS-$(CONFIG_MOV_MUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_MPEGTS_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
-OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \
+OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o \
mpeg12data.o \
dirac.o
OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index e044fd0..8abdd9d 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -27,7 +27,6 @@
#include "oggdec.h"
#include "vorbiscomment.h"
#include "replaygain.h"
-#include "libavcodec/bytestream.h"
static int flac_read_header(AVFormatContext *s)
{
@@ -76,7 +75,9 @@ static int flac_read_header(AVFormatContext *s)
}
if (metadata_type == FLAC_METADATA_TYPE_STREAMINFO) {
- FLACStreaminfo si;
+ uint32_t samplerate;
+ uint64_t samples;
+
/* STREAMINFO can only occur once */
if (found_streaminfo) {
av_freep(&buffer);
@@ -91,14 +92,16 @@ static int flac_read_header(AVFormatContext *s)
st->codec->extradata_size = metadata_size;
buffer = NULL;
- /* get codec params from STREAMINFO header */
- avpriv_flac_parse_streaminfo(st->codec, &si, st->codec->extradata);
+ /* get sample rate and sample count from STREAMINFO header;
+ * other parameters will be extracted by the parser */
+ samplerate = AV_RB24(st->codec->extradata + 10) >> 4;
+ samples = (AV_RB64(st->codec->extradata + 13) >> 24) & ((1ULL << 36) - 1);
/* set time base and duration */
- if (si.samplerate > 0) {
- avpriv_set_pts_info(st, 64, 1, si.samplerate);
- if (si.samples > 0)
- st->duration = si.samples;
+ if (samplerate > 0) {
+ avpriv_set_pts_info(st, 64, 1, samplerate);
+ if (samples > 0)
+ st->duration = samples;
}
} else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) {
uint8_t isrc[13];
diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index f9c15f9..57bba68 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -34,7 +34,6 @@ flac_header (AVFormatContext * s, int idx)
struct ogg_stream *os = ogg->streams + idx;
AVStream *st = s->streams[idx];
GetBitContext gb;
- FLACStreaminfo si;
int mdt;
if (os->buf[os->pstart] == 0xff)
@@ -46,6 +45,8 @@ flac_header (AVFormatContext * s, int idx)
if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
+ uint32_t samplerate;
+
skip_bits_long(&gb, 4*8); /* "FLAC" */
if(get_bits(&gb, 8) != 1) /* unsupported major version */
return -1;
@@ -56,8 +57,6 @@ flac_header (AVFormatContext * s, int idx)
if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
return -1;
- avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
-
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = AV_CODEC_ID_FLAC;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
@@ -67,7 +66,11 @@ flac_header (AVFormatContext * s, int idx)
memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);
st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
- avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ samplerate = AV_RB24(st->codec->extradata + 10) >> 4;
+ if (!samplerate)
+ return AVERROR_INVALIDDATA;
+
+ avpriv_set_pts_info(st, 64, 1, samplerate);
} else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 4, os->psize - 4);
}
More information about the ffmpeg-cvslog
mailing list