]> 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 cb077976c58b2d076d7878e6f7406985293909b7..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_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
-#include <vlc_vout.h>
-#include <vlc_aout.h>
+#include <vlc_codecs.h>
 
-#ifndef WIN32
-#    define LOADER
-#else
+#ifdef _WIN32
 #   include <objbase.h>
-#endif
-
-#ifdef LOADER
-/* Need the w32dll loader from mplayer */
-#   include <wine/winerror.h>
-#   include <ldt_keeper.h>
-#   include <wine/windef.h>
+#   include <vlc_charset.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** );
 
@@ -98,21 +79,22 @@ static int LoadDMO( vlc_object_t *, HINSTANCE *, IMediaObject **,
                     es_format_t *, bool );
 static void CopyPicture( picture_t *, uint8_t * );
 
-vlc_module_begin();
-    set_description( N_("DirectMedia Object decoder") );
-    add_shortcut( "dmo" );
-    set_capability( "decoder", 1 );
-    set_callbacks( DecoderOpen, DecoderClose );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_SCODEC );
+vlc_module_begin ()
+    set_description( N_("DirectMedia Object decoder") )
+    add_shortcut( "dmo" )
+    set_capability( "decoder", 1 )
+    set_callbacks( DecoderOpen, DecoderClose )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
 
 #   define ENC_CFG_PREFIX "sout-dmo-"
-    add_submodule();
-    set_description( N_("DirectMedia Object encoder") );
-    set_capability( "encoder", 10 );
-    set_callbacks( EncoderOpen, EncoderClose );
+    add_submodule ()
+    set_description( N_("DirectMedia Object encoder") )
+    add_shortcut( "dmo" )
+    set_capability( "encoder", 10 )
+    set_callbacks( EncoderOpen, EncoderClose )
 
-vlc_module_end();
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -131,16 +113,14 @@ 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;
-    bool         ready, works;
-    block_t    **input;
-    void        *output;
+    bool         b_ready, b_works;
+    block_t    **pp_input;
+
+    int          i_output;
+    void       **pp_output;
 };
 
 const GUID IID_IWMCodecPrivateData = {0x73f0be8e, 0x57f7, 0x4f01, {0xaa, 0x66, 0x9f, 0x57, 0x34, 0xc, 0xfe, 0xe}};
@@ -149,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}};
@@ -172,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;
@@ -183,42 +168,30 @@ typedef struct
 static const codec_dll decoders_table[] =
 {
     /* WVC1 */
-    { VLC_FOURCC('W','V','C','1'), "wvc1dmod.dll", &guid_wvc1 },
-    { VLC_FOURCC('w','v','c','1'), "wvc1dmod.dll", &guid_wvc1 },
+    { VLC_CODEC_VC1,    "wvc1dmod.dll", &guid_wvc1 },
     /* WMV3 */
-    { VLC_FOURCC('W','M','V','3'), "wmv9dmod.dll", &guid_wmv9 },
-    { VLC_FOURCC('w','m','v','3'), "wmv9dmod.dll", &guid_wmv9 },
-    { VLC_FOURCC('W','M','V','P'), "wmv9dmod.dll", &guid_wmv9 },
-    { VLC_FOURCC('w','m','v','p'), "wmv9dmod.dll", &guid_wmv9 },
+    { VLC_CODEC_WMV3,   "wmv9dmod.dll", &guid_wmv9 },
     /* WMV2 */
-    { VLC_FOURCC('W','M','V','2'), "wmvdmod.dll", &guid_wmv },
-    { VLC_FOURCC('w','m','v','2'), "wmvdmod.dll", &guid_wmv },
+    { VLC_CODEC_WMV2,   "wmvdmod.dll", &guid_wmv },
     /* WMV1 */
-    { VLC_FOURCC('W','M','V','1'), "wmvdmod.dll", &guid_wmv },
-    { VLC_FOURCC('w','m','v','1'), "wmvdmod.dll", &guid_wmv },
+    { 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_FOURCC('W','M','V','A'), "wmvadvd.dll", &guid_wmva },
-    { VLC_FOURCC('w','m','v','a'), "wmvadvd.dll", &guid_wmva },
-    { VLC_FOURCC('W','V','P','2'), "wmvadvd.dll", &guid_wmva },
-    { VLC_FOURCC('w','v','p','2'), "wmvadvd.dll", &guid_wmva },
+    { VLC_CODEC_WMVA,   "wmvadvd.dll", &guid_wmva },
 
     /* WMA 3 */
-    { VLC_FOURCC('W','M','A','3'), "wma9dmod.dll", &guid_wma9 },
-    { VLC_FOURCC('w','m','a','3'), "wma9dmod.dll", &guid_wma9 },
-    { VLC_FOURCC('W','M','A','P'), "wma9dmod.dll", &guid_wma9 },
-    { VLC_FOURCC('w','m','a','p'), "wma9dmod.dll", &guid_wma9 },
+    { VLC_CODEC_WMAP,   "wma9dmod.dll", &guid_wma9 },
+    { VLC_CODEC_WMAL,   "wma9dmod.dll", &guid_wma9 },
+
     /* WMA 2 */
-    { VLC_FOURCC('W','M','A','2'), "wma9dmod.dll", &guid_wma9 },
-    { VLC_FOURCC('w','m','a','2'), "wma9dmod.dll", &guid_wma9 },
+    { VLC_CODEC_WMA2,   "wma9dmod.dll", &guid_wma9 },
 
     /* WMA Speech */
-    { VLC_FOURCC('W','M','A','S'), "wmspdmod.dll", &guid_wma },
-    { VLC_FOURCC('w','m','a','s'), "wmspdmod.dll", &guid_wma },
+    { VLC_CODEC_WMAS,   "wmspdmod.dll", &guid_wma },
 
     /* */
     { 0, NULL, NULL }
@@ -227,21 +200,16 @@ static const codec_dll decoders_table[] =
 static const codec_dll encoders_table[] =
 {
     /* WMV3 */
-    { VLC_FOURCC('W','M','V','3'), "wmvdmoe2.dll", &guid_wmv_enc2 },
-    { VLC_FOURCC('w','m','v','3'), "wmvdmoe2.dll", &guid_wmv_enc2 },
+    { VLC_CODEC_WMV3, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV2 */
-    { VLC_FOURCC('W','M','V','2'), "wmvdmoe2.dll", &guid_wmv_enc2 },
-    { VLC_FOURCC('w','m','v','2'), "wmvdmoe2.dll", &guid_wmv_enc2 },
+    { VLC_CODEC_WMV2, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV1 */
-    { VLC_FOURCC('W','M','V','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },
-    { VLC_FOURCC('w','m','v','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },
+    { VLC_CODEC_WMV1, "wmvdmoe2.dll", &guid_wmv_enc2 },
 
     /* WMA 3 */
-    { VLC_FOURCC('W','M','A','3'), "wmadmoe.dll", &guid_wma_enc },
-    { VLC_FOURCC('w','m','a','3'), "wmadmoe.dll", &guid_wma_enc },
+    { VLC_CODEC_WMAP, "wmadmoe.dll", &guid_wma_enc },
     /* WMA 2 */
-    { VLC_FOURCC('W','M','A','2'), "wmadmoe.dll", &guid_wma_enc },
-    { VLC_FOURCC('w','m','a','2'), "wmadmoe.dll", &guid_wma_enc },
+    { VLC_CODEC_WMA2, "wmadmoe.dll", &guid_wma_enc },
 
     /* */
     { 0, NULL, NULL }
@@ -288,24 +256,27 @@ found:
     /* Set callbacks */
     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
-    p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
+    p_dec->pf_decode_audio = (block_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
 
     vlc_mutex_init( &p_sys->lock );
     vlc_cond_init( &p_sys->wait_input );
     vlc_cond_init( &p_sys->wait_output );
-    p_sys->works = p_sys->ready = false;
+    p_sys->b_works =
+    p_sys->b_ready = false;
+    p_sys->pp_input = NULL;
+    TAB_INIT( p_sys->i_output, p_sys->pp_output );
 
     if( vlc_clone( &p_sys->thread, DecoderThread, p_dec,
                    VLC_THREAD_PRIORITY_INPUT ) )
         goto error;
 
     vlc_mutex_lock( &p_sys->lock );
-    while( !p_sys->ready )
+    while( !p_sys->b_ready )
         vlc_cond_wait( &p_sys->wait_output, &p_sys->lock );
     vlc_mutex_unlock( &p_sys->lock );
 
-    if( p_sys->works )
+    if( p_sys->b_works )
         return VLC_SUCCESS;
 
     vlc_join( p_sys->thread, NULL );
@@ -326,11 +297,12 @@ static void DecoderClose( vlc_object_t *p_this )
     decoder_sys_t *p_sys = p_dec->p_sys;
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->ready = false;
+    p_sys->b_ready = false;
     vlc_cond_signal( &p_sys->wait_input );
     vlc_mutex_unlock( &p_sys->lock );
 
     vlc_join( p_sys->thread, NULL );
+    TAB_CLEAN( p_sys->i_output, p_sys->pp_output );
     vlc_cond_destroy( &p_sys->wait_input );
     vlc_cond_destroy( &p_sys->wait_output );
     vlc_mutex_destroy( &p_sys->lock );
@@ -340,18 +312,28 @@ static void DecoderClose( vlc_object_t *p_this )
 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    void *ret;
+    void *p_ret;
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->input = pp_block;
-    vlc_cond_signal( &p_sys->wait_input );
+    if( p_sys->i_output <= 0 )
+    {
+        p_sys->pp_input = pp_block;
+        vlc_cond_signal( &p_sys->wait_input );
+
+        while( p_sys->pp_input )
+            vlc_cond_wait( &p_sys->wait_output, &p_sys->lock );
+    }
+
+    p_ret = NULL;
+    if( p_sys->i_output > 0 )
+    {
+        p_ret = p_sys->pp_output[0];
+        TAB_REMOVE( p_sys->i_output, p_sys->pp_output, p_ret );
+    }
 
-    while( !(ret = p_sys->output) )
-        vlc_cond_wait( &p_sys->wait_output, &p_sys->lock );
-    p_sys->output = NULL;
     vlc_mutex_unlock( &p_sys->lock );
 
-    return ret;
+    return p_ret;
 }
 
 /*****************************************************************************
@@ -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 )
@@ -399,7 +377,7 @@ static int DecOpen( decoder_t *p_dec )
 
         dmo_input_type.majortype  = MEDIATYPE_Audio;
         dmo_input_type.subtype    = dmo_input_type.majortype;
-        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_codec;
+        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_original_fourcc ?: p_dec->fmt_in.i_codec;
         fourcc_to_wf_tag( p_dec->fmt_in.i_codec, &i_tag );
         if( i_tag ) dmo_input_type.subtype.Data1 = i_tag;
 
@@ -420,7 +398,7 @@ static int DecOpen( decoder_t *p_dec )
     }
     else
     {
-        BITMAPINFOHEADER *p_bih;
+        VLC_BITMAPINFOHEADER *p_bih;
 
         int i_size = sizeof(VIDEOINFOHEADER) + p_dec->fmt_in.i_extra;
         p_vih = malloc( i_size );
@@ -430,13 +408,13 @@ static int DecOpen( decoder_t *p_dec )
             memcpy( &p_vih[1], p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
 
         p_bih = &p_vih->bmiHeader;
-        p_bih->biCompression = p_dec->fmt_in.i_codec;
+        p_bih->biCompression = p_dec->fmt_in.i_original_fourcc ?: p_dec->fmt_in.i_codec;
         p_bih->biWidth = p_dec->fmt_in.video.i_width;
         p_bih->biHeight = p_dec->fmt_in.video.i_height;
         p_bih->biBitCount = p_dec->fmt_in.video.i_bits_per_pixel;
         p_bih->biPlanes = 1;
         p_bih->biSize = i_size - sizeof(VIDEOINFOHEADER) +
-            sizeof(BITMAPINFOHEADER);
+            sizeof(VLC_BITMAPINFOHEADER);
 
         p_vih->rcSource.left = p_vih->rcSource.top = 0;
         p_vih->rcSource.right = p_dec->fmt_in.video.i_width;
@@ -445,7 +423,7 @@ static int DecOpen( decoder_t *p_dec )
 
         dmo_input_type.majortype  = MEDIATYPE_Video;
         dmo_input_type.subtype    = dmo_input_type.majortype;
-        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_codec;
+        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_original_fourcc ?: p_dec->fmt_in.i_codec;
         dmo_input_type.formattype = FORMAT_VideoInfo;
         dmo_input_type.bFixedSizeSamples = 0;
         dmo_input_type.bTemporalCompression = 1;
@@ -467,7 +445,7 @@ static int DecOpen( decoder_t *p_dec )
     if( p_dec->fmt_in.i_cat == AUDIO_ES )
     {
         /* Setup the format */
-        p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
+        p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
         p_dec->fmt_out.audio.i_rate     = p_dec->fmt_in.audio.i_rate;
         p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels;
         p_dec->fmt_out.audio.i_bitspersample = 16;//p_dec->fmt_in.audio.i_bitspersample; We request 16
@@ -496,56 +474,73 @@ static int DecOpen( decoder_t *p_dec )
     }
     else
     {
-        BITMAPINFOHEADER *p_bih;
+        VLC_BITMAPINFOHEADER *p_bih;
         DMO_MEDIA_TYPE mt;
-        unsigned i_chroma = VLC_FOURCC('Y','U','Y','2');
-        int i_planes = 1, i_bpp = 16;
+        unsigned i_chroma = VLC_CODEC_YUYV;
+        int i_bpp = 16;
         int i = 0;
 
         /* Find out which chroma to use */
         while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) )
         {
-            if( mt.subtype.Data1 == VLC_FOURCC('Y','V','1','2') )
+            if( mt.subtype.Data1 == VLC_CODEC_YV12 )
             {
                 i_chroma = mt.subtype.Data1;
-                i_planes = 3; i_bpp = 12;
+                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_FOURCC('Y','V','1','2') ?
-            VLC_FOURCC('I','4','2','0') : 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;
 
         /* If an aspect-ratio was specified in the input format then force it */
-        if( p_dec->fmt_in.video.i_aspect )
+        if( p_dec->fmt_in.video.i_sar_num > 0 &&
+            p_dec->fmt_in.video.i_sar_den > 0 )
         {
-            p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect;
+            p_dec->fmt_out.video.i_sar_num = p_dec->fmt_in.video.i_sar_num;
+            p_dec->fmt_out.video.i_sar_den = p_dec->fmt_in.video.i_sar_den;
         }
         else
         {
-            p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR *
-                p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height;
+            p_dec->fmt_out.video.i_sar_num = 1;
+            p_dec->fmt_out.video.i_sar_den = 1;
         }
 
         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 *
             p_dec->fmt_in.video.i_height *
             (p_dec->fmt_in.video.i_bits_per_pixel + 7) / 8;
 
-        p_bih->biPlanes = i_planes;
-        p_bih->biSize = sizeof(BITMAPINFOHEADER);
+        p_bih->biPlanes = 1; /* http://msdn.microsoft.com/en-us/library/dd183376%28v=vs.85%29.aspx */
+        p_bih->biSize = sizeof(VLC_BITMAPINFOHEADER);
 
         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;
@@ -562,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 */
     {
@@ -614,7 +606,8 @@ static int DecOpen( decoder_t *p_dec )
     free( p_wf );
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->ready = p_sys->works = true;
+    p_sys->b_ready =
+    p_sys->b_works = true;
     vlc_cond_signal( &p_sys->wait_output );
     vlc_mutex_unlock( &p_sys->lock );
 
@@ -625,18 +618,14 @@ 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 );
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->ready = true;
+    p_sys->b_ready = true;
     vlc_cond_signal( &p_sys->wait_output );
     vlc_mutex_unlock( &p_sys->lock );
     return VLC_EGENERIC;
@@ -652,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 *,
@@ -662,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;
@@ -676,7 +663,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
         uint16_t i_tag;
         dmo_partial_type.type = MEDIATYPE_Audio;
         dmo_partial_type.subtype = dmo_partial_type.type;
-        dmo_partial_type.subtype.Data1 = p_fmt->i_codec;
+        dmo_partial_type.subtype.Data1 = p_fmt->i_original_fourcc ?: p_fmt->i_codec;
         fourcc_to_wf_tag( p_fmt->i_codec, &i_tag );
         if( i_tag ) dmo_partial_type.subtype.Data1 = i_tag;
     }
@@ -684,12 +671,11 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     {
         dmo_partial_type.type = MEDIATYPE_Video;
         dmo_partial_type.subtype = dmo_partial_type.type;
-        dmo_partial_type.subtype.Data1 = p_fmt->i_codec;
+        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" );
@@ -726,8 +712,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     while( ( S_OK == p_enum_dmo->vt->Next( p_enum_dmo, 1, &clsid_dmo,
                      &psz_dmo_name, &i_dummy /* NULL doesn't work */ ) ) )
     {
-        char psz_temp[MAX_PATH];
-        wcstombs( psz_temp, psz_dmo_name, MAX_PATH );
+        char *psz_temp = FromWide( psz_dmo_name );
         msg_Dbg( p_this, "found DMO: %s", psz_temp );
         CoTaskMemFree( psz_dmo_name );
 
@@ -736,9 +721,14 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
                               &IID_IMediaObject, (void **)pp_dmo ) )
         {
             msg_Warn( p_this, "can't create DMO: %s", psz_temp );
+            free( psz_temp );
             *pp_dmo = 0;
         }
-        else break;
+        else
+        {
+            free( psz_temp );
+            break;
+        }
     }
 
     p_enum_dmo->vt->Release( (IUnknown *)p_enum_dmo );
@@ -754,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++ )
     {
@@ -764,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'",
@@ -782,6 +771,7 @@ loader:
 
     i_err = GetClass( codecs_table[i_codec].p_guid, &IID_IClassFactory,
                       (void**)&cFactory );
+
     if( i_err || cFactory == NULL )
     {
         msg_Dbg( p_this, "no such class object" );
@@ -818,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 );
 }
@@ -833,7 +816,7 @@ static void DecClose( decoder_t *p_dec )
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
- * This function must be fed with ogg packets.
+ * This function must be fed with packets.
  ****************************************************************************/
 static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
 {
@@ -851,10 +834,11 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
     p_block = *pp_block;
 
     /* Won't work with streams with B-frames, but do we have any ? */
-    if( p_block && p_block->i_pts <= 0 ) p_block->i_pts = p_block->i_dts;
+    if( p_block && p_block->i_pts <= VLC_TS_INVALID )
+        p_block->i_pts = p_block->i_dts;
 
     /* Date management */
-    if( p_block && p_block->i_pts > 0 &&
+    if( p_block && p_block->i_pts > VLC_TS_INVALID &&
         p_block->i_pts != date_Get( &p_sys->end_date ) )
     {
         date_Set( &p_sys->end_date, p_block->i_pts );
@@ -902,14 +886,16 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
         }
         else
         {
-            //msg_Dbg( p_dec, "ProcessInput(): successful" );
-            *pp_block = 0;
+#ifdef DMO_DEBUG
+            msg_Dbg( p_dec, "ProcessInput(): successful" );
+#endif
+            *pp_block = NULL;
         }
     }
     else if( p_block && !p_block->i_buffer )
     {
         block_Release( p_block );
-        *pp_block = 0;
+        *pp_block = NULL;
     }
 
     /* Get output from the DMO */
@@ -968,7 +954,7 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
     }
     else
     {
-        aout_buffer_t *p_aout_buffer;
+        block_t *p_aout_buffer;
         int i_samples = block_out.i_buffer /
             ( p_dec->fmt_out.audio.i_bitspersample *
               p_dec->fmt_out.audio.i_channels / 8 );
@@ -979,9 +965,10 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
             memcpy( p_aout_buffer->p_buffer,
                     block_out.p_buffer, block_out.i_buffer );
             /* Date management */
-            p_aout_buffer->start_date = date_Get( &p_sys->end_date );
-            p_aout_buffer->end_date =
-                date_Increment( &p_sys->end_date, i_samples );
+            p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
+            p_aout_buffer->i_length =
+                date_Increment( &p_sys->end_date, i_samples )
+                - p_aout_buffer->i_pts;
         }
         p_out->vt->Release( (IUnknown *)p_out );
 
@@ -1008,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;
         }
@@ -1030,13 +1017,20 @@ static void *DecoderThread( void *data )
     vlc_mutex_lock( &p_sys->lock );
     for( ;; )
     {
-        while( p_sys->ready && !p_sys->input )
+        while( p_sys->b_ready && !p_sys->pp_input )
             vlc_cond_wait( &p_sys->wait_input, &p_sys->lock );
-        if( !p_sys->ready )
+        if( !p_sys->b_ready )
             break;
 
-        p_sys->output = DecBlock( p_dec, p_sys->input );
-        p_sys->input = NULL;
+        for( ;; )
+        {
+            void *p_output = DecBlock( p_dec, p_sys->pp_input );
+            if( !p_output )
+                break;
+            TAB_APPEND( p_sys->i_output, p_sys->pp_output, p_output );
+        }
+        p_sys->pp_input = NULL;
+        vlc_cond_signal( &p_sys->wait_output );
     }
     vlc_mutex_unlock( &p_sys->lock );
 
@@ -1057,9 +1051,6 @@ struct encoder_sys_t
 
     date_t end_date;
 
-#ifdef LOADER
-    ldt_fs_t    *ldt_fs;
-#endif
 };
 
 /*****************************************************************************
@@ -1075,7 +1066,7 @@ static int EncoderOpen( vlc_object_t *p_this )
     /* Set callbacks */
     p_enc->pf_encode_video = (block_t *(*)(encoder_t *, picture_t *))
         EncodeBlock;
-    p_enc->pf_encode_audio = (block_t *(*)(encoder_t *, aout_buffer_t *))
+    p_enc->pf_encode_audio = (block_t *(*)(encoder_t *, block_t *))
         EncodeBlock;
 
     return VLC_SUCCESS;
@@ -1089,7 +1080,7 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     int i, i_selected, i_err;
     DMO_MEDIA_TYPE dmo_type;
     VIDEOINFOHEADER vih, *p_vih;
-    BITMAPINFOHEADER *p_bih;
+    VLC_BITMAPINFOHEADER *p_bih;
 
     /* FIXME */
     p_enc->fmt_in.video.i_bits_per_pixel =
@@ -1116,14 +1107,14 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     memset( &vih, 0, sizeof(VIDEOINFOHEADER) );
 
     p_bih = &vih.bmiHeader;
-    p_bih->biCompression = VLC_FOURCC('I','4','2','0');
+    p_bih->biCompression = VLC_CODEC_I420;
     p_bih->biWidth = p_enc->fmt_in.video.i_width;
     p_bih->biHeight = p_enc->fmt_in.video.i_height;
     p_bih->biBitCount = p_enc->fmt_in.video.i_bits_per_pixel;
     p_bih->biSizeImage = p_enc->fmt_in.video.i_width *
         p_enc->fmt_in.video.i_height * p_enc->fmt_in.video.i_bits_per_pixel /8;
     p_bih->biPlanes = 3;
-    p_bih->biSize = sizeof(BITMAPINFOHEADER);
+    p_bih->biSize = sizeof(VLC_BITMAPINFOHEADER);
 
     vih.rcSource.left = vih.rcSource.top = 0;
     vih.rcSource.right = p_enc->fmt_in.video.i_width;
@@ -1191,7 +1182,7 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
 
         i_err = p_dmo->vt->QueryInterface( (IUnknown *)p_dmo,
                                            &IID_IWMCodecPrivateData,
-                                           (void **)&p_privdata );
+                                           (void**)&p_privdata );
         if( i_err ) break;
 
         i_err = p_privdata->vt->SetPartialOutputType( p_privdata, &dmo_type );
@@ -1231,16 +1222,16 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     i_err = p_dmo->vt->SetOutputType( p_dmo, 0, &dmo_type, 0 );
 
     p_vih = (VIDEOINFOHEADER *)dmo_type.pbFormat;
-    p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
+    p_enc->fmt_in.i_codec = VLC_CODEC_I420;
 
     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;
 }
 
@@ -1259,7 +1250,7 @@ static int EncoderSetAudioType( encoder_t *p_enc, IMediaObject *p_dmo )
     fourcc_to_wf_tag( p_enc->fmt_out.i_codec, &i_tag );
     if( i_tag == 0 ) return VLC_EGENERIC;
 
-    p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
+    p_enc->fmt_in.i_codec = VLC_CODEC_S16N;
     p_enc->fmt_in.audio.i_bitspersample = 16;
 
     /* We first need to choose an output type from the predefined
@@ -1366,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" );
@@ -1384,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 )
@@ -1409,17 +1396,13 @@ static int EncOpen( vlc_object_t *p_this )
     }
 
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_enc->p_sys = p_sys =
-          (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL )
+    if( ( p_enc->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL )
     {
         goto error;
     }
 
     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 */
     {
@@ -1464,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 );
 
@@ -1502,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;
@@ -1515,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;
             }
@@ -1525,12 +1504,12 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
     }
     else
     {
-        aout_buffer_t *p_aout_buffer = (aout_buffer_t *)p_data;
-        p_block_in = block_New( p_enc, p_aout_buffer->i_nb_bytes );
+        block_t *p_aout_buffer = (block_t *)p_data;
+        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 );
 
-        i_pts = p_aout_buffer->start_date;
+        i_pts = p_aout_buffer->i_pts;
     }
 
     /* Feed input to the DMO */
@@ -1569,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) );
@@ -1646,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 );
 }