From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7BDC749FB4 for ; Sun, 17 Mar 2024 20:02:44 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 549CE68D222; Sun, 17 Mar 2024 22:01:27 +0200 (EET) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1992168D1DB for ; Sun, 17 Mar 2024 22:01:14 +0200 (EET) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-512e4f4e463so4039099e87.1 for ; Sun, 17 Mar 2024 13:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710705673; x=1711310473; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ZxiT/CzwLtq1GGe+tkJ8pyUKMWrKFCt1EKSb8u67Hhs=; b=UWoqbstmJmtUE7uWymsi8Y2HPvuX0nMq91x32q7U2ydTQ3q1KDiq/uPeP4dsB3jpTD ohl/O2x0wc3+JNiWj3y0xkyQzLqTDPv9cRPKN3f2WTAabBHgK9Y8S4z1BshvuvEB06FK fC/ChEz+l/PfqFZS1PrAfkz8s1zP+xEje5Teuho2FKiEJGSyrSdlu7aMDc5ug62U5Jy0 xR0f3vJe62KZeU3HFG/Ghvy2rgHryVYzXbHVLypz0h3BHW+QwbkKY2rvUdQHfvI8isHj 5SEnz+poJgZKn+O3KbN7q9BEuiKe5H3x+y1VdMjCdaqrYJRWfEqsPyrUarKP3AO1Ge+4 R/Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710705673; x=1711310473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZxiT/CzwLtq1GGe+tkJ8pyUKMWrKFCt1EKSb8u67Hhs=; b=v3HO0KBnXiHcd+yzX+skP4ZZh8x6gB+zfeZoPjCcG/Whj/e3gbNehV8IdmSSDxarP4 MXMu0CgG12nE/G0M1WMJ3bkJrLSr3LOsR2SGBTN87CC7HQznxgZWJ0fFnPAjuHoZ5ulL s7To53zEPYzBBDU6po7HGY++V7aDFrWMenSdwT4LSGQ2UREeBSIHOs/koKXKuchEkkwh vkXErbNFcAYUNECd6THwT1K3WYcVwqPrhK4HLq2KmdqemHZGA/QhHJMmkXGRCRLsDx8a jYZhwqR5hNDZ8PiWa16TR9gHGBMj69cTffQUOdFHbcP6nDHjey+1AM29RYOxO5wjFJsm l6dg== X-Gm-Message-State: AOJu0YzeXU5ntLcQI6p7/Pdp2Eeds6B9t283KUyFIqROEsnATvN86Iw0 bUO18aEIWkiL4S5Bl3qei5pB0IPjRPwbuEoglc3YBn80hIo+taraPILDC/OO X-Google-Smtp-Source: AGHT+IGYbxbgsIk2zh4m4aBgLtQd+H/bH+PZLOBmSSAdy0rF8gWIqxBnlmY6Hi2UIB8V5wQrhtsWKg== X-Received: by 2002:a05:6512:68c:b0:513:db96:2be9 with SMTP id t12-20020a056512068c00b00513db962be9mr6726313lfe.64.1710705673125; Sun, 17 Mar 2024 13:01:13 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id y3-20020a056512044300b00513c844603fsm1340462lfk.41.2024.03.17.13.01.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:01:12 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Mar 2024 22:00:47 +0200 Message-ID: <20240317200100.152097-11-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317200100.152097-1-jeebjp@gmail.com> References: <20240317200100.152097-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v9 10/14] avcodec: add helper for configuring AVCodecContext's frame side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This allows API clients that wish to configure multiple entries at a time to do so without writing the looping code themselves. --- libavcodec/avcodec.c | 31 +++++++++++++++++++++++++++++++ libavcodec/avcodec.h | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index a9a87bb58c..3183952172 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -686,3 +686,34 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return ff_decode_receive_frame(avctx, frame); return ff_encode_receive_frame(avctx, frame); } + +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideData **sd, const int nb_sd, + unsigned int flags) +{ + if (!avctx) + return AVERROR(EINVAL); + + if (!sd) { + av_frame_side_data_free( + &avctx->encoder_side_data, &avctx->nb_encoder_side_data); + return 0; + } + + if (nb_sd > 0 && nb_sd == avctx->nb_encoder_side_data && + sd == (const AVFrameSideData **)avctx->encoder_side_data) + return AVERROR(EINVAL); + + for (int i = 0; i < nb_sd; i++) { + int ret = av_frame_side_data_clone( + &avctx->encoder_side_data, &avctx->nb_encoder_side_data, sd[i], + flags); + if (ret < 0) { + av_frame_side_data_free( + &avctx->encoder_side_data, &avctx->nb_encoder_side_data); + return ret; + } + } + + return 0; +} diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 550df0e589..01085cc3c8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3079,6 +3079,27 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); */ int avcodec_is_open(AVCodecContext *s); +/** + * Add multiple side data entries to an AVCodecContext's array in one go, for + * example from an AVFrame. + * + * In case the function fails to add a side data entry, it will clear the + * whole side data set. + * + * @param avctx context to which the side data should be added + * @param sd array of side data to use as input. + * if null, clears out the side data for this context. + * @param nb_sd integer containing the number of entries in the array. + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return negative error code on failure, >=0 on success. + * + * @see av_frame_side_data_new regarding the flags. + */ +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideData **sd, const int nb_sd, + unsigned int flags); + /** * @} */ -- 2.44.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".