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

Side by Side Diff: media/audio/audio_low_latency_input_output_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
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 "base/basictypes.h"
6 #include "base/environment.h" 5 #include "base/environment.h"
7 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
8 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 8 #include "base/path_service.h"
10 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
11 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "build/build_config.h" 12 #include "build/build_config.h"
14 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_manager_base.h" 14 #include "media/audio/audio_manager_base.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 state.output_delay_ms); 176 state.output_delay_ms);
178 ++elements_written; 177 ++elements_written;
179 } 178 }
180 179
181 base::CloseFile(text_file); 180 base::CloseFile(text_file);
182 } 181 }
183 182
184 // AudioInputStream::AudioInputCallback. 183 // AudioInputStream::AudioInputCallback.
185 void OnData(AudioInputStream* stream, 184 void OnData(AudioInputStream* stream,
186 const AudioBus* src, 185 const AudioBus* src,
187 uint32 hardware_delay_bytes, 186 uint32_t hardware_delay_bytes,
188 double volume) override { 187 double volume) override {
189 base::AutoLock lock(lock_); 188 base::AutoLock lock(lock_);
190 189
191 // Update three components in the AudioDelayState for this recorded 190 // Update three components in the AudioDelayState for this recorded
192 // audio packet. 191 // audio packet.
193 const base::TimeTicks now_time = base::TimeTicks::Now(); 192 const base::TimeTicks now_time = base::TimeTicks::Now();
194 const int diff = (now_time - previous_write_time_).InMilliseconds(); 193 const int diff = (now_time - previous_write_time_).InMilliseconds();
195 previous_write_time_ = now_time; 194 previous_write_time_ = now_time;
196 if (input_elements_to_write_ < kMaxDelayMeasurements) { 195 if (input_elements_to_write_ < kMaxDelayMeasurements) {
197 delay_states_[input_elements_to_write_].delta_time_ms = diff; 196 delay_states_[input_elements_to_write_].delta_time_ms = diff;
(...skipping 25 matching lines...) Expand all
223 222
224 // Update one component in the AudioDelayState for the packet 223 // Update one component in the AudioDelayState for the packet
225 // which is about to be played out. 224 // which is about to be played out.
226 if (output_elements_to_write_ < kMaxDelayMeasurements) { 225 if (output_elements_to_write_ < kMaxDelayMeasurements) {
227 delay_states_[output_elements_to_write_].output_delay_ms = 226 delay_states_[output_elements_to_write_].output_delay_ms =
228 BytesToMilliseconds(total_bytes_delay); 227 BytesToMilliseconds(total_bytes_delay);
229 ++output_elements_to_write_; 228 ++output_elements_to_write_;
230 } 229 }
231 230
232 int size; 231 int size;
233 const uint8* source; 232 const uint8_t* source;
234 // Read the data from the seekable media buffer which contains 233 // Read the data from the seekable media buffer which contains
235 // captured data at the same size and sample rate as the output side. 234 // captured data at the same size and sample rate as the output side.
236 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) { 235 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) {
237 EXPECT_EQ(channels_, audio_bus->channels()); 236 EXPECT_EQ(channels_, audio_bus->channels());
238 size = std::min(audio_bus->frames() * frame_size_, size); 237 size = std::min(audio_bus->frames() * frame_size_, size);
239 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*audio_bus->channel(0)), 0U); 238 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*audio_bus->channel(0)), 0U);
240 audio_bus->FromInterleaved( 239 audio_bus->FromInterleaved(
241 source, size / frame_size_, frame_size_ / channels_); 240 source, size / frame_size_, frame_size_ / channels_);
242 buffer_->Seek(size); 241 buffer_->Seek(size);
243 return size / frame_size_; 242 return size / frame_size_;
244 } 243 }
245 244
246 return 0; 245 return 0;
247 } 246 }
248 247
249 void OnError(AudioOutputStream* stream) override {} 248 void OnError(AudioOutputStream* stream) override {}
250 249
251 protected: 250 protected:
252 // Converts from bytes to milliseconds taking the sample rate and size 251 // Converts from bytes to milliseconds taking the sample rate and size
253 // of an audio frame into account. 252 // of an audio frame into account.
254 int BytesToMilliseconds(uint32 delay_bytes) const { 253 int BytesToMilliseconds(uint32_t delay_bytes) const {
255 return static_cast<int>((delay_bytes / frame_size_) * frames_to_ms_ + 0.5); 254 return static_cast<int>((delay_bytes / frame_size_) * frames_to_ms_ + 0.5);
256 } 255 }
257 256
258 private: 257 private:
259 base::Lock lock_; 258 base::Lock lock_;
260 scoped_ptr<media::SeekableBuffer> buffer_; 259 scoped_ptr<media::SeekableBuffer> buffer_;
261 int sample_rate_; 260 int sample_rate_;
262 int samples_per_packet_; 261 int samples_per_packet_;
263 int channels_; 262 int channels_;
264 int frame_size_; 263 int frame_size_;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 429
431 // All Close() operations that run on the mocked audio thread, 430 // All Close() operations that run on the mocked audio thread,
432 // should be synchronous and not post additional close tasks to 431 // should be synchronous and not post additional close tasks to
433 // mocked the audio thread. Hence, there is no need to call 432 // mocked the audio thread. Hence, there is no need to call
434 // message_loop()->RunUntilIdle() after the Close() methods. 433 // message_loop()->RunUntilIdle() after the Close() methods.
435 aos->Close(); 434 aos->Close();
436 ais->Close(); 435 ais->Close();
437 } 436 }
438 437
439 } // namespace media 438 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_io.h ('k') | media/audio/audio_manager.h » ('j') | media/cdm/stub/stub_cdm.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698