From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Haihao Xiang <haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_get_buffer2 Date: Tue, 16 May 2023 10:06:22 +0800 Message-ID: <20230516020624.71232-1-haihao.xiang@intel.com> (raw) From: Haihao Xiang <haihao.xiang@intel.com> 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 <haihao.xiang@intel.com> --- 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".
next reply other threads:[~2023-05-16 2:07 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-16 2:06 Xiang, Haihao [this message] 2023-05-16 2:06 ` [FFmpeg-devel] [PATCH 2/3] lavu/hwcontext_qsv: call av_frame_get_buffer2 instead of av_frame_get_buffer Xiang, Haihao 2023-05-16 2:06 ` [FFmpeg-devel] [PATCH 3/3] lavc/qsvenc: " Xiang, Haihao 2023-05-16 7:52 ` [FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_get_buffer2 Hendrik Leppkes 2023-05-16 8:22 ` "zhilizhao(赵志立)" 2023-05-17 5:08 ` Xiang, Haihao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230516020624.71232-1-haihao.xiang@intel.com \ --to=haihao.xiang-at-intel.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=haihao.xiang@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git