Chromium Code Reviews| Index: content/renderer/media/media_stream_impl.cc |
| diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc |
| index 9eab908f5f90e64927df8e065b0a605a71145c31..f1504cf2c9bbf84c767805c672df6e89f70659e8 100644 |
| --- a/content/renderer/media/media_stream_impl.cc |
| +++ b/content/renderer/media/media_stream_impl.cc |
| @@ -21,6 +21,8 @@ |
| #include "content/renderer/media/webrtc_audio_renderer.h" |
| #include "content/renderer/media/webrtc_local_audio_renderer.h" |
| #include "content/renderer/media/webrtc_uma_histograms.h" |
| +#include "content/renderer/render_thread_impl.h" |
| +#include "media/base/audio_hardware_config.h" |
| #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| @@ -592,7 +594,22 @@ scoped_refptr<WebRtcAudioRenderer> MediaStreamImpl::CreateRemoteAudioRenderer( |
| DVLOG(1) << "MediaStreamImpl::CreateRemoteAudioRenderer label:" |
| << stream->label(); |
| - return new WebRtcAudioRenderer(RenderViewObserver::routing_id()); |
| + int session_id = -1, sample_rate = 0, buffer_size = 0; |
| + if (!GetAuthorizedInputDeviceSessionIdForAudioRenderer(&session_id, |
| + &sample_rate, |
| + &buffer_size)) { |
| + // Fetch the default audio output hardware config. |
| + media::AudioHardwareConfig* hardware_config = |
| + RenderThreadImpl::current()->GetAudioHardwareConfig(); |
| + sample_rate = hardware_config->GetOutputSampleRate(); |
| + buffer_size = hardware_config->GetOutputBufferSize(); |
| + // Use session_id of 0 to indicate no association with the capture device |
|
Jói
2013/09/06 14:49:26
Above you use a guard of -1, which is correct?
tommi (sloooow) - chröme
2013/09/06 16:56:54
I changed it to 0 for consistency with what's used
|
| + // (i.e. use the default device). |
| + session_id = 0; |
| + } |
| + |
| + return new WebRtcAudioRenderer(RenderViewObserver::routing_id(), |
| + session_id, sample_rate, buffer_size); |
| } |
| scoped_refptr<WebRtcLocalAudioRenderer> |
| @@ -611,11 +628,28 @@ MediaStreamImpl::CreateLocalAudioRenderer( |
| << "audio_track.id : " << audio_track->id() |
| << "audio_track.enabled: " << audio_track->enabled(); |
| + int session_id = -1, sample_rate = 0, buffer_size = 0; |
|
Jói
2013/09/06 14:49:26
Same code, DRY.
tommi (sloooow) - chröme
2013/09/06 16:56:54
Done.
|
| + if (!GetAuthorizedInputDeviceSessionIdForAudioRenderer(&session_id, |
| + &sample_rate, |
| + &buffer_size)) { |
| + // Fetch the default audio output hardware config. |
| + media::AudioHardwareConfig* hardware_config = |
| + RenderThreadImpl::current()->GetAudioHardwareConfig(); |
| + sample_rate = hardware_config->GetOutputSampleRate(); |
| + buffer_size = hardware_config->GetOutputBufferSize(); |
| + // Use session_id of 0 to indicate no association with the capture device |
| + // (i.e. use the default device). |
| + session_id = 0; |
| + } |
| + |
| // Create a new WebRtcLocalAudioRenderer instance and connect it to the |
| // existing WebRtcAudioCapturer so that the renderer can use it as source. |
| return new WebRtcLocalAudioRenderer( |
| static_cast<WebRtcLocalAudioTrack*>(audio_track), |
| - RenderViewObserver::routing_id()); |
| + RenderViewObserver::routing_id(), |
| + session_id, |
| + sample_rate, |
| + buffer_size); |
| } |
| void MediaStreamImpl::StopLocalAudioTrack( |
| @@ -639,6 +673,47 @@ void MediaStreamImpl::StopLocalAudioTrack( |
| } |
| } |
| +bool MediaStreamImpl::GetAuthorizedInputDeviceSessionIdForAudioRenderer( |
|
no longer working on chromium
2013/09/06 15:17:37
The name does not completely fit to its functional
tommi (sloooow) - chröme
2013/09/06 16:56:54
Done (fixed typo).
|
| + int* session_id, |
| + int* output_sample_rate, |
| + int* output_frames_per_buffer) { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + const StreamDeviceInfo* device_info = NULL; |
| + WebKit::WebString device_id; |
| + UserMediaRequests::iterator it = user_media_requests_.begin(); |
| + for (; it != user_media_requests_.end(); ++it) { |
| + UserMediaRequestInfo* request = (*it); |
| + for (size_t i = 0; i < request->audio_sources.size(); ++i) { |
| + const WebKit::WebMediaStreamSource& source = request->audio_sources[i]; |
| + if (source.readyState() == WebKit::WebMediaStreamSource::ReadyStateEnded) |
| + continue; |
| + |
| + if (!device_id.isEmpty() && !device_id.equals(source.deviceId())) { |
| + DLOG(WARNING) |
|
Jói
2013/09/06 14:49:26
Not sure this is "bad" enough to demand a warning;
tommi (sloooow) - chröme
2013/09/06 16:56:54
Yeah, that's why I picked DLOG so that while debug
|
| + << "Multiple capture devices are open so we can't pick a " |
| + "session for a matching output device."; |
| + return false; |
| + } |
| + |
| + device_id = source.deviceId(); |
|
no longer working on chromium
2013/09/06 15:17:37
this should be the session_id
tommi (sloooow) - chröme
2013/09/06 16:56:54
Renamed the variable. Also added a todo to store
|
| + content::MediaStreamSourceExtraData* extra_data = |
| + static_cast<content::MediaStreamSourceExtraData*>(source.extraData()); |
| + device_info = &extra_data->device_info(); |
| + } |
| + } |
| + |
| + if (device_id.isEmpty() || !device_info) |
| + return false; |
| + |
| + base::StringToInt(UTF16ToUTF8(device_id), session_id); |
| + *output_sample_rate = device_info->device.matched_output.sample_rate; |
| + *output_frames_per_buffer = |
| + device_info->device.matched_output.frames_per_buffer; |
| + |
| + return true; |
| +} |
| + |
| MediaStreamSourceExtraData::MediaStreamSourceExtraData( |
| const StreamDeviceInfo& device_info, |
| const WebKit::WebMediaStreamSource& webkit_source) |