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.
Unified · Split
| @@ -13,6 +13,10 @@ libavutil: 2011-04-18 · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | API changes, most recent first: | 14 | API changes, most recent first: |
| 15 | 15 | ||
| 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 | |||
| 16 | 2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h | 20 | 2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h |
| 17 | Make libavfilter/vsrc_buffer.h public. | 21 | Make libavfilter/vsrc_buffer.h public. |
| 18 | 22 | ||
| @@ -3881,10 +3881,10 @@ static void opt_output_file(const char *filename) · 3880 unmodified lines | |||
| 3881 | if (!strcmp(filename, "-")) | 3881 | if (!strcmp(filename, "-")) |
| 3882 | filename = "pipe:"; | 3882 | filename = "pipe:"; |
| 3883 | 3883 | ||
| 3884 | oc = avformat_alloc_output_context(last_asked_format, NULL, filename); | 3884 | err = avformat_alloc_output_context2(&oc, NULL, last_asked_format, filename); |
| 3885 | last_asked_format = NULL; | 3885 | last_asked_format = NULL; |
| 3886 | if (!oc) { | 3886 | if (!oc) { |
| 3887 | print_error(filename, AVERROR(ENOMEM)); | 3887 | print_error(filename, err); |
| 3888 | ffmpeg_exit(1); | 3888 | ffmpeg_exit(1); |
| 3889 | } | 3889 | } |
| 3890 | file_oformat= oc->oformat; | 3890 | file_oformat= oc->oformat; |
| @@ -1054,12 +1054,34 @@ int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap); · 1053 unmodified lines | |||
| 1054 | */ | 1054 | */ |
| 1055 | AVFormatContext *avformat_alloc_context(void); | 1055 | AVFormatContext *avformat_alloc_context(void); |
| 1056 | 1056 | ||
| 1057 | #if FF_API_ALLOC_OUTPUT_CONTEXT | ||
| 1057 | /** | 1058 | /** |
| 1058 | * Allocate an AVFormatContext. | 1059 | * @deprecated deprecated in favor of avformat_alloc_output_context2() |
| 1059 | * avformat_free_context() can be used to free the context and everything | ||
| 1060 | * allocated by the framework within it. | ||
| 1061 | */ | 1060 | */ |
| 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); | ||
| 1063 | 1085 | ||
| 1064 | /** | 1086 | /** |
| 1065 | * Read packets of a media file to get stream information. This | 1087 | * Read packets of a media file to get stream information. This |
| @@ -443,10 +443,10 @@ int main(int argc, char **argv) · 442 unmodified lines | |||
| 443 | filename = argv[1]; | 443 | filename = argv[1]; |
| 444 | 444 | ||
| 445 | /* allocate the output media context */ | 445 | /* allocate the output media context */ |
| 446 | oc = avformat_alloc_output_context(NULL, NULL, filename); | 446 | avformat_alloc_output_context2(&oc, NULL, NULL, filename); |
| 447 | if (!oc) { | 447 | if (!oc) { |
| 448 | printf("Could not deduce output format from file extension: using MPEG.\n"); | 448 | 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); |
| 450 | } | 450 | } |
| 451 | if (!oc) { | 451 | if (!oc) { |
| 452 | exit(1); | 452 | exit(1); |
| @@ -2751,8 +2751,13 @@ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) · 2750 unmodified lines | |||
| 2751 | return 0; | 2751 | return 0; |
| 2752 | } | 2752 | } |
| 2753 | 2753 | ||
| 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 | { | ||
| 2755 | AVFormatContext *s= avformat_alloc_context(); | 2757 | AVFormatContext *s= avformat_alloc_context(); |
| 2758 | int ret = 0; | ||
| 2759 | |||
| 2760 | *avctx = NULL; | ||
| 2756 | if(!s) | 2761 | if(!s) |
| 2757 | goto nomem; | 2762 | goto nomem; |
| 2758 | 2763 | ||
| @@ -2761,11 +2766,13 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma · 2 unmodified lines | |||
| 2761 | oformat = av_guess_format(format, NULL, NULL); | 2766 | oformat = av_guess_format(format, NULL, NULL); |
| 2762 | if (!oformat) { | 2767 | if (!oformat) { |
| 2763 | av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format); | 2768 | av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format); |
| 2769 | ret = AVERROR(EINVAL); | ||
| 2764 | goto error; | 2770 | goto error; |
| 2765 | } | 2771 | } |
| 2766 | } else { | 2772 | } else { |
| 2767 | oformat = av_guess_format(NULL, filename, NULL); | 2773 | oformat = av_guess_format(NULL, filename, NULL); |
| 2768 | if (!oformat) { | 2774 | if (!oformat) { |
| 2775 | ret = AVERROR(EINVAL); | ||
| 2769 | av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n", | 2776 | av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n", |
| 2770 | filename); | 2777 | filename); |
| 2771 | goto error; | 2778 | goto error; |
| @@ -2787,14 +2794,26 @@ AVFormatContext *avformat_alloc_output_context(const char *format, AVOutputForma · 15 unmodified lines | |||
| 2787 | 2794 | ||
| 2788 | if(filename) | 2795 | if(filename) |
| 2789 | av_strlcpy(s->filename, filename, sizeof(s->filename)); | 2796 | av_strlcpy(s->filename, filename, sizeof(s->filename)); |
| 2790 | return s; | 2797 | *avctx = s; |
| 2798 | return 0; | ||
| 2791 | nomem: | 2799 | nomem: |
| 2792 | av_log(s, AV_LOG_ERROR, "Out of memory\n"); | 2800 | av_log(s, AV_LOG_ERROR, "Out of memory\n"); |
| 2801 | ret = AVERROR(ENOMEM); | ||
| 2793 | error: | 2802 | error: |
| 2794 | avformat_free_context(s); | 2803 | avformat_free_context(s); |
| 2795 | return NULL; | 2804 | return ret; |
| 2796 | } | 2805 | } |
| 2797 | 2806 | ||
| 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 | |||
| 2798 | static int validate_codec_tag(AVFormatContext *s, AVStream *st) | 2817 | static int validate_codec_tag(AVFormatContext *s, AVStream *st) |
| 2799 | { | 2818 | { |
| 2800 | const AVCodecTag *avctag; | 2819 | const AVCodecTag *avctag; |
| @@ -24,7 +24,7 @@ · 23 unmodified lines | |||
| 24 | #include "libavutil/avutil.h" | 24 | #include "libavutil/avutil.h" |
| 25 | 25 | ||
| 26 | #define LIBAVFORMAT_VERSION_MAJOR 53 | 26 | #define LIBAVFORMAT_VERSION_MAJOR 53 |
| 27 | #define LIBAVFORMAT_VERSION_MINOR 1 | 27 | #define LIBAVFORMAT_VERSION_MINOR 2 |
| 28 | #define LIBAVFORMAT_VERSION_MICRO 0 | 28 | #define LIBAVFORMAT_VERSION_MICRO 0 |
| 29 | 29 | ||
| 30 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ | 30 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
| @@ -68,5 +68,8 @@ · 37 unmodified lines | |||
| 68 | #ifndef FF_API_SDP_CREATE | 68 | #ifndef FF_API_SDP_CREATE |
| 69 | #define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54) | 69 | #define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54) |
| 70 | #endif | 70 | #endif |
| 71 | #ifndef FF_API_ALLOC_OUTPUT_CONTEXT | ||
| 72 | #define FF_API_ALLOC_OUTPUT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 54) | ||
| 73 | #endif | ||
| 71 | 74 | ||
| 72 | #endif /* AVFORMAT_VERSION_H */ | 75 | #endif /* AVFORMAT_VERSION_H */ |