| 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); | 56 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // AudioOutputStream::AudioSourceCallback implementation which enables audio | 59 // AudioOutputStream::AudioSourceCallback implementation which enables audio |
| 60 // play-through. It also creates a text file that contains times between two | 60 // play-through. It also creates a text file that contains times between two |
| 61 // successive callbacks. Units are in milliseconds. This file can be used for | 61 // successive callbacks. Units are in milliseconds. This file can be used for |
| 62 // off-line analysis of the callback sequence. | 62 // off-line analysis of the callback sequence. |
| 63 class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback { | 63 class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback { |
| 64 public: | 64 public: |
| 65 explicit UnifiedSourceCallback() | 65 explicit UnifiedSourceCallback() |
| 66 : previous_call_time_(base::Time::Now()), | 66 : previous_call_time_(base::TimeTicks::Now()), |
| 67 text_file_(NULL), | 67 text_file_(NULL), |
| 68 elements_to_write_(0) { | 68 elements_to_write_(0) { |
| 69 delta_times_.reset(new int[kMaxDeltaSamples]); | 69 delta_times_.reset(new int[kMaxDeltaSamples]); |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual ~UnifiedSourceCallback() { | 72 virtual ~UnifiedSourceCallback() { |
| 73 base::FilePath file_name; | 73 base::FilePath file_name; |
| 74 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_name)); | 74 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_name)); |
| 75 file_name = file_name.AppendASCII(kDeltaTimeMsFileName); | 75 file_name = file_name.AppendASCII(kDeltaTimeMsFileName); |
| 76 | 76 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 virtual int OnMoreData(AudioBus* dest, | 91 virtual int OnMoreData(AudioBus* dest, |
| 92 AudioBuffersState buffers_state) { | 92 AudioBuffersState buffers_state) { |
| 93 NOTREACHED(); | 93 NOTREACHED(); |
| 94 return 0; | 94 return 0; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 virtual int OnMoreIOData(AudioBus* source, | 97 virtual int OnMoreIOData(AudioBus* source, |
| 98 AudioBus* dest, | 98 AudioBus* dest, |
| 99 AudioBuffersState buffers_state) { | 99 AudioBuffersState buffers_state) { |
| 100 // Store time between this callback and the previous callback. | 100 // Store time between this callback and the previous callback. |
| 101 int diff = (base::Time::Now() - previous_call_time_).InMilliseconds(); | 101 const base::TimeTicks now_time = base::TimeTicks::Now(); |
| 102 previous_call_time_ = base::Time::Now(); | 102 const int diff = (now_time - previous_call_time_).InMilliseconds(); |
| 103 previous_call_time_ = now_time; |
| 103 if (elements_to_write_ < kMaxDeltaSamples) { | 104 if (elements_to_write_ < kMaxDeltaSamples) { |
| 104 delta_times_[elements_to_write_] = diff; | 105 delta_times_[elements_to_write_] = diff; |
| 105 ++elements_to_write_; | 106 ++elements_to_write_; |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Play out the recorded audio samples in loop back. Perform channel mixing | 109 // Play out the recorded audio samples in loop back. Perform channel mixing |
| 109 // if required using a channel mixer which is created only if needed. | 110 // if required using a channel mixer which is created only if needed. |
| 110 if (source->channels() == dest->channels()) | 111 if (source->channels() == dest->channels()) |
| 111 source->CopyTo(dest); | 112 source->CopyTo(dest); |
| 112 else { | 113 else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 channel_mixer_->Transform(source, dest); | 128 channel_mixer_->Transform(source, dest); |
| 128 } | 129 } |
| 129 return source->frames(); | 130 return source->frames(); |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 virtual void OnError(AudioOutputStream* stream) { | 133 virtual void OnError(AudioOutputStream* stream) { |
| 133 NOTREACHED(); | 134 NOTREACHED(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 private: | 137 private: |
| 137 base::Time previous_call_time_; | 138 base::TimeTicks previous_call_time_; |
| 138 scoped_ptr<int[]> delta_times_; | 139 scoped_ptr<int[]> delta_times_; |
| 139 FILE* text_file_; | 140 FILE* text_file_; |
| 140 size_t elements_to_write_; | 141 size_t elements_to_write_; |
| 141 scoped_ptr<ChannelMixer> channel_mixer_; | 142 scoped_ptr<ChannelMixer> channel_mixer_; |
| 142 }; | 143 }; |
| 143 | 144 |
| 144 // Convenience method which ensures that we fulfill all required conditions | 145 // Convenience method which ensures that we fulfill all required conditions |
| 145 // to run unified audio tests on Windows. | 146 // to run unified audio tests on Windows. |
| 146 static bool CanRunUnifiedAudioTests(AudioManager* audio_man) { | 147 static bool CanRunUnifiedAudioTests(AudioManager* audio_man) { |
| 147 if (!CoreAudioUtil::IsSupported()) { | 148 if (!CoreAudioUtil::IsSupported()) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 313 |
| 313 EXPECT_TRUE(wus->Open()); | 314 EXPECT_TRUE(wus->Open()); |
| 314 wus->Start(&source); | 315 wus->Start(&source); |
| 315 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 316 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 316 base::TimeDelta::FromMilliseconds(10000)); | 317 base::TimeDelta::FromMilliseconds(10000)); |
| 317 loop.Run(); | 318 loop.Run(); |
| 318 wus->Close(); | 319 wus->Close(); |
| 319 } | 320 } |
| 320 | 321 |
| 321 } // namespace media | 322 } // namespace media |
| OLD | NEW |