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

Unified Diff: content/renderer/media/media_stream_dependency_factory.cc

Issue 11783059: Ensures that WebRTC works for device selection using a different sample rate than default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes include order Created 7 years, 11 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/renderer/media/media_stream_dependency_factory.cc
diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc
index 69a35727ac7c413317e4292452788668680f0e03..7512cce0caff59ba1a22375bc147c1f9fd37d36a 100644
--- a/content/renderer/media/media_stream_dependency_factory.cc
+++ b/content/renderer/media/media_stream_dependency_factory.cc
@@ -190,6 +190,7 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources(
const WebKit::WebMediaConstraints& video_constraints,
WebKit::WebMediaStreamDescriptor* description,
const MediaSourcesCreatedCallback& sources_created) {
+ DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeMediaSources()";
if (!EnsurePeerConnectionFactory()) {
sources_created.Run(description, false);
return;
@@ -223,11 +224,59 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources(
&native_video_constraints));
source_observer->AddSource(source_data->video_source());
}
+
+ // Do additional source initialization if the audio source is a valid
+ // microphone.
+ WebKit::WebVector<WebKit::WebMediaStreamComponent> audio_components;
+ description->audioSources(audio_components);
+ for (size_t i = 0; i < audio_components.size(); ++i) {
+ const WebKit::WebMediaStreamSource& source = audio_components[i].source();
+ MediaStreamSourceExtraData* source_data =
+ static_cast<MediaStreamSourceExtraData*>(source.extraData());
perkj_chrome 2013/01/15 09:00:19 Will WebAudio also end up here? Fix comment in tha
henrika (OOO until Aug 14) 2013/01/16 16:49:00 Do you mean for the MediaStreamDestination case (n
+ if (!source_data) {
+ // TODO(henrika): Implement support for sources from remote MediaStreams.
+ NOTIMPLEMENTED();
+ continue;
+ }
+
+ const MediaStreamDevice device = source_data->device_info().device;
+ if (device.type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
+ // Initialize the source using audio parameters for the selected
+ // capture device.
+ WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer();
+ // TODO(henrika): refactor \content\public\common\media_stream_request.h
+ // to allow dependency of media::ChannelLayout and avoid static_cast.
+ if (!capturer->Initialize(
+ static_cast<media::ChannelLayout>(device.channel_layout),
+ device.sample_rate)) {
+ // The capturer does not support all possible sample rates.
perkj_chrome 2013/01/15 09:00:19 nit: all possible ? I don't understand the comment
henrika (OOO until Aug 14) 2013/01/16 16:49:00 Refactored + fixed.
+ sources_created.Run(description, false);
+ return;
+ }
+
+ // Specify which capture device to use. The acquired session id is used
+ // for identification.
+ // TODO(henrika): the current design does not support a uniqe source
+ // for each audio track.
+ if (source_data->device_info().session_id <= 0) {
+ LOG(ERROR) << "Invalid audio session id";
+ sources_created.Run(description, false);
+ return;
+ }
+ capturer->SetDevice(source_data->device_info().session_id);
+ } else {
+ DLOG(WARNING) << "Unsupported audio source";
perkj_chrome 2013/01/15 09:00:19 nit: NOTREACHED ?
henrika (OOO until Aug 14) 2013/01/16 16:49:00 See if you like new proposal better.
+ sources_created.Run(description, false);
+ return;
+ }
+ }
+
source_observer->StartObservering();
}
void MediaStreamDependencyFactory::CreateNativeLocalMediaStream(
WebKit::WebMediaStreamDescriptor* description) {
+ DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()";
DCHECK(PeerConnectionFactoryCreated());
std::string label = UTF16ToUTF8(description->label());
@@ -253,10 +302,6 @@ void MediaStreamDependencyFactory::CreateNativeLocalMediaStream(
CreateLocalAudioTrack(UTF16ToUTF8(source.id()), NULL));
native_stream->AddTrack(audio_track);
audio_track->set_enabled(audio_components[i].isEnabled());
- // TODO(xians): This set the source of all audio tracks to the same
- // microphone. Implement support for setting the source per audio track
- // instead.
- SetAudioDeviceSessionId(source_data->device_info().session_id);
}
// Add video tracks.
@@ -295,6 +340,7 @@ void MediaStreamDependencyFactory::CreateNativeLocalMediaStream(
}
bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() {
+ DVLOG(1) << "MediaStreamDependencyFactory::CreatePeerConnectionFactory()";
if (!pc_factory_.get()) {
DCHECK(!audio_device_);
audio_device_ = new WebRtcAudioDeviceImpl();
@@ -389,10 +435,6 @@ MediaStreamDependencyFactory::GetWebRtcAudioDevice() {
return audio_device_;
}
-void MediaStreamDependencyFactory::SetAudioDeviceSessionId(int session_id) {
- audio_device_->SetSessionId(session_id);
-}
-
void MediaStreamDependencyFactory::InitializeWorkerThread(
talk_base::Thread** thread,
base::WaitableEvent* event) {

Powered by Google App Engine
This is Rietveld 408576698