From 4af9f962c3a79b97c4b2d85be4c30c9b77ef7a21 Mon Sep 17 00:00:00 2001 From: tommi Date: Sat, 25 Feb 2017 09:05:22 -0800 Subject: [PATCH] Fix busy loop in FakeAudioDeviceModule. The implementation now has a mechanism that effectively turns off callbacks if used. BUG=webrtc:7237, 695438 TBR=solenberg@webrtc.org Review-Url: https://codereview.webrtc.org/2710023010 Cr-Commit-Position: refs/heads/master@{#16837} --- .../audio_device/include/fake_audio_device.h | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/audio_device/include/fake_audio_device.h b/webrtc/modules/audio_device/include/fake_audio_device.h index a28ad86464..1797dd5e8d 100644 --- a/webrtc/modules/audio_device/include/fake_audio_device.h +++ b/webrtc/modules/audio_device/include/fake_audio_device.h @@ -41,8 +41,20 @@ class FakeAudioDeviceModule : public AudioDeviceModule { virtual int32_t SetStereoRecording(bool enable) { return 0; } virtual int32_t SetAGC(bool enable) { return 0; } virtual int32_t StopRecording() { return 0; } - virtual int64_t TimeUntilNextProcess() { return 0; } - virtual void Process() {} + + // If the subclass doesn't override the ProcessThread implementation, + // we'll fall back on an implementation that doesn't eat too much CPU. + virtual int64_t TimeUntilNextProcess() { + if (turn_off_module_callbacks_) + return 7 * 24 * 60 * 60 * 1000; // call me next week. + uses_default_module_implementation_ = true; + return 10; + } + + virtual void Process() { + turn_off_module_callbacks_ = uses_default_module_implementation_; + } + virtual int32_t Terminate() { return 0; } virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const { return 0; } @@ -167,6 +179,10 @@ class FakeAudioDeviceModule : public AudioDeviceModule { return -1; } #endif // WEBRTC_IOS + + private: + bool uses_default_module_implementation_ = false; + bool turn_off_module_callbacks_ = false; }; } // namespace webrtc