From patchwork Sat Apr 22 17:26:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3474 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp793206vsd; Sat, 22 Apr 2017 10:26:51 -0700 (PDT) X-Received: by 10.223.149.33 with SMTP id 30mr2366934wrs.20.1492882011508; Sat, 22 Apr 2017 10:26:51 -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 w65si7933144wma.71.2017.04.22.10.26.51; Sat, 22 Apr 2017 10:26:51 -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=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 55BE468922C; Sat, 22 Apr 2017 20:26:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A6D968831A for ; Sat, 22 Apr 2017 20:26:33 +0300 (EEST) Received: by mail-qt0-f195.google.com with SMTP id t52so15579000qtb.3 for ; Sat, 22 Apr 2017 10:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=NY+y6SZ/zuSAEBNt2Aqu56OpLHvqi/M2wZa7xREGXRM=; b=P7atDju4M3O02QbBixHLIubncBE4UP04ZY+Tjt3zztXVow8lNAU2xhkYIaErrIcizb +5bYAORmnl0vCL25a4WNsYMFcX/xfXCMg6Kvx4CziJd8eAMsWiBvkhjMAjfo5ssM+4V6 NGjqSD4XUqpG1K+PFbOtxZUrZLggvShOMosh4d70OyCCEqeFZhzK30btZTBuF6wnbZHo u37i+FKGyV2MAK//OKfw2o8+XsX1InyYR0YMj2hFlxn7JgxNniD21582A4l7TjUZx3Jb pAnz7OgHkDkzuWLQipZRDYRtRZ9UWxtHhb6lmFaKIjOtlwDXdi/sw5AO3FjwVkEvdPe6 3uVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NY+y6SZ/zuSAEBNt2Aqu56OpLHvqi/M2wZa7xREGXRM=; b=c7rBDkdQbQ1dV9kOPYtnZlJNqI0iVsaHrzrb7PgAM9pDUi7QtfIYD99slXWtcZM+J3 /stlicdChoflFfhhGWJTp0OoYj24Bw24dyFAgy3NmQhagZokCXFX0LChLIG1Xw4prpa1 sJcWBVkeUzlh7YZmYeuxQavViWTRpbvKk/k3+LWBTmXxNHLG6z4rXErGHtjRn84wRXKL cxPhgdOlm9levC4qYurFMzoeeqdUPzDymlB/JImRo2xik+CTOp4azrT3Wa71IuqvUKCy jyPiWaJRhBSiqdXWBy9EcKGeF6uhGSapBAiEMSgWoF0zb/CV2XbhaoKRjIMRsWCmIQZp /idw== X-Gm-Message-State: AN3rC/6IOotz/5WtwsUPLx7gxvJz6AkdJiBLK+4gtq5SvnHfG47DoOhG MAGwyUyoeOKtHAt5 X-Received: by 10.200.4.140 with SMTP id s12mr19866353qtg.35.1492881992419; Sat, 22 Apr 2017 10:26:32 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id n5sm8954460qkb.39.2017.04.22.10.26.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Apr 2017 10:26:32 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Apr 2017 14:26:09 -0300 Message-Id: <20170422172609.5292-2-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170422172609.5292-1-jamrial@gmail.com> References: <20170422161538.GV4714@nb4> <20170422172609.5292-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/options: copy the coded_side_data in avcodec_copy_context() 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- libavcodec/options.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libavcodec/options.c b/libavcodec/options.c index b98da9378a..c721aa8d43 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -190,15 +190,21 @@ void avcodec_free_context(AVCodecContext **pavctx) #if FF_API_COPY_CONTEXT static void copy_context_reset(AVCodecContext *avctx) { + int i; + av_opt_free(avctx); av_freep(&avctx->rc_override); av_freep(&avctx->intra_matrix); av_freep(&avctx->inter_matrix); av_freep(&avctx->extradata); av_freep(&avctx->subtitle_header); + for (i = 0; i < avctx->nb_coded_side_data; i++) + av_freep(&avctx->coded_side_data[i].data); + av_freep(&avctx->coded_side_data); av_buffer_unref(&avctx->hw_frames_ctx); avctx->subtitle_header_size = 0; avctx->extradata_size = 0; + avctx->nb_coded_side_data = 0; } int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) @@ -262,6 +268,28 @@ FF_ENABLE_DEPRECATION_WARNINGS alloc_and_copy_or_fail(subtitle_header, src->subtitle_header_size, 1); av_assert0(dest->subtitle_header_size == src->subtitle_header_size); #undef alloc_and_copy_or_fail + if (src->nb_coded_side_data) { + int i; + + dest->nb_coded_side_data = 0; + dest->coded_side_data = av_realloc_array(NULL, src->nb_coded_side_data, + sizeof(*dest->coded_side_data)); + if (!dest->coded_side_data) + goto fail; + + for (i = 0; i < src->nb_coded_side_data; i++) { + const AVPacketSideData *sd_src = &src->coded_side_data[i]; + AVPacketSideData *sd_dst = &dest->coded_side_data[i]; + + sd_dst->data = av_malloc(sd_src->size); + if (!sd_dst->data) + goto fail; + memcpy(sd_dst->data, sd_src->data, sd_src->size); + sd_dst->size = sd_src->size; + sd_dst->type = sd_src->type; + dest->nb_coded_side_data++; + } + } if (src->hw_frames_ctx) { dest->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);