From patchwork Sun Mar 24 02:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 47395 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c889:b0:1a3:b6bb:3029 with SMTP id hb9csp483375pzb; Sat, 23 Mar 2024 19:25:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVn0/go6PFt1o8QKCj1vKa1bZm4IywJe23hZ400RD+pqIYi4Hg4lzQ9mtwJJTvaHNSeyFVY5+hZJHgR1luGDyy0JunpTUZqH2QCjQ== X-Google-Smtp-Source: AGHT+IH8VTOhJ6S2aEMuFZHiiFbZN/Rrmpvi9WFTOI3Dltw/cwmPv/jzf6oKnKxWriVRp8QQKF58 X-Received: by 2002:a2e:9816:0:b0:2d6:c59e:37bc with SMTP id a22-20020a2e9816000000b002d6c59e37bcmr1601920ljj.11.1711247127315; Sat, 23 Mar 2024 19:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711247127; cv=none; d=google.com; s=arc-20160816; b=C1d8uTL+svv3qARxMkdZoAzOJB4YU3qR9cMvTpXrgFROI54uN2eEewX6CPH5oUWKUX YQcNiJSgRjNeMngYl22g2ToKabOq2QS4Z1URW/jzEZ3wUFhte2LgsGl2eSseKrfXbJgl k+CGlHyvMhKvo6W3Dymz6HfKcOxypHBtSoW++YzpG6yQ56zoZW7rE62hUFUUOuucwJo/ ysnlyie6dVC6+gZTGr1ATfeks3zJ9b2604HuqVIT/nmwnNwD7U3sFCvqIMl8NFHRpxbI O5ODMI6FNkgUWXNc3MXf/sBnPL7KEuJPCEoMQ9SMftK4fkCC/Gzw6EjwJjhmHsUxDKO5 FVZg== 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=qF7dNbptwuy8knsIKR9gutwzLWDit6Om7Ig7I/c/FbI=; fh=PlWMzmI9LD2qGS7ipLrQl8z0iaQTLQLHzoGuXcBzpCg=; b=N4FSmJ0eQXS+7QdawNFpOoxD0zG/vzot9I2YypC7nDNr2ZRWFrApXSINKDVJCZ8Lq0 YUMak2P3GRTJQrnpr6wIJj1jmv+GZ55Fux7TaaYzcldE8lMpxe3IJpWFwvIAYLJMSs4R c2n050mjmWxYC4dedymzAdLLxqDEVlQbLapMTa8oAnfVImsgJoAAGZHVN6EuFPQUmRbt RgSFfZP/hmN449f/PUvmdd0X6eIexJ1ABSOCRh/H4y4pTE0sR9BHGP3plJLI08AtvMTX bITAnBvAdcAcstLj9F5l+32VPOm7/i1omk/f3vTGWLHdbCmZeJP56srYBlLwKOss4IDC kJSg==; 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=PZcCoufi; 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 p6-20020a05640243c600b0056c0a63b07esi25012edc.304.2024.03.23.19.25.26; Sat, 23 Mar 2024 19:25:27 -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=PZcCoufi; 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 CE5EB68D3CE; Sun, 24 Mar 2024 04:25:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: C5bd8E1NIrAe 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