| 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_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/process.h" | 9 #include "base/process.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 AudioInputRendererHost::AudioEntry::AudioEntry() | 39 AudioInputRendererHost::AudioEntry::AudioEntry() |
| 40 : stream_id(0), | 40 : stream_id(0), |
| 41 pending_close(false) { | 41 pending_close(false) { |
| 42 } | 42 } |
| 43 | 43 |
| 44 AudioInputRendererHost::AudioEntry::~AudioEntry() {} | 44 AudioInputRendererHost::AudioEntry::~AudioEntry() {} |
| 45 | 45 |
| 46 AudioInputRendererHost::AudioInputRendererHost( | 46 AudioInputRendererHost::AudioInputRendererHost( |
| 47 media::AudioManager* audio_manager, | 47 media::AudioManager* audio_manager, |
| 48 media_stream::MediaStreamManager* media_stream_manager) | 48 MediaStreamManager* media_stream_manager) |
| 49 : audio_manager_(audio_manager), | 49 : audio_manager_(audio_manager), |
| 50 media_stream_manager_(media_stream_manager) { | 50 media_stream_manager_(media_stream_manager) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 AudioInputRendererHost::~AudioInputRendererHost() { | 53 AudioInputRendererHost::~AudioInputRendererHost() { |
| 54 DCHECK(audio_entries_.empty()); | 54 DCHECK(audio_entries_.empty()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AudioInputRendererHost::OnChannelClosing() { | 57 void AudioInputRendererHost::OnChannelClosing() { |
| 58 BrowserMessageFilter::OnChannelClosing(); | 58 BrowserMessageFilter::OnChannelClosing(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // mapping shared memory and sharing with the renderer process. | 127 // mapping shared memory and sharing with the renderer process. |
| 128 base::SharedMemoryHandle foreign_memory_handle; | 128 base::SharedMemoryHandle foreign_memory_handle; |
| 129 if (!entry->shared_memory.ShareToProcess(peer_handle(), | 129 if (!entry->shared_memory.ShareToProcess(peer_handle(), |
| 130 &foreign_memory_handle)) { | 130 &foreign_memory_handle)) { |
| 131 // If we failed to map and share the shared memory then close the audio | 131 // If we failed to map and share the shared memory then close the audio |
| 132 // stream and send an error message. | 132 // stream and send an error message. |
| 133 DeleteEntryOnError(entry); | 133 DeleteEntryOnError(entry); |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 | 136 |
| 137 media::AudioInputSyncWriter* writer = | 137 AudioInputSyncWriter* writer = |
| 138 static_cast<media::AudioInputSyncWriter*>(entry->writer.get()); | 138 static_cast<AudioInputSyncWriter*>(entry->writer.get()); |
| 139 | 139 |
| 140 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 141 base::SyncSocket::Handle foreign_socket_handle; | 141 base::SyncSocket::Handle foreign_socket_handle; |
| 142 #else | 142 #else |
| 143 base::FileDescriptor foreign_socket_handle; | 143 base::FileDescriptor foreign_socket_handle; |
| 144 #endif | 144 #endif |
| 145 | 145 |
| 146 // If we failed to prepare the sync socket for the renderer then we fail | 146 // If we failed to prepare the sync socket for the renderer then we fail |
| 147 // the construction of audio input stream. | 147 // the construction of audio input stream. |
| 148 if (!writer->PrepareForeignSocketHandle(peer_handle(), | 148 if (!writer->PrepareForeignSocketHandle(peer_handle(), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; | 222 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; |
| 223 | 223 |
| 224 // Create the shared memory and share it with the renderer process | 224 // Create the shared memory and share it with the renderer process |
| 225 // using a new SyncWriter object. | 225 // using a new SyncWriter object. |
| 226 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { | 226 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { |
| 227 // If creation of shared memory failed then send an error message. | 227 // If creation of shared memory failed then send an error message. |
| 228 SendErrorMessage(stream_id); | 228 SendErrorMessage(stream_id); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 scoped_ptr<media::AudioInputSyncWriter> writer( | 232 scoped_ptr<AudioInputSyncWriter> writer( |
| 233 new media::AudioInputSyncWriter(&entry->shared_memory)); | 233 new AudioInputSyncWriter(&entry->shared_memory)); |
| 234 | 234 |
| 235 if (!writer->Init()) { | 235 if (!writer->Init()) { |
| 236 SendErrorMessage(stream_id); | 236 SendErrorMessage(stream_id); |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // If we have successfully created the SyncWriter then assign it to the | 240 // If we have successfully created the SyncWriter then assign it to the |
| 241 // entry and construct an AudioInputController. | 241 // entry and construct an AudioInputController. |
| 242 // TODO(henrika): replace CreateLowLatency() with Create() as soon | 242 // TODO(henrika): replace CreateLowLatency() with Create() as soon |
| 243 // as satish has ensured that Speech Input also uses the default low- | 243 // as satish has ensured that Speech Input also uses the default low- |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 for (SessionEntryMap::iterator it = session_entries_.begin(); | 422 for (SessionEntryMap::iterator it = session_entries_.begin(); |
| 423 it != session_entries_.end(); ++it) { | 423 it != session_entries_.end(); ++it) { |
| 424 if (stream_id == it->second) { | 424 if (stream_id == it->second) { |
| 425 return it->first; | 425 return it->first; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 return 0; | 428 return 0; |
| 429 } | 429 } |
| 430 | 430 |
| 431 } // namespace content | 431 } // namespace content |
| OLD | NEW |