[MPlayer-dev-eng] [PATCH] platform independent formats / loader patch

Dominik 'Rathann' Mierzejewski dominik at rangers.eu.org
Tue Apr 6 14:59:03 CEST 2004


First, a few quotes from A'rpi (yes, you're not mistaken, this is from
December 2002):

Date: Tue, 10 Dec 2002 13:42:24 +0100
From: Arpi <arpi at x>
Subject: Re: [MPlayer-dev-eng] [PATCH] Yet another batch of warning fixes :->
[...]
i mean in avifile sources, the structs (BITMAPINFOHEADER etc) are defined
twice. once in its include/ (used on all platforms) and once in
plugins/libwin32/loader/wine/* used only for x86. So, for avifile the 'long'
is ok, as they use the wine headers on x86 only.

but in mplayer, the windef.h is included in stheader.h which is used in all
platforms, including 64bit ones.  the long was changed to int by a patch for
Alpha support long time ago.
[...]

Date: Sun, 29 Dec 2002 21:58:38 +0100
From: Arpi <arpi at x>
Subject: Re: [MPlayer-dev-eng] [PATCH] loader - platform independent structures
[...]
i said that i'll add the structs (used on non-x86 systems too) to
stheader.h, so the wine/*.h files won't be used on non-x86 at all
(used only by the loader and the DLL interface (vd_vfw, _dshow etc) only)

i'm still against changing stuff under loader/ or any only-imported (not
developed in mplayer cvs) libs.
[...]

And now, the patch.

I created two additional files (basically, copy&paste and replacing DWORD
etc with uintXX_t) in libmpdemux/ - avifmt.h and formats.h which get
included on non-x86 platforms instead of the headers from
loader/wine/{mmreg,avifmt,vfw}.h. I also moved WAVEFORMATEX and
BITMAPINFOHEADER definitions from stheader.h to formats.h. Finally, I
re-synced the definitions of DWORD, ULONG (in windef.h) and
BITMAPINFOHEADER (in vfw.h) with latest loader sources from
avifile-0.7.38. 

So far I've been able to verify that it doesn't break anything (compilation,
vfw dll decoding) on x86. Sascha said it compiles for him on win32.
I also verified it compiles on Alpha yesterday.

Note: this is an RFC, it's not meant to be applied as-is. 

Regards,
R.

-- 
MPlayer RPMs maintainer: http://greysector.rangers.eu.org/mplayer.html
"The Universe doesn't give you any points for doing things that are easy."
        -- Sheridan to Garibaldi in Babylon 5:"The Geometry of Shadows"
-------------- next part --------------
--- MPlayer-20040403/libmpcodecs/ad_ffmpeg.c.loader	Tue Mar 16 20:49:42 2004
+++ MPlayer-20040403/libmpcodecs/ad_ffmpeg.c	Mon Apr  5 02:03:27 2004
@@ -143,7 +143,7 @@
 	int len2=0;
 	int x=ds_get_packet(sh_audio->ds,&start);
 	if(x<=0) break; // error
-	y=avcodec_decode_audio(sh_audio->context,(INT16*)buf,&len2,start,x);
+	y=avcodec_decode_audio(sh_audio->context,(int16_t*)buf,&len2,start,x);
 //printf("return:%d samples_out:%d bitstream_in:%d sample_sum:%d\n", y, len2, x, len); fflush(stdout);
 	if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; }
 	if(y<x) sh_audio->ds->buffer_pos+=y-x;  // put back data (HACK!)
--- MPlayer-20040403/libmpdemux/stheader.h.loader	Thu Jan 16 23:34:46 2003
+++ MPlayer-20040403/libmpdemux/stheader.h	Mon Apr  5 01:46:19 2004
@@ -2,41 +2,13 @@
 #define __ST_HEADER_H 1
 
 // for AVIStreamHeader:
+#ifdef ARCH_X86
+#include "wine/mmreg.h"
 #include "wine/avifmt.h"
-
-#ifndef _WAVEFORMATEX_
-#define _WAVEFORMATEX_
-typedef struct __attribute__((__packed__)) _WAVEFORMATEX {
-  WORD   wFormatTag;
-  WORD   nChannels;
-  DWORD  nSamplesPerSec;
-  DWORD  nAvgBytesPerSec;
-  WORD   nBlockAlign;
-  WORD   wBitsPerSample;
-  WORD   cbSize;
-} WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
-#endif /* _WAVEFORMATEX_ */
-
-#ifndef _BITMAPINFOHEADER_
-#define _BITMAPINFOHEADER_
-typedef struct __attribute__((__packed__))
-{
-    int 	biSize;
-    int  	biWidth;
-    int  	biHeight;
-    short 	biPlanes;
-    short 	biBitCount;
-    int 	biCompression;
-    int 	biSizeImage;
-    int  	biXPelsPerMeter;
-    int  	biYPelsPerMeter;
-    int 	biClrUsed;
-    int 	biClrImportant;
-} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
-typedef struct {
-	BITMAPINFOHEADER bmiHeader;
-	int	bmiColors[1];
-} BITMAPINFO, *LPBITMAPINFO;
+#include "wine/vfw.h"
+#else
+#include "avifmt.h"
+#include "formats.h"
 #endif
 
 // Stream headers:
--- MPlayer-20040403/libmpdemux/avifmt.h.loader	Mon Apr  5 01:46:19 2004
+++ MPlayer-20040403/libmpdemux/avifmt.h	Mon Apr  5 01:46:19 2004
@@ -0,0 +1,114 @@
+#ifndef AVIFMT_H
+#define AVIFMT_H
+
+#include <inttypes.h>
+
+#ifndef mmioFOURCC
+#define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
+	( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
+	( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
+#endif
+
+typedef struct {
+    int16_t  left;
+    int16_t  top;
+    int16_t  right;
+    int16_t  bottom;
+} RECT;
+
+/* form types, list types, and chunk types */
+#define formtypeAVI             mmioFOURCC('A', 'V', 'I', ' ')
+#define listtypeAVIHEADER       mmioFOURCC('h', 'd', 'r', 'l')
+#define ckidAVIMAINHDR          mmioFOURCC('a', 'v', 'i', 'h')
+#define listtypeSTREAMHEADER    mmioFOURCC('s', 't', 'r', 'l')
+#define ckidSTREAMHEADER        mmioFOURCC('s', 't', 'r', 'h')
+#define ckidSTREAMFORMAT        mmioFOURCC('s', 't', 'r', 'f')
+#define ckidSTREAMHANDLERDATA   mmioFOURCC('s', 't', 'r', 'd')
+#define ckidSTREAMNAME          mmioFOURCC('s', 't', 'r', 'n')
+
+#define listtypeAVIMOVIE        mmioFOURCC('m', 'o', 'v', 'i')
+#define listtypeAVIRECORD       mmioFOURCC('r', 'e', 'c', ' ')
+
+#define ckidAVINEWINDEX         mmioFOURCC('i', 'd', 'x', '1')
+
+/*
+** Stream types for the <fccType> field of the stream header.
+*/
+#define streamtypeVIDEO         mmioFOURCC('v', 'i', 'd', 's')
+#define streamtypeAUDIO         mmioFOURCC('a', 'u', 'd', 's')
+#define streamtypeMIDI          mmioFOURCC('m', 'i', 'd', 's')
+#define streamtypeTEXT          mmioFOURCC('t', 'x', 't', 's')
+
+/* Chunk id to use for extra chunks for padding. */
+#define ckidAVIPADDING          mmioFOURCC('J', 'U', 'N', 'K')
+
+/*
+** Main AVI File Header
+*/
+
+/* flags for use in <dwFlags> in AVIFileHdr */
+#define AVIF_HASINDEX           0x00000010      // Index at end of file?
+#define AVIF_MUSTUSEINDEX       0x00000020
+#define AVIF_ISINTERLEAVED      0x00000100
+#define AVIF_TRUSTCKTYPE        0x00000800      // Use CKType to find key frames?
+#define AVIF_WASCAPTUREFILE     0x00010000
+#define AVIF_COPYRIGHTED        0x00020000
+
+typedef struct
+{
+    uint32_t		dwMicroSecPerFrame;	// frame display rate (or 0L) 
+    uint32_t		dwMaxBytesPerSec;	// max. transfer rate 
+    uint32_t		dwPaddingGranularity;	// pad to multiples of this 
+						// size; normally 2K.
+    uint32_t		dwFlags;		// the ever-present flags
+    uint32_t		dwTotalFrames;		// # frames in file
+    uint32_t		dwInitialFrames;
+    uint32_t		dwStreams;
+    uint32_t		dwSuggestedBufferSize;
+
+    uint32_t		dwWidth;
+    uint32_t		dwHeight;
+
+    uint32_t		dwReserved[4];
+} MainAVIHeader;
+
+/*
+** Stream header
+*/
+
+typedef struct {
+    uint32_t		fccType;
+    uint32_t		fccHandler;
+    uint32_t		dwFlags;	/* Contains AVITF_* flags */
+    uint16_t		wPriority;
+    uint16_t		wLanguage;
+    uint32_t		dwInitialFrames;
+    uint32_t		dwScale;	
+    uint32_t		dwRate;	/* dwRate / dwScale == samples/second */
+    uint32_t		dwStart;
+    uint32_t		dwLength; /* In units above... */
+    uint32_t		dwSuggestedBufferSize;
+    int32_t		dwQuality;
+    uint32_t		dwSampleSize;
+    RECT		rcFrame;
+} AVIStreamHeader;
+
+/* Flags for index */
+#define AVIIF_LIST          0x00000001L // chunk is a 'LIST'
+#define AVIIF_KEYFRAME      0x00000010L // this frame is a key frame.
+
+#define AVIIF_NOTIME        0x00000100L // this frame doesn't take any time
+#define AVIIF_COMPUSE       0x0FFF0000L // these bits are for compressor use
+
+#define FOURCC_RIFF     mmioFOURCC('R', 'I', 'F', 'F')
+#define FOURCC_LIST     mmioFOURCC('L', 'I', 'S', 'T')
+
+typedef struct
+{
+    uint32_t		ckid;
+    uint32_t		dwFlags;
+    uint32_t		dwChunkOffset;		// Position of chunk
+    uint32_t		dwChunkLength;		// Length of chunk
+} AVIINDEXENTRY;
+
+#endif
--- MPlayer-20040403/libmpdemux/aviheader.c.loader	Mon Apr  5 01:46:19 2004
+++ MPlayer-20040403/libmpdemux/aviheader.c	Mon Apr  5 01:46:19 2004
@@ -223,7 +223,7 @@
       if(verbose>=1) print_strh(&h);
       break; }
     case mmioFOURCC('i', 'n', 'd', 'x'): {
-      DWORD i;
+      uint32_t i;
       unsigned msize = 0;
       avisuperindex_chunk *s;
       priv->suidx_size++;
--- MPlayer-20040403/libmpdemux/aviprint.c.loader	Thu Apr  1 20:47:26 2004
+++ MPlayer-20040403/libmpdemux/aviprint.c	Mon Apr  5 01:46:19 2004
@@ -9,9 +9,14 @@
 #include "stream.h"
 #include "demuxer.h"
 
+#ifdef ARCH_X86
 #include "wine/mmreg.h"
 #include "wine/avifmt.h"
 #include "wine/vfw.h"
+#else
+#include "formats.h"
+#include "avifmt.h"
+#endif
 
 #include "aviheader.h"
 
--- MPlayer-20040403/libmpdemux/muxer.c.loader	Tue Mar 16 20:49:42 2004
+++ MPlayer-20040403/libmpdemux/muxer.c	Mon Apr  5 01:54:59 2004
@@ -8,9 +8,14 @@
 #include "config.h"
 #include "../version.h"
 
+#ifdef ARCH_X86
 #include "wine/mmreg.h"
 #include "wine/avifmt.h"
 #include "wine/vfw.h"
+#else
+#include "avifmt.h"
+#include "formats.h"
+#endif
 
 #include "muxer.h"
 
--- MPlayer-20040403/libmpdemux/muxer_mpeg.c.loader	Sun Oct 26 12:49:03 2003
+++ MPlayer-20040403/libmpdemux/muxer_mpeg.c	Mon Apr  5 01:55:24 2004
@@ -8,9 +8,14 @@
 #include "../version.h"
 #include "../mp_msg.h"
 
+#ifdef ARCH_X86
 #include "wine/mmreg.h"
 #include "wine/avifmt.h"
 #include "wine/vfw.h"
+#else
+#include "avifmt.h"
+#include "formats.h"
+#endif
 #include "bswap.h"
 
 #include "muxer.h"
--- MPlayer-20040403/libmpdemux/muxer_rawvideo.c.loader	Tue Mar  9 15:46:34 2004
+++ MPlayer-20040403/libmpdemux/muxer_rawvideo.c	Mon Apr  5 01:56:32 2004
@@ -12,9 +12,14 @@
 //#include "demuxer.h"
 //#include "stheader.h"
 
+#ifdef ARCH_X86
 #include "wine/mmreg.h"
 #include "wine/avifmt.h"
 #include "wine/vfw.h"
+#else
+#include "avifmt.h"
+#include "formats.h"
+#endif
 #include "bswap.h"
 
 #include "muxer.h"
--- MPlayer-20040403/libmpdemux/formats.h.loader	Mon Apr  5 01:46:19 2004
+++ MPlayer-20040403/libmpdemux/formats.h	Mon Apr  5 01:46:19 2004
@@ -0,0 +1,60 @@
+#ifndef FORMATS_H
+#define FORMATS_H
+
+#include <inttypes.h>
+
+#ifndef _MPEGLAYER3WAVEFORMAT_
+#define _MPEGLAYER3WAVEFORMAT_
+typedef struct __attribute__((__packed__))
+{
+  uint16_t	wFormatTag;
+  uint16_t	nChannels;
+  uint32_t	nSamplesPerSec;
+  uint32_t	nAvgBytesPerSec;
+  uint16_t	nBlockAlign;
+  uint16_t	wBitsPerSample;
+  uint16_t	cbSize;
+  uint16_t	wID;
+  uint32_t	fdwFlags;
+  uint16_t	nBlockSize;
+  uint16_t	nFramesPerBlock;
+  uint16_t	nCodecDelay;
+} MPEGLAYER3WAVEFORMAT;
+#endif /* _MPEGLAYER3WAVEFORMAT_ */
+
+#ifndef _WAVEFORMATEX_
+#define _WAVEFORMATEX_
+typedef struct __attribute__((__packed__)) _WAVEFORMATEX {
+  uint16_t	wFormatTag;
+  uint16_t	nChannels;
+  uint32_t	nSamplesPerSec;
+  uint32_t	nAvgBytesPerSec;
+  uint16_t	nBlockAlign;
+  uint16_t	wBitsPerSample;
+  uint16_t	cbSize;
+} WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
+#endif /* _WAVEFORMATEX_ */
+
+#ifndef _BITMAPINFOHEADER_
+#define _BITMAPINFOHEADER_
+typedef struct __attribute__((__packed__))
+{
+    uint32_t    biSize;
+    uint32_t    biWidth;
+    int32_t     biHeight;
+    uint16_t    biPlanes;
+    uint16_t    biBitCount;
+    uint32_t    biCompression;
+    uint32_t    biSizeImage;
+    uint32_t    biXPelsPerMeter;
+    uint32_t    biYPelsPerMeter;
+    uint32_t    biClrUsed;
+    uint32_t    biClrImportant;
+} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
+typedef struct {
+        BITMAPINFOHEADER bmiHeader;
+        uint32_t        bmiColors[1];
+} BITMAPINFO, *LPBITMAPINFO;
+#endif
+
+#endif
--- MPlayer-20040403/libmpdemux/demux_asf.c.loader	Sat Sep 13 23:54:15 2003
+++ MPlayer-20040403/libmpdemux/demux_asf.c	Mon Apr  5 01:46:19 2004
@@ -11,7 +11,12 @@
 #include "stream.h"
 #include "asf.h"
 #include "demuxer.h"
-
+#ifdef ARCH_X86
+#include "wine/mmreg.h"
+#include "wine/vfw.h"
+#else
+#include "formats.h"
+#endif
 
 /*
  * Load 16/32-bit values in little endian byte order
--- MPlayer-20040403/libmpdemux/muxer_avi.c.loader	Mon Apr  5 01:46:19 2004
+++ MPlayer-20040403/libmpdemux/muxer_avi.c	Mon Apr  5 01:46:19 2004
@@ -12,9 +12,6 @@
 #include "demuxer.h"
 #include "stheader.h"
 
-#include "wine/mmreg.h"
-#include "wine/avifmt.h"
-#include "wine/vfw.h"
 #include "bswap.h"
 
 #include "muxer.h"
--- MPlayer-20040403/loader/wine/windef.h.loader	Thu Apr 24 20:48:30 2003
+++ MPlayer-20040403/loader/wine/windef.h	Mon Apr  5 01:46:19 2004
@@ -156,8 +156,8 @@
 typedef int             INT;
 typedef unsigned int    UINT;
 typedef unsigned short  WORD;
-typedef unsigned int    DWORD;
-typedef unsigned int    ULONG;
+typedef unsigned long   DWORD;
+typedef unsigned long   ULONG;
 typedef unsigned char   BYTE;
 typedef long            LONG;
 typedef short           SHORT;
--- MPlayer-20040403/loader/wine/vfw.h.loader	Wed Oct  9 15:16:27 2002
+++ MPlayer-20040403/loader/wine/vfw.h	Mon Apr  5 01:46:19 2004
@@ -19,17 +19,17 @@
 #define _BITMAPINFOHEADER_
 typedef struct __attribute__((__packed__))
 {
-    int 	biSize;
-    int  	biWidth;
-    int  	biHeight;
+    long 	biSize;
+    long  	biWidth;
+    long  	biHeight;
     short 	biPlanes;
     short 	biBitCount;
-    int 	biCompression;
-    int 	biSizeImage;
-    int  	biXPelsPerMeter;
-    int  	biYPelsPerMeter;
-    int 	biClrUsed;
-    int 	biClrImportant;
+    long 	biCompression;
+    long 	biSizeImage;
+    long  	biXPelsPerMeter;
+    long  	biYPelsPerMeter;
+    long 	biClrUsed;
+    long 	biClrImportant;
 } BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
 typedef struct {
 	BITMAPINFOHEADER bmiHeader;
--- MPlayer-20040403/mencoder.c.loader	Sat Apr  3 16:54:29 2004
+++ MPlayer-20040403/mencoder.c	Mon Apr  5 01:46:19 2004
@@ -55,7 +55,11 @@
 #include "libmpcodecs/vf.h"
 
 // for MPEGLAYER3WAVEFORMAT:
+#ifdef ARCH_X86
 #include "loader/wine/mmreg.h"
+#else
+#include "libmpdemux/avifmt.h"
+#endif
 
 #ifdef HAVE_MP3LAME
 #undef CDECL
--- MPlayer-20040403/codec-cfg.c.loader	Sun Jan 25 21:38:34 2004
+++ MPlayer-20040403/codec-cfg.c	Mon Apr  5 01:46:19 2004
@@ -27,7 +27,7 @@
 #include "mp_msg.h"
 
 // for mmioFOURCC:
-#include "wine/avifmt.h"
+#include "libmpdemux/avifmt.h"
 
 #include "libvo/img_format.h"
 #include "codec-cfg.h"


More information about the MPlayer-dev-eng mailing list