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

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: aggregate buffers 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,
+ uint32 shared_memory_segment_count)
+ : shared_memory_(shared_memory),
+ shared_memory_segment_count_(shared_memory_segment_count),
+ current_segment_id_(0) {
+ DCHECK(shared_memory_segment_count);
miu 2013/03/06 18:06:41 Should be DCHECK_LT(0, shared_memory_segment_count
wjia(left Chromium) 2013/03/06 22:12:41 Done.
+ 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() {}
@@ -20,12 +28,20 @@
// TODO(henrika): Combine into one method (including Write).
void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) {
socket_->Send(&bytes, sizeof(bytes));
+ // The shared memory has multiple equal lengthed segments used to transfer
+ // recorded data. Each time, one segment is used. Both data size and segment
+ // id need to be sent to the receiver.
+ socket_->Send(&current_segment_id_, sizeof(current_segment_id_));
miu 2013/03/06 18:06:41 Agree with Dale: That you don't need to send this
wjia(left Chromium) 2013/03/06 22:12:41 Done. I still think such constraint shouldn't be p
+ if (++current_segment_id_ >= shared_memory_segment_count_)
+ current_segment_id_ = 0;
}
-uint32 AudioInputSyncWriter::Write(const void* data, uint32 size,
- double volume) {
+uint32 AudioInputSyncWriter::Write(
+ const void* data, uint32 size, double volume) {
+ uint8* ptr = reinterpret_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);

Powered by Google App Engine
This is Rietveld 408576698