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 78A334A2FC for ; Tue, 26 Mar 2024 15:43:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7EDBC68D550; Tue, 26 Mar 2024 17:43:29 +0200 (EET) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E39868D308 for ; Tue, 26 Mar 2024 17:43:23 +0200 (EET) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-515a97846b5so2921905e87.2 for ; Tue, 26 Mar 2024 08:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711467801; x=1712072601; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=kv+uw/qHRYtketudoN0tU5F3jxpOW+/t9/I9zcsSzQE=; b=fbH247DMnC4QQUva5mX69eoQiC2SG2jO5RqFLE3VCauEROYxfbGx2KIbo6huFgDYxb LKw5Q4y5f//sLaWQOaO5T67rz8qSUmi3nHDuGj3o07KjoKC4+FwbZoA2zGNIbYee2EfR bP2Li0wQm0yAzKCzvEVc98GD3ST3ZltrSbz7Ho5ZZK6mR1mgIRYUb1bxCcwQkDYCMk5h GIr1DFYPAIMQNgG0wfZ5bdGS9PXvYanQ9nZ0fhn0pueUwwuvpMGhvaA4lMeSdyjbS/AN WeMvb5csNf9XKk+tdTEOcYiwhvaLVvJS/OSrUPgt9b2TyjQy+Ab9or+68K16Qs/XfU6m izvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711467801; x=1712072601; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kv+uw/qHRYtketudoN0tU5F3jxpOW+/t9/I9zcsSzQE=; b=t2j3WEjB5pdnco/f7zMjd3vMH7AX81iA8Kbc67uCML9o9RWQd/ajfSEUAaqeDC0P/n y/EaC77r0N1Y0aQwb/yOgXOy4zQ1qGm6grt6506MagXamD0k4Lp1+gO/A0TTLq57xSSk K9cFhAu+B0PM4wSBtD7ncH9Wc5e1xMM9G2tBju2sJ0Q24yzsDstjRGFH6VyYerr/w/Wd iWYlg73wSFCJcUdr/rO2GBPwYLrZhKkyjGfIJ3KX0FC3RzxFzmWdoVWPtth7jvIUvtc+ l8z7SAzXXijus6ZkRK3sg9ekQ5UpJMmEBJ/S1IyB1udbCYCZ7dP25Hqz5mOIIDDEWGvc Mq7w== X-Gm-Message-State: AOJu0YwLTqI1AL7YpNspeyLeKMl4Xi7QIwL/4VrtacsbTxP/XU6Md31h dszN3XGio5dC55Gp6PAFqNEgmATDPYdxUOrBB/GAsqIC3W8Gzb5IWd22woMkpYE= X-Google-Smtp-Source: AGHT+IEMPT8PA+ksRoRfrunFp+BB1U8RsbUcxeve8qfZquj4+0+ZntQB71CXfr7shdxlWqkrbFRdLg== X-Received: by 2002:a05:6512:289:b0:512:f3e7:bcef with SMTP id j9-20020a056512028900b00512f3e7bcefmr7115330lfp.51.1711467801151; Tue, 26 Mar 2024 08:43:21 -0700 (PDT) Received: from mariano (net-93-70-84-101.cust.vodafonedsl.it. [93.70.84.101]) by smtp.gmail.com with ESMTPSA id p9-20020a170906614900b00a46af5f023bsm4325755ejl.202.2024.03.26.08.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 08:43:20 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 1B49DBFCE6; Tue, 26 Mar 2024 16:43:21 +0100 (CET) Date: Tue, 26 Mar 2024 16:43:21 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches , Marth64 References: <20240324022504.1419451-1-marth64@proxyid.net> <20240324022504.1419451-2-marth64@proxyid.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240324022504.1419451-2-marth64@proxyid.net> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH v9 1/5] avformat/subtitles: extend ff_subtitles_queue_insert() to support not yet available events 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: Marth64 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: On date Saturday 2024-03-23 21:25:00 -0500, Marth64 wrote: > If ff_subtitles_queue_insert() were given a NULL buffer > with 0 length, it would still attempt to grow the packet > or memcpy depending on if merge option is enabled. > > In this commit, allow passing a NULL buffer with 0 length > without attempting to do such operations. This way, if a > subtitle demuxer happens to pass an empty cue or wants to > use av_get_packet() to read bytes, there are no unnecessary > operations on the packet after it is allocated. > > Signed-off-by: Marth64 > --- > libavformat/subtitles.c | 24 ++++++++++++++++-------- > libavformat/subtitles.h | 2 +- > 2 files changed, 17 insertions(+), 9 deletions(-) > > diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c > index 3413763c7b..4742ca0667 100644 > --- a/libavformat/subtitles.c > +++ b/libavformat/subtitles.c > @@ -21,6 +21,7 @@ > #include "avformat.h" > #include "subtitles.h" > #include "avio_internal.h" > +#include "libavutil/avassert.h" > #include "libavutil/avstring.h" > > void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb) > @@ -111,15 +112,20 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, > { > AVPacket **subs, *sub; > > + if (!event) > + av_assert1(len == 0); > + > if (merge && q->nb_subs > 0) { > /* merge with previous event */ > > int old_len; > sub = q->subs[q->nb_subs - 1]; > old_len = sub->size; > - if (av_grow_packet(sub, len) < 0) > - return NULL; > - memcpy(sub->data + old_len, event, len); > + if (event) { > + if (av_grow_packet(sub, len) < 0) > + return NULL; > + memcpy(sub->data + old_len, event, len); > + } > } else { > /* new event */ > > @@ -133,14 +139,16 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, > sub = av_packet_alloc(); > if (!sub) > return NULL; > - if (av_new_packet(sub, len) < 0) { > - av_packet_free(&sub); > - return NULL; > + if (event) { > + if (av_new_packet(sub, len) < 0) { > + av_packet_free(&sub); > + return NULL; > + } > + memcpy(sub->data, event, len); > } > - subs[q->nb_subs++] = sub; > sub->flags |= AV_PKT_FLAG_KEY; > sub->pts = sub->dts = 0; > - memcpy(sub->data, event, len); > + subs[q->nb_subs++] = sub; is the move needed? (but not blocking) LGTM otherwise. _______________________________________________ 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".