]> git.sesse.net Git - vlc/blobdiff - modules/codec/dmo/dmo.c
DMO: use FromWide(), fix charset
[vlc] / modules / codec / dmo / dmo.c
index 43857347a5b40932fcf63811797ed93992135630..33c30775765ccf0db381d5ab3c2062d5e6204a62 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 
-#include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/vout.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_codec.h>
+#include <vlc_aout.h>
 
 #ifndef WIN32
 #    define LOADER
 #else
 #   include <objbase.h>
+#   include <vlc_charset.h>
 #endif
 
 #ifdef LOADER
 #   include <wine/windef.h>
 #endif
 
-#include "codecs.h"
+#include <vlc_codecs.h>
 #include "dmo.h"
 
 //#define DMO_DEBUG 1
 
 #ifdef LOADER
 /* Not Needed */
-long CoInitialize( void *pvReserved ) { return -1; }
+long CoInitialize( void *pvReserved ) { VLC_UNUSED(pvReserved); return -1; }
 void CoUninitialize( void ) { }
 
 /* A few prototypes */
@@ -64,7 +67,7 @@ int     WINAPI FreeLibrary(HMODULE);
 
 typedef long (STDCALL *GETCLASS) ( const GUID*, const GUID*, void** );
 
-static int pi_channels_maps[7] =
+static const int pi_channels_maps[7] =
 {
     0,
     AOUT_CHAN_CENTER,
@@ -82,34 +85,35 @@ static int pi_channels_maps[7] =
  * Module descriptor
  *****************************************************************************/
 static int  DecoderOpen  ( vlc_object_t * );
-static int  DecOpen      ( vlc_object_t * );
 static void DecoderClose ( vlc_object_t * );
 static void *DecodeBlock ( decoder_t *, block_t ** );
-
+static void *DecoderThread( void * );
 static int  EncoderOpen  ( vlc_object_t * );
-static int  EncOpen      ( vlc_object_t * );
 static void EncoderClose ( vlc_object_t * );
 static block_t *EncodeBlock( encoder_t *, void * );
 
+static int  EncOpen  ( vlc_object_t * );
+
 static int LoadDMO( vlc_object_t *, HINSTANCE *, IMediaObject **,
-                    es_format_t *, vlc_bool_t );
-static void CopyPicture( decoder_t *, picture_t *, uint8_t * );
+                    es_format_t *, bool );
+static void CopyPicture( picture_t *, uint8_t * );
 
-vlc_module_begin();
-    set_description( _("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( _("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,17 +135,44 @@ struct decoder_sys_t
 #ifdef LOADER
     ldt_fs_t    *ldt_fs;
 #endif
+
+    vlc_thread_t thread;
+    vlc_mutex_t  lock;
+    vlc_cond_t   wait_input, wait_output;
+    bool         b_ready, b_works;
+    block_t    **pp_input;
+
+    int          i_output;
+    void       **pp_output;
 };
 
-static const GUID guid_wvc1 = { 0xc9bfbccf, 0xe60e, 0x4588, { 0xa3, 0xdf, 0x5a, 0x03, 0xb1, 0xfd, 0x95, 0x85 } };
+const GUID IID_IWMCodecPrivateData = {0x73f0be8e, 0x57f7, 0x4f01, {0xaa, 0x66, 0x9f, 0x57, 0x34, 0xc, 0xfe, 0xe}};
+const GUID IID_IMediaObject = {0xd8ad0f58, 0x5494, 0x4102, {0x97, 0xc5, 0xec, 0x79, 0x8e, 0x59, 0xbc, 0xf4}};
+const GUID IID_IMediaBuffer = {0x59eff8b9, 0x938c, 0x4a26, {0x82, 0xf2, 0x95, 0xcb, 0x84, 0xcd, 0xc8, 0x37}};
+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 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}};
+const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+const GUID MEDIASUBTYPE_RGB24 = {0xe436eb7d, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
+const GUID MEDIASUBTYPE_RGB565 = {0xe436eb7b, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
 
+
+static const GUID guid_wvc1 = { 0xc9bfbccf, 0xe60e, 0x4588, { 0xa3, 0xdf, 0x5a, 0x03, 0xb1, 0xfd, 0x95, 0x85 } };
 static const GUID guid_wmv9 = { 0x724bb6a4, 0xe526, 0x450f, { 0xaf, 0xfa, 0xab, 0x9b, 0x45, 0x12, 0x91, 0x11 } };
-static const GUID guid_wma9 = { 0x27ca0808, 0x01f5, 0x4e7a, { 0x8b, 0x05, 0x87, 0xf8, 0x07, 0xa2, 0x33, 0xd1 } };
 
 static const GUID guid_wmv = { 0x82d353df, 0x90bd, 0x4382, { 0x8b, 0xc2, 0x3f, 0x61, 0x92, 0xb7, 0x6e, 0x34 } };
+static const GUID guid_wms = { 0x7bafb3b1, 0xd8f4, 0x4279, { 0x92, 0x53, 0x27, 0xda, 0x42, 0x31, 0x08, 0xde } };
+static const GUID guid_wmva ={ 0x03be3ac4, 0x84b7, 0x4e0e, { 0xa7, 0x8d, 0xd3, 0x52, 0x4e, 0x60, 0x39, 0x5a } };
+
 static const GUID guid_wma = { 0x874131cb, 0x4ecc, 0x443b, { 0x89, 0x48, 0x74, 0x6b, 0x89, 0x59, 0x5d, 0x20 } };
+static const GUID guid_wma9 = { 0x27ca0808, 0x01f5, 0x4e7a, { 0x8b, 0x05, 0x87, 0xf8, 0x07, 0xa2, 0x33, 0xd1 } };
 
 static const GUID guid_wmv_enc = { 0x3181343b, 0x94a2, 0x4feb, { 0xad, 0xef, 0x30, 0xa1, 0xdd, 0xe6, 0x17, 0xb4 } };
+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 } };
 
 typedef struct
@@ -155,28 +186,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_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 },
+    /* Windows Media Video Adv */
+    { 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_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_CODEC_WMAS,   "wmspdmod.dll", &guid_wma },
 
     /* */
     { 0, NULL, NULL }
@@ -184,19 +217,17 @@ static const codec_dll decoders_table[] =
 
 static const codec_dll encoders_table[] =
 {
+    /* WMV3 */
+    { VLC_CODEC_WMV3, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV2 */
-    { VLC_FOURCC('W','M','V','2'), "wmvdmoe.dll", &guid_wmv_enc },
-    { VLC_FOURCC('w','m','v','2'), "wmvdmoe.dll", &guid_wmv_enc },
+    { VLC_CODEC_WMV2, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV1 */
-    { VLC_FOURCC('W','M','V','1'), "wmvdmoe.dll", &guid_wmv_enc },
-    { VLC_FOURCC('w','m','v','1'), "wmvdmoe.dll", &guid_wmv_enc },
+    { 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 }
@@ -217,34 +248,28 @@ static void WINAPI DMOFreeMediaType( DMO_MEDIA_TYPE *mt )
 static int DecoderOpen( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
+    decoder_sys_t *p_sys;
 
-#ifndef LOADER
-    int i_ret = DecOpen( p_this );
-    if( i_ret != VLC_SUCCESS ) return i_ret;
-
-
-#else
     /* We can't open it now, because of ldt_keeper or something
      * Open/Decode/Close has to be done in the same thread */
-    int i;
-
-    p_dec->p_sys = NULL;
 
     /* Probe if we support it */
-    for( i = 0; decoders_table[i].i_fourcc != 0; i++ )
+    for( unsigned i = 0; decoders_table[i].i_fourcc != 0; i++ )
     {
         if( decoders_table[i].i_fourcc == p_dec->fmt_in.i_codec )
         {
             msg_Dbg( p_dec, "DMO codec for %4.4s may work with dll=%s",
                      (char*)&p_dec->fmt_in.i_codec,
                      decoders_table[i].psz_dll );
-            break;
+            goto found;
         }
     }
+    return VLC_EGENERIC;
 
-    p_dec->p_sys = NULL;
-    if( !decoders_table[i].i_fourcc ) return VLC_EGENERIC;
-#endif /* LOADER */
+found:
+    p_sys = p_dec->p_sys = malloc(sizeof(*p_sys));
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     /* Set callbacks */
     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
@@ -252,16 +277,89 @@ static int DecoderOpen( vlc_object_t *p_this )
     p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
 
-    return VLC_SUCCESS;
+    vlc_mutex_init( &p_sys->lock );
+    vlc_cond_init( &p_sys->wait_input );
+    vlc_cond_init( &p_sys->wait_output );
+    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->b_ready )
+        vlc_cond_wait( &p_sys->wait_output, &p_sys->lock );
+    vlc_mutex_unlock( &p_sys->lock );
+
+    if( p_sys->b_works )
+        return VLC_SUCCESS;
+
+    vlc_join( p_sys->thread, NULL );
+error:
+    vlc_cond_destroy( &p_sys->wait_input );
+    vlc_cond_destroy( &p_sys->wait_output );
+    vlc_mutex_destroy( &p_sys->lock );
+    free( p_sys );
+    return VLC_ENOMEM;
 }
 
 /*****************************************************************************
- * DecOpen: open dmo codec
+ * DecoderClose: close codec
  *****************************************************************************/
-static int DecOpen( vlc_object_t *p_this )
+static void DecoderClose( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
-    decoder_sys_t *p_sys = NULL;
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    vlc_mutex_lock( &p_sys->lock );
+    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 );
+    free( p_sys );
+}
+
+static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    void *p_ret;
+
+    vlc_mutex_lock( &p_sys->lock );
+    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 );
+    }
+
+    vlc_mutex_unlock( &p_sys->lock );
+
+    return p_ret;
+}
+
+/*****************************************************************************
+ * DecOpen: open dmo codec
+ *****************************************************************************/
+static int DecOpen( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
 
     DMO_MEDIA_TYPE dmo_input_type, dmo_output_type;
     IMediaObject *p_dmo = NULL;
@@ -277,7 +375,7 @@ static int DecOpen( vlc_object_t *p_this )
     CoInitialize( 0 );
 #endif /* LOADER */
 
-    if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_dec->fmt_in, VLC_FALSE )
+    if( LoadDMO( VLC_OBJECT(p_dec), &hmsdmo_dll, &p_dmo, &p_dec->fmt_in, false )
         != VLC_SUCCESS )
     {
         hmsdmo_dll = 0;
@@ -301,7 +399,7 @@ static int DecOpen( vlc_object_t *p_this )
 
         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;
 
@@ -332,7 +430,7 @@ static int DecOpen( vlc_object_t *p_this )
             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;
@@ -347,7 +445,7 @@ static int DecOpen( vlc_object_t *p_this )
 
         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;
@@ -369,7 +467,7 @@ static int DecOpen( vlc_object_t *p_this )
     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
@@ -400,14 +498,14 @@ static int DecOpen( vlc_object_t *p_this )
     {
         BITMAPINFOHEADER *p_bih;
         DMO_MEDIA_TYPE mt;
-        unsigned i_chroma = VLC_FOURCC('Y','U','Y','2');
+        unsigned i_chroma = VLC_CODEC_YUYV;
         int i_planes = 1, 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;
@@ -416,21 +514,23 @@ static int DecOpen( vlc_object_t *p_this )
             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;
@@ -448,7 +548,7 @@ static int DecOpen( vlc_object_t *p_this )
         dmo_output_type.formattype = FORMAT_VideoInfo;
         dmo_output_type.subtype = dmo_output_type.majortype;
         dmo_output_type.subtype.Data1 = p_bih->biCompression;
-        dmo_output_type.bFixedSizeSamples = VLC_TRUE;
+        dmo_output_type.bFixedSizeSamples = true;
         dmo_output_type.bTemporalCompression = 0;
         dmo_output_type.lSampleSize = p_bih->biSizeImage;
         dmo_output_type.cbFormat = sizeof(VIDEOINFOHEADER);
@@ -479,13 +579,6 @@ static int DecOpen( vlc_object_t *p_this )
     msg_Dbg( p_dec, "DMO output type set" );
 
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys = p_sys =
-          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
-    {
-        msg_Err( p_dec, "out of memory" );
-        goto error;
-    }
-
     p_sys->hmsdmo_dll = hmsdmo_dll;
     p_sys->p_dmo = p_dmo;
 #ifdef LOADER
@@ -519,8 +612,14 @@ static int DecOpen( vlc_object_t *p_this )
     else
         date_Init( &p_sys->end_date, 25 /* FIXME */, 1 );
 
-    if( p_vih ) free( p_vih );
-    if( p_wf ) free( p_wf );
+    free( p_vih );
+    free( p_wf );
+
+    vlc_mutex_lock( &p_sys->lock );
+    p_sys->b_ready =
+    p_sys->b_works = true;
+    vlc_cond_signal( &p_sys->wait_output );
+    vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_SUCCESS;
 
@@ -536,10 +635,13 @@ static int DecOpen( vlc_object_t *p_this )
     CoUninitialize();
 #endif /* LOADER */
 
-    if( p_vih ) free( p_vih );
-    if( p_wf )  free( p_wf );
-    if( p_sys ) free( p_sys );
+    free( p_vih );
+    free( p_wf );
 
+    vlc_mutex_lock( &p_sys->lock );
+    p_sys->b_ready = true;
+    vlc_cond_signal( &p_sys->wait_output );
+    vlc_mutex_unlock( &p_sys->lock );
     return VLC_EGENERIC;
 }
 
@@ -548,7 +650,7 @@ static int DecOpen( vlc_object_t *p_this )
  *****************************************************************************/
 static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
                     IMediaObject **pp_dmo, es_format_t *p_fmt,
-                    vlc_bool_t b_out )
+                    bool b_out )
 {
     DMO_PARTIAL_MEDIATYPE dmo_partial_type;
     int i_err;
@@ -577,7 +679,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;
     }
@@ -585,7 +687,7 @@ 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
@@ -627,8 +729,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 );
 
@@ -637,9 +738,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 );
@@ -682,7 +788,7 @@ loader:
     }
 
     i_err = GetClass( codecs_table[i_codec].p_guid, &IID_IClassFactory,
-                      (void**)&cFactory );
+                      &cFactory );
     if( i_err || cFactory == NULL )
     {
         msg_Dbg( p_this, "no such class object" );
@@ -691,7 +797,7 @@ loader:
     }
 
     i_err = cFactory->vt->CreateInstance( cFactory, 0, &IID_IUnknown,
-                                          (void**)&cObject );
+                                          &cObject );
     cFactory->vt->Release( (IUnknown*)cFactory );
     if( i_err || !cObject )
     {
@@ -700,7 +806,7 @@ loader:
         return VLC_EGENERIC;
     }
     i_err = cObject->vt->QueryInterface( cObject, &IID_IMediaObject,
-                                        (void**)pp_dmo );
+                                        pp_dmo );
     cObject->vt->Release( (IUnknown*)cObject );
     if( i_err || !*pp_dmo )
     {
@@ -712,16 +818,10 @@ loader:
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * DecoderClose: close codec
- *****************************************************************************/
-void DecoderClose( vlc_object_t *p_this )
+static void DecClose( decoder_t *p_dec )
 {
-    decoder_t *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( !p_sys ) return;
-
     if( p_sys->p_dmo ) p_sys->p_dmo->vt->Release( (IUnknown *)p_sys->p_dmo );
     FreeLibrary( p_sys->hmsdmo_dll );
 
@@ -734,16 +834,15 @@ void DecoderClose( vlc_object_t *p_this )
     CoUninitialize();
 #endif
 
-    if( p_sys->p_buffer ) free( p_sys->p_buffer );
-    free( p_sys );
+    free( p_sys->p_buffer );
 }
 
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
- * This function must be fed with ogg packets.
+ * This function must be fed with packets.
  ****************************************************************************/
-static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
+static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t *p_block;
@@ -754,25 +853,16 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     block_t block_out;
     uint32_t i_status;
 
-    if( p_sys == NULL )
-    {
-        if( DecOpen( VLC_OBJECT(p_dec) ) )
-        {
-            msg_Err( p_dec, "DecOpen failed" );
-            return NULL;
-        }
-        p_sys = p_dec->p_sys;
-    }
-
     if( !pp_block ) return NULL;
 
     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 );
@@ -792,7 +882,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     {
         CMediaBuffer *p_in;
 
-        p_in = CMediaBufferCreate( p_block, p_block->i_buffer, VLC_TRUE );
+        p_in = CMediaBufferCreate( p_block, p_block->i_buffer, true );
 
         i_result = p_sys->p_dmo->vt->ProcessInput( p_sys->p_dmo, 0,
                        (IMediaBuffer *)p_in, DMO_INPUT_DATA_BUFFERF_SYNCPOINT,
@@ -820,21 +910,23 @@ static void *DecodeBlock( 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 */
     block_out.p_buffer = p_sys->p_buffer;
     block_out.i_buffer = 0;
 
-    p_out = CMediaBufferCreate( &block_out, p_sys->i_min_output, VLC_FALSE );
+    p_out = CMediaBufferCreate( &block_out, p_sys->i_min_output, false );
     memset( &db, 0, sizeof(db) );
     db.pBuffer = (IMediaBuffer *)p_out;
 
@@ -846,7 +938,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     {
         if( i_result != S_FALSE )
             msg_Dbg( p_dec, "ProcessOutput(): failed" );
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
         else
             msg_Dbg( p_dec, "ProcessOutput(): no output" );
 #endif
@@ -855,13 +947,13 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
     msg_Dbg( p_dec, "ProcessOutput(): success" );
 #endif
 
     if( !block_out.i_buffer )
     {
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
         msg_Dbg( p_dec, "ProcessOutput(): no output (i_buffer_out == 0)" );
 #endif
         p_out->vt->Release( (IUnknown *)p_out );
@@ -871,10 +963,10 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     if( p_dec->fmt_out.i_cat == VIDEO_ES )
     {
         /* Get a new picture */
-        picture_t *p_pic = p_dec->pf_vout_buffer_new( p_dec );
+        picture_t *p_pic = decoder_NewPicture( p_dec );
         if( !p_pic ) return NULL;
 
-        CopyPicture( p_dec, p_pic, block_out.p_buffer );
+        CopyPicture( p_pic, block_out.p_buffer );
 
         /* Date management */
         p_pic->date = date_Get( &p_sys->end_date );
@@ -891,15 +983,17 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             ( p_dec->fmt_out.audio.i_bitspersample *
               p_dec->fmt_out.audio.i_channels / 8 );
 
-        p_aout_buffer = p_dec->pf_aout_buffer_new( p_dec, i_samples );
-        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 = decoder_NewAudioBuffer( p_dec, i_samples );
+        if( p_aout_buffer )
+        {
+            memcpy( p_aout_buffer->p_buffer,
+                    block_out.p_buffer, block_out.i_buffer );
+            /* Date management */
+            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 );
 
         return p_aout_buffer;
@@ -908,7 +1002,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     return NULL;
 }
 
-static void CopyPicture( decoder_t *p_dec, picture_t *p_pic, uint8_t *p_in )
+static void CopyPicture( picture_t *p_pic, uint8_t *p_in )
 {
     int i_plane, i_line, i_width, i_dst_stride;
     uint8_t *p_dst, *p_src = p_in;
@@ -925,7 +1019,7 @@ static void CopyPicture( decoder_t *p_dec, picture_t *p_pic, uint8_t *p_in )
 
         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
         {
-            p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width );
+            vlc_memcpy( p_dst, p_src, i_width );
             p_src += i_width;
             p_dst += i_dst_stride;
         }
@@ -936,6 +1030,39 @@ static void CopyPicture( decoder_t *p_dec, picture_t *p_pic, uint8_t *p_in )
     p_pic->p[2].p_pixels = p_dst;
 }
 
+static void *DecoderThread( void *data )
+{
+    decoder_t *p_dec = data;
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    if( DecOpen( p_dec ) )
+        return NULL; /* failed */
+
+    vlc_mutex_lock( &p_sys->lock );
+    for( ;; )
+    {
+        while( p_sys->b_ready && !p_sys->pp_input )
+            vlc_cond_wait( &p_sys->wait_input, &p_sys->lock );
+        if( !p_sys->b_ready )
+            break;
+
+        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 );
+
+    DecClose( p_dec );
+    return NULL;
+}
+
+
 /****************************************************************************
  * Encoder descriptor declaration
  ****************************************************************************/
@@ -960,31 +1087,9 @@ static int EncoderOpen( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t*)p_this;
 
-#ifndef LOADER
     int i_ret = EncOpen( p_this );
     if( i_ret != VLC_SUCCESS ) return i_ret;
 
-#else
-    /* We can't open it now, because of ldt_keeper or something
-     * Open/Encode/Close has to be done in the same thread */
-    int i;
-
-    /* Probe if we support it */
-    for( i = 0; encoders_table[i].i_fourcc != 0; i++ )
-    {
-        if( encoders_table[i].i_fourcc == p_enc->fmt_out.i_codec )
-        {
-            msg_Dbg( p_enc, "DMO codec for %4.4s may work with dll=%s",
-                     (char*)&p_enc->fmt_out.i_codec,
-                     encoders_table[i].psz_dll );
-            break;
-        }
-    }
-
-    p_enc->p_sys = NULL;
-    if( !encoders_table[i].i_fourcc ) return VLC_EGENERIC;
-#endif /* LOADER */
-
     /* Set callbacks */
     p_enc->pf_encode_video = (block_t *(*)(encoder_t *, picture_t *))
         EncodeBlock;
@@ -1005,7 +1110,7 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     BITMAPINFOHEADER *p_bih;
 
     /* FIXME */
-    p_enc->fmt_in.video.i_bits_per_pixel = 
+    p_enc->fmt_in.video.i_bits_per_pixel =
         p_enc->fmt_out.video.i_bits_per_pixel = 12;
 
     /* Enumerate input format (for debug output) */
@@ -1026,11 +1131,10 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
 
     /* Setup input format */
     memset( &dmo_type, 0, sizeof(dmo_type) );
-    dmo_type.pUnk = 0;
     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;
@@ -1044,7 +1148,7 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     vih.rcSource.bottom = p_enc->fmt_in.video.i_height;
     vih.rcTarget = vih.rcSource;
 
-    vih.AvgTimePerFrame = I64C(10000000) / 25; //FIXME
+    vih.AvgTimePerFrame = INT64_C(10000000) / 25; //FIXME
 
     dmo_type.majortype = MEDIATYPE_Video;
     //dmo_type.subtype = MEDIASUBTYPE_RGB24;
@@ -1105,7 +1209,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 );
+                                           &p_privdata );
         if( i_err ) break;
 
         i_err = p_privdata->vt->SetPartialOutputType( p_privdata, &dmo_type );
@@ -1145,7 +1249,7 @@ 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 )
@@ -1173,7 +1277,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
@@ -1193,7 +1297,7 @@ static int EncoderSetAudioType( encoder_t *p_enc, IMediaObject *p_dmo )
             p_wf->nChannels == p_enc->fmt_in.audio.i_channels &&
             p_wf->wBitsPerSample == p_enc->fmt_in.audio.i_bitspersample )
         {
-            if( (int)p_wf->nAvgBytesPerSec <
+            if( p_wf->nAvgBytesPerSec <
                 p_enc->fmt_out.i_bitrate * 110 / 800 /* + 10% */ &&
                 p_wf->nAvgBytesPerSec > i_last_byterate )
             {
@@ -1305,7 +1409,7 @@ static int EncOpen( vlc_object_t *p_this )
     CoInitialize( 0 );
 #endif /* LOADER */
 
-    if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_enc->fmt_out, VLC_TRUE )
+    if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_enc->fmt_out, true )
         != VLC_SUCCESS )
     {
         hmsdmo_dll = 0;
@@ -1323,10 +1427,8 @@ 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 )
     {
-        msg_Err( p_enc, "out of memory" );
         goto error;
     }
 
@@ -1386,7 +1488,7 @@ static int EncOpen( vlc_object_t *p_this )
     CoUninitialize();
 #endif /* LOADER */
 
-    if( p_sys ) free( p_sys );
+    free( p_sys );
 
     return VLC_EGENERIC;
 }
@@ -1404,16 +1506,6 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
     int i_result;
     mtime_t i_pts;
 
-    if( p_sys == NULL )
-    {
-        if( EncOpen( VLC_OBJECT(p_enc) ) )
-        {
-            msg_Err( p_enc, "EncOpen failed" );
-            return NULL;
-        }
-        p_sys = p_enc->p_sys;
-    }
-
     if( !p_data ) return NULL;
 
     if( p_enc->fmt_out.i_cat == VIDEO_ES )
@@ -1440,7 +1532,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++ )
             {
-                p_enc->p_vlc->pf_memcpy( p_dst, p_src, i_width );
+                vlc_memcpy( p_dst, p_src, i_width );
                 p_dst += i_width;
                 p_src += i_src_stride;
             }
@@ -1451,15 +1543,15 @@ 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 );
+        p_block_in = block_New( p_enc, 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 */
-    p_in = CMediaBufferCreate( p_block_in, p_block_in->i_buffer, VLC_TRUE );
+    p_in = CMediaBufferCreate( p_block_in, p_block_in->i_buffer, true );
     i_result = p_sys->p_dmo->vt->ProcessInput( p_sys->p_dmo, 0,
        (IMediaBuffer *)p_in, DMO_INPUT_DATA_BUFFERF_TIME, i_pts * 10, 0 );
 
@@ -1468,7 +1560,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
     {
         /* No output generated */
 #ifdef DMO_DEBUG
-        msg_Dbg( p_enc, "ProcessInput(): no output generated "I64Fd, i_pts );
+        msg_Dbg( p_enc, "ProcessInput(): no output generated %"PRId64, i_pts );
 #endif
         return NULL;
     }
@@ -1483,7 +1575,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
         return NULL;
     }
 
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
     msg_Dbg( p_enc, "ProcessInput(): success" );
 #endif
 
@@ -1496,7 +1588,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
 
         p_block_out = block_New( p_enc, p_sys->i_min_output );
         p_block_out->i_buffer = 0;
-        p_out = CMediaBufferCreate(p_block_out, p_sys->i_min_output, VLC_FALSE);
+        p_out = CMediaBufferCreate(p_block_out, p_sys->i_min_output, false);
         memset( &db, 0, sizeof(db) );
         db.pBuffer = (IMediaBuffer *)p_out;
 
@@ -1507,7 +1599,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
         {
             if( i_result != S_FALSE )
                 msg_Dbg( p_enc, "ProcessOutput(): failed: %x", i_result );
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
             else
                 msg_Dbg( p_enc, "ProcessOutput(): no output" );
 #endif
@@ -1519,7 +1611,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
 
         if( !p_block_out->i_buffer )
         {
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
             msg_Dbg( p_enc, "ProcessOutput(): no output (i_buffer_out == 0)" );
 #endif
             p_out->vt->Release( (IUnknown *)p_out );
@@ -1529,8 +1621,8 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
 
         if( db.dwStatus & DMO_OUTPUT_DATA_BUFFERF_TIME )
         {
-#if DMO_DEBUG
-            msg_Dbg( p_enc, "ProcessOutput(): pts: "I64Fd", "I64Fd,
+#ifdef DMO_DEBUG
+            msg_Dbg( p_enc, "ProcessOutput(): pts: %"PRId64", %"PRId64,
                      i_pts, db.rtTimestamp / 10 );
 #endif
             i_pts = db.rtTimestamp / 10;
@@ -1539,8 +1631,8 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
         if( db.dwStatus & DMO_OUTPUT_DATA_BUFFERF_TIMELENGTH )
         {
             p_block_out->i_length = db.rtTimelength / 10;
-#if DMO_DEBUG
-            msg_Dbg( p_enc, "ProcessOutput(): length: "I64Fd,
+#ifdef DMO_DEBUG
+            msg_Dbg( p_enc, "ProcessOutput(): length: %"PRId64,
                      p_block_out->i_length );
 #endif
         }