From patchwork Sun Sep 22 18:00:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51702 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2083267vqb; Sun, 22 Sep 2024 11:39:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWMBqHvtQQ+Dga/OhpjQAhm1HYBRqkIBLK7bIi67sb6jwnIwmENCWI6laUBgFkSv2/7uxZBvvbqbh36L9XWW4hZ@gmail.com X-Google-Smtp-Source: AGHT+IFxwqGbRA6d44nM4EUuV1pqvaO6AGQCuiufDgYUt2kfBhNyGPzm/FOqeS1qAL1413lOMCsp X-Received: by 2002:a2e:9bcf:0:b0:2f7:a759:72a0 with SMTP id 38308e7fff4ca-2f7cb375d00mr35127161fa.40.1727030356848; Sun, 22 Sep 2024 11:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727030356; cv=none; d=google.com; s=arc-20240605; b=ez5DF+g6pvNwiLbY+eevGbulAwGWfud0mbJZuIOiZUQLznjNkMvdjNjw3Hb0xYkUPO WMQjAkLSiW8WprQ2KdXn21igo3XuL/jizj3LFtNJXtMWNjpiOqoJ6Ipg8Nns7eBOy5sM b2NSl7RvTl+QoK+NOSkreYwCeg0cMmnNEt7r/3Bb22cx+1B/1sglIdAEcVfZk1wO40WK UEw7lZWzHjw8ukjMyizak0m0YLPfDsKxv7r+JMU4ZvgmR0c+bhPVP6o8iR114AnQmiIV o9+FKwBLm9P0CQ8UnICd4lFKyB/3xvxlVjVlCVZEdbZ+/7iaoFhTsa6br+bIiqR3Y/W4 amAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=SdcwR299r19Fy1NIw9ihYGmNbDGMC8twj31pejueISM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=djcxtB/aZDskkBpTD346NiGPdKEvQPAgGXZR9BIOGehsNNPX8vrBD2L7qy1AJlMRyO UlE6cAG13u6v0K+w0sMfjrDZBdKye2xJE13CFnRS3/XCGGICRqcAePB1oAYUsYb7te6F mKgVWX0ES7I3AJbpTfqRR1N17i9zzkINMDF+9Ctqwew+6SYU9/FjFTFvYsX6xe1dU6PY myWMiibQWJucDHid+0IV91nJYOH3Uj5KM3/Rx0FJKv0ETtkyHa9pJj3VNOci0+Ge0ZJh 2cR9Zk9Jf1MnJAHH6pgptn/jJhjXFzBL4rdYk12OvU3oDONlKdJeZEtTDRnX+oeAE8eu vtFQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=kdruQY3i; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2f79d47bffdsi57462031fa.563.2024.09.22.11.39.16; Sun, 22 Sep 2024 11:39:16 -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=@khirnov.net header.s=mail header.b=kdruQY3i; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0EB4768DAD6; Sun, 22 Sep 2024 21:00:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 95CB968D9FD for ; Sun, 22 Sep 2024 21:00:24 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=kdruQY3i; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 389194D9D for ; Sun, 22 Sep 2024 20:00:24 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Nq1prH1MrG8g for ; Sun, 22 Sep 2024 20:00:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727028022; bh=Dwrardk+v2dbJ+UveheBaXeYkh4rG/BAHTVK6IG4Zwo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kdruQY3id47089wplbnXFLF8BRDFpol7P/sJzrLWif2A6z2+lU8Rjd9QKU4abCnI5 oT9BjM4vGr5pearcrhWmEKrff4DDqO8thXkqtNuBX8qjWIiqb6vfHDHr0Hndo+E5Zp rCi6WC0I7/g1MnpmNb+rDCphg9RlE+EwhDffU6FZrk+UaKtl4WsXOrik1FwvqGtVrM t5Pum3zZ4HtrwY3RGjXWppsxjH1bj+oamfsQ5/WP2t+veSr2eE9zeF1I9IqVrzscQ/ ID5/fFFSeX4Ml558IWyI7QdLTiqS6HRFKGu3E6kuc6wq21ntF5fd4MOmjiksW+Hh/o fvoUmVeGPUHqg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id A64544DEE for ; Sun, 22 Sep 2024 20:00:21 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 965EA3A036E for ; Sun, 22 Sep 2024 20:00:14 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Sep 2024 20:00:03 +0200 Message-ID: <20240922180005.6549-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/decode: clear side data in reget_buffer() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3xhj3PQ+gUlU Otherwise it may accumulate when e.g. global side data is repeatedly copied to the frame with in each subsequent reget_buffer() call. --- libavcodec/decode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 1f2fbda6ad..57cca44d05 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1685,6 +1685,8 @@ static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flag if (!frame->data[0]) return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF); + av_frame_side_data_free(&frame->side_data, &frame->nb_side_data); + if ((flags & FF_REGET_BUFFER_FLAG_READONLY) || av_frame_is_writable(frame)) return ff_decode_frame_props(avctx, frame); From patchwork Sun Sep 22 18:00:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51701 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2073924vqb; Sun, 22 Sep 2024 11:09:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXCZJ7UdDDayy7pnB1RHspZhsm6MAc4ZaDf2fghU9h+VhkCS0jmi8DGXwqp/PeUDoZkp20eFPgYhFPk2SGV4Pte@gmail.com X-Google-Smtp-Source: AGHT+IE4Pq5Gm6dE5Eoqg0bxmemNhw5GRp6rNO5Va8h65loELrlvnLM+6BIAM7V1pE3OqUIIJCqm X-Received: by 2002:a05:6512:1105:b0:530:daeb:c1d4 with SMTP id 2adb3069b0e04-536acf6ad3fmr4077957e87.12.1727028559839; Sun, 22 Sep 2024 11:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727028559; cv=none; d=google.com; s=arc-20240605; b=Vibe8wEhA/9HNbbwUx3pexF+hos+/aU3zYXoFrdtDUSD8gipHsaaCnJeMg7UhJpn3c EBcg9XEY55WJ+4HFNYHByxBIOG1NxoFbYnuiWmVe2OW7nVAqK7tFfrQmI2Lmk/6q56a0 UbdacH/UyszTeCJZme6c2t0LLABm1V8wkozvJOTiJhuI/779DMrCawD6+3V5oUB31U2g /9E9uH8uqh5yteyC4kQmb7DEousd2wg1GM2A0+XQ9cdDJ4tEAJ/HnXoyWcpHfr45XMyh qLQ5SkmniDlr6ygyntjfwAU1R6uPKjdAqaCPi2pJRkv5qFzMFvZU8Uc2pmpN/Rpp20p9 Fu0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=LGPvGYuYFqpmEXGPZrDwmnH6eqdc1vU3wqMdJ1XZMUI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Pe/B2kcqD1JyfKA6EgiAYGZTy+235fKDSqJpw87OWqXqsEPPKx8VQoXZN1bJ61p3fk WCRcDGf+9WGNjeB8q85MM49dCFoPGQRBcnDSKPWbZLFnbD1TbBcShgXBMFf7BCtCiT7F U95PicOLe5fOOLxmcL/KEReYiIonX7aO8lGE8TylOLAVsq8Lfik7OvsNMp08NP56EERr /EcP7Pj5LNKJ+Gx1dLEDulTvUkI9tjnfGc4PsUzoAail6iAaLLwHP+halF8wXztlGTDm fteb7f/xsQRcNuaIrQURKrLd4X9LO5+jc0W/IoRudgpXciSEMgd36ygn5etXv/JfsFmN cAGA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=nXrrNHkm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53687042c51si6127085e87.54.2024.09.22.11.09.19; Sun, 22 Sep 2024 11:09:19 -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=@khirnov.net header.s=mail header.b=nXrrNHkm; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CAE0568DAB0; Sun, 22 Sep 2024 21:00:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6FEC268DA01 for ; Sun, 22 Sep 2024 21:00:24 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=nXrrNHkm; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E65F94DE2 for ; Sun, 22 Sep 2024 20:00:23 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id e1-ZrYkU-6O4 for ; Sun, 22 Sep 2024 20:00:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727028021; bh=Xo/87TMYLrFrL6UMzkSvhooCMTx16ugv4eS3Ed6ymPo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nXrrNHkmxkm0QbyJtbNK+EiGxcab0rtdVhxqRKRPzzuoH+zYbU4lM/1eu7XU0EOR0 Z79NcoVARYMdsEUkvNtf60XjLkhVAK487ybgdIE2Ust9sNnrHLFsPPOVRVmDyCDvve Pz4q1y/o5H1uotPAaQUevyKclYpbXkv9GfG9Hoe/uJla6PG80PWOQkUWsPRLcY/BEh oO+mC0bMOuBj3HOKzlc0OGJC3gp1Fm5V42LEy+Y1kr82h8GsjNMN4G/um1426zhdLO fovXOBktxtl4LrjyiKOYmR/aGL5mLiUuyJnewOUxFwME2DueLtBgoUp3ZwF+mxXtTc Ku7tFD/kzt3jw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 921994D9D for ; Sun, 22 Sep 2024 20:00:21 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A31423A086F for ; Sun, 22 Sep 2024 20:00:14 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Sep 2024 20:00:04 +0200 Message-ID: <20240922180005.6549-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240922180005.6549-1-anton@khirnov.net> References: <20240922180005.6549-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/decode: make sure side data mapping does not produce duplicates 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PYnStHcHe06e Also, deduplicate the code performing the mapping. --- libavcodec/decode.c | 98 +++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 57cca44d05..9303254ef3 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1400,14 +1400,50 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) return ret; } +static const AVPacketSideData* +packet_side_data_get(const AVPacketSideData *sd, int nb_sd, + enum AVPacketSideDataType type) +{ + for (int i = 0; i < nb_sd; i++) + if (sd[i].type == type) + return &sd[i]; + + return NULL; +} + const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type) { - for (int i = 0; i < avctx->nb_coded_side_data; i++) - if (avctx->coded_side_data[i].type == type) - return &avctx->coded_side_data[i]; + return packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data, type); +} - return NULL; +static int side_data_map(AVFrame *dst, + const AVPacketSideData *sd_src, int nb_sd_src, + const SideDataMap *map) + +{ + for (int i = 0; map[i].packet < AV_PKT_DATA_NB; i++) { + const enum AVFrameSideDataType type_pkt = map[i].packet; + const enum AVFrameSideDataType type_frame = map[i].frame; + const AVPacketSideData *sd_pkt; + AVFrameSideData *sd_frame; + + sd_pkt = packet_side_data_get(sd_src, nb_sd_src, type_pkt); + if (!sd_pkt) + continue; + + sd_frame = av_frame_get_side_data(dst, type_frame); + if (sd_frame) + continue; + + sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size); + if (!sd_frame) + return AVERROR(ENOMEM); + + memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size); + } + + return 0; } static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) @@ -1425,17 +1461,17 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) { - static const struct { - enum AVPacketSideDataType packet; - enum AVFrameSideDataType frame; - } sd[] = { + static const SideDataMap sd[] = { { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC }, { AV_PKT_DATA_AFD, AV_FRAME_DATA_AFD }, { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS }, { AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE }, { AV_PKT_DATA_SKIP_SAMPLES, AV_FRAME_DATA_SKIP_SAMPLES }, + { AV_PKT_DATA_NB } }; + int ret = 0; + frame->pts = pkt->pts; frame->duration = pkt->duration; #if FF_API_FRAME_PKT @@ -1445,31 +1481,14 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) { - size_t size; - const uint8_t *packet_sd = av_packet_get_side_data(pkt, ff_sd_global_map[i].packet, &size); - if (packet_sd) { - AVFrameSideData *frame_sd; + ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, ff_sd_global_map); + if (ret < 0) + return ret; - frame_sd = av_frame_new_side_data(frame, ff_sd_global_map[i].frame, size); - if (!frame_sd) - return AVERROR(ENOMEM); - memcpy(frame_sd->data, packet_sd, size); - } - } - for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) { - size_t size; - uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size); - if (packet_sd) { - AVFrameSideData *frame_sd = av_frame_new_side_data(frame, - sd[i].frame, - size); - if (!frame_sd) - return AVERROR(ENOMEM); + ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, sd); + if (ret < 0) + return ret; - memcpy(frame_sd->data, packet_sd, size); - } - } add_metadata_from_side_data(pkt, frame); if (pkt->flags & AV_PKT_FLAG_DISCARD) { @@ -1490,19 +1509,10 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { int ret; - for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) { - const AVPacketSideData *packet_sd = ff_get_coded_side_data(avctx, - ff_sd_global_map[i].packet); - if (packet_sd) { - AVFrameSideData *frame_sd = av_frame_new_side_data(frame, - ff_sd_global_map[i].frame, - packet_sd->size); - if (!frame_sd) - return AVERROR(ENOMEM); - - memcpy(frame_sd->data, packet_sd->data, packet_sd->size); - } - } + ret = side_data_map(frame, avctx->coded_side_data, avctx->nb_coded_side_data, + ff_sd_global_map); + if (ret < 0) + return ret; if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) { const AVPacket *pkt = avctx->internal->last_pkt_props; From patchwork Sun Sep 22 18:00:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51700 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2070111vqb; Sun, 22 Sep 2024 11:00:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWaKS8eWlklKUY1DccLrcd/S2cj1m6JXHu78LAs4uv3iIkfhabR0ZWwY8I+XqF5igK2Ha+SZiquMFoxyj2BhGxP@gmail.com X-Google-Smtp-Source: AGHT+IGVoIeMYKf4iIr8DD182g+YDpF3eO52owzE9i2zNqR610xgpoHXkab6S2vyPm7yJufZF/0k X-Received: by 2002:a05:6512:2313:b0:536:55cc:963e with SMTP id 2adb3069b0e04-536ac32f0b3mr5422682e87.44.1727028037082; Sun, 22 Sep 2024 11:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727028037; cv=none; d=google.com; s=arc-20240605; b=czxbPvpZAfCfOLWdOTNov2FHKk42+OeQBqcE97qBypYiFr/lLMhTEeCdeM6ZUx7LOy Onel9iNzRIq0WDepop9iKGHQcBx/nDEdG1ofm76nTjda2mbrrCIAMLCkRTs4pRH9GLJ9 Yz5ULP7m3HpUqHfPlf33Y5Fl7FngMvLDfzUI/8oUf0sp2b9njCfMvqQZXXv4Ba/DYrCk eOja9qN/FvSRhzpoGDZUMiglj28jS1KFi+eHm5vWdkpnoVinJXEDrWGIb7cFPgp9sN0P DDSOvqthkdwzy50/ucMh5JEKhLUXLFNiAG6WC43ssyIkaDVZ3Z6/NWiYRuXOtkqC+Kf7 kV9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=vM2kFDVbG6UVh+Dlq+KHdUvrxmVI8gdHIYSUmEt81SE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=bl8waUxAQMkzKLdOEMUplkx9NxRgfmTG8Oe3iMx+kJe+sEHbwY/mHdwaNg79eBsTws 0d+UxRrA+Tdo10TvNRCU2x8AexmWGboOvOI4v5bFcvJzvFHkIpKlxeq2zn4404k/rpjr Tgz7hurOvxguBYiJzuPCzhz1BwdUo9A4bKIXEOCFGlOQirpgwskq2Dmk3hDjGfNSmLKY QNjeGVbktfJ4IOJqf2EFaG0eDqLNRvXzG20Qf2PVipng1nNURWnJ7v+P2vogy6jGYZ/c ccz4Aas4V/5cCNSEbNV6HlJfz8zqn4m81loUuG0Q3bAu7126O4FySsfuiXCSOgjG1LEz jj1g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=Ptqlohha; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-5368709ddc2si6620198e87.345.2024.09.22.11.00.35; Sun, 22 Sep 2024 11:00:37 -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=@khirnov.net header.s=mail header.b=Ptqlohha; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B308668DA7D; Sun, 22 Sep 2024 21:00:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4BA7368D9FD for ; Sun, 22 Sep 2024 21:00:24 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=Ptqlohha; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3CF204E07 for ; Sun, 22 Sep 2024 20:00:23 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id h10kvYRUGppQ for ; Sun, 22 Sep 2024 20:00:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727028021; bh=JyZIiJxJdVsqXIV0kGuE1VYPGa10dX1znv0hDDDhtkk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PtqlohhairpVWXQR9LPWTWctyveE1W8FQ4r13Y/gZ7VMtE4sTfBCgnrC/9oHxYF4f mxBAe63E0cqKHRF/gQdvDgsoYYM30Qjy7+yBsbm39JHDyuiCRqL3RgmkQVwTlmjU0U wV98GswrPHz87AyE10fwHaQSQNqCZaXEwxK7bjt/fwhT5m+ttaTcxsSd2GWtEv7h56 AqrmsdlLTt9OTHz6BNofVLzKpR/0T5wzCBjlwdHvrobos5bAPQ3SdiOWgN6OVXyISs Sx68Kum3adCS1XjorG35D+JsNgkPljf8OCeRhMuklNkJiWKn+iIQCeVt//jnTFCw2m q7NyvMWBTX1Kg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 968E54DE2 for ; Sun, 22 Sep 2024 20:00:21 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AE0B03A0998 for ; Sun, 22 Sep 2024 20:00:14 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Sep 2024 20:00:05 +0200 Message-ID: <20240922180005.6549-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240922180005.6549-1-anton@khirnov.net> References: <20240922180005.6549-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/decode: merge stereo3d information from decoder with packet 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: K4Ry7NBQpUOy The HEVC decoder will start setting stereoscopic view position (left or right) based on 3D Reference Displays Info SEI message in future commits. This information should be merged with container-derived stereo3D side data. --- libavcodec/decode.c | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 9303254ef3..ffae322612 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -37,6 +37,7 @@ #include "libavutil/internal.h" #include "libavutil/mastering_display_metadata.h" #include "libavutil/mem.h" +#include "libavutil/stereo3d.h" #include "avcodec.h" #include "avcodec_internal.h" @@ -1417,6 +1418,42 @@ const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx, return packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data, type); } +static int side_data_stereo3d_merge(AVFrameSideData *sd_frame, + const AVPacketSideData *sd_pkt) +{ + const AVStereo3D *src; + AVStereo3D *dst; + int ret; + + ret = av_buffer_make_writable(&sd_frame->buf); + if (ret < 0) + return ret; + sd_frame->data = sd_frame->buf->data; + + dst = ( AVStereo3D*)sd_frame->data; + src = (const AVStereo3D*)sd_pkt->data; + + if (dst->type == AV_STEREO3D_UNSPEC) + dst->type = src->type; + + if (dst->view == AV_STEREO3D_VIEW_UNSPEC) + dst->view = src->view; + + if (dst->primary_eye == AV_PRIMARY_EYE_NONE) + dst->primary_eye = src->primary_eye; + + if (!dst->baseline) + dst->baseline = src->baseline; + + if (!dst->horizontal_disparity_adjustment.num) + dst->horizontal_disparity_adjustment = src->horizontal_disparity_adjustment; + + if (!dst->horizontal_field_of_view.num) + dst->horizontal_field_of_view = src->horizontal_field_of_view; + + return 0; +} + static int side_data_map(AVFrame *dst, const AVPacketSideData *sd_src, int nb_sd_src, const SideDataMap *map) @@ -1433,8 +1470,15 @@ static int side_data_map(AVFrame *dst, continue; sd_frame = av_frame_get_side_data(dst, type_frame); - if (sd_frame) + if (sd_frame) { + if (type_frame == AV_FRAME_DATA_STEREO3D) { + int ret = side_data_stereo3d_merge(sd_frame, sd_pkt); + if (ret < 0) + return ret; + } + continue; + } sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size); if (!sd_frame)