From patchwork Wed Jul 26 00:10:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 4455 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp159466vsb; Tue, 25 Jul 2017 17:11:04 -0700 (PDT) X-Received: by 10.223.164.13 with SMTP id d13mr12339816wra.58.1501027864467; Tue, 25 Jul 2017 17:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501027864; cv=none; d=google.com; s=arc-20160816; b=EbY9w0pyvAhWnuAGE2MTPLSVVD83/1sY1Y+3JOZClalUMIgCwsvPSTGPyYgZa4T7X5 Xxwwheg+HBw8SlqCIVEcUHElCEkjCHSKaWsIksADTSZ9Zycmjq5VjR1ymgCmQCglnVdp IacidYUryx8mXHbI/1Tly/Ncdw9hC2h+RV2u7YmlsrGehF7DaahRf+HKy3cKEL2xJOel Lb7BfrTkN7MWa+Q7bPUfCX+H/9EKjulQkWP5ZZVViDYd/CpUnC8wawM2+2h1lCN4XtXw LxLS3N9xukC+pjgmgziDJV0IXKiFkzeRttpQa1OyUpk2c77ubIrTtWaLNbu+F+v5Akb5 5yXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=2I26O3o5290Sc57Mq6LpqztjJaCmECzlBFxR87RiQ5w=; b=Wrmjk/VUCXO/Vp6I0LXeoM3AasYt5rccNN4GQs4ntoebiex+EVCr1u6c/2Zqpjb1OJ QSwp7OXC7sRlvq97DaQ07MFyXs4S4un3W2/6DChugKzp4U459gAfq5epdeNn9A15IsMp JqPPME19Ta6oSvmubdkrrL7i2UpRTJfVSOFfJEvr0/bx6ofzxRldGhs7lE/57sXVTood O1Fd0zeFFeDLVgfqYE7yyMtHXygYQgtW7C8TBmECp0itFMx/wk6KJ6QhKY204NPNUsLt 52xPPjfC0JunO3oLzRwGvuUGYxOj3rCph2dIaY+Kz2L1E2+9gdVw14jGTdOLaNC6Phzf vVRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=Dx/1edj4; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k6si8272973wmc.177.2017.07.25.17.11.03; Tue, 25 Jul 2017 17:11:04 -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 header.b=Dx/1edj4; 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 3B8C86883EA; Wed, 26 Jul 2017 03:11:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25212680BE4 for ; Wed, 26 Jul 2017 03:10:55 +0300 (EEST) Received: by mail-qk0-f193.google.com with SMTP id v76so2545134qka.5 for ; Tue, 25 Jul 2017 17:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=BnzEHlYYOBnYL6Uysdjx5Tr6u9wKPQMNFO5hMHGihqU=; b=Dx/1edj4CrnnwwNpigmrbI02tT8pcHQbs4/Zg4ukAbiY/Oqa6qEgd6mNFyiG29BkbO fCYhXQRnFymjnkkVaHDqKABrT2cPYvvbrZJzEkuV+L5KEOIRPZQLwtx4Cht8q2RaLgHS M6OHOAwL7Bh5/NqU8dWtFM3EF/6GuPMFMUQrKJmMQT42S/og4FjSJvQQGDC8svhLz5zL EI6Bo8JepIX0ETF5OLzyG416qQxNgfX5pGCwddgHQQcdc/IxSIu9JPtluhy/a8epLgjW lydgZ6RE6FJLKaDBZDJMFb4qZuTFUIrPIUu/K+XN1THCz4OL9s9CMzTrAenCFYsUDO0N p4xg== 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; bh=BnzEHlYYOBnYL6Uysdjx5Tr6u9wKPQMNFO5hMHGihqU=; b=N3/ngGDKsyXXGs0UB8vExFsBxNkUbDvho5jh/SgtXu9rQOykrhK9K/FVSI3TblseyX O71ti8aL70wjisSF2g3fsQXaekSYYAkdOgcRxe8Z4JXkwizUwo927+hFT1ooIdazfM+4 KQb2UcmWTJaAoR6Th0asjqHGkrdEYB9CmDLpjpl3gU8P2mensA6dgGmD+NwGoEEsGF1S JrEjpQk4eGe/5udjWQU7Ud/6GQV7kMwl2rLB8U1gpc+NmBg+QLZaBulicWn4SiavI3Xo paYCImhLlu6KplvGa6toe6Wi5y3T/oYPndJUVMvhbAhJ+y1wRVwed213ArhdBsXtKZsi +iDQ== X-Gm-Message-State: AIVw111+L9BRo0A5x6Yk1zjOnzNHoE6yxYYfLcW3uHNxKJVM3FOBFHJ/ c7JhpDltvRHMKGjA X-Received: by 10.55.107.134 with SMTP id g128mr25574517qkc.166.1501027854061; Tue, 25 Jul 2017 17:10:54 -0700 (PDT) Received: from localhost.localdomain ([181.231.116.134]) by smtp.gmail.com with ESMTPSA id s2sm10506329qkh.31.2017.07.25.17.10.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Jul 2017 17:10:53 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Jul 2017 21:10:42 -0300 Message-Id: <20170726001042.5984-1-jamrial@gmail.com> X-Mailer: git-send-email 2.13.3 Subject: [FFmpeg-devel] [PATCH] avutil/frame: allow only one element per type in frame 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Same rationale as with packet side data, it was never meant to do otherwise as av_frame_get_side_data returns the first entry it finds of a given type. Based on code from libavformat's av_stream_add_side_data(). Signed-off-by: James Almer --- libavutil/frame.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 24d5d5f184..c41d4be8cc 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -638,10 +638,24 @@ static AVFrameSideData *frame_new_side_data(AVFrame *frame, AVBufferRef *buf) { AVFrameSideData *ret, **tmp; + int i; if (!buf) return NULL; + for (i = 0; i < frame->nb_side_data; i++) { + AVFrameSideData *sd = frame->side_data[i]; + + if (sd->type == type) { + av_buffer_unref(&sd->buf); + av_dict_free(&sd->metadata); + sd->buf = buf; + sd->data = sd->buf->data; + sd->size = buf->size; + return sd; + } + } + if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) goto fail;