| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "media/base/audio_shifter.h" | 5 #include "media/base/audio_shifter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 scoped_ptr<AudioBus> audio_) : | 80 scoped_ptr<AudioBus> audio_) : |
| 81 target_playout_time(target_playout_time_), | 81 target_playout_time(target_playout_time_), |
| 82 audio(audio_.release()) { | 82 audio(audio_.release()) { |
| 83 } | 83 } |
| 84 | 84 |
| 85 AudioShifter::AudioQueueEntry::~AudioQueueEntry() {} | 85 AudioShifter::AudioQueueEntry::~AudioQueueEntry() {} |
| 86 | 86 |
| 87 AudioShifter::AudioShifter(base::TimeDelta max_buffer_size, | 87 AudioShifter::AudioShifter(base::TimeDelta max_buffer_size, |
| 88 base::TimeDelta clock_accuracy, | 88 base::TimeDelta clock_accuracy, |
| 89 base::TimeDelta adjustment_time, | 89 base::TimeDelta adjustment_time, |
| 90 size_t rate, | 90 int rate, |
| 91 int channels) : | 91 int channels) |
| 92 max_buffer_size_(max_buffer_size), | 92 : max_buffer_size_(max_buffer_size), |
| 93 clock_accuracy_(clock_accuracy), | 93 clock_accuracy_(clock_accuracy), |
| 94 adjustment_time_(adjustment_time), | 94 adjustment_time_(adjustment_time), |
| 95 rate_(rate), | 95 rate_(rate), |
| 96 input_clock_smoother_(new ClockSmoother(clock_accuracy)), | 96 channels_(channels), |
| 97 output_clock_smoother_(new ClockSmoother(clock_accuracy)), | 97 input_clock_smoother_(new ClockSmoother(clock_accuracy)), |
| 98 running_(false), | 98 output_clock_smoother_(new ClockSmoother(clock_accuracy)), |
| 99 position_(0), | 99 running_(false), |
| 100 previous_requested_samples_(0), | 100 position_(0), |
| 101 resampler_(channels, 1.0, 96, | 101 previous_requested_samples_(0), |
| 102 base::Bind(&AudioShifter::ResamplerCallback, | 102 resampler_( |
| 103 base::Unretained(this))), | 103 channels, |
| 104 current_ratio_(1.0) { | 104 1.0, |
| 105 } | 105 96, |
| 106 base::Bind(&AudioShifter::ResamplerCallback, base::Unretained(this))), |
| 107 current_ratio_(1.0) {} |
| 106 | 108 |
| 107 AudioShifter::~AudioShifter() {} | 109 AudioShifter::~AudioShifter() {} |
| 108 | 110 |
| 109 void AudioShifter::Push(scoped_ptr<AudioBus> input, | 111 void AudioShifter::Push(scoped_ptr<AudioBus> input, |
| 110 base::TimeTicks playout_time) { | 112 base::TimeTicks playout_time) { |
| 111 if (!queue_.empty()) { | 113 if (!queue_.empty()) { |
| 112 playout_time = input_clock_smoother_->Smooth( | 114 playout_time = input_clock_smoother_->Smooth( |
| 113 playout_time, | 115 playout_time, |
| 114 base::TimeDelta::FromSeconds(queue_.back().audio->frames()) / rate_); | 116 base::TimeDelta::FromSeconds(queue_.back().audio->frames()) / rate_); |
| 115 } | 117 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (pos < destination->frames()) { | 265 if (pos < destination->frames()) { |
| 264 // Underflow | 266 // Underflow |
| 265 running_ = false; | 267 running_ = false; |
| 266 position_ = 0; | 268 position_ = 0; |
| 267 previous_playout_time_ = base::TimeTicks(); | 269 previous_playout_time_ = base::TimeTicks(); |
| 268 bias_ = base::TimeDelta(); | 270 bias_ = base::TimeDelta(); |
| 269 destination->ZeroFramesPartial(pos, destination->frames() - pos); | 271 destination->ZeroFramesPartial(pos, destination->frames() - pos); |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 | 274 |
| 273 void AudioShifter::Flush() { | |
| 274 resampler_.Flush(); | |
| 275 position_ = 0; | |
| 276 queue_.clear(); | |
| 277 running_ = false; | |
| 278 previous_playout_time_ = base::TimeTicks(); | |
| 279 bias_ = base::TimeDelta(); | |
| 280 } | |
| 281 | |
| 282 void AudioShifter::Zero(AudioBus* output) { | 275 void AudioShifter::Zero(AudioBus* output) { |
| 283 output->Zero(); | 276 output->Zero(); |
| 284 running_ = false; | 277 running_ = false; |
| 285 previous_playout_time_ = base::TimeTicks(); | 278 previous_playout_time_ = base::TimeTicks(); |
| 286 bias_ = base::TimeDelta(); | 279 bias_ = base::TimeDelta(); |
| 287 } | 280 } |
| 288 | 281 |
| 289 } // namespace media | 282 } // namespace media |
| OLD | NEW |