Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1797)

Unified Diff: content/renderer/media/audio_device.cc

Issue 9121045: Switch AudioDevice classes from SyncSocket to CancelableSyncSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_device.cc
diff --git a/content/renderer/media/audio_device.cc b/content/renderer/media/audio_device.cc
index 99b01f22c9c85ff8188af2410902e92a044046db..47fd6e0532c1255725bcf8afe3e1daf66a8ec8af 100644
--- a/content/renderer/media/audio_device.cc
+++ b/content/renderer/media/audio_device.cc
@@ -243,7 +243,7 @@ void AudioDevice::OnLowLatencyCreated(
shared_memory_handle_ = handle;
memory_length_ = length;
- audio_socket_ = new AudioSocket(socket_handle);
+ audio_socket_.reset(new base::CancelableSyncSocket(socket_handle));
audio_thread_.reset(
new base::DelegateSimpleThread(this, "renderer_audio_thread"));
@@ -270,14 +270,18 @@ void AudioDevice::Run() {
base::SharedMemory shared_memory(shared_memory_handle_, false);
shared_memory.Map(media::TotalSharedMemorySizeInBytes(memory_length_));
- scoped_refptr<AudioSocket> audio_socket(audio_socket_);
+ base::CancelableSyncSocket* audio_socket = audio_socket_.get();
int pending_data;
const int samples_per_ms = static_cast<int>(sample_rate_) / 1000;
const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms;
- while (sizeof(pending_data) ==
- audio_socket->socket()->Receive(&pending_data, sizeof(pending_data))) {
+ size_t bytes_read = 0U;
+ while (true) {
+ bytes_read = audio_socket->Receive(&pending_data, sizeof(pending_data));
+ if (bytes_read != sizeof(pending_data))
+ break;
+
if (pending_data == media::AudioOutputController::kPauseMark) {
memset(shared_memory.memory(), 0, memory_length_);
media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0);
@@ -297,7 +301,7 @@ void AudioDevice::Run() {
memory_length_,
num_frames * channels_ * sizeof(int16));
}
- audio_socket->Close();
+ DCHECK_EQ(bytes_read, 0U);
}
size_t AudioDevice::FireRenderCallback(int16* data) {
@@ -327,9 +331,9 @@ void AudioDevice::ShutDownAudioThread() {
if (audio_thread_.get()) {
// Close the socket to terminate the main thread function in the
// audio thread.
- audio_socket_->Close();
- audio_socket_ = NULL;
+ audio_socket_->Shutdown(); // Stops blocking Receive calls.
audio_thread_->Join();
audio_thread_.reset(NULL);
+ audio_socket_.reset();
}
}

Powered by Google App Engine
This is Rietveld 408576698