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 1A532400A6 for ; Tue, 16 May 2023 02:07:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 431CC68BFA1; Tue, 16 May 2023 05:07:19 +0300 (EEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A39968B4FE for ; Tue, 16 May 2023 05:07:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684202838; x=1715738838; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=39ux3dwMapGJ5C+sTUPZYE6Vv+cYNr7GqIIao41ZBK4=; b=QY9RuhhpQgHAa9ztKlAoBZcvaH7jDaeUc8IE3+jSsbDuOqyrWJovbM4v 1lAJv9VI0T4UhNmvQGrB16hHu+KAGY6fI/bcFFMwOGlB0S1fpAjXES3pK o+k6YQpgsVK3xPRyjiTAERpZ/ZaM9QTidIXCd13UAcUB97e0eBe3ofdRo lnxtdZLwz6EDiOrUHEB/ReFovMsoF2dFdlSMhgd7GhCxRfkuFoU4p/2Jf FPGXVM86aHpp6KVBa1YBjdQCaQ3vX0LpX+MSZ3sEpzrgaI8Bx9pOs2O9H rCr8BSMzN7D8RoUg+zQ9GKEkVMNwA4I2oFPoMv7Q+8PJ+59DpSSknM7un A==; X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="348857907" X-IronPort-AV: E=Sophos;i="5.99,277,1677571200"; d="scan'208";a="348857907" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2023 19:07:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="790891856" X-IronPort-AV: E=Sophos;i="5.99,277,1677571200"; d="scan'208";a="790891856" Received: from xhh-tgl64.sh.intel.com ([10.238.2.19]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2023 19:07:01 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 May 2023 10:06:22 +0800 Message-Id: <20230516020624.71232-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_get_buffer2 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 Cc: Haihao Xiang 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: From: Haihao Xiang Intel MediaSDK and oneVPL expect continuous allocation for data[i], however there are mandatory padding bytes between data[i] and data[i+1]. when calling av_frame_get_buffer. So adding av_frame_get_buffer2 to allow caller to specify the length of padding bytes. Signed-off-by: Haihao Xiang --- doc/APIchanges | 3 +++ libavutil/frame.c | 12 ++++++++---- libavutil/frame.h | 31 +++++++++++++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 20ab4709e7..6a2c3b6270 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-05-09 - xxxxxxxxxx - lavu 58.8.100 - frame.h + Add av_frame_get_buffer2 + 2023-05-xx - xxxxxxxxxx - lavc 60.11.100 - codec_par.h Add AVCodecParameters.framerate. diff --git a/libavutil/frame.c b/libavutil/frame.c index 97d40208c8..5c9e740c6b 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -106,11 +106,10 @@ void av_frame_free(AVFrame **frame) av_freep(frame); } -static int get_video_buffer(AVFrame *frame, int align) +static int get_video_buffer(AVFrame *frame, int align, int plane_padding) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); int ret, padded_height, total_size; - int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align); ptrdiff_t linesizes[4]; size_t sizes[4]; @@ -240,14 +239,14 @@ FF_ENABLE_DEPRECATION_WARNINGS } -int av_frame_get_buffer(AVFrame *frame, int align) +int av_frame_get_buffer2(AVFrame *frame, int align, int plane_padding) { if (frame->format < 0) return AVERROR(EINVAL); FF_DISABLE_DEPRECATION_WARNINGS if (frame->width > 0 && frame->height > 0) - return get_video_buffer(frame, align); + return get_video_buffer(frame, align, plane_padding); else if (frame->nb_samples > 0 && (av_channel_layout_check(&frame->ch_layout) #if FF_API_OLD_CHANNEL_LAYOUT @@ -260,6 +259,11 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } +int av_frame_get_buffer(AVFrame *frame, int align) +{ + return av_frame_get_buffer2(frame, align, FFMAX(16 + 16/*STRIDE_ALIGN*/, align)); +} + static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) { int ret; diff --git a/libavutil/frame.h b/libavutil/frame.h index f2b56beebb..197bcfeef2 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -867,6 +867,37 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src); */ int av_frame_get_buffer(AVFrame *frame, int align); +/** + * Allocate new buffer(s) for audio or video data. + * + * The following fields must be set on frame before calling this function: + * - format (pixel format for video, sample format for audio) + * - width and height for video + * - nb_samples and ch_layout for audio + * + * This function will fill AVFrame.data and AVFrame.buf arrays and, if + * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf. + * For planar formats, one buffer will be allocated for each plane. + * + * @warning: if frame already has been allocated, calling this function will + * leak memory. In addition, undefined behavior can occur in certain + * cases. + * + * @param frame frame in which to store the new buffers. + * @param align Required buffer size alignment. If equal to 0, alignment will be + * chosen automatically for the current CPU. It is highly + * recommended to pass 0 here unless you know what you are doing. + * @param plane_padding The length of padding bytes between two video planes. It is + * ignored for audio data. + * + * @return 0 on success, a negative AVERROR on error. + * + * @note It is recommended that you use av_frame_get_buffer instead if you do not + * care about the length of padding bytes. + * @see av_frame_get_buffer() + */ +int av_frame_get_buffer2(AVFrame *frame, int align, int plane_padding); + /** * Check if the frame data is writable. * diff --git a/libavutil/version.h b/libavutil/version.h index 341bcbf188..a4177aa137 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 58 -#define LIBAVUTIL_VERSION_MINOR 7 +#define LIBAVUTIL_VERSION_MINOR 8 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- 2.34.1 _______________________________________________ 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".