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

Unified Diff: content/browser/renderer_host/media/audio_input_sync_writer.cc

Issue 12379071: Use multiple shared memory buffers cyclically for audio capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: code review Created 7 years, 9 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/browser/renderer_host/media/audio_input_sync_writer.cc
===================================================================
--- content/browser/renderer_host/media/audio_input_sync_writer.cc (revision 186364)
+++ content/browser/renderer_host/media/audio_input_sync_writer.cc (working copy)
@@ -11,8 +11,16 @@
namespace content {
-AudioInputSyncWriter::AudioInputSyncWriter(base::SharedMemory* shared_memory)
- : shared_memory_(shared_memory) {
+AudioInputSyncWriter::AudioInputSyncWriter(
+ base::SharedMemory* shared_memory,
+ int shared_memory_segment_count)
+ : shared_memory_(shared_memory),
+ shared_memory_segment_count_(shared_memory_segment_count),
+ current_segment_id_(0) {
+ DCHECK_GT(shared_memory_segment_count, 0);
+ DCHECK_EQ(shared_memory->created_size() % shared_memory_segment_count, 0u);
+ shared_memory_segment_size_ =
+ shared_memory->created_size() / shared_memory_segment_count;
}
AudioInputSyncWriter::~AudioInputSyncWriter() {}
@@ -22,14 +30,19 @@
socket_->Send(&bytes, sizeof(bytes));
}
-uint32 AudioInputSyncWriter::Write(const void* data, uint32 size,
- double volume) {
+uint32 AudioInputSyncWriter::Write(
+ const void* data, uint32 size, double volume) {
+ uint8* ptr = static_cast<uint8*>(shared_memory_->memory());
+ ptr += current_segment_id_ * shared_memory_segment_size_;
media::AudioInputBuffer* buffer =
- reinterpret_cast<media::AudioInputBuffer*>(shared_memory_->memory());
+ reinterpret_cast<media::AudioInputBuffer*>(ptr);
buffer->params.volume = volume;
buffer->params.size = size;
memcpy(buffer->audio, data, size);
+ if (++current_segment_id_ >= shared_memory_segment_count_)
+ current_segment_id_ = 0;
+
return size;
}
« no previous file with comments | « content/browser/renderer_host/media/audio_input_sync_writer.h ('k') | content/common/media/audio_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698