aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-05-04 22:49:00 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-05-04 22:49:00 +0200
commit514917bf1cf48965b276aac0ddb2207b50263977 (patch)
tree1e968f56514e1631f30a3559ef5134833fa8c41c
parent9ae26ef9c3442b9c2cfa2c0f1bc346febd9a9499 (diff)
parent3938b6762132d3d7ef1b5782e7dc8bf73ac8145d (diff)
downloadffmpeg-514917bf1cf48965b276aac0ddb2207b50263977.tar.gz
Merge commit '3938b6762132d3d7ef1b5782e7dc8bf73ac8145d' into release/1.1
* commit '3938b6762132d3d7ef1b5782e7dc8bf73ac8145d': mp3enc: Properly write bitrate value in XING header Conflicts: libavformat/mp3enc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/mp3enc.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index cc9f0d0919..9491b646bc 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -119,15 +119,16 @@ static int mp3_write_xing(AVFormatContext *s)
{
MP3Context *mp3 = s->priv_data;
AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec;
- int bitrate_idx;
- int best_bitrate_idx = -1;
- int best_bitrate_error= INT_MAX;
- int xing_offset;
- int32_t header, mask;
- MPADecodeHeader c;
- int srate_idx, ver = 0, i, channels;
- int needed;
- const char *vendor = (codec->flags & CODEC_FLAG_BITEXACT) ? "Lavf" : LIBAVFORMAT_IDENT;
+ int32_t header;
+ MPADecodeHeader mpah;
+ int srate_idx, i, channels;
+ int bitrate_idx;
+ int best_bitrate_idx = -1;
+ int best_bitrate_error = INT_MAX;
+ int xing_offset;
+ int ver = 0;
+ int bytes_needed, lsf;
+ const char *vendor = (codec->flags & CODEC_FLAG_BITEXACT) ? "Lavf" : LIBAVFORMAT_IDENT;
if (!s->pb->seekable)
return 0;
@@ -159,28 +160,29 @@ static int mp3_write_xing(AVFormatContext *s)
/* dummy MPEG audio header */
header = 0xffU << 24; // sync
header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16; // sync/audio-version/layer 3/no crc*/
- header |= (srate_idx << 2) << 8;
+ header |= (srate_idx << 2) << 8;
header |= channels << 6;
- for (bitrate_idx=1; bitrate_idx<15; bitrate_idx++) {
- int error;
- avpriv_mpegaudio_decode_header(&c, header | (bitrate_idx << (4+8)));
- error= FFABS(c.bit_rate - codec->bit_rate);
- if(error < best_bitrate_error){
- best_bitrate_error= error;
- best_bitrate_idx = bitrate_idx;
+ for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
+ int bit_rate = 1000 * avpriv_mpa_bitrate_tab[lsf][3 - 1][bitrate_idx];
+ int error = FFABS(bit_rate - codec->bit_rate);
+
+ if (error < best_bitrate_error) {
+ best_bitrate_error = error;
+ best_bitrate_idx = bitrate_idx;
}
}
av_assert0(best_bitrate_idx >= 0);
- for (bitrate_idx= best_bitrate_idx;; bitrate_idx++) {
+ for (bitrate_idx = best_bitrate_idx; ; bitrate_idx++) {
+ int32_t mask = bitrate_idx << (4 + 8);
if (15 == bitrate_idx)
return -1;
- mask = bitrate_idx << (4+8);
header |= mask;
- avpriv_mpegaudio_decode_header(&c, header);
- xing_offset=xing_offtbl[c.lsf == 1][c.nb_channels == 1];
- needed = 4 // header
+
+ avpriv_mpegaudio_decode_header(&mpah, header);
+ xing_offset=xing_offtbl[mpah.lsf == 1][mpah.nb_channels == 1];
+ bytes_needed = 4 // header
+ xing_offset
+ 4 // xing tag
+ 4 // frames/size/toc flags
@@ -190,8 +192,9 @@ static int mp3_write_xing(AVFormatContext *s)
+ 24
;
- if (needed <= c.frame_size)
+ if (bytes_needed <= mpah.frame_size)
break;
+
header &= ~mask;
}
@@ -202,7 +205,7 @@ static int mp3_write_xing(AVFormatContext *s)
ffio_wfourcc(s->pb, "Xing");
avio_wb32(s->pb, 0x01 | 0x02 | 0x04); // frames / size / TOC
- mp3->size = c.frame_size;
+ mp3->size = mpah.frame_size;
mp3->want=1;
mp3->seen=0;
mp3->pos=0;
@@ -220,7 +223,7 @@ static int mp3_write_xing(AVFormatContext *s)
avio_w8(s->pb, 0);
avio_wb24(s->pb, FFMAX(codec->delay - 528 - 1, 0)<<12);
- ffio_fill(s->pb, 0, c.frame_size - needed);
+ ffio_fill(s->pb, 0, mpah.frame_size - bytes_needed);
return 0;
}
@@ -260,7 +263,7 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
MP3Context *mp3 = s->priv_data;
if (pkt->data && pkt->size >= 4) {
- MPADecodeHeader c;
+ MPADecodeHeader mpah;
int av_unused base;
uint32_t head = AV_RB32(pkt->data);
@@ -269,16 +272,16 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
"is invalid, writing it anyway.\n", pkt->size, head);
return ff_raw_write_packet(s, pkt);
}
- avpriv_mpegaudio_decode_header(&c, head);
+ avpriv_mpegaudio_decode_header(&mpah, head);
if (!mp3->initial_bitrate)
- mp3->initial_bitrate = c.bit_rate;
- if ((c.bit_rate == 0) || (mp3->initial_bitrate != c.bit_rate))
+ mp3->initial_bitrate = mpah.bit_rate;
+ if ((mpah.bit_rate == 0) || (mp3->initial_bitrate != mpah.bit_rate))
mp3->has_variable_bitrate = 1;
#ifdef FILTER_VBR_HEADERS
/* filter out XING and INFO headers. */
- base = 4 + xing_offtbl[c.lsf == 1][c.nb_channels == 1];
+ base = 4 + xing_offtbl[mpah.lsf == 1][mpah.nb_channels == 1];
if (base + 4 <= pkt->size) {
uint32_t v = AV_RB32(pkt->data + base);