| OLD | NEW |
| 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" |
| (...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 socket_.reset(new base::SyncSocket()); | 34 socket_.reset(new base::CancelableSyncSocket()); |
| 35 foreign_socket_.reset(new base::SyncSocket()); | 35 foreign_socket_.reset(new base::CancelableSyncSocket()); |
| 36 return base::SyncSocket::CreatePair(socket_.get(), foreign_socket_.get()); | 36 return base::CancelableSyncSocket::CreatePair(socket_.get(), |
| 37 foreign_socket_.get()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 40 | 41 |
| 41 bool AudioInputSyncWriter::PrepareForeignSocketHandle( | 42 bool AudioInputSyncWriter::PrepareForeignSocketHandle( |
| 42 base::ProcessHandle process_handle, | 43 base::ProcessHandle process_handle, |
| 43 base::SyncSocket::Handle* foreign_handle) { | 44 base::SyncSocket::Handle* foreign_handle) { |
| 44 ::DuplicateHandle(GetCurrentProcess(), foreign_socket_->handle(), | 45 ::DuplicateHandle(GetCurrentProcess(), foreign_socket_->handle(), |
| 45 process_handle, foreign_handle, | 46 process_handle, foreign_handle, |
| 46 0, FALSE, DUPLICATE_SAME_ACCESS); | 47 0, FALSE, DUPLICATE_SAME_ACCESS); |
| 47 return (*foreign_handle != 0); | 48 return (*foreign_handle != 0); |
| 48 } | 49 } |
| 49 | 50 |
| 50 #else | 51 #else |
| 51 | 52 |
| 52 bool AudioInputSyncWriter::PrepareForeignSocketHandle( | 53 bool AudioInputSyncWriter::PrepareForeignSocketHandle( |
| 53 base::ProcessHandle process_handle, | 54 base::ProcessHandle process_handle, |
| 54 base::FileDescriptor* foreign_handle) { | 55 base::FileDescriptor* foreign_handle) { |
| 55 foreign_handle->fd = foreign_socket_->handle(); | 56 foreign_handle->fd = foreign_socket_->handle(); |
| 56 foreign_handle->auto_close = false; | 57 foreign_handle->auto_close = false; |
| 57 return (foreign_handle->fd != -1); | 58 return (foreign_handle->fd != -1); |
| 58 } | 59 } |
| 59 | 60 |
| 60 #endif | 61 #endif |
| OLD | NEW |