| 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/audio/cast_audio_output_stream.h" | 5 #include "chromecast/media/audio/cast_audio_output_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 8 #include <string> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 9 #include "chromecast/base/metrics/cast_metrics_helper.h" | 12 #include "chromecast/base/metrics/cast_metrics_helper.h" |
| 10 #include "chromecast/base/task_runner_impl.h" | 13 #include "chromecast/base/task_runner_impl.h" |
| 11 #include "chromecast/media/audio/cast_audio_manager.h" | 14 #include "chromecast/media/audio/cast_audio_manager.h" |
| 12 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" | 15 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" |
| 13 #include "chromecast/public/media/decoder_config.h" | 16 #include "chromecast/public/media/decoder_config.h" |
| 14 #include "chromecast/public/media/media_pipeline_backend.h" | 17 #include "chromecast/public/media/media_pipeline_backend.h" |
| 15 #include "chromecast/public/media/media_pipeline_device_params.h" | 18 #include "chromecast/public/media/media_pipeline_device_params.h" |
| 16 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 263 |
| 261 void CastAudioOutputStream::PushBuffer() { | 264 void CastAudioOutputStream::PushBuffer() { |
| 262 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 265 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
| 263 DCHECK(push_in_progress_); | 266 DCHECK(push_in_progress_); |
| 264 | 267 |
| 265 if (!source_callback_) { | 268 if (!source_callback_) { |
| 266 push_in_progress_ = false; | 269 push_in_progress_ = false; |
| 267 return; | 270 return; |
| 268 } | 271 } |
| 269 | 272 |
| 270 const base::TimeTicks now = base::TimeTicks::Now(); | |
| 271 base::TimeDelta queue_delay = | |
| 272 std::max(base::TimeDelta(), next_push_time_ - now); | |
| 273 uint32_t bytes_delay = queue_delay.InMicroseconds() * | |
| 274 audio_params_.GetBytesPerSecond() / 1000000; | |
| 275 int frame_count = | 273 int frame_count = |
| 276 source_callback_->OnMoreData(audio_bus_.get(), bytes_delay, 0); | 274 source_callback_->OnMoreData(next_push_time_, 0, audio_bus_.get()); |
| 277 VLOG(3) << "frames_filled=" << frame_count << " with latency=" << bytes_delay; | 275 VLOG(3) << "frames_filled=" << frame_count << " with latency=" << bytes_delay; |
| 278 | 276 |
| 279 DCHECK_EQ(frame_count, audio_bus_->frames()); | 277 DCHECK_EQ(frame_count, audio_bus_->frames()); |
| 280 DCHECK_EQ(static_cast<int>(decoder_buffer_->data_size()), | 278 DCHECK_EQ(static_cast<int>(decoder_buffer_->data_size()), |
| 281 frame_count * audio_params_.GetBytesPerFrame()); | 279 frame_count * audio_params_.GetBytesPerFrame()); |
| 282 audio_bus_->ToInterleaved(frame_count, audio_params_.bits_per_sample() / 8, | 280 audio_bus_->ToInterleaved(frame_count, audio_params_.bits_per_sample() / 8, |
| 283 decoder_buffer_->writable_data()); | 281 decoder_buffer_->writable_data()); |
| 284 decoder_buffer_->set_timestamp(timestamp_helper_.GetTimestamp()); | 282 decoder_buffer_->set_timestamp(timestamp_helper_.GetTimestamp()); |
| 285 timestamp_helper_.AddFrames(frame_count); | 283 timestamp_helper_.AddFrames(frame_count); |
| 286 | 284 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 313 | 311 |
| 314 audio_manager_->GetTaskRunner()->PostDelayedTask( | 312 audio_manager_->GetTaskRunner()->PostDelayedTask( |
| 315 FROM_HERE, base::Bind(&CastAudioOutputStream::PushBuffer, | 313 FROM_HERE, base::Bind(&CastAudioOutputStream::PushBuffer, |
| 316 weak_factory_.GetWeakPtr()), | 314 weak_factory_.GetWeakPtr()), |
| 317 delay); | 315 delay); |
| 318 push_in_progress_ = true; | 316 push_in_progress_ = true; |
| 319 } | 317 } |
| 320 | 318 |
| 321 } // namespace media | 319 } // namespace media |
| 322 } // namespace chromecast | 320 } // namespace chromecast |
| OLD | NEW |