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 0A919456BF for ; Sat, 18 Feb 2023 04:50:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BEF768BE69; Sat, 18 Feb 2023 06:50:30 +0200 (EET) 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 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: 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, \ -- 2.39.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".