History

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.

Stefano Sabatini committed 15 years ago

Commit 5ecdfd01 parent 83db7196 files · +60 −12Browse files

Unified · Split

6 files
  1. doc/APIchanges +4 −0
  2. ffmpeg.c +2 −2
  3. libavformat/avformat.h +26 −4
  4. libavformat/output-example.c +2 −2
  5. libavformat/utils.c +22 −3
  6. libavformat/version.h +4 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2011-04-18 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2011-05-22 - xxxxxx - lavf 53.2.0 - avformat.h
17+ Introduce avformat_alloc_output_context2() and deprecate
18+ avformat_alloc_output_context().
19+
1620 2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h
1721 Make libavfilter/vsrc_buffer.h public.
1822
ffmpeg.c+2−2
@@ -3881,10 +3881,10 @@ static void opt_output_file(const char *filename) · 3880 unmodified lines
38813881 if (!strcmp(filename, "-"))
38823882 filename = "pipe:";
38833883
3884− oc = avformat_alloc_output_context(last_asked_format, NULL, filename);
3884+ err = avformat_alloc_output_context2(&oc, NULL, last_asked_format, filename);
38853885 last_asked_format = NULL;
38863886 if (!oc) {
3887− print_error(filename, AVERROR(ENOMEM));
3887+ print_error(filename, err);
38883888 ffmpeg_exit(1);
38893889 }
38903890 file_oformat= oc->oformat;
libavformat/avformat.h+26−4
@@ -1054,12 +1054,34 @@ int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap); · 1053 unmodified lines
10541054 */
10551055 AVFormatContext *avformat_alloc_context(void);
10561056
1057+#if FF_API_ALLOC_OUTPUT_CONTEXT
10571058 /**
1058− * Allocate an AVFormatContext.
1059− * avformat_free_context() can be used to free the context and everything
1060− * allocated by the framework within it.
1059+ * @deprecated deprecated in favor of avformat_alloc_output_context2()
10611060 */
1062−AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputFormat *oformat, const char *filename);
1061+attribute_deprecated
1062+AVFormatContext *avformat_alloc_output_context(const char *format,
1063+ AVOutputFormat *oformat,
1064+ const char *filename);
1065+#endif
1066+
1067+/**
1068+ * Allocate an AVFormatContext for an output format.
1069+ * avformat_free_context() can be used to free the context and
1070+ * everything allocated by the framework within it.
1071+ *
1072+ * @param *ctx is set to the created format context, or to NULL in
1073+ * case of failure
1074+ * @param oformat format to use for allocating the context, if NULL
1075+ * format_name and filename are used instead
1076+ * @param format_name the name of output format to use for allocating the
1077+ * context, if NULL filename is used instead
1078+ * @param filename the name of the filename to use for allocating the
1079+ * context, may be NULL
1080+ * @return >= 0 in case of success, a negative AVERROR code in case of
1081+ * failure
1082+ */
1083+int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
1084+ const char *format_name, const char *filename);
10631085
10641086 /**
10651087 * Read packets of a media file to get stream information. This
libavformat/output-example.c+2−2
@@ -443,10 +443,10 @@ int main(int argc, char **argv) · 442 unmodified lines
443443 filename = argv[1];
444444
445445 /* allocate the output media context */
446− oc = avformat_alloc_output_context(NULL, NULL, filename);
446+ avformat_alloc_output_context2(&oc, NULL, NULL, filename);
447447 if (!oc) {
448448 printf("Could not deduce output format from file extension: using MPEG.\n");
449− oc = avformat_alloc_output_context("mpeg", NULL, filename);
449+ avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
450450 }
451451 if (!oc) {
452452 exit(1);
libavformat/utils.c+22−3
@@ -2751,8 +2751,13 @@ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) · 2750 unmodified lines
27512751 return 0;
27522752 }
27532753
2754−AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputFormat *oformat, const char *filename){
2754+int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
2755+ const char *format, const char *filename)
2756+{
27552757 AVFormatContext *s= avformat_alloc_context();
2758+ int ret = 0;
2759+
2760+ *avctx = NULL;
27562761 if(!s)
27572762 goto nomem;
27582763
@@ -2761,11 +2766,13 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma · 2 unmodified lines
27612766 oformat = av_guess_format(format, NULL, NULL);
27622767 if (!oformat) {
27632768 av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
2769+ ret = AVERROR(EINVAL);
27642770 goto error;
27652771 }
27662772 } else {
27672773 oformat = av_guess_format(NULL, filename, NULL);
27682774 if (!oformat) {
2775+ ret = AVERROR(EINVAL);
27692776 av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
27702777 filename);
27712778 goto error;
@@ -2787,14 +2794,26 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma · 15 unmodified lines
27872794
27882795 if(filename)
27892796 av_strlcpy(s->filename, filename, sizeof(s->filename));
2790− return s;
2797+ *avctx = s;
2798+ return 0;
27912799 nomem:
27922800 av_log(s, AV_LOG_ERROR, "Out of memory\n");
2801+ ret = AVERROR(ENOMEM);
27932802 error:
27942803 avformat_free_context(s);
2795− return NULL;
2804+ return ret;
27962805 }
27972806
2807+#if FF_API_ALLOC_OUTPUT_CONTEXT
2808+AVFormatContext *avformat_alloc_output_context(const char *format,
2809+ AVOutputFormat *oformat, const char *filename)
2810+{
2811+ AVFormatContext *avctx;
2812+ int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename);
2813+ return ret < 0 ? NULL : avctx;
2814+}
2815+#endif
2816+
27982817 static int validate_codec_tag(AVFormatContext *s, AVStream *st)
27992818 {
28002819 const AVCodecTag *avctag;
libavformat/version.h+4−1
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424 #include "libavutil/avutil.h"
2525
2626 #define LIBAVFORMAT_VERSION_MAJOR 53
27−#define LIBAVFORMAT_VERSION_MINOR 1
27+#define LIBAVFORMAT_VERSION_MINOR 2
2828 #define LIBAVFORMAT_VERSION_MICRO 0
2929
3030 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -68,5 +68,8 @@ · 37 unmodified lines
6868 #ifndef FF_API_SDP_CREATE
6969 #define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54)
7070 #endif
71+#ifndef FF_API_ALLOC_OUTPUT_CONTEXT
72+#define FF_API_ALLOC_OUTPUT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 54)
73+#endif
7174
7275 #endif /* AVFORMAT_VERSION_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t