| 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" |
| 6 |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> |
| 7 | 10 |
| 8 #include "base/bind.h" | 11 #include "base/bind.h" |
| 9 #include "media/base/audio_bus.h" | 12 #include "media/base/audio_bus.h" |
| 10 #include "media/base/audio_shifter.h" | |
| 11 | 13 |
| 12 namespace media { | 14 namespace media { |
| 13 | 15 |
| 14 // return true if x is between a and b. | 16 // return true if x is between a and b. |
| 15 static bool between(double x, double a, double b) { | 17 static bool between(double x, double a, double b) { |
| 16 if (b < a) | 18 if (b < a) |
| 17 return b <= x && x <= a; | 19 return b <= x && x <= a; |
| 18 return a <= x && x <= b; | 20 return a <= x && x <= b; |
| 19 } | 21 } |
| 20 | 22 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 106 |
| 105 AudioShifter::~AudioShifter() {} | 107 AudioShifter::~AudioShifter() {} |
| 106 | 108 |
| 107 void AudioShifter::Push(scoped_ptr<AudioBus> input, | 109 void AudioShifter::Push(scoped_ptr<AudioBus> input, |
| 108 base::TimeTicks playout_time) { | 110 base::TimeTicks playout_time) { |
| 109 if (!queue_.empty()) { | 111 if (!queue_.empty()) { |
| 110 playout_time = input_clock_smoother_->Smooth( | 112 playout_time = input_clock_smoother_->Smooth( |
| 111 playout_time, | 113 playout_time, |
| 112 base::TimeDelta::FromSeconds(queue_.back().audio->frames()) / rate_); | 114 base::TimeDelta::FromSeconds(queue_.back().audio->frames()) / rate_); |
| 113 } | 115 } |
| 114 queue_.push_back(AudioQueueEntry(playout_time, input.Pass())); | 116 queue_.push_back(AudioQueueEntry(playout_time, std::move(input))); |
| 115 while (!queue_.empty() && | 117 while (!queue_.empty() && |
| 116 queue_.back().target_playout_time - | 118 queue_.back().target_playout_time - |
| 117 queue_.front().target_playout_time > max_buffer_size_) { | 119 queue_.front().target_playout_time > max_buffer_size_) { |
| 118 DVLOG(1) << "AudioShifter: Audio overflow!"; | 120 DVLOG(1) << "AudioShifter: Audio overflow!"; |
| 119 queue_.pop_front(); | 121 queue_.pop_front(); |
| 120 position_ = 0; | 122 position_ = 0; |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 void AudioShifter::Pull(AudioBus* output, | 126 void AudioShifter::Pull(AudioBus* output, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 280 } |
| 279 | 281 |
| 280 void AudioShifter::Zero(AudioBus* output) { | 282 void AudioShifter::Zero(AudioBus* output) { |
| 281 output->Zero(); | 283 output->Zero(); |
| 282 running_ = false; | 284 running_ = false; |
| 283 previous_playout_time_ = base::TimeTicks(); | 285 previous_playout_time_ = base::TimeTicks(); |
| 284 bias_ = base::TimeDelta(); | 286 bias_ = base::TimeDelta(); |
| 285 } | 287 } |
| 286 | 288 |
| 287 } // namespace media | 289 } // namespace media |
| OLD | NEW |