From: Gyan Doshi <ffmpeg@gyani.pro>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v3 1/5] avformat: add av_program_add_stream_index2()
Date: Fri, 17 Feb 2023 22:32:45 +0530
Message-ID: <20230217170249.8148-1-ffmpeg@gyani.pro> (raw)
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".
next reply other threads:[~2023-02-17 17:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 17:02 Gyan Doshi [this message]
2023-02-17 17:02 ` [FFmpeg-devel] [PATCH v3 2/5] avformat: add av_program_copy() Gyan Doshi
2023-02-17 17:02 ` [FFmpeg-devel] [PATCH v3 3/5] avformat/hls: relay programs to child muxers Gyan Doshi
2023-02-17 22:01 ` Marton Balint
2023-02-18 4:51 ` Gyan Doshi
2023-02-17 17:02 ` [FFmpeg-devel] [PATCH v3 4/5] avformat/segment: " Gyan Doshi
2023-02-17 17:02 ` [FFmpeg-devel] [PATCH v3 5/5] avformat/tee: " Gyan Doshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230217170249.8148-1-ffmpeg@gyani.pro \
--to=ffmpeg@gyani.pro \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git