Mercurial > libavcodec.hg
comparison utils.c @ 12097:e8a29b278ebf libavcodec
Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
| author | mru |
|---|---|
| date | Tue, 06 Jul 2010 13:04:21 +0000 |
| parents | fdafbcef52f5 |
| children | c35d7bc64882 |
comparison
equal
deleted
inserted
replaced
| 12096:900b6c2523dc | 12097:e8a29b278ebf |
|---|---|
| 23 /** | 23 /** |
| 24 * @file | 24 * @file |
| 25 * utils. | 25 * utils. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 /* needed for mkstemp() */ | |
| 29 #define _XOPEN_SOURCE 600 | |
| 30 | |
| 31 #include "libavutil/avstring.h" | 28 #include "libavutil/avstring.h" |
| 32 #include "libavutil/integer.h" | 29 #include "libavutil/integer.h" |
| 33 #include "libavutil/crc.h" | 30 #include "libavutil/crc.h" |
| 34 #include "libavutil/pixdesc.h" | 31 #include "libavutil/pixdesc.h" |
| 35 #include "avcodec.h" | 32 #include "avcodec.h" |
| 36 #include "dsputil.h" | 33 #include "dsputil.h" |
| 37 #include "opt.h" | 34 #include "opt.h" |
| 38 #include "imgconvert.h" | 35 #include "imgconvert.h" |
| 39 #include "audioconvert.h" | 36 #include "audioconvert.h" |
| 40 #include "libxvid_internal.h" | |
| 41 #include "internal.h" | 37 #include "internal.h" |
| 42 #include <stdlib.h> | 38 #include <stdlib.h> |
| 43 #include <stdarg.h> | 39 #include <stdarg.h> |
| 44 #include <limits.h> | 40 #include <limits.h> |
| 45 #include <float.h> | 41 #include <float.h> |
| 46 #if !HAVE_MKSTEMP | |
| 47 #include <fcntl.h> | |
| 48 #endif | |
| 49 | 42 |
| 50 static int volatile entangled_thread_counter=0; | 43 static int volatile entangled_thread_counter=0; |
| 51 int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); | 44 int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); |
| 52 static void *codec_mutex; | 45 static void *codec_mutex; |
| 53 | 46 |
| 1070 *s = v; | 1063 *s = v; |
| 1071 n++; | 1064 n++; |
| 1072 return n; | 1065 return n; |
| 1073 } | 1066 } |
| 1074 | 1067 |
| 1075 /* Wrapper to work around the lack of mkstemp() on mingw/cygin. | |
| 1076 * Also, tries to create file in /tmp first, if possible. | |
| 1077 * *prefix can be a character constant; *filename will be allocated internally. | |
| 1078 * @return file descriptor of opened file (or -1 on error) | |
| 1079 * and opened file name in **filename. */ | |
| 1080 int av_tempfile(char *prefix, char **filename) { | |
| 1081 int fd=-1; | |
| 1082 #if !HAVE_MKSTEMP | |
| 1083 *filename = tempnam(".", prefix); | |
| 1084 #else | |
| 1085 size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ | |
| 1086 *filename = av_malloc(len); | |
| 1087 #endif | |
| 1088 /* -----common section-----*/ | |
| 1089 if (*filename == NULL) { | |
| 1090 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); | |
| 1091 return -1; | |
| 1092 } | |
| 1093 #if !HAVE_MKSTEMP | |
| 1094 fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); | |
| 1095 #else | |
| 1096 snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); | |
| 1097 fd = mkstemp(*filename); | |
| 1098 if (fd < 0) { | |
| 1099 snprintf(*filename, len, "./%sXXXXXX", prefix); | |
| 1100 fd = mkstemp(*filename); | |
| 1101 } | |
| 1102 #endif | |
| 1103 /* -----common section-----*/ | |
| 1104 if (fd < 0) { | |
| 1105 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); | |
| 1106 return -1; | |
| 1107 } | |
| 1108 return fd; /* success */ | |
| 1109 } | |
| 1110 | |
| 1111 typedef struct { | 1068 typedef struct { |
| 1112 const char *abbr; | 1069 const char *abbr; |
| 1113 int width, height; | 1070 int width, height; |
| 1114 } VideoFrameSizeAbbr; | 1071 } VideoFrameSizeAbbr; |
| 1115 | 1072 |
