From patchwork Thu Mar 28 20:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 47599 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1588807pzb; Thu, 28 Mar 2024 13:11:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWAOe+oTTMQHKEW+91n8dXyndE8DYKnxyVazdAv88yiwJ0EwJQ6SRPBhLfhhPr6AYhueYVBZEkJF3onIC7ZxUbSE3PYgmzVuNBp6g== X-Google-Smtp-Source: AGHT+IEZYoR2zN58vwKO80vIKx/YptWpoZSdqlmjXxNS49Xhdkn7lS5iervXYVw6iQbCMUGCqzEE X-Received: by 2002:a50:c047:0:b0:568:c6a2:f411 with SMTP id u7-20020a50c047000000b00568c6a2f411mr237974edd.32.1711656716360; Thu, 28 Mar 2024 13:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711656716; cv=none; d=google.com; s=arc-20160816; b=Y1sn0PtwYelDd8Qzm+b933BIBTMKm3A6hcmVHh7dy/IURMWq6y2Hm1KYFbZlIlywNf SbT4YXmmOvlOOMwRlZezGmw0YJWyVWm8EBXZYwUSeLYoqU8bCBdV2/2L8E9i+5P2hhN/ a+H5Q9tTXQbvs4ffV2qWG/S7yA5866rDzue2h3kVkM7Xr9DIWCu0UMh56cf7cRYjHuVC wfEAuljdZiqXwbeWzsGWfBIz5CXrI/dnDCsGLSa0Wzd9QZ5nkxr7Ku1Jd/NlhEQLEx4g PVo1W7880t0dJPPVogXxXHJkL0T96uXmhkdLqbCBLw6yXBhbCU1PEcratTmSrlGcgHH9 zBCg== 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=6ztIIYG5hsfvwNx45jrwVXyyvFhO1yrczFTrqW5o7OI=; fh=PlWMzmI9LD2qGS7ipLrQl8z0iaQTLQLHzoGuXcBzpCg=; b=r77tHdHg/s5r+Mp5MBS80UOM3gvSSkjK0BxC7YKpnbA4lv7UpL1V6EC3X7JNhCVaVD 03aNCm454ZSTDiw89v8iOS+lPBx3c3kiilGYJJNX+yP4lLANAaHamDcCxRfnnvUOlL+9 mUtk4OyVespo9/P+GzcPA4dlCreYhFJ6hodOCcj5eFYnR95LOLKr4wPxBN6AraOkeIzF 1TeR6SVLYvhR7xIaeHe+oJdYayWJcOuiZNZM3PFy/k6H3RESasv38rpncB8kremTEol7 BJxWBvQP0ZRMFox3fX+ZOgX8f6dB1CZvpIR+mF77Br3MLCTLI4CpzWMPDbQJ5ZKIQUAM 43lw==; 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=BonlGSwl; 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 z16-20020a05640235d000b0056b8075f140si1067630edc.322.2024.03.28.13.11.55; Thu, 28 Mar 2024 13:11:56 -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=BonlGSwl; 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 934A568D714; Thu, 28 Mar 2024 22:11:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TNkYqA34RKse 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