From patchwork Mon Oct 17 21:55:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Toohill X-Patchwork-Id: 1040 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp463120vsd; Mon, 17 Oct 2016 14:55:21 -0700 (PDT) X-Received: by 10.194.122.67 with SMTP id lq3mr14781054wjb.54.1476741321041; Mon, 17 Oct 2016 14:55:21 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n10si34796069wjp.229.2016.10.17.14.55.20; Mon, 17 Oct 2016 14:55:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE7266891E2; Tue, 18 Oct 2016 00:55:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BAEA68049C for ; Tue, 18 Oct 2016 00:55:10 +0300 (EEST) Received: by mail-pa0-f42.google.com with SMTP id ry6so65454344pac.3 for ; Mon, 17 Oct 2016 14:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=COYQDf2wWO7azNm3rIP/pMKahJ2SoPBZaX3o5+C3YUs=; b=MzOAQjlMFaHD+BMRCuyNJbT4CUWJSt6YgVP+mDK9spIHchxddfHXMWf2gIyOOoblJQ eotg6rBK80ozcx33Qmv5Pymr17WKkH2xvpyEqKpFcr5hTTCP0NVxVIJWvRvQzS49x8L0 dhu3fNXVmVp3sTaFueC9DeH8dD8LwTCxfgZW1dW5f5kQ7zh3B3hLUB7LkOpDpZr6W5pb 4nD0wUYfL2gUpt1z6e7fhjHOhQ1gHAqxQd2trQ7RWyJXh989c0SnTZrtgjqkeXIN1g2V XXFg6y00UaWQ1EGVqkDkujg059f/Y49Yw2VZK7K8rbj2NPsHzWtU8wWZgvRwcMZxbaTC D0VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=COYQDf2wWO7azNm3rIP/pMKahJ2SoPBZaX3o5+C3YUs=; b=Da+ksdNfoxQ/f72ETdl+vZ2sN1uqgHJOoF17NZk7vQ8kdiiYvEhGW6kcYSm7toFWYX bg6O5Rp+G6lrcbkCGpGL4w3AlcEkWFYu7mBJcvOwDVQAETpke3F/5wg2ndM5puRERCUd WTHR8qhCTYOJt556Pfeql01ev/yrPANMYJLwtlrCyzpLNgw0xT0/5CikqnuAKPgHb5Sf c7q2NgkQLAvRFM8ToR5iAm/znTHKHEzAmZZK5W2pa0CgkubfKno7luJF+aXZyyT+mdxv svYQq89TLmP31Jz5ef0fM+yYpBNpwU5vOVHJKrDDNwQh52qq31unuNIoVWQp43wVk3ah rLUA== X-Gm-Message-State: AA6/9RmPiP/9EKtg6YOoyCR3qmMnuPotmjpgR+fnP+3cXDZE6z0w5JZBeYHFbqOitqt51o9m X-Received: by 10.66.49.164 with SMTP id v4mr30236438pan.90.1476741310781; Mon, 17 Oct 2016 14:55:10 -0700 (PDT) Received: from mungolini.mtv.corp.google.com ([100.96.2.61]) by smtp.gmail.com with ESMTPSA id y125sm50309404pfg.61.2016.10.17.14.55.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 14:55:10 -0700 (PDT) From: Jon Toohill To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Oct 2016 14:55:03 -0700 Message-Id: <1476741304-16328-2-git-send-email-jtoohill@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1476741304-16328-1-git-send-email-jtoohill@google.com> References: <1475696257-12390-1-git-send-email-jtoohill@google.com> <1476741304-16328-1-git-send-email-jtoohill@google.com> Subject: [FFmpeg-devel] [PATCH 1/2] lavc/libmp3lame: send encoder delay/padding in packet side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Jon Toohill MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/libmp3lame.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..e55aa85 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -50,6 +50,7 @@ typedef struct LAMEContext { int reservoir; int joint_stereo; int abr; + int delay_sent; float *samples_flt[2]; AudioFrameQueue afq; AVFloatDSPContext *fdsp; @@ -185,7 +186,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { LAMEContext *s = avctx->priv_data; MPADecodeHeader hdr; - int len, ret, ch; + int len, ret, ch, discard_padding; int lame_result; uint32_t h; @@ -269,6 +270,30 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); + discard_padding = avctx->frame_size - avpkt->duration; + // Check if subtraction resulted in an overflow + if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { + av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); + av_packet_unref(avpkt); + av_free(avpkt); + return AVERROR(EINVAL); + } + if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) { + uint8_t* side_data = av_packet_new_side_data(avpkt, + AV_PKT_DATA_SKIP_SAMPLES, + 10); + if(!side_data) { + av_packet_unref(avpkt); + av_free(avpkt); + return AVERROR(ENOMEM); + } + if (!s->delay_sent) { + AV_WL32(side_data, avctx->initial_padding); + s->delay_sent = 1; + } + AV_WL32(side_data + 4, discard_padding); + } + avpkt->size = len; *got_packet_ptr = 1; }