Skip to content
Browse files

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  fate: Allow setting the ld parameter from the config file
  x86: dsputil: Do not redundantly check for CPU caps before calling init funcs
  configure: Disable some warnings in MSVC
  x86: vp56: cmov version of vp56_rac_get_prob requires inline asm
  avopt: fix examples to match the same style about default values as the actual code.
  configure: Add support for MSVC cl.exe/link.exe
  lavu: add snprintf(), vsnprint() and strtod() replacements for MS runtime.

Conflicts:
	libavutil/opt.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information...
2 parents 2bb6245 + 2b36600 commit 40112e7b3589e1cf37cd80a7d2e8baad4cb8c523 @michaelni michaelni committed Sep 6, 2012
Showing with 220 additions and 9 deletions.
  1. +63 −0 compat/msvcrt/snprintf.c
  2. +94 −0 compat/strtod.c
  3. +50 −0 configure
  4. +4 −4 libavcodec/x86/dsputil_mmx.c
  5. +1 −1 libavcodec/x86/vp56_arith.h
  6. +3 −0 libavutil/Makefile
  7. +4 −4 libavutil/opt.h
  8. +1 −0 tests/fate.sh
View
63 compat/msvcrt/snprintf.c
@@ -0,0 +1,63 @@
+/*
+ * C99-compatible snprintf() and vsnprintf() implementations
+ * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <string.h>
+
+#include "libavutil/error.h"
+
+int avpriv_snprintf(char *s, size_t n, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = avpriv_vsnprintf(s, n, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
+int avpriv_vsnprintf(char *s, size_t n, const char *fmt,
+ va_list ap)
+{
+ int ret;
+
+ if (n == 0)
+ return 0;
+ else if (n > INT_MAX)
+ return AVERROR(EOVERFLOW);
+
+ /* we use n - 1 here because if the buffer is not big enough, the MS
+ * runtime libraries don't add a terminating zero at the end. MSDN
+ * recommends to provide _snprintf/_vsnprintf() a buffer size that
+ * is one less than the actual buffer, and zero it before calling
+ * _snprintf/_vsnprintf() to workaround this problem.
+ * See http://msdn.microsoft.com/en-us/library/1kt27hek(v=vs.80).aspx */
+ memset(s, 0, n);
+ ret = _vsnprintf(s, n - 1, fmt, ap);
+ if (ret == -1)
+ ret = n;
+
+ return ret;
+}
View
94 compat/strtod.c
@@ -0,0 +1,94 @@
+/*
+ * C99-compatible strtod() implementation
+ * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <ctype.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "libavutil/avstring.h"
+#include "libavutil/mathematics.h"
+
+static char *check_nan_suffix(char *s)
+{
+ char *start = s;
+
+ if (*s++ != '(')
+ return start;
+
+ while ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
+ (*s >= '0' && *s <= '9') || *s == '_')
+ s++;
+
+ return *s == ')' ? s + 1 : start;
+}
+
+#undef strtod
+double strtod(const char *, char **);
+
+double avpriv_strtod(const char *nptr, char **endptr)
+{
+ char *end;
+ double res;
+
+ /* Skip leading spaces */
+ while (isspace(*nptr))
+ nptr++;
+
+ if (!av_strncasecmp(nptr, "infinity", 8)) {
+ end = nptr + 8;
+ res = INFINITY;
+ } else if (!av_strncasecmp(nptr, "inf", 3)) {
+ end = nptr + 3;
+ res = INFINITY;
+ } else if (!av_strncasecmp(nptr, "+infinity", 9)) {
+ end = nptr + 9;
+ res = INFINITY;
+ } else if (!av_strncasecmp(nptr, "+inf", 4)) {
+ end = nptr + 4;
+ res = INFINITY;
+ } else if (!av_strncasecmp(nptr, "-infinity", 9)) {
+ end = nptr + 9;
+ res = -INFINITY;
+ } else if (!av_strncasecmp(nptr, "-inf", 4)) {
+ end = nptr + 4;
+ res = -INFINITY;
+ } else if (!av_strncasecmp(nptr, "nan", 3)) {
+ end = check_nan_suffix(nptr + 3);
+ res = NAN;
+ } else if (!av_strncasecmp(nptr, "+nan", 4) ||
+ !av_strncasecmp(nptr, "-nan", 4)) {
+ end = check_nan_suffix(nptr + 4);
+ res = NAN;
+ } else if (!av_strncasecmp(nptr, "0x", 2) ||
+ !av_strncasecmp(nptr, "-0x", 3) ||
+ !av_strncasecmp(nptr, "+0x", 3)) {
+ /* FIXME this doesn't handle exponents, non-integers (float/double)
+ * and numbers too large for long long */
+ res = strtoll(nptr, &end, 16);
+ } else {
+ res = strtod(nptr, &end);
+ }
+
+ if (endptr)
+ *endptr = end;
+
+ return res;
+}
View
50 configure
@@ -1330,6 +1330,7 @@ HAVE_LIST="
mkstemp
mm_empty
mmap
+ msvcrt
nanosleep
PeekNamedPipe
perl
@@ -2369,6 +2370,26 @@ EOF
die "Sanity test failed."
fi
+msvc_flags(){
+ for flag; do
+ case $flag in
+ -fomit-frame-pointer) echo -Oy ;;
+ -g) echo -Z7 ;;
+ -Wall) echo -W4 -wd4244 -wd4127 -wd4018 -wd4389 \
+ -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \
+ -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \
+ -wd4996 ;;
+ -std=c99) ;;
+ -fno-math-errno) ;;
+ -fno-common) ;;
+ -fno-signed-zeros) ;;
+ -lz) echo zlib.lib ;;
+ -l*) echo ${flag#-l}.lib ;;
+ *) echo $flag ;;
+ esac
+ done
+}
+
pgi_flags(){
for flag; do
case $flag in
@@ -2555,6 +2576,29 @@ probe_cc(){
_cflags_size="-O2 -Munroll=c:1 $opt_common"
_cflags_noopt="-O1"
_flags_filter=pgi_flags
+ elif $_cc 2>&1 | grep -q Microsoft; then
+ _type=msvc
+ _ident=$($cc 2>&1 | head -n1)
+ _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
+ _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
+ _cflags_speed="-O2"
+ _cflags_size="-O1"
+ # Nonstandard output options, to avoid msys path conversion issues, relies on wrapper to remap it
+ if $_cc 2>&1 | grep -q Linker; then
+ _ld_o='-out $@'
+ else
+ _ld_o='-Fe$@'
+ fi
+ _cc_o='-Fo $@'
+ _flags_filter=msvc_flags
+ _ld_lib='lib%.a'
+ _ld_path='-libpath:'
+ _flags='-nologo'
+ _cflags='-D_USE_MATH_DEFINES -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64'
+ if [ $pfx = hostcc ]; then
+ _cflags="$cflags -Dsnprintf=_snprintf"
+ fi
+ disable aligned_stack
fi
eval ${pfx}_type=\$_type
@@ -3117,6 +3161,12 @@ elif check_header _mingw.h; then
die "ERROR: MinGW runtime version must be >= 3.15."
elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then
libc_type=newlib
+elif check_func_headers stdlib.h _get_doserrno; then
+ libc_type=msvcrt
+ add_cflags -Dstrtod=avpriv_strtod
+ add_cflags -Dsnprintf=avpriv_snprintf \
+ -D_snprintf=avpriv_snprintf \
+ -Dvsnprintf=avpriv_vsnprintf
elif check_cpp_condition stddef.h "defined __KLIBC__"; then
libc_type=klibc
fi
View
8 libavcodec/x86/dsputil_mmx.c
@@ -3189,13 +3189,13 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
if (mm_flags & AV_CPU_FLAG_MMXEXT)
dsputil_init_mmx2(c, avctx, mm_flags);
- if (mm_flags & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW)
+ if (mm_flags & AV_CPU_FLAG_3DNOW)
dsputil_init_3dnow(c, avctx, mm_flags);
- if (mm_flags & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT)
+ if (mm_flags & AV_CPU_FLAG_3DNOWEXT)
dsputil_init_3dnowext(c, avctx, mm_flags);
- if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE)
+ if (mm_flags & AV_CPU_FLAG_SSE)
dsputil_init_sse(c, avctx, mm_flags);
if (mm_flags & AV_CPU_FLAG_SSE2)
@@ -3204,7 +3204,7 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
if (mm_flags & AV_CPU_FLAG_SSSE3)
dsputil_init_ssse3(c, avctx, mm_flags);
- if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE)
+ if (mm_flags & AV_CPU_FLAG_SSE4)
dsputil_init_sse4(c, avctx, mm_flags);
if (mm_flags & AV_CPU_FLAG_AVX)
View
2 libavcodec/x86/vp56_arith.h
@@ -24,7 +24,7 @@
#ifndef AVCODEC_X86_VP56_ARITH_H
#define AVCODEC_X86_VP56_ARITH_H
-#if HAVE_FAST_CMOV
+#if HAVE_INLINE_ASM && HAVE_FAST_CMOV
#define vp56_rac_get_prob vp56_rac_get_prob
static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
{
View
3 libavutil/Makefile
@@ -94,6 +94,9 @@ OBJS = adler32.o \
utils.o \
xtea.o \
+OBJS-$(HAVE_MSVCRT) += ../compat/msvcrt/snprintf.o \
+ ../compat/strtod.o
+
TESTPROGS = adler32 \
aes \
avstring \
View
8 libavutil/opt.h
@@ -64,7 +64,7 @@
*
* static const AVOption options[] = {
* { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
- * AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX },
+ * AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX },
* { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
* AV_OPT_TYPE_STRING },
* { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
@@ -123,7 +123,7 @@
* } child_struct;
* static const AVOption child_opts[] = {
* { "test_flags", "This is a test option of flags type.",
- * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX },
+ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX },
* { NULL },
* };
* static const AVClass child_class = {
@@ -170,8 +170,8 @@
* above, put the following into the child_opts array:
* @code
* { "test_flags", "This is a test option of flags type.",
- * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, "test_unit" },
- * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, {.i64 = 16 }, 0, 0, "test_unit" },
+ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" },
+ * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" },
* @endcode
*
* @section avoptions_use Using AVOptions
View
1 tests/fate.sh
@@ -50,6 +50,7 @@ configure()(
${cpu:+--cpu="$cpu"} \
${cross_prefix:+--cross-prefix="$cross_prefix"} \
${cc:+--cc="$cc"} \
+ ${ld:+--ld="$ld"} \
${target_os:+--target-os="$target_os"} \
${sysroot:+--sysroot="$sysroot"} \
${target_exec:+--target-exec="$target_exec"} \

0 comments on commit 40112e7

Please sign in to comment.
Something went wrong with that request. Please try again.