OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 | 10 |
11 #include "pc/test/fakeaudiocapturemodule.h" | 11 #include "pc/test/fakeaudiocapturemodule.h" |
12 | 12 |
13 #include "rtc_base/checks.h" | 13 #include "rtc_base/checks.h" |
14 #include "rtc_base/refcount.h" | 14 #include "rtc_base/refcount.h" |
15 #include "rtc_base/thread.h" | 15 #include "rtc_base/thread.h" |
16 #include "rtc_base/timeutils.h" | 16 #include "rtc_base/timeutils.h" |
17 | 17 |
18 // Audio sample value that is high enough that it doesn't occur naturally when | 18 // Audio sample value that is high enough that it doesn't occur naturally when |
19 // frames are being faked. E.g. NetEq will not generate this large sample value | 19 // frames are being faked. E.g. NetEq will not generate this large sample value |
20 // unless it has received an audio frame containing a sample of this value. | 20 // unless it has received an audio frame containing a sample of this value. |
21 // Even simpler buffers would likely just contain audio sample values of 0. | 21 // Even simpler buffers would likely just contain audio sample values of 0. |
22 static const int kHighSampleValue = 10000; | 22 static const int kHighSampleValue = 10000; |
23 | 23 |
24 // Same value as src/modules/audio_device/main/source/audio_device_config.h in | |
25 // https://code.google.com/p/webrtc/ | |
26 static const int kAdmMaxIdleTimeProcess = 1000; | |
27 | |
28 // Constants here are derived by running VoE using a real ADM. | 24 // Constants here are derived by running VoE using a real ADM. |
29 // The constants correspond to 10ms of mono audio at 44kHz. | 25 // The constants correspond to 10ms of mono audio at 44kHz. |
30 static const int kTimePerFrameMs = 10; | 26 static const int kTimePerFrameMs = 10; |
31 static const uint8_t kNumberOfChannels = 1; | 27 static const uint8_t kNumberOfChannels = 1; |
32 static const int kSamplesPerSecond = 44000; | 28 static const int kSamplesPerSecond = 44000; |
33 static const int kTotalDelayMs = 0; | 29 static const int kTotalDelayMs = 0; |
34 static const int kClockDriftMs = 0; | 30 static const int kClockDriftMs = 0; |
35 static const uint32_t kMaxVolume = 14392; | 31 static const uint32_t kMaxVolume = 14392; |
36 | 32 |
37 enum { | 33 enum { |
38 MSG_START_PROCESS, | 34 MSG_START_PROCESS, |
39 MSG_RUN_PROCESS, | 35 MSG_RUN_PROCESS, |
40 }; | 36 }; |
41 | 37 |
42 FakeAudioCaptureModule::FakeAudioCaptureModule() | 38 FakeAudioCaptureModule::FakeAudioCaptureModule() |
43 : last_process_time_ms_(0), | 39 : audio_callback_(nullptr), |
44 audio_callback_(nullptr), | |
45 recording_(false), | 40 recording_(false), |
46 playing_(false), | 41 playing_(false), |
47 play_is_initialized_(false), | 42 play_is_initialized_(false), |
48 rec_is_initialized_(false), | 43 rec_is_initialized_(false), |
49 current_mic_level_(kMaxVolume), | 44 current_mic_level_(kMaxVolume), |
50 started_(false), | 45 started_(false), |
51 next_frame_time_(0), | 46 next_frame_time_(0), |
52 frames_received_(0) { | 47 frames_received_(0) { |
53 } | 48 } |
54 | 49 |
(...skipping 10 matching lines...) Expand all Loading... |
65 return nullptr; | 60 return nullptr; |
66 } | 61 } |
67 return capture_module; | 62 return capture_module; |
68 } | 63 } |
69 | 64 |
70 int FakeAudioCaptureModule::frames_received() const { | 65 int FakeAudioCaptureModule::frames_received() const { |
71 rtc::CritScope cs(&crit_); | 66 rtc::CritScope cs(&crit_); |
72 return frames_received_; | 67 return frames_received_; |
73 } | 68 } |
74 | 69 |
75 int64_t FakeAudioCaptureModule::TimeUntilNextProcess() { | |
76 const int64_t current_time = rtc::TimeMillis(); | |
77 if (current_time < last_process_time_ms_) { | |
78 // TODO: wraparound could be handled more gracefully. | |
79 return 0; | |
80 } | |
81 const int64_t elapsed_time = current_time - last_process_time_ms_; | |
82 if (kAdmMaxIdleTimeProcess < elapsed_time) { | |
83 return 0; | |
84 } | |
85 return kAdmMaxIdleTimeProcess - elapsed_time; | |
86 } | |
87 | |
88 void FakeAudioCaptureModule::Process() { | |
89 last_process_time_ms_ = rtc::TimeMillis(); | |
90 } | |
91 | |
92 int32_t FakeAudioCaptureModule::ActiveAudioLayer( | 70 int32_t FakeAudioCaptureModule::ActiveAudioLayer( |
93 AudioLayer* /*audio_layer*/) const { | 71 AudioLayer* /*audio_layer*/) const { |
94 RTC_NOTREACHED(); | 72 RTC_NOTREACHED(); |
95 return 0; | 73 return 0; |
96 } | 74 } |
97 | 75 |
98 webrtc::AudioDeviceModule::ErrorCode FakeAudioCaptureModule::LastError() const { | 76 webrtc::AudioDeviceModule::ErrorCode FakeAudioCaptureModule::LastError() const { |
99 RTC_NOTREACHED(); | 77 RTC_NOTREACHED(); |
100 return webrtc::AudioDeviceModule::kAdmErrNone; | 78 return webrtc::AudioDeviceModule::kAdmErrNone; |
101 } | 79 } |
102 | 80 |
103 int32_t FakeAudioCaptureModule::RegisterEventObserver( | |
104 webrtc::AudioDeviceObserver* /*event_callback*/) { | |
105 // Only used to report warnings and errors. This fake implementation won't | |
106 // generate any so discard this callback. | |
107 return 0; | |
108 } | |
109 | |
110 int32_t FakeAudioCaptureModule::RegisterAudioCallback( | 81 int32_t FakeAudioCaptureModule::RegisterAudioCallback( |
111 webrtc::AudioTransport* audio_callback) { | 82 webrtc::AudioTransport* audio_callback) { |
112 rtc::CritScope cs(&crit_callback_); | 83 rtc::CritScope cs(&crit_callback_); |
113 audio_callback_ = audio_callback; | 84 audio_callback_ = audio_callback; |
114 return 0; | 85 return 0; |
115 } | 86 } |
116 | 87 |
117 int32_t FakeAudioCaptureModule::Init() { | 88 int32_t FakeAudioCaptureModule::Init() { |
118 // Initialize is called by the factory method. Safe to ignore this Init call. | 89 // Initialize is called by the factory method. Safe to ignore this Init call. |
119 return 0; | 90 return 0; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 RTC_NOTREACHED(); | 469 RTC_NOTREACHED(); |
499 } | 470 } |
500 } | 471 } |
501 | 472 |
502 bool FakeAudioCaptureModule::Initialize() { | 473 bool FakeAudioCaptureModule::Initialize() { |
503 // Set the send buffer samples high enough that it would not occur on the | 474 // Set the send buffer samples high enough that it would not occur on the |
504 // remote side unless a packet containing a sample of that magnitude has been | 475 // remote side unless a packet containing a sample of that magnitude has been |
505 // sent to it. Note that the audio processing pipeline will likely distort the | 476 // sent to it. Note that the audio processing pipeline will likely distort the |
506 // original signal. | 477 // original signal. |
507 SetSendBuffer(kHighSampleValue); | 478 SetSendBuffer(kHighSampleValue); |
508 last_process_time_ms_ = rtc::TimeMillis(); | |
509 return true; | 479 return true; |
510 } | 480 } |
511 | 481 |
512 void FakeAudioCaptureModule::SetSendBuffer(int value) { | 482 void FakeAudioCaptureModule::SetSendBuffer(int value) { |
513 Sample* buffer_ptr = reinterpret_cast<Sample*>(send_buffer_); | 483 Sample* buffer_ptr = reinterpret_cast<Sample*>(send_buffer_); |
514 const size_t buffer_size_in_samples = | 484 const size_t buffer_size_in_samples = |
515 sizeof(send_buffer_) / kNumberBytesPerSample; | 485 sizeof(send_buffer_) / kNumberBytesPerSample; |
516 for (size_t i = 0; i < buffer_size_in_samples; ++i) { | 486 for (size_t i = 0; i < buffer_size_in_samples; ++i) { |
517 buffer_ptr[i] = value; | 487 buffer_ptr[i] = value; |
518 } | 488 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 kNumberBytesPerSample, | 600 kNumberBytesPerSample, |
631 kNumberOfChannels, | 601 kNumberOfChannels, |
632 kSamplesPerSecond, kTotalDelayMs, | 602 kSamplesPerSecond, kTotalDelayMs, |
633 kClockDriftMs, current_mic_level, | 603 kClockDriftMs, current_mic_level, |
634 key_pressed, | 604 key_pressed, |
635 current_mic_level) != 0) { | 605 current_mic_level) != 0) { |
636 RTC_NOTREACHED(); | 606 RTC_NOTREACHED(); |
637 } | 607 } |
638 SetMicrophoneVolume(current_mic_level); | 608 SetMicrophoneVolume(current_mic_level); |
639 } | 609 } |
OLD | NEW |