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 C947348A0F for ; Sun, 24 Mar 2024 02:25:24 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 95C4B68D3CA; Sun, 24 Mar 2024 04:25:18 +0200 (EET) Received: from mail-qv1-f97.google.com (mail-qv1-f97.google.com [209.85.219.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7782268D2E9 for ; Sun, 24 Mar 2024 04:25:10 +0200 (EET) Received: by mail-qv1-f97.google.com with SMTP id 6a1803df08f44-68f41af71ebso27714206d6.1 for ; Sat, 23 Mar 2024 19:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1711247109; x=1711851909; 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=Hn/LMrlhIbLU+1Jb6tDt02HlNdZnmJCVQQpJGCctkfg=; b=PZcCoufiu+q64AVFQpnicrZe4DkctQsO118GYv8uvM2uBbvTU2FqJnzTeITpEAKLjj n90HVfNhp5ybNdVnou/Wg2UzyBFG3ENBoaZOjmR+d58PysKPUmVxcNOyYD07o5ELHZpj Dyh7R7KW/4bTjQgEO3H7Tf8qtCOp7GYdxe8xBjWyqHvMrKu9wWUdjtDGGOqyUbA7n+6i C+h522CK+azOzHiHZDQ9maWLV/wKtGbAheO0LpzypkpdRZiCVb83DPYl5odEzFN8Vv9b iQByOxVthaAk0ezNgsexFs4IMbbVDX+FOzTckw9DTBl728zlWge+Zc+GCMAwGLMyLWbl 1eOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711247109; x=1711851909; 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=Hn/LMrlhIbLU+1Jb6tDt02HlNdZnmJCVQQpJGCctkfg=; b=SR5DamvBUc64MXmaQ623PHj7MwiObybNl7ow55bSJV2dpNJDo6P9NREKrdGEKQ61sb 7qxdGHo9a7Vj7Vp/uFAo9EaPkwvreyRPxh1V9KB9z5b3lXWImoLduSh/x/LyhiP6iWgG T/+JE5xtp2/QYz3piyJRdJR4K112lxXUZNUQ7a2XmnN1Jxt8oacvt8RZHxDGHqvrJtGK o4SWAdoABlFqCbtjc9vlfkmNIn73CqbEOncpbvKFbI3K0UBgNSbFaXD9yoCwdRZ9YNHK DYjhCgQMIE5GRPWxdH2yJUR66qa3nEFXVHgSxx8bCKhmLUnBbejhamv5Vazt1wREjIYY YGIw== X-Gm-Message-State: AOJu0Yw8Bg8DGx8Y0W3d+c3+2KBVOVeYaajrsLFJpRWuY7L2FatJAb/A j9bU2tSSsOBj6Wzmid7v0bZZtUb8dz5d6RXoih9B1YdM7vcniIzPXTDt8O80pgLmLxNN+HMd6i1 xdIkWru34AY6djajSNtbf++6+x95R0brFqBy6LiLU X-Google-Smtp-Source: AGHT+IGjLCKQN/hxpKTBUfPWap126nZP+0h7lhdDwwQ8T5/Zwd6wc2VIsJIcTCufktk/MlmJ9fFcsKFknEld X-Received: by 2002:a05:6214:76f:b0:696:8630:ef6a with SMTP id f15-20020a056214076f00b006968630ef6amr1141871qvz.6.1711247109239; Sat, 23 Mar 2024 19:25:09 -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 gu4-20020a056214260400b00690ba140f7esm362113qvb.56.2024.03.23.19.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:25:09 -0700 (PDT) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Mar 2024 21:25:00 -0500 Message-Id: <20240324022504.1419451-2-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240324022504.1419451-1-marth64@proxyid.net> References: <20240324022504.1419451-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [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: 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; } 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 -- 2.34.1 _______________________________________________ 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".