OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/environment.h" | 6 #include "base/environment.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
11 #include "media/audio/audio_manager_base.h" | 11 #include "media/audio/audio_manager_base.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 static const int kSamplingRate = 8000; | 14 static const int kSamplingRate = 8000; |
15 static const int kSamplesPerPacket = kSamplingRate / 20; | 15 static const int kSamplesPerPacket = kSamplingRate / 20; |
16 | 16 |
17 // This class allows to find out if the callbacks are occurring as | 17 // This class allows to find out if the callbacks are occurring as |
18 // expected and if any error has been reported. | 18 // expected and if any error has been reported. |
19 class TestInputCallback : public AudioInputStream::AudioInputCallback { | 19 class TestInputCallback : public AudioInputStream::AudioInputCallback { |
20 public: | 20 public: |
21 explicit TestInputCallback(int max_data_bytes) | 21 explicit TestInputCallback(int max_data_bytes) |
22 : callback_count_(0), | 22 : callback_count_(0), |
23 had_error_(0), | 23 had_error_(0), |
24 was_closed_(0), | 24 was_closed_(0), |
25 max_data_bytes_(max_data_bytes) { | 25 max_data_bytes_(max_data_bytes) { |
26 } | 26 } |
27 virtual void OnData(AudioInputStream* stream, const uint8* data, | 27 virtual void OnData(AudioInputStream* stream, const uint8* data, |
28 uint32 size, uint32 hardware_delay_bytes) { | 28 uint32 size, uint32 hardware_delay_bytes, double volume) { |
29 ++callback_count_; | 29 ++callback_count_; |
30 // Read the first byte to make sure memory is good. | 30 // Read the first byte to make sure memory is good. |
31 if (size) { | 31 if (size) { |
32 ASSERT_LE(static_cast<int>(size), max_data_bytes_); | 32 ASSERT_LE(static_cast<int>(size), max_data_bytes_); |
33 int value = data[0]; | 33 int value = data[0]; |
34 EXPECT_GE(value, 0); | 34 EXPECT_GE(value, 0); |
35 } | 35 } |
36 } | 36 } |
37 virtual void OnClose(AudioInputStream* stream) { | 37 virtual void OnClose(AudioInputStream* stream) { |
38 ++was_closed_; | 38 ++was_closed_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 FROM_HERE, | 163 FROM_HERE, |
164 MessageLoop::QuitClosure(), | 164 MessageLoop::QuitClosure(), |
165 base::TimeDelta::FromMilliseconds(590)); | 165 base::TimeDelta::FromMilliseconds(590)); |
166 message_loop.Run(); | 166 message_loop.Run(); |
167 EXPECT_GE(test_callback.callback_count(), 10); | 167 EXPECT_GE(test_callback.callback_count(), 10); |
168 EXPECT_FALSE(test_callback.had_error()); | 168 EXPECT_FALSE(test_callback.had_error()); |
169 | 169 |
170 ais->Stop(); | 170 ais->Stop(); |
171 ais->Close(); | 171 ais->Close(); |
172 } | 172 } |
OLD | NEW |