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

Side by Side Diff: content/browser/renderer_host/media/audio_input_renderer_host.cc

Issue 9433006: Remove GetAudioManager and GetMediaStreamManager from ResourceContext. The reason is the content mo… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 10 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_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"
11 #include "content/browser/renderer_host/media/audio_common.h" 11 #include "content/browser/renderer_host/media/audio_common.h"
12 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 12 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
13 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 13 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h" 14 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/common/media/audio_messages.h" 15 #include "content/common/media/audio_messages.h"
16 #include "content/public/browser/resource_context.h"
17 16
18 using content::BrowserMessageFilter; 17 using content::BrowserMessageFilter;
19 using content::BrowserThread; 18 using content::BrowserThread;
20 19
21 AudioInputRendererHost::AudioEntry::AudioEntry() 20 AudioInputRendererHost::AudioEntry::AudioEntry()
22 : stream_id(0), 21 : stream_id(0),
23 pending_close(false) { 22 pending_close(false) {
24 } 23 }
25 24
26 AudioInputRendererHost::AudioEntry::~AudioEntry() {} 25 AudioInputRendererHost::AudioEntry::~AudioEntry() {}
27 26
28 AudioInputRendererHost::AudioInputRendererHost( 27 AudioInputRendererHost::AudioInputRendererHost(
29 content::ResourceContext* resource_context) 28 content::ResourceContext* resource_context,
30 : resource_context_(resource_context) { 29 AudioManager* audio_manager)
30 : resource_context_(resource_context),
31 audio_manager_(audio_manager) {
31 } 32 }
32 33
33 AudioInputRendererHost::~AudioInputRendererHost() { 34 AudioInputRendererHost::~AudioInputRendererHost() {
34 DCHECK(audio_entries_.empty()); 35 DCHECK(audio_entries_.empty());
35 } 36 }
36 37
37 void AudioInputRendererHost::OnChannelClosing() { 38 void AudioInputRendererHost::OnChannelClosing() {
38 BrowserMessageFilter::OnChannelClosing(); 39 BrowserMessageFilter::OnChannelClosing();
39 40
40 // Since the IPC channel is gone, close all requested audio streams. 41 // Since the IPC channel is gone, close all requested audio streams.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 IPC_END_MESSAGE_MAP_EX() 181 IPC_END_MESSAGE_MAP_EX()
181 182
182 return handled; 183 return handled;
183 } 184 }
184 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { 185 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
185 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" 186 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
186 << stream_id << ", session_id = " << session_id << ")"; 187 << stream_id << ", session_id = " << session_id << ")";
187 188
188 // Get access to the AudioInputDeviceManager to start the device. 189 // Get access to the AudioInputDeviceManager to start the device.
189 media_stream::AudioInputDeviceManager* audio_input_man = 190 media_stream::AudioInputDeviceManager* audio_input_man =
190 resource_context_->GetMediaStreamManager()->audio_input_device_manager(); 191 media_stream::MediaStreamManager::GetForResourceContext(
192 resource_context_, audio_manager_)->audio_input_device_manager();
191 193
192 // Add the session entry to the map. 194 // Add the session entry to the map.
193 session_entries_[session_id] = stream_id; 195 session_entries_[session_id] = stream_id;
194 196
195 // Start the device with the session_id. If the device is started 197 // Start the device with the session_id. If the device is started
196 // successfully, OnDeviceStarted() callback will be triggered. 198 // successfully, OnDeviceStarted() callback will be triggered.
197 audio_input_man->Start(session_id, this); 199 audio_input_man->Start(session_id, this);
198 } 200 }
199 201
200 void AudioInputRendererHost::OnCreateStream(int stream_id, 202 void AudioInputRendererHost::OnCreateStream(int stream_id,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return; 234 return;
233 } 235 }
234 236
235 // If we have successfully created the SyncWriter then assign it to the 237 // If we have successfully created the SyncWriter then assign it to the
236 // entry and construct an AudioInputController. 238 // entry and construct an AudioInputController.
237 // TODO(henrika): replace CreateLowLatency() with Create() as soon 239 // TODO(henrika): replace CreateLowLatency() with Create() as soon
238 // as satish has ensured that Speech Input also uses the default low- 240 // as satish has ensured that Speech Input also uses the default low-
239 // latency path. See crbug.com/112472 for details. 241 // latency path. See crbug.com/112472 for details.
240 entry->writer.reset(writer.release()); 242 entry->writer.reset(writer.release());
241 entry->controller = media::AudioInputController::CreateLowLatency( 243 entry->controller = media::AudioInputController::CreateLowLatency(
242 resource_context_->GetAudioManager(), 244 audio_manager_,
243 this, 245 this,
244 audio_params, 246 audio_params,
245 device_id, 247 device_id,
246 entry->writer.get()); 248 entry->writer.get());
247 249
248 if (!entry->controller) { 250 if (!entry->controller) {
249 SendErrorMessage(stream_id); 251 SendErrorMessage(stream_id);
250 return; 252 return;
251 } 253 }
252 254
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 359 }
358 360
359 // Delete the session entry. 361 // Delete the session entry.
360 session_entries_.erase(it); 362 session_entries_.erase(it);
361 } 363 }
362 364
363 void AudioInputRendererHost::StopAndDeleteDevice(int session_id) { 365 void AudioInputRendererHost::StopAndDeleteDevice(int session_id) {
364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
365 367
366 media_stream::AudioInputDeviceManager* audio_input_man = 368 media_stream::AudioInputDeviceManager* audio_input_man =
367 resource_context_->GetMediaStreamManager()->audio_input_device_manager(); 369 media_stream::MediaStreamManager::GetForResourceContext(
370 resource_context_, audio_manager_)->audio_input_device_manager();
368 audio_input_man->Stop(session_id); 371 audio_input_man->Stop(session_id);
369 372
370 // Delete the session entry. 373 // Delete the session entry.
371 session_entries_.erase(session_id); 374 session_entries_.erase(session_id);
372 } 375 }
373 376
374 void AudioInputRendererHost::CloseAndDeleteStream(AudioEntry* entry) { 377 void AudioInputRendererHost::CloseAndDeleteStream(AudioEntry* entry) {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
376 379
377 if (!entry->pending_close) { 380 if (!entry->pending_close) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
439 442
440 for (SessionEntryMap::iterator it = session_entries_.begin(); 443 for (SessionEntryMap::iterator it = session_entries_.begin();
441 it != session_entries_.end(); ++it) { 444 it != session_entries_.end(); ++it) {
442 if (stream_id == it->second) { 445 if (stream_id == it->second) {
443 return it->first; 446 return it->first;
444 } 447 }
445 } 448 }
446 return 0; 449 return 0;
447 } 450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698