38
38
39
39
#include "../SDL_sysaudio.h"
40
40
#include "SDL_alsa_audio.h"
41
+ #include "../../core/linux/SDL_udev.h"
41
42
42
43
#if SDL_ALSA_DEBUG
43
44
#define LOGDEBUG (...) SDL_LogDebug(SDL_LOG_CATEGORY_AUDIO, "ALSA: " __VA_ARGS__)
@@ -1441,6 +1442,65 @@ static int SDLCALL ALSA_HotplugThread(void *arg)
1441
1442
}
1442
1443
#endif
1443
1444
1445
+ #ifdef SDL_USE_LIBUDEV
1446
+
1447
+ static bool udev_initialized ;
1448
+
1449
+ static void ALSA_udev_callback (SDL_UDEV_deviceevent udev_type , int udev_class , const char * devpath )
1450
+ {
1451
+ if (!devpath ) {
1452
+ return ;
1453
+ }
1454
+
1455
+ switch (udev_type ) {
1456
+ case SDL_UDEV_DEVICEADDED :
1457
+ ALSA_HotplugIteration (NULL , NULL );
1458
+ break ;
1459
+
1460
+ case SDL_UDEV_DEVICEREMOVED :
1461
+ ALSA_HotplugIteration (NULL , NULL );
1462
+ break ;
1463
+
1464
+ default :
1465
+ break ;
1466
+ }
1467
+ }
1468
+
1469
+ static bool ALSA_start_udev ()
1470
+ {
1471
+ udev_initialized = SDL_UDEV_Init ();
1472
+ if (udev_initialized ) {
1473
+ // Set up the udev callback
1474
+ if (!SDL_UDEV_AddCallback (ALSA_udev_callback )) {
1475
+ SDL_UDEV_Quit ();
1476
+ udev_initialized = false;
1477
+ }
1478
+ }
1479
+ return udev_initialized ;
1480
+ }
1481
+
1482
+ static void ALSA_stop_udev ()
1483
+ {
1484
+ if (udev_initialized ) {
1485
+ SDL_UDEV_DelCallback (ALSA_udev_callback );
1486
+ SDL_UDEV_Quit ();
1487
+ udev_initialized = false;
1488
+ }
1489
+ }
1490
+
1491
+ #else
1492
+
1493
+ static bool ALSA_start_udev ()
1494
+ {
1495
+ return false;
1496
+ }
1497
+
1498
+ static void ALSA_stop_udev ()
1499
+ {
1500
+ }
1501
+
1502
+ #endif // SDL_USE_LIBUDEV
1503
+
1444
1504
static void ALSA_DetectDevices (SDL_AudioDevice * * default_playback , SDL_AudioDevice * * default_recording )
1445
1505
{
1446
1506
ALSA_guess_device_prefix ();
@@ -1456,11 +1516,13 @@ static void ALSA_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDevi
1456
1516
* default_recording = SDL_AddAudioDevice (/*recording=*/ true, "ALSA default recording device" , NULL , (void * )& default_recording_handle );
1457
1517
}
1458
1518
1519
+ if (!ALSA_start_udev ()) {
1459
1520
#if SDL_ALSA_HOTPLUG_THREAD
1460
- SDL_SetAtomicInt (& ALSA_hotplug_shutdown , 0 );
1461
- ALSA_hotplug_thread = SDL_CreateThread (ALSA_HotplugThread , "SDLHotplugALSA" , NULL );
1462
- // if the thread doesn't spin, oh well, you just don't get further hotplug events.
1521
+ SDL_SetAtomicInt (& ALSA_hotplug_shutdown , 0 );
1522
+ ALSA_hotplug_thread = SDL_CreateThread (ALSA_HotplugThread , "SDLHotplugALSA" , NULL );
1523
+ // if the thread doesn't spin, oh well, you just don't get further hotplug events.
1463
1524
#endif
1525
+ }
1464
1526
}
1465
1527
1466
1528
static void ALSA_DeinitializeStart (void )
@@ -1475,6 +1537,7 @@ static void ALSA_DeinitializeStart(void)
1475
1537
ALSA_hotplug_thread = NULL ;
1476
1538
}
1477
1539
#endif
1540
+ ALSA_stop_udev ();
1478
1541
1479
1542
// Shutting down! Clean up any data we've gathered.
1480
1543
for (dev = hotplug_devices ; dev ; dev = next ) {
0 commit comments