Commit cdc166ac authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '32d05934'

* commit '32d05934':
  mp3dec: decode more data from Info header

Conflicts:
	libavformat/mp3dec.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a8d01a73 32d05934
...@@ -105,6 +105,8 @@ void ffio_init_checksum(AVIOContext *s, ...@@ -105,6 +105,8 @@ void ffio_init_checksum(AVIOContext *s,
unsigned long ffio_get_checksum(AVIOContext *s); unsigned long ffio_get_checksum(AVIOContext *s);
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
unsigned int len); unsigned int len);
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
unsigned int len);
/** /**
* Open a write only packetized memory stream with a maximum packet * Open a write only packetized memory stream with a maximum packet
......
...@@ -469,6 +469,12 @@ unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, ...@@ -469,6 +469,12 @@ unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len); return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
} }
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
unsigned int len)
{
return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
}
unsigned long ffio_get_checksum(AVIOContext *s) unsigned long ffio_get_checksum(AVIOContext *s)
{ {
s->checksum = s->update_checksum(s->checksum, s->checksum_ptr, s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
......
...@@ -22,10 +22,12 @@ ...@@ -22,10 +22,12 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/crc.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h"
#include "id3v2.h" #include "id3v2.h"
#include "id3v1.h" #include "id3v1.h"
#include "replaygain.h" #include "replaygain.h"
...@@ -120,11 +122,20 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration ...@@ -120,11 +122,20 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration
mp3->xing_toc = 1; mp3->xing_toc = 1;
} }
static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
MPADecodeHeader *c, uint32_t spf) MPADecodeHeader *c, uint32_t spf)
{ {
#define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
#define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m)))
uint16_t crc;
uint32_t v; uint32_t v;
char version[10];
uint32_t peak = 0;
int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
MP3DecContext *mp3 = s->priv_data; MP3DecContext *mp3 = s->priv_data;
static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
...@@ -132,24 +143,67 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, ...@@ -132,24 +143,67 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]); 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'); mp3->is_cbr = v == MKBETAG('I', 'n', 'f', 'o');
if (v == MKBETAG('X', 'i', 'n', 'g') || mp3->is_cbr) { if (v != MKBETAG('X', 'i', 'n', 'g') && !mp3->is_cbr)
return;
v = avio_rb32(s->pb); v = avio_rb32(s->pb);
if (v & XING_FLAG_FRAMES) if (v & XING_FLAG_FRAMES)
mp3->frames = avio_rb32(s->pb); mp3->frames = avio_rb32(s->pb);
if (v & XING_FLAG_SIZE) if (v & XING_FLAG_SIZE)
mp3->header_filesize = avio_rb32(s->pb); mp3->header_filesize = avio_rb32(s->pb);
if (v & XING_FLAG_TOC) if (v & XING_FLAG_TOC)
read_xing_toc(s, mp3->header_filesize, read_xing_toc(s, mp3->header_filesize, av_rescale_q(mp3->frames,
av_rescale_q(mp3->frames,
(AVRational){spf, c->sample_rate}, (AVRational){spf, c->sample_rate},
st->time_base)); st->time_base));
/* VBR quality */
if(v & 8) if(v & 8)
avio_skip(s->pb, 4); avio_skip(s->pb, 4);
/* Encoder short version string */
memset(version, 0, sizeof(version));
avio_read(s->pb, version, 9);
/* Info Tag revision + VBR method */
avio_r8(s->pb);
/* Lowpass filter value */
avio_r8(s->pb);
/* ReplayGain peak */
v = avio_rb32(s->pb); v = avio_rb32(s->pb);
if(v == MKBETAG('L', 'A', 'M', 'E') || v == MKBETAG('L', 'a', 'v', 'f')) { peak = av_rescale(v, 100000, 1 << 23);
avio_skip(s->pb, 21-4);
/* Radio ReplayGain */
v = avio_rb16(s->pb);
if (MIDDLE_BITS(v, 13, 15) == 1) {
r_gain = MIDDLE_BITS(v, 0, 8) * 10000;
if (v & (1 << 9))
r_gain *= -1;
}
/* Audiophile ReplayGain */
v = avio_rb16(s->pb);
if (MIDDLE_BITS(v, 13, 15) == 2) {
a_gain = MIDDLE_BITS(v, 0, 8) * 10000;
if (v & (1 << 9))
a_gain *= -1;
}
/* Encoding flags + ATH Type */
avio_r8(s->pb);
/* if ABR {specified bitrate} else {minimal bitrate} */
avio_r8(s->pb);
/* Encoder delays */
v= avio_rb24(s->pb); v= avio_rb24(s->pb);
if(AV_RB32(version) == MKBETAG('L', 'A', 'M', 'E')
|| AV_RB32(version) == MKBETAG('L', 'a', 'v', 'f')) {
mp3->start_pad = v>>12; mp3->start_pad = v>>12;
mp3-> end_pad = v&4095; mp3-> end_pad = v&4095;
st->skip_samples = mp3->start_pad + 528 + 1; st->skip_samples = mp3->start_pad + 528 + 1;
...@@ -159,6 +213,29 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, ...@@ -159,6 +213,29 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
st->time_base); st->time_base);
av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad); av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad);
} }
/* Misc */
avio_r8(s->pb);
/* MP3 gain */
avio_r8(s->pb);
/* Preset and surround info */
avio_rb16(s->pb);
/* Music length */
avio_rb32(s->pb);
/* Music CRC */
avio_rb16(s->pb);
/* Info Tag CRC */
crc = ffio_get_checksum(s->pb);
v = avio_rb16(s->pb);
if (v == crc) {
ff_replaygain_export_raw(st, r_gain, peak, a_gain, 0);
av_dict_set(&st->metadata, "encoder", version, 0);
} }
} }
...@@ -191,6 +268,8 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) ...@@ -191,6 +268,8 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
int vbrtag_size = 0; int vbrtag_size = 0;
MP3DecContext *mp3 = s->priv_data; MP3DecContext *mp3 = s->priv_data;
ffio_init_checksum(s->pb, ff_crcA001_update, 0);
v = avio_rb32(s->pb); v = avio_rb32(s->pb);
if(ff_mpa_check_header(v) < 0) if(ff_mpa_check_header(v) < 0)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment