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(base::TimeDelta delay, | 42 int TrackAudioRenderer::Render(media::AudioBus* audio_bus, |
43 base::TimeTicks delay_timestamp, | 43 uint32_t frames_delayed, |
44 int prior_frames_skipped, | 44 uint32_t frames_skipped) { |
45 media::AudioBus* audio_bus) { | |
46 TRACE_EVENT0("audio", "TrackAudioRenderer::Render"); | 45 TRACE_EVENT0("audio", "TrackAudioRenderer::Render"); |
47 base::AutoLock auto_lock(thread_lock_); | 46 base::AutoLock auto_lock(thread_lock_); |
48 | 47 |
49 if (!audio_shifter_) { | 48 if (!audio_shifter_) { |
50 audio_bus->Zero(); | 49 audio_bus->Zero(); |
51 return 0; | 50 return 0; |
52 } | 51 } |
53 | 52 |
| 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(); |
54 | 57 |
55 // TODO(miu): Plumbing is needed to determine the actual playout timestamp | 58 // TODO(miu): Plumbing is needed to determine the actual playout timestamp |
56 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 59 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
57 // audio/video sync. http://crbug.com/335335 | 60 // audio/video sync. http://crbug.com/335335 |
58 const base::TimeTicks playout_time = base::TimeTicks::Now() + delay; | 61 const base::TimeTicks playout_time = |
59 DLOG(ERROR) << "Pulling audio out of shifter to be played " | 62 base::TimeTicks::Now() + |
60 << delay.InMilliseconds() << " ms from now. " | 63 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); |
61 << audio_bus->frames(); | 64 DVLOG(2) << "Pulling audio out of shifter to be played " |
| 65 << audio_delay_milliseconds << " ms from now."; |
62 audio_shifter_->Pull(audio_bus, playout_time); | 66 audio_shifter_->Pull(audio_bus, playout_time); |
63 num_samples_rendered_ += audio_bus->frames(); | 67 num_samples_rendered_ += audio_bus->frames(); |
64 return audio_bus->frames(); | 68 return audio_bus->frames(); |
65 } | 69 } |
66 | 70 |
67 void TrackAudioRenderer::OnRenderError() { | 71 void TrackAudioRenderer::OnRenderError() { |
68 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
69 } | 73 } |
70 | 74 |
71 // content::MediaStreamAudioSink implementation | 75 // content::MediaStreamAudioSink implementation |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 if (source_params_.IsValid()) { | 386 if (source_params_.IsValid()) { |
383 prior_elapsed_render_time_ = | 387 prior_elapsed_render_time_ = |
384 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, | 388 ComputeTotalElapsedRenderTime(prior_elapsed_render_time_, |
385 num_samples_rendered_, | 389 num_samples_rendered_, |
386 source_params_.sample_rate()); | 390 source_params_.sample_rate()); |
387 num_samples_rendered_ = 0; | 391 num_samples_rendered_ = 0; |
388 } | 392 } |
389 } | 393 } |
390 | 394 |
391 } // namespace content | 395 } // namespace content |
OLD | NEW |