From patchwork Fri Feb 17 17:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 40423 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1499412pzk; Fri, 17 Feb 2023 09:03:22 -0800 (PST) X-Google-Smtp-Source: AK7set8UED80x+OlNEdR0FLxY1t8k/MKtbiIrxTkfp5XqAz79qpy0Sn29kIYpdJqadhMPKI4nCmS X-Received: by 2002:a17:907:97cd:b0:8b7:80d5:e7e5 with SMTP id js13-20020a17090797cd00b008b780d5e7e5mr1455926ejc.17.1676653401907; Fri, 17 Feb 2023 09:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676653401; cv=none; d=google.com; s=arc-20160816; b=HWu0iuVmtprl0jn+LrK3aU27JDwgM/RGh20l1UImFTFeQKFdVd4JsDsxVBTD33mB1Z TvtVZNwluQZUeYfRT6u1W2A3kj79H6s3X+aXoa7GCZmc1IDUPq1yisYG3fwGm79FSb1U cNXuRN3FXj01TrO+MvGh7yNNfWKA/1R731sb7Nh/mapc6gVlJ73EzfgDbR/FwUsyt4jI Tmo1f5A7LOuuuhwET+TiT9K7XRJzNp36r212bqtqP/n2RSDdJrY3RM0VRf9wbDxjjkZS gTWzxLhxxIU7GBftcStZQoBdWN4qneuAzq+RCdbDzpsriSPJQVXBstS7V0MutrA8zCCB DK4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=Kcmac+PPCPHK9WjUmCvMCj+IgzkX7ix2kZmJHmSY+o0=; b=junU9fiWN2OasZsG6SWWrKRMCPD1g8bwTiSky7JM9yJVwr4g0a+Ef/et+q6NXtrvMm JBzsW6wM8kiXd/RgQIrhKP2olvpp4fJ2bkfWRu0RrFnoga0gNFDn6o4PcXc1opGjhatG 5IY6ApvUWaoRZ2J4Lf4O4G5rzBwuCvTMd7tgG1gQODbU/GNsyNPLTOZyrnxhV+QHj1xf 3YMAjC8m/MCZQh5WBeWmERVwf1Qj0fiz041KWC7ghtLAK6pnj0KRyWPK77jwtaVeWahB v9JIoZ5o0V1dw2x4eCtUXa4J/ji4KGEWkPJXr4cSVZZ4r1Qodsz3oU5Ij2AN02fGnoxX aBWw== ARC-Authentication-Results: i=1; mx.google.com; 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 w12-20020a50fa8c000000b004acdef7bab2si6039574edr.220.2023.02.17.09.03.21; Fri, 17 Feb 2023 09:03:21 -0800 (PST) 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; 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 0B3D068BE80; Fri, 17 Feb 2023 19:03:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13E0868B418 for ; Fri, 17 Feb 2023 19:03:12 +0200 (EET) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4PJJ6N5Vbtz9sW3 for ; Fri, 17 Feb 2023 18:03:08 +0100 (CET) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Feb 2023 22:32:45 +0530 Message-Id: <20230217170249.8148-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/5] avformat: add av_program_add_stream_index2() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nPMDZg+D84AE av_program_add_stream_index() added in 526efa10534 may fail to carry out its purpose but the lack of a return value stops callers from catching any error. Fixed in new function. --- As suggested by Andreas in https://ffmpeg.org/pipermail/ffmpeg-devel/2023-February/306645.html doc/APIchanges | 3 +++ libavformat/avformat.c | 21 +++++++++++++++------ libavformat/avformat.h | 13 +++++++++++++ libavformat/version.h | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 29161e30bf..889f9925b1 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-02-xx - xxxxxxxxxx - lavf 60.3.100 - avformat.h + Add av_program_add_stream_index2(). + 2023-02-16 - xxxxxxxxxx - lavf 60.2.100 - avformat.h Deprecate AVFormatContext io_close callback. The superior io_close2 callback should be used instead. diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 708d90b38c..0f203e4f86 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -333,14 +333,14 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) return program; } -void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) +int av_program_add_stream_index2(AVFormatContext *ac, int progid, unsigned idx) { AVProgram *program = NULL; void *tmp; if (idx >= ac->nb_streams) { - av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx); - return; + av_log(ac, AV_LOG_ERROR, "stream index %d is greater than stream count %d\n", idx, ac->nb_streams); + return AVERROR(EINVAL); } for (unsigned i = 0; i < ac->nb_programs; i++) { @@ -349,15 +349,24 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) program = ac->programs[i]; for (unsigned j = 0; j < program->nb_stream_indexes; j++) if (program->stream_index[j] == idx) - return; + return 0; tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int)); if (!tmp) - return; + return AVERROR(ENOMEM); program->stream_index = tmp; program->stream_index[program->nb_stream_indexes++] = idx; - return; + return 0; } + + av_log(ac, AV_LOG_ERROR, "No program with id %d found\n", progid); + return AVERROR(EINVAL); +} + +void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) +{ + av_program_add_stream_index2(ac, progid, idx); + return; } AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 1916aa2dc5..33ab0bc8ba 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2046,6 +2046,19 @@ AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); +/** + * Add the supplied index of a stream to the AVProgram with matching id. + * + * @param ac the format context which contains the target AVProgram + * @param progid the ID of the AVProgram whose stream index is to be updated + * @param idx the index of the stream to be added + * + * @return >=0 upon successful addition or if index was already present, + * AVERROR if no matching program is found or stream index is invalid or + * the stream index array reallocation failed. + */ +int av_program_add_stream_index2(AVFormatContext *ac, int progid, unsigned int idx); + /** * Find the "best" stream in the file. * The best stream is determined according to various heuristics as the most diff --git a/libavformat/version.h b/libavformat/version.h index 904e7f06aa..7ff1483912 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 2 +#define LIBAVFORMAT_VERSION_MINOR 3 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \