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

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: Made some methods private. Readded init. 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/criticalsection.h" 16 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/base/platform_thread.h" 17 #include "webrtc/base/platform_thread.h"
18 #include "webrtc/modules/audio_device/include/fake_audio_device.h" 18 #include "webrtc/modules/audio_device/include/fake_audio_device.h"
19 #include "webrtc/test/drifting_clock.h" 19 #include "webrtc/test/drifting_clock.h"
20 #include "webrtc/typedefs.h" 20 #include "webrtc/typedefs.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 23
24 class Clock; 24 class Clock;
25 class EventTimerWrapper; 25 class EventTimerWrapper;
26 class FileWrapper;
27 class ModuleFileUtility;
28 26
29 namespace test { 27 namespace test {
30 28
31 class FakeAudioDevice : public FakeAudioDeviceModule { 29 class FakeAudioDevice : public FakeAudioDeviceModule {
32 public: 30 public:
33 FakeAudioDevice(Clock* clock, const std::string& filename, float speed); 31 FakeAudioDevice(Clock* clock, float speed);
the sun 2017/01/24 08:58:12 What's "speed"?
perkj_webrtc 2017/01/24 09:57:03 Added a comment. Note that this is nothing I want
34
35 virtual ~FakeAudioDevice(); 32 virtual ~FakeAudioDevice();
the sun 2017/01/24 08:58:12 override
perkj_webrtc 2017/01/24 09:57:03 Done.
36 33
34 int32_t StartPlayout() override;
35 int32_t StopPlayout() override;
36
37 // Generates a sine tone with |frequency_in_hz| and |peak_to_peak|.
38 void StartRecordingSine(int frequency_in_hz, uint16_t peak_to_peak);
39 int32_t StopRecording() override;
40
41 private:
37 int32_t Init() override; 42 int32_t Init() override;
38 int32_t RegisterAudioCallback(AudioTransport* callback) override; 43 int32_t RegisterAudioCallback(AudioTransport* callback) override;
39 44
40 bool Playing() const override; 45 bool Playing() const override;
41 int32_t PlayoutDelay(uint16_t* delay_ms) const override; 46 int32_t PlayoutDelay(uint16_t* delay_ms) const override;
42 bool Recording() const override; 47 bool Recording() const override;
43 48
44 void Start();
45 void Stop();
46
47 private:
48 static bool Run(void* obj); 49 static bool Run(void* obj);
49 void CaptureAudio(); 50 void ProcessAudio();
50 51
51 static const uint32_t kFrequencyHz = 16000; 52 static const uint32_t kFrequencyHz = 16000;
52 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; 53 static const size_t kBufferSizeBytes = 2 * kFrequencyHz;
53 54
54 AudioTransport* audio_callback_; 55 rtc::CriticalSection lock_;
55 bool capturing_; 56 AudioTransport* audio_callback_ GUARDED_BY(lock_);
57 bool recording_ GUARDED_BY(lock_);
58 bool playing_ GUARDED_BY(lock_);
59
60 // Used for recording.
61 double normalized_frequency_ GUARDED_BY(lock_);
the sun 2017/01/24 08:58:12 float
perkj_webrtc 2017/01/24 09:57:03 Done.
62 uint16_t peak_to_peak_ GUARDED_BY(lock_);
the sun 2017/01/24 08:58:12 float
perkj_webrtc 2017/01/24 09:57:03 Done.
63 double n_;
the sun 2017/01/24 08:58:12 float
perkj_webrtc 2017/01/24 09:57:03 Done.
56 int8_t captured_audio_[kBufferSizeBytes]; 64 int8_t captured_audio_[kBufferSizeBytes];
65
66 // Used for playout.
57 int8_t playout_buffer_[kBufferSizeBytes]; 67 int8_t playout_buffer_[kBufferSizeBytes];
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_;
the sun 2017/01/24 08:58:12 Are there any build file deps you can remove now?
perkj_webrtc 2017/01/24 09:57:03 Done.
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