Chromium Code Reviews| 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_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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 std::string input_device_id, output_device_id; |
|
Jói
2013/09/06 14:49:26
output_device_id will be empty if there is no info
tommi (sloooow) - chröme
2013/09/06 16:56:54
Yes, that's intentional. Added comments to explain
| |
| 308 const StreamDeviceInfo* info = media_stream_manager_-> | |
| 309 audio_input_device_manager()->GetOpenedDeviceInfoById(session_id); | |
| 310 if (info) | |
| 311 output_device_id = info->device.matched_output_device_id; | |
| 312 | |
| 307 if (input_channels > 0) { | 313 if (input_channels > 0) { |
| 308 const StreamDeviceInfo* info = media_stream_manager_-> | |
| 309 audio_input_device_manager()->GetOpenedDeviceInfoById(session_id); | |
| 310 if (!info) { | 314 if (!info) { |
| 311 SendErrorMessage(stream_id); | 315 SendErrorMessage(stream_id); |
| 312 DLOG(WARNING) << "No permission has been granted to input stream with " | 316 DLOG(WARNING) << "No permission has been granted to input stream with " |
| 313 << "session_id=" << session_id; | 317 << "session_id=" << session_id; |
| 314 return; | 318 return; |
| 315 } | 319 } |
| 316 | 320 |
| 317 input_device_id = info->device.id; | 321 input_device_id = info->device.id; |
| 318 } | 322 } |
| 319 | 323 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 341 SendErrorMessage(stream_id); | 345 SendErrorMessage(stream_id); |
| 342 return; | 346 return; |
| 343 } | 347 } |
| 344 | 348 |
| 345 MediaObserver* const media_observer = | 349 MediaObserver* const media_observer = |
| 346 GetContentClient()->browser()->GetMediaObserver(); | 350 GetContentClient()->browser()->GetMediaObserver(); |
| 347 if (media_observer) | 351 if (media_observer) |
| 348 media_observer->OnCreatingAudioStream(render_process_id_, render_view_id); | 352 media_observer->OnCreatingAudioStream(render_process_id_, render_view_id); |
| 349 | 353 |
| 350 scoped_ptr<AudioEntry> entry(new AudioEntry( | 354 scoped_ptr<AudioEntry> entry(new AudioEntry( |
| 351 this, stream_id, render_view_id, params, input_device_id, | 355 this, stream_id, render_view_id, params, output_device_id, |
| 352 shared_memory.Pass(), | 356 input_device_id, shared_memory.Pass(), |
| 353 reader.PassAs<media::AudioOutputController::SyncReader>())); | 357 reader.PassAs<media::AudioOutputController::SyncReader>())); |
| 354 if (mirroring_manager_) { | 358 if (mirroring_manager_) { |
| 355 mirroring_manager_->AddDiverter( | 359 mirroring_manager_->AddDiverter( |
| 356 render_process_id_, entry->render_view_id(), entry->controller()); | 360 render_process_id_, entry->render_view_id(), entry->controller()); |
| 357 } | 361 } |
| 358 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 362 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
| 359 if (media_internals_) { | 363 if (media_internals_) { |
| 360 media_internals_->OnAudioStreamCreated( | 364 media_internals_->OnAudioStreamCreated( |
| 361 this, stream_id, params, input_device_id); | 365 this, stream_id, params, input_device_id); |
| 362 } | 366 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } | 476 } |
| 473 | 477 |
| 474 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 478 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 476 | 480 |
| 477 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 481 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
| 478 return i != audio_entries_.end() ? i->second : NULL; | 482 return i != audio_entries_.end() ? i->second : NULL; |
| 479 } | 483 } |
| 480 | 484 |
| 481 } // namespace content | 485 } // namespace content |
| OLD | NEW |