| 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 "media/audio/audio_device_thread.h" | 5 #include "media/audio/audio_device_thread.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> |
| 8 | 11 |
| 9 #include "base/bind.h" | 12 #include "base/bind.h" |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 11 #include "base/memory/aligned_memory.h" | 14 #include "base/memory/aligned_memory.h" |
| 12 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 13 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 15 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 16 #include "media/base/audio_bus.h" | 19 #include "media/base/audio_bus.h" |
| 17 | 20 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 159 } |
| 157 | 160 |
| 158 Run(); | 161 Run(); |
| 159 | 162 |
| 160 // Release the reference for the thread. Note that after this, the Thread | 163 // Release the reference for the thread. Note that after this, the Thread |
| 161 // instance will most likely be deleted. | 164 // instance will most likely be deleted. |
| 162 Release(); | 165 Release(); |
| 163 } | 166 } |
| 164 | 167 |
| 165 void AudioDeviceThread::Thread::Run() { | 168 void AudioDeviceThread::Thread::Run() { |
| 166 uint32 buffer_index = 0; | 169 uint32_t buffer_index = 0; |
| 167 while (true) { | 170 while (true) { |
| 168 uint32 pending_data = 0; | 171 uint32_t pending_data = 0; |
| 169 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); | 172 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); |
| 170 if (bytes_read != sizeof(pending_data)) | 173 if (bytes_read != sizeof(pending_data)) |
| 171 break; | 174 break; |
| 172 | 175 |
| 173 // kuint32max is a special signal which is returned after the browser | 176 // std::numeric_limits<uint32_t>::max() is a special signal which is |
| 174 // stops the output device in response to a renderer side request. | 177 // returned after the browser stops the output device in response to a |
| 178 // renderer side request. |
| 175 // | 179 // |
| 176 // Avoid running Process() for the paused signal, we still need to update | 180 // Avoid running Process() for the paused signal, we still need to update |
| 177 // the buffer index if |synchronized_buffers_| is true though. | 181 // the buffer index if |synchronized_buffers_| is true though. |
| 178 // | 182 // |
| 179 // See comments in AudioOutputController::DoPause() for details on why. | 183 // See comments in AudioOutputController::DoPause() for details on why. |
| 180 if (pending_data != kuint32max) { | 184 if (pending_data != std::numeric_limits<uint32_t>::max()) { |
| 181 base::AutoLock auto_lock(callback_lock_); | 185 base::AutoLock auto_lock(callback_lock_); |
| 182 if (callback_) | 186 if (callback_) |
| 183 callback_->Process(pending_data); | 187 callback_->Process(pending_data); |
| 184 } | 188 } |
| 185 | 189 |
| 186 // The usage of |synchronized_buffers_| differs between input and output | 190 // The usage of |synchronized_buffers_| differs between input and output |
| 187 // cases. | 191 // cases. |
| 188 // Input: | 192 // Input: |
| 189 // Let the other end know that we have read data, so that it can verify | 193 // Let the other end know that we have read data, so that it can verify |
| 190 // it doesn't overwrite any data before read. The |buffer_index| value is | 194 // it doesn't overwrite any data before read. The |buffer_index| value is |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 229 } |
| 226 | 230 |
| 227 AudioDeviceThread::Callback::~Callback() {} | 231 AudioDeviceThread::Callback::~Callback() {} |
| 228 | 232 |
| 229 void AudioDeviceThread::Callback::InitializeOnAudioThread() { | 233 void AudioDeviceThread::Callback::InitializeOnAudioThread() { |
| 230 MapSharedMemory(); | 234 MapSharedMemory(); |
| 231 CHECK(shared_memory_.memory()); | 235 CHECK(shared_memory_.memory()); |
| 232 } | 236 } |
| 233 | 237 |
| 234 } // namespace media. | 238 } // namespace media. |
| OLD | NEW |