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

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

Issue 23731007: Implicit audio output device selection for getUserMedia. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 3 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
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_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_renderer_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 18 matching lines...) Expand all
29 29
30 namespace content { 30 namespace content {
31 31
32 class AudioRendererHost::AudioEntry 32 class AudioRendererHost::AudioEntry
33 : public media::AudioOutputController::EventHandler { 33 : public media::AudioOutputController::EventHandler {
34 public: 34 public:
35 AudioEntry(AudioRendererHost* host, 35 AudioEntry(AudioRendererHost* host,
36 int stream_id, 36 int stream_id,
37 int render_view_id, 37 int render_view_id,
38 const media::AudioParameters& params, 38 const media::AudioParameters& params,
39 const std::string& output_device_id,
39 const std::string& input_device_id, 40 const std::string& input_device_id,
40 scoped_ptr<base::SharedMemory> shared_memory, 41 scoped_ptr<base::SharedMemory> shared_memory,
41 scoped_ptr<media::AudioOutputController::SyncReader> reader); 42 scoped_ptr<media::AudioOutputController::SyncReader> reader);
42 virtual ~AudioEntry(); 43 virtual ~AudioEntry();
43 44
44 int stream_id() const { 45 int stream_id() const {
45 return stream_id_; 46 return stream_id_;
46 } 47 }
47 48
48 int render_view_id() const { 49 int render_view_id() const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Shared memory for transmission of the audio data. 82 // Shared memory for transmission of the audio data.
82 const scoped_ptr<base::SharedMemory> shared_memory_; 83 const scoped_ptr<base::SharedMemory> shared_memory_;
83 84
84 // The synchronous reader to be used by the controller. 85 // The synchronous reader to be used by the controller.
85 const scoped_ptr<media::AudioOutputController::SyncReader> reader_; 86 const scoped_ptr<media::AudioOutputController::SyncReader> reader_;
86 }; 87 };
87 88
88 AudioRendererHost::AudioEntry::AudioEntry( 89 AudioRendererHost::AudioEntry::AudioEntry(
89 AudioRendererHost* host, int stream_id, int render_view_id, 90 AudioRendererHost* host, int stream_id, int render_view_id,
90 const media::AudioParameters& params, 91 const media::AudioParameters& params,
92 const std::string& output_device_id,
91 const std::string& input_device_id, 93 const std::string& input_device_id,
92 scoped_ptr<base::SharedMemory> shared_memory, 94 scoped_ptr<base::SharedMemory> shared_memory,
93 scoped_ptr<media::AudioOutputController::SyncReader> reader) 95 scoped_ptr<media::AudioOutputController::SyncReader> reader)
94 : host_(host), 96 : host_(host),
95 stream_id_(stream_id), 97 stream_id_(stream_id),
96 render_view_id_(render_view_id), 98 render_view_id_(render_view_id),
97 controller_(media::AudioOutputController::Create( 99 controller_(media::AudioOutputController::Create(
98 // TODO(tommi): Feed in the proper output device id. 100 host->audio_manager_, this, params, output_device_id,
99 host->audio_manager_, this, params, std::string(),
100 input_device_id, reader.get())), 101 input_device_id, reader.get())),
101 shared_memory_(shared_memory.Pass()), 102 shared_memory_(shared_memory.Pass()),
102 reader_(reader.Pass()) { 103 reader_(reader.Pass()) {
103 DCHECK(controller_.get()); 104 DCHECK(controller_.get());
104 } 105 }
105 106
106 AudioRendererHost::AudioEntry::~AudioEntry() {} 107 AudioRendererHost::AudioEntry::~AudioEntry() {}
107 108
108 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
109 // AudioRendererHost implementations. 110 // AudioRendererHost implementations.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 int input_channels = params.input_channels(); 297 int input_channels = params.input_channels();
297 if (input_channels < 0 || 298 if (input_channels < 0 ||
298 input_channels > media::limits::kMaxChannels || 299 input_channels > media::limits::kMaxChannels ||
299 LookupById(stream_id) != NULL) { 300 LookupById(stream_id) != NULL) {
300 SendErrorMessage(stream_id); 301 SendErrorMessage(stream_id);
301 return; 302 return;
302 } 303 }
303 304
304 // When the |input_channels| is valid, clients are trying to create a unified 305 // When the |input_channels| is valid, clients are trying to create a unified
305 // IO stream which opens an input device mapping to the |session_id|. 306 // IO stream which opens an input device mapping to the |session_id|.
306 std::string input_device_id; 307 // Initialize the |output_device_id| to an empty string which indicates that
308 // the default device should be used. If a StreamDeviceInfo instance was found
309 // though, then we use the matched output device.
310 std::string input_device_id, output_device_id;
311 const StreamDeviceInfo* info = media_stream_manager_->
312 audio_input_device_manager()->GetOpenedDeviceInfoById(session_id);
313 if (info)
314 output_device_id = info->device.matched_output_device_id;
315
307 if (input_channels > 0) { 316 if (input_channels > 0) {
308 const StreamDeviceInfo* info = media_stream_manager_->
309 audio_input_device_manager()->GetOpenedDeviceInfoById(session_id);
310 if (!info) { 317 if (!info) {
311 SendErrorMessage(stream_id); 318 SendErrorMessage(stream_id);
312 DLOG(WARNING) << "No permission has been granted to input stream with " 319 DLOG(WARNING) << "No permission has been granted to input stream with "
313 << "session_id=" << session_id; 320 << "session_id=" << session_id;
314 return; 321 return;
315 } 322 }
316 323
317 input_device_id = info->device.id; 324 input_device_id = info->device.id;
318 } 325 }
319 326
(...skipping 21 matching lines...) Expand all
341 SendErrorMessage(stream_id); 348 SendErrorMessage(stream_id);
342 return; 349 return;
343 } 350 }
344 351
345 MediaObserver* const media_observer = 352 MediaObserver* const media_observer =
346 GetContentClient()->browser()->GetMediaObserver(); 353 GetContentClient()->browser()->GetMediaObserver();
347 if (media_observer) 354 if (media_observer)
348 media_observer->OnCreatingAudioStream(render_process_id_, render_view_id); 355 media_observer->OnCreatingAudioStream(render_process_id_, render_view_id);
349 356
350 scoped_ptr<AudioEntry> entry(new AudioEntry( 357 scoped_ptr<AudioEntry> entry(new AudioEntry(
351 this, stream_id, render_view_id, params, input_device_id, 358 this, stream_id, render_view_id, params, output_device_id,
352 shared_memory.Pass(), 359 input_device_id, shared_memory.Pass(),
353 reader.PassAs<media::AudioOutputController::SyncReader>())); 360 reader.PassAs<media::AudioOutputController::SyncReader>()));
354 if (mirroring_manager_) { 361 if (mirroring_manager_) {
355 mirroring_manager_->AddDiverter( 362 mirroring_manager_->AddDiverter(
356 render_process_id_, entry->render_view_id(), entry->controller()); 363 render_process_id_, entry->render_view_id(), entry->controller());
357 } 364 }
358 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 365 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
359 if (media_internals_) { 366 if (media_internals_) {
360 media_internals_->OnAudioStreamCreated( 367 media_internals_->OnAudioStreamCreated(
361 this, stream_id, params, input_device_id); 368 this, stream_id, params, input_device_id);
362 } 369 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 479 }
473 480
474 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 481 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
476 483
477 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 484 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
478 return i != audio_entries_.end() ? i->second : NULL; 485 return i != audio_entries_.end() ? i->second : NULL;
479 } 486 }
480 487
481 } // namespace content 488 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698