| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/audio_modem/audio_recorder.h" | 5 #include "components/audio_modem/audio_recorder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/aligned_memory.h" | 14 #include "base/memory/aligned_memory.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "components/audio_modem/audio_recorder_impl.h" | 18 #include "components/audio_modem/audio_recorder_impl.h" |
| 18 #include "components/audio_modem/public/audio_modem_types.h" | 19 #include "components/audio_modem/public/audio_modem_types.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void SetVolume(double volume) override {} | 57 void SetVolume(double volume) override {} |
| 57 double GetVolume() override { return 1.0; } | 58 double GetVolume() override { return 1.0; } |
| 58 bool SetAutomaticGainControl(bool enabled) override { return false; } | 59 bool SetAutomaticGainControl(bool enabled) override { return false; } |
| 59 bool GetAutomaticGainControl() override { return true; } | 60 bool GetAutomaticGainControl() override { return true; } |
| 60 bool IsMuted() override { return false; } | 61 bool IsMuted() override { return false; } |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 void SimulateRecording() { | 64 void SimulateRecording() { |
| 64 const int fpb = params_.frames_per_buffer(); | 65 const int fpb = params_.frames_per_buffer(); |
| 65 for (int i = 0; i < buffer_->frames() / fpb; ++i) { | 66 for (int i = 0; i < buffer_->frames() / fpb; ++i) { |
| 66 scoped_ptr<media::AudioBus> source = media::AudioBus::Create(2, fpb); | 67 std::unique_ptr<media::AudioBus> source = media::AudioBus::Create(2, fpb); |
| 67 buffer_->CopyPartialFramesTo(i * fpb, fpb, 0, source.get()); | 68 buffer_->CopyPartialFramesTo(i * fpb, fpb, 0, source.get()); |
| 68 callback_->OnData(this, source.get(), fpb, 1.0); | 69 callback_->OnData(this, source.get(), fpb, 1.0); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 AudioInputCallback* callback_; | 73 AudioInputCallback* callback_; |
| 73 media::AudioParameters params_; | 74 media::AudioParameters params_; |
| 74 scoped_ptr<media::AudioBus> buffer_; | 75 std::unique_ptr<media::AudioBus> buffer_; |
| 75 | 76 |
| 76 DISALLOW_COPY_AND_ASSIGN(TestAudioInputStream); | 77 DISALLOW_COPY_AND_ASSIGN(TestAudioInputStream); |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 } // namespace | 80 } // namespace |
| 80 | 81 |
| 81 namespace audio_modem { | 82 namespace audio_modem { |
| 82 | 83 |
| 83 class AudioRecorderTest : public testing::Test { | 84 class AudioRecorderTest : public testing::Test { |
| 84 public: | 85 public: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 198 |
| 198 std::vector<float*> channel_data_; | 199 std::vector<float*> channel_data_; |
| 199 media::AudioParameters params_; | 200 media::AudioParameters params_; |
| 200 size_t total_samples_; | 201 size_t total_samples_; |
| 201 | 202 |
| 202 // Deleted by calling Finalize() on the object. | 203 // Deleted by calling Finalize() on the object. |
| 203 AudioRecorderImpl* recorder_; | 204 AudioRecorderImpl* recorder_; |
| 204 | 205 |
| 205 std::string received_samples_; | 206 std::string received_samples_; |
| 206 | 207 |
| 207 scoped_ptr<base::RunLoop> run_loop_; | 208 std::unique_ptr<base::RunLoop> run_loop_; |
| 208 }; | 209 }; |
| 209 | 210 |
| 210 | 211 |
| 211 // http://crbug.com/463854 | 212 // http://crbug.com/463854 |
| 212 #if defined(OS_MACOSX) | 213 #if defined(OS_MACOSX) |
| 213 #define MAYBE_BasicRecordAndStop DISABLED_BasicRecordAndStop | 214 #define MAYBE_BasicRecordAndStop DISABLED_BasicRecordAndStop |
| 214 #else | 215 #else |
| 215 #define MAYBE_BasicRecordAndStop BasicRecordAndStop | 216 #define MAYBE_BasicRecordAndStop BasicRecordAndStop |
| 216 #endif | 217 #endif |
| 217 | 218 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 CreateRecorder(kNumSamples); | 273 CreateRecorder(kNumSamples); |
| 273 | 274 |
| 274 RecordAndVerifySamples(); | 275 RecordAndVerifySamples(); |
| 275 | 276 |
| 276 DeleteRecorder(); | 277 DeleteRecorder(); |
| 277 } | 278 } |
| 278 | 279 |
| 279 // TODO(rkc): Add tests with recording different sample rates. | 280 // TODO(rkc): Add tests with recording different sample rates. |
| 280 | 281 |
| 281 } // namespace audio_modem | 282 } // namespace audio_modem |
| OLD | NEW |