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/time.h" | 10 #include "base/time.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 int pending_data; | 292 int pending_data; |
293 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; | 293 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; |
294 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; | 294 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; |
295 | 295 |
296 while (sizeof(pending_data) == | 296 while (sizeof(pending_data) == |
297 audio_socket->socket()->Receive(&pending_data, sizeof(pending_data))) { | 297 audio_socket->socket()->Receive(&pending_data, sizeof(pending_data))) { |
298 if (pending_data == media::AudioOutputController::kPauseMark) { | 298 if (pending_data == media::AudioOutputController::kPauseMark) { |
299 memset(shared_memory.memory(), 0, memory_length_); | 299 memset(shared_memory.memory(), 0, memory_length_); |
300 media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0); | 300 media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0); |
301 continue; | 301 continue; |
302 } else if (pending_data < 0) { | 302 } else if (pending_data == media::AudioOutputController::kStopMark || |
| 303 pending_data < 0) { |
303 break; | 304 break; |
304 } | 305 } |
305 | 306 |
306 // Convert the number of pending bytes in the render buffer | 307 // Convert the number of pending bytes in the render buffer |
307 // into milliseconds. | 308 // into milliseconds. |
308 audio_delay_milliseconds_ = pending_data / bytes_per_ms; | 309 audio_delay_milliseconds_ = pending_data / bytes_per_ms; |
309 size_t num_frames = FireRenderCallback( | 310 size_t num_frames = FireRenderCallback( |
310 reinterpret_cast<int16*>(shared_memory.memory())); | 311 reinterpret_cast<int16*>(shared_memory.memory())); |
311 | 312 |
312 // Let the host know we are done. | 313 // Let the host know we are done. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // audio thread. | 347 // audio thread. |
347 audio_socket_->Close(); | 348 audio_socket_->Close(); |
348 audio_thread_->Join(); | 349 audio_thread_->Join(); |
349 // Make sure not to release the socket pointer until after the thread | 350 // Make sure not to release the socket pointer until after the thread |
350 // has exited. Otherwise there's a race between startup of the thread | 351 // has exited. Otherwise there's a race between startup of the thread |
351 // and this. | 352 // and this. |
352 audio_socket_ = NULL; | 353 audio_socket_ = NULL; |
353 audio_thread_.reset(NULL); | 354 audio_thread_.reset(NULL); |
354 } | 355 } |
355 } | 356 } |
OLD | NEW |