From patchwork Sat Feb 29 12:21:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17971 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1EB6544B655 for ; Sat, 29 Feb 2020 14:23:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EDDDB68AFEB; Sat, 29 Feb 2020 14:23:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-3.mx.upcmail.net (vie01a-dmta-pe05-3.mx.upcmail.net [84.116.36.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC17C68AFEB for ; Sat, 29 Feb 2020 14:23:08 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1j819A-0001gi-0L for ffmpeg-devel@ffmpeg.org; Sat, 29 Feb 2020 13:23:08 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 818Bj9JlI6Jy6818BjsSBc; Sat, 29 Feb 2020 13:22:08 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=GKl27dFK c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=uGrar2RNcgsiUvPQL-wA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 29 Feb 2020 13:21:53 +0100 Message-Id: <20200229122156.28115-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200229122156.28115-1-michael@niedermayer.cc> References: <20200229122156.28115-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBR3vZKXz13Hf4zcKVjn7R/E2JQZVZmrRmk/Ripg5htj9GzL0rwz/cwIojRDEDQQ6tUg5Q5viAjRv4+xU/LZUucskWH/QBIzApr8E+yzSK0m3gzMDXFu vNRaohAIhjVNCg9xwxe3FWKwJ+LXYyC2zZNrUYT/XJY/QJbpzvS4lElQ Subject: [FFmpeg-devel] [PATCH 1/4] Remove all uses of AVFrame QP tables and related fields in AVFrame 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: Michael Niedermayer --- libavutil/frame.c | 62 +++++++++-------------------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index e4038096c2..89089c6cc0 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -57,15 +57,6 @@ int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type) AVFrameSideData *sd; AVBufferRef *ref; -FF_DISABLE_DEPRECATION_WARNINGS - av_buffer_unref(&f->qp_table_buf); - - f->qp_table_buf = buf; - f->qscale_table = buf->data; - f->qstride = stride; - f->qscale_type = qp_type; -FF_ENABLE_DEPRECATION_WARNINGS - av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES); av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA); @@ -90,30 +81,22 @@ FF_ENABLE_DEPRECATION_WARNINGS int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type) { AVBufferRef *buf = NULL; + AVFrameSideData *sd; + struct qp_properties *p; *stride = 0; *type = 0; -FF_DISABLE_DEPRECATION_WARNINGS - if (f->qp_table_buf) { - *stride = f->qstride; - *type = f->qscale_type; - buf = f->qp_table_buf; -FF_ENABLE_DEPRECATION_WARNINGS - } else { - AVFrameSideData *sd; - struct qp_properties *p; - sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES); - if (!sd) - return NULL; - p = (struct qp_properties *)sd->data; - sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA); - if (!sd) - return NULL; - *stride = p->stride; - *type = p->type; - buf = sd->buf; - } + sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES); + if (!sd) + return NULL; + p = (struct qp_properties *)sd->data; + sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA); + if (!sd) + return NULL; + *stride = p->stride; + *type = p->type; + buf = sd->buf; return buf ? buf->data : NULL; } @@ -408,22 +391,6 @@ FF_ENABLE_DEPRECATION_WARNINGS av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); } -#if FF_API_FRAME_QP -FF_DISABLE_DEPRECATION_WARNINGS - dst->qscale_table = NULL; - dst->qstride = 0; - dst->qscale_type = 0; - av_buffer_unref(&dst->qp_table_buf); - if (src->qp_table_buf) { - dst->qp_table_buf = av_buffer_ref(src->qp_table_buf); - if (dst->qp_table_buf) { - dst->qscale_table = dst->qp_table_buf->data; - dst->qstride = src->qstride; - dst->qscale_type = src->qscale_type; - } - } -FF_ENABLE_DEPRECATION_WARNINGS -#endif av_buffer_unref(&dst->opaque_ref); av_buffer_unref(&dst->private_ref); @@ -565,11 +532,6 @@ void av_frame_unref(AVFrame *frame) av_buffer_unref(&frame->extended_buf[i]); av_freep(&frame->extended_buf); av_dict_free(&frame->metadata); -#if FF_API_FRAME_QP -FF_DISABLE_DEPRECATION_WARNINGS - av_buffer_unref(&frame->qp_table_buf); -FF_ENABLE_DEPRECATION_WARNINGS -#endif av_buffer_unref(&frame->hw_frames_ctx); From patchwork Sat Feb 29 12:21:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17974 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0F5B1449BD8 for ; Sat, 29 Feb 2020 14:28:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0CD468B463; Sat, 29 Feb 2020 14:28:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 877CA68B06D for ; Sat, 29 Feb 2020 14:28:37 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1j819A-0007Nf-0L for ffmpeg-devel@ffmpeg.org; Sat, 29 Feb 2020 13:23:08 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 818Cj9Jlf6Jy6818CjsSBi; Sat, 29 Feb 2020 13:22:08 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=GKl27dFK c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=2szs24V8uQ9fgXY3Kz4A:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 29 Feb 2020 13:21:54 +0100 Message-Id: <20200229122156.28115-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200229122156.28115-1-michael@niedermayer.cc> References: <20200229122156.28115-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBR3vZKXz13Hf4zcKVjn7R/E2JQZVZmrRmk/Ripg5htj9GzL0rwz/cwIojRDEDQQ6tUg5Q5viAjRv4+xU/LZUucskWH/QBIzApr8E+yzSK0m3gzMDXFu vNRaohAIhjVNCg9xwxe3FWKwJ+LXYyC2zZNrUYT/XJY/QJbpzvS4lElQ Subject: [FFmpeg-devel] [PATCH 2/4] avutil/frame: Rename QP related fields so unintentional use is impossible 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: Michael Niedermayer --- libavutil/frame.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/frame.h b/libavutil/frame.h index b5afb58634..b966f37fe0 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -614,18 +614,18 @@ typedef struct AVFrame { * QP table */ attribute_deprecated - int8_t *qscale_table; + int8_t *qscale_table_deprecated; /** * QP store stride */ attribute_deprecated - int qstride; + int qstride_deprecated; attribute_deprecated - int qscale_type; + int qscale_type_deprecated; attribute_deprecated - AVBufferRef *qp_table_buf; + AVBufferRef *qp_table_deprecated; #endif /** * For hwaccel-format frames, this should be a reference to the From patchwork Sat Feb 29 12:21:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17972 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E472644B655 for ; Sat, 29 Feb 2020 14:23:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D1C4168B458; Sat, 29 Feb 2020 14:23:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D9E2068AFE3 for ; Sat, 29 Feb 2020 14:23:08 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1j819A-00025y-0M for ffmpeg-devel@ffmpeg.org; Sat, 29 Feb 2020 13:23:08 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 818Cj9Jls6Jy6818CjsSBp; Sat, 29 Feb 2020 13:22:08 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=GKl27dFK c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=bHpbcL36GbkKP7XMA2UA:9 a=D4BviALDquDo_kxh:21 a=kABuh3bK9wJXMQWo:21 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 29 Feb 2020 13:21:55 +0100 Message-Id: <20200229122156.28115-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200229122156.28115-1-michael@niedermayer.cc> References: <20200229122156.28115-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBR3vZKXz13Hf4zcKVjn7R/E2JQZVZmrRmk/Ripg5htj9GzL0rwz/cwIojRDEDQQ6tUg5Q5viAjRv4+xU/LZUucskWH/QBIzApr8E+yzSK0m3gzMDXFu vNRaohAIhjVNCg9xwxe3FWKwJ+LXYyC2zZNrUYT/XJY/QJbpzvS4lElQ Subject: [FFmpeg-devel] [PATCH 3/4] avutil: frame Update the existing QP API 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" This should extend the API to allow exporting internal tables for codecs with block sizes different from 16x16 and different values per plane or multiple values per block. This is unfinished and only to demonstrate how such API (which maintains API/ABI compatibility) would look This API may allow some codecs to export their tables with 0 copy Signed-off-by: Michael Niedermayer --- libavutil/frame.c | 21 ++++++++++++++++++++ libavutil/frame.h | 49 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 89089c6cc0..2cd680c886 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -100,6 +100,27 @@ int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type) return buf ? buf->data : NULL; } + +int av_get_qp_table_type_details(int type, int *block_size, int *independant_qps_per_block, int *dependant_qps_per_block, + int *independant_chroma_planes, int *dependant_chroma_planes, int *independant_alpha_planes, int *dependant_alpha_planes) +{ + *block_size = 16; + *independant_qps_per_block = 0; + * dependant_qps_per_block = 0; + *independant_chroma_planes = 0; + * dependant_chroma_planes = 0; + *independant_alpha_planes = 0; + * dependant_alpha_planes = 0; + switch (type) { + case 0: + case 1: + case 2: + case 3: + return 0; + default: + return AVERROR(EINVAL); + } +} #endif const char *av_get_colorspace_name(enum AVColorSpace val) diff --git a/libavutil/frame.h b/libavutil/frame.h index b966f37fe0..84ee94c7bb 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -715,12 +715,6 @@ attribute_deprecated int av_frame_get_pkt_size(const AVFrame *frame); attribute_deprecated void av_frame_set_pkt_size(AVFrame *frame, int val); -#if FF_API_FRAME_QP -attribute_deprecated -int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type); -attribute_deprecated -int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type); -#endif attribute_deprecated enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame); attribute_deprecated @@ -731,6 +725,49 @@ attribute_deprecated void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val); #endif +/** + * Get Quantization parameter table. + * This returns a 2D array of values representing the QP of the specified AVFrame. + * the array is organized in planes then rows then columns then QP per block. + * + * @param stride bytes per row in the returned array + * @returns a 2D array of QP values, the pixels per block depend on the type. + * the array is valid as long as the frame is not destroyed or a new + * qp table set. + * @see av_frame_set_qp_table() + */ +int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type); + +/** + * Set Quantization parameter table. + * This returns a 2D array of values representing the QP of the specified AVFrame. + * + * @param stride bytes per row in the set array + * @returns a 2D array of QP values, the pixels per block depend on the type. + * @see av_frame_set_qp_table() + */ +int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type); + +/** + * Returns the details, each QP represents. + * + * @param block_size spatial size of the square, each QP represents. + * @param independant_qps_per_block number of independant QP parameters per block (stored for each block) + * @param dependant_qps_per_block number of dependant QP parameters per block (stored for each plane) + * @param independant_chroma_planes number of independant planes for chroma, this can be 0, 1 or 2 + * with 0, the luma plane is used for chroma, with 1 there is + * one QP plane for both chroma components, or 2 for seperate QP + * per Chroma channel. + * @param dependant_chroma_planes number of dependant planes for chroma, for each + * dependant chroma plane a single offset parameter if stored relative to + * the previous plane + * @param independant_alpha_planes number of independant alpha planes of QP components + * @param dependant_alpha_planes number of dependant alpha planes of QP components + */ +int av_get_qp_table_type_details(int type, int *block_size, int *independant_qps_per_block, int *dependant_qps_per_block, + int *independant_chroma_planes, int *dependant_chroma_planes, int *independant_alpha_planes, int *dependant_alpha_planes); + + /** * Get the name of a colorspace. * @return a static string identifying the colorspace; can be NULL. From patchwork Sat Feb 29 12:21:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17973 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AF43544B655 for ; Sat, 29 Feb 2020 14:23:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92E3568B47A; Sat, 29 Feb 2020 14:23:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-3.mx.upcmail.net (vie01a-dmta-pe05-3.mx.upcmail.net [84.116.36.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD6B568B0F4 for ; Sat, 29 Feb 2020 14:23:08 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1j819A-0001gh-0L for ffmpeg-devel@ffmpeg.org; Sat, 29 Feb 2020 13:23:08 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 818Cj9JmA6Jy6818CjsSBu; Sat, 29 Feb 2020 13:22:08 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=GKl27dFK c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=IkcTkHD0fZMA:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=emhf11hzAAAA:8 a=1XWaLZrsAAAA:8 a=OJBb8224HkiEGr4m80UA:9 a=5WdOpARD86RY2hP3:21 a=MOpsP9YdCgeQpPsf:21 a=QEXdDO2ut3YA:10 a=HLUCug_QN4oeKp6PugZw:22 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 29 Feb 2020 13:21:56 +0100 Message-Id: <20200229122156.28115-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200229122156.28115-1-michael@niedermayer.cc> References: <20200229122156.28115-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfBR3vZKXz13Hf4zcKVjn7R/E2JQZVZmrRmk/Ripg5htj9GzL0rwz/cwIojRDEDQQ6tUg5Q5viAjRv4+xU/LZUucskWH/QBIzApr8E+yzSK0m3gzMDXFu vNRaohAIhjVNCripgyBBOyk9cnEM2QUUtnfoZHyuI4zXtEAH4cSVO70cr16HJsUBLyPriBxFGeaGV6+jSCyQtMyQJfeYizxdvfg= Subject: [FFmpeg-devel] [PATCH 4/4] libavutil: AVEncodeInfo data structures 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 Cc: =?utf-8?q?Juan_De_Le=C3=B3n?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Juan De León AVEncodeInfoFrame data structure to store as AVFrameSideData of type AV_FRAME_DATA_ENCODE_INFO. The structure stores quantization index for each plane, DC/AC deltas for luma and chroma planes, and an array of AVEncodeInfoBlock type denoting position, size, and delta quantizer for each block in the frame. Can be extended to support extraction of other block information. Signed-off-by: Juan De León Signed-off-by: Michael Niedermayer --- libavutil/Makefile | 2 + libavutil/encode_info.c | 72 ++++++++++++++++++++++++++ libavutil/encode_info.h | 110 ++++++++++++++++++++++++++++++++++++++++ libavutil/frame.c | 1 + libavutil/frame.h | 7 +++ 5 files changed, 192 insertions(+) create mode 100644 libavutil/encode_info.c create mode 100644 libavutil/encode_info.h diff --git a/libavutil/Makefile b/libavutil/Makefile index a2dae8e89a..df01424c31 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -24,6 +24,7 @@ HEADERS = adler32.h \ dict.h \ display.h \ downmix_info.h \ + encode_info.h \ encryption_info.h \ error.h \ eval.h \ @@ -112,6 +113,7 @@ OBJS = adler32.o \ dict.o \ display.o \ downmix_info.o \ + encode_info.o \ encryption_info.o \ error.o \ eval.o \ diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c new file mode 100644 index 0000000000..1048173e7f --- /dev/null +++ b/libavutil/encode_info.c @@ -0,0 +1,72 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include "libavutil/encode_info.h" +#include "libavutil/mem.h" + +/** + * Get the size to allocate of AVEncodeInfoFrame and the array of AVEncodeInfoBlock. + * AVEncodeInfoFrame already allocates size for one element of AVEncodeInfoBlock. + */ +#define AV_ENCODE_INFO_GET_SIZE(SIZE, N) \ + if (N > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) / sizeof(AVEncodeInfoBlock) + 1) \ + return NULL; \ + SIZE = sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock) \ + + FFMAX(1, N) * sizeof(AVEncodeInfoBlock) + +static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned nb_blocks) +{ + info->nb_blocks = nb_blocks; + info->block_size = sizeof(AVEncodeInfoBlock); + info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks); + + for(int i = 0; i < AV_NUM_DATA_POINTERS; i++) + info->plane_q[i] = -1; + + return 0; +} + +AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks) +{ + size_t size; + AV_ENCODE_INFO_GET_SIZE(size, nb_blocks); + AVEncodeInfoFrame *ptr = av_mallocz(size); + if (!ptr) + return NULL; + + init_encode_info_data(ptr, nb_blocks); + + return ptr; +} + +AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned nb_blocks) +{ + size_t size; + AV_ENCODE_INFO_GET_SIZE(size, nb_blocks); + AVFrameSideData *sd = av_frame_new_side_data(frame, + AV_FRAME_DATA_ENCODE_INFO, + size); + if (!sd) + return NULL; + + memset(sd->data, 0, size); + init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks); + + return (AVEncodeInfoFrame*)sd->data; +} diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h new file mode 100644 index 0000000000..8afe0c9c9e --- /dev/null +++ b/libavutil/encode_info.h @@ -0,0 +1,110 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_ENCODE_INFO_H +#define AVUTIL_ENCODE_INFO_H + +#include "libavutil/avassert.h" +#include "libavutil/frame.h" + +/** + * Data structure for extracting block data, stored as an array in AVEncodeInfoFrame. + */ +typedef struct AVEncodeInfoBlock{ + /** + * Distance in luma pixels from the top-left corner of the visible frame + * to the top-left corner of the block. + * Can be negative if top/right padding is present on the coded frame. + */ + int src_x, src_y; + /** + * Width and height of the block in luma pixels. + */ + int w, h; + /** + * Delta quantization index for the block with respect to the frame. + */ + int delta_q; +} AVEncodeInfoBlock; + +/** + * Frame encoding info, used as AVFrameSideData. Data in this structure concerns + * the whole frame. + * Additional entries may be added without bumping major before nb_blocks, + * so using the accessor function av_encode_info_get_block() is recommended. + */ +typedef struct AVEncodeInfoFrame { + /** + * Base plane quantizer for the frame, set to -1 when value is unsupported. + */ + int plane_q[AV_NUM_DATA_POINTERS]; + /** + * DC/AC quantizer index delta, set to -1 when value is value unsupported. + */ + int ac_q, dc_q; + /** + * DC/AC chroma quantizer index delta, set to -1 when value is value unsupported. + */ + int ac_chroma_q, dc_chroma_q; + /** + * Number of blocks in the array, may be 0. + */ + unsigned nb_blocks; + /** + * Offset in this structure at which blocks begin in bytes. May not match + * offsetof(AVEncodeInfoFrame, blocks). + */ + size_t blocks_offset; + /* + * Size of each block in bytes. May not match sizeof(AVEncodeInfoBlock). + */ + size_t block_size; + + /* + * Array of blocks, with a total size of block_size*nb_blocks, the [1] + * is meant for compatibility with C++. + */ + AVEncodeInfoBlock blocks[1]; +} AVEncodeInfoFrame; + +/* + * Gets the block at the specified {@code idx}. Must be between 0 and nb_blocks. + */ +static inline AVEncodeInfoBlock *av_encode_info_get_block(AVEncodeInfoFrame *info, unsigned idx) +{ + av_assert0(idx < info->nb_blocks); + + return (AVEncodeInfoBlock *)((uint8_t *)info + info->blocks_offset + idx*info->block_size); +} + +/** + * Allocates memory for AVEncodeInfoFrame plus an array of + * {@code nb_blocks} AVEncodeInfoBlock and initializes the variables. + * Can be freed with a normal av_free() call. + */ +AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks); + +/** + * Allocates memory for AVEncodeInfoFrame plus an array of + * {@code nb_blocks} AVEncodeInfoBlock in the given AVFrame {@code frame} + * as AVFrameSideData of type AV_FRAME_DATA_ENCODE_INFO + * and initializes the variables. + */ +AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned nb_blocks); + +#endif /* AVUTIL_ENCODE_INFO_H */ diff --git a/libavutil/frame.c b/libavutil/frame.c index 2cd680c886..198272edb0 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -825,6 +825,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) #endif case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata SMPTE2094-40 (HDR10+)"; case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest"; + case AV_FRAME_DATA_ENCODE_INFO: return "AVEncodeInfo"; } return NULL; } diff --git a/libavutil/frame.h b/libavutil/frame.h index 84ee94c7bb..954ad0c773 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -179,6 +179,13 @@ enum AVFrameSideDataType { * array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size. */ AV_FRAME_DATA_REGIONS_OF_INTEREST, + /** + * Extract frame and block encode info from supported decoders. The data + * stored is an AVEncodeInfoFrame type, which contains an array of + * AVEncodeInfoBlock. Described in libavuitls/encode_info.h + * Can be allocated in the frame directly with av_encode_info_create_side_data(). + */ + AV_FRAME_DATA_ENCODE_INFO, }; enum AVActiveFormatDescription {