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

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

Issue 8659040: There is a racing between SyncSocket::Receive in audio_thread_ and SyncSocket::Close in renderer ... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: new proposal from timmi Created 9 years, 1 month 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_input_device.cc
===================================================================
--- content/renderer/media/audio_input_device.cc (revision 111890)
+++ content/renderer/media/audio_input_device.cc (working copy)
@@ -25,7 +25,8 @@
volume_(1.0),
stream_id_(0),
session_id_(0),
- pending_device_ready_(false) {
+ pending_device_ready_(false),
+ memory_length_(0) {
filter_ = RenderThreadImpl::current()->audio_input_message_filter();
audio_data_.reserve(channels);
#if defined(OS_MACOSX)
@@ -72,6 +73,7 @@
}
bool AudioInputDevice::Stop() {
+ DCHECK(MessageLoop::current() != ChildProcess::current()->io_message_loop());
VLOG(1) << "Stop()";
// Max waiting time for Stop() to complete. If this time limit is passed,
// we will stop waiting and return false. It ensures that Stop() can't block
@@ -88,18 +90,19 @@
// We wait here for the IO task to be completed to remove race conflicts
// with OnLowLatencyCreated() and to ensure that Stop() acts as a synchronous
// function call.
- if (completion.TimedWait(kMaxTimeOut)) {
- if (audio_thread_.get()) {
- // Terminate the main thread function in the audio thread.
- socket_->Close();
- // Wait for the audio thread to exit.
- audio_thread_->Join();
- // Ensures that we can call Stop() multiple times.
- audio_thread_.reset(NULL);
+ if (!completion.TimedWait(kMaxTimeOut)) {
+ LOG(WARNING) << "Failed to shut down audio input on IO thread";
+ }
+
+ if (audio_thread_.get()) {
+ // Terminate the main thread function in the audio thread.
+ {
+ base::SyncSocket socket(socket_handle_);
}
- } else {
- LOG(ERROR) << "Failed to shut down audio input on IO thread";
- return false;
+ // Wait for the audio thread to exit.
+ audio_thread_->Join();
+ // Ensures that we can call Stop() multiple times.
+ audio_thread_.reset(NULL);
}
return true;
@@ -194,10 +197,10 @@
return;
}
- shared_memory_.reset(new base::SharedMemory(handle, false));
- shared_memory_->Map(length);
+ shared_memory_handle_ = handle;
+ memory_length_ = length;
- socket_.reset(new base::SyncSocket(socket_handle));
+ socket_handle_ = socket_handle;
audio_thread_.reset(
new base::DelegateSimpleThread(this, "RendererAudioInputThread"));
@@ -225,7 +228,9 @@
// Joining the audio thread will be quite soon, since the stream has
// been closed before.
if (audio_thread_.get()) {
- socket_->Close();
+ {
+ base::SyncSocket socket(socket_handle_);
+ }
audio_thread_->Join();
audio_thread_.reset(NULL);
}
@@ -281,15 +286,20 @@
void AudioInputDevice::Run() {
audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio);
+ base::SharedMemory shared_memory(shared_memory_handle_, false);
+ shared_memory.Map(memory_length_);
+
+ base::SyncSocket socket(socket_handle_);
+
int pending_data;
const int samples_per_ms =
static_cast<int>(audio_parameters_.sample_rate) / 1000;
const int bytes_per_ms = audio_parameters_.channels *
(audio_parameters_.bits_per_sample / 8) * samples_per_ms;
- while (sizeof(pending_data) == socket_->Receive(&pending_data,
- sizeof(pending_data)) &&
- pending_data >= 0) {
+ while ((sizeof(pending_data) == socket.Receive(&pending_data,
+ sizeof(pending_data))) &&
+ (pending_data >= 0)) {
// TODO(henrika): investigate the provided |pending_data| value
// and ensure that it is actually an accurate delay estimation.
@@ -297,18 +307,16 @@
// into milliseconds.
audio_delay_milliseconds_ = pending_data / bytes_per_ms;
- FireCaptureCallback();
+ FireCaptureCallback(static_cast<int16*>(shared_memory.memory()));
tommi (sloooow) - chröme 2011/12/01 14:40:45 reinterpret_cast
}
}
-void AudioInputDevice::FireCaptureCallback() {
+void AudioInputDevice::FireCaptureCallback(int16* input_audio) {
if (!callback_)
return;
const size_t number_of_frames = audio_parameters_.samples_per_packet;
- // Read 16-bit samples from shared memory (browser writes to it).
- int16* input_audio = static_cast<int16*>(shared_memory_data());
const int bytes_per_sample = sizeof(input_audio[0]);
// Deinterleave each channel and convert to 32-bit floating-point
« content/renderer/media/audio_device.cc ('K') | « content/renderer/media/audio_input_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698