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 21 matching lines...) Expand all Loading... |
32 base::TimeDelta prior_elapsed_render_time, | 32 base::TimeDelta prior_elapsed_render_time, |
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(base::TimeDelta delay, |
43 uint32_t frames_delayed, | 43 base::TimeTicks delay_timestamp, |
44 uint32_t frames_skipped) { | 44 int prior_frames_skipped, |
| 45 media::AudioBus* audio_bus) { |
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() + | |
63 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); | |
64 DVLOG(2) << "Pulling audio out of shifter to be played " | 59 DVLOG(2) << "Pulling audio out of shifter to be played " |
65 << audio_delay_milliseconds << " ms from now."; | 60 << delay.InMilliseconds() << " ms from now."; |
66 audio_shifter_->Pull(audio_bus, playout_time); | 61 audio_shifter_->Pull(audio_bus, playout_time); |
67 num_samples_rendered_ += audio_bus->frames(); | 62 num_samples_rendered_ += audio_bus->frames(); |
68 return audio_bus->frames(); | 63 return audio_bus->frames(); |
69 } | 64 } |
70 | 65 |
71 void TrackAudioRenderer::OnRenderError() { | 66 void TrackAudioRenderer::OnRenderError() { |
72 NOTIMPLEMENTED(); | 67 NOTIMPLEMENTED(); |
73 } | 68 } |
74 | 69 |
75 // content::MediaStreamAudioSink implementation | 70 // content::MediaStreamAudioSink implementation |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if (source_params_.IsValid()) { | 381 if (source_params_.IsValid()) { |
387 prior_elapsed_render_time_ = | 382 prior_elapsed_render_time_ = |
388 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, | 383 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, |
389 num_samples_rendered_, | 384 num_samples_rendered_, |
390 source_params_.sample_rate()); | 385 source_params_.sample_rate()); |
391 num_samples_rendered_ = 0; | 386 num_samples_rendered_ = 0; |
392 } | 387 } |
393 } | 388 } |
394 | 389 |
395 } // namespace content | 390 } // namespace content |
OLD | NEW |