OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
8 #include "media/filters/null_audio_renderer.h" | 8 #include "media/filters/null_audio_renderer.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 11 matching lines...) Expand all Loading... |
22 thread_(NULL), | 22 thread_(NULL), |
23 shutdown_(false) { | 23 shutdown_(false) { |
24 } | 24 } |
25 | 25 |
26 NullAudioRenderer::~NullAudioRenderer() { | 26 NullAudioRenderer::~NullAudioRenderer() { |
27 Stop(); | 27 Stop(); |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 bool NullAudioRenderer::IsMediaFormatSupported( | 31 bool NullAudioRenderer::IsMediaFormatSupported( |
32 const MediaFormat* media_format) { | 32 const MediaFormat& media_format) { |
33 int channels; | 33 int channels; |
34 int sample_rate; | 34 int sample_rate; |
35 int sample_bits; | 35 int sample_bits; |
36 return ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); | 36 return ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); |
37 } | 37 } |
38 | 38 |
39 void NullAudioRenderer::SetPlaybackRate(float playback_rate) { | 39 void NullAudioRenderer::SetPlaybackRate(float playback_rate) { |
40 playback_rate_ = playback_rate; | 40 playback_rate_ = playback_rate; |
41 } | 41 } |
42 | 42 |
(...skipping 13 matching lines...) Expand all Loading... |
56 // Calculate our sleep duration, taking playback rate into consideration. | 56 // Calculate our sleep duration, taking playback rate into consideration. |
57 sleep_in_milliseconds = | 57 sleep_in_milliseconds = |
58 floor(bytes / static_cast<float>(bytes_per_millisecond_)); | 58 floor(bytes / static_cast<float>(bytes_per_millisecond_)); |
59 sleep_in_milliseconds /= playback_rate_; | 59 sleep_in_milliseconds /= playback_rate_; |
60 } | 60 } |
61 | 61 |
62 PlatformThread::Sleep(static_cast<int>(sleep_in_milliseconds)); | 62 PlatformThread::Sleep(static_cast<int>(sleep_in_milliseconds)); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 bool NullAudioRenderer::OnInitialize(const MediaFormat* media_format) { | 66 bool NullAudioRenderer::OnInitialize(const MediaFormat& media_format) { |
67 // Parse out audio parameters. | 67 // Parse out audio parameters. |
68 int channels; | 68 int channels; |
69 int sample_rate; | 69 int sample_rate; |
70 int sample_bits; | 70 int sample_bits; |
71 if (!ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits)) { | 71 if (!ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits)) { |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 // Calculate our bytes per millisecond value and allocate our buffer. | 75 // Calculate our bytes per millisecond value and allocate our buffer. |
76 bytes_per_millisecond_ = (channels * sample_rate * sample_bits / 8) | 76 bytes_per_millisecond_ = (channels * sample_rate * sample_bits / 8) |
77 / base::Time::kMillisecondsPerSecond; | 77 / base::Time::kMillisecondsPerSecond; |
78 buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds; | 78 buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds; |
79 buffer_.reset(new uint8[buffer_size_]); | 79 buffer_.reset(new uint8[buffer_size_]); |
80 DCHECK(buffer_.get()); | 80 DCHECK(buffer_.get()); |
81 | 81 |
82 // It's safe to start the thread now because it simply sleeps when playback | 82 // It's safe to start the thread now because it simply sleeps when playback |
83 // rate is 0.0f. | 83 // rate is 0.0f. |
84 return PlatformThread::Create(0, this, &thread_); | 84 return PlatformThread::Create(0, this, &thread_); |
85 } | 85 } |
86 | 86 |
87 void NullAudioRenderer::OnStop() { | 87 void NullAudioRenderer::OnStop() { |
88 shutdown_ = true; | 88 shutdown_ = true; |
89 if (thread_) | 89 if (thread_) |
90 PlatformThread::Join(thread_); | 90 PlatformThread::Join(thread_); |
91 } | 91 } |
92 | 92 |
93 } // namespace media | 93 } // namespace media |
OLD | NEW |