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

Side by Side Diff: content/renderer/media/media_stream_dependency_factory.cc

Issue 133903004: Cleaned up the WebRtcAudioCapturer a bit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added a comment and content_browsertest Created 6 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 unified diff | Download patch | Annotate | Revision Log
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/renderer/media/media_stream_dependency_factory.h" 5 #include "content/renderer/media/media_stream_dependency_factory.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 constraints.AddMandatory(kConstraintEffectMap[i].constraint, 357 constraints.AddMandatory(kConstraintEffectMap[i].constraint,
358 webrtc::MediaConstraintsInterface::kValueFalse, true); 358 webrtc::MediaConstraintsInterface::kValueFalse, true);
359 DVLOG(1) << "Disabling platform effect: " 359 DVLOG(1) << "Disabling platform effect: "
360 << kConstraintEffectMap[i].constraint; 360 << kConstraintEffectMap[i].constraint;
361 } 361 }
362 } 362 }
363 device_info.device.input.effects = effects; 363 device_info.device.input.effects = effects;
364 } 364 }
365 365
366 scoped_refptr<WebRtcAudioCapturer> capturer( 366 scoped_refptr<WebRtcAudioCapturer> capturer(
367 MaybeCreateAudioCapturer(render_view_id, device_info)); 367 CreateAudioCapturer(render_view_id, device_info));
368 if (!capturer.get()) { 368 if (!capturer.get()) {
369 DLOG(WARNING) << "Failed to create the capturer for device " 369 DLOG(WARNING) << "Failed to create the capturer for device "
370 << device_info.device.id; 370 << device_info.device.id;
371 sources_created.Run(web_stream, false); 371 sources_created.Run(web_stream, false);
372 // TODO(xians): Don't we need to check if source_observer is observing 372 // TODO(xians): Don't we need to check if source_observer is observing
373 // something? If not, then it looks like we have a leak here. 373 // something? If not, then it looks like we have a leak here.
374 // OTOH, if it _is_ observing something, then the callback might 374 // OTOH, if it _is_ observing something, then the callback might
375 // be called multiple times which is likely also a bug. 375 // be called multiple times which is likely also a bug.
376 return; 376 return;
377 } 377 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 source_data = 452 source_data =
453 static_cast<MediaStreamSourceExtraData*>(source.extraData()); 453 static_cast<MediaStreamSourceExtraData*>(source.extraData());
454 } else { 454 } else {
455 // TODO(perkj): Implement support for sources from 455 // TODO(perkj): Implement support for sources from
456 // remote MediaStreams. 456 // remote MediaStreams.
457 NOTIMPLEMENTED(); 457 NOTIMPLEMENTED();
458 return NULL; 458 return NULL;
459 } 459 }
460 } 460 }
461 461
462 std::string track_id = base::UTF16ToUTF8(track.id());
463 scoped_refptr<WebRtcAudioCapturer> capturer;
464 if (GetWebRtcAudioDevice())
465 capturer = GetWebRtcAudioDevice()->GetDefaultCapturer();
466
467 scoped_refptr<webrtc::AudioTrackInterface> audio_track( 462 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
468 CreateLocalAudioTrack(track_id, 463 CreateLocalAudioTrack(track.id().utf8(),
469 capturer, 464 source_data->GetAudioCapturer(),
470 webaudio_source.get(), 465 webaudio_source.get(),
471 source_data->local_audio_source(), 466 source_data->local_audio_source(),
472 &track_constraints)); 467 &track_constraints));
473 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); 468 AddNativeTrackToBlinkTrack(audio_track.get(), track, true);
474 469
475 audio_track->set_enabled(track.isEnabled()); 470 audio_track->set_enabled(track.isEnabled());
476 471
477 // Pass the pointer of the source provider to the blink audio track. 472 // Pass the pointer of the source provider to the blink audio track.
478 blink::WebMediaStreamTrack writable_track = track; 473 blink::WebMediaStreamTrack writable_track = track;
479 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>( 474 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>(
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // processed before returning. We wait for the above task to finish before 915 // processed before returning. We wait for the above task to finish before
921 // letting the the function continue to avoid any potential race issues. 916 // letting the the function continue to avoid any potential race issues.
922 chrome_worker_thread_.Stop(); 917 chrome_worker_thread_.Stop();
923 } else { 918 } else {
924 NOTREACHED() << "Worker thread not running."; 919 NOTREACHED() << "Worker thread not running.";
925 } 920 }
926 } 921 }
927 } 922 }
928 923
929 scoped_refptr<WebRtcAudioCapturer> 924 scoped_refptr<WebRtcAudioCapturer>
930 MediaStreamDependencyFactory::MaybeCreateAudioCapturer( 925 MediaStreamDependencyFactory::CreateAudioCapturer(
931 int render_view_id, 926 int render_view_id,
932 const StreamDeviceInfo& device_info) { 927 const StreamDeviceInfo& device_info) {
933 // TODO(xians): Handle the cases when gUM is called without a proper render 928 // TODO(xians): Handle the cases when gUM is called without a proper render
934 // view, for example, by an extension. 929 // view, for example, by an extension.
935 DCHECK_GE(render_view_id, 0); 930 DCHECK_GE(render_view_id, 0);
936 931
937 scoped_refptr<WebRtcAudioCapturer> capturer = 932 return WebRtcAudioCapturer::CreateCapturer(render_view_id, device_info,
938 GetWebRtcAudioDevice()->GetDefaultCapturer(); 933 GetWebRtcAudioDevice());
939
940 // If the default capturer does not exist or |render_view_id| == -1, create
941 // a new capturer.
942 bool is_new_capturer = false;
943 if (!capturer.get()) {
944 capturer = WebRtcAudioCapturer::CreateCapturer();
945 is_new_capturer = true;
946 }
947
948 if (!capturer->Initialize(
949 render_view_id,
950 static_cast<media::ChannelLayout>(
951 device_info.device.input.channel_layout),
952 device_info.device.input.sample_rate,
953 device_info.device.input.frames_per_buffer,
954 device_info.session_id,
955 device_info.device.id,
956 device_info.device.matched_output.sample_rate,
957 device_info.device.matched_output.frames_per_buffer,
958 device_info.device.input.effects)) {
959 return NULL;
960 }
961
962 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer.
963 if (is_new_capturer)
964 GetWebRtcAudioDevice()->AddAudioCapturer(capturer);
965
966 return capturer;
967 } 934 }
968 935
969 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( 936 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack(
970 webrtc::MediaStreamTrackInterface* native_track, 937 webrtc::MediaStreamTrackInterface* native_track,
971 const blink::WebMediaStreamTrack& webkit_track, 938 const blink::WebMediaStreamTrack& webkit_track,
972 bool is_local_track) { 939 bool is_local_track) {
973 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); 940 DCHECK(!webkit_track.isNull() && !webkit_track.extraData());
974 blink::WebMediaStreamTrack track = webkit_track; 941 blink::WebMediaStreamTrack track = webkit_track;
975 942
976 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { 943 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 if (!aec_dump_file_stream) { 1007 if (!aec_dump_file_stream) {
1041 VLOG(1) << "Could not open AEC dump file."; 1008 VLOG(1) << "Could not open AEC dump file.";
1042 base::ClosePlatformFile(aec_dump_file); 1009 base::ClosePlatformFile(aec_dump_file);
1043 } else { 1010 } else {
1044 // |pc_factory_| takes ownership of |aec_dump_file_stream|. 1011 // |pc_factory_| takes ownership of |aec_dump_file_stream|.
1045 pc_factory_->StartAecDump(aec_dump_file_stream); 1012 pc_factory_->StartAecDump(aec_dump_file_stream);
1046 } 1013 }
1047 } 1014 }
1048 1015
1049 } // namespace content 1016 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698