* GNU General Public License for more details.
*
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
-#include <vlc_charset.h>
+#include <vlc_charset.h> /* FromLocaleDup, LocaleFree */
+#include <vlc_atomic.h>
#include "windows_audio_common.h"
/*****************************************************************************
* notification_thread_t: waveOut event thread
*****************************************************************************/
-typedef struct notification_thread_t
-{
- VLC_COMMON_MEMBERS
- aout_instance_t *p_aout;
-
-} notification_thread_t;
-
/* local functions */
static void Probe ( aout_instance_t * );
static int OpenWaveOut ( aout_instance_t *, uint32_t,
aout_buffer_t *, bool );
static void CALLBACK WaveOutCallback ( HWAVEOUT, UINT, DWORD, DWORD, DWORD );
-static void* WaveOutThread( vlc_object_t * );
+static void* WaveOutThread( void * );
-static int VolumeGet( aout_instance_t *, audio_volume_t * );
-static int VolumeSet( aout_instance_t *, audio_volume_t );
+static int VolumeSet( aout_instance_t *, audio_volume_t, bool );
static int WaveOutClearDoneBuffers(aout_sys_t *p_sys);
static const char *const ppsz_adev_text[] = { N_("Microsoft Soundmapper") };
-
/*****************************************************************************
* Module descriptor
*****************************************************************************/
DEVICE_TEXT, DEVICE_LONG, false )
add_deprecated_alias( "waveout-dev" ) /* deprecated since 0.9.3 */
change_string_list( ppsz_adev, ppsz_adev_text, ReloadWaveoutDevices )
- change_need_restart ()
change_action_add( ReloadWaveoutDevices, N_("Refresh list") )
-
set_callbacks( Open, Close )
vlc_module_end ()
WAVEHDR waveheader[FRAMES_NUM];
- notification_thread_t *p_notif; /* WaveOutThread id */
+ vlc_thread_t thread;
+ vlc_atomic_t abort;
HANDLE event;
HANDLE new_buffer_event;
if( waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_dummy )
== MMSYSERR_NOERROR )
{
- p_aout->output.pf_volume_get = VolumeGet;
p_aout->output.pf_volume_set = VolumeSet;
}
}
p_aout->output.p_sys->i_buffer_size );
/* Now we need to setup our waveOut play notification structure */
- p_aout->output.p_sys->p_notif =
- vlc_object_create( p_aout, sizeof(notification_thread_t) );
- p_aout->output.p_sys->p_notif->p_aout = p_aout;
p_aout->output.p_sys->event = CreateEvent( NULL, FALSE, FALSE, NULL );
p_aout->output.p_sys->new_buffer_event = CreateEvent( NULL, FALSE, FALSE, NULL );
/* Then launch the notification thread */
- if( vlc_thread_create( p_aout->output.p_sys->p_notif,
- WaveOutThread, VLC_THREAD_PRIORITY_OUTPUT ) )
+ vlc_atomic_set( &p_aout->output.p_sys->abort, 0);
+ if( vlc_clone( &p_aout->output.p_sys->thread,
+ WaveOutThread, p_aout, VLC_THREAD_PRIORITY_OUTPUT ) )
{
msg_Err( p_aout, "cannot create WaveOutThread" );
}
}
var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL );
- var_SetBool( p_aout, "intf-change", true );
+ var_TriggerCallback( p_aout, "intf-change" );
}
/*****************************************************************************
aout_sys_t *p_sys = p_aout->output.p_sys;
/* Before calling waveOutClose we must reset the device */
- vlc_object_kill( p_aout );
+ vlc_atomic_set( &p_sys->abort, 1);
/* wake up the audio thread, to recognize that p_aout died */
SetEvent( p_sys->event );
SetEvent( p_sys->new_buffer_event );
- vlc_thread_join( p_sys->p_notif );
- vlc_object_release( p_sys->p_notif );
+ vlc_join( p_sys->thread, NULL );
/*
kill the real output then - when the feed thread
bool b_probe )
{
MMRESULT result;
- unsigned int i;
/* Set sound format */
#define waveformat p_aout->output.p_sys->waveformat
waveformat.dwChannelMask = 0;
- for( i = 0; i < sizeof(pi_channels_src)/sizeof(uint32_t); i++ )
+ for( unsigned i = 0; i < sizeof(pi_channels_src)/sizeof(uint32_t); i++ )
{
if( i_channels & pi_channels_src[i] )
waveformat.dwChannelMask |= pi_channels_in[i];
/* Prepare the buffer */
if( p_buffer != NULL )
{
- p_waveheader->lpData = p_buffer->p_buffer;
+ p_waveheader->lpData = (LPSTR)p_buffer->p_buffer;
/*
copy the buffer to the silence buffer :) so in case we don't
get the next buffer fast enough (I will repeat this one a time
0x00, p_aout->output.p_sys->i_buffer_size );
}
}
- p_waveheader->lpData = p_aout->output.p_sys->p_silence_buffer;
+ p_waveheader->lpData = (LPSTR)p_aout->output.p_sys->p_silence_buffer;
}
p_waveheader->dwUser = p_buffer ? (DWORD_PTR)p_buffer : (DWORD_PTR)1;
{
(void)h_waveout; (void)dwParam1; (void)dwParam2;
aout_instance_t *p_aout = (aout_instance_t *)_p_aout;
- int i, i_queued_frames = 0;
+ int i_queued_frames = 0;
if( uMsg != WOM_DONE ) return;
- if( !vlc_object_alive (p_aout) ) return;
+ if( vlc_atomic_get(&p_aout->output.p_sys->abort) ) return;
/* Find out the current latency */
- for( i = 0; i < FRAMES_NUM; i++ )
+ for( int i = 0; i < FRAMES_NUM; i++ )
{
/* Check if frame buf is available */
if( !(p_aout->output.p_sys->waveheader[i].dwFlags & WHDR_DONE) )
* we are not authorized to use waveOutWrite() directly in the waveout
* callback.
*****************************************************************************/
-static void* WaveOutThread( vlc_object_t *p_this )
+static void* WaveOutThread( void *data )
{
- notification_thread_t *p_notif = (notification_thread_t*)p_this;
- aout_instance_t *p_aout = p_notif->p_aout;
+ aout_instance_t *p_aout = data;
aout_sys_t *p_sys = p_aout->output.p_sys;
aout_buffer_t *p_buffer = NULL;
WAVEHDR *p_waveheader = p_sys->waveheader;
b_sleek = p_aout->output.output.i_format == VLC_CODEC_SPDIFL;
// wait for first call to "play()"
- while( !p_sys->start_date && vlc_object_alive (p_aout) )
+ while( !p_sys->start_date && !vlc_atomic_get(&p_aout->output.p_sys->abort) )
WaitForSingleObject( p_sys->event, INFINITE );
- if( !vlc_object_alive (p_aout) )
+ if( vlc_atomic_get(&p_aout->output.p_sys->abort) )
return NULL;
msg_Dbg( p_aout, "will start to play in %"PRId64" us",
p_aout->output.b_starving, msg);
next_date = mdate();
- while( vlc_object_alive (p_aout) )
+ while( !vlc_atomic_get(&p_aout->output.p_sys->abort) )
{
/* Cleanup and find out the current latency */
i_queued_frames = WaveOutClearDoneBuffers( p_sys );
- if( !vlc_object_alive (p_aout) ) return NULL;
+ if( vlc_atomic_get(&p_aout->output.p_sys->abort) ) return NULL;
/* Try to fill in as many frame buffers as possible */
for( i = 0; i < FRAMES_NUM; i++ )
}
}
- if( !vlc_object_alive (p_aout) ) return NULL;
+ if( vlc_atomic_get(&p_aout->output.p_sys->abort) ) return NULL;
/*
deal with the case that the loop didn't fillup the buffer to the
return NULL;
}
-static int VolumeGet( aout_instance_t * p_aout, audio_volume_t * pi_volume )
+static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume,
+ bool mute )
{
- DWORD i_waveout_vol;
-
-#ifdef UNDER_CE
- waveOutGetVolume( 0, &i_waveout_vol );
-#else
- waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_waveout_vol );
-#endif
-
- i_waveout_vol &= 0xFFFF;
- *pi_volume = p_aout->output.i_volume =
- (i_waveout_vol * AOUT_VOLUME_MAX + 0xFFFF /*rounding*/) / 2 / 0xFFFF;
- return 0;
-}
+ if( mute )
+ i_volume = AOUT_VOLUME_MIN;
-static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume )
-{
unsigned long i_waveout_vol = i_volume * 0xFFFF * 2 / AOUT_VOLUME_MAX;
i_waveout_vol |= (i_waveout_vol << 16);
#else
waveOutSetVolume( p_aout->output.p_sys->h_waveout, i_waveout_vol );
#endif
-
- p_aout->output.i_volume = i_volume;
return 0;
}
*/
static uint32_t findDeviceID(char *psz_device_name)
{
- if(!psz_device_name)
+ if( !psz_device_name )
return WAVE_MAPPER;
uint32_t wave_devices = waveOutGetNumDevs();
WAVEOUTCAPS caps;
char sz_dev_name[MAXPNAMELEN+32];
- for(uint32_t i=0; i<wave_devices; i++)
+
+ for( uint32_t i = 0; i < wave_devices; i++ )
{
- if(waveOutGetDevCaps(i, &caps, sizeof(WAVEOUTCAPS))
+ if( waveOutGetDevCaps( i, &caps, sizeof(WAVEOUTCAPS) )
== MMSYSERR_NOERROR)
{
- sprintf(sz_dev_name, psz_device_name_fmt, caps.szPname,
+ sprintf( sz_dev_name, psz_device_name_fmt, caps.szPname,
caps.wMid,
caps.wPid
);