From patchwork Mon Mar 4 13:06:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46759 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp2789586pzb; Mon, 4 Mar 2024 05:09:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW5goNAt0bgPSR3p0C84Q42lLsF5l5FbJWeGaAxmbed/RnrBYm60BT3e+Fq7TqHEUvjuhJU/5kUKynwlgicP85FP1y0EFWvLx6Jig== X-Google-Smtp-Source: AGHT+IEzMDtrEs0zni/kwjODaSX1gXHJQm8Kpg/MHrhKhf/fqWCM55ZDP3SLdc4EGIOk0OqD0nM/ X-Received: by 2002:aa7:dbcb:0:b0:567:683:11bb with SMTP id v11-20020aa7dbcb000000b00567068311bbmr4781008edt.20.1709557751052; Mon, 04 Mar 2024 05:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709557751; cv=none; d=google.com; s=arc-20160816; b=dlUr1YQ9FOD3BwrpT87PEyRq/fd6K8uaNgLxnETtxLI8BN4pWlxK3i5zOX93EKY8iO XRNqSy8A0BJuErK3YLdranRNPPKfJWhMyg/kpquzvDqz5vqwAI4S5/Jy+372AynDtTmm LzymYia9PQ+j80dEDRY7wC0tTzNKOsbLqKWV+9R9SkMmCN6Qf/xw59caxdcBzMioQ0tV FGrxtLfFZyYDzZVE32j89gc5FMYsUCA5vdBbXTUk193oodhRclEuGVv7LTm3QyEgokLT 0cRt2DlL9tzRznewIytosPHujtFIr0pAhRsntDz/cMyVT956jOOGQFUnSl6GhFvjWxqg KXqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=0lML2+WO1iuYIRaWITZKCotVTEUV+UIpBtEI5jcGmwk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=jf1q0ES0IQlgh/lPrBa+I/5ZturY7jox6hJf7OgfMOfRASiH9c6OZfOMXRx5zk+hWJ Jkih57gzs7OgoA3R6kDSFDvv0dIChUaRuNz8LYaEysb7sz+gyQp8fAbad8XbODUZqynf R7EUn9/R1gn1bXidQ1IEkRSScQseWioXflGlTpZgpQhpbsqxZmcGDAjkYYSixdpfyXxe BBctvzfvBM20z1lY/bgk/4brcSQUl7tdSoYfdUID6Qie9ED7gp9Hgk/pVtOBCludtcVB L8/Jg7DedZUAqQDg9+mzsBiTQK3z9aJbMbQZwws3ENC4JZwmjaqbrnbObfFkf6R3ulvK WoLw==; 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=nJ5oCGhv; 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 dz15-20020a0564021d4f00b005676b7b8f08si267974edb.50.2024.03.04.05.09.10; Mon, 04 Mar 2024 05:09:11 -0800 (PST) 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=nJ5oCGhv; 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 36A8768D3A9; Mon, 4 Mar 2024 15:07:25 +0200 (EET) 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 6AA2668D43A for ; Mon, 4 Mar 2024 15:07:14 +0200 (EET) 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=nJ5oCGhv; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 21D634D59 for ; Mon, 4 Mar 2024 14:07:10 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id zBIkWVdO88Pz for ; Mon, 4 Mar 2024 14:07:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709557626; bh=/V9LVu36ekTmKu1qkc6uNNng3yp5qW8xf6EiDKQhdfo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nJ5oCGhvGpwUtjmE8yLNcgHBHkO9ra7SJ9HLAEzR2W2JIotSDu0TuJOyshogCq+BI UDQheJesabtP/oFcOimPIfCaCD76IMJRZcsWlNxelc0gDaMvmKgjBJhVj9IuZ6uHGF 0m607ib5YzrsDkdudp1ZJVjDyVD8NU+QmQjGuZxLEo43lPjRm8c5+o90qAggzQ9z0U Uyp3yU0T4jWLqN5nceOOGLBtjpHcQERnIqqLTCgcyXa3giCbFp/v9SttpuTjI+tdcj 7+tpf9oHOaCC0D2ODtiRxqXnz2oNVoUWXe/cL59//6TINricOVmEL90WEA0OrMCh9j AACzjBjdj64Sw== 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 940894D5E for ; Mon, 4 Mar 2024 14:07:06 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 807373A131E for ; Mon, 4 Mar 2024 14:07:00 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 14:06:29 +0100 Message-ID: <20240304130657.30631-14-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304130657.30631-1-anton@khirnov.net> References: <20240304130657.30631-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/29] avcodec/hevcdec: respect side data preference 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: Y2L6pb9Ta6fB From: Niklas Haas If the time code side data is overridden by the packet level, we also make sure not to update `out->metadata` to a mismatched timecode. Signed-off-by: Anton Khirnov --- libavcodec/hevcdec.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 17c6a9212f..76aa6b4588 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2788,24 +2788,27 @@ static int set_side_data(HEVCContext *s) 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, - sizeof(uint32_t) * 4); - if (!tcside) - return AVERROR(ENOMEM); + AVFrameSideData *tcside; + ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, + sizeof(uint32_t) * 4, &tcside); + if (ret < 0) + return ret; - tc_sd = (uint32_t*)tcside->data; - tc_sd[0] = s->sei.timecode.num_clock_ts; + if (tcside) { + tc_sd = (uint32_t*)tcside->data; + tc_sd[0] = s->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]; + 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]; - 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); + 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; @@ -2816,10 +2819,9 @@ static int set_side_data(HEVCContext *s) if (!info_ref) return AVERROR(ENOMEM); - if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, info_ref)) { - av_buffer_unref(&info_ref); - return AVERROR(ENOMEM); - } + ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref, NULL); + if (ret < 0) + return ret; } if (s->rpu_buf) {