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

Side by Side Diff: webrtc/test/fake_audio_device.h

Issue 2652803002: Refactor FakeAudioDevice to have separate methods for starting recording and playout. (Closed)
Patch Set: Use 48000KHz sample rate. Changed from sine to a noise pulse. 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ 10 #ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
11 #define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ 11 #define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
12 12
13 #include <memory> 13 #include <memory>
14 #include <string> 14 #include <string>
15 15
16 #include "webrtc/base/buffer.h"
16 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/base/platform_thread.h" 18 #include "webrtc/base/platform_thread.h"
18 #include "webrtc/modules/audio_device/include/fake_audio_device.h" 19 #include "webrtc/modules/audio_device/include/fake_audio_device.h"
19 #include "webrtc/test/drifting_clock.h" 20 #include "webrtc/test/drifting_clock.h"
20 #include "webrtc/typedefs.h" 21 #include "webrtc/typedefs.h"
21 22
22 namespace webrtc { 23 namespace webrtc {
23 24
24 class Clock; 25 class Clock;
25 class EventTimerWrapper; 26 class EventTimerWrapper;
26 class FileWrapper;
27 class ModuleFileUtility;
28 27
29 namespace test { 28 namespace test {
30 29
31 class FakeAudioDevice : public FakeAudioDeviceModule { 30 class FakeAudioDevice : public FakeAudioDeviceModule {
32 public: 31 public:
33 FakeAudioDevice(Clock* clock, const std::string& filename, float speed); 32 // Creates a new FakeAudioDevice. |speed| controls how much faster or slower
33 // time elapse compared to the system clock. It can be used to simulate
34 // clock drift. 1.0 means that the system clock will be used.
35 FakeAudioDevice(Clock* clock, float speed, int sampling_frequency_in_hz);
36 ~FakeAudioDevice() override;
34 37
35 virtual ~FakeAudioDevice(); 38 int32_t StartPlayout() override;
39 int32_t StopPlayout() override;
36 40
41 // Generates a signal where every second frame is zero and every second frame
42 // is evenly distributed random noise with max amplitude |max_amplitude|.
43 void StartRecordingPulsedNoise(int16_t max_amplitude);
44 int32_t StopRecording() override;
45
46 private:
37 int32_t Init() override; 47 int32_t Init() override;
38 int32_t RegisterAudioCallback(AudioTransport* callback) override; 48 int32_t RegisterAudioCallback(AudioTransport* callback) override;
39 49
40 bool Playing() const override; 50 bool Playing() const override;
41 int32_t PlayoutDelay(uint16_t* delay_ms) const override; 51 int32_t PlayoutDelay(uint16_t* delay_ms) const override;
42 bool Recording() const override; 52 bool Recording() const override;
43 53
44 void Start(); 54 static bool Run(void* obj);
45 void Stop(); 55 void ProcessAudio();
46 56
47 private: 57 const int sampling_frequency_in_hz_;
48 static bool Run(void* obj);
49 void CaptureAudio();
50 58
51 static const uint32_t kFrequencyHz = 16000; 59 rtc::CriticalSection lock_;
52 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; 60 AudioTransport* audio_callback_ GUARDED_BY(lock_);
61 bool rendering_ GUARDED_BY(lock_);
53 62
54 AudioTransport* audio_callback_; 63 class PulsedNoiseCapturer;
55 bool capturing_; 64 std::unique_ptr<PulsedNoiseCapturer> capturer_ GUARDED_BY(lock_);
56 int8_t captured_audio_[kBufferSizeBytes]; 65
57 int8_t playout_buffer_[kBufferSizeBytes]; 66 // Used for playout.
67 rtc::BufferT<int16_t> playout_buffer_;
peah-webrtc 2017/01/26 09:24:00 Since the size of playout_buffer_ is static, I thi
58 const float speed_; 68 const float speed_;
59 int64_t last_playout_ms_; 69 int64_t last_playout_ms_;
60 70
61 DriftingClock clock_; 71 DriftingClock clock_;
62 std::unique_ptr<EventTimerWrapper> tick_; 72 std::unique_ptr<EventTimerWrapper> tick_;
63 rtc::CriticalSection lock_;
64 rtc::PlatformThread thread_; 73 rtc::PlatformThread thread_;
65 std::unique_ptr<ModuleFileUtility> file_utility_;
66 std::unique_ptr<FileWrapper> input_stream_;
67 }; 74 };
68 } // namespace test 75 } // namespace test
69 } // namespace webrtc 76 } // namespace webrtc
70 77
71 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ 78 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698