Commit 4382bc2c authored by Michael Niedermayer's avatar Michael Niedermayer

mp3enc: drop nested structs

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent f2a90c3b
...@@ -163,18 +163,13 @@ AVOutputFormat ff_mp2_muxer = { ...@@ -163,18 +163,13 @@ AVOutputFormat ff_mp2_muxer = {
typedef struct MP3Context { typedef struct MP3Context {
const AVClass *class; const AVClass *class;
int id3v2_version; int id3v2_version;
struct xing_header { int64_t offset;
int64_t offset; int32_t frames;
int32_t frames; int32_t size;
int32_t size; uint32_t want;
/* following lame's "VbrTag.c". */ uint32_t seen;
struct xing_toc { uint32_t pos;
uint32_t want; uint64_t bag[VBR_NUM_BAGS];
uint32_t seen;
uint32_t pos;
uint64_t bag[VBR_NUM_BAGS];
} toc;
} xing_header;
} MP3Context; } MP3Context;
static const AVOption options[] = { static const AVOption options[] = {
...@@ -271,11 +266,11 @@ static int mp3_write_xing(AVFormatContext *s) ...@@ -271,11 +266,11 @@ static int mp3_write_xing(AVFormatContext *s)
avio_wb32(s->pb, MKBETAG('X', 'i', 'n', 'g')); avio_wb32(s->pb, MKBETAG('X', 'i', 'n', 'g'));
avio_wb32(s->pb, 0x01 | 0x02 | 0x04); // frames/size/toc avio_wb32(s->pb, 0x01 | 0x02 | 0x04); // frames/size/toc
mp3->xing_header.offset = avio_tell(s->pb); mp3->offset = avio_tell(s->pb);
mp3->xing_header.size = c.frame_size; mp3->size = c.frame_size;
mp3->xing_header.toc.want=1; mp3->want=1;
mp3->xing_header.toc.seen=0; mp3->seen=0;
mp3->xing_header.toc.pos=0; mp3->pos=0;
avio_wb32(s->pb, 0); // frames avio_wb32(s->pb, 0); // frames
avio_wb32(s->pb, 0); // size avio_wb32(s->pb, 0); // size
...@@ -297,48 +292,44 @@ static int mp3_write_xing(AVFormatContext *s) ...@@ -297,48 +292,44 @@ static int mp3_write_xing(AVFormatContext *s)
static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt) static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt)
{ {
MP3Context *mp3 = s->priv_data; MP3Context *mp3 = s->priv_data;
struct xing_header *xing_header = &mp3->xing_header;
struct xing_toc *toc = &xing_header->toc;
int i; int i;
++xing_header->frames; ++mp3->frames;
xing_header->size += pkt->size; mp3->size += pkt->size;
if (toc->want == ++toc->seen) { if (mp3->want == ++mp3->seen) {
toc->bag[toc->pos] = xing_header->size; mp3->bag[mp3->pos] = mp3->size;
if (VBR_NUM_BAGS == ++toc->pos) { if (VBR_NUM_BAGS == ++mp3->pos) {
/* shrink table to half size by throwing away each second bag. */ /* shrink table to half size by throwing away each second bag. */
for (i = 1; i < VBR_NUM_BAGS; i += 2) for (i = 1; i < VBR_NUM_BAGS; i += 2)
toc->bag[i >> 1] = toc->bag[i]; mp3->bag[i >> 1] = mp3->bag[i];
/* double wanted amount per bag. */ /* double wanted amount per bag. */
toc->want <<= 1; mp3->want <<= 1;
/* adjust current position to half of table size. */ /* adjust current position to half of table size. */
toc->pos >>= 1; mp3->pos >>= 1;
} }
toc->seen = 0; mp3->seen = 0;
} }
} }
static void mp3_fix_xing(AVFormatContext *s) static void mp3_fix_xing(AVFormatContext *s)
{ {
MP3Context *mp3 = s->priv_data; MP3Context *mp3 = s->priv_data;
struct xing_header *xing_header = &mp3->xing_header;
struct xing_toc *toc = &xing_header->toc;
int i; int i;
avio_flush(s->pb); avio_flush(s->pb);
avio_seek(s->pb, xing_header->offset, SEEK_SET); avio_seek(s->pb, mp3->offset, SEEK_SET);
avio_wb32(s->pb, xing_header->frames); avio_wb32(s->pb, mp3->frames);
avio_wb32(s->pb, xing_header->size); avio_wb32(s->pb, mp3->size);
avio_w8(s->pb, 0); // first toc entry has to be zero. avio_w8(s->pb, 0); // first toc entry has to be zero.
for (i = 1; i < VBR_TOC_SIZE; ++i) { for (i = 1; i < VBR_TOC_SIZE; ++i) {
int j = i * toc->pos / VBR_TOC_SIZE; int j = i * mp3->pos / VBR_TOC_SIZE;
int seek_point = 256LL * toc->bag[j] / xing_header->size; int seek_point = 256LL * mp3->bag[j] / mp3->size;
avio_w8(s->pb, FFMIN(seek_point, 255)); avio_w8(s->pb, FFMIN(seek_point, 255));
} }
...@@ -429,7 +420,7 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -429,7 +420,7 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
return 0; return 0;
#endif #endif
if (0 < mp3->xing_header.offset) if (0 < mp3->offset)
mp3_xing_add_frame(s, pkt); mp3_xing_add_frame(s, pkt);
return ff_raw_write_packet(s, pkt); return ff_raw_write_packet(s, pkt);
...@@ -444,7 +435,7 @@ static int mp3_write_trailer(AVFormatContext *s) ...@@ -444,7 +435,7 @@ static int mp3_write_trailer(AVFormatContext *s)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (0 < mp3->xing_header.offset) if (0 < mp3->offset)
mp3_fix_xing(s); mp3_fix_xing(s);
return 0; return 0;
......
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