diff --git a/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc b/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc index 30b2933b61..877d98b053 100644 --- a/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc +++ b/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc @@ -10,27 +10,17 @@ #include "webrtc/base/timeutils.h" #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" namespace webrtc { TimeScheduler::TimeScheduler(const int64_t periodicityInMs) - : _crit(CriticalSectionWrapper::CreateCriticalSection()), - _isStarted(false), + : _isStarted(false), _lastPeriodMark(), _periodicityInMs(periodicityInMs), _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec), - _missedPeriods(0) - { - } + _missedPeriods(0) {} -TimeScheduler::~TimeScheduler() -{ - delete _crit; -} - -int32_t TimeScheduler::UpdateScheduler() -{ - CriticalSectionScoped cs(_crit); +int32_t TimeScheduler::UpdateScheduler() { + rtc::CritScope cs(&_crit); if(!_isStarted) { _isStarted = true; @@ -79,7 +69,7 @@ int32_t TimeScheduler::UpdateScheduler() int32_t TimeScheduler::TimeToNextUpdate( int64_t& updateTimeInMS) const { - CriticalSectionScoped cs(_crit); + rtc::CritScope cs(&_crit); // Missed periods means that the next UpdateScheduler() should happen // immediately. if(_missedPeriods > 0) diff --git a/webrtc/modules/audio_conference_mixer/source/time_scheduler.h b/webrtc/modules/audio_conference_mixer/source/time_scheduler.h index d1897fa100..b155429b8b 100644 --- a/webrtc/modules/audio_conference_mixer/source/time_scheduler.h +++ b/webrtc/modules/audio_conference_mixer/source/time_scheduler.h @@ -11,17 +11,18 @@ // The TimeScheduler class keeps track of periodic events. It is non-drifting // and keeps track of any missed periods so that it is possible to catch up. // (compare to a metronome) +#include "webrtc/base/criticalsection.h" #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_TIME_SCHEDULER_H_ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_TIME_SCHEDULER_H_ namespace webrtc { class CriticalSectionWrapper; -class TimeScheduler -{ + +class TimeScheduler { public: TimeScheduler(const int64_t periodicityInMs); - ~TimeScheduler(); + ~TimeScheduler() = default; // Signal that a periodic event has been triggered. int32_t UpdateScheduler(); @@ -31,7 +32,7 @@ public: int32_t TimeToNextUpdate(int64_t& updateTimeInMS) const; private: - CriticalSectionWrapper* _crit; + rtc::CriticalSection _crit; bool _isStarted; int64_t _lastPeriodMark; // In ns diff --git a/webrtc/modules/audio_device/audio_device_impl.cc b/webrtc/modules/audio_device/audio_device_impl.cc index 5040189eeb..45bc3a5aaf 100644 --- a/webrtc/modules/audio_device/audio_device_impl.cc +++ b/webrtc/modules/audio_device/audio_device_impl.cc @@ -53,7 +53,6 @@ #include "webrtc/modules/audio_device/dummy/audio_device_dummy.h" #include "webrtc/modules/audio_device/dummy/file_audio_device.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #define CHECK_INITIALIZED() \ { \ @@ -118,10 +117,7 @@ rtc::scoped_refptr AudioDeviceModule::Create( AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) - : _critSect(*CriticalSectionWrapper::CreateCriticalSection()), - _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()), - _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()), - _ptrCbAudioDeviceObserver(NULL), + : _ptrCbAudioDeviceObserver(NULL), _ptrAudioDevice(NULL), _id(id), _platformAudioLayer(audioLayer), @@ -358,15 +354,10 @@ int32_t AudioDeviceModuleImpl::AttachAudioBuffer() { AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { LOG(INFO) << __FUNCTION__; - if (_ptrAudioDevice) { delete _ptrAudioDevice; _ptrAudioDevice = NULL; } - - delete &_critSect; - delete &_critSectEventCb; - delete &_critSectAudioCb; } // ============================================================================ @@ -398,7 +389,7 @@ void AudioDeviceModuleImpl::Process() { // kPlayoutWarning if (_ptrAudioDevice->PlayoutWarning()) { - CriticalSectionScoped lock(&_critSectEventCb); + rtc::CritScope lock(&_critSectEventCb); if (_ptrCbAudioDeviceObserver) { LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)"; _ptrCbAudioDeviceObserver->OnWarningIsReported( @@ -409,7 +400,7 @@ void AudioDeviceModuleImpl::Process() { // kPlayoutError if (_ptrAudioDevice->PlayoutError()) { - CriticalSectionScoped lock(&_critSectEventCb); + rtc::CritScope lock(&_critSectEventCb); if (_ptrCbAudioDeviceObserver) { LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)"; _ptrCbAudioDeviceObserver->OnErrorIsReported( @@ -420,7 +411,7 @@ void AudioDeviceModuleImpl::Process() { // kRecordingWarning if (_ptrAudioDevice->RecordingWarning()) { - CriticalSectionScoped lock(&_critSectEventCb); + rtc::CritScope lock(&_critSectEventCb); if (_ptrCbAudioDeviceObserver) { LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)"; _ptrCbAudioDeviceObserver->OnWarningIsReported( @@ -431,7 +422,7 @@ void AudioDeviceModuleImpl::Process() { // kRecordingError if (_ptrAudioDevice->RecordingError()) { - CriticalSectionScoped lock(&_critSectEventCb); + rtc::CritScope lock(&_critSectEventCb); if (_ptrCbAudioDeviceObserver) { LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)"; _ptrCbAudioDeviceObserver->OnErrorIsReported( @@ -1459,7 +1450,7 @@ bool AudioDeviceModuleImpl::Recording() const { int32_t AudioDeviceModuleImpl::RegisterEventObserver( AudioDeviceObserver* eventCallback) { LOG(INFO) << __FUNCTION__; - CriticalSectionScoped lock(&_critSectEventCb); + rtc::CritScope lock(&_critSectEventCb); _ptrCbAudioDeviceObserver = eventCallback; return 0; @@ -1472,7 +1463,7 @@ int32_t AudioDeviceModuleImpl::RegisterEventObserver( int32_t AudioDeviceModuleImpl::RegisterAudioCallback( AudioTransport* audioCallback) { LOG(INFO) << __FUNCTION__; - CriticalSectionScoped lock(&_critSectAudioCb); + rtc::CritScope lock(&_critSectAudioCb); return _audioDeviceBuffer.RegisterAudioCallback(audioCallback); } diff --git a/webrtc/modules/audio_device/audio_device_impl.h b/webrtc/modules/audio_device/audio_device_impl.h index 034690f6b2..709eb769bd 100644 --- a/webrtc/modules/audio_device/audio_device_impl.h +++ b/webrtc/modules/audio_device/audio_device_impl.h @@ -16,6 +16,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/criticalsection.h" #include "webrtc/modules/audio_device/audio_device_buffer.h" #include "webrtc/modules/audio_device/include/audio_device.h" @@ -23,7 +24,6 @@ namespace webrtc { class AudioDeviceGeneric; class AudioManager; -class CriticalSectionWrapper; class AudioDeviceModuleImpl : public AudioDeviceModule { public: @@ -203,9 +203,9 @@ class AudioDeviceModuleImpl : public AudioDeviceModule { PlatformType Platform() const; AudioLayer PlatformAudioLayer() const; - CriticalSectionWrapper& _critSect; - CriticalSectionWrapper& _critSectEventCb; - CriticalSectionWrapper& _critSectAudioCb; + rtc::CriticalSection _critSect; + rtc::CriticalSection _critSectEventCb; + rtc::CriticalSection _critSectAudioCb; AudioDeviceObserver* _ptrCbAudioDeviceObserver; diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.cc b/webrtc/modules/audio_device/dummy/file_audio_device.cc index 3dcb1384e7..92b09e0a9d 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device.cc +++ b/webrtc/modules/audio_device/dummy/file_audio_device.cc @@ -33,7 +33,6 @@ FileAudioDevice::FileAudioDevice(const int32_t id, _playoutBuffer(NULL), _recordingFramesLeft(0), _playoutFramesLeft(0), - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), _recordingBufferSizeIn10MS(0), _recordingFramesIn10MS(0), _playoutFramesIn10MS(0), @@ -161,7 +160,7 @@ int32_t FileAudioDevice::RecordingIsAvailable(bool& available) { } int32_t FileAudioDevice::InitRecording() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { return -1; @@ -219,7 +218,7 @@ int32_t FileAudioDevice::StartPlayout() { int32_t FileAudioDevice::StopPlayout() { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playing = false; } @@ -229,7 +228,7 @@ int32_t FileAudioDevice::StopPlayout() { _ptrThreadPlay.reset(); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playoutFramesLeft = 0; delete [] _playoutBuffer; @@ -280,7 +279,7 @@ int32_t FileAudioDevice::StartRecording() { int32_t FileAudioDevice::StopRecording() { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recording = false; } @@ -289,7 +288,7 @@ int32_t FileAudioDevice::StopRecording() { _ptrThreadRec.reset(); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recordingFramesLeft = 0; if (_recordingBuffer) { delete [] _recordingBuffer; @@ -456,7 +455,7 @@ void FileAudioDevice::ClearRecordingWarning() {} void FileAudioDevice::ClearRecordingError() {} void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _ptrAudioBuffer = audioBuffer; diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.h b/webrtc/modules/audio_device/dummy/file_audio_device.h index 2065f21d47..41760552c3 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device.h +++ b/webrtc/modules/audio_device/dummy/file_audio_device.h @@ -16,9 +16,9 @@ #include #include +#include "webrtc/base/criticalsection.h" #include "webrtc/base/timeutils.h" #include "webrtc/modules/audio_device/audio_device_generic.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" namespace rtc { @@ -176,7 +176,7 @@ class FileAudioDevice : public AudioDeviceGeneric { int8_t* _playoutBuffer; // In bytes. uint32_t _recordingFramesLeft; uint32_t _playoutFramesLeft; - CriticalSectionWrapper& _critSect; + rtc::CriticalSection _critSect; size_t _recordingBufferSizeIn10MS; size_t _recordingFramesIn10MS; diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc index f7315de2af..3b8cf24773 100644 --- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc +++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc @@ -62,7 +62,6 @@ static const unsigned int ALSA_CAPTURE_WAIT_TIMEOUT = 5; // in ms AudioDeviceLinuxALSA::AudioDeviceLinuxALSA(const int32_t id) : _ptrAudioBuffer(NULL), - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), _id(id), _mixerManager(id), _inputDeviceIndex(0), @@ -130,13 +129,12 @@ AudioDeviceLinuxALSA::~AudioDeviceLinuxALSA() delete [] _playoutBuffer; _playoutBuffer = NULL; } - delete &_critSect; } void AudioDeviceLinuxALSA::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _ptrAudioBuffer = audioBuffer; @@ -157,7 +155,7 @@ int32_t AudioDeviceLinuxALSA::ActiveAudioLayer( } AudioDeviceGeneric::InitStatus AudioDeviceLinuxALSA::Init() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); // Load libasound if (!AlsaSymbolTable.Load()) { @@ -194,7 +192,7 @@ int32_t AudioDeviceLinuxALSA::Terminate() return 0; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _mixerManager.Close(); @@ -243,7 +241,7 @@ bool AudioDeviceLinuxALSA::Initialized() const int32_t AudioDeviceLinuxALSA::InitSpeaker() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_playing) { @@ -258,7 +256,7 @@ int32_t AudioDeviceLinuxALSA::InitSpeaker() int32_t AudioDeviceLinuxALSA::InitMicrophone() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { @@ -560,7 +558,7 @@ int32_t AudioDeviceLinuxALSA::MicrophoneBoost(bool& enabled) const int32_t AudioDeviceLinuxALSA::StereoRecordingIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); // If we already have initialized in stereo it's obviously available if (_recIsInitialized && (2 == _recChannels)) @@ -631,7 +629,7 @@ int32_t AudioDeviceLinuxALSA::StereoRecording(bool& enabled) const int32_t AudioDeviceLinuxALSA::StereoPlayoutIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); // If we already have initialized in stereo it's obviously available if (_playIsInitialized && (2 == _playChannels)) @@ -1009,7 +1007,7 @@ int32_t AudioDeviceLinuxALSA::InitPlayout() int errVal = 0; - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_playing) { return -1; @@ -1162,7 +1160,7 @@ int32_t AudioDeviceLinuxALSA::InitRecording() int errVal = 0; - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { @@ -1397,7 +1395,7 @@ int32_t AudioDeviceLinuxALSA::StopRecording() { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_recIsInitialized) { @@ -1420,7 +1418,7 @@ int32_t AudioDeviceLinuxALSA::StopRecording() _ptrThreadRec.reset(); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recordingFramesLeft = 0; if (_recordingBuffer) { @@ -1523,7 +1521,7 @@ int32_t AudioDeviceLinuxALSA::StopPlayout() { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_playIsInitialized) { @@ -1545,7 +1543,7 @@ int32_t AudioDeviceLinuxALSA::StopPlayout() _ptrThreadPlay.reset(); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playoutFramesLeft = 0; delete [] _playoutBuffer; @@ -1635,49 +1633,49 @@ int32_t AudioDeviceLinuxALSA::CPULoad(uint16_t& load) const bool AudioDeviceLinuxALSA::PlayoutWarning() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_playWarning > 0); } bool AudioDeviceLinuxALSA::PlayoutError() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_playError > 0); } bool AudioDeviceLinuxALSA::RecordingWarning() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_recWarning > 0); } bool AudioDeviceLinuxALSA::RecordingError() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_recError > 0); } void AudioDeviceLinuxALSA::ClearPlayoutWarning() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playWarning = 0; } void AudioDeviceLinuxALSA::ClearPlayoutError() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playError = 0; } void AudioDeviceLinuxALSA::ClearRecordingWarning() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recWarning = 0; } void AudioDeviceLinuxALSA::ClearRecordingError() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recError = 0; } diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h index aba62e8669..40525982bb 100644 --- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h +++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h @@ -13,10 +13,10 @@ #include +#include "webrtc/base/criticalsection.h" #include "webrtc/base/platform_thread.h" #include "webrtc/modules/audio_device/audio_device_generic.h" #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #if defined(USE_X11) #include @@ -145,7 +145,6 @@ public: // CPU load int32_t CPULoad(uint16_t& load) const override; -public: bool PlayoutWarning() const override; bool PlayoutError() const override; bool RecordingWarning() const override; @@ -155,7 +154,6 @@ public: void ClearRecordingWarning() override; void ClearRecordingError() override; -public: void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; private: @@ -166,26 +164,22 @@ private: const int32_t ednLen = 0) const; int32_t ErrorRecovery(int32_t error, snd_pcm_t* deviceHandle); -private: bool KeyPressed() const; -private: void Lock() EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); }; void UnLock() UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); }; -private: + inline int32_t InputSanityCheckAfterUnlockedPeriod() const; inline int32_t OutputSanityCheckAfterUnlockedPeriod() const; -private: static bool RecThreadFunc(void*); static bool PlayThreadFunc(void*); bool RecThreadProcess(); bool PlayThreadProcess(); -private: AudioDeviceBuffer* _ptrAudioBuffer; - CriticalSectionWrapper& _critSect; + rtc::CriticalSection _critSect; // TODO(pbos): Make plain members and start/stop instead of resetting these // pointers. A thread can be reused. @@ -226,7 +220,6 @@ private: AudioDeviceModule::BufferType _playBufType; -private: bool _initialized; bool _recording; bool _playing; diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc index e408f22066..a486ee5468 100644 --- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc +++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc @@ -30,7 +30,6 @@ namespace webrtc AudioDeviceLinuxPulse::AudioDeviceLinuxPulse(const int32_t id) : _ptrAudioBuffer(NULL), - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), _timeEventRec(*EventWrapper::Create()), _timeEventPlay(*EventWrapper::Create()), _recStartEvent(*EventWrapper::Create()), @@ -133,7 +132,6 @@ AudioDeviceLinuxPulse::~AudioDeviceLinuxPulse() delete &_playStartEvent; delete &_timeEventRec; delete &_timeEventPlay; - delete &_critSect; } void AudioDeviceLinuxPulse::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) @@ -751,7 +749,7 @@ int32_t AudioDeviceLinuxPulse::StereoPlayout(bool& enabled) const int32_t AudioDeviceLinuxPulse::SetAGC(bool enable) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _AGC = enable; return 0; @@ -759,7 +757,7 @@ int32_t AudioDeviceLinuxPulse::SetAGC(bool enable) bool AudioDeviceLinuxPulse::AGC() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return _AGC; } @@ -1346,7 +1344,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() if (kEventTimeout == _recStartEvent.Wait(10000)) { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _startRec = false; } StopRecording(); @@ -1356,7 +1354,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() } { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { // The recording state is set by the audio thread after recording @@ -1375,7 +1373,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() int32_t AudioDeviceLinuxPulse::StopRecording() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_recIsInitialized) { @@ -1469,7 +1467,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() // Set state to ensure that playout starts from the audio thread. { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _startPlay = true; } @@ -1481,7 +1479,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() if (kEventTimeout == _playStartEvent.Wait(10000)) { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _startPlay = false; } StopPlayout(); @@ -1491,7 +1489,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() } { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_playing) { // The playing state is set by the audio thread after playout @@ -1510,7 +1508,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() int32_t AudioDeviceLinuxPulse::StopPlayout() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_playIsInitialized) { @@ -1574,7 +1572,7 @@ int32_t AudioDeviceLinuxPulse::StopPlayout() int32_t AudioDeviceLinuxPulse::PlayoutDelay(uint16_t& delayMS) const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); delayMS = (uint16_t) _sndCardPlayDelay; return 0; } @@ -1631,49 +1629,49 @@ int32_t AudioDeviceLinuxPulse::CPULoad(uint16_t& /*load*/) const bool AudioDeviceLinuxPulse::PlayoutWarning() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_playWarning > 0); } bool AudioDeviceLinuxPulse::PlayoutError() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_playError > 0); } bool AudioDeviceLinuxPulse::RecordingWarning() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_recWarning > 0); } bool AudioDeviceLinuxPulse::RecordingError() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return (_recError > 0); } void AudioDeviceLinuxPulse::ClearPlayoutWarning() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playWarning = 0; } void AudioDeviceLinuxPulse::ClearPlayoutError() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playError = 0; } void AudioDeviceLinuxPulse::ClearRecordingWarning() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recWarning = 0; } void AudioDeviceLinuxPulse::ClearRecordingError() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _recError = 0; } @@ -2602,7 +2600,7 @@ bool AudioDeviceLinuxPulse::PlayThreadProcess() return true; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_startPlay) { @@ -2843,7 +2841,7 @@ bool AudioDeviceLinuxPulse::RecThreadProcess() return true; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_startRec) { diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h index 3aa169807d..58934583db 100644 --- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h +++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h @@ -13,11 +13,11 @@ #include +#include "webrtc/base/criticalsection.h" #include "webrtc/base/platform_thread.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/audio_device/audio_device_generic.h" #include "webrtc/modules/audio_device/linux/audio_mixer_manager_pulse_linux.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include #include @@ -280,7 +280,7 @@ private: AudioDeviceBuffer* _ptrAudioBuffer; - CriticalSectionWrapper& _critSect; + rtc::CriticalSection _critSect; EventWrapper& _timeEventRec; EventWrapper& _timeEventPlay; EventWrapper& _recStartEvent; diff --git a/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc b/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc index 29620eb043..be5e17e14c 100644 --- a/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc +++ b/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.cc @@ -25,7 +25,6 @@ namespace webrtc { AudioMixerManagerLinuxALSA::AudioMixerManagerLinuxALSA(const int32_t id) : - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), _id(id), _outputMixerHandle(NULL), _inputMixerHandle(NULL), @@ -43,10 +42,7 @@ AudioMixerManagerLinuxALSA::~AudioMixerManagerLinuxALSA() { WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destructed", __FUNCTION__); - Close(); - - delete &_critSect; } // ============================================================================ @@ -58,7 +54,7 @@ int32_t AudioMixerManagerLinuxALSA::Close() WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); CloseSpeaker(); CloseMicrophone(); @@ -72,7 +68,7 @@ int32_t AudioMixerManagerLinuxALSA::CloseSpeaker() WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int errVal = 0; @@ -113,7 +109,7 @@ int32_t AudioMixerManagerLinuxALSA::CloseMicrophone() { WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int errVal = 0; @@ -165,7 +161,7 @@ int32_t AudioMixerManagerLinuxALSA::OpenSpeaker(char* deviceName) WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "AudioMixerManagerLinuxALSA::OpenSpeaker(name=%s)", deviceName); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int errVal = 0; @@ -259,7 +255,7 @@ int32_t AudioMixerManagerLinuxALSA::OpenMicrophone(char *deviceName) "AudioMixerManagerLinuxALSA::OpenMicrophone(name=%s)", deviceName); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int errVal = 0; @@ -378,7 +374,7 @@ int32_t AudioMixerManagerLinuxALSA::SetSpeakerVolume( "AudioMixerManagerLinuxALSA::SetSpeakerVolume(volume=%u)", volume); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_outputMixerElement == NULL) { @@ -642,7 +638,7 @@ int32_t AudioMixerManagerLinuxALSA::SetSpeakerMute(bool enable) "AudioMixerManagerLinuxALSA::SetSpeakerMute(enable=%u)", enable); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_outputMixerElement == NULL) { @@ -739,7 +735,7 @@ int32_t AudioMixerManagerLinuxALSA::SetMicrophoneMute(bool enable) "AudioMixerManagerLinuxALSA::SetMicrophoneMute(enable=%u)", enable); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_inputMixerElement == NULL) { @@ -838,7 +834,7 @@ int32_t AudioMixerManagerLinuxALSA::SetMicrophoneBoost(bool enable) "AudioMixerManagerLinuxALSA::SetMicrophoneBoost(enable=%u)", enable); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_inputMixerHandle == NULL) { @@ -900,7 +896,7 @@ int32_t AudioMixerManagerLinuxALSA::SetMicrophoneVolume( "AudioMixerManagerLinuxALSA::SetMicrophoneVolume(volume=%u)", volume); - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_inputMixerElement == NULL) { @@ -1296,19 +1292,16 @@ void AudioMixerManagerLinuxALSA::GetControlName(char* controlName, // controlName: "hw:CARD=Intel" char* pos1 = strchr(deviceName, ':'); char* pos2 = strchr(deviceName, ','); - if (!pos2) - { + if (!pos2) { // Can also be default:CARD=Intel pos2 = &deviceName[strlen(deviceName)]; } - if (pos1 && pos2) - { + if (pos1 && pos2) { strcpy(controlName, "hw"); int nChar = (int) (pos2 - pos1); strncpy(&controlName[2], pos1, nChar); controlName[2 + nChar] = '\0'; - } else - { + } else { strcpy(controlName, deviceName); } diff --git a/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h b/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h index b8be8c1b70..0ad11c8b6d 100644 --- a/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h +++ b/webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H #define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H +#include "webrtc/base/criticalsection.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_device/linux/alsasymboltable_linux.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/typedefs.h" #include @@ -63,7 +63,7 @@ private: void GetControlName(char *controlName, char* deviceName) const; private: - CriticalSectionWrapper& _critSect; + rtc::CriticalSection _critSect; int32_t _id; mutable snd_mixer_t* _outputMixerHandle; char _outputMixerStr[kAdmMaxDeviceNameSize]; diff --git a/webrtc/modules/audio_device/win/audio_device_core_win.cc b/webrtc/modules/audio_device/win/audio_device_core_win.cc index 8b38b94f62..9d1d5322fb 100644 --- a/webrtc/modules/audio_device/win/audio_device_core_win.cc +++ b/webrtc/modules/audio_device/win/audio_device_core_win.cc @@ -406,8 +406,6 @@ bool AudioDeviceWindowsCore::CoreAudioIsSupported() AudioDeviceWindowsCore::AudioDeviceWindowsCore(const int32_t id) : _comInit(ScopedCOMInitializer::kMTA), - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), - _volumeMutex(*CriticalSectionWrapper::CreateCriticalSection()), _id(id), _ptrAudioBuffer(NULL), _ptrEnumerator(NULL), @@ -638,9 +636,6 @@ AudioDeviceWindowsCore::~AudioDeviceWindowsCore() "AudioDeviceWindowsCore::~AudioDeviceWindowsCore() the Avrt DLL module is now unloaded"); } } - - delete &_critSect; - delete &_volumeMutex; } // ============================================================================ @@ -680,7 +675,7 @@ int32_t AudioDeviceWindowsCore::ActiveAudioLayer(AudioDeviceModule::AudioLayer& // ---------------------------------------------------------------------------- AudioDeviceGeneric::InitStatus AudioDeviceWindowsCore::Init() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_initialized) { return InitStatus::OK; @@ -709,7 +704,7 @@ AudioDeviceGeneric::InitStatus AudioDeviceWindowsCore::Init() { int32_t AudioDeviceWindowsCore::Terminate() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_initialized) { return 0; @@ -751,7 +746,7 @@ bool AudioDeviceWindowsCore::Initialized() const int32_t AudioDeviceWindowsCore::InitSpeaker() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_playing) { @@ -833,7 +828,7 @@ int32_t AudioDeviceWindowsCore::InitSpeaker() int32_t AudioDeviceWindowsCore::InitMicrophone() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { @@ -923,7 +918,7 @@ bool AudioDeviceWindowsCore::MicrophoneIsInitialized() const int32_t AudioDeviceWindowsCore::SpeakerVolumeIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_ptrDeviceOut == NULL) { @@ -968,7 +963,7 @@ int32_t AudioDeviceWindowsCore::SetSpeakerVolume(uint32_t volume) { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_speakerIsInitialized) { @@ -1011,7 +1006,7 @@ int32_t AudioDeviceWindowsCore::SpeakerVolume(uint32_t& volume) const { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_speakerIsInitialized) { @@ -1123,7 +1118,7 @@ int32_t AudioDeviceWindowsCore::SpeakerVolumeStepSize(uint16_t& stepSize) const int32_t AudioDeviceWindowsCore::SpeakerMuteIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_ptrDeviceOut == NULL) { @@ -1162,7 +1157,7 @@ Exit: int32_t AudioDeviceWindowsCore::SetSpeakerMute(bool enable) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_speakerIsInitialized) { @@ -1242,7 +1237,7 @@ Exit: int32_t AudioDeviceWindowsCore::MicrophoneMuteIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_ptrDeviceIn == NULL) { @@ -1402,7 +1397,7 @@ int32_t AudioDeviceWindowsCore::StereoRecordingIsAvailable(bool& available) int32_t AudioDeviceWindowsCore::SetStereoRecording(bool enable) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (enable) { @@ -1453,7 +1448,7 @@ int32_t AudioDeviceWindowsCore::StereoPlayoutIsAvailable(bool& available) int32_t AudioDeviceWindowsCore::SetStereoPlayout(bool enable) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (enable) { @@ -1492,7 +1487,7 @@ int32_t AudioDeviceWindowsCore::StereoPlayout(bool& enabled) const int32_t AudioDeviceWindowsCore::SetAGC(bool enable) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _AGC = enable; return 0; } @@ -1503,7 +1498,7 @@ int32_t AudioDeviceWindowsCore::SetAGC(bool enable) bool AudioDeviceWindowsCore::AGC() const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); return _AGC; } @@ -1514,7 +1509,7 @@ bool AudioDeviceWindowsCore::AGC() const int32_t AudioDeviceWindowsCore::MicrophoneVolumeIsAvailable(bool& available) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_ptrDeviceIn == NULL) { @@ -1553,7 +1548,7 @@ int32_t AudioDeviceWindowsCore::SetMicrophoneVolume(uint32_t volume) WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "AudioDeviceWindowsCore::SetMicrophoneVolume(volume=%u)", volume); { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_microphoneIsInitialized) { @@ -1594,7 +1589,7 @@ Exit: int32_t AudioDeviceWindowsCore::MicrophoneVolume(uint32_t& volume) const { { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (!_microphoneIsInitialized) { @@ -1689,7 +1684,7 @@ int32_t AudioDeviceWindowsCore::MicrophoneVolumeStepSize(uint16_t& stepSize) con int16_t AudioDeviceWindowsCore::PlayoutDevices() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_RefreshDeviceList(eRender) != -1) { @@ -1720,7 +1715,7 @@ int32_t AudioDeviceWindowsCore::SetPlayoutDevice(uint16_t index) return -1; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); HRESULT hr(S_OK); @@ -1775,7 +1770,7 @@ int32_t AudioDeviceWindowsCore::SetPlayoutDevice(AudioDeviceModule::WindowsDevic role = eCommunications; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); // Refresh the list of rendering endpoint devices _RefreshDeviceList(eRender); @@ -1845,7 +1840,7 @@ int32_t AudioDeviceWindowsCore::PlayoutDeviceName( memset(guid, 0, kAdmMaxGuidSize); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int32_t ret(-1); WCHAR szDeviceName[MAX_PATH]; @@ -1925,7 +1920,7 @@ int32_t AudioDeviceWindowsCore::RecordingDeviceName( memset(guid, 0, kAdmMaxGuidSize); } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); int32_t ret(-1); WCHAR szDeviceName[MAX_PATH]; @@ -1979,7 +1974,7 @@ int32_t AudioDeviceWindowsCore::RecordingDeviceName( int16_t AudioDeviceWindowsCore::RecordingDevices() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_RefreshDeviceList(eCapture) != -1) { @@ -2010,7 +2005,7 @@ int32_t AudioDeviceWindowsCore::SetRecordingDevice(uint16_t index) return -1; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); HRESULT hr(S_OK); @@ -2065,7 +2060,7 @@ int32_t AudioDeviceWindowsCore::SetRecordingDevice(AudioDeviceModule::WindowsDev role = eCommunications; } - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); // Refresh the list of capture endpoint devices _RefreshDeviceList(eCapture); @@ -2155,7 +2150,7 @@ int32_t AudioDeviceWindowsCore::RecordingIsAvailable(bool& available) int32_t AudioDeviceWindowsCore::InitPlayout() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_playing) { @@ -2495,7 +2490,7 @@ int32_t AudioDeviceWindowsCore::InitRecordingDMO() int32_t AudioDeviceWindowsCore::InitRecording() { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); if (_recording) { @@ -2746,7 +2741,7 @@ int32_t AudioDeviceWindowsCore::StartRecording() } { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); // Create thread which will drive the capturing LPTHREAD_START_ROUTINE lpStartAddress = WSAPICaptureThread; @@ -2996,7 +2991,7 @@ int32_t AudioDeviceWindowsCore::StartPlayout() } { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); // Create thread which will drive the rendering. assert(_hPlayThread == NULL); @@ -3046,7 +3041,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() } { - CriticalSectionScoped critScoped(&_critSect) ; + rtc::CritScope critScoped(&_critSect) ; if (_hPlayThread == NULL) { @@ -3079,7 +3074,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() } { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "webrtc_core_audio_render_thread is now closed"); @@ -3123,7 +3118,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() int32_t AudioDeviceWindowsCore::PlayoutDelay(uint16_t& delayMS) const { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); delayMS = static_cast(_sndCardPlayDelay); return 0; } @@ -3134,7 +3129,7 @@ int32_t AudioDeviceWindowsCore::PlayoutDelay(uint16_t& delayMS) const int32_t AudioDeviceWindowsCore::RecordingDelay(uint16_t& delayMS) const { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); delayMS = static_cast(_sndCardRecDelay); return 0; } @@ -3154,7 +3149,7 @@ bool AudioDeviceWindowsCore::Playing() const int32_t AudioDeviceWindowsCore::SetPlayoutBuffer(const AudioDeviceModule::BufferType type, uint16_t sizeMS) { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); _playBufType = type; @@ -3172,7 +3167,7 @@ int32_t AudioDeviceWindowsCore::SetPlayoutBuffer(const AudioDeviceModule::Buffer int32_t AudioDeviceWindowsCore::PlayoutBuffer(AudioDeviceModule::BufferType& type, uint16_t& sizeMS) const { - CriticalSectionScoped lock(&_critSect); + rtc::CritScope lock(&_critSect); type = _playBufType; if (type == AudioDeviceModule::kFixedBufferSize) @@ -3773,7 +3768,7 @@ DWORD AudioDeviceWindowsCore::DoCaptureThreadPollDMO() while (keepRecording) { - CriticalSectionScoped critScoped(&_critSect); + rtc::CritScope critScoped(&_critSect); DWORD dwStatus = 0; { diff --git a/webrtc/modules/audio_device/win/audio_device_core_win.h b/webrtc/modules/audio_device/win/audio_device_core_win.h index 5e813cc4a7..0c9ada52ea 100644 --- a/webrtc/modules/audio_device/win/audio_device_core_win.h +++ b/webrtc/modules/audio_device/win/audio_device_core_win.h @@ -24,8 +24,8 @@ #include #include // IMediaObject +#include "webrtc/base/criticalsection.h" #include "webrtc/base/scoped_ref_ptr.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" // Use Multimedia Class Scheduler Service (MMCSS) to boost the thread priority #pragma comment( lib, "avrt.lib" ) @@ -237,10 +237,8 @@ private: // thread functions void _Lock() { _critSect.Enter(); }; void _UnLock() { _critSect.Leave(); }; -private: int32_t Id() {return _id;} -private: int SetDMOProperties(); int SetBoolProperty(IPropertyStore* ptrPS, @@ -272,21 +270,18 @@ private: int32_t InitRecordingDMO(); -private: ScopedCOMInitializer _comInit; AudioDeviceBuffer* _ptrAudioBuffer; - CriticalSectionWrapper& _critSect; - CriticalSectionWrapper& _volumeMutex; - int32_t _id; + rtc::CriticalSection _critSect; + rtc::CriticalSection _volumeMutex; + int32_t _id; -private: // MMDevice IMMDeviceEnumerator* _ptrEnumerator; IMMDeviceCollection* _ptrRenderCollection; IMMDeviceCollection* _ptrCaptureCollection; IMMDevice* _ptrDeviceOut; IMMDevice* _ptrDeviceIn; -private: // WASAPI IAudioClient* _ptrClientOut; IAudioClient* _ptrClientIn; IAudioRenderClient* _ptrRenderClient; diff --git a/webrtc/modules/bitrate_controller/include/bitrate_controller.h b/webrtc/modules/bitrate_controller/include/bitrate_controller.h index 36637a3dc0..194c99be55 100644 --- a/webrtc/modules/bitrate_controller/include/bitrate_controller.h +++ b/webrtc/modules/bitrate_controller/include/bitrate_controller.h @@ -24,7 +24,6 @@ namespace webrtc { -class CriticalSectionWrapper; class RtcEventLog; // Deprecated diff --git a/webrtc/modules/media_file/media_file_impl.cc b/webrtc/modules/media_file/media_file_impl.cc index 9f9511d837..e35626c760 100644 --- a/webrtc/modules/media_file/media_file_impl.cc +++ b/webrtc/modules/media_file/media_file_impl.cc @@ -12,7 +12,6 @@ #include "webrtc/base/format_macros.h" #include "webrtc/modules/media_file/media_file_impl.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" @@ -29,8 +28,6 @@ void MediaFile::DestroyMediaFile(MediaFile* module) MediaFileImpl::MediaFileImpl(const int32_t id) : _id(id), - _crit(CriticalSectionWrapper::CreateCriticalSection()), - _callbackCrit(CriticalSectionWrapper::CreateCriticalSection()), _ptrFileUtilityObj(NULL), codec_info_(), _ptrInStream(NULL), @@ -57,7 +54,7 @@ MediaFileImpl::~MediaFileImpl() { WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, "~MediaFileImpl()"); { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(_playingActive) { @@ -79,9 +76,6 @@ MediaFileImpl::~MediaFileImpl() _ptrOutStream = NULL; } } - - delete _crit; - delete _callbackCrit; } int64_t MediaFileImpl::TimeUntilNextProcess() @@ -119,7 +113,7 @@ int32_t MediaFileImpl::PlayoutAudioData(int8_t* buffer, int32_t bytesRead = 0; { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_playingActive) { @@ -213,7 +207,7 @@ void MediaFileImpl::HandlePlayCallbacks(int32_t bytesRead) } // Only _callbackCrit may and should be taken when making callbacks. - CriticalSectionScoped lock(_callbackCrit); + rtc::CritScope lock(&_callbackCrit); if(_ptrCallback) { if(callbackNotifyMs) @@ -252,7 +246,7 @@ int32_t MediaFileImpl::PlayoutStereoData( bool playEnded = false; uint32_t callbackNotifyMs = 0; { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_playingActive || !_isStereo) { @@ -313,7 +307,7 @@ int32_t MediaFileImpl::PlayoutStereoData( } } - CriticalSectionScoped lock(_callbackCrit); + rtc::CritScope lock(&_callbackCrit); if(_ptrCallback) { if(callbackNotifyMs) @@ -386,7 +380,7 @@ int32_t MediaFileImpl::StartPlayingAudioFile( return -1; } - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); _openFile = true; strncpy(_fileName, fileName, sizeof(_fileName)); _fileName[sizeof(_fileName) - 1] = '\0'; @@ -424,7 +418,7 @@ int32_t MediaFileImpl::StartPlayingStream( return -1; } - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(_playingActive || _recordingActive) { WEBRTC_TRACE( @@ -555,7 +549,7 @@ int32_t MediaFileImpl::StartPlayingStream( int32_t MediaFileImpl::StopPlaying() { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); _isStereo = false; if(_ptrFileUtilityObj) { @@ -590,7 +584,7 @@ int32_t MediaFileImpl::StopPlaying() bool MediaFileImpl::IsPlaying() { WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsPlaying()"); - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); return _playingActive; } @@ -612,7 +606,7 @@ int32_t MediaFileImpl::IncomingAudioData( bool recordingEnded = false; uint32_t callbackNotifyMs = 0; { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_recordingActive) { @@ -707,7 +701,7 @@ int32_t MediaFileImpl::IncomingAudioData( } // Only _callbackCrit may and should be taken when making callbacks. - CriticalSectionScoped lock(_callbackCrit); + rtc::CritScope lock(&_callbackCrit); if(_ptrCallback) { if(callbackNotifyMs) @@ -767,7 +761,7 @@ int32_t MediaFileImpl::StartRecordingAudioFile( return -1; } - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); _openFile = true; strncpy(_fileName, fileName, sizeof(_fileName)); _fileName[sizeof(_fileName) - 1] = '\0'; @@ -786,7 +780,7 @@ int32_t MediaFileImpl::StartRecordingAudioStream( return -1; } - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(_recordingActive || _playingActive) { WEBRTC_TRACE( @@ -923,7 +917,7 @@ int32_t MediaFileImpl::StartRecordingAudioStream( int32_t MediaFileImpl::StopRecording() { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_recordingActive) { WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, @@ -967,14 +961,14 @@ int32_t MediaFileImpl::StopRecording() bool MediaFileImpl::IsRecording() { WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsRecording()"); - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); return _recordingActive; } int32_t MediaFileImpl::RecordDurationMs(uint32_t& durationMs) { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_recordingActive) { durationMs = 0; @@ -987,14 +981,14 @@ int32_t MediaFileImpl::RecordDurationMs(uint32_t& durationMs) bool MediaFileImpl::IsStereo() { WEBRTC_TRACE(kTraceStream, kTraceFile, _id, "MediaFileImpl::IsStereo()"); - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); return _isStereo; } int32_t MediaFileImpl::SetModuleFileCallback(FileCallback* callback) { - CriticalSectionScoped lock(_callbackCrit); + rtc::CritScope lock(&_callbackCrit); _ptrCallback = callback; return 0; @@ -1038,7 +1032,7 @@ int32_t MediaFileImpl::FileDurationMs(const char* fileName, int32_t MediaFileImpl::PlayoutPositionMs(uint32_t& positionMs) const { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_playingActive) { positionMs = 0; @@ -1050,7 +1044,7 @@ int32_t MediaFileImpl::PlayoutPositionMs(uint32_t& positionMs) const int32_t MediaFileImpl::codec_info(CodecInst& codecInst) const { - CriticalSectionScoped lock(_crit); + rtc::CritScope lock(&_crit); if(!_playingActive && !_recordingActive) { WEBRTC_TRACE(kTraceError, kTraceFile, _id, diff --git a/webrtc/modules/media_file/media_file_impl.h b/webrtc/modules/media_file/media_file_impl.h index 677098e8fc..7d974ef313 100644 --- a/webrtc/modules/media_file/media_file_impl.h +++ b/webrtc/modules/media_file/media_file_impl.h @@ -11,12 +11,12 @@ #ifndef WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_ #define WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_ +#include "webrtc/base/criticalsection.h" #include "webrtc/common_types.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/media_file/media_file.h" #include "webrtc/modules/media_file/media_file_defines.h" #include "webrtc/modules/media_file/media_file_utility.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" namespace webrtc { class MediaFileImpl : public MediaFile @@ -120,8 +120,8 @@ private: const uint32_t stopPointMs); int32_t _id; - CriticalSectionWrapper* _crit; - CriticalSectionWrapper* _callbackCrit; + rtc::CriticalSection _crit; + rtc::CriticalSection _callbackCrit; ModuleFileUtility* _ptrFileUtilityObj; CodecInst codec_info_; diff --git a/webrtc/modules/pacing/paced_sender.cc b/webrtc/modules/pacing/paced_sender.cc index 96a6a8860e..a57ec05149 100644 --- a/webrtc/modules/pacing/paced_sender.cc +++ b/webrtc/modules/pacing/paced_sender.cc @@ -23,7 +23,6 @@ #include "webrtc/modules/pacing/bitrate_prober.h" #include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/system_wrappers/include/clock.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/field_trial.h" namespace { @@ -253,7 +252,6 @@ PacedSender::PacedSender(const Clock* clock, : clock_(clock), packet_sender_(packet_sender), alr_detector_(new AlrDetector()), - critsect_(CriticalSectionWrapper::CreateCriticalSection()), paused_(false), media_budget_(new paced_sender::IntervalBudget(0)), padding_budget_(new paced_sender::IntervalBudget(0)), @@ -272,14 +270,14 @@ PacedSender::PacedSender(const Clock* clock, PacedSender::~PacedSender() {} void PacedSender::CreateProbeCluster(int bitrate_bps) { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); prober_->CreateProbeCluster(bitrate_bps, clock_->TimeInMilliseconds()); } void PacedSender::Pause() { LOG(LS_INFO) << "PacedSender paused."; { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); paused_ = true; } // Tell the process thread to call our TimeUntilNextProcess() method to get @@ -291,7 +289,7 @@ void PacedSender::Pause() { void PacedSender::Resume() { LOG(LS_INFO) << "PacedSender resumed."; { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); paused_ = false; } // Tell the process thread to call our TimeUntilNextProcess() method to @@ -302,14 +300,14 @@ void PacedSender::Resume() { void PacedSender::SetProbingEnabled(bool enabled) { RTC_CHECK_EQ(0, packet_counter_); - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); prober_->SetEnabled(enabled); } void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { if (bitrate_bps == 0) LOG(LS_ERROR) << "PacedSender is not designed to handle 0 bitrate."; - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); estimated_bitrate_bps_ = bitrate_bps; padding_budget_->set_target_rate_kbps( std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); @@ -321,7 +319,7 @@ void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, int padding_bitrate) { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); min_send_bitrate_kbps_ = min_send_bitrate_bps / 1000; pacing_bitrate_kbps_ = std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * @@ -337,7 +335,7 @@ void PacedSender::InsertPacket(RtpPacketSender::Priority priority, int64_t capture_time_ms, size_t bytes, bool retransmission) { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); RTC_DCHECK(estimated_bitrate_bps_ > 0) << "SetEstimatedBitrate must be called before InsertPacket."; @@ -353,7 +351,7 @@ void PacedSender::InsertPacket(RtpPacketSender::Priority priority, } int64_t PacedSender::ExpectedQueueTimeMs() const { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); RTC_DCHECK_GT(pacing_bitrate_kbps_, 0); return static_cast(packets_->SizeInBytes() * 8 / pacing_bitrate_kbps_); @@ -361,17 +359,17 @@ int64_t PacedSender::ExpectedQueueTimeMs() const { rtc::Optional PacedSender::GetApplicationLimitedRegionStartTime() const { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); return alr_detector_->GetApplicationLimitedRegionStartTime(); } size_t PacedSender::QueueSizePackets() const { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); return packets_->SizeInPackets(); } int64_t PacedSender::QueueInMs() const { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); int64_t oldest_packet = packets_->OldestEnqueueTimeMs(); if (oldest_packet == 0) @@ -381,13 +379,13 @@ int64_t PacedSender::QueueInMs() const { } int64_t PacedSender::AverageQueueTimeMs() { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); return packets_->AverageQueueTimeMs(); } int64_t PacedSender::TimeUntilNextProcess() { - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); if (paused_) return 1000 * 60 * 60; @@ -403,7 +401,7 @@ int64_t PacedSender::TimeUntilNextProcess() { void PacedSender::Process() { int64_t now_us = clock_->TimeInMicroseconds(); - CriticalSectionScoped cs(critsect_.get()); + rtc::CritScope cs(&critsect_); int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; time_last_update_us_ = now_us; int target_bitrate_kbps = pacing_bitrate_kbps_; @@ -489,11 +487,11 @@ bool PacedSender::SendPacket(const paced_sender::Packet& packet, return false; } - critsect_->Leave(); + critsect_.Leave(); const bool success = packet_sender_->TimeToSendPacket( packet.ssrc, packet.sequence_number, packet.capture_time_ms, packet.retransmission, pacing_info); - critsect_->Enter(); + critsect_.Enter(); if (success) { // TODO(holmer): High priority packets should only be accounted for if we @@ -509,10 +507,10 @@ bool PacedSender::SendPacket(const paced_sender::Packet& packet, size_t PacedSender::SendPadding(size_t padding_needed, const PacedPacketInfo& pacing_info) { - critsect_->Leave(); + critsect_.Leave(); size_t bytes_sent = packet_sender_->TimeToSendPadding(padding_needed, pacing_info); - critsect_->Enter(); + critsect_.Enter(); if (bytes_sent > 0) { UpdateBudgetWithBytesSent(bytes_sent); diff --git a/webrtc/modules/pacing/paced_sender.h b/webrtc/modules/pacing/paced_sender.h index 320e62f076..3b5fe2e45e 100644 --- a/webrtc/modules/pacing/paced_sender.h +++ b/webrtc/modules/pacing/paced_sender.h @@ -15,6 +15,7 @@ #include #include +#include "webrtc/base/criticalsection.h" #include "webrtc/base/optional.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/modules/include/module.h" @@ -25,7 +26,6 @@ namespace webrtc { class AlrDetector; class BitrateProber; class Clock; -class CriticalSectionWrapper; class ProbeClusterCreatedObserver; class RtcEventLog; @@ -162,7 +162,7 @@ class PacedSender : public Module, public RtpPacketSender { PacketSender* const packet_sender_; std::unique_ptr alr_detector_ GUARDED_BY(critsect_); - std::unique_ptr critsect_; + rtc::CriticalSection critsect_; bool paused_ GUARDED_BY(critsect_); // This is the media budget, keeping track of how many bits of media // we can pace out during the current interval.