From patchwork Thu Mar 21 03:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 47280 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a4a:b0:1a3:31a3:7958 with SMTP id zu10csp308764pzb; Wed, 20 Mar 2024 20:52:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUzgj3KZX914GiAyQMItY5+Yva+0DN7yj+vxI9zXroWPgAUgCaQBeV32Po2LgpDyzE71Ytpi5UQ6ogiCvJzZVsF73+RYNkOKzPiOQ== X-Google-Smtp-Source: AGHT+IGBb/8V7+rc1RaKz5Cb0r27CfzwnCxscHgHdxUS8+bMT6aM5iPGlcueN0lgg2YWvdl0g1dh X-Received: by 2002:a17:906:c352:b0:a44:4c9e:8809 with SMTP id ci18-20020a170906c35200b00a444c9e8809mr442704ejb.32.1710993151611; Wed, 20 Mar 2024 20:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710993151; cv=none; d=google.com; s=arc-20160816; b=NWKjA6phVyFP4HzO2ePB7Bw38CTxH5EroG4rOEXOfxL/YinpRhDrscQ/PR3IVdoyD3 UzI1oKi3/dVE68aDJqtUHvozOLqtdX754+OBlJTVXVKuK50eaQYRvKrmuvhvE5f4dWlg HUA9pqR97GfZ7J1uWlL803yDXVtn1V6Yo7H+lQKqJ4MbErpOh2mdGTTkKf/xjMGxod0M anahVDeiuCvp8IqHx2A0PHKVXZgKkg/Ctmm0C72KXR2GMLzndloTCv5nfR6EmkzRj09t X/wzrtmOh1I2I47n2v5W3B6m54iahF6fpe/mouUI/pxAz+wx6CMDGUhFGSjDtzCUthhX r8kA== 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:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=JiLeTry4RnaLF7HqZYt1rULb9D6zG/Rb8amm0X3gC+Q=; fh=PlWMzmI9LD2qGS7ipLrQl8z0iaQTLQLHzoGuXcBzpCg=; b=o8yWtBUtkOwEe+yTJ22DrKqstc6erZEkjSxaJEo6ruS3ihI2ZNqaAueW3cla7aQSpn 16RwTACBka/bgMksZLT+Vk/yoXrm6449Dg8hIkqjAnJo/0TZS1HkY55CgUxsp1cyZgad I/ZV0ymOaQfc3APZWfeq5dMwRlO5LRi7DPY/qGbqdcq7slTUZsQebX+PBDINA8hDGzlG hNKLr6I9lNrEivYEaHSRmXNwAEoOTvsOGe7Q+eJAUZDo/snrVKSolJS3tq69QRJ0eH6F FkiBXWh1J8f5ckeGS0mcZCDZ1umLGjZbuC3YNTnHuVsjlvf9CFKPxRgnuTQ2Vu3NY7Wr QbZA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@proxyid.net header.s=google header.b="SQba/0Ff"; 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 g11-20020a170906348b00b00a440cbc0b95si7140547ejb.307.2024.03.20.20.52.31; Wed, 20 Mar 2024 20:52:31 -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=@proxyid.net header.s=google header.b="SQba/0Ff"; 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 9E90968D50C; Thu, 21 Mar 2024 05:52:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f98.google.com (mail-ua1-f98.google.com [209.85.222.98]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CEB0168D4BD for ; Thu, 21 Mar 2024 05:52:13 +0200 (EET) Received: by mail-ua1-f98.google.com with SMTP id a1e0cc1a2514c-7e09e1871fdso226416241.0 for ; Wed, 20 Mar 2024 20:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1710993132; x=1711597932; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C7ddoKYHF75u8902kbMzlTKnC0vB8Euy1Yn0XRjjHJ8=; b=SQba/0FfefpWJzss8YGBbE6mFSTexje7gzuRTdsQyEb0Dhw5Rq2nlAfH5AuztEsYj4 Lr6Ob7R9s0fudsznlEbAKS01+qxMAMRlzWDSHIvg4Z5qKDKFTmCndXnfpXTbs7ct6DV0 EzAHLKBViKq12WwjPgcf/uOe25uVIpC2HEp8AYCkLLK5eiVKfxPj5IWLDyz922iho+wG Jp0GnyBzNd9GnZOaIMG1WVedTp6Qv1VI4FAA8K0ojWblzdX2r+Uqgkm/1L8EtgEXdbVT /h7eyojhMsvAILjC7eK4GlL3huy4ogKryd6rQA74Cn74QFF1IFMdk3FznvPJwQ14A7Ew aIdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710993132; x=1711597932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C7ddoKYHF75u8902kbMzlTKnC0vB8Euy1Yn0XRjjHJ8=; b=mQreH6s1hAoJocKzF7thXsJlttUkY618kbrZGAhgaGXbgbKLnipU/Lp+IRVdVqvu0i sKlc+uhDEIKWGANDRzrGQGJJYG2HMZoRpRxt4MQE7rDHUzWmW52juUwkMOJym8Q9+Mh6 4EjX2Iw5/EtCixew3XmWHXReGwjW6BAFx1BjiaFGwfq/fztAMTIqVw9uXbIiRMdKbkQP YLU0Z/bJ+kJqB/CdeU0RJDvJmI5FyvEkhryE15X3q3w7X8lK7vviMEjVItBeAHPzE7gw e6J+5ggvqZrE4ZO4AJkR+uTkmpsbEjEq9XSilOGPtmzsvQWQPdha+w0IfSjmhZ3VWJto DVcw== X-Gm-Message-State: AOJu0YzyrazZHZfpp9c0aSahmm25uHDBBc8MSsjju+aXcNocSjEEDIAB fSoNwuh4dm4MKaTbPM7q1S1DvymUKSVa8DmGc3enMpZifTAs8PCMmObgX8KvP1gfARqZQID5gKJ IUwqDCOPNIak42e8nw7izpcR4JIM9/z2gu1kmxMbN X-Received: by 2002:a1f:f28a:0:b0:4d4:3fa5:e19e with SMTP id q132-20020a1ff28a000000b004d43fa5e19emr742271vkh.2.1710993132398; Wed, 20 Mar 2024 20:52:12 -0700 (PDT) Received: from wsx-cc1-001.. (c-76-141-249-38.hsd1.il.comcast.net. [76.141.249.38]) by smtp-relay.gmail.com with ESMTPS id x125-20020a1f7c83000000b004d14fb3e0b7sm1204250vkc.14.2024.03.20.20.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 20:52:12 -0700 (PDT) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Mar 2024 22:52:03 -0500 Message-Id: <20240321035207.3849560-2-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240321035207.3849560-1-marth64@proxyid.net> References: <20240321035207.3849560-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 1/5] avformat/subtitles: extend ff_subtitles_queue_insert() to support empty 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: C2RzofJec8OC If ff_subtitles_queue_insert() were to 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, consider a NULL buffer with 0 length as an empty event and do not attempt to modify the packet. 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 | 4 ++++ libavformat/subtitles.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 3413763c7b..38d2ffb8a9 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -117,6 +117,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, int old_len; sub = q->subs[q->nb_subs - 1]; old_len = sub->size; + if (event == NULL && len == 0) + return sub; if (av_grow_packet(sub, len) < 0) return NULL; memcpy(sub->data + old_len, event, len); @@ -140,6 +142,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, subs[q->nb_subs++] = sub; sub->flags |= AV_PKT_FLAG_KEY; sub->pts = sub->dts = 0; + if (event == NULL && len == 0) + return sub; memcpy(sub->data, event, len); } return sub; diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 88665663c5..ba162fa503 100644 --- a/libavformat/subtitles.h +++ b/libavformat/subtitles.h @@ -112,7 +112,7 @@ typedef struct { /** * Insert a new subtitle event. * - * @param event the subtitle line, may not be zero terminated + * @param event the subtitle line (not zero terminated), or NULL on empty event * @param len the length of the event (in strlen() sense, so without '\0') * @param merge set to 1 if the current event should be concatenated with the * previous one instead of adding a new entry, 0 otherwise