Mercurial > libavcodec.hg
changeset 12118:14f1cfd2f1f2 libavcodec
Allow using libxvid RC without enabling encoding wrapper
author | mru |
---|---|
date | Fri, 09 Jul 2010 10:53:30 +0000 |
parents | 5043c3aaa0a2 |
children | 4530b6b4d931 |
files | Makefile libxvidff.c |
diffstat | 2 files changed, 41 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Jul 08 22:57:27 2010 +0000 +++ b/Makefile Fri Jul 09 10:53:30 2010 +0000 @@ -544,7 +544,7 @@ OBJS-$(CONFIG_LIBVPX_DECODER) += libvpxdec.o OBJS-$(CONFIG_LIBVPX_ENCODER) += libvpxenc.o OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o -OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvidff.o libxvid_rc.o +OBJS-$(CONFIG_LIBXVID) += libxvidff.o libxvid_rc.o # parsers OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o \
--- a/libxvidff.c Thu Jul 08 22:57:27 2010 +0000 +++ b/libxvidff.c Fri Jul 09 10:53:30 2010 +0000 @@ -80,6 +80,44 @@ int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); void xvid_correct_framerate(AVCodecContext *avctx); +/* Wrapper to work around the lack of mkstemp() on mingw/cygin. + * Also, tries to create file in /tmp first, if possible. + * *prefix can be a character constant; *filename will be allocated internally. + * @return file descriptor of opened file (or -1 on error) + * and opened file name in **filename. */ +int ff_tempfile(char *prefix, char **filename) { + int fd=-1; +#if !HAVE_MKSTEMP + *filename = tempnam(".", prefix); +#else + size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ + *filename = av_malloc(len); +#endif + /* -----common section-----*/ + if (*filename == NULL) { + av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); + return -1; + } +#if !HAVE_MKSTEMP + fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); +#else + snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); + fd = mkstemp(*filename); + if (fd < 0) { + snprintf(*filename, len, "./%sXXXXXX", prefix); + fd = mkstemp(*filename); + } +#endif + /* -----common section-----*/ + if (fd < 0) { + av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); + return -1; + } + return fd; /* success */ +} + +#if CONFIG_LIBXVID_ENCODER + /** * Create the private context for the encoder. * All buffers are allocated, settings are loaded from the user, @@ -770,42 +808,6 @@ } } -/* Wrapper to work around the lack of mkstemp() on mingw/cygin. - * Also, tries to create file in /tmp first, if possible. - * *prefix can be a character constant; *filename will be allocated internally. - * @return file descriptor of opened file (or -1 on error) - * and opened file name in **filename. */ -int ff_tempfile(char *prefix, char **filename) { - int fd=-1; -#if !HAVE_MKSTEMP - *filename = tempnam(".", prefix); -#else - size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ - *filename = av_malloc(len); -#endif - /* -----common section-----*/ - if (*filename == NULL) { - av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); - return -1; - } -#if !HAVE_MKSTEMP - fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); -#else - snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); - fd = mkstemp(*filename); - if (fd < 0) { - snprintf(*filename, len, "./%sXXXXXX", prefix); - fd = mkstemp(*filename); - } -#endif - /* -----common section-----*/ - if (fd < 0) { - av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); - return -1; - } - return fd; /* success */ -} - /** * Xvid codec definition for libavcodec. */ @@ -820,3 +822,5 @@ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"), }; + +#endif /* CONFIG_LIBXVID_ENCODER */