| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 void AudioDeviceThread::Thread::Run() { | 165 void AudioDeviceThread::Thread::Run() { |
| 166 uint32 buffer_index = 0; | 166 uint32 buffer_index = 0; |
| 167 while (true) { | 167 while (true) { |
| 168 uint32 pending_data = 0; | 168 uint32 pending_data = 0; |
| 169 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); | 169 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); |
| 170 if (bytes_read != sizeof(pending_data)) | 170 if (bytes_read != sizeof(pending_data)) |
| 171 break; | 171 break; |
| 172 | 172 |
| 173 { | 173 { |
| 174 base::AutoLock auto_lock(callback_lock_); | 174 base::AutoLock auto_lock(callback_lock_); |
| 175 if (callback_) { | 175 if (callback_) |
| 176 // TODO(acolwell): Update downstream code to use a uint32. | 176 callback_->Process(pending_data); |
| 177 // Under normal operation saturation should never occur here | |
| 178 // and even if it does, it would only cause a temporary loss | |
| 179 // of A/V sync which is much better than crashing or halting | |
| 180 // playback. | |
| 181 callback_->Process(base::saturated_cast<int>(pending_data)); | |
| 182 } | |
| 183 } | 177 } |
| 184 | 178 |
| 185 // Let the other end know which buffer we just filled. The buffer index is | 179 // Let the other end know which buffer we just filled. The buffer index is |
| 186 // used to ensure the other end is getting the buffer it expects. For more | 180 // used to ensure the other end is getting the buffer it expects. For more |
| 187 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). | 181 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). |
| 188 if (synchronized_buffers_) { | 182 if (synchronized_buffers_) { |
| 189 ++buffer_index; | 183 ++buffer_index; |
| 190 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); | 184 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); |
| 191 if (bytes_sent != sizeof(buffer_index)) | 185 if (bytes_sent != sizeof(buffer_index)) |
| 192 break; | 186 break; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 217 } | 211 } |
| 218 | 212 |
| 219 AudioDeviceThread::Callback::~Callback() {} | 213 AudioDeviceThread::Callback::~Callback() {} |
| 220 | 214 |
| 221 void AudioDeviceThread::Callback::InitializeOnAudioThread() { | 215 void AudioDeviceThread::Callback::InitializeOnAudioThread() { |
| 222 MapSharedMemory(); | 216 MapSharedMemory(); |
| 223 CHECK(shared_memory_.memory()); | 217 CHECK(shared_memory_.memory()); |
| 224 } | 218 } |
| 225 | 219 |
| 226 } // namespace media. | 220 } // namespace media. |
| OLD | NEW |