History

lavf/mp3enc: write encoder delay/padding upon closing

Jon Toohill committed 10 years ago

Commit 3b02f6d1 parent 81f4f781 file · +28 −6Browse files

Unified · Split

libavformat/mp3enc.c+28−6
@@ -111,6 +111,8 @@ typedef struct MP3Context { · 110 unmodified lines
111111 uint64_t bag[XING_NUM_BAGS];
112112 int initial_bitrate;
113113 int has_variable_bitrate;
114+ int delay;
115+ int padding;
114116
115117 /* index of the audio stream */
116118 int audio_stream_idx;
@@ -247,12 +249,7 @@ static int mp3_write_xing(AVFormatContext *s) · 130 unmodified lines
247249 ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields
248250 avio_w8(dyn_ctx, 0); // unknown encoding flags
249251 avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate
250−
251− // encoder delay
252− if (par->initial_padding - 528 - 1 >= 1 << 12) {
253− av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n");
254− }
255− avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12);
252+ avio_wb24(dyn_ctx, 0); // empty encoder delay/padding
256253
257254 avio_w8(dyn_ctx, 0); // misc
258255 avio_w8(dyn_ctx, 0); // mp3gain
@@ -345,10 +342,24 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt) · 86 unmodified lines
345342 #endif
346343
347344 if (mp3->xing_offset) {
345+ uint8_t *side_data = NULL;
346+ int side_data_size = 0;
347+
348348 mp3_xing_add_frame(mp3, pkt);
349349 mp3->audio_size += pkt->size;
350350 mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE),
351351 mp3->audio_crc, pkt->data, pkt->size);
352+
353+ side_data = av_packet_get_side_data(pkt,
354+ AV_PKT_DATA_SKIP_SAMPLES,
355+ &side_data_size);
356+ if (side_data && side_data_size >= 10) {
357+ mp3->padding = FFMAX(AV_RL32(side_data + 4) + 528 + 1, 0);
358+ if (!mp3->delay)
359+ mp3->delay = FFMAX(AV_RL32(side_data) - 528 - 1, 0);
360+ } else {
361+ mp3->padding = 0;
362+ }
352363 }
353364 }
354365
@@ -422,6 +433,17 @@ static void mp3_update_xing(AVFormatContext *s) · 67 unmodified lines
422433 }
423434 }
424435
436+ /* write encoder delay/padding */
437+ if (mp3->delay >= 1 << 12) {
438+ mp3->delay = (1 << 12) - 1;
439+ av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n");
440+ }
441+ if (mp3->padding >= 1 << 12) {
442+ mp3->padding = (1 << 12) - 1;
443+ av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n");
444+ }
445+ AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (mp3->delay << 12) + mp3->padding);
446+
425447 AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size);
426448 AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc);
427449

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t