]> git.sesse.net Git - vlc/blobdiff - modules/codec/dmo/dmo.c
DMO/loader patch from Alex Antropoff.
[vlc] / modules / codec / dmo / dmo.c
index ad366a8909ba3b23983d6871fbccc8db3575e247..7e22a3dd2471102e9ce8f0930533f2b8dcd1e7a2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * dmo.c : DirectMedia Object decoder module for vlc
  *****************************************************************************
- * Copyright (C) 2002, 2003 VideoLAN
+ * Copyright (C) 2002, 2003 the VideoLAN team
  * $Id$
  *
  * Author: Gildas Bazin <gbazin@videolan.org>
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/vout.h>
+#include <vlc_codec.h>
+#include <vlc_vout.h>
+#include <vlc_aout.h>
 
 #ifndef WIN32
 #    define LOADER
@@ -45,7 +43,7 @@
 #   include <wine/windef.h>
 #endif
 
-#include "codecs.h"
+#include <vlc_codecs.h>
 #include "dmo.h"
 
 //#define DMO_DEBUG 1
@@ -60,9 +58,10 @@ HMODULE WINAPI LoadLibraryA(LPCSTR);
 #define LoadLibrary LoadLibraryA
 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
 int     WINAPI FreeLibrary(HMODULE);
-typedef long STDCALL (*GETCLASS) ( const GUID*, const GUID*, void** );
 #endif /* LOADER */
 
+typedef long (STDCALL *GETCLASS) ( const GUID*, const GUID*, void** );
+
 static int pi_channels_maps[7] =
 {
     0,
@@ -99,6 +98,8 @@ vlc_module_begin();
     add_shortcut( "dmo" );
     set_capability( "decoder", 1 );
     set_callbacks( DecoderOpen, DecoderClose );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_SCODEC );
 
 #   define ENC_CFG_PREFIX "sout-dmo-"
     add_submodule();
@@ -130,14 +131,18 @@ struct decoder_sys_t
 #endif
 };
 
-#ifdef LOADER
+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
@@ -150,8 +155,12 @@ typedef struct
 
 static const codec_dll decoders_table[] =
 {
-    /* WM3 */
+    /* WVC1 */
+    { VLC_FOURCC('W','V','C','1'), "wvc1dmod.dll", &guid_wvc1 },
+    { VLC_FOURCC('w','v','c','1'), "wvc1dmod.dll", &guid_wvc1 },
+    /* WMV3 */
     { 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','3'), "wmv9dmod.dll", &guid_wmv9 },
     /* WMV2 */
     { VLC_FOURCC('W','M','V','2'), "wmvdmod.dll", &guid_wmv },
@@ -159,26 +168,39 @@ static const codec_dll decoders_table[] =
     /* WMV1 */
     { VLC_FOURCC('W','M','V','1'), "wmvdmod.dll", &guid_wmv },
     { VLC_FOURCC('w','m','v','1'), "wmvdmod.dll", &guid_wmv },
+    /* Screen codecs */
+    { VLC_FOURCC('M','S','S','1'), "wmsdmod.dll", &guid_wms },
+    { VLC_FOURCC('M','S','S','2'), "wmsdmod.dll", &guid_wms },
+    /* Windows Media Video Adv */
+    { VLC_FOURCC('W','M','V','A'), "wmvadvd.dll", &guid_wmva },
+    { VLC_FOURCC('W','V','P','2'), "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 },
     /* WMA 2 */
     { VLC_FOURCC('W','M','A','2'), "wma9dmod.dll", &guid_wma9 },
     { VLC_FOURCC('w','m','a','2'), "wma9dmod.dll", &guid_wma9 },
 
+    /* WMA Speech */
+    { VLC_FOURCC('w','m','a','s'), "wmspdmod.dll", &guid_wma },
+
     /* */
     { 0, NULL, NULL }
 };
 
 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 },
     /* WMV2 */
-    { VLC_FOURCC('W','M','V','2'), "wmvdmoe.dll", &guid_wmv_enc },
-    { VLC_FOURCC('w','m','v','1'), "wmvdmoe.dll", &guid_wmv_enc },
+    { VLC_FOURCC('W','M','V','2'), "wmvdmoe2.dll", &guid_wmv_enc2 },
+    { VLC_FOURCC('w','m','v','2'), "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_FOURCC('W','M','V','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },
+    { VLC_FOURCC('w','m','v','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },
 
     /* WMA 3 */
     { VLC_FOURCC('W','M','A','3'), "wmadmoe.dll", &guid_wma_enc },
@@ -191,8 +213,6 @@ static const codec_dll encoders_table[] =
     { 0, NULL, NULL }
 };
 
-#endif /* LOADER */
-
 static void WINAPI DMOFreeMediaType( DMO_MEDIA_TYPE *mt )
 {
     if( mt->cbFormat != 0 ) CoTaskMemFree( (PVOID)mt->pbFormat );
@@ -390,29 +410,55 @@ static int DecOpen( vlc_object_t *p_this )
     else
     {
         BITMAPINFOHEADER *p_bih;
+        DMO_MEDIA_TYPE mt;
+        unsigned i_chroma = VLC_FOURCC('Y','U','Y','2');
+        int i_planes = 1, i_bpp = 16;
+        int i = 0;
 
-        p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','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') )
+            {
+                i_chroma = mt.subtype.Data1;
+                i_planes = 3; i_bpp = 12;
+            }
+
+            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.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 = 12;
-        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_bits_per_pixel = i_bpp;
 
-        dmo_output_type.formattype = FORMAT_VideoInfo;
-        dmo_output_type.subtype = MEDIASUBTYPE_YV12;
+        /* If an aspect-ratio was specified in the input format then force it */
+        if( p_dec->fmt_in.video.i_aspect )
+        {
+            p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect;
+        }
+        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_bih = &p_vih->bmiHeader;
-        p_bih->biCompression = VLC_FOURCC('Y','V','1','2');
+        p_bih->biCompression = 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 = 1;
+        p_bih->biPlanes = i_planes;
         p_bih->biSize = sizeof(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;
         dmo_output_type.bFixedSizeSamples = VLC_TRUE;
         dmo_output_type.bTemporalCompression = 0;
         dmo_output_type.lSampleSize = p_bih->biSizeImage;
@@ -519,17 +565,22 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     int i_err;
 
 #ifndef LOADER
+    long (STDCALL *OurDMOEnum)( const GUID *, uint32_t, uint32_t,
+                               const DMO_PARTIAL_MEDIATYPE *,
+                               uint32_t, const DMO_PARTIAL_MEDIATYPE *,
+                               IEnumDMO ** );
+
     IEnumDMO *p_enum_dmo = NULL;
     WCHAR *psz_dmo_name;
     GUID clsid_dmo;
-#else
+    uint32_t i_dummy;
+#endif
 
     GETCLASS GetClass;
     IClassFactory *cFactory = NULL;
     IUnknown *cObject = NULL;
-    codec_dll *codecs_table = b_out ? encoders_table : decoders_table;
+    const codec_dll *codecs_table = b_out ? encoders_table : decoders_table;
     int i_codec;
-#endif
 
     /* Look for a DMO which can handle the requested codec */
     if( p_fmt->i_cat == AUDIO_ES )
@@ -549,11 +600,6 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     }
 
 #ifndef LOADER
-    long (STDCALL *OurDMOEnum)( const GUID *, uint32_t, uint32_t,
-                               const DMO_PARTIAL_MEDIATYPE *,
-                               uint32_t, const DMO_PARTIAL_MEDIATYPE *,
-                               IEnumDMO ** );
-
     /* Load msdmo DLL */
     *p_hmsdmo_dll = LoadLibrary( "msdmo.dll" );
     if( *p_hmsdmo_dll == NULL )
@@ -577,46 +623,51 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     else
     {
         i_err = OurDMOEnum( &GUID_NULL, 1 /*DMO_ENUMF_INCLUDE_KEYED*/,
-                             0, NULL, 1, &dmo_partial_type, &p_enum_dmo );
+                            0, NULL, 1, &dmo_partial_type, &p_enum_dmo );
     }
     if( i_err )
     {
-        CoUninitialize();
         FreeLibrary( *p_hmsdmo_dll );
-        return VLC_EGENERIC;
+        /* return VLC_EGENERIC; */
+        /* Try loading the dll directly */
+        goto loader;
     }
 
     /* Pickup the first available codec */
-    if( p_enum_dmo->vt->Next( p_enum_dmo, 1, &clsid_dmo,
-                              &psz_dmo_name, NULL ) )
-    {
-        CoUninitialize();
-        FreeLibrary( *p_hmsdmo_dll );
-        return VLC_EGENERIC;
-    }
-    p_enum_dmo->vt->Release( (IUnknown *)p_enum_dmo );
-
-#if 1
+    *pp_dmo = 0;
+    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 );
         msg_Dbg( p_this, "found DMO: %s", psz_temp );
+        CoTaskMemFree( psz_dmo_name );
+
+        /* Create DMO */
+        if( CoCreateInstance( &clsid_dmo, NULL, CLSCTX_INPROC,
+                              &IID_IMediaObject, (void **)pp_dmo ) )
+        {
+            msg_Warn( p_this, "can't create DMO: %s", psz_temp );
+            *pp_dmo = 0;
+        }
+        else break;
     }
-#endif
 
-    CoTaskMemFree( psz_dmo_name );
+    p_enum_dmo->vt->Release( (IUnknown *)p_enum_dmo );
 
-    /* Create DMO */
-    if( CoCreateInstance( &clsid_dmo, NULL, CLSCTX_INPROC,
-                          &IID_IMediaObject, (void **)pp_dmo ) )
+    if( !*pp_dmo )
     {
-        msg_Err( p_this, "can't create DMO" );
-        CoUninitialize();
         FreeLibrary( *p_hmsdmo_dll );
-        return VLC_EGENERIC;
+        /* return VLC_EGENERIC; */
+        /* Try loading the dll directly */
+        goto loader;
     }
 
-#else   /* LOADER */
+    return VLC_SUCCESS;
+
+loader:
+#endif   /* LOADER */
+
     for( i_codec = 0; codecs_table[i_codec].i_fourcc != 0; i_codec++ )
     {
         if( codecs_table[i_codec].i_fourcc == p_fmt->i_codec )
@@ -668,7 +719,6 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
         FreeLibrary( *p_hmsdmo_dll );
         return VLC_EGENERIC;
     }
-#endif  /* LOADER */
 
     return VLC_SUCCESS;
 }
@@ -683,6 +733,7 @@ void DecoderClose( vlc_object_t *p_this )
 
     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 );
 
 #ifdef LOADER
@@ -768,7 +819,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 #endif
             return NULL;
         }
-        else if( i_result == DMO_E_NOTACCEPTING )
+        else if( i_result == (int)DMO_E_NOTACCEPTING )
         {
             /* Need to call ProcessOutput */
             msg_Dbg( p_dec, "ProcessInput(): not accepting" );
@@ -806,7 +857,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
@@ -815,13 +866,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 );
@@ -885,7 +936,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 );
+            p_dec->p_libvlc->pf_memcpy( p_dst, p_src, i_width );
             p_src += i_width;
             p_dst += i_dst_stride;
         }
@@ -920,31 +971,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;
@@ -965,7 +994,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) */
@@ -986,7 +1015,6 @@ 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;
@@ -1093,7 +1121,7 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
         memcpy( p_vih, dmo_type.pbFormat, dmo_type.cbFormat );
         memcpy( ((uint8_t *)p_vih) + dmo_type.cbFormat, p_data, i_data );
         DMOFreeMediaType( &dmo_type );
-        dmo_type.pbFormat = p_vih;
+        dmo_type.pbFormat = (char*)p_vih;
         dmo_type.cbFormat = i_vih;
 
         msg_Dbg( p_enc, "found extra data: %i", i_data );
@@ -1105,10 +1133,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_out.video.i_width = p_enc->fmt_in.video.i_width;
-    p_enc->fmt_out.video.i_height = p_enc->fmt_in.video.i_height;
-    p_enc->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR *
-      p_enc->fmt_out.video.i_width / p_enc->fmt_out.video.i_height;
+    p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
 
     DMOFreeMediaType( &dmo_type );
     if( i_err )
@@ -1136,7 +1161,8 @@ 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.audio.i_bitspersample = 16; // Forced
+    p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
+    p_enc->fmt_in.audio.i_bitspersample = 16;
 
     /* We first need to choose an output type from the predefined
      * list of choices (we cycle through the list to select the best match) */
@@ -1171,7 +1197,7 @@ static int EncoderSetAudioType( encoder_t *p_enc, IMediaObject *p_dmo )
 
     if( i_selected < 0 )
     {
-        msg_Err( p_enc, "couldn't find a matching ouput" );
+        msg_Err( p_enc, "couldn't find a matching output" );
         return VLC_EGENERIC;
     }
 
@@ -1366,16 +1392,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 )
@@ -1402,7 +1418,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 );
+                p_enc->p_libvlc->pf_memcpy( p_dst, p_src, i_width );
                 p_dst += i_width;
                 p_src += i_src_stride;
             }
@@ -1434,7 +1450,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
 #endif
         return NULL;
     }
-    else if( i_result == DMO_E_NOTACCEPTING )
+    else if( i_result == (int)DMO_E_NOTACCEPTING )
     {
         /* Need to call ProcessOutput */
         msg_Dbg( p_enc, "ProcessInput(): not accepting" );
@@ -1445,7 +1461,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
 
@@ -1469,7 +1485,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
@@ -1481,7 +1497,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 );
@@ -1491,7 +1507,7 @@ static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
 
         if( db.dwStatus & DMO_OUTPUT_DATA_BUFFERF_TIME )
         {
-#if DMO_DEBUG
+#ifdef DMO_DEBUG
             msg_Dbg( p_enc, "ProcessOutput(): pts: "I64Fd", "I64Fd,
                      i_pts, db.rtTimestamp / 10 );
 #endif
@@ -1501,7 +1517,7 @@ 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
+#ifdef DMO_DEBUG
             msg_Dbg( p_enc, "ProcessOutput(): length: "I64Fd,
                      p_block_out->i_length );
 #endif
@@ -1530,6 +1546,7 @@ void EncoderClose( vlc_object_t *p_this )
 
     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 );
 
 #ifdef LOADER