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

Unified Diff: media/audio/audio_device_thread.cc

Issue 12379071: Use multiple shared memory buffers cyclically for audio capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 7 years, 10 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: media/audio/audio_device_thread.cc
===================================================================
--- media/audio/audio_device_thread.cc (revision 186213)
+++ media/audio/audio_device_thread.cc (working copy)
@@ -28,6 +28,7 @@
public base::RefCountedThreadSafe<AudioDeviceThread::Thread> {
public:
Thread(AudioDeviceThread::Callback* callback,
+ bool need_read_index,
base::SyncSocket::Handle socket,
const char* thread_name);
@@ -52,6 +53,7 @@
private:
base::PlatformThreadHandle thread_;
AudioDeviceThread::Callback* callback_;
+ bool need_read_index_;
base::CancelableSyncSocket socket_;
base::Lock callback_lock_;
const char* thread_name_;
@@ -61,7 +63,8 @@
// AudioDeviceThread implementation
-AudioDeviceThread::AudioDeviceThread() {
+AudioDeviceThread::AudioDeviceThread(bool need_read_index)
+ : need_read_index_(need_read_index) {
}
AudioDeviceThread::~AudioDeviceThread() {
@@ -73,7 +76,8 @@
const char* thread_name) {
base::AutoLock auto_lock(thread_lock_);
CHECK(thread_ == NULL);
- thread_ = new AudioDeviceThread::Thread(callback, socket, thread_name);
+ thread_ = new AudioDeviceThread::Thread(
+ callback, need_read_index_, socket, thread_name);
thread_->Start();
}
@@ -92,10 +96,12 @@
// AudioDeviceThread::Thread implementation
AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback,
+ bool need_read_index,
base::SyncSocket::Handle socket,
const char* thread_name)
: thread_(base::kNullThreadHandle),
callback_(callback),
+ need_read_index_(need_read_index),
socket_(socket),
thread_name_(thread_name) {
}
@@ -161,15 +167,24 @@
void AudioDeviceThread::Thread::Run() {
while (true) {
int pending_data = 0;
+ int pending_id = 0;
size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data));
if (bytes_read != sizeof(pending_data)) {
DCHECK_EQ(bytes_read, 0U);
break;
}
+ if (need_read_index_) {
+ size_t bytes_read = socket_.Receive(&pending_id, sizeof(pending_id));
+ if (bytes_read != sizeof(pending_id)) {
+ DCHECK_EQ(bytes_read, 0U);
+ break;
+ }
+ }
+
base::AutoLock auto_lock(callback_lock_);
if (callback_)
- callback_->Process(pending_data);
+ callback_->Process(pending_data, pending_id);
}
}
@@ -177,23 +192,27 @@
AudioDeviceThread::Callback::Callback(
const AudioParameters& audio_parameters,
- base::SharedMemoryHandle memory, int memory_length)
+ SharedMemoryHandleVector& memory,
+ int memory_length)
: audio_parameters_(audio_parameters),
samples_per_ms_(audio_parameters.sample_rate() / 1000),
bytes_per_ms_(audio_parameters.channels() *
(audio_parameters_.bits_per_sample() / 8) *
samples_per_ms_),
- shared_memory_(memory, false),
memory_length_(memory_length) {
CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early.
CHECK_NE(samples_per_ms_, 0);
+ shared_memory_.resize(memory.size());
+ for (size_t id = 0; id < shared_memory_.size(); ++id)
+ shared_memory_[id] = new base::SharedMemory(memory[id], false);
}
AudioDeviceThread::Callback::~Callback() {}
void AudioDeviceThread::Callback::InitializeOnAudioThread() {
MapSharedMemory();
- CHECK(shared_memory_.memory());
+ for (size_t id = 0; id < shared_memory_.size(); ++id)
+ CHECK(shared_memory_[id]->memory());
}
} // namespace media.

Powered by Google App Engine
This is Rietveld 408576698