Chromium Code Reviews| Index: media/audio/audio_device_thread.cc |
| diff --git a/media/audio/audio_device_thread.cc b/media/audio/audio_device_thread.cc |
| index 9447293979415cccca39977c937f55c0d9f4f576..86de1dbfe7a69d9df4c2e0db1a76a83190a39826 100644 |
| --- a/media/audio/audio_device_thread.cc |
| +++ b/media/audio/audio_device_thread.cc |
| @@ -30,7 +30,8 @@ class AudioDeviceThread::Thread |
| Thread(AudioDeviceThread::Callback* callback, |
| base::SyncSocket::Handle socket, |
| const char* thread_name, |
| - bool synchronized_buffers); |
| + bool synchronized_buffers, |
| + bool input); |
| void Start(); |
| @@ -57,6 +58,7 @@ class AudioDeviceThread::Thread |
| base::Lock callback_lock_; |
| const char* thread_name_; |
| const bool synchronized_buffers_; |
| + const bool input_; |
| DISALLOW_COPY_AND_ASSIGN(Thread); |
| }; |
| @@ -71,11 +73,12 @@ AudioDeviceThread::~AudioDeviceThread() { DCHECK(!thread_.get()); } |
| void AudioDeviceThread::Start(AudioDeviceThread::Callback* callback, |
| base::SyncSocket::Handle socket, |
| const char* thread_name, |
| - bool synchronized_buffers) { |
| + bool synchronized_buffers, |
| + bool input) { |
| base::AutoLock auto_lock(thread_lock_); |
| CHECK(!thread_.get()); |
| - thread_ = new AudioDeviceThread::Thread( |
| - callback, socket, thread_name, synchronized_buffers); |
| + thread_ = new AudioDeviceThread::Thread(callback, socket, thread_name, |
| + synchronized_buffers, input); |
| thread_->Start(); |
| } |
| @@ -96,13 +99,14 @@ bool AudioDeviceThread::IsStopped() { |
| AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback, |
| base::SyncSocket::Handle socket, |
| const char* thread_name, |
| - bool synchronized_buffers) |
| + bool synchronized_buffers, |
| + bool input) |
| : thread_(), |
| callback_(callback), |
| socket_(socket), |
| thread_name_(thread_name), |
| - synchronized_buffers_(synchronized_buffers) { |
| -} |
| + synchronized_buffers_(synchronized_buffers), |
| + input_(input) {} |
| AudioDeviceThread::Thread::~Thread() { |
| DCHECK(thread_.is_null()); |
| @@ -165,22 +169,39 @@ void AudioDeviceThread::Thread::ThreadMain() { |
| void AudioDeviceThread::Thread::Run() { |
| uint32 buffer_index = 0; |
| while (true) { |
| - uint32 pending_data = 0; |
| - size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); |
| - if (bytes_read != sizeof(pending_data)) |
| - break; |
| - |
| - // kuint32max is a special signal which is returned after the browser |
| - // stops the output device in response to a renderer side request. |
| - // |
| - // Avoid running Process() for the paused signal, we still need to update |
| - // the buffer index if |synchronized_buffers_| is true though. |
| - // |
| - // See comments in AudioOutputController::DoPause() for details on why. |
| - if (pending_data != kuint32max) { |
| + if (input_) { |
| + uint32_t pending_data = 0; |
| + size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); |
| + if (bytes_read != sizeof(pending_data)) |
| + break; |
| + |
| base::AutoLock auto_lock(callback_lock_); |
| if (callback_) |
| callback_->Process(pending_data); |
| + } else { |
| + uint64_t data = 0; |
|
tommi (sloooow) - chröme
2015/12/01 13:34:25
if you don't want to use a struct, you can also us
DaleCurtis
2015/12/01 18:12:46
Long ago we were worried anything more than 4 byte
tommi (sloooow) - chröme
2015/12/01 19:03:31
Would it work to use the shared memory buffer inst
DaleCurtis
2015/12/01 20:06:48
That's what we do for input I believe.
Henrik Grunell
2015/12/03 17:01:06
Good to know. We can use the shared memory. Yes we
|
| + size_t bytes_read = socket_.Receive(&data, sizeof(data)); |
| + if (bytes_read != sizeof(data)) |
| + break; |
| + |
| + uint32_t pending_data = static_cast<uint32_t>((data >> 32) & 0xffffffff); |
| + uint32_t frames_skipped = static_cast<uint32_t>(data & 0xffffffff); |
| + |
| + base::AutoLock auto_lock(callback_lock_); |
| + if (callback_) { |
| + if (frames_skipped > 0) |
| + callback_->FramesSkipped(frames_skipped); |
| + |
| + // kuint32max is a special signal which is returned after the browser |
| + // stops the output device in response to a renderer side request. |
| + // |
| + // Avoid running Process() for the paused signal, we still need to |
| + // update the buffer index if |synchronized_buffers_| is true though. |
| + // |
| + // See comments in AudioOutputController::DoPause() for details on why. |
| + if (pending_data != kuint32max) |
| + callback_->Process(pending_data); |
| + } |
| } |
| // The usage of |synchronized_buffers_| differs between input and output |