From bfb72ad4f4a670f204dc232f87729755b1f523da Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Thu, 13 Sep 2018 11:58:23 +0200 Subject: [PATCH] Fix no_{global_constructors,exit_time_destructors} in audio device alsa. Bug: webrtc:9693 Change-Id: Id37ef7e8c33830b494165202323ea65286052aae Reviewed-on: https://webrtc-review.googlesource.com/100103 Reviewed-by: Henrik Andreassson Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#24725} --- modules/audio_device/BUILD.gn | 6 ++++-- .../audio_device/linux/audio_device_alsa_linux.cc | 12 +++++------- modules/audio_device/linux/audio_device_alsa_linux.h | 10 ++++++++++ .../linux/audio_mixer_manager_alsa_linux.cc | 9 +-------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn index 964cfefcc2..70c9c0af6c 100644 --- a/modules/audio_device/BUILD.gn +++ b/modules/audio_device/BUILD.gn @@ -304,7 +304,6 @@ rtc_source_set("audio_device_impl") { defines += [ "WEBRTC_DUMMY_FILE_DEVICES" ] } else { if (is_linux) { - configs += [ "../../..:no_global_constructors" ] sources += [ "linux/alsasymboltable_linux.cc", "linux/alsasymboltable_linux.h", @@ -322,7 +321,10 @@ rtc_source_set("audio_device_impl") { defines += [ "WEBRTC_USE_X11" ] } if (rtc_include_pulse_audio) { - configs += [ "../..:no_exit_time_destructors" ] + configs += [ + "../..:no_exit_time_destructors", + "../..:no_global_constructors", + ] sources += [ "linux/audio_device_pulse_linux.cc", "linux/audio_device_pulse_linux.h", diff --git a/modules/audio_device/linux/audio_device_alsa_linux.cc b/modules/audio_device/linux/audio_device_alsa_linux.cc index f8be24e7f0..e6cfcb8d8d 100644 --- a/modules/audio_device/linux/audio_device_alsa_linux.cc +++ b/modules/audio_device/linux/audio_device_alsa_linux.cc @@ -16,13 +16,11 @@ #include "rtc_base/system/arch.h" #include "system_wrappers/include/event_wrapper.h" #include "system_wrappers/include/sleep.h" -webrtc::adm_linux_alsa::AlsaSymbolTable AlsaSymbolTable; -// Accesses ALSA functions through our late-binding symbol table instead of -// directly. This way we don't have to link to libasound, which means our binary -// will work on systems that don't have it. -#define LATE(sym) \ - LATESYM_GET(webrtc::adm_linux_alsa::AlsaSymbolTable, &AlsaSymbolTable, sym) +WebRTCAlsaSymbolTable* GetAlsaSymbolTable() { + static WebRTCAlsaSymbolTable* alsa_symbol_table = new WebRTCAlsaSymbolTable(); + return alsa_symbol_table; +} // Redefine these here to be able to do late-binding #undef snd_ctl_card_info_alloca @@ -140,7 +138,7 @@ AudioDeviceGeneric::InitStatus AudioDeviceLinuxALSA::Init() { rtc::CritScope lock(&_critSect); // Load libasound - if (!AlsaSymbolTable.Load()) { + if (!GetAlsaSymbolTable()->Load()) { // Alsa is not installed on this system RTC_LOG(LS_ERROR) << "failed to load symbol table"; return InitStatus::OTHER_ERROR; diff --git a/modules/audio_device/linux/audio_device_alsa_linux.h b/modules/audio_device/linux/audio_device_alsa_linux.h index f8961453b5..1c78ef115d 100644 --- a/modules/audio_device/linux/audio_device_alsa_linux.h +++ b/modules/audio_device/linux/audio_device_alsa_linux.h @@ -25,6 +25,16 @@ #include #include +typedef webrtc::adm_linux_alsa::AlsaSymbolTable WebRTCAlsaSymbolTable; +WebRTCAlsaSymbolTable* GetAlsaSymbolTable(); + +// Accesses ALSA functions through our late-binding symbol table instead of +// directly. This way we don't have to link to libasound, which means our binary +// will work on systems that don't have it. +#define LATE(sym) \ + LATESYM_GET(webrtc::adm_linux_alsa::AlsaSymbolTable, GetAlsaSymbolTable(), \ + sym) + namespace webrtc { class EventWrapper; diff --git a/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc b/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc index c1d67cfa19..7701364a3e 100644 --- a/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc +++ b/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc @@ -10,17 +10,10 @@ #include +#include "modules/audio_device/linux/audio_device_alsa_linux.h" #include "modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" #include "rtc_base/logging.h" -extern webrtc::adm_linux_alsa::AlsaSymbolTable AlsaSymbolTable; - -// Accesses ALSA functions through our late-binding symbol table instead of -// directly. This way we don't have to link to libalsa, which means our binary -// will work on systems that don't have it. -#define LATE(sym) \ - LATESYM_GET(webrtc::adm_linux_alsa::AlsaSymbolTable, &AlsaSymbolTable, sym) - namespace webrtc { AudioMixerManagerLinuxALSA::AudioMixerManagerLinuxALSA()