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

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

Issue 23450041: Set default audio constraints for mediastreams with audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove check for '2' constraints. Created 7 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #if defined(GOOGLE_TV) 47 #if defined(GOOGLE_TV)
48 #include "content/renderer/media/rtc_video_decoder_factory_tv.h" 48 #include "content/renderer/media/rtc_video_decoder_factory_tv.h"
49 #endif 49 #endif
50 50
51 namespace content { 51 namespace content {
52 52
53 // The constraint key for the PeerConnection constructor for enabling diagnostic 53 // The constraint key for the PeerConnection constructor for enabling diagnostic
54 // WebRTC logging. It's a Google specific key, hence the "goog" prefix. 54 // WebRTC logging. It's a Google specific key, hence the "goog" prefix.
55 const char kWebRtcLoggingConstraint[] = "googLog"; 55 const char kWebRtcLoggingConstraint[] = "googLog";
56 56
57 // Constant constraint keys which disables all audio constraints. 57 // Constant constraint keys which enables default audio constraints on
58 // Only used in combination with WebAudio sources. 58 // mediastreams with audio.
59 struct { 59 struct {
60 const char* key; 60 const char* key;
61 const char* value; 61 const char* value;
62 } const kWebAudioConstraints[] = { 62 } const kDefaultAudioConstraints[] = {
63 {webrtc::MediaConstraintsInterface::kEchoCancellation, 63 { webrtc::MediaConstraintsInterface::kEchoCancellation,
64 webrtc::MediaConstraintsInterface::kValueTrue}, 64 webrtc::MediaConstraintsInterface::kValueTrue },
65 {webrtc::MediaConstraintsInterface::kAutoGainControl, 65 { webrtc::MediaConstraintsInterface::kAutoGainControl,
66 webrtc::MediaConstraintsInterface::kValueTrue}, 66 webrtc::MediaConstraintsInterface::kValueTrue },
67 {webrtc::MediaConstraintsInterface::kNoiseSuppression, 67 { webrtc::MediaConstraintsInterface::kNoiseSuppression,
68 webrtc::MediaConstraintsInterface::kValueTrue}, 68 webrtc::MediaConstraintsInterface::kValueTrue },
69 {webrtc::MediaConstraintsInterface::kHighpassFilter, 69 { webrtc::MediaConstraintsInterface::kHighpassFilter,
70 webrtc::MediaConstraintsInterface::kValueTrue}, 70 webrtc::MediaConstraintsInterface::kValueTrue },
71 }; 71 };
72 72
73 void ApplyFixedWebAudioConstraints(RTCMediaConstraints* constraints) { 73 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) {
74 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWebAudioConstraints); ++i) { 74 const webrtc::MediaConstraintsInterface::Constraints& mandatory =
75 constraints->AddMandatory(kWebAudioConstraints[i].key, 75 constraints->GetMandatory();
76 kWebAudioConstraints[i].value, false); 76 std::string string_value;
77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) {
78 if (!mandatory.FindFirst(kDefaultAudioConstraints[i].key, &string_value)) {
79 constraints->AddMandatory(kDefaultAudioConstraints[i].key,
80 kDefaultAudioConstraints[i].value, false);
81 } else {
82 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key
83 << " already set to " << string_value;
84 }
77 } 85 }
78 } 86 }
79 87
80 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { 88 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface {
81 public: 89 public:
82 P2PPortAllocatorFactory( 90 P2PPortAllocatorFactory(
83 P2PSocketDispatcher* socket_dispatcher, 91 P2PSocketDispatcher* socket_dispatcher,
84 talk_base::NetworkManager* network_manager, 92 talk_base::NetworkManager* network_manager,
85 talk_base::PacketSocketFactory* socket_factory, 93 talk_base::PacketSocketFactory* socket_factory,
86 WebKit::WebFrame* web_frame) 94 WebKit::WebFrame* web_frame)
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 source_data->SetVideoSource( 289 source_data->SetVideoSource(
282 CreateLocalVideoSource(source_data->device_info().session_id, 290 CreateLocalVideoSource(source_data->device_info().session_id,
283 is_screencast, 291 is_screencast,
284 &native_video_constraints).get()); 292 &native_video_constraints).get());
285 source_observer->AddSource(source_data->video_source()); 293 source_observer->AddSource(source_data->video_source());
286 } 294 }
287 295
288 // Do additional source initialization if the audio source is a valid 296 // Do additional source initialization if the audio source is a valid
289 // microphone or tab audio. 297 // microphone or tab audio.
290 RTCMediaConstraints native_audio_constraints(audio_constraints); 298 RTCMediaConstraints native_audio_constraints(audio_constraints);
299 ApplyFixedAudioConstraints(&native_audio_constraints);
291 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks; 300 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks;
292 web_stream->audioTracks(audio_tracks); 301 web_stream->audioTracks(audio_tracks);
293 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 302 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
294 if (command_line.HasSwitch(switches::kEnableWebRtcAecRecordings)) { 303 if (command_line.HasSwitch(switches::kEnableWebRtcAecRecordings)) {
295 native_audio_constraints.AddOptional( 304 native_audio_constraints.AddOptional(
296 RTCMediaConstraints::kInternalAecDump, "true"); 305 RTCMediaConstraints::kInternalAecDump, "true");
297 } 306 }
298 for (size_t i = 0; i < audio_tracks.size(); ++i) { 307 for (size_t i = 0; i < audio_tracks.size(); ++i) {
299 const WebKit::WebMediaStreamSource& source = audio_tracks[i].source(); 308 const WebKit::WebMediaStreamSource& source = audio_tracks[i].source();
300 MediaStreamSourceExtraData* source_data = 309 MediaStreamSourceExtraData* source_data =
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 scoped_refptr<WebAudioCapturerSource> 624 scoped_refptr<WebAudioCapturerSource>
616 webaudio_capturer_source(new WebAudioCapturerSource(capturer.get())); 625 webaudio_capturer_source(new WebAudioCapturerSource(capturer.get()));
617 MediaStreamSourceExtraData* source_data = 626 MediaStreamSourceExtraData* source_data =
618 new content::MediaStreamSourceExtraData(webaudio_capturer_source.get()); 627 new content::MediaStreamSourceExtraData(webaudio_capturer_source.get());
619 628
620 // Create a LocalAudioSource object which holds audio options. 629 // Create a LocalAudioSource object which holds audio options.
621 // Use audio constraints where all values are true, i.e., enable 630 // Use audio constraints where all values are true, i.e., enable
622 // echo cancellation, automatic gain control, noise suppression and 631 // echo cancellation, automatic gain control, noise suppression and
623 // high-pass filter. SetLocalAudioSource() affects core audio parts in 632 // high-pass filter. SetLocalAudioSource() affects core audio parts in
624 // third_party/Libjingle. 633 // third_party/Libjingle.
625 ApplyFixedWebAudioConstraints(constraints); 634 ApplyFixedAudioConstraints(constraints);
626 source_data->SetLocalAudioSource(CreateLocalAudioSource(constraints).get()); 635 source_data->SetLocalAudioSource(CreateLocalAudioSource(constraints).get());
627 source->setExtraData(source_data); 636 source->setExtraData(source_data);
628 637
629 // Replace the default source with WebAudio as source instead. 638 // Replace the default source with WebAudio as source instead.
630 source->addAudioConsumer(webaudio_capturer_source.get()); 639 source->addAudioConsumer(webaudio_capturer_source.get());
631 640
632 return capturer; 641 return capturer;
633 } 642 }
634 643
635 scoped_refptr<webrtc::VideoTrackInterface> 644 scoped_refptr<webrtc::VideoTrackInterface>
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 835 }
827 836
828 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. 837 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer.
829 if (is_new_capturer) 838 if (is_new_capturer)
830 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); 839 GetWebRtcAudioDevice()->AddAudioCapturer(capturer);
831 840
832 return capturer; 841 return capturer;
833 } 842 }
834 843
835 } // namespace content 844 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698