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

Side by Side Diff: media/audio/android/audio_android_unittest.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: Bloop Created 3 years, 10 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 << "bytes per frame: " << params.GetBytesPerFrame() << endl 151 << "bytes per frame: " << params.GetBytesPerFrame() << endl
152 << "chunk size in ms: " << ExpectedTimeBetweenCallbacks(params) << endl 152 << "chunk size in ms: " << ExpectedTimeBetweenCallbacks(params) << endl
153 << "echo_canceller: " 153 << "echo_canceller: "
154 << (params.effects() & AudioParameters::ECHO_CANCELLER); 154 << (params.effects() & AudioParameters::ECHO_CANCELLER);
155 return os; 155 return os;
156 } 156 }
157 157
158 // Gmock implementation of AudioInputStream::AudioInputCallback. 158 // Gmock implementation of AudioInputStream::AudioInputCallback.
159 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { 159 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback {
160 public: 160 public:
161 MOCK_METHOD4(OnData, 161 MOCK_METHOD5(OnData,
162 void(AudioInputStream* stream, 162 void(AudioInputStream* stream,
163 const AudioBus* src, 163 const AudioBus* src,
164 uint32_t hardware_delay_bytes, 164 base::TimeDelta delay,
165 base::TimeTicks delay_timestamp,
165 double volume)); 166 double volume));
166 MOCK_METHOD1(OnError, void(AudioInputStream* stream)); 167 MOCK_METHOD1(OnError, void(AudioInputStream* stream));
167 }; 168 };
168 169
169 // Implements AudioOutputStream::AudioSourceCallback and provides audio data 170 // Implements AudioOutputStream::AudioSourceCallback and provides audio data
170 // by reading from a data file. 171 // by reading from a data file.
171 class FileAudioSource : public AudioOutputStream::AudioSourceCallback { 172 class FileAudioSource : public AudioOutputStream::AudioSourceCallback {
172 public: 173 public:
173 explicit FileAudioSource(base::WaitableEvent* event, const std::string& name) 174 explicit FileAudioSource(base::WaitableEvent* event, const std::string& name)
174 : event_(event), pos_(0) { 175 : event_(event), pos_(0) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 fwrite(chunk, 1, chunk_size, binary_file_); 269 fwrite(chunk, 1, chunk_size, binary_file_);
269 buffer_->Seek(chunk_size); 270 buffer_->Seek(chunk_size);
270 bytes_written += chunk_size; 271 bytes_written += chunk_size;
271 } 272 }
272 base::CloseFile(binary_file_); 273 base::CloseFile(binary_file_);
273 } 274 }
274 275
275 // AudioInputStream::AudioInputCallback implementation. 276 // AudioInputStream::AudioInputCallback implementation.
276 void OnData(AudioInputStream* stream, 277 void OnData(AudioInputStream* stream,
277 const AudioBus* src, 278 const AudioBus* src,
278 uint32_t hardware_delay_bytes, 279 base::TimeDelta delay,
280 base::TimeTicks delay_timestamp,
279 double volume) override { 281 double volume) override {
280 const int num_samples = src->frames() * src->channels(); 282 const int num_samples = src->frames() * src->channels();
281 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]); 283 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]);
282 const int bytes_per_sample = sizeof(*interleaved); 284 const int bytes_per_sample = sizeof(*interleaved);
283 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); 285 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get());
284 286
285 // Store data data in a temporary buffer to avoid making blocking 287 // Store data data in a temporary buffer to avoid making blocking
286 // fwrite() calls in the audio callback. The complete buffer will be 288 // fwrite() calls in the audio callback. The complete buffer will be
287 // written to file in the destructor. 289 // written to file in the destructor.
288 const int size = bytes_per_sample * num_samples; 290 const int size = bytes_per_sample * num_samples;
(...skipping 27 matching lines...) Expand all
316 // dynamically during the test if required. 318 // dynamically during the test if required.
317 fifo_.reset(new media::SeekableBuffer(0, 2 * params.GetBytesPerBuffer())); 319 fifo_.reset(new media::SeekableBuffer(0, 2 * params.GetBytesPerBuffer()));
318 buffer_.reset(new uint8_t[params_.GetBytesPerBuffer()]); 320 buffer_.reset(new uint8_t[params_.GetBytesPerBuffer()]);
319 } 321 }
320 322
321 ~FullDuplexAudioSinkSource() override {} 323 ~FullDuplexAudioSinkSource() override {}
322 324
323 // AudioInputStream::AudioInputCallback implementation 325 // AudioInputStream::AudioInputCallback implementation
324 void OnData(AudioInputStream* stream, 326 void OnData(AudioInputStream* stream,
325 const AudioBus* src, 327 const AudioBus* src,
326 uint32_t hardware_delay_bytes, 328 base::TimeDelta delay,
329 base::TimeTicks delay_timestamp,
327 double volume) override { 330 double volume) override {
328 const base::TimeTicks now_time = base::TimeTicks::Now(); 331 const base::TimeTicks now_time = base::TimeTicks::Now();
329 const int diff = (now_time - previous_time_).InMilliseconds(); 332 const int diff = (now_time - previous_time_).InMilliseconds();
330 333
331 EXPECT_EQ(params_.bits_per_sample(), 16); 334 EXPECT_EQ(params_.bits_per_sample(), 16);
332 const int num_samples = src->frames() * src->channels(); 335 const int num_samples = src->frames() * src->channels();
333 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]); 336 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]);
334 const int bytes_per_sample = sizeof(*interleaved); 337 const int bytes_per_sample = sizeof(*interleaved);
335 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); 338 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get());
336 const int size = bytes_per_sample * num_samples; 339 const int size = bytes_per_sample * num_samples;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 ExpectedTimeBetweenCallbacks(params); 653 ExpectedTimeBetweenCallbacks(params);
651 const int num_callbacks = 654 const int num_callbacks =
652 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); 655 (kCallbackTestTimeMs / expected_time_between_callbacks_ms);
653 656
654 MakeAudioInputStreamOnAudioThread(params); 657 MakeAudioInputStreamOnAudioThread(params);
655 658
656 int count = 0; 659 int count = 0;
657 MockAudioInputCallback sink; 660 MockAudioInputCallback sink;
658 661
659 base::RunLoop run_loop; 662 base::RunLoop run_loop;
660 EXPECT_CALL(sink, OnData(audio_input_stream_, NotNull(), _, _)) 663 EXPECT_CALL(sink, OnData(audio_input_stream_, NotNull(), _, _, _))
661 .Times(AtLeast(num_callbacks)) 664 .Times(AtLeast(num_callbacks))
662 .WillRepeatedly(CheckCountAndPostQuitTask( 665 .WillRepeatedly(CheckCountAndPostQuitTask(
663 &count, num_callbacks, base::ThreadTaskRunnerHandle::Get(), 666 &count, num_callbacks, base::ThreadTaskRunnerHandle::Get(),
664 run_loop.QuitWhenIdleClosure())); 667 run_loop.QuitWhenIdleClosure()));
665 EXPECT_CALL(sink, OnError(audio_input_stream_)).Times(0); 668 EXPECT_CALL(sink, OnError(audio_input_stream_)).Times(0);
666 669
667 OpenAndStartAudioInputStreamOnAudioThread(&sink); 670 OpenAndStartAudioInputStreamOnAudioThread(&sink);
668 671
669 start_time_ = base::TimeTicks::Now(); 672 start_time_ = base::TimeTicks::Now();
670 run_loop.Run(); 673 run_loop.Run();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 printf("\n"); 966 printf("\n");
964 StopAndCloseAudioOutputStreamOnAudioThread(); 967 StopAndCloseAudioOutputStreamOnAudioThread();
965 StopAndCloseAudioInputStreamOnAudioThread(); 968 StopAndCloseAudioInputStreamOnAudioThread();
966 } 969 }
967 970
968 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, 971 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest,
969 AudioAndroidInputTest, 972 AudioAndroidInputTest,
970 testing::Bool()); 973 testing::Bool());
971 974
972 } // namespace media 975 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698