From patchwork Sat Feb 18 04:49: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: 40436 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp344253pzk; Fri, 17 Feb 2023 20:50:36 -0800 (PST) X-Google-Smtp-Source: AK7set9NtZ3SyCZpkCKvjj3dc2KqmkbOh3Wmc3KWuYbQyTpu6WYj4gwKtbtimE3Gbo7tlWGDhWle X-Received: by 2002:aa7:d690:0:b0:4ad:7224:ce97 with SMTP id d16-20020aa7d690000000b004ad7224ce97mr6141186edr.21.1676695835929; Fri, 17 Feb 2023 20:50:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676695835; cv=none; d=google.com; s=arc-20160816; b=c0/esz8HErVQWFw0sVwArvK5xut0tSct7t4nxPZeUys1COPEknH+LrExpvpokDsfcs 6eLbELWjwWI5dKgFdnfrj5md2Ujkr8PuE1PBxg7hFVvl0l4+ToigedMKqW2vPef0kR3u 7oPvqIaS+8JkRV+nzI+2vOIAwT/6x9AxoKEZ6U7TAOwjYYi58OA0J8+2sd/P4cGvNxnq 49yQLX8Umq4Anf0Lft9Sy+9KNMYBj/hWkyk4s6Br5i/nPRzBIo5sYjv8JG4gid5+D/er DfFyG5yex1f/yQ89ztOw90dcZca1KplbEJjP2emmxGrOYR2hdLV+4ueWU0bVyHosR5cD XsHA== 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=iF2a4N+PMIW8QW215YZmOobe2ZFOmcAg4pgjj7gsWGEbxSP+KS9IbcnLOArXR6yqZ5 SaMLsY/bQa+DQkhImi6ezjv5THJbUgN1C70U14EvMsZ+lyHfaTxnZFyKe7VeiZ8tHyHv vBmL5YJR+L1haJkjpjQxSeHm8son4A7cB0AKD3MWWZOGnnxMtkHbEvHjIwayCFW09/f8 YC94OUXwQUulygz4T9VbV/GnUCv0oZPUyKVWKKPj0znhAE3pucEq5bHAkvWxh/TgD0md yFvMcioaT+W8rDzpL29Ht51JY7e+MNnsy6qxX7juZqpetaOA9FOfjv2i17xXO0dyJ0Bm 5qnw== 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 d17-20020aa7ce11000000b004ace3a00b69si5387976edv.331.2023.02.17.20.50.35; Fri, 17 Feb 2023 20:50:35 -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 B2DE268BE6E; Sat, 18 Feb 2023 06:50:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82ECC68AC05 for ; Sat, 18 Feb 2023 06:50:22 +0200 (EET) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-202.mailbox.org (Postfix) with ESMTPS id 4PJbpM6J0kz9sSL for ; Sat, 18 Feb 2023 05:50:19 +0100 (CET) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Feb 2023 10:19:45 +0530 Message-Id: <20230218044949.1179-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4PJbpM6J0kz9sSL Subject: [FFmpeg-devel] [PATCH v4 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: ULns17B80V+4 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, \