---
libavformat/mp3dec.c | 96 ++++++++++++++++++++++++++++++----------------------
1 file changed, 55 insertions(+), 41 deletions(-)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 5aee21f..d8ad08f 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -58,65 +58,76 @@ static int mp3_read_probe(AVProbeData *p)
AVCodecContext avctx;
buf0 = p->buf;
- end = p->buf + p->buf_size - sizeof(uint32_t);
- while(buf0 < end && !*buf0)
+ end = p->buf + p->buf_size - sizeof(uint32_t);
+ while (buf0 < end && !*buf0)
buf0++;
max_frames = 0;
- buf = buf0;
+ buf = buf0;
- for(; buf < end; buf= buf2+1) {
+ for (; buf < end; buf = buf2 + 1) {
buf2 = buf;
- for(frames = 0; buf2 < end; frames++) {
+ for (frames = 0; buf2 < end; frames++) {
header = AV_RB32(buf2);
- fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate,
&sample_rate, &sample_rate, &sample_rate);
- if(fsize < 0)
+ fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate,
+ &sample_rate, &sample_rate,
+ &sample_rate);
+ if (fsize < 0)
break;
buf2 += fsize;
}
max_frames = FFMAX(max_frames, frames);
- if(buf == buf0)
- first_frames= frames;
+ if (buf == buf0)
+ first_frames = frames;
}
// keep this in sync with ac3 probe, both need to avoid
// issues with MPEG-files!
- if (first_frames >= 4) return AVPROBE_SCORE_EXTENSION + 1;
+ if (first_frames >= 4)
+ return AVPROBE_SCORE_EXTENSION + 1;
if (max_frames) {
- int pes = 0, i;
+ int pes = 0, i;
unsigned int code = -1;
#define VIDEO_ID 0x000001e0
#define AUDIO_ID 0x000001c0
/* do a search for mpegps headers to be able to properly bias
* towards mpegps if we detect this stream as both. */
- for (i = 0; i<p->buf_size; i++) {
+ for (i = 0; i < p->buf_size; i++) {
code = (code << 8) + p->buf[i];
if ((code & 0xffffff00) == 0x100) {
- if ((code & 0x1f0) == VIDEO_ID) pes++;
- else if((code & 0x1e0) == AUDIO_ID) pes++;
+ if ((code & 0x1f0) == VIDEO_ID)
+ pes++;
+ else if ((code & 0x1e0) == AUDIO_ID)
+ pes++;
}
}
if (pes)
max_frames = (max_frames + pes - 1) / pes;
}
- if (max_frames > 500) return AVPROBE_SCORE_EXTENSION;
- else if (max_frames >= 4) return AVPROBE_SCORE_EXTENSION / 2;
- else if (max_frames >= 1) return 1;
- else return 0;
+ if (max_frames > 500)
+ return AVPROBE_SCORE_EXTENSION;
+ else if (max_frames >= 4)
+ return AVPROBE_SCORE_EXTENSION / 2;
+ else if (max_frames >= 1)
+ return 1;
+ else
+ return 0;
//mpegps_mp3_unrecognized_format.mpg has max_frames=3
}
-static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t
duration)
+static void read_xing_toc(AVFormatContext *s, int64_t filesize,
+ int64_t duration)
{
int i;
MP3DecContext *mp3 = s->priv_data;
if (!filesize &&
!(filesize = avio_size(s->pb))) {
- av_log(s, AV_LOG_WARNING, "Cannot determine file size, skipping TOC
table.\n");
+ av_log(s, AV_LOG_WARNING,
+ "Cannot determine file size, skipping TOC table.\n");
return;
}
@@ -142,15 +153,15 @@ static void mp3_parse_info_tag(AVFormatContext *s,
AVStream *st,
char version[10];
- uint32_t peak = 0;
- int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
+ uint32_t peak = 0;
+ int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
- MP3DecContext *mp3 = s->priv_data;
- const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
+ MP3DecContext *mp3 = s->priv_data;
+ const int64_t xing_offtbl[2][2] = { { 32, 17 }, { 17, 9 } };
/* Check for Xing / Info tag */
avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
- v = avio_rb32(s->pb);
+ v = avio_rb32(s->pb);
mp3->is_cbr = v == MKBETAG('I', 'n', 'f', 'o');
if (v != MKBETAG('X', 'i', 'n', 'g') && !mp3->is_cbr)
return;
@@ -162,8 +173,9 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream
*st,
mp3->size = avio_rb32(s->pb);
if (v & XING_FLAG_TOC && mp3->frames)
read_xing_toc(s, mp3->size, av_rescale_q(mp3->frames,
- (AVRational){spf, c->sample_rate},
- st->time_base));
+ (AVRational) {spf,
+ c->sample_rate
},
+ st->time_base));
/* VBR quality */
if (v & XING_FLAC_QSCALE)
@@ -250,7 +262,7 @@ static void mp3_parse_vbri_tag(AVFormatContext *s, AVStream
*st, int64_t base)
if (avio_rb16(s->pb) == 1) {
/* skip delay and quality */
avio_skip(s->pb, 4);
- mp3->size = avio_rb32(s->pb);
+ mp3->size = avio_rb32(s->pb);
mp3->frames = avio_rb32(s->pb);
}
}
@@ -263,18 +275,18 @@ static int mp3_parse_vbr_tags(AVFormatContext *s,
AVStream *st, int64_t base)
{
uint32_t v, spf;
MPADecodeHeader c;
- int vbrtag_size = 0;
+ int vbrtag_size = 0;
MP3DecContext *mp3 = s->priv_data;
ffio_init_checksum(s->pb, ff_crcA001_update, 0);
v = avio_rb32(s->pb);
- if(ff_mpa_check_header(v) < 0)
- return -1;
+ if (ff_mpa_check_header(v) < 0)
+ return -1;
if (avpriv_mpegaudio_decode_header(&c, v) == 0)
vbrtag_size = c.frame_size;
- if(c.layer != 3)
+ if (c.layer != 3)
return -1;
spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
@@ -292,10 +304,12 @@ static int mp3_parse_vbr_tags(AVFormatContext *s,
AVStream *st, int64_t base)
avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
if (mp3->frames)
- st->duration = av_rescale_q(mp3->frames, (AVRational){spf,
c.sample_rate},
+ st->duration = av_rescale_q(mp3->frames,
+ (AVRational) {spf, c.sample_rate },
st->time_base);
if (mp3->size && mp3->frames && !mp3->is_cbr)
- st->codec->bit_rate = av_rescale(mp3->size, 8 * c.sample_rate,
mp3->frames * (int64_t)spf);
+ st->codec->bit_rate = av_rescale(mp3->size, 8 * c.sample_rate,
+ mp3->frames * (int64_t)spf);
return 0;
}
@@ -311,9 +325,9 @@ static int mp3_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codec->codec_id = AV_CODEC_ID_MP3;
- st->need_parsing = AVSTREAM_PARSE_FULL;
- st->start_time = 0;
+ st->codec->codec_id = AV_CODEC_ID_MP3;
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+ st->start_time = 0;
// lcm of all mp3 sample rates
avpriv_set_pts_info(st, 64, 1, 14112000);
@@ -351,7 +365,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket
*pkt)
ret -= ID3v1_TAG_SIZE;
/* note: we need to modify the packet size here to handle the last
- packet */
+ * packet */
pkt->size = ret;
return ret;
}
@@ -361,8 +375,8 @@ static int mp3_seek(AVFormatContext *s, int stream_index,
int64_t timestamp,
{
MP3DecContext *mp3 = s->priv_data;
AVIndexEntry *ie;
- AVStream *st = s->streams[0];
- int64_t ret = av_index_search_timestamp(st, timestamp, flags);
+ AVStream *st = s->streams[0];
+ int64_t ret = av_index_search_timestamp(st, timestamp, flags);
uint32_t header = 0;
if (!mp3->xing_toc)
@@ -371,7 +385,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index,
int64_t timestamp,
if (ret < 0)
return ret;
- ie = &st->index_entries[ret];
+ ie = &st->index_entries[ret];
ret = avio_seek(s->pb, ie->pos, SEEK_SET);
if (ret < 0)
return ret;
--
2.1.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel