Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chromecast/media/cma/backend/alsa/audio_decoder_alsa.cc

Issue 2683993004: [Chromecast] Fix issue where new playback rate was never used (Closed)
Patch Set: add check during bypass Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/audio_decoder_alsa.h" 5 #include "chromecast/media/cma/backend/alsa/audio_decoder_alsa.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return true; 146 return true;
147 } 147 }
148 148
149 bool AudioDecoderAlsa::SetPlaybackRate(float rate) { 149 bool AudioDecoderAlsa::SetPlaybackRate(float rate) {
150 if (std::abs(rate - 1.0) < kPlaybackRateEpsilon) { 150 if (std::abs(rate - 1.0) < kPlaybackRateEpsilon) {
151 // AudioRendererAlgorithm treats values close to 1 as exactly 1. 151 // AudioRendererAlgorithm treats values close to 1 as exactly 1.
152 rate = 1.0f; 152 rate = 1.0f;
153 } 153 }
154 LOG(INFO) << "SetPlaybackRate to " << rate; 154 LOG(INFO) << "SetPlaybackRate to " << rate;
155 155
156 while (!rate_shifter_info_.empty() && 156 // Remove info for rates that have no pending output left.
157 rate_shifter_info_.back().input_frames == 0) { 157 while (!rate_shifter_info_.empty()) {
158 rate_shifter_info_.pop_back(); 158 RateShifterInfo* rate_info = &rate_shifter_info_.back();
159 int64_t possible_output_frames = rate_info->input_frames / rate_info->rate;
160 DCHECK_GE(possible_output_frames, rate_info->output_frames);
161 if (rate_info->output_frames == possible_output_frames) {
162 rate_shifter_info_.pop_back();
163 } else {
164 break;
165 }
159 } 166 }
167
160 rate_shifter_info_.push_back(RateShifterInfo(rate)); 168 rate_shifter_info_.push_back(RateShifterInfo(rate));
161 return true; 169 return true;
162 } 170 }
163 171
164 AudioDecoderAlsa::BufferStatus AudioDecoderAlsa::PushBuffer( 172 AudioDecoderAlsa::BufferStatus AudioDecoderAlsa::PushBuffer(
165 CastDecoderBuffer* buffer) { 173 CastDecoderBuffer* buffer) {
166 TRACE_FUNCTION_ENTRY0(); 174 TRACE_FUNCTION_ENTRY0();
167 DCHECK(task_runner_->BelongsToCurrentThread()); 175 DCHECK(task_runner_->BelongsToCurrentThread());
168 DCHECK(buffer); 176 DCHECK(buffer);
169 DCHECK(!got_eos_); 177 DCHECK(!got_eos_);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (decoded->end_of_stream()) { 352 if (decoded->end_of_stream()) {
345 got_eos_ = true; 353 got_eos_ = true;
346 } else { 354 } else {
347 int input_frames = decoded->data_size() / (kNumChannels * sizeof(float)); 355 int input_frames = decoded->data_size() / (kNumChannels * sizeof(float));
348 356
349 DCHECK(!rate_shifter_info_.empty()); 357 DCHECK(!rate_shifter_info_.empty());
350 RateShifterInfo* rate_info = &rate_shifter_info_.front(); 358 RateShifterInfo* rate_info = &rate_shifter_info_.front();
351 // Bypass rate shifter if the rate is 1.0, and there are no frames queued 359 // Bypass rate shifter if the rate is 1.0, and there are no frames queued
352 // in the rate shifter. 360 // in the rate shifter.
353 if (rate_info->rate == 1.0 && rate_shifter_->frames_buffered() == 0 && 361 if (rate_info->rate == 1.0 && rate_shifter_->frames_buffered() == 0 &&
354 pending_output_frames_ == kNoPendingOutput) { 362 pending_output_frames_ == kNoPendingOutput &&
363 rate_shifter_info_.size() == 1) {
355 DCHECK_EQ(rate_info->output_frames, rate_info->input_frames); 364 DCHECK_EQ(rate_info->output_frames, rate_info->input_frames);
356 pending_output_frames_ = input_frames; 365 pending_output_frames_ = input_frames;
357 if (got_eos_) { 366 if (got_eos_) {
358 DCHECK(!pushed_eos_); 367 DCHECK(!pushed_eos_);
359 pushed_eos_ = true; 368 pushed_eos_ = true;
360 } 369 }
361 mixer_input_->WritePcm(decoded); 370 mixer_input_->WritePcm(decoded);
362 return; 371 return;
363 } 372 }
364 373
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 scoped_refptr<DecoderBufferBase> output_buffer(new DecoderBufferAdapter( 465 scoped_refptr<DecoderBufferBase> output_buffer(new DecoderBufferAdapter(
457 new ::media::DecoderBuffer(channel_data_size * kNumChannels))); 466 new ::media::DecoderBuffer(channel_data_size * kNumChannels)));
458 for (int c = 0; c < kNumChannels; ++c) { 467 for (int c = 0; c < kNumChannels; ++c) {
459 memcpy(output_buffer->writable_data() + c * channel_data_size, 468 memcpy(output_buffer->writable_data() + c * channel_data_size,
460 rate_shifter_output_->channel(c), channel_data_size); 469 rate_shifter_output_->channel(c), channel_data_size);
461 } 470 }
462 pending_output_frames_ = out_frames; 471 pending_output_frames_ = out_frames;
463 mixer_input_->WritePcm(output_buffer); 472 mixer_input_->WritePcm(output_buffer);
464 473
465 if (rate_shifter_info_.size() > 1 && 474 if (rate_shifter_info_.size() > 1 &&
466 possible_output_frames == rate_info->output_frames) { 475 rate_info->output_frames == possible_output_frames) {
467 double remaining_input_frames = 476 double remaining_input_frames =
468 rate_info->input_frames - (rate_info->output_frames * rate_info->rate); 477 rate_info->input_frames - (rate_info->output_frames * rate_info->rate);
469 rate_shifter_info_.pop_front(); 478 rate_shifter_info_.pop_front();
470 479
471 rate_info = &rate_shifter_info_.front(); 480 rate_info = &rate_shifter_info_.front();
472 LOG(INFO) << "New playback rate in effect: " << rate_info->rate; 481 LOG(INFO) << "New playback rate in effect: " << rate_info->rate;
473 rate_info->input_frames += remaining_input_frames; 482 rate_info->input_frames += remaining_input_frames;
474 DCHECK_EQ(0, rate_info->output_frames); 483 DCHECK_EQ(0, rate_info->output_frames);
475 484
476 // If new playback rate is 1.0, clear out 'extra' data in the rate shifter. 485 // If new playback rate is 1.0, clear out 'extra' data in the rate shifter.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 TRACE_FUNCTION_ENTRY0(); 536 TRACE_FUNCTION_ENTRY0();
528 DCHECK(task_runner_->BelongsToCurrentThread()); 537 DCHECK(task_runner_->BelongsToCurrentThread());
529 if (error != MixerError::kInputIgnored) 538 if (error != MixerError::kInputIgnored)
530 LOG(ERROR) << "Mixer error occurred."; 539 LOG(ERROR) << "Mixer error occurred.";
531 mixer_error_ = true; 540 mixer_error_ = true;
532 delegate_->OnDecoderError(); 541 delegate_->OnDecoderError();
533 } 542 }
534 543
535 } // namespace media 544 } // namespace media
536 } // namespace chromecast 545 } // namespace chromecast
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698