[FFmpeg-cvslog] lavf: deprecate avformat_alloc_output_context() in favor of avformat_alloc_output_context2()
Stefano Sabatini
git at videolan.org
Sun May 22 20:41:51 CEST 2011
ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Thu May 19 22:09:34 2011 +0200| [5ecdfd008bce961c3241eaa1f8dc06e82a6b12db] | committer: Stefano Sabatini
lavf: deprecate avformat_alloc_output_context() in favor of avformat_alloc_output_context2()
The new function accepts a slightly more intuitive order of paramters,
and returns an error code, thus allowing applications to report a
meaningful error message.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5ecdfd008bce961c3241eaa1f8dc06e82a6b12db
---
doc/APIchanges | 4 ++++
ffmpeg.c | 4 ++--
libavformat/avformat.h | 30 ++++++++++++++++++++++++++----
libavformat/output-example.c | 4 ++--
libavformat/utils.c | 25 ++++++++++++++++++++++---
libavformat/version.h | 5 ++++-
6 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 4ccd72b..c738924 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2011-04-18
API changes, most recent first:
+2011-05-22 - xxxxxx - lavf 53.2.0 - avformat.h
+ Introduce avformat_alloc_output_context2() and deprecate
+ avformat_alloc_output_context().
+
2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h
Make libavfilter/vsrc_buffer.h public.
diff --git a/ffmpeg.c b/ffmpeg.c
index b9d182c..af57fc9 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3881,10 +3881,10 @@ static void opt_output_file(const char *filename)
if (!strcmp(filename, "-"))
filename = "pipe:";
- oc = avformat_alloc_output_context(last_asked_format, NULL, filename);
+ err = avformat_alloc_output_context2(&oc, NULL, last_asked_format, filename);
last_asked_format = NULL;
if (!oc) {
- print_error(filename, AVERROR(ENOMEM));
+ print_error(filename, err);
ffmpeg_exit(1);
}
file_oformat= oc->oformat;
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 991b0a4..fc74444 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1054,12 +1054,34 @@ int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
*/
AVFormatContext *avformat_alloc_context(void);
+#if FF_API_ALLOC_OUTPUT_CONTEXT
/**
- * Allocate an AVFormatContext.
- * avformat_free_context() can be used to free the context and everything
- * allocated by the framework within it.
+ * @deprecated deprecated in favor of avformat_alloc_output_context2()
*/
-AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputFormat *oformat, const char *filename);
+attribute_deprecated
+AVFormatContext *avformat_alloc_output_context(const char *format,
+ AVOutputFormat *oformat,
+ const char *filename);
+#endif
+
+/**
+ * Allocate an AVFormatContext for an output format.
+ * avformat_free_context() can be used to free the context and
+ * everything allocated by the framework within it.
+ *
+ * @param *ctx is set to the created format context, or to NULL in
+ * case of failure
+ * @param oformat format to use for allocating the context, if NULL
+ * format_name and filename are used instead
+ * @param format_name the name of output format to use for allocating the
+ * context, if NULL filename is used instead
+ * @param filename the name of the filename to use for allocating the
+ * context, may be NULL
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
+ const char *format_name, const char *filename);
/**
* Read packets of a media file to get stream information. This
diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index ac35ff0..f174305 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -443,10 +443,10 @@ int main(int argc, char **argv)
filename = argv[1];
/* allocate the output media context */
- oc = avformat_alloc_output_context(NULL, NULL, filename);
+ avformat_alloc_output_context2(&oc, NULL, NULL, filename);
if (!oc) {
printf("Could not deduce output format from file extension: using MPEG.\n");
- oc = avformat_alloc_output_context("mpeg", NULL, filename);
+ avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
}
if (!oc) {
exit(1);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c5e5700..71c325a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2751,8 +2751,13 @@ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
return 0;
}
-AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputFormat *oformat, const char *filename){
+int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
+ const char *format, const char *filename)
+{
AVFormatContext *s= avformat_alloc_context();
+ int ret = 0;
+
+ *avctx = NULL;
if(!s)
goto nomem;
@@ -2761,11 +2766,13 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma
oformat = av_guess_format(format, NULL, NULL);
if (!oformat) {
av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
+ ret = AVERROR(EINVAL);
goto error;
}
} else {
oformat = av_guess_format(NULL, filename, NULL);
if (!oformat) {
+ ret = AVERROR(EINVAL);
av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
filename);
goto error;
@@ -2787,14 +2794,26 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma
if(filename)
av_strlcpy(s->filename, filename, sizeof(s->filename));
- return s;
+ *avctx = s;
+ return 0;
nomem:
av_log(s, AV_LOG_ERROR, "Out of memory\n");
+ ret = AVERROR(ENOMEM);
error:
avformat_free_context(s);
- return NULL;
+ return ret;
}
+#if FF_API_ALLOC_OUTPUT_CONTEXT
+AVFormatContext *avformat_alloc_output_context(const char *format,
+ AVOutputFormat *oformat, const char *filename)
+{
+ AVFormatContext *avctx;
+ int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename);
+ return ret < 0 ? NULL : avctx;
+}
+#endif
+
static int validate_codec_tag(AVFormatContext *s, AVStream *st)
{
const AVCodecTag *avctag;
diff --git a/libavformat/version.h b/libavformat/version.h
index fb4577a..76b86ed 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -24,7 +24,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 1
+#define LIBAVFORMAT_VERSION_MINOR 2
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -68,5 +68,8 @@
#ifndef FF_API_SDP_CREATE
#define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
+#ifndef FF_API_ALLOC_OUTPUT_CONTEXT
+#define FF_API_ALLOC_OUTPUT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
#endif /* AVFORMAT_VERSION_H */
More information about the ffmpeg-cvslog
mailing list