| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/copresence/mediums/audio/audio_recorder.h" | 5 #include "components/copresence/mediums/audio/audio_recorder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/aligned_memory.h" | 8 #include "base/memory/aligned_memory.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "components/copresence/mediums/audio/audio_recorder_impl.h" |
| 10 #include "components/copresence/public/copresence_constants.h" | 11 #include "components/copresence/public/copresence_constants.h" |
| 11 #include "components/copresence/test/audio_test_support.h" | 12 #include "components/copresence/test/audio_test_support.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
| 14 #include "media/audio/audio_manager_base.h" | 15 #include "media/audio/audio_manager_base.h" |
| 15 #include "media/base/audio_bus.h" | 16 #include "media/base/audio_bus.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 79 } |
| 79 | 80 |
| 80 virtual ~AudioRecorderTest() { | 81 virtual ~AudioRecorderTest() { |
| 81 DeleteRecorder(); | 82 DeleteRecorder(); |
| 82 for (size_t i = 0; i < channel_data_.size(); ++i) | 83 for (size_t i = 0; i < channel_data_.size(); ++i) |
| 83 base::AlignedFree(channel_data_[i]); | 84 base::AlignedFree(channel_data_[i]); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void CreateSimpleRecorder() { | 87 void CreateSimpleRecorder() { |
| 87 DeleteRecorder(); | 88 DeleteRecorder(); |
| 88 recorder_ = new AudioRecorder( | 89 recorder_ = new AudioRecorderImpl(); |
| 90 recorder_->Initialize( |
| 89 base::Bind(&AudioRecorderTest::DecodeSamples, base::Unretained(this))); | 91 base::Bind(&AudioRecorderTest::DecodeSamples, base::Unretained(this))); |
| 90 recorder_->Initialize(); | |
| 91 } | 92 } |
| 92 | 93 |
| 93 void CreateRecorder(size_t channels, | 94 void CreateRecorder(size_t channels, |
| 94 size_t sample_rate, | 95 size_t sample_rate, |
| 95 size_t bits_per_sample, | 96 size_t bits_per_sample, |
| 96 size_t samples) { | 97 size_t samples) { |
| 97 DeleteRecorder(); | 98 DeleteRecorder(); |
| 98 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 99 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 99 kDefaultChannelLayout, | 100 kDefaultChannelLayout, |
| 100 channels, | 101 channels, |
| 101 sample_rate, | 102 sample_rate, |
| 102 bits_per_sample, | 103 bits_per_sample, |
| 103 4096); | 104 4096); |
| 104 | 105 |
| 105 channel_data_.clear(); | 106 channel_data_.clear(); |
| 106 channel_data_.push_back(GenerateSamples(0x1337, samples)); | 107 channel_data_.push_back(GenerateSamples(0x1337, samples)); |
| 107 channel_data_.push_back(GenerateSamples(0x7331, samples)); | 108 channel_data_.push_back(GenerateSamples(0x7331, samples)); |
| 108 | 109 |
| 109 total_samples_ = samples; | 110 total_samples_ = samples; |
| 110 | 111 |
| 111 recorder_ = new AudioRecorder( | 112 recorder_ = new AudioRecorderImpl(); |
| 112 base::Bind(&AudioRecorderTest::DecodeSamples, base::Unretained(this))); | |
| 113 recorder_->set_input_stream_for_testing( | 113 recorder_->set_input_stream_for_testing( |
| 114 new TestAudioInputStream(params_, channel_data_, samples)); | 114 new TestAudioInputStream(params_, channel_data_, samples)); |
| 115 recorder_->set_params_for_testing(new media::AudioParameters(params_)); | 115 recorder_->set_params_for_testing(new media::AudioParameters(params_)); |
| 116 recorder_->Initialize(); | 116 recorder_->Initialize( |
| 117 base::Bind(&AudioRecorderTest::DecodeSamples, base::Unretained(this))); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void DeleteRecorder() { | 120 void DeleteRecorder() { |
| 120 if (!recorder_) | 121 if (!recorder_) |
| 121 return; | 122 return; |
| 122 recorder_->Finalize(); | 123 recorder_->Finalize(); |
| 123 recorder_ = NULL; | 124 recorder_ = NULL; |
| 124 } | 125 } |
| 125 | 126 |
| 126 void RecordAndVerifySamples() { | 127 void RecordAndVerifySamples() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 175 } |
| 175 bool IsRecording() { | 176 bool IsRecording() { |
| 176 recorder_->FlushAudioLoopForTesting(); | 177 recorder_->FlushAudioLoopForTesting(); |
| 177 return recorder_->is_recording_; | 178 return recorder_->is_recording_; |
| 178 } | 179 } |
| 179 | 180 |
| 180 std::vector<float*> channel_data_; | 181 std::vector<float*> channel_data_; |
| 181 media::AudioParameters params_; | 182 media::AudioParameters params_; |
| 182 size_t total_samples_; | 183 size_t total_samples_; |
| 183 | 184 |
| 184 AudioRecorder* recorder_; | 185 // Deleted by calling Finalize() on the object. |
| 186 AudioRecorderImpl* recorder_; |
| 185 | 187 |
| 186 std::string received_samples_; | 188 std::string received_samples_; |
| 187 | 189 |
| 188 scoped_ptr<base::RunLoop> run_loop_; | 190 scoped_ptr<base::RunLoop> run_loop_; |
| 189 content::TestBrowserThreadBundle thread_bundle_; | 191 content::TestBrowserThreadBundle thread_bundle_; |
| 190 }; | 192 }; |
| 191 | 193 |
| 192 // TODO(rkc): These tests are broken on all platforms. | 194 // TODO(rkc): These tests are broken on all platforms. |
| 193 // On Windows and Mac, we cannot use non-OS params. The tests need to be | 195 // On Windows and Mac, we cannot use non-OS params. The tests need to be |
| 194 // rewritten to use the params provided to us by the audio manager | 196 // rewritten to use the params provided to us by the audio manager |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 kDefaultChannels, kDefaultSampleRate, kDefaultBitsPerSample, kNumSamples); | 246 kDefaultChannels, kDefaultSampleRate, kDefaultBitsPerSample, kNumSamples); |
| 245 | 247 |
| 246 RecordAndVerifySamples(); | 248 RecordAndVerifySamples(); |
| 247 | 249 |
| 248 DeleteRecorder(); | 250 DeleteRecorder(); |
| 249 } | 251 } |
| 250 | 252 |
| 251 // TODO(rkc): Add tests with recording different sample rates. | 253 // TODO(rkc): Add tests with recording different sample rates. |
| 252 | 254 |
| 253 } // namespace copresence | 255 } // namespace copresence |
| OLD | NEW |