From 1e3475e369c7f3a794234c4c4da69e1df5264e49 Mon Sep 17 00:00:00 2001
From: Xander Victory <x@xandervictory.id.au>
Date: Sat, 12 May 2012 20:39:16 +0800
Subject: [PATCH] enable compilation on mingw32-w64 (64 bit mingw)

---
 mythtv/filters/greedyhdeint/mangle.h               |    2 +-
 mythtv/filters/linearblend/filter_linearblend.c    |    4 +-
 mythtv/filters/yadif/aclib_template.c              |   12 ++++----
 mythtv/filters/yadif/filter_yadif.c                |    4 +-
 mythtv/libs/libmyth/audio/audiooutputbase.cpp      |    4 ++
 mythtv/libs/libmyth/audio/audiooutpututil.cpp      |    8 ++--
 mythtv/libs/libmyth/audio/audiooutputwin.cpp       |    4 +-
 mythtv/libs/libmythbase/compat.h                   |    2 +-
 mythtv/libs/libmythbluray/file/filesystem.h        |    6 +++-
 mythtv/libs/libmythsoundtouch/FIFOSampleBuffer.cpp |    2 +-
 mythtv/libs/libmythsoundtouch/TDStretch.cpp        |    2 +-
 .../libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp  |    2 +-
 mythtv/libs/libmythsoundtouch/sse_gcc.cpp          |   31 +++++++++++++++----
 mythtv/libs/libmythtv/RTjpegN.cpp                  |    8 ++--
 mythtv/libs/libmythtv/nuppeldecoder.cpp            |    4 +-
 mythtv/libs/libmythtv/signalmonitor.cpp            |    2 +-
 .../programs/mythfrontend/audiogeneralsettings.cpp |    2 +-
 17 files changed, 62 insertions(+), 37 deletions(-)

diff --git a/mythtv/filters/greedyhdeint/mangle.h b/mythtv/filters/greedyhdeint/mangle.h
index a868245..8dd7ff5 100644
--- a/mythtv/filters/greedyhdeint/mangle.h
+++ b/mythtv/filters/greedyhdeint/mangle.h
@@ -9,7 +9,7 @@
 
 /* Feel free to add more to the list, eg. a.out IMO */
 /* Use rip-relative addressing if compiling PIC code on x86-64. */
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || \
+#if defined(__CYGWIN__) || defined(__MINGW32__) && !defined(_WIN64) || defined(__OS2__) || \
     CONFIG_DARWIN || (defined(__OpenBSD__) && !defined(__ELF__))
 #if ARCH_X86_64 && defined(PIC)
 #define MANGLE(a) "_" #a"(%%rip)"
diff --git a/mythtv/filters/linearblend/filter_linearblend.c b/mythtv/filters/linearblend/filter_linearblend.c
index dda046f..5317f66 100644
--- a/mythtv/filters/linearblend/filter_linearblend.c
+++ b/mythtv/filters/linearblend/filter_linearblend.c
@@ -82,7 +82,7 @@ void linearBlendMMX(unsigned char *src, int stride)
        PAVGB(%%mm1, %%mm2)                                   // 2L8 + L7 + L9
        "movq %%mm2, (%%"REG_d", %1, 2)                     \n\t"
 
-       : : "r" (src), "r" ((long)stride)
+       : : "r" (src), "r" ((intptr_t)stride)
        : "%"REG_a, "%"REG_d
     );
 }
@@ -129,7 +129,7 @@ void linearBlend3DNow(unsigned char *src, int stride)
        PAVGUSB(%%mm1, %%mm2)                                 // 2L8 + L7 + L9
        "movq %%mm2, (%%"REG_d", %1, 2)                     \n\t"
 
-       : : "r" (src), "r" ((long)stride)
+       : : "r" (src), "r" ((intptr_t)stride)
        : "%"REG_a, "%"REG_d
     );
 }
diff --git a/mythtv/filters/yadif/aclib_template.c b/mythtv/filters/yadif/aclib_template.c
index 436db6a..c80aedd 100644
--- a/mythtv/filters/yadif/aclib_template.c
+++ b/mythtv/filters/yadif/aclib_template.c
@@ -78,7 +78,7 @@ If you have questions please contact with me: Nick Kurshev: nickols_k@mail.ru.
 /* for small memory blocks (<256 bytes) this version is faster */
 #define small_memcpy(to,from,n)\
 {\
-register unsigned long int dummy;\
+register uintptr_t dummy;\
 __asm__ __volatile__(\
 	"rep; movsb"\
 	:"=&D"(to), "=&S"(from), "=&c"(dummy)\
@@ -165,9 +165,9 @@ void * RENAME(fast_memcpy)(void * to, const void * from, size_t len)
 #endif
         if (len >= MIN_LEN)
 	{
-	  register unsigned long int delta;
+	  register uintptr_t delta;
           /* Align destinition to MMREG_SIZE -boundary */
-          delta = ((unsigned long int)to)&(MMREG_SIZE-1);
+          delta = ((uintptr_t)to)&(MMREG_SIZE-1);
           if (delta)
 	  {
 	    delta=MMREG_SIZE-delta;
@@ -186,7 +186,7 @@ void * RENAME(fast_memcpy)(void * to, const void * from, size_t len)
            processor's decoders, but it's not always possible.
         */
 #ifdef HAVE_SSE /* Only P3 (may be Cyrix3) */
-	if (((unsigned long)from) & 15)
+	if (((uintptr_t)from) & 15)
 	/* if SRC is misaligned */
 	for (; i>0; i--)
 	{
@@ -231,7 +231,7 @@ void * RENAME(fast_memcpy)(void * to, const void * from, size_t len)
 	}
 #else
 	// Align destination at BLOCK_SIZE boundary
-	for (; ((long)to & (BLOCK_SIZE-1)) && i>0; i--)
+	for (; ((intptr_t)to & (BLOCK_SIZE-1)) && i>0; i--)
 	{
 		__asm__ __volatile__ (
 #ifndef HAVE_ONLY_MMX1
@@ -318,7 +318,7 @@ void * RENAME(fast_memcpy)(void * to, const void * from, size_t len)
 			" jae 1b		\n\t"
       MOVX" %6, %%"REG_b" \n\t"
 				: "+r" (from), "+r" (to), "+r" (i)
-				: "r" ((long)BLOCK_SIZE), "i" (BLOCK_SIZE/64), "i" ((long)CONFUSION_FACTOR), "m" (oldbx)
+				: "r" ((intptr_t)BLOCK_SIZE), "i" (BLOCK_SIZE/64), "i" ((intptr_t)CONFUSION_FACTOR), "m" (oldbx)
 				: "%"REG_a, "memory"
 		);
 
diff --git a/mythtv/filters/yadif/filter_yadif.c b/mythtv/filters/yadif/filter_yadif.c
index cd2c1e3..b2b8d58 100644
--- a/mythtv/filters/yadif/filter_yadif.c
+++ b/mythtv/filters/yadif/filter_yadif.c
@@ -352,8 +352,8 @@ static void filter_line_mmx2(struct ThisFilter *p, uint8_t *dst,
             :[prev] "r"(prev),\
              [cur]  "r"(cur),\
              [next] "r"(next),\
-             [prefs]"r"((long)refs),\
-             [mrefs]"r"((long)-refs),\
+             [prefs]"r"((intptr_t)refs),\
+             [mrefs]"r"((intptr_t)-refs),\
              [pw1]  "m"(pw_1),\
              [pb1]  "m"(pb_1),\
              [mode] "g"(mode)\
diff --git a/mythtv/libs/libmyth/audio/audiooutputbase.cpp b/mythtv/libs/libmyth/audio/audiooutputbase.cpp
index 4024221..79d3700 100644
--- a/mythtv/libs/libmyth/audio/audiooutputbase.cpp
+++ b/mythtv/libs/libmyth/audio/audiooutputbase.cpp
@@ -26,7 +26,11 @@
 #define RPOS audiobuffer + raud
 #define ABUF audiobuffer
 #define STST soundtouch::SAMPLETYPE
+#ifdef _WIN64
+#define AOALIGN(x) (((long long)&x + 15) & ~0xf);
+#else
 #define AOALIGN(x) (((long)&x + 15) & ~0xf);
+#endif
 
 // 1,2,5 and 7 channels are currently valid for upmixing if required
 #define UPMIX_CHANNEL_MASK ((1<<1)|(1<<2)|(1<<5)|1<<7)
diff --git a/mythtv/libs/libmyth/audio/audiooutpututil.cpp b/mythtv/libs/libmyth/audio/audiooutpututil.cpp
index 68e882b..2a69f8a 100644
--- a/mythtv/libs/libmyth/audio/audiooutpututil.cpp
+++ b/mythtv/libs/libmyth/audio/audiooutpututil.cpp
@@ -140,7 +140,7 @@ static int fromFloat8(uchar *out, float *in, int len)
     float f = (1<<7) - 1;
 
 #if ARCH_X86
-    if (sse_check() && len >= 16 && ((unsigned long)out & 0xf) == 0)
+    if (sse_check() && len >= 16 && ((uintptr_t)out & 0xf) == 0)
     {
         int loops = len >> 4;
         i = loops << 4;
@@ -245,7 +245,7 @@ static int fromFloat16(short *out, float *in, int len)
     float f = (1<<15) - 1;
 
 #if ARCH_X86
-    if (sse_check() && len >= 16 && ((unsigned long)out & 0xf) == 0)
+    if (sse_check() && len >= 16 && ((uintptr_t)out & 0xf) == 0)
     {
         int loops = len >> 4;
         i = loops << 4;
@@ -352,7 +352,7 @@ static int fromFloat32(AudioFormat format, int *out, float *in, int len)
         shift = 0;
 
 #if ARCH_X86
-    if (sse_check() && len >= 16 && ((unsigned long)out & 0xf) == 0)
+    if (sse_check() && len >= 16 && ((uintptr_t)out & 0xf) == 0)
     {
         float o = 1, mo = -1;
         int loops = len >> 4;
@@ -417,7 +417,7 @@ static int fromFloatFLT(float *out, float *in, int len)
     int i = 0;
 
 #if ARCH_X86
-    if (sse_check() && len >= 16 && ((unsigned long)in & 0xf) == 0)
+    if (sse_check() && len >= 16 && ((uintptr_t)in & 0xf) == 0)
     {
         int loops = len >> 4;
         float o = 1, mo = -1;
diff --git a/mythtv/libs/libmyth/audio/audiooutputwin.cpp b/mythtv/libs/libmyth/audio/audiooutputwin.cpp
index ff665dc..0b81e82 100644
--- a/mythtv/libs/libmyth/audio/audiooutputwin.cpp
+++ b/mythtv/libs/libmyth/audio/audiooutputwin.cpp
@@ -218,8 +218,8 @@ bool AudioOutputWin::OpenDevice(void)
 
     MMRESULT mmr = waveOutOpen(&m_priv->m_hWaveOut, WAVE_MAPPER,
                                (WAVEFORMATEX *)&wf,
-                               (DWORD)AudioOutputWinPrivate::waveOutProc,
-                               (DWORD)this, CALLBACK_FUNCTION);
+                               (DWORD_PTR)AudioOutputWinPrivate::waveOutProc,
+                               (DWORD_PTR)this, CALLBACK_FUNCTION);
 
     if (mmr == WAVERR_BADFORMAT)
     {
diff --git a/mythtv/libs/libmythbase/compat.h b/mythtv/libs/libmythbase/compat.h
index 425624a..6e97f73 100644
--- a/mythtv/libs/libmythbase/compat.h
+++ b/mythtv/libs/libmythbase/compat.h
@@ -202,7 +202,7 @@ inline int statfs(const char* path, struct statfs* buffer)
 
 #ifdef USING_MINGW
 #define mkfifo(path, mode) \
-    (int)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
+    (intptr_t)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
                           PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \
                           1024, 1024, 10000, NULL)
 #endif // USING_MINGW
diff --git a/mythtv/libs/libmythbluray/file/filesystem.h b/mythtv/libs/libmythbluray/file/filesystem.h
index c173f4c..b9c5ce8 100644
--- a/mythtv/libs/libmythbluray/file/filesystem.h
+++ b/mythtv/libs/libmythbluray/file/filesystem.h
@@ -40,7 +40,11 @@ struct bd_file_s
     int64_t (*seek)(BD_FILE_H *file, int64_t offset, int32_t origin);
     int64_t (*tell)(BD_FILE_H *file);
     int (*eof)(BD_FILE_H *file);
-    int (*stat)(BD_FILE_H *file, struct stat *buf);
+    #ifdef _WIN64
+        int (*_stat64)(BD_FILE_H *file, struct stat *buf);//not sure if this is just my mingw32-w64 install or not
+    #else
+        int (*stat)(BD_FILE_H *file, struct stat *buf);
+    #endif
     int64_t (*read)(BD_FILE_H *file, uint8_t *buf, int64_t size);
     int64_t (*write)(BD_FILE_H *file, const uint8_t *buf, int64_t size);
 };
diff --git a/mythtv/libs/libmythsoundtouch/FIFOSampleBuffer.cpp b/mythtv/libs/libmythsoundtouch/FIFOSampleBuffer.cpp
index f88b4f6..ad4573a 100644
--- a/mythtv/libs/libmythsoundtouch/FIFOSampleBuffer.cpp
+++ b/mythtv/libs/libmythsoundtouch/FIFOSampleBuffer.cpp
@@ -171,7 +171,7 @@ void FIFOSampleBuffer::ensureCapacity(uint capacityRequirement)
         {
             throw std::runtime_error("Couldn't allocate memory!\n");
         }
-        temp = (SAMPLETYPE *)(((ulong)tempUnaligned + 15) & -16);
+        temp = (SAMPLETYPE *)(((intptr_t)tempUnaligned + 15) & -16);
         memcpy(temp, ptrBegin(), samplesInBuffer * channels * sizeof(SAMPLETYPE));
         delete[] bufferUnaligned;
         buffer = temp;
diff --git a/mythtv/libs/libmythsoundtouch/TDStretch.cpp b/mythtv/libs/libmythsoundtouch/TDStretch.cpp
index d00b057..9b55468 100644
--- a/mythtv/libs/libmythsoundtouch/TDStretch.cpp
+++ b/mythtv/libs/libmythsoundtouch/TDStretch.cpp
@@ -781,7 +781,7 @@ void TDStretch::acceptNewOverlapLength(uint newOverlapLength)
 
         pRefMidBufferUnaligned = new SAMPLETYPE[midBufferLength + 16 / sizeof(SAMPLETYPE)];
         // ensure that 'pRefMidBuffer' is aligned to 16 byte boundary for efficiency
-        pRefMidBuffer = (SAMPLETYPE *)((((ulong)pRefMidBufferUnaligned) + 15) & -16);
+        pRefMidBuffer = (SAMPLETYPE *)((((intptr_t)pRefMidBufferUnaligned) + 15) & -16);
     }
 }
 
diff --git a/mythtv/libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp b/mythtv/libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp
index ac5c284..de82b17 100644
--- a/mythtv/libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp
+++ b/mythtv/libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp
@@ -95,7 +95,7 @@ static int mm_support(void)
     int rval = 0;
     int eax, ebx, ecx, edx;
     int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
-    long a, c;
+    intptr_t a, c;
 
     __asm__ __volatile__ (
                           /* See if CPUID instruction is supported ... */
diff --git a/mythtv/libs/libmythsoundtouch/sse_gcc.cpp b/mythtv/libs/libmythsoundtouch/sse_gcc.cpp
index acbbcd9..2c8ff53 100644
--- a/mythtv/libs/libmythsoundtouch/sse_gcc.cpp
+++ b/mythtv/libs/libmythsoundtouch/sse_gcc.cpp
@@ -11,7 +11,11 @@ double TDStretchSSE3::calcCrossCorrMulti(const float *mPos, const float *cPos) c
 {
     double corr = 0;
     int count = overlapLength * channels;
-    int loops = count >> 4;
+    #ifdef _WIN64
+        intptr_t loops = count >> 4;
+    #else 
+        int loops = count >> 4;
+    #endif
     int i = loops << 4;
     const float *mp = mPos;
     const float *cp = cPos;
@@ -53,7 +57,11 @@ double TDStretchSSE2::calcCrossCorrMulti(const float *mPos, const float *cPos) c
 {
     double corr = 0;
     int count = overlapLength * channels;
-    int loops = count >> 4;
+    #ifdef _WIN64
+        intptr_t loops = count >> 4;
+    #else 
+        int loops = count >> 4;
+    #endif
     int i = loops << 4;
     const float *mp = mPos;
     const float *cp = cPos;
@@ -99,8 +107,13 @@ double TDStretchSSE3::calcCrossCorrStereo(const float *mPos, const float *cPos)
 {
     double corr = 0;
     int count = overlapLength <<1;
-    int loops = count >> 4;
+    #ifdef _WIN64
+        intptr_t loops = count >> 4;
+    #else 
+        int loops = count >> 4;
+    #endif
     int i = loops << 4;
+    
     const float *mp = mPos;
     const float *cp = cPos;
 
@@ -141,7 +154,11 @@ double TDStretchSSE2::calcCrossCorrStereo(const float *mPos, const float *cPos)
 {
     double corr = 0;
     int count = overlapLength <<1;
-    int loops = count >> 4;
+    #ifdef _WIN64
+        intptr_t loops = count >> 4;
+    #else 
+        int loops = count >> 4;
+    #endif
     int i = loops << 4;
     const float *mp = mPos;
     const float *cp = cPos;
@@ -220,7 +237,7 @@ void TDStretchSSE2::overlapMulti(float *output, const float *input) const
             "sub        $1,     %%ecx       \n\t"
             "jnz        1b                  \n\t"
             :
-            :"c"(overlapLength),"r"(i),"r"(m),"r"(o),"r"((long)channels)
+            :"c"(overlapLength),"r"(i),"r"(m),"r"(o),"r"((intptr_t)channels)
         );
     else
         __asm__ volatile (
@@ -258,7 +275,7 @@ void TDStretchSSE2::overlapMulti(float *output, const float *input) const
             "sub        $1,     %%ecx       \n\t"
             "jnz        1b                  \n\t"
             :
-            :"c"(overlapLength),"r"(i),"r"(m),"r"(o),"r"((long)channels)
+            :"c"(overlapLength),"r"(i),"r"(m),"r"(o),"r"((intptr_t)channels)
         );
 }
 
@@ -325,7 +342,7 @@ void FIRFilterSSE2::setCoefficients(const float *coeffs, uint newLen, uint uRDF)
     // Ensure that filter coeffs array is aligned to 16-byte boundary
     delete[] filterCoeffsUnalign;
     filterCoeffsUnalign = new float[2 * newLen + 16];
-    filterCoeffsAlign = (float *)(((ulong)filterCoeffsUnalign + 15) & -16);
+    filterCoeffsAlign = (float *)(((uintptr_t)filterCoeffsUnalign + 15) & -16);
 
     float fdiv = (float)resultDivider;
 
diff --git a/mythtv/libs/libmythtv/RTjpegN.cpp b/mythtv/libs/libmythtv/RTjpegN.cpp
index 1a3d61c..df6afab 100644
--- a/mythtv/libs/libmythtv/RTjpegN.cpp
+++ b/mythtv/libs/libmythtv/RTjpegN.cpp
@@ -2727,12 +2727,12 @@ int RTjpeg::SetSize(int *w, int *h)
 
     if (key_rate > 0)
     {
-        unsigned long tmp;
+        uintptr_t tmp;
         if (old)
             delete [] old_start;
         old_start = new int16_t[((4*width*height)+32)];
 
-        tmp = (unsigned long)old_start;
+        tmp = (uintptr_t)old_start;
         tmp += 32;
         tmp = tmp>>5;
 
@@ -2749,7 +2749,7 @@ int RTjpeg::SetSize(int *w, int *h)
 
 int RTjpeg::SetIntra(int *key, int *lm, int *cm)
 {
-    unsigned long tmp;
+    uintptr_t tmp;
 
     if (*key < 0)
         *key = 0;
@@ -2777,7 +2777,7 @@ int RTjpeg::SetIntra(int *key, int *lm, int *cm)
     if (old)
         delete [] old_start;
     old_start = new int16_t[((4*width*height)+32)];
-    tmp = (unsigned long)old_start;
+    tmp = (uintptr_t)old_start;
     tmp += 32;
     tmp = tmp >> 5;
     old = (int16_t *)(tmp << 5);
diff --git a/mythtv/libs/libmythtv/nuppeldecoder.cpp b/mythtv/libs/libmythtv/nuppeldecoder.cpp
index 33d8061..8aef8a1 100644
--- a/mythtv/libs/libmythtv/nuppeldecoder.cpp
+++ b/mythtv/libs/libmythtv/nuppeldecoder.cpp
@@ -56,7 +56,7 @@ NuppelDecoder::NuppelDecoder(MythPlayer *parent,
     memset(&extradata, 0, sizeof(extendeddata));
     memset(&tmppicture, 0, sizeof(AVPicture));
     planes[0] = planes[1] = planes[2] = 0;
-    audioSamples = (short int*) (((long)audioSamples_buf + 15) & ~0xf);
+    audioSamples = (short int*) (((intptr_t)audioSamples_buf + 15) & ~0xf);
     memset(audioSamples, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof(short int));
 
     // set parent class variables
@@ -615,7 +615,7 @@ int NuppelDecoder::OpenFile(RingBuffer *rbuffer, bool novideo,
 
     buf = new unsigned char[video_size];
     strm_buf = new unsigned char[video_size * 2 + 16];
-    strm = (unsigned char*) (((long)strm_buf + 15) & ~0xf);
+    strm = (unsigned char*) (((intptr_t)strm_buf + 15) & ~0xf);
 
     if (hasFullPositionMap)
         return 1;
diff --git a/mythtv/libs/libmythtv/signalmonitor.cpp b/mythtv/libs/libmythtv/signalmonitor.cpp
index 9bfc339..29a8c4d 100644
--- a/mythtv/libs/libmythtv/signalmonitor.cpp
+++ b/mythtv/libs/libmythtv/signalmonitor.cpp
@@ -167,7 +167,7 @@ SignalMonitor *SignalMonitor::Init(QString cardtype, int db_cardnum,
     {
         LOG(VB_GENERAL, LOG_ERR,
             QString("Failed to create signal monitor in Init(%1, %2, 0x%3)")
-                .arg(cardtype).arg(db_cardnum).arg((long)channel,0,16));
+                .arg(cardtype).arg(db_cardnum).arg((intptr_t)channel,0,16));
     }
 
     return signalMonitor;
diff --git a/mythtv/programs/mythfrontend/audiogeneralsettings.cpp b/mythtv/programs/mythfrontend/audiogeneralsettings.cpp
index 7d40e09..c2d58a2 100644
--- a/mythtv/programs/mythfrontend/audiogeneralsettings.cpp
+++ b/mythtv/programs/mythfrontend/audiogeneralsettings.cpp
@@ -621,7 +621,7 @@ void AudioTestThread::run()
     if (m_audioOutput)
     {
         char *frames_in = new char[m_channels * 1024 * sizeof(int32_t) + 15];
-        char *frames = (char *)(((long)frames_in + 15) & ~0xf);
+        char *frames = (char *)(((intptr_t)frames_in + 15) & ~0xf);
 
         m_audioOutput->Pause(false);
 
-- 
1.7.3.4

