| 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 #include <limits> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 17 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
| 17 #include "chromecast/media/cma/base/decoder_buffer_base.h" | 18 #include "chromecast/media/cma/base/decoder_buffer_base.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 const int kNumOutputChannels = 2; | 49 const int kNumOutputChannels = 2; |
| 49 const int64_t kMaxInputQueueUs = 90000; | 50 const int64_t kMaxInputQueueUs = 90000; |
| 50 const int64_t kFadeMs = 15; | 51 const int64_t kFadeMs = 15; |
| 51 // Number of samples to report as readable when paused. When paused, the mixer | 52 // Number of samples to report as readable when paused. When paused, the mixer |
| 52 // will still pull this many frames each time it tries to write frames, but we | 53 // will still pull this many frames each time it tries to write frames, but we |
| 53 // fill the frames with silence. | 54 // fill the frames with silence. |
| 54 const int kPausedReadSamples = 512; | 55 const int kPausedReadSamples = 512; |
| 55 const int kDefaultReadSize = ::media::SincResampler::kDefaultRequestSize; | 56 const int kDefaultReadSize = ::media::SincResampler::kDefaultRequestSize; |
| 57 const int64_t kNoTimestamp = std::numeric_limits<int64_t>::min(); |
| 56 | 58 |
| 57 } // namespace | 59 } // namespace |
| 58 | 60 |
| 59 StreamMixerAlsaInputImpl::StreamMixerAlsaInputImpl( | 61 StreamMixerAlsaInputImpl::StreamMixerAlsaInputImpl( |
| 60 StreamMixerAlsaInput::Delegate* delegate, | 62 StreamMixerAlsaInput::Delegate* delegate, |
| 61 int input_samples_per_second, | 63 int input_samples_per_second, |
| 62 bool primary, | 64 bool primary, |
| 63 StreamMixerAlsa* mixer) | 65 StreamMixerAlsa* mixer) |
| 64 : delegate_(delegate), | 66 : delegate_(delegate), |
| 65 input_samples_per_second_(input_samples_per_second), | 67 input_samples_per_second_(input_samples_per_second), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const scoped_refptr<DecoderBufferBase>& data) { | 195 const scoped_refptr<DecoderBufferBase>& data) { |
| 194 queue_lock_.AssertAcquired(); | 196 queue_lock_.AssertAcquired(); |
| 195 if (!data->end_of_stream()) { | 197 if (!data->end_of_stream()) { |
| 196 int frames = data->data_size() / (kNumOutputChannels * sizeof(float)); | 198 int frames = data->data_size() / (kNumOutputChannels * sizeof(float)); |
| 197 queue_.push_back(data); | 199 queue_.push_back(data); |
| 198 queued_frames_ += frames; | 200 queued_frames_ += frames; |
| 199 queued_frames_including_resampler_ += frames; | 201 queued_frames_including_resampler_ += frames; |
| 200 } | 202 } |
| 201 | 203 |
| 202 MediaPipelineBackendAlsa::RenderingDelay delay = mixer_rendering_delay_; | 204 MediaPipelineBackendAlsa::RenderingDelay delay = mixer_rendering_delay_; |
| 203 delay.delay_microseconds += static_cast<int64_t>( | 205 if (delay.timestamp_microseconds != kNoTimestamp) { |
| 204 queued_frames_including_resampler_ * base::Time::kMicrosecondsPerSecond / | 206 delay.delay_microseconds += static_cast<int64_t>( |
| 205 input_samples_per_second_); | 207 queued_frames_including_resampler_ * |
| 208 base::Time::kMicrosecondsPerSecond / input_samples_per_second_); |
| 209 } |
| 206 return delay; | 210 return delay; |
| 207 } | 211 } |
| 208 | 212 |
| 209 void StreamMixerAlsaInputImpl::PostPcmCallback( | 213 void StreamMixerAlsaInputImpl::PostPcmCallback( |
| 210 const MediaPipelineBackendAlsa::RenderingDelay& delay) { | 214 const MediaPipelineBackendAlsa::RenderingDelay& delay) { |
| 211 RUN_ON_CALLER_THREAD(PostPcmCallback, delay); | 215 RUN_ON_CALLER_THREAD(PostPcmCallback, delay); |
| 212 delegate_->OnWritePcmCompletion(MediaPipelineBackendAlsa::kBufferSuccess, | 216 delegate_->OnWritePcmCompletion(MediaPipelineBackendAlsa::kBufferSuccess, |
| 213 delay); | 217 delay); |
| 214 } | 218 } |
| 215 | 219 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 DCHECK(!IsDeleting()); | 488 DCHECK(!IsDeleting()); |
| 485 if (multiplier > 1.0f) | 489 if (multiplier > 1.0f) |
| 486 multiplier = 1.0f; | 490 multiplier = 1.0f; |
| 487 if (multiplier < 0.0f) | 491 if (multiplier < 0.0f) |
| 488 multiplier = 0.0f; | 492 multiplier = 0.0f; |
| 489 volume_multiplier_ = multiplier; | 493 volume_multiplier_ = multiplier; |
| 490 } | 494 } |
| 491 | 495 |
| 492 } // namespace media | 496 } // namespace media |
| 493 } // namespace chromecast | 497 } // namespace chromecast |
| OLD | NEW |