From patchwork Fri Jul 1 20:48:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261228pzh; Fri, 1 Jul 2022 13:49:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vOMo4xsLKIBpqceqtVSRNSNj7Jey7tuicoG/x6Zj3ohkl0EgRfsEI3YajjEaA2rnBbPykF X-Received: by 2002:a17:907:75e8:b0:722:e8c5:ee96 with SMTP id jz8-20020a17090775e800b00722e8c5ee96mr3523775ejc.147.1656708583248; Fri, 01 Jul 2022 13:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708583; cv=none; d=google.com; s=arc-20160816; b=VQTE1y9HbaLIG6k03LiOUhEymYifWpGKxU6eYaE38jnJ/pDmOr/c6csQPWob0EllfO h7u7rPUVOCceeAXdjyb9WA39UxIIQhCCUJKRNiJrpa8PI/57fEqUeGM+0gvwCXCtOUf6 BxaqGoQCmP3Cey+6bvabnjq3QjasRJjHy0DWDRKCwttzvC/PBMJhTFdzHElBEXCxMhae JGTjS+raKKyijAFSJvdXI8XyzuG2q9TDhk9lWdu92dCkh7JVNZLLnZy7hpTXK3kXXjNE ZXHh5imdsZh2NcTyk/bOkJhU7pkOuuFL3RVYX/sOi4iCAFjlqLxQen97ddbn43fwVFy/ FiBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=PI1kwDUMrmVqskstbGODCONQQW/5s5SiTEBKmzoWFyM=; b=u5ZNKP39jM0hpwWmFNBsxhH7lozAnYaItC9Hn1QIIcmIgIARPkT9SVd9R+08WtMjir o+OdEvS4b5rmEFm5ispb8rzZmdTH+ay2eZpVwkBxr2L+iD1vFyQKz8xg6/umV3owzCgm mvb7vG9RdgafSxiP0OxHngsD6h1933ClzB0tV3MpC21TumkfJb7DsBwFSUWVUWy2jfro 7bpYXGGj7culKnFK0d0w2n7c8kb608/5oJJPFVml8JH9xpfBcOQoX7ccqrA1YGVVzfI0 ok1dNq0pX0QRS70eGBxNXe6XDBvdYzJZoK4Hc+J1c0EhaMqROw2AL5YiDsPp/chiMOmh AzwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=I9+6NvQp; 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=QUARANTINE 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 s12-20020a1709064d8c00b006fe8b1baec0si2381321eju.709.2022.07.01.13.49.42; Fri, 01 Jul 2022 13:49:43 -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.s=20210112 header.b=I9+6NvQp; 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=QUARANTINE 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 DA8C968B81B; Fri, 1 Jul 2022 23:49:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B59A68B655 for ; Fri, 1 Jul 2022 23:49:01 +0300 (EEST) Received: by mail-pg1-f179.google.com with SMTP id o18so2241600pgu.9; Fri, 01 Jul 2022 13:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Z1By0WxhSs+F1+ExubIgn2ViMY7zhfK9Xtzywquw6D0=; b=I9+6NvQp5nW/qiOTevTbnf3/SJBgT4V9HEfU8xy4GmHgQX79yN2r3x5QWQd3YDdizF YrJJRmCYeULI5prFXUadCQdeVYuXqwQcD3CuBiTOGz4WgQrznMoXMZ3r298Amixag6xF aRH+2KJfP6tGGg8jzUFNCAdTitl29kqLpSd4BK4/nxkNBjHgygdNXQruRv9bUE4F7l95 yARji+AgMmQx48jftR6LNR5zFEnsqwFPTRJKKbnaXqvCL0WPXlV8ACBwMVhz91veNrpW NGiInoBWI6IManlF34QYcFN8B30JvuXeqnOPjXtIJQFe+V7+WHq4RU/tHtPo0puulGQI yg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Z1By0WxhSs+F1+ExubIgn2ViMY7zhfK9Xtzywquw6D0=; b=Fll6gwxVwQUc/3ug4fDjMG133fB4YWogpa68yUELkvf8RKNJKIFVpSkM7okEmmsO23 qxV5CpltQriExlvIz3suWCb3swjukPFD4gYbTr63mR1ffoGWnmzj5FO7ZMtKkjLExFee T1NPKBPPpR57tZv6BAkDXh09C/2eji8Ime1FCqkkS67o6vVj4EZIZ2A0o6LT5/5G2TGw mYVdwYoqaLEL6RN3ZjR/cBhL1VsiNtGupbg7/zy7kEevtQW1K3fXJSR+GzIG1fxL/64v hnNV7iRs6LAFUCckEoW+ERuEhBy9vhVsbcOIIYeNvFcQ599GRR1p9JFRM0VnugH5xzp3 u+yw== X-Gm-Message-State: AJIora/Ndq/Le1A49FwBMLbTZkOOgB7rGVUncO02xRN908vGTbWxy3PG jVieEwIAfQOmxCQeGReJ8SNwbP31Akj3MA== X-Received: by 2002:a05:6a00:170f:b0:525:467c:3516 with SMTP id h15-20020a056a00170f00b00525467c3516mr21588278pfc.22.1656708538707; Fri, 01 Jul 2022 13:48:58 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id r4-20020a635d04000000b0040da5441312sm8521809pgb.12.2022.07.01.13.48.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:48:57 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <7656477360b1e993b0a432a13332b48c4b7fc4bc.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:49 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_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 Cc: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: T/AXXgrRGQ/O From: softworkz Signed-off-by: softworkz Signed-off-by: Anton Khirnov --- doc/APIchanges | 4 +++ libavutil/frame.c | 67 +++++++++++++++++++++++++++------------------ libavutil/frame.h | 32 ++++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 78 insertions(+), 27 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 20b944933a..6b5bf61d85 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,10 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-05-26 - xxxxxxxxx - lavu 57.28.100 - frame.h + Add av_frame_remove_all_side_data(), av_frame_copy_side_data(), + AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER. + 2022-06-12 - xxxxxxxxxx - lavf 59.25.100 - avio.h Add avio_vprintf(), similar to avio_printf() but allow to use it from within a function taking a variable argument list as input. diff --git a/libavutil/frame.c b/libavutil/frame.c index 4c16488c66..5d34fde904 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -271,9 +271,45 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } +void av_frame_remove_all_side_data(AVFrame *frame) +{ + wipe_side_data(frame); +} + +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags) +{ + for (unsigned i = 0; i < src->nb_side_data; i++) { + const AVFrameSideData *sd_src = src->side_data[i]; + AVFrameSideData *sd_dst; + if ((flags & AV_FRAME_TRANSFER_SD_FILTER) && + sd_src->type == AV_FRAME_DATA_PANSCAN && + (src->width != dst->width || src->height != dst->height)) + continue; + if (flags & AV_FRAME_TRANSFER_SD_COPY) { + sd_dst = av_frame_new_side_data(dst, sd_src->type, + sd_src->size); + if (!sd_dst) { + wipe_side_data(dst); + return AVERROR(ENOMEM); + } + memcpy(sd_dst->data, sd_src->data, sd_src->size); + } else { + AVBufferRef *ref = av_buffer_ref(sd_src->buf); + sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); + if (!sd_dst) { + av_buffer_unref(&ref); + wipe_side_data(dst); + return AVERROR(ENOMEM); + } + } + av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); + } + return 0; +} + static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) { - int ret, i; + int ret; dst->key_frame = src->key_frame; dst->pict_type = src->pict_type; @@ -309,31 +345,10 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) av_dict_copy(&dst->metadata, src->metadata, 0); - for (i = 0; i < src->nb_side_data; i++) { - const AVFrameSideData *sd_src = src->side_data[i]; - AVFrameSideData *sd_dst; - if ( sd_src->type == AV_FRAME_DATA_PANSCAN - && (src->width != dst->width || src->height != dst->height)) - continue; - if (force_copy) { - sd_dst = av_frame_new_side_data(dst, sd_src->type, - sd_src->size); - if (!sd_dst) { - wipe_side_data(dst); - return AVERROR(ENOMEM); - } - memcpy(sd_dst->data, sd_src->data, sd_src->size); - } else { - AVBufferRef *ref = av_buffer_ref(sd_src->buf); - sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); - if (!sd_dst) { - av_buffer_unref(&ref); - wipe_side_data(dst); - return AVERROR(ENOMEM); - } - } - av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); - } + if ((ret = av_frame_copy_side_data(dst, src, + (force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) | + AV_FRAME_TRANSFER_SD_FILTER) < 0)) + return ret; ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref); ret |= av_buffer_replace(&dst->private_ref, src->private_ref); diff --git a/libavutil/frame.h b/libavutil/frame.h index 33fac2054c..f72b6fae71 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -850,6 +850,30 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src); */ int av_frame_copy_props(AVFrame *dst, const AVFrame *src); + +/** + * Copy side data, rather than creating new references. + */ +#define AV_FRAME_TRANSFER_SD_COPY (1 << 0) +/** + * Filter out side data that does not match dst properties. + */ +#define AV_FRAME_TRANSFER_SD_FILTER (1 << 1) + +/** + * Copy all side-data from src to dst. + * + * @param dst a frame to which the side data should be copied. + * @param src a frame from which to copy the side data. + * @param flags a combination of AV_FRAME_TRANSFER_SD_* + * + * @return 0 on success, a negative AVERROR on error. + * + * @note This function will create new references to side data buffers in src, + * unless the AV_FRAME_TRANSFER_SD_COPY flag is passed. + */ +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags); + /** * Get the buffer reference a given data plane is stored in. * @@ -901,6 +925,14 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, */ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); +/** + * Remove and free all side data instances. + * + * @param frame from which to remove all side data. + */ +void av_frame_remove_all_side_data(AVFrame *frame); + + /** * Flags for frame cropping. diff --git a/libavutil/version.h b/libavutil/version.h index 2e9e02dda8..87178e9e9a 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 27 +#define LIBAVUTIL_VERSION_MINOR 28 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ From patchwork Fri Jul 1 20:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36585 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261293pzh; Fri, 1 Jul 2022 13:49:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tQJqapx2+jrfXhRkJsfYw3y6ONwsGkQ7SdZtOfj1HF7s/aZU9Qq+Vd11If2IVjiE3Epy7m X-Received: by 2002:a05:6402:2741:b0:434:fe8a:1f96 with SMTP id z1-20020a056402274100b00434fe8a1f96mr21849583edd.331.1656708591982; Fri, 01 Jul 2022 13:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708591; cv=none; d=google.com; s=arc-20160816; b=sDYQFDmxmvuaZeafFUZJBHobkFc/58JEeIGZQfZ6s1prkFFalcsn42Wmj4p8ZkjaNQ 1xvrt7bwKbT9eXtmmNQSnafnm0dPbFknJ+YzWe2bCLKJahw3pACOw36c7Pn5J0T6YfbR I45Y39n/4VP6kYRw4vDhyW0+jfFWFNvcBZDr+iVwDUbDTTaGRQ+s9Nsn7n5US6R7jObR D3wyZ1GS8OBpLBSXeINSP8xcRSHiCVh7Q3yLj40xBHWvjCvDW8HXLV4aWue3aIJMmIKN dHDA8iXuGO9Z/nsHGwy/qa67HrYwRLjiaoW5YUk0BuODr2YcTc+RFSZhh1Tehjj2qJ8W /70Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=8YW+9azwue3ZKcaWIJN3kh2U6xbrBMbjWFMO5cgVeug=; b=TioCQtdrVi+NNFS5OlGCr0e8U0Zsts6vIziHhr7OyfP2rjWJCWDILltqDlRl3QThfx vVNUdLyOEcrIRQ9bq3GLs73UVkxoM0x7WWAqyxao2fLMlfbkY9wlNOr2lWhzBj78nCFF Db0Ltztd8UK8yly5rM2tQM3cp42G57anMg92G5R3X+RV1ggpTnx7o6OJZQeI8CxhTbIJ g9zBYmnrCz8ruY3zPNJArtFg5hmo5DGWpfGUmKRtnVvZ1s44R55DqFsSsCLSdRfxuuY6 e5UOna6W2ylh04TZLKvFdil9VROEx0dUkPQUuVG0kz5sZj+Oi4yVGBKBYVJKlZqI1QrU 4pWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=C+yiNBSX; 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=QUARANTINE 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 e10-20020a056402088a00b00428679d26b1si26660532edy.331.2022.07.01.13.49.51; Fri, 01 Jul 2022 13:49:51 -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.s=20210112 header.b=C+yiNBSX; 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=QUARANTINE 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 D521E68B825; Fri, 1 Jul 2022 23:49:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2436E68B722 for ; Fri, 1 Jul 2022 23:49:02 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id y141so3481636pfb.7; Fri, 01 Jul 2022 13:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=9KZTrJTRMHUr48e/zhnkR7L99y96lcu+jQEQiX6aAYE=; b=C+yiNBSXKipNgrEarYHmS6o4ciQu1EMQ5JrHQ7DFSed+dQ8kXXnShxUNrmdOknRUoq B0PzvD1dEd/jAeMkVadJ5slmgTPRx3mPEy96M8ITuNaSGtgWMYZFhL1vrwv5Ry7dDa7y UJhQd/fHz2yKxGlPRhrR3Aqg3mFPwVOu9VQooMriMDiHalXOZUpXk361OnmKBWcJ9Dhc QmCes0Qnm49ZvaH/h/o+gYQmdU8OcfVWan+lhxdN+Xlg/exHEW/fyhHp6R0jCPjUHwln gyn4QCrJfdu+RGM3WEHgpFVkRbkHSGO5edkb476CmeKcRK5Rl4uDKqOJQ36KZTiu6vXt ucpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=9KZTrJTRMHUr48e/zhnkR7L99y96lcu+jQEQiX6aAYE=; b=YJ15Iqdse0mEPFHx7Way0Kb+M/rPZr8SuurFrC5nl/Q59/G6oSbkXFHxi5OPWXt2UO 4XtlP53rRsBIi40fdwPvPJgKelf2jqNl2LTpqwwqyEeRh+wIQfZGggGgtp508ArlzEMw 9yyVz9S+cZglZwLvbKZ23v5xpFIEOX1MK2Lf/7U9YG6reZVUBa2SyPN8oR2fhoao6nDb EunAbJU486vv3fxGVdRNEAuBfvMhBcHOeCQPwFzYYR8rFtNJ9RO02WXOKBxEhPrLs4Oo jlrFMSGBaI9+ciAcDZYOUrJcrYgo+Nvu/B3djQT1KvLMijIFGml5bVX0mlEG31X+WwqJ zShA== X-Gm-Message-State: AJIora8rSKi4Wi1OWkXP+vH55ZBwrC90L9FFGSFWXzPd0WqgjglPPUXQ mR/hTxSRtrc14WldzjpiBeCuXaOBi555vA== X-Received: by 2002:a63:90c7:0:b0:40d:3c0d:33f4 with SMTP id a190-20020a6390c7000000b0040d3c0d33f4mr13721990pge.334.1656708540300; Fri, 01 Jul 2022 13:49:00 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id c12-20020a621c0c000000b0050dc7628178sm16063182pfc.82.2022.07.01.13.48.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:48:59 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <06976606c5d31f43c3c5410aa6f92f797d859f7c.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:50 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 2/6] avcodec/vpp_qsv: Copy side data from input to output frame 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BMamn+ERk35/ From: softworkz Signed-off-by: softworkz --- libavfilter/qsvvpp.c | 6 ++++++ libavfilter/vf_overlay_qsv.c | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 954f882637..f4bf628073 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -843,6 +843,12 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr return AVERROR(EAGAIN); break; } + + av_frame_remove_all_side_data(out_frame->frame); + ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame, 0); + if (ret < 0) + return ret; + out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp, default_tb, outlink->time_base); diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c index 7e76b39aa9..e15214dbf2 100644 --- a/libavfilter/vf_overlay_qsv.c +++ b/libavfilter/vf_overlay_qsv.c @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs) { AVFilterContext *ctx = fs->parent; QSVOverlayContext *s = fs->opaque; + AVFrame *frame0 = NULL; AVFrame *frame = NULL; - int ret = 0, i; + int ret = 0; - for (i = 0; i < ctx->nb_inputs; i++) { + for (unsigned i = 0; i < ctx->nb_inputs; i++) { ret = ff_framesync_get_frame(fs, i, &frame, 0); - if (ret == 0) - ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame); + + if (ret == 0) { + if (i == 0) + frame0 = frame; + else { + av_frame_remove_all_side_data(frame); + ret = av_frame_copy_side_data(frame, frame0, 0); + } + + ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame); + } + if (ret < 0 && ret != AVERROR(EAGAIN)) break; } From patchwork Fri Jul 1 20:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36587 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261457pzh; Fri, 1 Jul 2022 13:50:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vHWDkhcXKMGjqJGhHWkkkf+pk1aMkwE4Cllk2xINIuy7Fs4ssxz3jevd2G21uqIiIsgrB3 X-Received: by 2002:a17:906:9508:b0:723:ef49:fe4c with SMTP id u8-20020a170906950800b00723ef49fe4cmr16666214ejx.489.1656708610531; Fri, 01 Jul 2022 13:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708610; cv=none; d=google.com; s=arc-20160816; b=Kb+hzQOf5P3PWTgfa7nJKZy85gQFdRf5yvGN7B/ssbzzmPV8VQL26PRgyS034mtTB+ Fw9UeWjgFCxMZX88/QLQuywaLARGfgy2A/v1jtD1HuVXkI8EBsMFM3MT73pqB/0Sr+H7 yVo5PMuFj4WjdnnMp5cjNnwU75AehbGxHGPRM9FZWfvy6dl1J755wyyyP/mnoWu+c4ZG TlYD3jcrv7gsa77u/X8CpKFAUikV25h2nqabLfqbSPFGyq3RgYRC0eUv1t2KMJ+kqSRe X+U8PaQUAe0iWSE0RI1qG1TkD6yH4LChRVrbB8giBJW3gnCKt4FLtpxyjtHeYW27OmVZ f1MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=kdR1YmSiFbbLGLSkWCpqyM48n5DrPBnChPgyJdhSDhQ=; b=bjq6Jd/HQ6wBABz1UZKt8FLju6EsGkHCVy5p9vpWBsm/EjmwAEJZ2x3Nwkl3cbIcRa Rj0ArV3V7N2Kfa25XDqeriB82NcmHNuieg5FUYahwqlqGOnD0aQkPr3CblVBZX/CenS/ weeg/+x+f9SloRCAQVtR4ZtXA8t0a0w2Cy1BQTMxJxwE2v1c78rKjMU4G0HyCd9Gptd/ SkAhJCrrWpcEska/YK1jk9JakbaNEQp/APf0wOC2yP5GSSAbF2Vo3b0pRBmtVRprDvL8 lFOisevLqWNJe6pZscLurI1ZOz4L0FL8x6uBtHx8I56UkCERH8BOLFdLS+3h5ecTY3uQ k1iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=SnEeQD8L; 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=QUARANTINE 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 q12-20020a056402518c00b00435dde2e2d6si18158820edd.562.2022.07.01.13.50.10; Fri, 01 Jul 2022 13:50:10 -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.s=20210112 header.b=SnEeQD8L; 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=QUARANTINE 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 01C1768B81D; Fri, 1 Jul 2022 23:49:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5743F68B786 for ; Fri, 1 Jul 2022 23:49:03 +0300 (EEST) Received: by mail-pf1-f175.google.com with SMTP id a15so3460381pfv.13; Fri, 01 Jul 2022 13:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=98LpnvH/HD0Q8JInmZMfJz2v1DbVTAU2FPyI3+P0RhI=; b=SnEeQD8LIzkWf9MQcJANebDniCW6r2xrvo8LdjXEtpOriDb/mnl5DhFhRc2sSVZtNO MeyBBSlDEKWqZMGppWiHfH7rDMdGnPjKcYJNIed7UgoKeLxHF9siZU1QBWPCUfyXF/PN sLAgN6iHExZbWwBrgbdTMVygXxGeDnRQVpwmy2sT61AY7BDUX4VD2fqLiCyXhgcaMlgi Sd8JstLjlrcA3r/4vcfPdCAoaRzjCOB9+XBWyNYQOzmE6WIDH+vqVJjHNtxjgMuHbNXI ZheX/e8SVgFVn7GiL8ZRqp1iF1ujV/4KIEn/g/g3y+rq/l113mnpQ9FW8l3ycRPMIDjS 3Raw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=98LpnvH/HD0Q8JInmZMfJz2v1DbVTAU2FPyI3+P0RhI=; b=O2XjN5Um2pBBDvWZSI5CfEu/l6aG06YoYLHUy0iclFtSI84h5P0E5ADvwR3wqCzEMB proQUAzeAsGXOxFOLr1PYf9hnamSi0OX0EcMT4Bh4qtPoZ2rdIahCFlsZGKGFZDmYabk soKj1AVdxG2PMBjeLABABZlGDyNcDr5g6TGC6IDse76pl6rlo9TEVK3O3MHRrFvuI733 MCIvT3n8SD8YEQe+8egV/Jc6e/3I/QDDXioVmmGq+fvJWhUfvIwGA6I60EqhVpkg3/Uy S4HvTfgppZ83jSMXt8Z/U8DMFQX1O82hbZfnRfvb6612/3PrgsCW9D9nJo4ibP4BnSSu 5xew== X-Gm-Message-State: AJIora9QmnNWXsPmk61HHXqxgqdpFhZEKzFlpPEHQP6YFbwjk2XNdwOP qzUx0XNHC8t7OiveMUwATIfGjwjw1YA9sw== X-Received: by 2002:a05:6a00:c:b0:525:55cb:83cd with SMTP id h12-20020a056a00000c00b0052555cb83cdmr22794204pfk.20.1656708541617; Fri, 01 Jul 2022 13:49:01 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id kx10-20020a17090b228a00b001ec9ae91e30sm4629309pjb.12.2022.07.01.13.49.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:49:00 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <320a8a535c619defc221b170448272373d367b98.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:51 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ctsJLTCnFrol From: softworkz Signed-off-by: softworkz --- libavcodec/mpeg12.h | 28 ++++++++++++++++++++++++++++ libavcodec/mpeg12dec.c | 40 +++++----------------------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h index e0406b32d9..84a829cdd3 100644 --- a/libavcodec/mpeg12.h +++ b/libavcodec/mpeg12.h @@ -23,6 +23,7 @@ #define AVCODEC_MPEG12_H #include "mpegvideo.h" +#include "libavutil/stereo3d.h" /* Start codes. */ #define SEQ_END_CODE 0x000001b7 @@ -34,6 +35,31 @@ #define EXT_START_CODE 0x000001b5 #define USER_START_CODE 0x000001b2 +typedef struct Mpeg1Context { + MpegEncContext mpeg_enc_ctx; + int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ + int repeat_field; /* true if we must repeat the field */ + AVPanScan pan_scan; /* some temporary storage for the panscan */ + AVStereo3D stereo3d; + int has_stereo3d; + AVBufferRef *a53_buf_ref; + uint8_t afd; + int has_afd; + int slice_count; + unsigned aspect_ratio_info; + AVRational save_aspect; + int save_width, save_height, save_progressive_seq; + int rc_buffer_size; + AVRational frame_rate_ext; /* MPEG-2 specific framerate modificator */ + unsigned frame_rate_index; + int sync; /* Did we reach a sync point like a GOP/SEQ/KEYFrame? */ + int closed_gop; + int tmpgexs; + int first_slice; + int extradata_decoded; + int64_t timecode_frame_start; /*< GOP timecode frame start number, in non drop frame format */ +} Mpeg1Context; + void ff_mpeg12_common_init(MpegEncContext *s); void ff_mpeg1_clean_buffers(MpegEncContext *s); @@ -45,4 +71,6 @@ void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard); +void ff_mpeg_decode_user_data(AVCodecContext *avctx, Mpeg1Context *s1, const uint8_t *p, int buf_size); + #endif /* AVCODEC_MPEG12_H */ diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index e9bde48f7a..11d2b58185 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -58,31 +58,6 @@ #define A53_MAX_CC_COUNT 2000 -typedef struct Mpeg1Context { - MpegEncContext mpeg_enc_ctx; - int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ - int repeat_field; /* true if we must repeat the field */ - AVPanScan pan_scan; /* some temporary storage for the panscan */ - AVStereo3D stereo3d; - int has_stereo3d; - AVBufferRef *a53_buf_ref; - uint8_t afd; - int has_afd; - int slice_count; - unsigned aspect_ratio_info; - AVRational save_aspect; - int save_width, save_height, save_progressive_seq; - int rc_buffer_size; - AVRational frame_rate_ext; /* MPEG-2 specific framerate modificator */ - unsigned frame_rate_index; - int sync; /* Did we reach a sync point like a GOP/SEQ/KEYFrame? */ - int closed_gop; - int tmpgexs; - int first_slice; - int extradata_decoded; - int64_t timecode_frame_start; /*< GOP timecode frame start number, in non drop frame format */ -} Mpeg1Context; - #define MB_TYPE_ZERO_MV 0x20000000 static const uint32_t ptype2mb_type[7] = { @@ -2198,11 +2173,9 @@ static int vcr2_init_sequence(AVCodecContext *avctx) return 0; } -static int mpeg_decode_a53_cc(AVCodecContext *avctx, +static int mpeg_decode_a53_cc(AVCodecContext *avctx, Mpeg1Context *s1, const uint8_t *p, int buf_size) { - Mpeg1Context *s1 = avctx->priv_data; - if (buf_size >= 6 && p[0] == 'G' && p[1] == 'A' && p[2] == '9' && p[3] == '4' && p[4] == 3 && (p[5] & 0x40)) { @@ -2333,12 +2306,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, return 0; } -static void mpeg_decode_user_data(AVCodecContext *avctx, - const uint8_t *p, int buf_size) +void ff_mpeg_decode_user_data(AVCodecContext *avctx, Mpeg1Context *s1, const uint8_t *p, int buf_size) { - Mpeg1Context *s = avctx->priv_data; const uint8_t *buf_end = p + buf_size; - Mpeg1Context *s1 = avctx->priv_data; #if 0 int i; @@ -2352,7 +2322,7 @@ static void mpeg_decode_user_data(AVCodecContext *avctx, int i; for(i=0; i<20; i++) if (!memcmp(p+i, "\0TMPGEXS\0", 9)){ - s->tmpgexs= 1; + s1->tmpgexs= 1; } } /* we parse the DTG active format information */ @@ -2398,7 +2368,7 @@ static void mpeg_decode_user_data(AVCodecContext *avctx, break; } } - } else if (mpeg_decode_a53_cc(avctx, p, buf_size)) { + } else if (mpeg_decode_a53_cc(avctx, s1, p, buf_size)) { return; } } @@ -2590,7 +2560,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, } break; case USER_START_CODE: - mpeg_decode_user_data(avctx, buf_ptr, input_size); + ff_mpeg_decode_user_data(avctx, s, buf_ptr, input_size); break; case GOP_START_CODE: if (last_code == 0) { From patchwork Fri Jul 1 20:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36582 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261104pzh; Fri, 1 Jul 2022 13:49:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1usMRfrjPfgJfilv60/N6sRxSkd1B1hMfW7Ho0lR3G0/5mKY4T7zWZrSal+BodAMFSfQ4Sc X-Received: by 2002:a05:6402:1907:b0:435:c243:a66e with SMTP id e7-20020a056402190700b00435c243a66emr20895016edz.44.1656708565150; Fri, 01 Jul 2022 13:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708565; cv=none; d=google.com; s=arc-20160816; b=a45MFl8upIviEl7w0KGHnyIR0vIznjEahJ3+oTDQBcURJj5ygS3qca/r9qC+l5EsE/ yMRFS014UBHzzcTpUr6Hnw0ULtWQ+XaWU6dEK7Z8TjKDiSc3xTxFxRwXWKFpnBTAP99z 3ZmONPx4RIsZCGrrclUTnytlVvDic9cYH8CyK+c5EEJ8yjchsvnMh9VaR0g7WdxmW/m/ 15lftFQfu7XYOoqc1POAtjCVLBuDSbiPyr1VMdGNTrtvQBuKtsFSwMu3V5CzGB7vuRfy RYZtTiu/WBDBcz/9T1MsgJSHCeFoCozKLCMNFipfNevlo8ggJbQQsTyaqbhb435xGrdq pJnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=gwru7bfy9cbhd4TR0+zWF3BGMHE3llBXnHyJgTzF+Uo=; b=Rfzg0VxJlW2Enc3CvZGfpkPg8xl0+JLSXx9V21A1d48GgYmAhFYvbI1ORou8g7goQd MZDT+xzFyOLcbNOQXphVf6/YWycjwBvBd/R1PblSklR4IFe4D7cnz8K9v8bl6MtxuP/a AtrNKmw/ewXg8GIVv5TZy40xV4vQZ+qVsP3N/rOitPy9vIfFF3c0uPqZ9k1onIk15dtp rs+cd7t0yA8M15/l/xiv3/Fp0Zj37gd3c9QBOE3k0bSi9DSP4aDh8aFXMUS6TLbNX0Qa 7zNsn6EX0FZPQl8KIC73wJKLh31wh7RlCTgNXv3q3v0YwC05pq2Yv1KOS4HhnXrI0P+N CroQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WOwiwvF8; 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=QUARANTINE 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 hw9-20020a170907a0c900b0070ebb93abe4si2187629ejc.117.2022.07.01.13.49.24; Fri, 01 Jul 2022 13:49:25 -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.s=20210112 header.b=WOwiwvF8; 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=QUARANTINE 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 8846968B7C9; Fri, 1 Jul 2022 23:49:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32A6D68B7CF for ; Fri, 1 Jul 2022 23:49:05 +0300 (EEST) Received: by mail-pj1-f42.google.com with SMTP id n16-20020a17090ade9000b001ed15b37424so3812317pjv.3; Fri, 01 Jul 2022 13:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dzOlKCC5GccuVS3kA5V1uiB3MN+uEfAZXWaAAaAZrMk=; b=WOwiwvF8O00IGdNLByr6kjbja2IxkJuEvmAAXj5OUALiTpiSK/2/eUxK+OvANjT90U PQZQdbXrcflkSrMyZJpMBytCcg1NFftDM3FoJ2SlKWZ5pTA0HxMNcYVKs1iv748JYM9l R3mrtqgj7UKFcPnf3sZsAMMwVGAzAFV7uY3f9DgXrJpsQW0fspoG2vfiGytAzbFBPzOk p4hHAgzMyKOBRaN0eqY3yfnhrIJzXVUqpzvsP1GoyUGYgOjrk6fmhCAX1iDaickjrRcW Dkr3oMCsqAKA4ndlls2L7moms9AYP591tEnsEDq0Kxg1isIdORtqFPdlPbRoKNLXOTGS 6MMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dzOlKCC5GccuVS3kA5V1uiB3MN+uEfAZXWaAAaAZrMk=; b=0ppBVBXkerzG24SVFRoN0JVtJfldyQzwQldx/CGKqObXgXvnQ4bO2Syg+lyM+QLMth TtAz+zWgUAyVuFVhNBeULSP8vKItyd9wvZfMl1S3nQhvcK8p9yPo2b0gV8E8gvX4Xkqs Gf2Gmw1WwkUsWgQXvOI7G7iXb3aASevnjw8AS3PLDly+DierTAj7fOPpdJZmNS84gzvX HTuU5iDkSBtKQnZOLgf9s1dfUbCmA1qBDA0Fig7tlPbWhd4TG3jTyQwTNNQPhycXDnHh 3YGvdafoATZIh7ctJcSiOVC8Fq9Ty9QEgKScQLWYJOv9zJBVIihckyigodHIqtEo8M9g o0Ew== X-Gm-Message-State: AJIora+05BNAS2k4+Z3UvTIrM2iecLT71FuKVwVgxrFIrep/QLRk9vNw SwFGXonKC3pIe7yFXO0gdehuNBf94IrwcQ== X-Received: by 2002:a17:90a:e4c6:b0:1ed:4ffb:11f8 with SMTP id e6-20020a17090ae4c600b001ed4ffb11f8mr19182836pju.150.1656708543218; Fri, 01 Jul 2022 13:49:03 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id h27-20020aa79f5b000000b0051c79bd5047sm16100960pfr.139.2022.07.01.13.49.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:49:02 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:52 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 4/6] avcodec/hevcdec: make set_side_data() accessible 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WNfn/D8XFMz8 From: softworkz Signed-off-by: softworkz --- libavcodec/hevcdec.c | 117 +++++++++++++++++++++---------------------- libavcodec/hevcdec.h | 9 ++++ 2 files changed, 67 insertions(+), 59 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index e84c30dd13..b4d8db8c6b 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2726,23 +2726,22 @@ error: return res; } -static int set_side_data(HEVCContext *s) +int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, HEVCContext *s, AVFrame *out) { - AVFrame *out = s->ref->frame; - int ret; + int ret = 0; - if (s->sei.frame_packing.present && - s->sei.frame_packing.arrangement_type >= 3 && - s->sei.frame_packing.arrangement_type <= 5 && - s->sei.frame_packing.content_interpretation_type > 0 && - s->sei.frame_packing.content_interpretation_type < 3) { + if (sei->frame_packing.present && + sei->frame_packing.arrangement_type >= 3 && + sei->frame_packing.arrangement_type <= 5 && + sei->frame_packing.content_interpretation_type > 0 && + sei->frame_packing.content_interpretation_type < 3) { AVStereo3D *stereo = av_stereo3d_create_side_data(out); if (!stereo) return AVERROR(ENOMEM); - switch (s->sei.frame_packing.arrangement_type) { + switch (sei->frame_packing.arrangement_type) { case 3: - if (s->sei.frame_packing.quincunx_subsampling) + if (sei->frame_packing.quincunx_subsampling) stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX; else stereo->type = AV_STEREO3D_SIDEBYSIDE; @@ -2755,21 +2754,21 @@ static int set_side_data(HEVCContext *s) break; } - if (s->sei.frame_packing.content_interpretation_type == 2) + if (sei->frame_packing.content_interpretation_type == 2) stereo->flags = AV_STEREO3D_FLAG_INVERT; - if (s->sei.frame_packing.arrangement_type == 5) { - if (s->sei.frame_packing.current_frame_is_frame0_flag) + if (sei->frame_packing.arrangement_type == 5) { + if (sei->frame_packing.current_frame_is_frame0_flag) stereo->view = AV_STEREO3D_VIEW_LEFT; else stereo->view = AV_STEREO3D_VIEW_RIGHT; } } - if (s->sei.display_orientation.present && - (s->sei.display_orientation.anticlockwise_rotation || - s->sei.display_orientation.hflip || s->sei.display_orientation.vflip)) { - double angle = s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16); + if (sei->display_orientation.present && + (sei->display_orientation.anticlockwise_rotation || + sei->display_orientation.hflip || sei->display_orientation.vflip)) { + double angle = sei->display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16); AVFrameSideData *rotation = av_frame_new_side_data(out, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9); @@ -2788,17 +2787,17 @@ static int set_side_data(HEVCContext *s) * (1 - 2 * !!s->sei.display_orientation.vflip); av_display_rotation_set((int32_t *)rotation->data, angle); av_display_matrix_flip((int32_t *)rotation->data, - s->sei.display_orientation.hflip, - s->sei.display_orientation.vflip); + sei->display_orientation.hflip, + sei->display_orientation.vflip); } // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1 // so the side data persists for the entire coded video sequence. - if (s->sei.mastering_display.present > 0 && + if (s && sei->mastering_display.present > 0 && IS_IRAP(s) && s->no_rasl_output_flag) { - s->sei.mastering_display.present--; + sei->mastering_display.present--; } - if (s->sei.mastering_display.present) { + if (sei->mastering_display.present) { // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b const int mapping[3] = {2, 0, 1}; const int chroma_den = 50000; @@ -2811,25 +2810,25 @@ static int set_side_data(HEVCContext *s) for (i = 0; i < 3; i++) { const int j = mapping[i]; - metadata->display_primaries[i][0].num = s->sei.mastering_display.display_primaries[j][0]; + metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; metadata->display_primaries[i][0].den = chroma_den; - metadata->display_primaries[i][1].num = s->sei.mastering_display.display_primaries[j][1]; + metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; metadata->display_primaries[i][1].den = chroma_den; } - metadata->white_point[0].num = s->sei.mastering_display.white_point[0]; + metadata->white_point[0].num = sei->mastering_display.white_point[0]; metadata->white_point[0].den = chroma_den; - metadata->white_point[1].num = s->sei.mastering_display.white_point[1]; + metadata->white_point[1].num = sei->mastering_display.white_point[1]; metadata->white_point[1].den = chroma_den; - metadata->max_luminance.num = s->sei.mastering_display.max_luminance; + metadata->max_luminance.num = sei->mastering_display.max_luminance; metadata->max_luminance.den = luma_den; - metadata->min_luminance.num = s->sei.mastering_display.min_luminance; + metadata->min_luminance.num = sei->mastering_display.min_luminance; metadata->min_luminance.den = luma_den; metadata->has_luminance = 1; metadata->has_primaries = 1; - av_log(s->avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); - av_log(s->avctx, AV_LOG_DEBUG, + av_log(logctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); + av_log(logctx, AV_LOG_DEBUG, "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", av_q2d(metadata->display_primaries[0][0]), av_q2d(metadata->display_primaries[0][1]), @@ -2838,31 +2837,31 @@ static int set_side_data(HEVCContext *s) av_q2d(metadata->display_primaries[2][0]), av_q2d(metadata->display_primaries[2][1]), av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); - av_log(s->avctx, AV_LOG_DEBUG, + av_log(logctx, AV_LOG_DEBUG, "min_luminance=%f, max_luminance=%f\n", av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1 // so the side data persists for the entire coded video sequence. - if (s->sei.content_light.present > 0 && + if (s && sei->content_light.present > 0 && IS_IRAP(s) && s->no_rasl_output_flag) { - s->sei.content_light.present--; + sei->content_light.present--; } - if (s->sei.content_light.present) { + if (sei->content_light.present) { AVContentLightMetadata *metadata = av_content_light_metadata_create_side_data(out); if (!metadata) return AVERROR(ENOMEM); - metadata->MaxCLL = s->sei.content_light.max_content_light_level; - metadata->MaxFALL = s->sei.content_light.max_pic_average_light_level; + metadata->MaxCLL = sei->content_light.max_content_light_level; + metadata->MaxFALL = sei->content_light.max_pic_average_light_level; - av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); - av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", + av_log(logctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); + av_log(logctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", metadata->MaxCLL, metadata->MaxFALL); } - if (s->sei.a53_caption.buf_ref) { - HEVCSEIA53Caption *a53 = &s->sei.a53_caption; + if (sei->a53_caption.buf_ref) { + HEVCSEIA53Caption *a53 = &sei->a53_caption; AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref); if (!sd) @@ -2870,8 +2869,8 @@ static int set_side_data(HEVCContext *s) a53->buf_ref = NULL; } - for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) { - HEVCSEIUnregistered *unreg = &s->sei.unregistered; + for (int i = 0; i < sei->unregistered.nb_buf_ref; i++) { + HEVCSEIUnregistered *unreg = &sei->unregistered; if (unreg->buf_ref[i]) { AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, @@ -2882,9 +2881,9 @@ static int set_side_data(HEVCContext *s) unreg->buf_ref[i] = NULL; } } - s->sei.unregistered.nb_buf_ref = 0; + sei->unregistered.nb_buf_ref = 0; - if (s->sei.timecode.present) { + if (s && sei->timecode.present) { uint32_t *tc_sd; char tcbuf[AV_TIMECODE_STR_SIZE]; AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE, @@ -2893,25 +2892,25 @@ static int set_side_data(HEVCContext *s) return AVERROR(ENOMEM); tc_sd = (uint32_t*)tcside->data; - tc_sd[0] = s->sei.timecode.num_clock_ts; + tc_sd[0] = sei->timecode.num_clock_ts; for (int i = 0; i < tc_sd[0]; i++) { - int drop = s->sei.timecode.cnt_dropped_flag[i]; - int hh = s->sei.timecode.hours_value[i]; - int mm = s->sei.timecode.minutes_value[i]; - int ss = s->sei.timecode.seconds_value[i]; - int ff = s->sei.timecode.n_frames[i]; + int drop = sei->timecode.cnt_dropped_flag[i]; + int hh = sei->timecode.hours_value[i]; + int mm = sei->timecode.minutes_value[i]; + int ss = sei->timecode.seconds_value[i]; + int ff = sei->timecode.n_frames[i]; tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); av_dict_set(&out->metadata, "timecode", tcbuf, 0); } - s->sei.timecode.num_clock_ts = 0; + sei->timecode.num_clock_ts = 0; } - if (s->sei.film_grain_characteristics.present) { - HEVCSEIFilmGrainCharacteristics *fgc = &s->sei.film_grain_characteristics; + if (s && sei->film_grain_characteristics.present) { + HEVCSEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics; AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out); if (!fgp) return AVERROR(ENOMEM); @@ -2965,8 +2964,8 @@ static int set_side_data(HEVCContext *s) fgc->present = fgc->persistence_flag; } - if (s->sei.dynamic_hdr_plus.info) { - AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_plus.info); + if (sei->dynamic_hdr_plus.info) { + AVBufferRef *info_ref = av_buffer_ref(sei->dynamic_hdr_plus.info); if (!info_ref) return AVERROR(ENOMEM); @@ -2976,7 +2975,7 @@ static int set_side_data(HEVCContext *s) } } - if (s->rpu_buf) { + if (s && s->rpu_buf) { AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); if (!rpu) return AVERROR(ENOMEM); @@ -2984,10 +2983,10 @@ static int set_side_data(HEVCContext *s) s->rpu_buf = NULL; } - if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) + if (s && (ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) return ret; - if (s->sei.dynamic_hdr_vivid.info) { + if (s && s->sei.dynamic_hdr_vivid.info) { AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_vivid.info); if (!info_ref) return AVERROR(ENOMEM); @@ -3046,7 +3045,7 @@ static int hevc_frame_start(HEVCContext *s) goto fail; } - ret = set_side_data(s); + ret = ff_hevc_set_side_data(s->avctx, &s->sei, s, s->ref->frame); if (ret < 0) goto fail; diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index de861b88b3..cd8cd40da0 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -690,6 +690,15 @@ void ff_hevc_hls_residual_coding(HEVCContext *s, int x0, int y0, void ff_hevc_hls_mvd_coding(HEVCContext *s, int x0, int y0, int log2_cb_size); +/** + * Set the decodec side data to an AVFrame. + * @logctx context for logging. + * @sei HEVCSEI decoding context, must not be NULL. + * @s HEVCContext, can be NULL. + * @return < 0 on error, 0 otherwise. + */ +int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, HEVCContext *s, AVFrame *out); + extern const uint8_t ff_hevc_qpel_extra_before[4]; extern const uint8_t ff_hevc_qpel_extra_after[4]; extern const uint8_t ff_hevc_qpel_extra[4]; From patchwork Fri Jul 1 20:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36583 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261171pzh; Fri, 1 Jul 2022 13:49:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWC+Y5nH9OXI8NJu+ZQQ6OwOn0W7KXUSt+1PvvNR3BAZPjnDVuXvpYMqZRsFRtdAXRpU+X X-Received: by 2002:a17:907:9812:b0:726:3e5b:d299 with SMTP id ji18-20020a170907981200b007263e5bd299mr16682573ejc.26.1656708574268; Fri, 01 Jul 2022 13:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708574; cv=none; d=google.com; s=arc-20160816; b=iR2T42IST5k5z5Goe+UTkOIymQ6+dlE2OWKIWu7Z/G1zNqe5Jzl+8ilTpXlZl6OXTB kG8LLEVhpXn/WOUVaaEIlixm1igkzAOb82+AaQrci8r4ReTXYAHJ/Vwv5XqEVrA6aQd1 KrywOXM1JrsGTLp5zKn2/+ueKkJYGzoQTzeHZqvDqub5vIEhKj2+MlDsMHTCwngxmspW M1meIgr0hMHhgcVqsCxfb/rNFqMh/oGJ6nZYS3jGSwf57Su16FLFOnFsOR+URklloyba E5D372f6E9lFQLF/JcaZ+LP0j7YMblk70jfErZlXe+CkwJeOYjGIUGaArjxX4Gn033+x F1CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=X9v33IOMlkj3SYealTptb6YXpC5vMBQlLLp6IKaus8M=; b=UkGH/QDJ/N8o219sZxA42j1bi1vCKLadN9t/EIp/D86iSAsVHW4aN2f8PJZHRe8XMj rkJzcE0eZAdIoy5GOeeJe/93eu3WbfM5N7+eiZ5kXRyG+OZMgIE/fsAQbwA0VACt3Rm5 64Jx8Er9qecWTt+/ePPbTYKIF8xhFiJKiFLGv1z6PwvKgjhkY+XDtIGWzKZreW/Euo14 gNcBy4dBVBsCJIxkzUQ6ntuSb7wcvEHInY+OdiOf9m2et93rLSYarfLke6FcRM6m2jAx TkYmYQ1cA5RbnZANJhbv7mZaxhpNaXUhz6m9TQXJh8IOQ59c4GF9uiEUcD/zMPQhW/Kf 15lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="g/r8IFGw"; 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=QUARANTINE 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 y5-20020a17090668c500b007136091f459si3686315ejr.302.2022.07.01.13.49.33; Fri, 01 Jul 2022 13:49:34 -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.s=20210112 header.b="g/r8IFGw"; 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=QUARANTINE 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 AE31768B803; Fri, 1 Jul 2022 23:49:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 160F968B7B5 for ; Fri, 1 Jul 2022 23:49:06 +0300 (EEST) Received: by mail-pj1-f46.google.com with SMTP id d14so3701418pjs.3; Fri, 01 Jul 2022 13:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=woDLBsAm1baHrRCV48xAJlDmANE3EG0buKKKgOC6iEk=; b=g/r8IFGw5/4UWthgh3NZQINfX3RmwQUbQEDhLB5FWoZogaLFl5bFoVoDO23qDXdAmK aftuAah+U0Vreu9trfePc4SpGYGoXawwmqa0VQFbv+j2EbUGg1Syr7wDf3dJoFCxTNy0 Z45pAAqHf7rQwi9m+ya1TlYp5RWv3P7YKyDiBP9AdWgKD9D3NiENMbZKBGnmku4Tr1pQ kloJPD+JceGzFkRffYBlzaaX7wWxYri9Pf0n62Z8TsQtEtwIYRPRxdWXtrCEonWKsCi9 r1SFf0IoupDR/31a0D1bt4S1DKcLZnojNVd73j/t2onQI46eRjACTbcFf3xnB2lWuwMx TkIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=woDLBsAm1baHrRCV48xAJlDmANE3EG0buKKKgOC6iEk=; b=RjIL1VpdBuiCMvptIlSG7F03LXNYi03fMBrWCp//ZIxh+39HLhK5/ipzim0fE0ft18 URxhQyv6ed8vvuXP8ZESnVbLimf/UA7xply9FT6y2gExsTR8Y69gk2qphfBDyjqYfjXP fDFxBXRMbqjEGaCr8hvyuG+O2Sul8XdUTfrkhOqpUGDIIoJb/KN2vk1GPvcJdjpB7Lpw fVhYIW7hoLDqBb7Y21TjF8aIn4zgOAF/WbGplu1FnRQ0KKKLBbEqVZRAqk5qa1D2o420 GsF/gAx+Ubr/U3GRzDAfr46hwbfNHFLKcglTaQUvlhInAxQ68h09QC8ahGj+5vA09UXv q1+g== X-Gm-Message-State: AJIora86RARtm/0mOURQQ8Oo0y8K1yzV/sxbjA2m/L6YgXkir/Rcb17j Jwi1KQQK81nR01igsnDK84cwxgNINUDJOg== X-Received: by 2002:a17:902:f151:b0:16a:466a:4ae4 with SMTP id d17-20020a170902f15100b0016a466a4ae4mr2527205plb.61.1656708544415; Fri, 01 Jul 2022 13:49:04 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id v4-20020a170902b7c400b0016223b5d228sm15899458plz.288.2022.07.01.13.49.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:49:03 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <4c0b6eb4cb9b480a9cab1695719cc52f9bb078dc.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:53 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 5/6] avcodec/h264dec: make h264_export_frame_props() accessible 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UprlDMeJz9xv From: softworkz Signed-off-by: softworkz --- libavcodec/h264_slice.c | 98 +++++++++++++++++++++-------------------- libavcodec/h264dec.h | 2 + 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index d56722a5c2..f2a4c1c657 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1157,11 +1157,10 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl return 0; } -static int h264_export_frame_props(H264Context *h) +int ff_h264_export_frame_props(AVCodecContext *logctx, H264SEIContext *sei, H264Context *h, AVFrame *out) { - const SPS *sps = h->ps.sps; - H264Picture *cur = h->cur_pic_ptr; - AVFrame *out = cur->f; + const SPS *sps = h ? h->ps.sps : NULL; + H264Picture *cur = h ? h->cur_pic_ptr : NULL; out->interlaced_frame = 0; out->repeat_pict = 0; @@ -1169,19 +1168,19 @@ static int h264_export_frame_props(H264Context *h) /* Signal interlacing information externally. */ /* Prioritize picture timing SEI information over used * decoding process if it exists. */ - if (h->sei.picture_timing.present) { - int ret = ff_h264_sei_process_picture_timing(&h->sei.picture_timing, sps, - h->avctx); + if (sps && sei->picture_timing.present) { + int ret = ff_h264_sei_process_picture_timing(&sei->picture_timing, sps, + logctx); if (ret < 0) { - av_log(h->avctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); - if (h->avctx->err_recognition & AV_EF_EXPLODE) + av_log(logctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); + if (logctx->err_recognition & AV_EF_EXPLODE) return ret; - h->sei.picture_timing.present = 0; + sei->picture_timing.present = 0; } } - if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { - H264SEIPictureTiming *pt = &h->sei.picture_timing; + if (h && sps && sps->pic_struct_present_flag && sei->picture_timing.present) { + H264SEIPictureTiming *pt = &sei->picture_timing; switch (pt->pic_struct) { case H264_SEI_PIC_STRUCT_FRAME: break; @@ -1215,21 +1214,23 @@ static int h264_export_frame_props(H264Context *h) if ((pt->ct_type & 3) && pt->pic_struct <= H264_SEI_PIC_STRUCT_BOTTOM_TOP) out->interlaced_frame = (pt->ct_type & (1 << 1)) != 0; - } else { + } else if (h) { /* Derive interlacing flag from used decoding process. */ out->interlaced_frame = FIELD_OR_MBAFF_PICTURE(h); } - h->prev_interlaced_frame = out->interlaced_frame; - if (cur->field_poc[0] != cur->field_poc[1]) { + if (h) + h->prev_interlaced_frame = out->interlaced_frame; + + if (sps && cur->field_poc[0] != cur->field_poc[1]) { /* Derive top_field_first from field pocs. */ out->top_field_first = cur->field_poc[0] < cur->field_poc[1]; - } else { - if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { + } else if (sps) { + if (sps->pic_struct_present_flag && sei->picture_timing.present) { /* Use picture timing SEI information. Even if it is a * information of a past frame, better than nothing. */ - if (h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM || - h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP) + if (sei->picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM || + sei->picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP) out->top_field_first = 1; else out->top_field_first = 0; @@ -1243,11 +1244,11 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.frame_packing.present && - h->sei.frame_packing.arrangement_type <= 6 && - h->sei.frame_packing.content_interpretation_type > 0 && - h->sei.frame_packing.content_interpretation_type < 3) { - H264SEIFramePacking *fp = &h->sei.frame_packing; + if (sei->frame_packing.present && + sei->frame_packing.arrangement_type <= 6 && + sei->frame_packing.content_interpretation_type > 0 && + sei->frame_packing.content_interpretation_type < 3) { + H264SEIFramePacking *fp = &sei->frame_packing; AVStereo3D *stereo = av_stereo3d_create_side_data(out); if (stereo) { switch (fp->arrangement_type) { @@ -1289,11 +1290,11 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.display_orientation.present && - (h->sei.display_orientation.anticlockwise_rotation || - h->sei.display_orientation.hflip || - h->sei.display_orientation.vflip)) { - H264SEIDisplayOrientation *o = &h->sei.display_orientation; + if (sei->display_orientation.present && + (sei->display_orientation.anticlockwise_rotation || + sei->display_orientation.hflip || + sei->display_orientation.vflip)) { + H264SEIDisplayOrientation *o = &sei->display_orientation; double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16); AVFrameSideData *rotation = av_frame_new_side_data(out, AV_FRAME_DATA_DISPLAYMATRIX, @@ -1314,29 +1315,30 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.afd.present) { + if (sei->afd.present) { AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD, sizeof(uint8_t)); if (sd) { - *sd->data = h->sei.afd.active_format_description; - h->sei.afd.present = 0; + *sd->data = sei->afd.active_format_description; + sei->afd.present = 0; } } - if (h->sei.a53_caption.buf_ref) { - H264SEIA53Caption *a53 = &h->sei.a53_caption; + if (sei->a53_caption.buf_ref) { + H264SEIA53Caption *a53 = &sei->a53_caption; AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref); if (!sd) av_buffer_unref(&a53->buf_ref); a53->buf_ref = NULL; - h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; + if (h) + h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } - for (int i = 0; i < h->sei.unregistered.nb_buf_ref; i++) { - H264SEIUnregistered *unreg = &h->sei.unregistered; + for (int i = 0; i < sei->unregistered.nb_buf_ref; i++) { + H264SEIUnregistered *unreg = &sei->unregistered; if (unreg->buf_ref[i]) { AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, @@ -1347,10 +1349,10 @@ static int h264_export_frame_props(H264Context *h) unreg->buf_ref[i] = NULL; } } - h->sei.unregistered.nb_buf_ref = 0; + sei->unregistered.nb_buf_ref = 0; - if (h->sei.film_grain_characteristics.present) { - H264SEIFilmGrainCharacteristics *fgc = &h->sei.film_grain_characteristics; + if (h && sps && sei->film_grain_characteristics.present) { + H264SEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics; AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out); if (!fgp) return AVERROR(ENOMEM); @@ -1404,7 +1406,7 @@ static int h264_export_frame_props(H264Context *h) h->avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; } - if (h->sei.picture_timing.timecode_cnt > 0) { + if (h && sei->picture_timing.timecode_cnt > 0) { uint32_t *tc_sd; char tcbuf[AV_TIMECODE_STR_SIZE]; @@ -1415,14 +1417,14 @@ static int h264_export_frame_props(H264Context *h) return AVERROR(ENOMEM); tc_sd = (uint32_t*)tcside->data; - tc_sd[0] = h->sei.picture_timing.timecode_cnt; + tc_sd[0] = sei->picture_timing.timecode_cnt; for (int i = 0; i < tc_sd[0]; i++) { - int drop = h->sei.picture_timing.timecode[i].dropframe; - int hh = h->sei.picture_timing.timecode[i].hours; - int mm = h->sei.picture_timing.timecode[i].minutes; - int ss = h->sei.picture_timing.timecode[i].seconds; - int ff = h->sei.picture_timing.timecode[i].frame; + int drop = sei->picture_timing.timecode[i].dropframe; + int hh = sei->picture_timing.timecode[i].hours; + int mm = sei->picture_timing.timecode[i].minutes; + int ss = sei->picture_timing.timecode[i].seconds; + int ff = sei->picture_timing.timecode[i].frame; tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff); av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0); @@ -1817,7 +1819,7 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, * field coded frames, since some SEI information is present for each field * and is merged by the SEI parsing code. */ if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) { - ret = h264_export_frame_props(h); + ret = ff_h264_export_frame_props(h->avctx, &h->sei, h, h->cur_pic_ptr->f); if (ret < 0) return ret; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 9a1ec1bace..38930da4ca 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -808,4 +808,6 @@ void ff_h264_free_tables(H264Context *h); void ff_h264_set_erpic(ERPicture *dst, H264Picture *src); +int ff_h264_export_frame_props(AVCodecContext *logctx, H264SEIContext *sei, H264Context *h, AVFrame *out); + #endif /* AVCODEC_H264DEC_H */ From patchwork Fri Jul 1 20:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36586 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261384pzh; Fri, 1 Jul 2022 13:50:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZLMowtKaoNNshYc2Z6GzuuMOIvgk1bnUvCWAWVRx3qEED6z/YWmyJl8EKXfodmmvoiH6S X-Received: by 2002:a05:6402:4011:b0:437:e02f:7bdf with SMTP id d17-20020a056402401100b00437e02f7bdfmr18101860eda.105.1656708601065; Fri, 01 Jul 2022 13:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708601; cv=none; d=google.com; s=arc-20160816; b=TGWkzNIgANc1n615V4K7YJxn1NNQCLuSTRZAL3WIUVHOG0H1m+g5oUoWwSqB3P+kEl C2YUP3fo+8giVBaYVVQ7V/PGbMPRiH/zXQJ1wMDAojJabyUpwk53LNEPKQilM8XHVqE7 R/JEPnRwhEzAwAmFFs0OF0I+aXdYO5DGOnGLVvnM23a9LUU6khJXDUfLCWSC+V6rrV+B Uytt2wCYzTMCH54GW7CPJ+83r/apNK0fq6U/LeEtXjJn+b/n1olbOFbub+Jvf5NUeoyH b/lQLyILkMZ9Wj0DGpxPXw9cqSw+elRBXXjp1E1tkmNXleqTEZAQU1osfM9bwXDx8Qar XPmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=XfE/lksAvyEOcQWTaGdHE0NjLpAWnj/mjy4BvFG2Wj8=; b=dzE5G7cVA7BK0goH5GtXekrtuoAJ3pABsP9yvpp/Aybww5uIDxmTsaMPoZM03dkfFg fD6ASYP4QcoNT1c4zt2xl7DOmU6bzkGQqDjyOQuXpW9IUkau7DaNaRnktRb1yWlpUwnG ZKV6OK7lTH/ap1ODCQNbbD2Lhs/WypURky8CnKg9sTpaZ0J9EDuDjF7Rgaocqbvncyhl 0BQ85bUxXNsSv2UjrwDWZ23FynIHINHVil6jKU772e72MdhPkwTSoAlBi33wx81K3WSB t7Ju/RUWuO15q3L71VMiPqQbCe1rCYtzc01j3nIHIa7seYhsw4ZhQn37Csw/Mai8zXhl q6xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dK8Ieo6V; 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=QUARANTINE 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 k17-20020a170906971100b007157d4e84b8si4127126ejx.304.2022.07.01.13.50.00; Fri, 01 Jul 2022 13:50:01 -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.s=20210112 header.b=dK8Ieo6V; 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=QUARANTINE 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 E6BB768B840; Fri, 1 Jul 2022 23:49:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72F5368B80E for ; Fri, 1 Jul 2022 23:49:07 +0300 (EEST) Received: by mail-pl1-f182.google.com with SMTP id l6so3392498plg.11; Fri, 01 Jul 2022 13:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Mxkwh+cp7e4o/urV3kIyraElBQIhmXIDSSPVgjaDNSo=; b=dK8Ieo6V2oJK38eeJqHqvtDwnJGmLSBgW4jVhkztQTvEJyra9N5pblTgSSzUkUpLGz lDT3JnrKN5Km11xPiOjvuc+I6a/vMCBsS7TF1xwMEVQ+Lkl8XUdV3wXPw3G4Sfc6YB0N SO/ixoOnbBQwdev3/mArSfq/gNWeij+J6u9eskdooo0D9hkBGdOOSd1uNmWqLjFVfLNy ttv0X+9bgg2EX5pKKd+NxZhkUg5n64EqI5rzOaMJEo74QepkKVY0nqtsqlYUYjC+08aT vVEf5ulphJaYa5BdkahXsuWglSfEocg1H7Z4A5jQByJbBaNnDpIcSrrbvw/F7ZueAtem 8MfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Mxkwh+cp7e4o/urV3kIyraElBQIhmXIDSSPVgjaDNSo=; b=2fVG2HTldDJzKKpNO9vm7TRqbqpUbo/cmefZMQiN8rsUDH4blm0L7XUQFG07L5NfLa JlOaAKYzgBIAmLIDhJrbxTy91b5yPybCgUj3yDdaz5W/EPjtOuMUc8XO5v8UajkrLPXt jSVxpN/wL7ewaAN4EELVKs6M6caISmdvqNEOQNlDEATmsvJU5325Ba5aI9DubdpUbdRZ oJQpnjUe364vbIC+jcebG+9htTzUlq6jxMZwFz+4QNEkU82LIAJAmX0QwNwPaM64sfvs dnwGlfNDZndYx72aFkSjHn2qAYJyvKAizuCcIEgNSNVq9ed+/UeWSAuQ5z7H4KK4M4D2 nHsQ== X-Gm-Message-State: AJIora9Pf6KTYIvmdEMniz7M+baA9au74luwzeFYBnb8mzsX/VMXj6Ac OFeXMLeLf9iBp1bqgI32uTVdZP+NmBzR0Q== X-Received: by 2002:a17:90a:d158:b0:1ec:8298:40dc with SMTP id t24-20020a17090ad15800b001ec829840dcmr18844398pjw.51.1656708545817; Fri, 01 Jul 2022 13:49:05 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id g2-20020a170902d5c200b0015e8d4eb29csm15977481plh.230.2022.07.01.13.49.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:49:05 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <19bc00be4db904ca8eb711b5a017678338ea8445.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:54 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FAiaGQICLxNn From: softworkz Signed-off-by: softworkz --- libavcodec/Makefile | 6 +- libavcodec/hevcdsp.c | 4 + libavcodec/qsvdec.c | 234 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+), 1 deletion(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3b8f7b5e01..7b98391745 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -144,7 +144,11 @@ OBJS-$(CONFIG_MSS34DSP) += mss34dsp.o OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o OBJS-$(CONFIG_QPELDSP) += qpeldsp.o OBJS-$(CONFIG_QSV) += qsv.o -OBJS-$(CONFIG_QSVDEC) += qsvdec.o +OBJS-$(CONFIG_QSVDEC) += qsvdec.o h264_slice.o h264_cabac.o h264_cavlc.o \ + h264_direct.o h264_mb.o h264_picture.o h264_loopfilter.o \ + h264dec.o h264_refs.o cabac.o hevcdec.o hevc_refs.o \ + hevc_filter.o hevc_cabac.o hevc_mvs.o hevcpred.o hevcdsp.o \ + h274.o dovi_rpu.o mpeg12dec.o OBJS-$(CONFIG_QSVENC) += qsvenc.o OBJS-$(CONFIG_RANGECODER) += rangecoder.o OBJS-$(CONFIG_RDFT) += rdft.o diff --git a/libavcodec/hevcdsp.c b/libavcodec/hevcdsp.c index 2ca551df1d..c7a436d30f 100644 --- a/libavcodec/hevcdsp.c +++ b/libavcodec/hevcdsp.c @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config_components.h" + #include "hevcdsp.h" static const int8_t transform[32][32] = { @@ -257,6 +259,7 @@ int i = 0; break; } +#if CONFIG_HEVC_DECODER #if ARCH_AARCH64 ff_hevc_dsp_init_aarch64(hevcdsp, bit_depth); #elif ARCH_ARM @@ -270,4 +273,5 @@ int i = 0; #elif ARCH_LOONGARCH ff_hevc_dsp_init_loongarch(hevcdsp, bit_depth); #endif +#endif } diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 5fc5bed4c8..e854f363ec 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -49,6 +49,12 @@ #include "hwconfig.h" #include "qsv.h" #include "qsv_internal.h" +#include "h264dec.h" +#include "h264_sei.h" +#include "hevcdec.h" +#include "hevc_ps.h" +#include "hevc_sei.h" +#include "mpeg12.h" static const AVRational mfx_tb = { 1, 90000 }; @@ -60,6 +66,8 @@ static const AVRational mfx_tb = { 1, 90000 }; AV_NOPTS_VALUE : pts_tb.num ? \ av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts) +#define PAYLOAD_BUFFER_SIZE 65535 + typedef struct QSVAsyncFrame { mfxSyncPoint *sync; QSVFrame *frame; @@ -101,6 +109,9 @@ typedef struct QSVContext { mfxExtBuffer **ext_buffers; int nb_ext_buffers; + + mfxU8 payload_buffer[PAYLOAD_BUFFER_SIZE]; + Mpeg1Context mpeg_ctx; } QSVContext; static const AVCodecHWConfigInternal *const qsv_hw_configs[] = { @@ -599,6 +610,210 @@ static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam return 0; } #endif +static int find_start_offset(mfxU8 data[4]) +{ + if (data[0] == 0 && data[1] == 0 && data[2] == 1) + return 3; + + if (data[0] == 0 && data[1] == 0 && data[2] == 0 && data[3] == 1) + return 4; + + return 0; +} + +static int parse_sei_h264(AVCodecContext* avctx, QSVContext* q, AVFrame* out) +{ + H264SEIContext sei = { 0 }; + GetBitContext gb = { 0 }; + mfxPayload payload = { 0, .Data = &q->payload_buffer[0], .BufSize = sizeof(q->payload_buffer) }; + mfxU64 ts; + int ret; + + while (1) { + int start; + memset(payload.Data, 0, payload.BufSize); + + ret = MFXVideoDECODE_GetPayload(q->session, &ts, &payload); + if (ret == MFX_ERR_NOT_ENOUGH_BUFFER) { + av_log(avctx, AV_LOG_WARNING, "Warning: Insufficient buffer on GetPayload(). Size: %"PRIu64" Needed: %d\n", sizeof(q->payload_buffer), payload.BufSize); + return 0; + } + if (ret != MFX_ERR_NONE) + return ret; + + if (payload.NumBit == 0 || payload.NumBit >= payload.BufSize * 8) + break; + + start = find_start_offset(payload.Data); + + switch (payload.Type) { + case SEI_TYPE_BUFFERING_PERIOD: + case SEI_TYPE_PIC_TIMING: + continue; + } + + if (init_get_bits(&gb, &payload.Data[start], payload.NumBit - start * 8) < 0) + av_log(avctx, AV_LOG_ERROR, "Error initializing bitstream reader SEI type: %d Numbits %d error: %d\n", payload.Type, payload.NumBit, ret); + else { + ret = ff_h264_sei_decode(&sei, &gb, NULL, avctx); + + if (ret < 0) + av_log(avctx, AV_LOG_WARNING, "Failed to parse SEI type: %d Numbits %d error: %d\n", payload.Type, payload.NumBit, ret); + else + av_log(avctx, AV_LOG_DEBUG, "mfxPayload Type: %d Numbits %d\n", payload.Type, payload.NumBit); + } + } + + if (out) + return ff_h264_export_frame_props(avctx, &sei, NULL, out); + + return 0; +} + +static int parse_sei_hevc(AVCodecContext* avctx, QSVContext* q, QSVFrame* out) +{ + HEVCSEI sei = { 0 }; + HEVCParamSets ps = { 0 }; + GetBitContext gb = { 0 }; + mfxPayload payload = { 0, .Data = &q->payload_buffer[0], .BufSize = sizeof(q->payload_buffer) }; + mfxFrameSurface1 *surface = &out->surface; + mfxU64 ts; + int ret, has_logged = 0; + + while (1) { + int start; + memset(payload.Data, 0, payload.BufSize); + + ret = MFXVideoDECODE_GetPayload(q->session, &ts, &payload); + if (ret == MFX_ERR_NOT_ENOUGH_BUFFER) { + av_log(avctx, AV_LOG_WARNING, "Warning: Insufficient buffer on GetPayload(). Size: %"PRIu64" Needed: %d\n", sizeof(q->payload_buffer), payload.BufSize); + return 0; + } + if (ret != MFX_ERR_NONE) + return ret; + + if (payload.NumBit == 0 || payload.NumBit >= payload.BufSize * 8) + break; + + if (!has_logged) { + has_logged = 1; + av_log(avctx, AV_LOG_VERBOSE, "-----------------------------------------\n"); + av_log(avctx, AV_LOG_VERBOSE, "Start reading SEI - payload timestamp: %llu - surface timestamp: %llu\n", ts, surface->Data.TimeStamp); + } + + if (ts != surface->Data.TimeStamp) { + av_log(avctx, AV_LOG_WARNING, "GetPayload timestamp (%llu) does not match surface timestamp: (%llu)\n", ts, surface->Data.TimeStamp); + } + + start = find_start_offset(payload.Data); + + av_log(avctx, AV_LOG_VERBOSE, "parsing SEI type: %3d Numbits %3d Start: %d\n", payload.Type, payload.NumBit, start); + + switch (payload.Type) { + case SEI_TYPE_BUFFERING_PERIOD: + case SEI_TYPE_PIC_TIMING: + continue; + case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: + // There seems to be a bug in MSDK + payload.NumBit -= 8; + + break; + case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: + // There seems to be a bug in MSDK + payload.NumBit = 48; + + break; + case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: + // There seems to be a bug in MSDK + if (payload.NumBit == 552) + payload.NumBit = 528; + break; + } + + if (init_get_bits(&gb, &payload.Data[start], payload.NumBit - start * 8) < 0) + av_log(avctx, AV_LOG_ERROR, "Error initializing bitstream reader SEI type: %d Numbits %d error: %d\n", payload.Type, payload.NumBit, ret); + else { + ret = ff_hevc_decode_nal_sei(&gb, avctx, &sei, &ps, HEVC_NAL_SEI_PREFIX); + + if (ret < 0) + av_log(avctx, AV_LOG_WARNING, "Failed to parse SEI type: %d Numbits %d error: %d\n", payload.Type, payload.NumBit, ret); + else + av_log(avctx, AV_LOG_DEBUG, "mfxPayload Type: %d Numbits %d\n", payload.Type, payload.NumBit); + } + } + + if (has_logged) { + av_log(avctx, AV_LOG_VERBOSE, "End reading SEI\n"); + } + + if (out && out->frame) + return ff_hevc_set_side_data(avctx, &sei, NULL, out->frame); + + return 0; +} + +static int parse_sei_mpeg12(AVCodecContext* avctx, QSVContext* q, AVFrame* out) +{ + Mpeg1Context *mpeg_ctx = &q->mpeg_ctx; + mfxPayload payload = { 0, .Data = &q->payload_buffer[0], .BufSize = sizeof(q->payload_buffer) }; + mfxU64 ts; + int ret; + + while (1) { + int start; + + memset(payload.Data, 0, payload.BufSize); + ret = MFXVideoDECODE_GetPayload(q->session, &ts, &payload); + if (ret == MFX_ERR_NOT_ENOUGH_BUFFER) { + av_log(avctx, AV_LOG_WARNING, "Warning: Insufficient buffer on GetPayload(). Size: %"PRIu64" Needed: %d\n", sizeof(q->payload_buffer), payload.BufSize); + return 0; + } + if (ret != MFX_ERR_NONE) + return ret; + + if (payload.NumBit == 0 || payload.NumBit >= payload.BufSize * 8) + break; + + start = find_start_offset(payload.Data); + + start++; + + ff_mpeg_decode_user_data(avctx, mpeg_ctx, &payload.Data[start], (int)((payload.NumBit + 7) / 8) - start); + + av_log(avctx, AV_LOG_DEBUG, "mfxPayload Type: %d Numbits %d start %d -> %.s\n", payload.Type, payload.NumBit, start, (char *)(&payload.Data[start])); + } + + if (!out) + return 0; + + if (mpeg_ctx->a53_buf_ref) { + + AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, mpeg_ctx->a53_buf_ref); + if (!sd) + av_buffer_unref(&mpeg_ctx->a53_buf_ref); + mpeg_ctx->a53_buf_ref = NULL; + } + + if (mpeg_ctx->has_stereo3d) { + AVStereo3D *stereo = av_stereo3d_create_side_data(out); + if (!stereo) + return AVERROR(ENOMEM); + + *stereo = mpeg_ctx->stereo3d; + mpeg_ctx->has_stereo3d = 0; + } + + if (mpeg_ctx->has_afd) { + AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD, 1); + if (!sd) + return AVERROR(ENOMEM); + + *sd->data = mpeg_ctx->afd; + mpeg_ctx->has_afd = 0; + } + + return 0; +} static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, @@ -636,6 +851,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, insurf, &outsurf, sync); if (ret == MFX_WRN_DEVICE_BUSY) av_usleep(500); + else if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) + parse_sei_mpeg12(avctx, q, NULL); } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE); @@ -677,6 +894,23 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, return AVERROR_BUG; } + switch (avctx->codec_id) { + case AV_CODEC_ID_MPEG2VIDEO: + ret = parse_sei_mpeg12(avctx, q, out_frame->frame); + break; + case AV_CODEC_ID_H264: + ret = parse_sei_h264(avctx, q, out_frame->frame); + break; + case AV_CODEC_ID_HEVC: + ret = parse_sei_hevc(avctx, q, out_frame); + break; + default: + ret = 0; + } + + if (ret < 0) + av_log(avctx, AV_LOG_ERROR, "Error parsing SEI data: %d\n", ret); + out_frame->queued += 1; aframe = (QSVAsyncFrame){ sync, out_frame };