@@ -83,6 +83,12 @@ static int (*ALSA_snd_device_name_hint)(int, const char *, void ***);
8383static char * (* ALSA_snd_device_name_get_hint )(const void * , const char * );
8484static int (* ALSA_snd_device_name_free_hint )(void * * );
8585static snd_pcm_sframes_t (* ALSA_snd_pcm_avail )(snd_pcm_t * );
86+ static int (* ALSA_snd_pcm_info )(snd_pcm_t * , snd_pcm_info_t * );
87+ static const char * (* ALSA_snd_pcm_info_get_name )(const snd_pcm_info_t * );
88+ static int (* ALSA_snd_pcm_info_get_card )(const snd_pcm_info_t * );
89+ static int (* ALSA_snd_card_get_name )(int , char * * );
90+ static int (* ALSA_snd_pcm_info_malloc )(snd_pcm_info_t * * );
91+ static int (* ALSA_snd_pcm_info_free )(snd_pcm_info_t * );
8692#ifdef SND_CHMAP_API_VERSION
8793static snd_pcm_chmap_t * (* ALSA_snd_pcm_get_chmap )(snd_pcm_t * );
8894static int (* ALSA_snd_pcm_chmap_print )(const snd_pcm_chmap_t * map , size_t maxlen , char * buf );
@@ -152,6 +158,12 @@ static int load_alsa_syms(void)
152158 SDL_ALSA_SYM (snd_device_name_get_hint );
153159 SDL_ALSA_SYM (snd_device_name_free_hint );
154160 SDL_ALSA_SYM (snd_pcm_avail );
161+ SDL_ALSA_SYM (snd_pcm_info );
162+ SDL_ALSA_SYM (snd_pcm_info_get_card );
163+ SDL_ALSA_SYM (snd_pcm_info_get_name );
164+ SDL_ALSA_SYM (snd_card_get_name );
165+ SDL_ALSA_SYM (snd_pcm_info_malloc );
166+ SDL_ALSA_SYM (snd_pcm_info_free );
155167#ifdef SND_CHMAP_API_VERSION
156168 SDL_ALSA_SYM (snd_pcm_get_chmap );
157169 SDL_ALSA_SYM (snd_pcm_chmap_print );
@@ -466,6 +478,58 @@ static void ALSA_CloseDevice(_THIS)
466478 SDL_free (this -> hidden );
467479}
468480
481+ static int ALSA_GetDefaultAudioInfo (char * * name , SDL_AudioSpec * spec , int iscapture )
482+ {
483+ const char * device = "default" ;
484+ snd_pcm_t * pcm_handle ;
485+ snd_pcm_info_t * pcm_info ;
486+ snd_pcm_stream_t stream ;
487+ int card_index ;
488+ const char * dev_name ;
489+ char * card_name = NULL ;
490+ char final_name [256 ];
491+
492+ SDL_zero (final_name );
493+ stream = iscapture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK ;
494+
495+ if (ALSA_snd_pcm_open (& pcm_handle , device , stream , SND_PCM_NONBLOCK ) < 0 ) {
496+ return SDL_SetError ("ALSA: Couldn't open default device" );
497+ }
498+
499+ if (ALSA_snd_pcm_info_malloc (& pcm_info ) < 0 ) {
500+ ALSA_snd_pcm_close (pcm_handle );
501+ return SDL_SetError ("ALSA: Couldn't allocate pcm_info" );
502+ }
503+
504+ if (ALSA_snd_pcm_info (pcm_handle , pcm_info ) < 0 ) {
505+ ALSA_snd_pcm_info_free (pcm_info );
506+ ALSA_snd_pcm_close (pcm_handle );
507+ return SDL_SetError ("ALSA: Couldn't get PCM info" );
508+ }
509+
510+ card_index = ALSA_snd_pcm_info_get_card (pcm_info );
511+ dev_name = ALSA_snd_pcm_info_get_name (pcm_info );
512+
513+ if (card_index >= 0 && ALSA_snd_card_get_name (card_index , & card_name ) >= 0 ) {
514+ SDL_snprintf (final_name , sizeof (final_name ), "%s, %s" , card_name , dev_name );
515+ * name = SDL_strdup (final_name );
516+ } else {
517+ * name = SDL_strdup (dev_name ? dev_name : "Unknown ALSA Device" );
518+ }
519+
520+ if (spec ) {
521+ SDL_zero (* spec );
522+ spec -> freq = 48000 ;
523+ spec -> format = AUDIO_S16SYS ;
524+ spec -> channels = 2 ;
525+ spec -> samples = 512 ;
526+ }
527+
528+ ALSA_snd_pcm_info_free (pcm_info );
529+ ALSA_snd_pcm_close (pcm_handle );
530+ return 0 ;
531+ }
532+
469533static int ALSA_set_buffer_size (_THIS , snd_pcm_hw_params_t * params )
470534{
471535 int status ;
@@ -975,6 +1039,7 @@ static SDL_bool ALSA_Init(SDL_AudioDriverImpl *impl)
9751039 impl -> Deinitialize = ALSA_Deinitialize ;
9761040 impl -> CaptureFromDevice = ALSA_CaptureFromDevice ;
9771041 impl -> FlushCapture = ALSA_FlushCapture ;
1042+ impl -> GetDefaultAudioInfo = ALSA_GetDefaultAudioInfo ;
9781043
9791044 impl -> HasCaptureSupport = SDL_TRUE ;
9801045 impl -> SupportsNonPow2Samples = SDL_TRUE ;
0 commit comments