| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" | 5 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 { | 143 { |
| 144 base::AutoLock lock(queue_lock_); | 144 base::AutoLock lock(queue_lock_); |
| 145 if (state_ == kStateGotEos) { | 145 if (state_ == kStateGotEos) { |
| 146 fade_out_frames_total_ = queued_frames_including_resampler_; | 146 fade_out_frames_total_ = queued_frames_including_resampler_; |
| 147 fade_frames_remaining_ = queued_frames_including_resampler_; | 147 fade_frames_remaining_ = queued_frames_including_resampler_; |
| 148 } else if (state_ == kStateNormalPlayback) { | 148 } else if (state_ == kStateNormalPlayback) { |
| 149 fade_out_frames_total_ = | 149 fade_out_frames_total_ = |
| 150 std::min(queued_frames_including_resampler_, NormalFadeFrames()); | 150 std::min(static_cast<int>(queued_frames_including_resampler_), |
| 151 NormalFadeFrames()); |
| 151 fade_frames_remaining_ = fade_out_frames_total_; | 152 fade_frames_remaining_ = fade_out_frames_total_; |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 state_ = kStateFinalFade; | 156 state_ = kStateFinalFade; |
| 156 if (fade_frames_remaining_ == 0) { | 157 if (fade_frames_remaining_ == 0) { |
| 157 DeleteThis(); | 158 DeleteThis(); |
| 158 } else { | 159 } else { |
| 159 // Tell the mixer that some more data might be available (since when fading | 160 // Tell the mixer that some more data might be available (since when fading |
| 160 // out, we can drain the queue completely). | 161 // out, we can drain the queue completely). |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 queue_lock_.AssertAcquired(); | 193 queue_lock_.AssertAcquired(); |
| 193 if (!data->end_of_stream()) { | 194 if (!data->end_of_stream()) { |
| 194 int frames = | 195 int frames = |
| 195 data->data_size() / (mixer_->num_output_channels() * sizeof(float)); | 196 data->data_size() / (mixer_->num_output_channels() * sizeof(float)); |
| 196 queue_.push_back(data); | 197 queue_.push_back(data); |
| 197 queued_frames_ += frames; | 198 queued_frames_ += frames; |
| 198 queued_frames_including_resampler_ += frames; | 199 queued_frames_including_resampler_ += frames; |
| 199 } | 200 } |
| 200 | 201 |
| 201 MediaPipelineBackendAlsa::RenderingDelay delay = mixer_rendering_delay_; | 202 MediaPipelineBackendAlsa::RenderingDelay delay = mixer_rendering_delay_; |
| 202 delay.delay_microseconds += | 203 delay.delay_microseconds += static_cast<int64_t>( |
| 203 static_cast<int64_t>(queued_frames_including_resampler_) * | 204 queued_frames_including_resampler_ * base::Time::kMicrosecondsPerSecond / |
| 204 base::Time::kMicrosecondsPerSecond / input_samples_per_second_; | 205 input_samples_per_second_); |
| 205 return delay; | 206 return delay; |
| 206 } | 207 } |
| 207 | 208 |
| 208 void StreamMixerAlsaInputImpl::PostPcmCallback( | 209 void StreamMixerAlsaInputImpl::PostPcmCallback( |
| 209 const MediaPipelineBackendAlsa::RenderingDelay& delay) { | 210 const MediaPipelineBackendAlsa::RenderingDelay& delay) { |
| 210 RUN_ON_CALLER_THREAD(PostPcmCallback, delay); | 211 RUN_ON_CALLER_THREAD(PostPcmCallback, delay); |
| 211 delegate_->OnWritePcmCompletion(MediaPipelineBackendAlsa::kBufferSuccess, | 212 delegate_->OnWritePcmCompletion(MediaPipelineBackendAlsa::kBufferSuccess, |
| 212 delay); | 213 delay); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void StreamMixerAlsaInputImpl::DidQueueData(bool end_of_stream) { | 216 void StreamMixerAlsaInputImpl::DidQueueData(bool end_of_stream) { |
| 216 RUN_ON_MIXER_THREAD(DidQueueData, end_of_stream); | 217 RUN_ON_MIXER_THREAD(DidQueueData, end_of_stream); |
| 217 DCHECK(!IsDeleting()); | 218 DCHECK(!IsDeleting()); |
| 218 if (end_of_stream) { | 219 if (end_of_stream) { |
| 219 state_ = kStateGotEos; | 220 state_ = kStateGotEos; |
| 220 } else if (state_ == kStateUninitialized) { | 221 } else if (state_ == kStateUninitialized) { |
| 221 state_ = kStateNormalPlayback; | 222 state_ = kStateNormalPlayback; |
| 222 } | 223 } |
| 223 mixer_->OnFramesQueued(); | 224 mixer_->OnFramesQueued(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void StreamMixerAlsaInputImpl::AfterWriteFrames( | 227 void StreamMixerAlsaInputImpl::AfterWriteFrames( |
| 227 const MediaPipelineBackendAlsa::RenderingDelay& mixer_rendering_delay) { | 228 const MediaPipelineBackendAlsa::RenderingDelay& mixer_rendering_delay) { |
| 228 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); | 229 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); |
| 229 int resampler_queued_frames = (resampler_ ? resampler_->BufferedFrames() : 0); | 230 double resampler_queued_frames = |
| 231 (resampler_ ? resampler_->BufferedFrames() : 0); |
| 230 | 232 |
| 231 bool queued_more_data = false; | 233 bool queued_more_data = false; |
| 232 MediaPipelineBackendAlsa::RenderingDelay total_delay; | 234 MediaPipelineBackendAlsa::RenderingDelay total_delay; |
| 233 { | 235 { |
| 234 base::AutoLock lock(queue_lock_); | 236 base::AutoLock lock(queue_lock_); |
| 235 mixer_rendering_delay_ = mixer_rendering_delay; | 237 mixer_rendering_delay_ = mixer_rendering_delay; |
| 236 queued_frames_ = 0; | 238 queued_frames_ = 0; |
| 237 for (const auto& data : queue_) | 239 for (const auto& data : queue_) |
| 238 queued_frames_ += | 240 queued_frames_ += |
| 239 data->data_size() / (mixer_->num_output_channels() * sizeof(float)); | 241 data->data_size() / (mixer_->num_output_channels() * sizeof(float)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 260 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); | 262 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); |
| 261 if (state_ == kStatePaused || state_ == kStateDeleted) | 263 if (state_ == kStatePaused || state_ == kStateDeleted) |
| 262 return kPausedReadSamples; | 264 return kPausedReadSamples; |
| 263 if (state_ == kStateFinalFade) | 265 if (state_ == kStateFinalFade) |
| 264 return fade_frames_remaining_; | 266 return fade_frames_remaining_; |
| 265 | 267 |
| 266 int queued_frames; | 268 int queued_frames; |
| 267 { | 269 { |
| 268 base::AutoLock lock(queue_lock_); | 270 base::AutoLock lock(queue_lock_); |
| 269 if (state_ == kStateGotEos) | 271 if (state_ == kStateGotEos) |
| 270 return std::max(queued_frames_including_resampler_, kDefaultReadSize); | 272 return std::max(static_cast<int>(queued_frames_including_resampler_), |
| 273 kDefaultReadSize); |
| 271 queued_frames = queued_frames_; | 274 queued_frames = queued_frames_; |
| 272 } | 275 } |
| 273 | 276 |
| 274 int available_frames = 0; | 277 int available_frames = 0; |
| 275 if (resampler_) { | 278 if (resampler_) { |
| 276 int num_chunks = queued_frames / kDefaultReadSize; | 279 int num_chunks = queued_frames / kDefaultReadSize; |
| 277 available_frames = resampler_->ChunkSize() * num_chunks; | 280 available_frames = resampler_->ChunkSize() * num_chunks; |
| 278 } else { | 281 } else { |
| 279 available_frames = queued_frames; | 282 available_frames = queued_frames; |
| 280 } | 283 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 DCHECK(!IsDeleting()); | 482 DCHECK(!IsDeleting()); |
| 480 if (multiplier > 1.0f) | 483 if (multiplier > 1.0f) |
| 481 multiplier = 1.0f; | 484 multiplier = 1.0f; |
| 482 if (multiplier < 0.0f) | 485 if (multiplier < 0.0f) |
| 483 multiplier = 0.0f; | 486 multiplier = 0.0f; |
| 484 volume_multiplier_ = multiplier; | 487 volume_multiplier_ = multiplier; |
| 485 } | 488 } |
| 486 | 489 |
| 487 } // namespace media | 490 } // namespace media |
| 488 } // namespace chromecast | 491 } // namespace chromecast |
| OLD | NEW |