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

Side by Side Diff: media/audio/win/audio_low_latency_output_win_unittest.cc

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/2011/2012/ Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/buffers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/win/scoped_com_initializer.h" 16 #include "base/win/scoped_com_initializer.h"
17 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager.h" 18 #include "media/audio/audio_manager.h"
19 #include "media/audio/audio_util.h" 19 #include "media/audio/audio_util.h"
20 #include "media/audio/win/audio_low_latency_output_win.h" 20 #include "media/audio/win/audio_low_latency_output_win.h"
21 #include "media/base/decoder_buffer.h"
21 #include "media/base/seekable_buffer.h" 22 #include "media/base/seekable_buffer.h"
22 #include "media/base/test_data_util.h" 23 #include "media/base/test_data_util.h"
23 #include "testing/gmock_mutant.h" 24 #include "testing/gmock_mutant.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using ::testing::_; 28 using ::testing::_;
28 using ::testing::AnyNumber; 29 using ::testing::AnyNumber;
29 using ::testing::Between; 30 using ::testing::Between;
30 using ::testing::CreateFunctor; 31 using ::testing::CreateFunctor;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // it takes about 20 seconds to play out a file. 64 // it takes about 20 seconds to play out a file.
64 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { 65 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
65 public: 66 public:
66 explicit ReadFromFileAudioSource(const std::string& name) 67 explicit ReadFromFileAudioSource(const std::string& name)
67 : pos_(0), 68 : pos_(0),
68 previous_call_time_(base::Time::Now()), 69 previous_call_time_(base::Time::Now()),
69 text_file_(NULL), 70 text_file_(NULL),
70 elements_to_write_(0) { 71 elements_to_write_(0) {
71 // Reads a test file from media/test/data directory and stores it in 72 // Reads a test file from media/test/data directory and stores it in
72 // a scoped_array. 73 // a scoped_array.
73 ReadTestDataFile(name, &file_, &file_size_); 74 file_ = ReadTestDataFile(name);
74 75
75 // Creates an array that will store delta times between callbacks. 76 // Creates an array that will store delta times between callbacks.
76 // The content of this array will be written to a text file at 77 // The content of this array will be written to a text file at
77 // destruction and can then be used for off-line analysis of the exact 78 // destruction and can then be used for off-line analysis of the exact
78 // timing of callbacks. The text file will be stored in media/test/data. 79 // timing of callbacks. The text file will be stored in media/test/data.
79 delta_times_.reset(new int[kMaxDeltaSamples]); 80 delta_times_.reset(new int[kMaxDeltaSamples]);
80 } 81 }
81 82
82 virtual ~ReadFromFileAudioSource() { 83 virtual ~ReadFromFileAudioSource() {
83 // Get complete file path to output file in directory containing 84 // Get complete file path to output file in directory containing
(...skipping 24 matching lines...) Expand all
108 // These values will be written to a file in the destructor. 109 // These values will be written to a file in the destructor.
109 int diff = (base::Time::Now() - previous_call_time_).InMilliseconds(); 110 int diff = (base::Time::Now() - previous_call_time_).InMilliseconds();
110 previous_call_time_ = base::Time::Now(); 111 previous_call_time_ = base::Time::Now();
111 if (elements_to_write_ < kMaxDeltaSamples) { 112 if (elements_to_write_ < kMaxDeltaSamples) {
112 delta_times_[elements_to_write_] = diff; 113 delta_times_[elements_to_write_] = diff;
113 ++elements_to_write_; 114 ++elements_to_write_;
114 } 115 }
115 116
116 // Use samples read from a data file and fill up the audio buffer 117 // Use samples read from a data file and fill up the audio buffer
117 // provided to us in the callback. 118 // provided to us in the callback.
118 if (pos_ + static_cast<int>(max_size) > file_size_) 119 if (pos_ + static_cast<int>(max_size) > file_size())
119 max_size = file_size_ - pos_; 120 max_size = file_size() - pos_;
120 if (max_size) { 121 if (max_size) {
121 memcpy(dest, &file_[pos_], max_size); 122 memcpy(dest, &file_[pos_], max_size);
122 pos_ += max_size; 123 pos_ += max_size;
123 } 124 }
124 return max_size; 125 return max_size;
125 } 126 }
126 127
127 virtual void OnError(AudioOutputStream* stream, int code) {} 128 virtual void OnError(AudioOutputStream* stream, int code) {}
128 129
129 int file_size() { return file_size_; } 130 int file_size() { return file_->GetDataSize(); }
130 131
131 private: 132 private:
132 scoped_array<uint8> file_; 133 scoped_refptr<DecoderBuffer> file_;
133 scoped_array<int> delta_times_; 134 scoped_array<int> delta_times_;
134 int file_size_;
135 int pos_; 135 int pos_;
136 base::Time previous_call_time_; 136 base::Time previous_call_time_;
137 FILE* text_file_; 137 FILE* text_file_;
138 size_t elements_to_write_; 138 size_t elements_to_write_;
139 }; 139 };
140 140
141 // Convenience method which ensures that we are not running on the build 141 // Convenience method which ensures that we are not running on the build
142 // bots and that at least one valid output device can be found. We also 142 // bots and that at least one valid output device can be found. We also
143 // verify that we are not running on XP since the low-latency (WASAPI- 143 // verify that we are not running on XP since the low-latency (WASAPI-
144 // based) version requires Windows Vista or higher. 144 // based) version requires Windows Vista or higher.
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 aos->Start(&file_source); 539 aos->Start(&file_source);
540 base::PlatformThread::Sleep( 540 base::PlatformThread::Sleep(
541 base::TimeDelta::FromMilliseconds(kFileDurationMs)); 541 base::TimeDelta::FromMilliseconds(kFileDurationMs));
542 aos->Stop(); 542 aos->Stop();
543 543
544 LOG(INFO) << ">> File playout has stopped."; 544 LOG(INFO) << ">> File playout has stopped.";
545 aos->Close(); 545 aos->Close();
546 } 546 }
547 547
548 } // namespace media 548 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/buffers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698