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/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Reads a test file from media/test/data directory. | 74 // Reads a test file from media/test/data directory. |
75 file_ = ReadTestDataFile(name); | 75 file_ = ReadTestDataFile(name); |
76 | 76 |
77 // Creates an array that will store delta times between callbacks. | 77 // Creates an array that will store delta times between callbacks. |
78 // The content of this array will be written to a text file at | 78 // The content of this array will be written to a text file at |
79 // destruction and can then be used for off-line analysis of the exact | 79 // destruction and can then be used for off-line analysis of the exact |
80 // timing of callbacks. The text file will be stored in media/test/data. | 80 // timing of callbacks. The text file will be stored in media/test/data. |
81 delta_times_.reset(new int[kMaxDeltaSamples]); | 81 delta_times_.reset(new int[kMaxDeltaSamples]); |
82 } | 82 } |
83 | 83 |
84 virtual ~ReadFromFileAudioSource() { | 84 ~ReadFromFileAudioSource() override { |
85 // Get complete file path to output file in directory containing | 85 // Get complete file path to output file in directory containing |
86 // media_unittests.exe. | 86 // media_unittests.exe. |
87 base::FilePath file_name; | 87 base::FilePath file_name; |
88 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_name)); | 88 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_name)); |
89 file_name = file_name.AppendASCII(kDeltaTimeMsFileName); | 89 file_name = file_name.AppendASCII(kDeltaTimeMsFileName); |
90 | 90 |
91 EXPECT_TRUE(!text_file_); | 91 EXPECT_TRUE(!text_file_); |
92 text_file_ = base::OpenFile(file_name, "wt"); | 92 text_file_ = base::OpenFile(file_name, "wt"); |
93 DLOG_IF(ERROR, !text_file_) << "Failed to open log file."; | 93 DLOG_IF(ERROR, !text_file_) << "Failed to open log file."; |
94 | 94 |
95 // Write the array which contains delta times to a text file. | 95 // Write the array which contains delta times to a text file. |
96 size_t elements_written = 0; | 96 size_t elements_written = 0; |
97 while (elements_written < elements_to_write_) { | 97 while (elements_written < elements_to_write_) { |
98 fprintf(text_file_, "%d\n", delta_times_[elements_written]); | 98 fprintf(text_file_, "%d\n", delta_times_[elements_written]); |
99 ++elements_written; | 99 ++elements_written; |
100 } | 100 } |
101 | 101 |
102 base::CloseFile(text_file_); | 102 base::CloseFile(text_file_); |
103 } | 103 } |
104 | 104 |
105 // AudioOutputStream::AudioSourceCallback implementation. | 105 // AudioOutputStream::AudioSourceCallback implementation. |
106 virtual int OnMoreData(AudioBus* audio_bus, | 106 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override { |
107 uint32 total_bytes_delay) { | |
108 // Store time difference between two successive callbacks in an array. | 107 // Store time difference between two successive callbacks in an array. |
109 // These values will be written to a file in the destructor. | 108 // These values will be written to a file in the destructor. |
110 const base::TimeTicks now_time = base::TimeTicks::Now(); | 109 const base::TimeTicks now_time = base::TimeTicks::Now(); |
111 const int diff = (now_time - previous_call_time_).InMilliseconds(); | 110 const int diff = (now_time - previous_call_time_).InMilliseconds(); |
112 previous_call_time_ = now_time; | 111 previous_call_time_ = now_time; |
113 if (elements_to_write_ < kMaxDeltaSamples) { | 112 if (elements_to_write_ < kMaxDeltaSamples) { |
114 delta_times_[elements_to_write_] = diff; | 113 delta_times_[elements_to_write_] = diff; |
115 ++elements_to_write_; | 114 ++elements_to_write_; |
116 } | 115 } |
117 | 116 |
118 int max_size = | 117 int max_size = |
119 audio_bus->frames() * audio_bus->channels() * kBitsPerSample / 8; | 118 audio_bus->frames() * audio_bus->channels() * kBitsPerSample / 8; |
120 | 119 |
121 // Use samples read from a data file and fill up the audio buffer | 120 // Use samples read from a data file and fill up the audio buffer |
122 // provided to us in the callback. | 121 // provided to us in the callback. |
123 if (pos_ + static_cast<int>(max_size) > file_size()) | 122 if (pos_ + static_cast<int>(max_size) > file_size()) |
124 max_size = file_size() - pos_; | 123 max_size = file_size() - pos_; |
125 int frames = max_size / (audio_bus->channels() * kBitsPerSample / 8); | 124 int frames = max_size / (audio_bus->channels() * kBitsPerSample / 8); |
126 if (max_size) { | 125 if (max_size) { |
127 audio_bus->FromInterleaved( | 126 audio_bus->FromInterleaved( |
128 file_->data() + pos_, frames, kBitsPerSample / 8); | 127 file_->data() + pos_, frames, kBitsPerSample / 8); |
129 pos_ += max_size; | 128 pos_ += max_size; |
130 } | 129 } |
131 return frames; | 130 return frames; |
132 } | 131 } |
133 | 132 |
134 virtual void OnError(AudioOutputStream* stream) {} | 133 void OnError(AudioOutputStream* stream) override {} |
135 | 134 |
136 int file_size() { return file_->data_size(); } | 135 int file_size() { return file_->data_size(); } |
137 | 136 |
138 private: | 137 private: |
139 scoped_refptr<DecoderBuffer> file_; | 138 scoped_refptr<DecoderBuffer> file_; |
140 scoped_ptr<int[]> delta_times_; | 139 scoped_ptr<int[]> delta_times_; |
141 int pos_; | 140 int pos_; |
142 base::TimeTicks previous_call_time_; | 141 base::TimeTicks previous_call_time_; |
143 FILE* text_file_; | 142 FILE* text_file_; |
144 size_t elements_to_write_; | 143 size_t elements_to_write_; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 613 |
615 aos->Start(&source); | 614 aos->Start(&source); |
616 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 615 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
617 TestTimeouts::action_timeout()); | 616 TestTimeouts::action_timeout()); |
618 loop.Run(); | 617 loop.Run(); |
619 aos->Stop(); | 618 aos->Stop(); |
620 aos->Close(); | 619 aos->Close(); |
621 } | 620 } |
622 | 621 |
623 } // namespace media | 622 } // namespace media |
OLD | NEW |