From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5665F41069 for ; Mon, 10 Jul 2023 21:55:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AEB4168C3CC; Tue, 11 Jul 2023 00:55:15 +0300 (EEST) Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E554C68C5A7 for ; Tue, 11 Jul 2023 00:55:07 +0300 (EEST) Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6b5ef64bca6so4414998a34.3 for ; Mon, 10 Jul 2023 14:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689026106; x=1691618106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9xhE7Qhf53DaFHOZDIpX7GN2cspkaY5FseVTJxQbBgU=; b=FN3e+tv6+otMgOjaDwwi/aENjvGqAN940hEhXxW3r13uirAMTDCYZGnLpd+k708hjC SiieWjKJeqeuqmh1xICrourk1LcF3yzzdkNIKC1RVfSB8ZJX+OG+cgw+FADE7NUahQlf 1pkYlYDIsyzm8eyXXFMwhu66cmwn4XJdFWskhRA1ID9EJHDEoFG6GHeuJZprRO7XqfQk c9r0sVOQoq5wUx6bHiDzBxWG6H39ahbXyEya/XNtlqrEKntIkT17vmukxP5xAoRqDWZK XrExuyJFrQYjQy/uKPJFnOQlfnuFIPPo2uGvAXOXJH1I5TzoNydD+TqT492sYcWHTDX8 B70w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689026106; x=1691618106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9xhE7Qhf53DaFHOZDIpX7GN2cspkaY5FseVTJxQbBgU=; b=lfQJeozXPawHQ2cuLx4XVhYJOplA/ODVjiX4PeznwbRCaNs0xL/oP6yWHQw22LPss1 OlAydFKSyF5b7o0QpJAfTrXFB4dczLqe2pmeJhkq8hfhDneVw2ZVjRBbDfq42oqaY98d VDY5GskniPh56Vzj2htrMjwoL4jrnfHq8KYBDuZ/UFPLSIfpE281nNm90u7f1FMH1NLm 5eU+lCQgtxxj5wGk2waJSxVSYxORlNEm9QU05xUucW/Lchk6wAnVX38AHPQiV5nZGTQg Aw1UVIakdJeWVCC4edT9NdhMCIttME0Y6+rlGUbAB4D+RKiG9/Qk9s8aNQIldEZvR6Ec B/lQ== X-Gm-Message-State: ABy/qLYcwKNi+zIjhXlG4vDi8e1asF8AWwzIpoQjv7GnmdcYBGOwcVQI HkZifmOXeWaHFY9ZVzaI90w6XDLd5pk= X-Google-Smtp-Source: APBJJlE5FUWiVdg8TDKVVF8TBmfULAYoPKmop1+ndF8sTkHlGOfOvv47WxWiRA4waZlEBD/oE76omg== X-Received: by 2002:a05:6870:8191:b0:1b4:5ef7:50fe with SMTP id k17-20020a056870819100b001b45ef750femr10374471oae.29.1689026106072; Mon, 10 Jul 2023 14:55:06 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id dy45-20020a056870c7ad00b0019ed19a8659sm405446oab.8.2023.07.10.14.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 14:55:05 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Jul 2023 18:54:53 -0300 Message-ID: <20230710215453.34421-3-jamrial@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710215453.34421-1-jamrial@gmail.com> References: <20230710215453.34421-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/decode: prevent discarding skip_samples side data if the decoder didn't generate a 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Accumulate it instead, to be applied once a frame is returned. This change also prevents decoder set values from being potentially overwritten by side data. Signed-off-by: James Almer --- libavcodec/decode.c | 18 ++++++++++-------- libavcodec/internal.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 1270acaa50..8b0f506d24 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -300,11 +300,12 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca side = av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if (side && side_size >= 10) { - avci->skip_samples = AV_RL32(side); - avci->skip_samples = FFMAX(0, avci->skip_samples); + uint32_t skip = AV_RL32(side); + skip = FFMIN(skip, INT64_MAX - avci->skip_samples); + avci->skip_samples += skip; discard_padding = AV_RL32(side + 4); - av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n", - avci->skip_samples, (int)discard_padding); + av_log(avctx, AV_LOG_DEBUG, "skip %u / discard %d samples due to side data\n", + skip, (int)discard_padding); skip_reason = AV_RL8(side + 8); discard_reason = AV_RL8(side + 9); } @@ -324,7 +325,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca if (frame->nb_samples <= avci->skip_samples){ *discarded_samples += frame->nb_samples; avci->skip_samples -= frame->nb_samples; - av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n", + av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %"PRId64"\n", avci->skip_samples); return AVERROR(EAGAIN); } else { @@ -343,7 +344,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca } else av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n"); - av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n", + av_log(avctx, AV_LOG_DEBUG, "skip %"PRId64"/%d samples\n", avci->skip_samples, frame->nb_samples); *discarded_samples += avci->skip_samples; frame->nb_samples -= avci->skip_samples; @@ -374,11 +375,12 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { AVFrameSideData *fside = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10); if (fside) { - AV_WL32(fside->data, avci->skip_samples); + uint32_t skip = FFMIN(avci->skip_samples, UINT32_MAX); + AV_WL32(fside->data, skip); AV_WL32(fside->data + 4, discard_padding); AV_WL8(fside->data + 8, skip_reason); AV_WL8(fside->data + 9, discard_reason); - avci->skip_samples = 0; + avci->skip_samples -= skip; } } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 868dd46b48..33c9bf9d9b 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -116,7 +116,7 @@ typedef struct AVCodecInternal { /** * Number of audio samples to skip at the start of the next decoded frame */ - int skip_samples; + int64_t skip_samples; /** * hwaccel-specific private data -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".