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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 AudioInputSyncWriter::AudioInputSyncWriter(base::SharedMemory* shared_memory) 14 AudioInputSyncWriter::AudioInputSyncWriter(SharedMemoryVector* shared_memory)
15 : shared_memory_(shared_memory) { 15 : shared_memory_(shared_memory),
16 current_buffer_id_(0) {
16 } 17 }
17 18
18 AudioInputSyncWriter::~AudioInputSyncWriter() {} 19 AudioInputSyncWriter::~AudioInputSyncWriter() {}
19 20
20 // TODO(henrika): Combine into one method (including Write). 21 // TODO(henrika): Combine into one method (including Write).
21 void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) { 22 void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) {
22 socket_->Send(&bytes, sizeof(bytes)); 23 socket_->Send(&bytes, sizeof(bytes));
24 uint32 index = static_cast<uint32>(current_buffer_id_);
henrika (OOO until Aug 14) 2013/03/04 13:12:51 Please add a few lines of comments here which expl
wjia(left Chromium) 2013/03/05 02:40:13 Done.
25 socket_->Send(&index, sizeof(index));
26 if (++current_buffer_id_ >= shared_memory_->size())
27 current_buffer_id_ = 0;
23 } 28 }
24 29
25 uint32 AudioInputSyncWriter::Write(const void* data, uint32 size, 30 uint32 AudioInputSyncWriter::Write(const void* data, uint32 size,
26 double volume) { 31 double volume) {
27 media::AudioInputBuffer* buffer = 32 media::AudioInputBuffer* buffer = reinterpret_cast<media::AudioInputBuffer*>(
28 reinterpret_cast<media::AudioInputBuffer*>(shared_memory_->memory()); 33 (*shared_memory_)[current_buffer_id_]->memory());
29 buffer->params.volume = volume; 34 buffer->params.volume = volume;
30 buffer->params.size = size; 35 buffer->params.size = size;
31 memcpy(buffer->audio, data, size); 36 memcpy(buffer->audio, data, size);
32 37
33 return size; 38 return size;
34 } 39 }
35 40
36 void AudioInputSyncWriter::Close() { 41 void AudioInputSyncWriter::Close() {
37 socket_->Close(); 42 socket_->Close();
38 } 43 }
(...skipping 22 matching lines...) Expand all
61 base::ProcessHandle process_handle, 66 base::ProcessHandle process_handle,
62 base::FileDescriptor* foreign_handle) { 67 base::FileDescriptor* foreign_handle) {
63 foreign_handle->fd = foreign_socket_->handle(); 68 foreign_handle->fd = foreign_socket_->handle();
64 foreign_handle->auto_close = false; 69 foreign_handle->auto_close = false;
65 return (foreign_handle->fd != -1); 70 return (foreign_handle->fd != -1);
66 } 71 }
67 72
68 #endif 73 #endif
69 74
70 } // namespace content 75 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698