History

lavc/libmp3lame: send encoder delay/padding in packet side data

Jon Toohill committed 10 years ago

Commit 81f4f781 parent d3be1861 file · +26 −1Browse files

Unified · Split

libavcodec/libmp3lame.c+26−1
@@ -50,6 +50,7 @@ typedef struct LAMEContext { · 49 unmodified lines
5050 int reservoir;
5151 int joint_stereo;
5252 int abr;
53+ int delay_sent;
5354 float *samples_flt[2];
5455 AudioFrameQueue afq;
5556 AVFloatDSPContext *fdsp;
@@ -185,7 +186,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 129 unmodified lines
185186 {
186187 LAMEContext *s = avctx->priv_data;
187188 MPADecodeHeader hdr;
188− int len, ret, ch;
189+ int len, ret, ch, discard_padding;
189190 int lame_result;
190191 uint32_t h;
191192
@@ -269,6 +270,30 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 77 unmodified lines
269270 ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,
270271 &avpkt->duration);
271272
273+ discard_padding = avctx->frame_size - avpkt->duration;
274+ // Check if subtraction resulted in an overflow
275+ if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) {
276+ av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n");
277+ av_packet_unref(avpkt);
278+ av_free(avpkt);
279+ return AVERROR(EINVAL);
280+ }
281+ if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) {
282+ uint8_t* side_data = av_packet_new_side_data(avpkt,
283+ AV_PKT_DATA_SKIP_SAMPLES,
284+ 10);
285+ if(!side_data) {
286+ av_packet_unref(avpkt);
287+ av_free(avpkt);
288+ return AVERROR(ENOMEM);
289+ }
290+ if (!s->delay_sent) {
291+ AV_WL32(side_data, avctx->initial_padding);
292+ s->delay_sent = 1;
293+ }
294+ AV_WL32(side_data + 4, discard_padding);
295+ }
296+
272297 avpkt->size = len;
273298 *got_packet_ptr = 1;
274299 }

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