Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2134)

Unified Diff: webrtc/test/fake_audio_device.h

Issue 2652803002: Refactor FakeAudioDevice to have separate methods for starting recording and playout. (Closed)
Patch Set: Addressed review comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/test/fake_audio_device.h
diff --git a/webrtc/test/fake_audio_device.h b/webrtc/test/fake_audio_device.h
index 77a74bac8f6d1bc962cf8b8aceea9313f9c50bec..1f10bd5d609604ce50c0c90dd1a62e139e27c8e8 100644
--- a/webrtc/test/fake_audio_device.h
+++ b/webrtc/test/fake_audio_device.h
@@ -12,6 +12,7 @@
#include <memory>
#include <string>
+#include <vector>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/platform_thread.h"
@@ -23,17 +24,26 @@ namespace webrtc {
class Clock;
class EventTimerWrapper;
-class FileWrapper;
-class ModuleFileUtility;
namespace test {
class FakeAudioDevice : public FakeAudioDeviceModule {
public:
- FakeAudioDevice(Clock* clock, const std::string& filename, float speed);
+ // Creates a new FakeAudioDevice. |speed| controls how much faster or slower
+ // time elapse compared to the system clock. It can be used to simulate
+ // clock drift. 1.0 means that the system clock will be used.
+ FakeAudioDevice(Clock* clock, float speed, int sampling_frequency_in_hz);
+ ~FakeAudioDevice() override;
- virtual ~FakeAudioDevice();
+ int32_t StartPlayout() override;
+ int32_t StopPlayout() override;
+ // Generates a signal where every second frame is zero and every second frame
+ // is evenly distributed random noise with max amplitude |max_amplitude|.
+ void StartRecordingPulsedNoise(int16_t max_amplitude);
+ int32_t StopRecording() override;
+
+ private:
int32_t Init() override;
int32_t RegisterAudioCallback(AudioTransport* callback) override;
@@ -41,29 +51,26 @@ class FakeAudioDevice : public FakeAudioDeviceModule {
int32_t PlayoutDelay(uint16_t* delay_ms) const override;
bool Recording() const override;
- void Start();
- void Stop();
-
- private:
static bool Run(void* obj);
- void CaptureAudio();
+ void ProcessAudio();
- static const uint32_t kFrequencyHz = 16000;
- static const size_t kBufferSizeBytes = 2 * kFrequencyHz;
+ const int sampling_frequency_in_hz_;
- AudioTransport* audio_callback_;
- bool capturing_;
- int8_t captured_audio_[kBufferSizeBytes];
- int8_t playout_buffer_[kBufferSizeBytes];
+ rtc::CriticalSection lock_;
+ AudioTransport* audio_callback_ GUARDED_BY(lock_);
+ bool rendering_ GUARDED_BY(lock_);
+
+ class PulsedNoiseCapturer;
+ std::unique_ptr<PulsedNoiseCapturer> capturer_ GUARDED_BY(lock_);
+
+ // Used for playout.
+ std::vector<int16_t> playout_buffer_;
peah-webrtc 2017/01/26 13:20:12 playout_buffer_ should also be guarded by lock_, r
perkj_webrtc 2017/01/29 13:25:20 Done.
const float speed_;
int64_t last_playout_ms_;
peah-webrtc 2017/01/26 13:20:12 last_playout_ms_ should also be guarded by lock_,
perkj_webrtc 2017/01/29 13:25:20 removed
DriftingClock clock_;
std::unique_ptr<EventTimerWrapper> tick_;
peah-webrtc 2017/01/26 13:20:12 Does clock_ and tick_ need to be guarded by lock_?
perkj_webrtc 2017/01/29 13:25:20 removed
- rtc::CriticalSection lock_;
rtc::PlatformThread thread_;
- std::unique_ptr<ModuleFileUtility> file_utility_;
- std::unique_ptr<FileWrapper> input_stream_;
};
} // namespace test
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698