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

Unified Diff: content/browser/renderer_host/media/audio_input_renderer_host.cc

Issue 12440027: Do not pass the string device_id via IPC message to create an audio input stream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready for review Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/audio_input_renderer_host.cc
diff --git a/content/browser/renderer_host/media/audio_input_renderer_host.cc b/content/browser/renderer_host/media/audio_input_renderer_host.cc
index f83d19aacb8df035e4523e8fec60313f309bd758..2b3416133f800d682d6645021ea8055e27f0c034 100644
--- a/content/browser/renderer_host/media/audio_input_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_input_renderer_host.cc
@@ -14,6 +14,7 @@
#include "content/browser/renderer_host/media/web_contents_audio_input_stream.h"
#include "content/browser/renderer_host/media/web_contents_capture_util.h"
#include "content/common/media/audio_messages.h"
+#include "media/audio/audio_manager_base.h"
namespace content {
@@ -183,7 +184,6 @@ bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok)
- IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice)
IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream)
IPC_MESSAGE_HANDLER(AudioInputHostMsg_AssociateStreamWithConsumer,
OnAssociateStreamWithConsumer)
@@ -196,23 +196,11 @@ bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message,
return handled;
}
-void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
- VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
- << stream_id << ", session_id = " << session_id << ")";
-
- // Add the session entry to the map.
- session_entries_[session_id] = stream_id;
-
- // Start the device with the session_id. If the device is started
- // successfully, OnDeviceStarted() callback will be triggered.
- media_stream_manager_->audio_input_device_manager()->Start(session_id, this);
-}
-
void AudioInputRendererHost::OnCreateStream(
- int stream_id, const media::AudioParameters& params,
- const std::string& device_id, bool automatic_gain_control) {
+ int stream_id, int session_id, const media::AudioParameters& params,
+ bool automatic_gain_control) {
VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
- << stream_id << ")";
+ << stream_id << ", session_id=" << session_id << ")";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// media::AudioParameters is validated in the deserializer.
if (LookupById(stream_id) != NULL) {
@@ -220,8 +208,23 @@ void AudioInputRendererHost::OnCreateStream(
return;
}
- media::AudioParameters audio_params(params);
+ // Check if we have the permission to open the device and which device to use.
+ std::string device_id = media::AudioManagerBase::kDefaultDeviceId;
+ if (session_id != AudioInputDeviceManager::kFakeOpenSessionId) {
palmer 2013/03/12 17:45:11 NIT: Two spaces after the "!=". Just use one.
no longer working on chromium 2013/03/14 10:47:32 Done.
+ const StreamDeviceInfo& info = media_stream_manager_->
+ audio_input_device_manager()->GetOpenedDeviceInfoById(session_id);
+ if (info.device.id.empty()) {
+ // An empty device info indicates that no permission has been granted .
palmer 2013/03/12 17:45:11 NIT: Space before period.
no longer working on chromium 2013/03/14 10:47:32 Done.
+ SendErrorMessage(stream_id);
+ DLOG(WARNING) << "No permission has been granted to input stream with "
+ << "session_id=" << session_id;
+ return;
+ }
+
+ device_id = info.device.id;
+ }
+ media::AudioParameters audio_params(params);
if (media_stream_manager_->audio_input_device_manager()->
ShouldUseFakeDevice()) {
audio_params.Reset(media::AudioParameters::AUDIO_FAKE,
@@ -318,11 +321,6 @@ void AudioInputRendererHost::OnCloseStream(int stream_id) {
if (entry)
CloseAndDeleteStream(entry);
-
- int session_id = LookupSessionById(stream_id);
-
- if (session_id)
- StopAndDeleteDevice(session_id);
}
void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) {
@@ -351,52 +349,6 @@ void AudioInputRendererHost::DeleteEntries() {
}
}
-void AudioInputRendererHost::OnDeviceStarted(
- int session_id, const std::string& device_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- SessionEntryMap::iterator it = session_entries_.find(session_id);
- if (it == session_entries_.end()) {
- DLOG(WARNING) << "AudioInputRendererHost::OnDeviceStarted()"
- " session does not exist.";
- return;
- }
-
- // Notify the renderer with the id of the opened device.
- Send(new AudioInputMsg_NotifyDeviceStarted(it->second, device_id));
-}
-
-void AudioInputRendererHost::OnDeviceStopped(int session_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- SessionEntryMap::iterator it = session_entries_.find(session_id);
- // Return if the stream has been closed.
- if (it == session_entries_.end())
- return;
-
- int stream_id = it->second;
- AudioEntry* entry = LookupById(stream_id);
-
- if (entry) {
- // Device has been stopped, close the input stream.
- CloseAndDeleteStream(entry);
- // Notify the renderer that the state of the input stream has changed.
- Send(new AudioInputMsg_NotifyStreamStateChanged(
- stream_id, media::AudioInputIPCDelegate::kStopped));
- }
-
- // Delete the session entry.
- session_entries_.erase(it);
-}
-
-void AudioInputRendererHost::StopAndDeleteDevice(int session_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- media_stream_manager_->audio_input_device_manager()->Stop(session_id);
-
- // Delete the session entry.
- session_entries_.erase(session_id);
-}
-
void AudioInputRendererHost::CloseAndDeleteStream(AudioEntry* entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -450,16 +402,4 @@ AudioInputRendererHost::AudioEntry* AudioInputRendererHost::LookupByController(
return NULL;
}
-int AudioInputRendererHost::LookupSessionById(int stream_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- for (SessionEntryMap::iterator it = session_entries_.begin();
- it != session_entries_.end(); ++it) {
- if (stream_id == it->second) {
- return it->first;
- }
- }
- return 0;
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698