]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/waveout.c
mozilla: fix out-of-tree compilation on macosx
[vlc] / modules / audio_output / waveout.c
index aef828567d5334aff6f13790c9dc9f72ed4d94de..b7efbe2c413d00f51511acfa9f71d49f03ab2e4b 100644 (file)
@@ -1,16 +1,16 @@
 /*****************************************************************************
  * waveout.c : Windows waveOut plugin for vlc
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2001 the VideoLAN team
  * $Id$
  *
  * Authors: 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
  * (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
  *
  * 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 <string.h>                                            /* strerror() */
-#include <stdlib.h>                            /* calloc(), malloc(), free() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include "aout_internal.h"
+#include <vlc_aout.h>
 
 #include <windows.h>
 #include <mmsystem.h>
  *****************************************************************************/
 #ifdef UNDER_CE
 #   define DWORD_PTR DWORD
+#   ifdef waveOutGetDevCaps
+#       undef waveOutGetDevCaps
+        MMRESULT WINAPI waveOutGetDevCaps(UINT, LPWAVEOUTCAPS, UINT);
+#   endif
 #endif
 
 #ifndef WAVE_FORMAT_IEEE_FLOAT
@@ -250,6 +255,8 @@ static int Open( vlc_object_t *p_this )
     }
     else
     {
+        WAVEOUTCAPS wocaps;
+
         if( val.i_int == AOUT_VAR_5_1 )
         {
             p_aout->output.output.i_physical_channels
@@ -292,9 +299,20 @@ static int Open( vlc_object_t *p_this )
 
         aout_VolumeSoftInit( p_aout );
 
-        p_aout->output.pf_volume_infos = VolumeInfos;
-        p_aout->output.pf_volume_get = VolumeGet;
-        p_aout->output.pf_volume_set = VolumeSet;
+        /* Check for hardware volume support */
+        if( waveOutGetDevCaps( (UINT_PTR)p_aout->output.p_sys->h_waveout,
+                               &wocaps, sizeof(wocaps) ) == MMSYSERR_NOERROR &&
+            wocaps.dwSupport & WAVECAPS_VOLUME )
+        {
+            DWORD i_dummy;
+            if( waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_dummy )
+                == MMSYSERR_NOERROR )
+            {
+                p_aout->output.pf_volume_infos = VolumeInfos;
+                p_aout->output.pf_volume_get = VolumeGet;
+                p_aout->output.pf_volume_set = VolumeSet;
+            }
+        }
     }
 
 
@@ -470,7 +488,7 @@ static void Close( vlc_object_t *p_this )
     aout_sys_t *p_sys = p_aout->output.p_sys;
 
     /* Before calling waveOutClose we must reset the device */
-    p_aout->b_die = VLC_TRUE;
+    vlc_object_kill( p_aout );
 
     waveOutReset( p_sys->h_waveout );
 
@@ -698,7 +716,7 @@ static void CALLBACK WaveOutCallback( HWAVEOUT h_waveout, UINT uMsg,
 }
 
 /*****************************************************************************
- * WaveOutThread: this thread will capture play notification events. 
+ * WaveOutThread: this thread will capture play notification events.
  *****************************************************************************
  * We use this thread to feed new audio samples to the sound card because
  * we are not authorized to use waveOutWrite() directly in the waveout
@@ -727,12 +745,14 @@ static void WaveOutThread( notification_thread_t *p_notif )
             if( (p_waveheader[i].dwFlags & WHDR_DONE) &&
                 p_waveheader[i].dwUser )
             {
+                aout_buffer_t *p_buffer =
+                        (aout_buffer_t *)(p_waveheader[i].dwUser);
                 /* Unprepare and free the buffers which has just been played */
                 waveOutUnprepareHeader( p_sys->h_waveout, &p_waveheader[i],
                                         sizeof(WAVEHDR) );
 
                 if( p_waveheader[i].dwUser != 1 )
-                    aout_BufferFree( (aout_buffer_t *)p_waveheader[i].dwUser );
+                    aout_BufferFree( p_buffer );
 
                 p_waveheader[i].dwUser = 0;
             }
@@ -801,7 +821,7 @@ static int VolumeGet( aout_instance_t * p_aout, audio_volume_t * pi_volume )
 
     i_waveout_vol &= 0xFFFF;
     *pi_volume = p_aout->output.i_volume =
-        i_waveout_vol * AOUT_VOLUME_MAX / 2 / 0xFFFF;
+        (i_waveout_vol * AOUT_VOLUME_MAX + 0xFFFF /*rounding*/) / 2 / 0xFFFF;
     return 0;
 }