| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <cmath> | 6 #include <cmath> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // If paused, sleep for 10 milliseconds before polling again. | 53 // If paused, sleep for 10 milliseconds before polling again. |
| 54 sleep_in_milliseconds = 10.0f; | 54 sleep_in_milliseconds = 10.0f; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Sleep for at least one millisecond so we don't spin the CPU. | 57 // Sleep for at least one millisecond so we don't spin the CPU. |
| 58 base::PlatformThread::Sleep( | 58 base::PlatformThread::Sleep( |
| 59 std::max(1, static_cast<int>(sleep_in_milliseconds))); | 59 std::max(1, static_cast<int>(sleep_in_milliseconds))); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool NullAudioRenderer::OnInitialize(const AudioDecoderConfig& config) { | 63 bool NullAudioRenderer::OnInitialize(int bits_per_channel, |
| 64 ChannelLayout channel_layout, |
| 65 int sample_rate) { |
| 64 // Calculate our bytes per millisecond value and allocate our buffer. | 66 // Calculate our bytes per millisecond value and allocate our buffer. |
| 65 bytes_per_millisecond_ = | 67 bytes_per_millisecond_ = |
| 66 (ChannelLayoutToChannelCount(config.channel_layout) * config.sample_rate * | 68 (ChannelLayoutToChannelCount(channel_layout) * sample_rate * |
| 67 config.bits_per_channel / 8) / base::Time::kMillisecondsPerSecond; | 69 bits_per_channel / 8) / base::Time::kMillisecondsPerSecond; |
| 68 buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds; | 70 buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds; |
| 69 buffer_.reset(new uint8[buffer_size_]); | 71 buffer_.reset(new uint8[buffer_size_]); |
| 70 DCHECK(buffer_.get()); | 72 DCHECK(buffer_.get()); |
| 71 | 73 |
| 72 // It's safe to start the thread now because it simply sleeps when playback | 74 // It's safe to start the thread now because it simply sleeps when playback |
| 73 // rate is 0.0f. | 75 // rate is 0.0f. |
| 74 return base::PlatformThread::Create(0, this, &thread_); | 76 return base::PlatformThread::Create(0, this, &thread_); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void NullAudioRenderer::OnStop() { | 79 void NullAudioRenderer::OnStop() { |
| 78 shutdown_ = true; | 80 shutdown_ = true; |
| 79 if (thread_) { | 81 if (thread_) { |
| 80 base::PlatformThread::Join(thread_); | 82 base::PlatformThread::Join(thread_); |
| 81 thread_ = base::kNullThreadHandle; | 83 thread_ = base::kNullThreadHandle; |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 | 86 |
| 85 } // namespace media | 87 } // namespace media |
| OLD | NEW |