| Index: chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.cc
|
| diff --git a/chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.cc b/chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.cc
|
| index 0a8f0a462da7a4550cd0060682e3d5ac05139214..1e7cc895cc43fcefb9ff7106d9cf1178d2614106 100644
|
| --- a/chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.cc
|
| +++ b/chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.cc
|
| @@ -69,6 +69,7 @@ StreamMixerAlsaInputImpl::StreamMixerAlsaInputImpl(
|
| mixer_(mixer),
|
| mixer_task_runner_(mixer_->task_runner()),
|
| caller_task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| + resample_ratio_(1.0),
|
| state_(kStateUninitialized),
|
| volume_multiplier_(1.0f),
|
| queued_frames_(0),
|
| @@ -80,12 +81,14 @@ StreamMixerAlsaInputImpl::StreamMixerAlsaInputImpl(
|
| fade_out_frames_total_(0),
|
| zeroed_frames_(0),
|
| weak_factory_(this) {
|
| + LOG(INFO) << "Create " << this;
|
| DCHECK(delegate_);
|
| DCHECK(mixer_);
|
| weak_this_ = weak_factory_.GetWeakPtr();
|
| }
|
|
|
| StreamMixerAlsaInputImpl::~StreamMixerAlsaInputImpl() {
|
| + LOG(INFO) << "Destroy " << this;
|
| DCHECK(mixer_task_runner_->BelongsToCurrentThread());
|
| }
|
|
|
| @@ -111,10 +114,10 @@ void StreamMixerAlsaInputImpl::Initialize(
|
| DCHECK(mixer_task_runner_->BelongsToCurrentThread());
|
| DCHECK(!IsDeleting());
|
| if (mixer_->output_samples_per_second() != input_samples_per_second_) {
|
| - double resample_ratio = static_cast<double>(input_samples_per_second_) /
|
| - mixer_->output_samples_per_second();
|
| + resample_ratio_ = static_cast<double>(input_samples_per_second_) /
|
| + mixer_->output_samples_per_second();
|
| resampler_.reset(new ::media::MultiChannelResampler(
|
| - kNumOutputChannels, resample_ratio, kDefaultReadSize,
|
| + kNumOutputChannels, resample_ratio_, kDefaultReadSize,
|
| base::Bind(&StreamMixerAlsaInputImpl::ReadCB, base::Unretained(this))));
|
| resampler_->PrimeWithSilence();
|
| }
|
| @@ -146,11 +149,14 @@ void StreamMixerAlsaInputImpl::PrepareToDelete(
|
| {
|
| base::AutoLock lock(queue_lock_);
|
| if (state_ == kStateGotEos) {
|
| - fade_out_frames_total_ = queued_frames_including_resampler_;
|
| - fade_frames_remaining_ = queued_frames_including_resampler_;
|
| + fade_out_frames_total_ =
|
| + queued_frames_including_resampler_ / resample_ratio_;
|
| + fade_frames_remaining_ =
|
| + queued_frames_including_resampler_ / resample_ratio_;
|
| } else if (state_ == kStateNormalPlayback) {
|
| fade_out_frames_total_ =
|
| - std::min(static_cast<int>(queued_frames_including_resampler_),
|
| + std::min(static_cast<int>(queued_frames_including_resampler_ /
|
| + resample_ratio_),
|
| NormalFadeFrames());
|
| fade_frames_remaining_ = fade_out_frames_total_;
|
| }
|
| @@ -221,6 +227,7 @@ void StreamMixerAlsaInputImpl::DidQueueData(bool end_of_stream) {
|
| RUN_ON_MIXER_THREAD(DidQueueData, end_of_stream);
|
| DCHECK(!IsDeleting());
|
| if (end_of_stream) {
|
| + LOG(INFO) << "End of stream for " << this;
|
| state_ = kStateGotEos;
|
| } else if (state_ == kStateUninitialized) {
|
| state_ = kStateNormalPlayback;
|
| @@ -240,9 +247,10 @@ void StreamMixerAlsaInputImpl::AfterWriteFrames(
|
| base::AutoLock lock(queue_lock_);
|
| mixer_rendering_delay_ = mixer_rendering_delay;
|
| queued_frames_ = 0;
|
| - for (const auto& data : queue_)
|
| + for (const auto& data : queue_) {
|
| queued_frames_ +=
|
| data->data_size() / (kNumOutputChannels * sizeof(float));
|
| + }
|
| queued_frames_ -= current_buffer_offset_;
|
| DCHECK_GE(queued_frames_, 0);
|
| queued_frames_including_resampler_ =
|
| @@ -253,8 +261,10 @@ void StreamMixerAlsaInputImpl::AfterWriteFrames(
|
| pending_data_ = nullptr;
|
| total_delay = QueueData(data);
|
| queued_more_data = true;
|
| - if (data->end_of_stream())
|
| + if (data->end_of_stream()) {
|
| + LOG(INFO) << "End of stream for " << this;
|
| state_ = kStateGotEos;
|
| + }
|
| }
|
| }
|
|
|
| @@ -273,7 +283,8 @@ int StreamMixerAlsaInputImpl::MaxReadSize() {
|
| {
|
| base::AutoLock lock(queue_lock_);
|
| if (state_ == kStateGotEos)
|
| - return std::max(static_cast<int>(queued_frames_including_resampler_),
|
| + return std::max(static_cast<int>(queued_frames_including_resampler_ /
|
| + resample_ratio_),
|
| kDefaultReadSize);
|
| queued_frames = queued_frames_;
|
| }
|
| @@ -368,12 +379,13 @@ void StreamMixerAlsaInputImpl::FillFrames(int frame_delay,
|
| }
|
| frames_left -= frames_to_copy;
|
| frames_filled += frames_to_copy;
|
| - LOG_IF(WARNING, zeroed_frames_ > 0) << "Filled a total of "
|
| - << zeroed_frames_ << " frames with 0";
|
| + LOG_IF(WARNING, state_ != kStateFinalFade && zeroed_frames_ > 0)
|
| + << "Filled a total of " << zeroed_frames_ << " frames with 0";
|
| zeroed_frames_ = 0;
|
| } else {
|
| // No data left in queue; fill remaining frames with zeros.
|
| - LOG_IF(WARNING, zeroed_frames_ == 0) << "Starting to fill frames with 0";
|
| + LOG_IF(WARNING, state_ != kStateFinalFade && zeroed_frames_ == 0)
|
| + << "Starting to fill frames with 0";
|
| zeroed_frames_ += frames_left;
|
| output->ZeroFramesPartial(frames_filled, frames_left);
|
| frames_filled += frames_left;
|
| @@ -485,6 +497,7 @@ void StreamMixerAlsaInputImpl::SetPaused(bool paused) {
|
|
|
| void StreamMixerAlsaInputImpl::SetVolumeMultiplier(float multiplier) {
|
| RUN_ON_MIXER_THREAD(SetVolumeMultiplier, multiplier);
|
| + LOG(INFO) << this << ": stream volume = " << multiplier;
|
| DCHECK(!IsDeleting());
|
| if (multiplier > 1.0f)
|
| multiplier = 1.0f;
|
|
|