]> git.sesse.net Git - vlc/blobdiff - modules/codec/dmo/dmo.c
Use _WIN32 rather than WIN32 (same for WIN64)
[vlc] / modules / codec / dmo / dmo.c
index dcc2b5fb00189d49689e32f1a4b14e506d51a5d0..6595f70acb2a76809e54851c1d0a2f27dffdc3bf 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * dmo.c : DirectMedia Object decoder module for vlc
  *****************************************************************************
- * Copyright (C) 2002, 2003 the VideoLAN team
+ * Copyright (C) 2002, 2003 VLC authors and VideoLAN
  * $Id$
  *
  * Author: Gildas Bazin <gbazin@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program 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.
  *
  * This program 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 General Public License for more details.
+ * 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 General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #include <vlc_codec.h>
 #include <vlc_codecs.h>
 
-#ifndef WIN32
-#    define LOADER
-#else
+#ifdef _WIN32
 #   include <objbase.h>
 #   include <vlc_charset.h>
 #endif
 
-#ifdef LOADER
-/* Need the w32dll loader from mplayer */
-#   include <wine/winerror.h>
-#   include <ldt_keeper.h>
-#   include <wine/windef.h>
-#endif
-
 #include <vlc_codecs.h>
 #include "dmo.h"
 
-//#define DMO_DEBUG 1
-
-#ifdef LOADER
-/* Not Needed */
-long CoInitialize( void *pvReserved ) { VLC_UNUSED(pvReserved); return -1; }
-void CoUninitialize( void ) { }
-
-/* A few prototypes */
-HMODULE WINAPI LoadLibraryA(LPCSTR);
-#define LoadLibrary LoadLibraryA
-FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
-int     WINAPI FreeLibrary(HMODULE);
-#endif /* LOADER */
+#ifndef NDEBUG
+# define DMO_DEBUG 1
+#endif
 
 typedef long (STDCALL *GETCLASS) ( const GUID*, const GUID*, void** );
 
@@ -132,10 +113,6 @@ struct decoder_sys_t
 
     date_t end_date;
 
-#ifdef LOADER
-    ldt_fs_t    *ldt_fs;
-#endif
-
     vlc_thread_t thread;
     vlc_mutex_t  lock;
     vlc_cond_t   wait_input, wait_output;
@@ -152,6 +129,7 @@ const GUID IID_IMediaBuffer = {0x59eff8b9, 0x938c, 0x4a26, {0x82, 0xf2, 0x95, 0x
 const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
 const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
 const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+const GUID MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
 const GUID FORMAT_VideoInfo = {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
 const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
 const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
@@ -175,6 +153,10 @@ static const GUID guid_wmv_enc = { 0x3181343b, 0x94a2, 0x4feb, { 0xad, 0xef, 0x3
 static const GUID guid_wmv_enc2 = { 0x96b57cdd, 0x8966, 0x410c,{ 0xbb, 0x1f, 0xc9, 0x7e, 0xea, 0x76, 0x5c, 0x04 } };
 static const GUID guid_wma_enc = { 0x70f598e9, 0xf4ab, 0x495a, { 0x99, 0xe2, 0xa7, 0xc4, 0xd3, 0xd8, 0x9a, 0xbf } };
 
+#ifndef BI_RGB
+# define BI_RGB 0x0
+#endif
+
 typedef struct
 {
     vlc_fourcc_t i_fourcc;
@@ -194,10 +176,10 @@ static const codec_dll decoders_table[] =
     /* WMV1 */
     { VLC_CODEC_WMV1,   "wmvdmod.dll", &guid_wmv },
     /* Screen codecs */
-    { VLC_FOURCC('M','S','S','2'), "wmsdmod.dll", &guid_wms },
-    { VLC_FOURCC('m','s','s','2'), "wmsdmod.dll", &guid_wms },
-    { VLC_FOURCC('M','S','S','1'), "wmsdmod.dll", &guid_wms },
-    { VLC_FOURCC('m','s','s','1'), "wmsdmod.dll", &guid_wms },
+    { VLC_CODEC_MSS2,   "WMVSDECD.DLL", &guid_wms },
+    { VLC_CODEC_MSS2,   "wmsdmod.dll",  &guid_wms },
+    { VLC_CODEC_MSS1,   "WMVSDECD.DLL", &guid_wms },
+    { VLC_CODEC_MSS1,   "wmsdmod.dll",  &guid_wms },
     /* Windows Media Video Adv */
     { VLC_CODEC_WMVA,   "wmvadvd.dll", &guid_wmva },
 
@@ -368,12 +350,8 @@ static int DecOpen( decoder_t *p_dec )
     VIDEOINFOHEADER *p_vih = NULL;
     WAVEFORMATEX *p_wf = NULL;
 
-#ifdef LOADER
-    ldt_fs_t *ldt_fs = Setup_LDT_Keeper();
-#else
     /* Initialize OLE/COM */
-    CoInitialize( 0 );
-#endif /* LOADER */
+    CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
 
     if( LoadDMO( VLC_OBJECT(p_dec), &hmsdmo_dll, &p_dmo, &p_dec->fmt_in, false )
         != VLC_SUCCESS )
@@ -509,13 +487,21 @@ static int DecOpen( decoder_t *p_dec )
             {
                 i_chroma = mt.subtype.Data1;
                 i_bpp = 12;
+                DMOFreeMediaType( &mt );
+                break;
+            }
+            else if( (p_dec->fmt_in.i_codec == VLC_CODEC_MSS1 ||
+                      p_dec->fmt_in.i_codec == VLC_CODEC_MSS2 ) &&
+                      guidcmp( &mt.subtype, &MEDIASUBTYPE_RGB24 ) )
+            {
+                i_chroma = VLC_CODEC_RGB24;
+                i_bpp = 24;
             }
 
             DMOFreeMediaType( &mt );
         }
 
-        p_dec->fmt_out.i_codec = i_chroma == VLC_CODEC_YV12 ?
-            VLC_CODEC_I420 : i_chroma;
+        p_dec->fmt_out.i_codec = i_chroma == VLC_CODEC_YV12 ? VLC_CODEC_I420 : i_chroma;
         p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
         p_dec->fmt_out.video.i_height = p_dec->fmt_in.video.i_height;
         p_dec->fmt_out.video.i_bits_per_pixel = i_bpp;
@@ -534,7 +520,7 @@ static int DecOpen( decoder_t *p_dec )
         }
 
         p_bih = &p_vih->bmiHeader;
-        p_bih->biCompression = i_chroma;
+        p_bih->biCompression = i_chroma == VLC_CODEC_RGB24 ? BI_RGB : i_chroma;
         p_bih->biHeight *= -1;
         p_bih->biBitCount = p_dec->fmt_out.video.i_bits_per_pixel;
         p_bih->biSizeImage = p_dec->fmt_in.video.i_width *
@@ -546,8 +532,15 @@ static int DecOpen( decoder_t *p_dec )
 
         dmo_output_type.majortype = MEDIATYPE_Video;
         dmo_output_type.formattype = FORMAT_VideoInfo;
-        dmo_output_type.subtype = dmo_output_type.majortype;
-        dmo_output_type.subtype.Data1 = p_bih->biCompression;
+        if( i_chroma == VLC_CODEC_RGB24 )
+        {
+            dmo_output_type.subtype = MEDIASUBTYPE_RGB24;
+        }
+        else
+        {
+            dmo_output_type.subtype = dmo_output_type.majortype;
+            dmo_output_type.subtype.Data1 = p_bih->biCompression;
+        }
         dmo_output_type.bFixedSizeSamples = true;
         dmo_output_type.bTemporalCompression = 0;
         dmo_output_type.lSampleSize = p_bih->biSizeImage;
@@ -564,26 +557,23 @@ static int DecOpen( decoder_t *p_dec )
 
         while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) )
         {
-            msg_Dbg( p_dec, "available output chroma: %4.4s",
-                     (char *)&mt.subtype.Data1 );
+            msg_Dbg( p_dec, "available output chroma: %4.4s", (char *)&mt.subtype.Data1 );
             DMOFreeMediaType( &mt );
         }
     }
 #endif
 
-    if( p_dmo->vt->SetOutputType( p_dmo, 0, &dmo_output_type, 0 ) )
+    unsigned i_err = p_dmo->vt->SetOutputType( p_dmo, 0, &dmo_output_type, 0 );
+    if( i_err )
     {
-        msg_Err( p_dec, "can't set DMO output type" );
+        msg_Err( p_dec, "can't set DMO output type for decoder: 0x%x", i_err );
         goto error;
     }
-    msg_Dbg( p_dec, "DMO output type set" );
+    msg_Dbg( p_dec, "DMO output type set for decoder" );
 
     /* Allocate the memory needed to store the decoder's structure */
     p_sys->hmsdmo_dll = hmsdmo_dll;
     p_sys->p_dmo = p_dmo;
-#ifdef LOADER
-    p_sys->ldt_fs = ldt_fs;
-#endif
 
     /* Find out some properties of the output */
     {
@@ -628,12 +618,8 @@ static int DecOpen( decoder_t *p_dec )
     if( p_dmo ) p_dmo->vt->Release( (IUnknown *)p_dmo );
     if( hmsdmo_dll ) FreeLibrary( hmsdmo_dll );
 
-#ifdef LOADER
-    Restore_LDT_Keeper( ldt_fs );
-#else
     /* Uninitialize OLE/COM */
     CoUninitialize();
-#endif /* LOADER */
 
     free( p_vih );
     free( p_wf );
@@ -655,7 +641,6 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     DMO_PARTIAL_MEDIATYPE dmo_partial_type;
     int i_err;
 
-#ifndef LOADER
     long (STDCALL *OurDMOEnum)( const GUID *, uint32_t, uint32_t,
                                const DMO_PARTIAL_MEDIATYPE *,
                                uint32_t, const DMO_PARTIAL_MEDIATYPE *,
@@ -665,7 +650,6 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     WCHAR *psz_dmo_name;
     GUID clsid_dmo;
     uint32_t i_dummy;
-#endif
 
     GETCLASS GetClass;
     IClassFactory *cFactory = NULL;
@@ -690,9 +674,8 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
         dmo_partial_type.subtype.Data1 = p_fmt->i_original_fourcc ?: p_fmt->i_codec;
     }
 
-#ifndef LOADER
     /* Load msdmo DLL */
-    *p_hmsdmo_dll = LoadLibrary( "msdmo.dll" );
+    *p_hmsdmo_dll = LoadLibraryA( "msdmo.dll" );
     if( *p_hmsdmo_dll == NULL )
     {
         msg_Dbg( p_this, "failed loading msdmo.dll" );
@@ -761,7 +744,6 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     return VLC_SUCCESS;
 
 loader:
-#endif   /* LOADER */
 
     for( i_codec = 0; codecs_table[i_codec].i_fourcc != 0; i_codec++ )
     {
@@ -771,7 +753,7 @@ loader:
     if( codecs_table[i_codec].i_fourcc == 0 )
         return VLC_EGENERIC;    /* Can't happen */
 
-    *p_hmsdmo_dll = LoadLibrary( codecs_table[i_codec].psz_dll );
+    *p_hmsdmo_dll = LoadLibraryA( codecs_table[i_codec].psz_dll );
     if( *p_hmsdmo_dll == NULL )
     {
         msg_Dbg( p_this, "failed loading '%s'",
@@ -826,14 +808,7 @@ static void DecClose( decoder_t *p_dec )
     if( p_sys->p_dmo ) p_sys->p_dmo->vt->Release( (IUnknown *)p_sys->p_dmo );
     FreeLibrary( p_sys->hmsdmo_dll );
 
-#ifdef LOADER
-#if 0
-    Restore_LDT_Keeper( p_sys->ldt_fs );
-#endif
-#else
-    /* Uninitialize OLE/COM */
     CoUninitialize();
-#endif
 
     free( p_sys->p_buffer );
 }
@@ -1020,7 +995,7 @@ static void CopyPicture( picture_t *p_pic, uint8_t *p_in )
 
         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
         {
-            vlc_memcpy( p_dst, p_src, i_width );
+            memcpy( p_dst, p_src, i_width );
             p_src += i_width;
             p_dst += i_dst_stride;
         }
@@ -1076,9 +1051,6 @@ struct encoder_sys_t
 
     date_t end_date;
 
-#ifdef LOADER
-    ldt_fs_t    *ldt_fs;
-#endif
 };
 
 /*****************************************************************************
@@ -1255,11 +1227,11 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     DMOFreeMediaType( &dmo_type );
     if( i_err )
     {
-        msg_Err( p_enc, "can't set DMO output type: %i", i_err );
+        msg_Err( p_enc, "can't set DMO output type for encoder: 0x%x", i_err );
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_enc, "successfully set output type" );
+    msg_Dbg( p_enc, "successfully set output type for encoder" );
     return VLC_SUCCESS;
 }
 
@@ -1385,7 +1357,7 @@ static int EncoderSetAudioType( encoder_t *p_enc, IMediaObject *p_dmo )
     DMOFreeMediaType( &dmo_type );
     if( i_err )
     {
-        msg_Err( p_enc, "can't set DMO input type: %x", i_err );
+        msg_Err( p_enc, "can't set DMO input type: 0x%x", i_err );
         return VLC_EGENERIC;
     }
     msg_Dbg( p_enc, "successfully set input type" );
@@ -1403,12 +1375,8 @@ static int EncOpen( vlc_object_t *p_this )
     IMediaObject *p_dmo = NULL;
     HINSTANCE hmsdmo_dll = NULL;
 
-#ifdef LOADER
-    ldt_fs_t *ldt_fs = Setup_LDT_Keeper();
-#else
     /* Initialize OLE/COM */
-    CoInitialize( 0 );
-#endif /* LOADER */
+    CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
 
     if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_enc->fmt_out, true )
         != VLC_SUCCESS )
@@ -1435,9 +1403,6 @@ static int EncOpen( vlc_object_t *p_this )
 
     p_sys->hmsdmo_dll = hmsdmo_dll;
     p_sys->p_dmo = p_dmo;
-#ifdef LOADER
-    p_sys->ldt_fs = ldt_fs;
-#endif
 
     /* Find out some properties of the inputput */
     {
@@ -1482,12 +1447,8 @@ static int EncOpen( vlc_object_t *p_this )
     if( p_dmo ) p_dmo->vt->Release( (IUnknown *)p_dmo );
     if( hmsdmo_dll ) FreeLibrary( hmsdmo_dll );
 
-#ifdef LOADER
-    Restore_LDT_Keeper( ldt_fs );
-#else
     /* Uninitialize OLE/COM */
     CoUninitialize();
-#endif /* LOADER */
 
     free( p_sys );
 
@@ -1520,7 +1481,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
             p_enc->fmt_in.video.i_height *
             p_enc->fmt_in.video.i_bits_per_pixel / 8;
 
-        p_block_in = block_New( p_enc, i_buffer );
+        p_block_in = block_Alloc( i_buffer );
 
         /* Copy picture stride by stride */
         p_dst = p_block_in->p_buffer;
@@ -1533,7 +1494,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
             for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
                  i_line++ )
             {
-                vlc_memcpy( p_dst, p_src, i_width );
+                memcpy( p_dst, p_src, i_width );
                 p_dst += i_width;
                 p_src += i_src_stride;
             }
@@ -1544,7 +1505,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
     else
     {
         block_t *p_aout_buffer = (block_t *)p_data;
-        p_block_in = block_New( p_enc, p_aout_buffer->i_buffer );
+        p_block_in = block_Alloc( p_aout_buffer->i_buffer );
         memcpy( p_block_in->p_buffer, p_aout_buffer->p_buffer,
                 p_block_in->i_buffer );
 
@@ -1587,7 +1548,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
         block_t *p_block_out;
         CMediaBuffer *p_out;
 
-        p_block_out = block_New( p_enc, p_sys->i_min_output );
+        p_block_out = block_Alloc( p_sys->i_min_output );
         p_block_out->i_buffer = 0;
         p_out = CMediaBufferCreate(p_block_out, p_sys->i_min_output, false);
         memset( &db, 0, sizeof(db) );
@@ -1664,14 +1625,8 @@ void EncoderClose( vlc_object_t *p_this )
     if( p_sys->p_dmo ) p_sys->p_dmo->vt->Release( (IUnknown *)p_sys->p_dmo );
     FreeLibrary( p_sys->hmsdmo_dll );
 
-#ifdef LOADER
-#if 0
-    Restore_LDT_Keeper( p_sys->ldt_fs );
-#endif
-#else
     /* Uninitialize OLE/COM */
     CoUninitialize();
-#endif
 
     free( p_sys );
 }