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

Unified Diff: media/audio/audio_device_thread.cc

Issue 22886005: Switch audio synchronization from sleep() based to select() based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK. Created 7 years, 2 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
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_device_thread.cc
diff --git a/media/audio/audio_device_thread.cc b/media/audio/audio_device_thread.cc
index 6998890dd2fc9ef29e80c6b8131406f718b9f393..daf908556d8edf221f61fda6d4cd38fc41d9fbd2 100644
--- a/media/audio/audio_device_thread.cc
+++ b/media/audio/audio_device_thread.cc
@@ -28,7 +28,8 @@ class AudioDeviceThread::Thread
public:
Thread(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
- const char* thread_name);
+ const char* thread_name,
+ bool synchronized_buffers);
void Start();
@@ -54,6 +55,7 @@ class AudioDeviceThread::Thread
base::CancelableSyncSocket socket_;
base::Lock callback_lock_;
const char* thread_name_;
+ const bool synchronized_buffers_;
DISALLOW_COPY_AND_ASSIGN(Thread);
};
@@ -67,10 +69,12 @@ AudioDeviceThread::~AudioDeviceThread() { DCHECK(!thread_.get()); }
void AudioDeviceThread::Start(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
- const char* thread_name) {
+ const char* thread_name,
+ bool synchronized_buffers) {
base::AutoLock auto_lock(thread_lock_);
- CHECK(thread_.get() == NULL);
- thread_ = new AudioDeviceThread::Thread(callback, socket, thread_name);
+ CHECK(!thread_);
+ thread_ = new AudioDeviceThread::Thread(
+ callback, socket, thread_name, synchronized_buffers);
thread_->Start();
}
@@ -84,17 +88,19 @@ void AudioDeviceThread::Stop(base::MessageLoop* loop_for_join) {
bool AudioDeviceThread::IsStopped() {
base::AutoLock auto_lock(thread_lock_);
- return thread_.get() == NULL;
+ return !thread_;
}
// AudioDeviceThread::Thread implementation
AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
- const char* thread_name)
+ const char* thread_name,
+ bool synchronized_buffers)
: thread_(),
callback_(callback),
socket_(socket),
- thread_name_(thread_name) {
+ thread_name_(thread_name),
+ synchronized_buffers_(synchronized_buffers) {
}
AudioDeviceThread::Thread::~Thread() {
@@ -156,6 +162,7 @@ void AudioDeviceThread::Thread::ThreadMain() {
}
void AudioDeviceThread::Thread::Run() {
+ uint32 buffer_index = 0;
while (true) {
int pending_data = 0;
size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data));
@@ -164,9 +171,21 @@ void AudioDeviceThread::Thread::Run() {
break;
}
- base::AutoLock auto_lock(callback_lock_);
- if (callback_)
- callback_->Process(pending_data);
+ {
+ base::AutoLock auto_lock(callback_lock_);
+ if (callback_)
+ callback_->Process(pending_data);
+ }
+
+ // Let the other end know which buffer we just filled. The buffer index is
+ // used to ensure the other end is getting the buffer it expects. For more
+ // details on how this works see AudioSyncReader::WaitUntilDataIsReady().
+ if (synchronized_buffers_) {
+ ++buffer_index;
+ size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index));
+ if (bytes_sent != sizeof(buffer_index))
+ break;
+ }
}
}
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698