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
50 int reservoir;50 int reservoir;
51 int joint_stereo;51 int joint_stereo;
52 int abr;52 int abr;
53 int delay_sent;
53 float *samples_flt[2];54 float *samples_flt[2];
54 AudioFrameQueue afq;55 AudioFrameQueue afq;
55 AVFloatDSPContext *fdsp;56 AVFloatDSPContext *fdsp;
@@ -185,7 +186,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 129 unmodified lines
185{186{
186 LAMEContext *s = avctx->priv_data;187 LAMEContext *s = avctx->priv_data;
187 MPADecodeHeader hdr;188 MPADecodeHeader hdr;
188 int len, ret, ch;189 int len, ret, ch, discard_padding;
189 int lame_result;190 int lame_result;
190 uint32_t h;191 uint32_t h;
191 192
@@ -269,6 +270,30 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 77 unmodified lines
269 ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,270 ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,
270 &avpkt->duration);271 &avpkt->duration);
271 272
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
272 avpkt->size = len;297 avpkt->size = len;
273 *got_packet_ptr = 1;298 *got_packet_ptr = 1;
274 }299 }

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