| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const AudioHardwareConfig& hardware_config, | 50 const AudioHardwareConfig& hardware_config, |
| 51 const scoped_refptr<MediaLog>& media_log) | 51 const scoped_refptr<MediaLog>& media_log) |
| 52 : task_runner_(task_runner), | 52 : task_runner_(task_runner), |
| 53 expecting_config_changes_(false), | 53 expecting_config_changes_(false), |
| 54 sink_(sink), | 54 sink_(sink), |
| 55 audio_buffer_stream_( | 55 audio_buffer_stream_( |
| 56 new AudioBufferStream(task_runner, decoders.Pass(), media_log)), | 56 new AudioBufferStream(task_runner, decoders.Pass(), media_log)), |
| 57 hardware_config_(hardware_config), | 57 hardware_config_(hardware_config), |
| 58 media_log_(media_log), | 58 media_log_(media_log), |
| 59 tick_clock_(new base::DefaultTickClock()), | 59 tick_clock_(new base::DefaultTickClock()), |
| 60 last_audio_memory_usage_(0), |
| 60 playback_rate_(0.0), | 61 playback_rate_(0.0), |
| 61 state_(kUninitialized), | 62 state_(kUninitialized), |
| 62 buffering_state_(BUFFERING_HAVE_NOTHING), | 63 buffering_state_(BUFFERING_HAVE_NOTHING), |
| 63 rendering_(false), | 64 rendering_(false), |
| 64 sink_playing_(false), | 65 sink_playing_(false), |
| 65 pending_read_(false), | 66 pending_read_(false), |
| 66 received_end_of_stream_(false), | 67 received_end_of_stream_(false), |
| 67 rendered_end_of_stream_(false), | 68 rendered_end_of_stream_(false), |
| 68 weak_factory_(this) { | 69 weak_factory_(this) { |
| 69 audio_buffer_stream_->set_splice_observer(base::Bind( | 70 audio_buffer_stream_->set_splice_observer(base::Bind( |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 328 |
| 328 state_ = kInitializing; | 329 state_ = kInitializing; |
| 329 | 330 |
| 330 // Always post |init_cb_| because |this| could be destroyed if initialization | 331 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 331 // failed. | 332 // failed. |
| 332 init_cb_ = BindToCurrentLoop(init_cb); | 333 init_cb_ = BindToCurrentLoop(init_cb); |
| 333 | 334 |
| 334 buffering_state_cb_ = buffering_state_cb; | 335 buffering_state_cb_ = buffering_state_cb; |
| 335 ended_cb_ = ended_cb; | 336 ended_cb_ = ended_cb; |
| 336 error_cb_ = error_cb; | 337 error_cb_ = error_cb; |
| 338 statistics_cb_ = statistics_cb; |
| 337 | 339 |
| 338 const AudioParameters& hw_params = hardware_config_.GetOutputConfig(); | 340 const AudioParameters& hw_params = hardware_config_.GetOutputConfig(); |
| 339 expecting_config_changes_ = stream->SupportsConfigChanges(); | 341 expecting_config_changes_ = stream->SupportsConfigChanges(); |
| 340 if (!expecting_config_changes_ || !hw_params.IsValid()) { | 342 if (!expecting_config_changes_ || !hw_params.IsValid()) { |
| 341 // The actual buffer size is controlled via the size of the AudioBus | 343 // The actual buffer size is controlled via the size of the AudioBus |
| 342 // provided to Render(), so just choose something reasonable here for looks. | 344 // provided to Render(), so just choose something reasonable here for looks. |
| 343 int buffer_size = stream->audio_decoder_config().samples_per_second() / 100; | 345 int buffer_size = stream->audio_decoder_config().samples_per_second() / 100; |
| 344 audio_parameters_.Reset( | 346 audio_parameters_.Reset( |
| 345 AudioParameters::AUDIO_PCM_LOW_LATENCY, | 347 AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 346 stream->audio_decoder_config().channel_layout(), | 348 stream->audio_decoder_config().channel_layout(), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 509 |
| 508 if (state_ != kUninitialized) | 510 if (state_ != kUninitialized) |
| 509 algorithm_->EnqueueBuffer(buffer); | 511 algorithm_->EnqueueBuffer(buffer); |
| 510 } | 512 } |
| 511 | 513 |
| 512 // Store the timestamp of the first packet so we know when to start actual | 514 // Store the timestamp of the first packet so we know when to start actual |
| 513 // audio playback. | 515 // audio playback. |
| 514 if (first_packet_timestamp_ == kNoTimestamp()) | 516 if (first_packet_timestamp_ == kNoTimestamp()) |
| 515 first_packet_timestamp_ = buffer->timestamp(); | 517 first_packet_timestamp_ = buffer->timestamp(); |
| 516 | 518 |
| 519 const size_t memory_usage = algorithm_->GetMemoryUsage(); |
| 520 PipelineStatistics stats; |
| 521 stats.audio_memory_usage = memory_usage - last_audio_memory_usage_; |
| 522 last_audio_memory_usage_ = memory_usage; |
| 523 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, stats)); |
| 524 |
| 517 switch (state_) { | 525 switch (state_) { |
| 518 case kUninitialized: | 526 case kUninitialized: |
| 519 case kInitializing: | 527 case kInitializing: |
| 520 case kFlushing: | 528 case kFlushing: |
| 521 NOTREACHED(); | 529 NOTREACHED(); |
| 522 return false; | 530 return false; |
| 523 | 531 |
| 524 case kFlushed: | 532 case kFlushed: |
| 525 DCHECK(!pending_read_); | 533 DCHECK(!pending_read_); |
| 526 return false; | 534 return false; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 << buffering_state; | 806 << buffering_state; |
| 799 DCHECK_NE(buffering_state_, buffering_state); | 807 DCHECK_NE(buffering_state_, buffering_state); |
| 800 lock_.AssertAcquired(); | 808 lock_.AssertAcquired(); |
| 801 buffering_state_ = buffering_state; | 809 buffering_state_ = buffering_state; |
| 802 | 810 |
| 803 task_runner_->PostTask(FROM_HERE, | 811 task_runner_->PostTask(FROM_HERE, |
| 804 base::Bind(buffering_state_cb_, buffering_state_)); | 812 base::Bind(buffering_state_cb_, buffering_state_)); |
| 805 } | 813 } |
| 806 | 814 |
| 807 } // namespace media | 815 } // namespace media |
| OLD | NEW |