| 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 "content/renderer/media/track_audio_renderer.h" | 5 #include "content/renderer/media/track_audio_renderer.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 int64_t num_samples_rendered, | 33 int64_t num_samples_rendered, |
| 34 int sample_rate) { | 34 int sample_rate) { |
| 35 return prior_elapsed_render_time + base::TimeDelta::FromMicroseconds( | 35 return prior_elapsed_render_time + base::TimeDelta::FromMicroseconds( |
| 36 num_samples_rendered * base::Time::kMicrosecondsPerSecond / sample_rate); | 36 num_samples_rendered * base::Time::kMicrosecondsPerSecond / sample_rate); |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 // media::AudioRendererSink::RenderCallback implementation | 41 // media::AudioRendererSink::RenderCallback implementation |
| 42 int TrackAudioRenderer::Render(media::AudioBus* audio_bus, | 42 int TrackAudioRenderer::Render(media::AudioBus* audio_bus, |
| 43 uint32_t frames_delayed, | 43 base::TimeDelta delay, |
| 44 base::TimeTicks delay_timestamp, |
| 44 uint32_t frames_skipped) { | 45 uint32_t frames_skipped) { |
| 45 TRACE_EVENT0("audio", "TrackAudioRenderer::Render"); | 46 TRACE_EVENT0("audio", "TrackAudioRenderer::Render"); |
| 46 base::AutoLock auto_lock(thread_lock_); | 47 base::AutoLock auto_lock(thread_lock_); |
| 47 | 48 |
| 48 if (!audio_shifter_) { | 49 if (!audio_shifter_) { |
| 49 audio_bus->Zero(); | 50 audio_bus->Zero(); |
| 50 return 0; | 51 return 0; |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Source sample rate equals to output one, see MaybeStartSink(), so using it. | |
| 54 uint32_t audio_delay_milliseconds = static_cast<double>(frames_delayed) * | |
| 55 base::Time::kMillisecondsPerSecond / | |
| 56 source_params_.sample_rate(); | |
| 57 | 54 |
| 58 // TODO(miu): Plumbing is needed to determine the actual playout timestamp | 55 // TODO(miu): Plumbing is needed to determine the actual playout timestamp |
| 59 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 56 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
| 60 // audio/video sync. http://crbug.com/335335 | 57 // audio/video sync. http://crbug.com/335335 |
| 61 const base::TimeTicks playout_time = | 58 const base::TimeTicks playout_time = base::TimeTicks::Now() + delay; |
| 62 base::TimeTicks::Now() + | 59 DLOG(ERROR) << "Pulling audio out of shifter to be played " |
| 63 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); | 60 << delay.InMilliseconds() << " ms from now. " |
| 64 DVLOG(2) << "Pulling audio out of shifter to be played " | 61 << audio_bus->frames(); |
| 65 << audio_delay_milliseconds << " ms from now."; | |
| 66 audio_shifter_->Pull(audio_bus, playout_time); | 62 audio_shifter_->Pull(audio_bus, playout_time); |
| 67 num_samples_rendered_ += audio_bus->frames(); | 63 num_samples_rendered_ += audio_bus->frames(); |
| 68 return audio_bus->frames(); | 64 return audio_bus->frames(); |
| 69 } | 65 } |
| 70 | 66 |
| 71 void TrackAudioRenderer::OnRenderError() { | 67 void TrackAudioRenderer::OnRenderError() { |
| 72 NOTIMPLEMENTED(); | 68 NOTIMPLEMENTED(); |
| 73 } | 69 } |
| 74 | 70 |
| 75 // content::MediaStreamAudioSink implementation | 71 // content::MediaStreamAudioSink implementation |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (source_params_.IsValid()) { | 382 if (source_params_.IsValid()) { |
| 387 prior_elapsed_render_time_ = | 383 prior_elapsed_render_time_ = |
| 388 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, | 384 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, |
| 389 num_samples_rendered_, | 385 num_samples_rendered_, |
| 390 source_params_.sample_rate()); | 386 source_params_.sample_rate()); |
| 391 num_samples_rendered_ = 0; | 387 num_samples_rendered_ = 0; |
| 392 } | 388 } |
| 393 } | 389 } |
| 394 | 390 |
| 395 } // namespace content | 391 } // namespace content |
| OLD | NEW |