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 0EC8F48DCD for ; Thu, 28 Mar 2024 20:11:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49F8D68D70F; Thu, 28 Mar 2024 22:11:47 +0200 (EET) Received: from mail-pl1-f228.google.com (mail-pl1-f228.google.com [209.85.214.228]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3185868D509 for ; Thu, 28 Mar 2024 22:11:38 +0200 (EET) Received: by mail-pl1-f228.google.com with SMTP id d9443c01a7336-1e2232e30f4so6571265ad.2 for ; Thu, 28 Mar 2024 13:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1711656696; x=1712261496; 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=D1yE8al03Ym+FCEbux3/VxG1QcAx/KooNH4mSPGo0LQ=; b=BonlGSwlpfZq+k83QDXH35s9JyLPRGX43AX9Zl3dcDHs0nMOUNIxksy1sFbzvQcNhJ ZjzMKhvo+zSA59JwYpJVkI1Ig1tp+f3nofsFzTWSstyR9LwMG4f08dNEXxhUMutCfCL5 8kftO44sx6xjeK9xDB1Y6HYbiRZZeHjZwRYlPxD3fbjSjfaPFh2D4JjvKNKfVO8j/Z27 MGq08Jz0NBQL8gyz8JtcZncqrNKqelxcejRn4OSPJoA+LnqyufoERx1efdGBcHrbvuyC oWSO3Xu0tn86eVRJFjnm5Ra0jeSkkbnlMSROG5gMEvy94rrCCfxDYntL/mXS7RUNXpbL nUmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711656696; x=1712261496; 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=D1yE8al03Ym+FCEbux3/VxG1QcAx/KooNH4mSPGo0LQ=; b=GQ4wxTfX5cIpJkU8kzh4Hy8uxRaObmeGFKafOdyCT89QA34oZgpKm/Y6eIlUWp8ZBr HasufUEWZqgfxHCA46g8fWN21y2tj3ryiJ1NCXFY5pO7lcT1epTnNEzu2SnAEkFEo8DS 6OMpdM5CB7Dzm25aQqDwmBvCgmO3Ky0izcbLGPWGb/Svd+1jnQdpdfGRcKjfhV4iQpNi Gg+RRujE6G4fqmi8BzXMjKfca0b3xStjTbDkF3GDNk3i4kuhEeTFGOk8ybz1HdsN0jSQ dCH899GhC+Kr9Xd6ZmK/GRAlYFnKOLBMCGVuKyCYqtlweD8vlCBaR8rGtfHrwXH74DD6 ISkw== X-Gm-Message-State: AOJu0YzeaynEf6G4OsZCNmSV/jN2YGWMpGpdPaUKoraiCXL9DSYgLYFg gtEctEPtJYTDM4lpqiQHNCP73DLCphes5odFLAL+E6hAWHxUidkYhAXm34EaqVytpii0nbIp0Uu ykhPDiRE0VioxayTKz0ANaRn5LfhiWoF8MiG77m6T X-Google-Smtp-Source: AGHT+IE4Z0T194vbd/ZkewtQuZVaj6DiuRQWoErW7MJnKKb8/oerCC9ifsOEf1r5HiJIT1P+5HmKPx0pXsiT X-Received: by 2002:a17:902:f552:b0:1e0:9aab:7500 with SMTP id h18-20020a170902f55200b001e09aab7500mr595734plf.44.1711656696316; Thu, 28 Mar 2024 13:11:36 -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 b8-20020a170902d88800b001e0c9462e9fsm61791plz.57.2024.03.28.13.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:11:36 -0700 (PDT) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 15:11:28 -0500 Message-Id: <20240328201132.1804716-2-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328201132.1804716-1-marth64@proxyid.net> References: <20240328201132.1804716-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v10 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 | 23 +++++++++++++++-------- libavformat/subtitles.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 3413763c7b..1c9b229f5b 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,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 */ @@ -133,14 +138,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".