X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Faudio_output%2Fsdl.c;h=070e2f6a27c3f2da37159ec10fa0574c462244c3;hb=94d22180c0afcd6f4f7cf45c9e23b091f728f4eb;hp=7712c6be07171a7964b6f5dd36c0b6442c7d04b4;hpb=35b474003dac21d775f8c37f0c68e40e65bf2e9b;p=vlc diff --git a/modules/audio_output/sdl.c b/modules/audio_output/sdl.c index 7712c6be07..070e2f6a27 100644 --- a/modules/audio_output/sdl.c +++ b/modules/audio_output/sdl.c @@ -1,18 +1,19 @@ /***************************************************************************** * sdl.c : SDL audio output plugin for vlc ***************************************************************************** - * Copyright (C) 2000-2002 VideoLAN - * $Id: sdl.c,v 1.12 2002/09/18 21:21:23 massiot Exp $ + * Copyright (C) 2000-2002 the VideoLAN team + * $Id$ * * Authors: Michel Kaempf - * Samuel Hocevar + * Sam Hocevar * Pierre Baillet - * + * Christophe Massiot + * * 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 @@ -20,23 +21,23 @@ * * 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 /* ENOMEM */ -#include /* open(), O_WRONLY */ -#include /* strerror() */ #include /* write(), close() */ -#include /* calloc(), malloc(), free() */ -#include -#include -#include "aout_internal.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include -#include SDL_INCLUDE_FILE +#include #define FRAME_SIZE 2048 @@ -47,7 +48,7 @@ * It describes the specific properties of an audio device. *****************************************************************************/ struct aout_sys_t -{ +{ mtime_t next_date; mtime_t buffer_time; }; @@ -58,16 +59,20 @@ struct aout_sys_t static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); static void Play ( aout_instance_t * ); -static void SDLCallback ( void *, Uint8 *, int ); +static void SDLCallback ( void *, uint8_t *, int ); /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_description( _("Simple DirectMedia Layer audio module") ); - set_capability( "audio output", 40 ); - set_callbacks( Open, Close ); -vlc_module_end(); +vlc_module_begin () + set_shortname( "SDL" ) + set_description( N_("Simple DirectMedia Layer audio output") ) + set_capability( "audio output", 40 ) + set_category( CAT_AUDIO ) + set_subcategory( SUBCAT_AUDIO_AOUT ) + add_shortcut( "sdl" ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: open the audio device @@ -75,23 +80,22 @@ vlc_module_end(); static int Open ( vlc_object_t *p_this ) { aout_instance_t *p_aout = (aout_instance_t *)p_this; - SDL_AudioSpec desired; - - Uint32 i_flags = SDL_INIT_AUDIO; + SDL_AudioSpec desired, obtained; + int i_nb_channels; + vlc_value_t val, text; + /* Check that no one uses the DSP. */ + uint32_t i_flags = SDL_INIT_AUDIO; if( SDL_WasInit( i_flags ) ) { return VLC_EGENERIC; } - p_aout->output.pf_play = Play; - - aout_VolumeSoftInit( p_aout ); #ifndef WIN32 - /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/ + /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet */ i_flags |= SDL_INIT_EVENTTHREAD; #endif -#ifdef DEBUG +#ifndef NDEBUG /* In debug mode you may want vlc to dump a core instead of staying * stuck */ i_flags |= SDL_INIT_NOPARACHUTE; @@ -104,28 +108,117 @@ static int Open ( vlc_object_t *p_this ) return VLC_EGENERIC; } - if ( p_aout->output.output.i_channels > 2 ) - p_aout->output.output.i_channels = 2; - p_aout->output.output.i_format = AOUT_FMT_S16_NE; - p_aout->output.i_nb_samples = FRAME_SIZE; - - /* TODO: finish and clean this */ + if( var_Get( p_aout, "audio-device", &val ) != VLC_ENOVAR ) + { + /* The user has selected an audio device. */ + if ( val.i_int == AOUT_VAR_STEREO ) + { + p_aout->output.output.i_physical_channels + = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; + } + else if ( val.i_int == AOUT_VAR_MONO ) + { + p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER; + } + } + i_nb_channels = aout_FormatNbChannels( &p_aout->output.output ); + if ( i_nb_channels > 2 ) + { + /* SDL doesn't support more than two channels. */ + i_nb_channels = 2; + p_aout->output.output.i_physical_channels + = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; + } desired.freq = p_aout->output.output.i_rate; desired.format = AUDIO_S16SYS; - desired.channels = p_aout->output.output.i_channels; + desired.channels = i_nb_channels; desired.callback = SDLCallback; desired.userdata = p_aout; desired.samples = FRAME_SIZE; - /* Open the sound device - FIXME : get the "natural" parameters */ - if( SDL_OpenAudio( &desired, NULL ) < 0 ) + /* Open the sound device. */ + if( SDL_OpenAudio( &desired, &obtained ) < 0 ) { return VLC_EGENERIC; } SDL_PauseAudio( 0 ); + /* Now have a look at what we got. */ + switch ( obtained.format ) + { + case AUDIO_S16LSB: + p_aout->output.output.i_format = VLC_CODEC_S16L; break; + case AUDIO_S16MSB: + p_aout->output.output.i_format = VLC_CODEC_S16B; break; + case AUDIO_U16LSB: + p_aout->output.output.i_format = VLC_CODEC_U16L; break; + case AUDIO_U16MSB: + p_aout->output.output.i_format = VLC_CODEC_U16B; break; + case AUDIO_S8: + p_aout->output.output.i_format = VLC_CODEC_S8; break; + case AUDIO_U8: + p_aout->output.output.i_format = VLC_CODEC_U8; break; + } + /* Volume is entirely done in software. */ + aout_VolumeSoftInit( p_aout ); + + if ( obtained.channels != i_nb_channels ) + { + p_aout->output.output.i_physical_channels = (obtained.channels == 2 ? + AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT : + AOUT_CHAN_CENTER); + + if ( var_Type( p_aout, "audio-device" ) == 0 ) + { + var_Create( p_aout, "audio-device", + VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ); + text.psz_string = _("Audio Device"); + var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL ); + + val.i_int = (obtained.channels == 2) ? AOUT_VAR_STEREO : + AOUT_VAR_MONO; + text.psz_string = (obtained.channels == 2) ? _("Stereo") : + _("Mono"); + var_Change( p_aout, "audio-device", + VLC_VAR_ADDCHOICE, &val, &text ); + var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, + NULL ); + } + } + else if ( var_Type( p_aout, "audio-device" ) == 0 ) + { + /* First launch. */ + var_Create( p_aout, "audio-device", + VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ); + text.psz_string = _("Audio Device"); + var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL ); + + val.i_int = AOUT_VAR_STEREO; + text.psz_string = _("Stereo"); + var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text ); + val.i_int = AOUT_VAR_MONO; + text.psz_string = _("Mono"); + var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text ); + if ( i_nb_channels == 2 ) + { + val.i_int = AOUT_VAR_STEREO; + } + else + { + val.i_int = AOUT_VAR_MONO; + } + var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL ); + var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL ); + } + + var_SetBool( p_aout, "intf-change", true ); + + p_aout->output.output.i_rate = obtained.freq; + p_aout->output.i_nb_samples = obtained.samples; + p_aout->output.pf_play = Play; + return VLC_SUCCESS; } @@ -134,6 +227,7 @@ static int Open ( vlc_object_t *p_this ) *****************************************************************************/ static void Play( aout_instance_t * p_aout ) { + VLC_UNUSED(p_aout); } /***************************************************************************** @@ -141,6 +235,7 @@ static void Play( aout_instance_t * p_aout ) *****************************************************************************/ static void Close ( vlc_object_t *p_this ) { + VLC_UNUSED(p_this); SDL_PauseAudio( 1 ); SDL_CloseAudio(); SDL_QuitSubSystem( SDL_INIT_AUDIO ); @@ -149,7 +244,7 @@ static void Close ( vlc_object_t *p_this ) /***************************************************************************** * SDLCallback: what to do once SDL has played sound samples *****************************************************************************/ -static void SDLCallback( void * _p_aout, byte_t * p_stream, int i_len ) +static void SDLCallback( void * _p_aout, uint8_t * p_stream, int i_len ) { aout_instance_t * p_aout = (aout_instance_t *)_p_aout; aout_buffer_t * p_buffer; @@ -164,12 +259,12 @@ static void SDLCallback( void * _p_aout, byte_t * p_stream, int i_len ) if ( p_buffer != NULL ) { - p_aout->p_vlc->pf_memcpy( p_stream, p_buffer->p_buffer, i_len ); + vlc_memcpy( p_stream, p_buffer->p_buffer, i_len ); aout_BufferFree( p_buffer ); } else { - p_aout->p_vlc->pf_memset( p_stream, 0, i_len ); + vlc_memset( p_stream, 0, i_len ); } }