| 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/audio_device.h" | 5 #include "content/renderer/media/audio_device.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 271 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
| 272 | 272 |
| 273 base::SharedMemory shared_memory(shared_memory_handle_, false); | 273 base::SharedMemory shared_memory(shared_memory_handle_, false); |
| 274 shared_memory.Map(media::TotalSharedMemorySizeInBytes(memory_length_)); | 274 shared_memory.Map(media::TotalSharedMemorySizeInBytes(memory_length_)); |
| 275 base::CancelableSyncSocket* audio_socket = audio_socket_.get(); | 275 base::CancelableSyncSocket* audio_socket = audio_socket_.get(); |
| 276 | 276 |
| 277 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; | 277 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; |
| 278 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; | 278 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; |
| 279 | 279 |
| 280 while (true) { | 280 while (true) { |
| 281 uint32 pending_data = 0; | 281 int pending_data = 0; |
| 282 size_t bytes_read = audio_socket->Receive(&pending_data, | 282 size_t bytes_read = audio_socket->Receive(&pending_data, |
| 283 sizeof(pending_data)); | 283 sizeof(pending_data)); |
| 284 if (bytes_read != sizeof(pending_data)) { | 284 if (bytes_read != sizeof(pending_data)) { |
| 285 DCHECK_EQ(bytes_read, 0U); | 285 DCHECK_EQ(bytes_read, 0U); |
| 286 break; | 286 break; |
| 287 } | 287 } |
| 288 | 288 |
| 289 if (pending_data == | 289 if (pending_data == media::AudioOutputController::kPauseMark) { |
| 290 static_cast<uint32>(media::AudioOutputController::kPauseMark)) { | |
| 291 memset(shared_memory.memory(), 0, memory_length_); | 290 memset(shared_memory.memory(), 0, memory_length_); |
| 292 media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0); | 291 media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0); |
| 293 continue; | 292 continue; |
| 294 } | 293 } |
| 295 | 294 |
| 296 // Convert the number of pending bytes in the render buffer | 295 // Convert the number of pending bytes in the render buffer |
| 297 // into milliseconds. | 296 // into milliseconds. |
| 298 audio_delay_milliseconds_ = pending_data / bytes_per_ms; | 297 audio_delay_milliseconds_ = pending_data / bytes_per_ms; |
| 299 size_t num_frames = FireRenderCallback( | 298 size_t num_frames = FireRenderCallback( |
| 300 reinterpret_cast<int16*>(shared_memory.memory())); | 299 reinterpret_cast<int16*>(shared_memory.memory())); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // Close the socket to terminate the main thread function in the | 333 // Close the socket to terminate the main thread function in the |
| 335 // audio thread. | 334 // audio thread. |
| 336 audio_socket_->Shutdown(); // Stops blocking Receive calls. | 335 audio_socket_->Shutdown(); // Stops blocking Receive calls. |
| 337 // TODO(tommi): We must not do this from the IO thread. Fix. | 336 // TODO(tommi): We must not do this from the IO thread. Fix. |
| 338 base::ThreadRestrictions::ScopedAllowIO allow_wait; | 337 base::ThreadRestrictions::ScopedAllowIO allow_wait; |
| 339 audio_thread_->Join(); | 338 audio_thread_->Join(); |
| 340 audio_thread_.reset(NULL); | 339 audio_thread_.reset(NULL); |
| 341 audio_socket_.reset(); | 340 audio_socket_.reset(); |
| 342 } | 341 } |
| 343 } | 342 } |
| OLD | NEW |