OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // Copy audio input samples from recorded data to shared memory. | 24 // Copy audio input samples from recorded data to shared memory. |
25 memcpy(shared_memory_->memory(), data, write_size); | 25 memcpy(shared_memory_->memory(), data, write_size); |
26 return write_size; | 26 return write_size; |
27 } | 27 } |
28 | 28 |
29 void AudioInputSyncWriter::Close() { | 29 void AudioInputSyncWriter::Close() { |
30 socket_->Close(); | 30 socket_->Close(); |
31 } | 31 } |
32 | 32 |
33 bool AudioInputSyncWriter::Init() { | 33 bool AudioInputSyncWriter::Init() { |
34 base::SyncSocket* sockets[2] = {0}; | 34 socket_.reset(new base::SyncSocket()); |
35 if (base::SyncSocket::CreatePair(sockets)) { | 35 foreign_socket_.reset(new base::SyncSocket()); |
36 socket_.reset(sockets[0]); | 36 return base::SyncSocket::CreatePair(socket_.get(), foreign_socket_.get()); |
37 foreign_socket_.reset(sockets[1]); | |
38 return true; | |
39 } | |
40 return false; | |
41 } | 37 } |
42 | 38 |
43 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
44 | 40 |
45 bool AudioInputSyncWriter::PrepareForeignSocketHandle( | 41 bool AudioInputSyncWriter::PrepareForeignSocketHandle( |
46 base::ProcessHandle process_handle, | 42 base::ProcessHandle process_handle, |
47 base::SyncSocket::Handle* foreign_handle) { | 43 base::SyncSocket::Handle* foreign_handle) { |
48 ::DuplicateHandle(GetCurrentProcess(), foreign_socket_->handle(), | 44 ::DuplicateHandle(GetCurrentProcess(), foreign_socket_->handle(), |
49 process_handle, foreign_handle, | 45 process_handle, foreign_handle, |
50 0, FALSE, DUPLICATE_SAME_ACCESS); | 46 0, FALSE, DUPLICATE_SAME_ACCESS); |
51 return (*foreign_handle != 0); | 47 return (*foreign_handle != 0); |
52 } | 48 } |
53 | 49 |
54 #else | 50 #else |
55 | 51 |
56 bool AudioInputSyncWriter::PrepareForeignSocketHandle( | 52 bool AudioInputSyncWriter::PrepareForeignSocketHandle( |
57 base::ProcessHandle process_handle, | 53 base::ProcessHandle process_handle, |
58 base::FileDescriptor* foreign_handle) { | 54 base::FileDescriptor* foreign_handle) { |
59 foreign_handle->fd = foreign_socket_->handle(); | 55 foreign_handle->fd = foreign_socket_->handle(); |
60 foreign_handle->auto_close = false; | 56 foreign_handle->auto_close = false; |
61 return (foreign_handle->fd != -1); | 57 return (foreign_handle->fd != -1); |
62 } | 58 } |
63 | 59 |
64 #endif | 60 #endif |
OLD | NEW |