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
111 uint64_t bag[XING_NUM_BAGS];111 uint64_t bag[XING_NUM_BAGS];
112 int initial_bitrate;112 int initial_bitrate;
113 int has_variable_bitrate;113 int has_variable_bitrate;
114 int delay;
115 int padding;
114 116
115 /* index of the audio stream */117 /* index of the audio stream */
116 int audio_stream_idx;118 int audio_stream_idx;
@@ -247,12 +249,7 @@ static int mp3_write_xing(AVFormatContext *s) · 130 unmodified lines
247 ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields249 ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields
248 avio_w8(dyn_ctx, 0); // unknown encoding flags250 avio_w8(dyn_ctx, 0); // unknown encoding flags
249 avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate251 avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate
250 252 avio_wb24(dyn_ctx, 0); // empty encoder delay/padding
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);
256 253
257 avio_w8(dyn_ctx, 0); // misc254 avio_w8(dyn_ctx, 0); // misc
258 avio_w8(dyn_ctx, 0); // mp3gain255 avio_w8(dyn_ctx, 0); // mp3gain
@@ -345,10 +342,24 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt) · 86 unmodified lines
345#endif342#endif
346 343
347 if (mp3->xing_offset) {344 if (mp3->xing_offset) {
345 uint8_t *side_data = NULL;
346 int side_data_size = 0;
347
348 mp3_xing_add_frame(mp3, pkt);348 mp3_xing_add_frame(mp3, pkt);
349 mp3->audio_size += pkt->size;349 mp3->audio_size += pkt->size;
350 mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE),350 mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE),
351 mp3->audio_crc, pkt->data, pkt->size);351 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 }
352 }363 }
353 }364 }
354 365
@@ -422,6 +433,17 @@ static void mp3_update_xing(AVFormatContext *s) · 67 unmodified lines
422 }433 }
423 }434 }
424 435
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
425 AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size);447 AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size);
426 AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc);448 AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc);
427 449

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