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

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: rebased and fixed the comment. 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 constraints.AddMandatory(kConstraintEffectMap[i].constraint, 317 constraints.AddMandatory(kConstraintEffectMap[i].constraint,
318 webrtc::MediaConstraintsInterface::kValueFalse, true); 318 webrtc::MediaConstraintsInterface::kValueFalse, true);
319 DVLOG(1) << "Disabling platform effect: " 319 DVLOG(1) << "Disabling platform effect: "
320 << kConstraintEffectMap[i].constraint; 320 << kConstraintEffectMap[i].constraint;
321 } 321 }
322 } 322 }
323 device_info.device.input.effects = effects; 323 device_info.device.input.effects = effects;
324 } 324 }
325 325
326 scoped_refptr<WebRtcAudioCapturer> capturer( 326 scoped_refptr<WebRtcAudioCapturer> capturer(
327 MaybeCreateAudioCapturer(render_view_id, device_info, 327 CreateAudioCapturer(render_view_id, device_info, audio_constraints));
328 audio_constraints));
329 if (!capturer.get()) { 328 if (!capturer.get()) {
330 DLOG(WARNING) << "Failed to create the capturer for device " 329 DLOG(WARNING) << "Failed to create the capturer for device "
331 << device_info.device.id; 330 << device_info.device.id;
332 sources_created.Run(web_stream, false); 331 sources_created.Run(web_stream, false);
333 // TODO(xians): Don't we need to check if source_observer is observing 332 // TODO(xians): Don't we need to check if source_observer is observing
334 // something? If not, then it looks like we have a leak here. 333 // something? If not, then it looks like we have a leak here.
335 // OTOH, if it _is_ observing something, then the callback might 334 // OTOH, if it _is_ observing something, then the callback might
336 // be called multiple times which is likely also a bug. 335 // be called multiple times which is likely also a bug.
337 return; 336 return;
338 } 337 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 source_data = 412 source_data =
414 static_cast<MediaStreamSourceExtraData*>(source.extraData()); 413 static_cast<MediaStreamSourceExtraData*>(source.extraData());
415 } else { 414 } else {
416 // TODO(perkj): Implement support for sources from 415 // TODO(perkj): Implement support for sources from
417 // remote MediaStreams. 416 // remote MediaStreams.
418 NOTIMPLEMENTED(); 417 NOTIMPLEMENTED();
419 return NULL; 418 return NULL;
420 } 419 }
421 } 420 }
422 421
423 std::string track_id = base::UTF16ToUTF8(track.id());
424 scoped_refptr<WebRtcAudioCapturer> capturer;
425 if (GetWebRtcAudioDevice())
426 capturer = GetWebRtcAudioDevice()->GetDefaultCapturer();
427
428 scoped_refptr<webrtc::AudioTrackInterface> audio_track( 422 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
429 CreateLocalAudioTrack(track_id, 423 CreateLocalAudioTrack(track.id().utf8(),
430 capturer, 424 source_data->GetAudioCapturer(),
431 webaudio_source.get(), 425 webaudio_source.get(),
432 source_data->local_audio_source())); 426 source_data->local_audio_source()));
433 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); 427 AddNativeTrackToBlinkTrack(audio_track.get(), track, true);
434 428
435 audio_track->set_enabled(track.isEnabled()); 429 audio_track->set_enabled(track.isEnabled());
436 430
437 // Pass the pointer of the source provider to the blink audio track. 431 // Pass the pointer of the source provider to the blink audio track.
438 blink::WebMediaStreamTrack writable_track = track; 432 blink::WebMediaStreamTrack writable_track = track;
439 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>( 433 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>(
440 audio_track.get())->audio_source_provider()); 434 audio_track.get())->audio_source_provider());
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 // processed before returning. We wait for the above task to finish before 881 // processed before returning. We wait for the above task to finish before
888 // letting the the function continue to avoid any potential race issues. 882 // letting the the function continue to avoid any potential race issues.
889 chrome_worker_thread_.Stop(); 883 chrome_worker_thread_.Stop();
890 } else { 884 } else {
891 NOTREACHED() << "Worker thread not running."; 885 NOTREACHED() << "Worker thread not running.";
892 } 886 }
893 } 887 }
894 } 888 }
895 889
896 scoped_refptr<WebRtcAudioCapturer> 890 scoped_refptr<WebRtcAudioCapturer>
897 MediaStreamDependencyFactory::MaybeCreateAudioCapturer( 891 MediaStreamDependencyFactory::CreateAudioCapturer(
898 int render_view_id, 892 int render_view_id,
899 const StreamDeviceInfo& device_info, 893 const StreamDeviceInfo& device_info,
900 const blink::WebMediaConstraints& constraints) { 894 const blink::WebMediaConstraints& constraints) {
901 // TODO(xians): Handle the cases when gUM is called without a proper render 895 // TODO(xians): Handle the cases when gUM is called without a proper render
902 // view, for example, by an extension. 896 // view, for example, by an extension.
903 DCHECK_GE(render_view_id, 0); 897 DCHECK_GE(render_view_id, 0);
904 898
905 scoped_refptr<WebRtcAudioCapturer> capturer = 899 return WebRtcAudioCapturer::CreateCapturer(render_view_id, device_info,
906 GetWebRtcAudioDevice()->GetDefaultCapturer(); 900 constraints,
907 901 GetWebRtcAudioDevice());
908 // If the default capturer does not exist or |render_view_id| == -1, create
909 // a new capturer.
910 bool is_new_capturer = false;
911 if (!capturer.get()) {
912 capturer = WebRtcAudioCapturer::CreateCapturer();
913 is_new_capturer = true;
914 }
915
916 if (!capturer->Initialize(
917 render_view_id,
918 static_cast<media::ChannelLayout>(
919 device_info.device.input.channel_layout),
920 device_info.device.input.sample_rate,
921 device_info.device.input.frames_per_buffer,
922 device_info.session_id,
923 device_info.device.id,
924 device_info.device.matched_output.sample_rate,
925 device_info.device.matched_output.frames_per_buffer,
926 device_info.device.input.effects,
927 constraints)) {
928 return NULL;
929 }
930
931 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer.
932 if (is_new_capturer)
933 GetWebRtcAudioDevice()->AddAudioCapturer(capturer);
934
935 return capturer;
936 } 902 }
937 903
938 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( 904 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack(
939 webrtc::MediaStreamTrackInterface* native_track, 905 webrtc::MediaStreamTrackInterface* native_track,
940 const blink::WebMediaStreamTrack& webkit_track, 906 const blink::WebMediaStreamTrack& webkit_track,
941 bool is_local_track) { 907 bool is_local_track) {
942 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); 908 DCHECK(!webkit_track.isNull() && !webkit_track.extraData());
943 blink::WebMediaStreamTrack track = webkit_track; 909 blink::WebMediaStreamTrack track = webkit_track;
944 910
945 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { 911 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 if (!aec_dump_file_stream) { 975 if (!aec_dump_file_stream) {
1010 VLOG(1) << "Could not open AEC dump file."; 976 VLOG(1) << "Could not open AEC dump file.";
1011 base::ClosePlatformFile(aec_dump_file); 977 base::ClosePlatformFile(aec_dump_file);
1012 } else { 978 } else {
1013 // |pc_factory_| takes ownership of |aec_dump_file_stream|. 979 // |pc_factory_| takes ownership of |aec_dump_file_stream|.
1014 pc_factory_->StartAecDump(aec_dump_file_stream); 980 pc_factory_->StartAecDump(aec_dump_file_stream);
1015 } 981 }
1016 } 982 }
1017 983
1018 } // namespace content 984 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_dependency_factory.h ('k') | content/renderer/media/media_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698