| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 AudioBuffersState buffers_state)); | 70 AudioBuffersState buffers_state)); |
| 71 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); | 71 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // This audio source implementation should be used for manual tests only since | 74 // This audio source implementation should be used for manual tests only since |
| 75 // it takes about 20 seconds to play out a file. | 75 // it takes about 20 seconds to play out a file. |
| 76 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { | 76 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 77 public: | 77 public: |
| 78 explicit ReadFromFileAudioSource(const std::string& name) | 78 explicit ReadFromFileAudioSource(const std::string& name) |
| 79 : pos_(0), | 79 : pos_(0), |
| 80 previous_call_time_(base::Time::Now()), | 80 previous_call_time_(base::TimeTicks::Now()), |
| 81 text_file_(NULL), | 81 text_file_(NULL), |
| 82 elements_to_write_(0) { | 82 elements_to_write_(0) { |
| 83 // Reads a test file from media/test/data directory. | 83 // Reads a test file from media/test/data directory. |
| 84 file_ = ReadTestDataFile(name); | 84 file_ = ReadTestDataFile(name); |
| 85 | 85 |
| 86 // Creates an array that will store delta times between callbacks. | 86 // Creates an array that will store delta times between callbacks. |
| 87 // The content of this array will be written to a text file at | 87 // The content of this array will be written to a text file at |
| 88 // destruction and can then be used for off-line analysis of the exact | 88 // destruction and can then be used for off-line analysis of the exact |
| 89 // timing of callbacks. The text file will be stored in media/test/data. | 89 // timing of callbacks. The text file will be stored in media/test/data. |
| 90 delta_times_.reset(new int[kMaxDeltaSamples]); | 90 delta_times_.reset(new int[kMaxDeltaSamples]); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 file_util::CloseFile(text_file_); | 111 file_util::CloseFile(text_file_); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // AudioOutputStream::AudioSourceCallback implementation. | 114 // AudioOutputStream::AudioSourceCallback implementation. |
| 115 virtual int OnMoreData(AudioBus* audio_bus, | 115 virtual int OnMoreData(AudioBus* audio_bus, |
| 116 AudioBuffersState buffers_state) { | 116 AudioBuffersState buffers_state) { |
| 117 // Store time difference between two successive callbacks in an array. | 117 // Store time difference between two successive callbacks in an array. |
| 118 // These values will be written to a file in the destructor. | 118 // These values will be written to a file in the destructor. |
| 119 int diff = (base::Time::Now() - previous_call_time_).InMilliseconds(); | 119 const base::TimeTicks now_time = base::TimeTicks::Now(); |
| 120 previous_call_time_ = base::Time::Now(); | 120 const int diff = (now_time - previous_call_time_).InMilliseconds(); |
| 121 previous_call_time_ = now_time; |
| 121 if (elements_to_write_ < kMaxDeltaSamples) { | 122 if (elements_to_write_ < kMaxDeltaSamples) { |
| 122 delta_times_[elements_to_write_] = diff; | 123 delta_times_[elements_to_write_] = diff; |
| 123 ++elements_to_write_; | 124 ++elements_to_write_; |
| 124 } | 125 } |
| 125 | 126 |
| 126 int max_size = | 127 int max_size = |
| 127 audio_bus->frames() * audio_bus->channels() * kBitsPerSample / 8; | 128 audio_bus->frames() * audio_bus->channels() * kBitsPerSample / 8; |
| 128 | 129 |
| 129 // Use samples read from a data file and fill up the audio buffer | 130 // Use samples read from a data file and fill up the audio buffer |
| 130 // provided to us in the callback. | 131 // provided to us in the callback. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 147 } | 148 } |
| 148 | 149 |
| 149 virtual void OnError(AudioOutputStream* stream) {} | 150 virtual void OnError(AudioOutputStream* stream) {} |
| 150 | 151 |
| 151 int file_size() { return file_->GetDataSize(); } | 152 int file_size() { return file_->GetDataSize(); } |
| 152 | 153 |
| 153 private: | 154 private: |
| 154 scoped_refptr<DecoderBuffer> file_; | 155 scoped_refptr<DecoderBuffer> file_; |
| 155 scoped_ptr<int[]> delta_times_; | 156 scoped_ptr<int[]> delta_times_; |
| 156 int pos_; | 157 int pos_; |
| 157 base::Time previous_call_time_; | 158 base::TimeTicks previous_call_time_; |
| 158 FILE* text_file_; | 159 FILE* text_file_; |
| 159 size_t elements_to_write_; | 160 size_t elements_to_write_; |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 static bool ExclusiveModeIsEnabled() { | 163 static bool ExclusiveModeIsEnabled() { |
| 163 return (WASAPIAudioOutputStream::GetShareMode() == | 164 return (WASAPIAudioOutputStream::GetShareMode() == |
| 164 AUDCLNT_SHAREMODE_EXCLUSIVE); | 165 AUDCLNT_SHAREMODE_EXCLUSIVE); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // Convenience method which ensures that we are not running on the build | 168 // Convenience method which ensures that we are not running on the build |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 694 |
| 694 aos->Start(&source); | 695 aos->Start(&source); |
| 695 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 696 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 696 TestTimeouts::action_timeout()); | 697 TestTimeouts::action_timeout()); |
| 697 loop.Run(); | 698 loop.Run(); |
| 698 aos->Stop(); | 699 aos->Stop(); |
| 699 aos->Close(); | 700 aos->Close(); |
| 700 } | 701 } |
| 701 | 702 |
| 702 } // namespace media | 703 } // namespace media |
| OLD | NEW |