[Ffmpeg-devel] [PATCH] MinGW and portability

Måns Rullgård mru
Tue Mar 28 22:43:54 CEST 2006


Frantisek Dvorak <valtri at users.sourceforge.net> writes:

> Hi coders, encoders and decoders,
>
> I send several patches which fixes cross build with MinGW:
>
> ff_win32_xine.patch - small patch needed for MinGW compilation. I think
> there should be no problem with this patch

You call that small?

> ff_win32_decls.sh - patch in the "shell" format. :-) Quite agressive,
> may be needed for some Windowze compilers using ffmpeg libraries and
> headers (MSVC, MinGW - needed for 1.2 version for compilation even
> ffmpeg itself).

We do not include workarounds for antiquated compiler versions when
new versions work properly.  We do support compiling with gcc 2.95 as
long as that compiler actually produces faster code than newer
versions.

> ff_win32.diff - various multiplatform fixes (inttypes x stdin), but
> there are some hacks too (rint, lrint,...)
>
> ff_cross)sdl.diff - usind cross compiled SDL (SDL's config file with
> cross prefix)
>
> Please apply mainly the first one (to keep in sync with our xine tree).
> Other are just for inspiration (needed for my FreeBSD's mingw) but
> probably useful...
>
> Cheers,
>   Frantisek
>
> Simple patch needed for MinGW: replacing keyword near.
>
> Index: libavcodec/jpeg_ls.c
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/jpeg_ls.c,v
> retrieving revision 1.5
> diff -u -p -u -r1.5 jpeg_ls.c
> --- libavcodec/jpeg_ls.c	2 Feb 2006 02:36:27 -0000	1.5
> +++ libavcodec/jpeg_ls.c	28 Mar 2006 14:30:33 -0000
> @@ -34,7 +34,7 @@ typedef struct JLSState{
>      int T1, T2, T3;
>      int A[367], B[367], C[365], N[367];
>      int limit, reset, bpp, qbpp, maxval, range;
> -    int near, twonear;
> +    int onenear, twonear;

Rejected, "near" is not a keyword in any version of C.  Fix the compiler.

> #! /bin/sh
>
> #
> # patch using declspec for Windoze clients,
> # its required even inside ffmpeg libraries (tested  on MinGW 1.2)
> #
>
> patch -p0 < $0
>
> cp libavcodec/avcodec.h libavcodec/avcodec.h.dllimports; cat libavcodec/avcodec.h.dllimports | sed -e 's/\(extern AVCodec\)/_DL_IMPORT_AVCODEC \1/' > libavcodec/avcodec.h
> cp libavformat/avformat.h libavformat/avformat.h.dllimports; cat libavformat/avformat.h.dllimports | sed -e 's/\(extern AVImageFormat\)/_DL_IMPORT_AVFORMAT \1/' | sed -e 's/\(extern AVInputFormat\)/_DL_IMPORT_AVFORMAT \1/' | sed -e 's/\(extern AVOutputFormat\)/_DL_IMPORT_AVFORMAT \1/' > libavformat/avformat.h
> cp libavformat/avio.h libavformat/avio.h.dllimports; cat libavformat/avio.h.dllimports | sed -e 's/\(extern URLProtocol\)/_DL_IMPORT_AVFORMAT \1/' | sed -e 's/\(extern URLInterruptCB\)/_DL_IMPORT_AVFORMAT \1/' | sed -e 's/\(extern URLProtocol\)/_DL_IMPORT_AVFORMAT \1/' > libavformat/avio.h

WTF is this supposed to do?  Send a patch if you want to have it
looked at.

> exit 0
>
> Index: Makefile
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/Makefile,v
> retrieving revision 1.102
> diff -u -p -u -r1.102 Makefile
> --- Makefile	26 Mar 2006 21:01:49 -0000	1.102
> +++ Makefile	28 Mar 2006 18:02:31 -0000
> @@ -6,7 +6,7 @@ include config.mak
>  
>  VPATH=$(SRC_PATH)
>  
> -CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
> +CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -DLIB_CLIENT

Why?  LIB_CLIENT doesn't have a magic meaning, and you're not using it
elsewhere.

> -extern int ffm_nopts;
> +_DL_IMPORT extern int ffm_nopts;

Ugh, yuck!!  #define extern if you must.  Changes like this are
unacceptable.

> -CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
> +CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -DAVFORMAT_COMPILE
>  
>  OBJS= utils.o cutils.o os_support.o allformats.o
>  CPPOBJS=
> Index: libavutil/common.h
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavutil/common.h,v
> retrieving revision 1.162
> diff -u -p -u -r1.162 common.h
> --- libavutil/common.h	6 Mar 2006 22:06:33 -0000	1.162
> +++ libavutil/common.h	28 Mar 2006 18:02:46 -0000
> @@ -60,6 +61,28 @@
>  
>  #endif /* HAVE_AV_CONFIG_H */
>  
> +/* for WIN32 library clients */
> +#if defined(WIN32) || defined(__MINGW32__)
> +#  define _DL_IMPORT __declspec(dllimport)
> +#else
> +#  define _DL_IMPORT
> +#endif
> +#ifdef AVUTIL_COMPILE
> +#  define _DL_IMPORT_AVUTIL
> +#else
> +#  define _DL_IMPORT_AVUTIL _DL_IMPORT
> +#endif
> +#ifdef AVCODEC_COMPILE
> +#  define _DL_IMPORT_AVCODEC
> +#else
> +#  define _DL_IMPORT_AVCODEC _DL_IMPORT
> +#endif
> +#ifdef AVFORMAT_COMPILE
> +#  define _DL_IMPORT_AVFORMAT
> +#else
> +#  define _DL_IMPORT_AVFORMAT _DL_IMPORT
> +#endif

What's this all about?  People are compiling and using ffmpeg on
windows all the time without any mess like this.

> Index: qt-faststart.c
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/qt-faststart.c,v
> retrieving revision 1.8
> diff -u -p -u -r1.8 qt-faststart.c
> --- qt-faststart.c	27 Mar 2006 16:34:21 -0000	1.8
> +++ qt-faststart.c	28 Mar 2006 18:02:39 -0000
> @@ -20,13 +20,24 @@
>   * presently only operates on uncompressed moov atoms.
>   */
>  
> +#include "config.h"
>  #include <stdio.h>
>  #include <stdlib.h>
> +#ifdef HAVE_INTTYPES_H
>  #include <inttypes.h>
> +#endif
> +#ifdef HAVE_STDINT_H
> +#include <stdint.h>
> +#endif

Both inttypes.h and stdint.h are standard C.  If you are missing them
you should fix your environment.

>  #ifdef __MINGW32__
> +#if __MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION > 1002

See above about ancient compilers.

>  #define fseeko(x,y,z)  fseeko64(x,y,z)
>  #define ftello(x)      ftello64(x)
> +#else
> +#define fseeko(x,y,z)  fseek(x,y,z)
> +#define ftello(x)      ftell(x)
> +#endif
>  #endif
>  
>  #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
> Index: output_example.c
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/output_example.c,v
> retrieving revision 1.20
> diff -u -p -u -r1.20 output_example.c
> --- output_example.c	6 Feb 2006 12:45:52 -0000	1.20
> +++ output_example.c	28 Mar 2006 18:02:39 -0000
> @@ -22,6 +22,8 @@
>   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>   * THE SOFTWARE.
>   */
> +#include "config.h"
> +
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <string.h>
> @@ -31,6 +33,22 @@
>  #define M_PI 3.1415926535897931
>  #endif
>  
> +#if defined(WIN32) || defined(__MINGW32__)
> +
> +#include <stdarg.h>
> +
> +int snprintf(char *buf, const char *fmt, size_t size, ...) {
> +  va_list ap;
> +  int ret;
> +
> +  va_start(ap, size);
> +  ret = vsprintf(buf, fmt, ap);
> +  va_end(ap);
> +  return ret;
> +}
> +
> +#endif

Potential security risk.  Rejected.

Someone had put a "fix" like this in some code at work.  A case turned
up recently where it overflowed the buffer, which wasn't "large
enough" after all, and it took quite some time to track down the
reason for bizarre behavior.

> Index: configure
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/configure,v
> retrieving revision 1.258
> diff -u -p -u -r1.258 configure
> --- configure	24 Mar 2006 01:17:22 -0000	1.258
> +++ configure	28 Mar 2006 18:02:31 -0000
> @@ -1217,9 +1237,10 @@ EOF
>  
>  sdl_too_old=no
>  sdl=no
> -if (sdl-config --version) >/dev/null 2>&1 ; then
> -if $cc -o $TMPE `sdl-config --cflags` $TMPC `sdl-config --libs`  > /dev/null 2>&1  ; then
> -_sdlversion=`sdl-config --version | sed 's/[^0-9]//g'`
> +SDL_CONFIG="${cross_prefix}sdl-config"
> +if ("${SDL_CONFIG}" --version) >/dev/null 2>&1 ; then
> +if $cc -o $TMPE `"${SDL_CONFIG}" --cflags` $TMPC `"${SDL_CONFIG}" --libs`  > /dev/null 2>&1  ; then
> +_sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'`
>  if test "$_sdlversion" -lt 121 ; then
>  sdl_too_old=yes
>  else
> @@ -1572,8 +1600,8 @@ if test "$pthreads" = "yes" ; then
>  fi
>  if test "$sdl" = "yes" ; then
>    echo "CONFIG_SDL=yes" >> config.mak
> -  echo "SDL_LIBS=`sdl-config --libs`" >> config.mak
> -  echo "SDL_CFLAGS=`sdl-config --cflags`" >> config.mak
> +  echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak
> +  echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak
>  fi
>  if test "$texi2html" = "yes"; then
>    echo "BUILD_DOC=yes" >> config.mak

This one looks sensible, assuming SDL is normally installed like that.

-- 
M?ns Rullg?rd
mru at inprovide.com





More information about the ffmpeg-devel mailing list