]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/waveout.c
Fix potential memleak.
[vlc] / modules / audio_output / waveout.c
index b329d1478136b33bb1bac4584be2b1d93dd617c4..bf9ac039186fd44a0fb4954c82d4906ccbb77b7e 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_charset.h>
 
@@ -143,8 +144,8 @@ static uint32_t findDeviceID(char *);
 
 static const char psz_device_name_fmt[] = "%s ($%x,$%x)";
 
-static const char *ppsz_adev[] = { "wavemapper", };
-static const char *ppsz_adev_text[] = { N_("Microsoft Soundmapper") };
+static const char *const ppsz_adev[] = { "wavemapper", };
+static const char *const ppsz_adev_text[] = { N_("Microsoft Soundmapper") };
 
 
 
@@ -163,7 +164,7 @@ static const char *ppsz_adev_text[] = { N_("Microsoft Soundmapper") };
 
 vlc_module_begin();
     set_shortname( "WaveOut" );
-    set_description( _("Win32 waveOut extension output") );
+    set_description( N_("Win32 waveOut extension output") );
     set_capability( "audio output", 50 );
     set_category( CAT_AUDIO );
     set_subcategory( SUBCAT_AUDIO_AOUT );
@@ -244,10 +245,7 @@ static int Open( vlc_object_t *p_this )
     p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );
 
     if( p_aout->output.p_sys == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
-        return VLC_EGENERIC;
-    }
+        return VLC_ENOMEM;
 
     p_aout->output.pf_play = Play;
     p_aout->b_die = false;
@@ -410,7 +408,6 @@ static int Open( vlc_object_t *p_this )
     if( p_aout->output.p_sys->p_silence_buffer == NULL )
     {
         free( p_aout->output.p_sys );
-        msg_Err( p_aout, "out of memory" );
         return 1;
     }
     p_aout->output.p_sys->i_repeat_counter = 0;
@@ -858,9 +855,9 @@ static int PlayWaveOut( aout_instance_t *p_aout, HWAVEOUT h_waveout,
         */
         if(b_spdif)
         {
-           p_aout->p_libvlc->pf_memcpy( p_aout->output.p_sys->p_silence_buffer,
-                                     p_buffer->p_buffer,
-                                     p_aout->output.p_sys->i_buffer_size );
+           vlc_memcpy( p_aout->output.p_sys->p_silence_buffer,
+                       p_buffer->p_buffer,
+                       p_aout->output.p_sys->i_buffer_size );
            p_aout->output.p_sys->i_repeat_counter = 2;
         }
     } else {
@@ -870,10 +867,8 @@ static int PlayWaveOut( aout_instance_t *p_aout, HWAVEOUT h_waveout,
            p_aout->output.p_sys->i_repeat_counter--;
            if(!p_aout->output.p_sys->i_repeat_counter)
            {
-               p_aout->p_libvlc->pf_memset( p_aout->output.p_sys->p_silence_buffer,
-                                            0x00,
-                                            p_aout->output.p_sys->i_buffer_size
-                                          );
+               vlc_memset( p_aout->output.p_sys->p_silence_buffer,
+                           0x00, p_aout->output.p_sys->i_buffer_size );
            }
         }
         p_waveheader->lpData = p_aout->output.p_sys->p_silence_buffer;
@@ -913,7 +908,7 @@ static void CALLBACK WaveOutCallback( HWAVEOUT h_waveout, UINT uMsg,
 
     if( uMsg != WOM_DONE ) return;
 
-    if( p_aout->b_die ) return;
+    if( !vlc_object_alive (p_aout) ) return;
 
     /* Find out the current latency */
     for( i = 0; i < FRAMES_NUM; i++ )
@@ -989,12 +984,12 @@ static void WaveOutThread( notification_thread_t *p_notif )
     b_sleek = p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i');
 
     // wait for first call to "play()"
-    while( !p_sys->start_date && !p_aout->b_die )
+    while( !p_sys->start_date && vlc_object_alive (p_aout) )
            WaitForSingleObject( p_sys->event, INFINITE );
-    if( p_aout->b_die )
+    if( !vlc_object_alive (p_aout) )
         return;
 
-    msg_Dbg( p_aout, "will start to play in "I64Fd" us",
+    msg_Dbg( p_aout, "will start to play in %"PRId64" us",
              (p_sys->start_date - AOUT_PTS_TOLERANCE/4)-mdate());
 
     // than wait a short time... before grabbing first frames
@@ -1008,12 +1003,12 @@ static void WaveOutThread( notification_thread_t *p_notif )
                            p_aout->output.b_starving, msg);
     next_date = mdate();
 
-    while( !p_aout->b_die )
+    while( vlc_object_alive (p_aout) )
     {
         /* Cleanup and find out the current latency */
         i_queued_frames = WaveOutClearDoneBuffers( p_sys );
 
-        if( p_aout->b_die ) return;
+        if( !vlc_object_alive (p_aout) ) return;
 
         /* Try to fill in as many frame buffers as possible */
         for( i = 0; i < FRAMES_NUM; i++ )
@@ -1089,7 +1084,7 @@ static void WaveOutThread( notification_thread_t *p_notif )
             }
         }
 
-        if( p_aout->b_die ) return;
+        if( !vlc_object_alive (p_aout) ) return;
 
         /*
           deal with the case that the loop didn't fillup the buffer to the