From patchwork Tue Apr 2 05:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 47726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1148943pzb; Mon, 1 Apr 2024 22:25:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXseaeAqu5FHZSGCmb0NjUYyVOvBTIH85QJ264AEEgJyZvyk6hz8+gyIaU3j2gZP6rUbH6d0/5BWkPhW382xTYi4urC6cbnmyEUDw== X-Google-Smtp-Source: AGHT+IHbxbOrrEHu3hILFJA4ehRtVeQdW+4GRvXdfk7w5kAV1K+ymL8+uF1YjajOJtdWq7sRvcR/ X-Received: by 2002:a19:7708:0:b0:515:9ea7:cf8b with SMTP id s8-20020a197708000000b005159ea7cf8bmr5287044lfc.6.1712035522567; Mon, 01 Apr 2024 22:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712035522; cv=none; d=google.com; s=arc-20160816; b=xlBSItnjNP003g0unJ6k/ITQCbkpIH7Tm/YBeuOQeQ6mnwTqhPGUjcJihYnxO8RrqI 1hGaiHW5LrB3aFQ39SC/Ky6rf/JqSXoDH0E3vrUInwAqDi6OrExGxqOz2ioYm/EPn0PK OxZxzAmN2lek5igY9JItGQyo2j8W5HUdP/n6nk0ihTiWgJYDRSaP/HLzqKVLwgQ42Si7 bkxkddf4cVD6uzCyMMFXCIWZNcegUqLQetmzGD8SyPoBdltZfaTDqM84HfpjiupXoWme QlK1evxhedHLSjvubBjDFJnrWb/QbBv9nfyhonOZmsv4M53Zsm0copxUbd6RC+XdaRdF LDMg== 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=kWlO9UGM+u4QVJg9fWkUv04hFqTFKdDV8X6DhIBLDR0=; fh=PlWMzmI9LD2qGS7ipLrQl8z0iaQTLQLHzoGuXcBzpCg=; b=kTb8NwmLN6sD76Ijrc08NGgHBJKDSMApAS78SthOxw/b3aKHsGo3ktuAFhIFS7zEvP 3QKt1Suejj3oaTO3Op4mnl18OZyELKTxK2SAcpJm4cJRqpndPacVuqkg6nzd25V51gH5 0EmhN6IFYHqaXKPtsTDwVaoi+GeGcAqlurnrjLIhKPKfOBnvJaF1vGG7a773vntX0rR0 cirQqXYxzrGRUoolLJTOl8vXsOtj3x8jUSxSwI9t24/4bGNX2GawUKt4jzIKgF+KjcF8 zm5T8dovOsv4huxgeWAk9ttCBYdLS7w4iRQrvp8Rfcou2lWqr8AY1ouiQHhCYYL/3T7M KdcQ==; 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="QJ/56ZF1"; 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 js7-20020a17090797c700b00a46f88c0cc9si5397781ejc.873.2024.04.01.22.25.22; Mon, 01 Apr 2024 22:25:22 -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="QJ/56ZF1"; 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 EF89068D118; Tue, 2 Apr 2024 08:25:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f228.google.com (mail-oi1-f228.google.com [209.85.167.228]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EDBE768C90C for ; Tue, 2 Apr 2024 08:25:03 +0300 (EEST) Received: by mail-oi1-f228.google.com with SMTP id 5614622812f47-3c3d2d0e86dso2260115b6e.2 for ; Mon, 01 Apr 2024 22:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1712035502; x=1712640302; 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=eyfh4MNGAyAajuKLF1hxunu0ZbFLrTafh0hkcbspn8I=; b=QJ/56ZF1xidX9knJkVKr3hyy5il6RtV6C10cBzr45qpkyjJ37xQVTkGxy4ZAp54Y7Z cVGMhjnMuyB721oWIi/TKMyjErs4x0nxoDsE8KRgJHnNGU8E+XAj8ot/0aiYRqD018md MuDMs9xoFhyTxHL5iSzmDhuJLicivqqBcUP7Two8eK/B5l+zYF0IiW7jW+DqBG8FfJ0l mVu3ia/FPsszIY69hgEQYH6CB8J12eAC/CxB3wfGJjw+UUFXqdN6xa1BreymN4k45R7f ZUt6petdI77O16yZP71OQHXwzGi0467lUQX4stbluEjVB/XZC5XgqK6FlHB6S/ltLWMB dhIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712035502; x=1712640302; 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=eyfh4MNGAyAajuKLF1hxunu0ZbFLrTafh0hkcbspn8I=; b=e1O2CZdqYFx5ArCfYrd95JW7K6F3L9tWlUpS9Q+cDkEItgLcUesXTS5Q9ZLLlHxQaC W0msJzUs6c7s17m++IXLFo1RB2yZ6DCPfn0frdeSeuckSt562yiw8m24pSVngivz9HF5 zQo1kTobYj3n+4ZMfDGYRiRwNpV1EVjFDW+FM/rZ9+G8viwtLHoCWN7a1StTHgADMfh+ v8C5ty2EkQ044KIRabr8sMORIeY0MW3XWYKtwGzKHNj+g72TrwjWJC7qOTTuyCXQMglm m4BgrShCkjsruB6x/nw9+kPbEhdaBBqxUcZWEkPoeCXuhkSZh6PuOtvSh33gSLnHeDi2 Su6g== X-Gm-Message-State: AOJu0YzB6yLFfOvT2X10EsztkUMAcECwlnWWdpGYlsYhHXpxxfD1nk0v 4NcepZ8104aAfyTr8YM0HHjzhDe/lH21TMSFQ/uFQ5Kt+rEwWogwscWbLb2RRk9R5W0YkRSXKbz 2EiQHIB8307Wc6ubj6iJ0jM+905m9gDlZuUqNw5IA X-Received: by 2002:a05:6808:238e:b0:3c3:e682:7e2c with SMTP id bp14-20020a056808238e00b003c3e6827e2cmr14359529oib.7.1712035502629; Mon, 01 Apr 2024 22:25:02 -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 ka2-20020a056a00938200b006eabc5f5bbcsm760190pfb.8.2024.04.01.22.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:25:02 -0700 (PDT) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Apr 2024 00:24:53 -0500 Message-Id: <20240402052458.2034678-2-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240402052458.2034678-1-marth64@proxyid.net> References: <20240402052458.2034678-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v11 1/6] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZgbGt0nGA+LT 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 | 23 +++++++++++++++-------- libavformat/subtitles.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index d7723c497f..69e4df88a3 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" #include "libavutil/mem.h" @@ -112,15 +113,19 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, { AVPacket **subs, *sub; + av_assert1(event || 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 */ @@ -134,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; } return sub; } diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 88665663c5..ad6b96ca6a 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 not yet available 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