]> git.sesse.net Git - vlc/blobdiff - modules/codec/dmo/dmo.c
DMO: use FromWide(), fix charset
[vlc] / modules / codec / dmo / dmo.c
index 159d5f12c596891f6f5613460f657b6bd3011d76..33c30775765ccf0db381d5ab3c2062d5e6204a62 100644 (file)
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
-#include <vlc_vout.h>
 #include <vlc_aout.h>
 
 #ifndef WIN32
 #    define LOADER
 #else
 #   include <objbase.h>
+#   include <vlc_charset.h>
 #endif
 
 #ifdef LOADER
@@ -104,7 +104,7 @@ vlc_module_begin ()
     set_capability( "decoder", 1 )
     set_callbacks( DecoderOpen, DecoderClose )
     set_category( CAT_INPUT )
-    set_subcategory( SUBCAT_INPUT_SCODEC )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
 
 #   define ENC_CFG_PREFIX "sout-dmo-"
     add_submodule ()
@@ -141,7 +141,9 @@ struct decoder_sys_t
     vlc_cond_t   wait_input, wait_output;
     bool         b_ready, b_works;
     block_t    **pp_input;
-    void        *p_output;
+
+    int          i_output;
+    void       **pp_output;
 };
 
 const GUID IID_IWMCodecPrivateData = {0x73f0be8e, 0x57f7, 0x4f01, {0xaa, 0x66, 0x9f, 0x57, 0x34, 0xc, 0xfe, 0xe}};
@@ -201,6 +203,8 @@ static const codec_dll decoders_table[] =
 
     /* WMA 3 */
     { VLC_CODEC_WMAP,   "wma9dmod.dll", &guid_wma9 },
+    { VLC_CODEC_WMAL,   "wma9dmod.dll", &guid_wma9 },
+
     /* WMA 2 */
     { VLC_CODEC_WMA2,   "wma9dmod.dll", &guid_wma9 },
 
@@ -279,7 +283,7 @@ found:
     p_sys->b_works =
     p_sys->b_ready = false;
     p_sys->pp_input = NULL;
-    p_sys->p_output = NULL;
+    TAB_INIT( p_sys->i_output, p_sys->pp_output );
 
     if( vlc_clone( &p_sys->thread, DecoderThread, p_dec,
                    VLC_THREAD_PRIORITY_INPUT ) )
@@ -316,6 +320,7 @@ static void DecoderClose( vlc_object_t *p_this )
     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 );
@@ -328,12 +333,22 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     void *p_ret;
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->pp_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( p_sys->pp_input )
-        vlc_cond_wait( &p_sys->wait_output, &p_sys->lock );
-    p_ret = p_sys->p_output;
     vlc_mutex_unlock( &p_sys->lock );
 
     return p_ret;
@@ -452,7 +467,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
@@ -506,14 +521,16 @@ static int DecOpen( decoder_t *p_dec )
         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;
@@ -712,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 );
 
@@ -722,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 );
@@ -767,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" );
@@ -776,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 )
     {
@@ -785,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 )
     {
@@ -837,10 +858,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 );
@@ -888,7 +910,9 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
         }
         else
         {
-            //msg_Dbg( p_dec, "ProcessInput(): successful" );
+#ifdef DMO_DEBUG
+            msg_Dbg( p_dec, "ProcessInput(): successful" );
+#endif
             *pp_block = NULL;
         }
     }
@@ -965,9 +989,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 );
 
@@ -1021,7 +1046,13 @@ static void *DecoderThread( void *data )
         if( !p_sys->b_ready )
             break;
 
-        p_sys->p_output = DecBlock( p_dec, p_sys->pp_input );
+        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 );
     }
@@ -1178,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 );
@@ -1246,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
@@ -1512,11 +1543,11 @@ 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 */