Fix the audio source failure due to unsupported constraints.

Some constraints, like kEchoCancellation, kMediaStreamAudioDucking are supported in Chrome but not in Libjingle, if the users set it in mandatory, LocalAudioSource::Initialize() will fail the getUserMedia call.

This patch fixes the problem by fully initializing the LocalAudioSource even though some constraints are not supported in libjingle.

BUT=crbug/398080
TEST=manual test:
var constraints = {audio: { mandatory: { googEchoCancellation: true } }};
getUserMedia(constraints, gotStream, gotStreamFailed);
verify you get a gotStream callback

R=henrika@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/21049004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6885 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
xians@webrtc.org 2014-08-13 13:51:58 +00:00
parent 5af76aedcd
commit 38d88816e3
2 changed files with 8 additions and 16 deletions

View File

@ -41,9 +41,8 @@ namespace {
// Convert constraints to audio options. Return false if constraints are
// invalid.
bool FromConstraints(const MediaConstraintsInterface::Constraints& constraints,
void FromConstraints(const MediaConstraintsInterface::Constraints& constraints,
cricket::AudioOptions* options) {
bool success = true;
MediaConstraintsInterface::Constraints::const_iterator iter;
// This design relies on the fact that all the audio constraints are actually
@ -53,10 +52,8 @@ bool FromConstraints(const MediaConstraintsInterface::Constraints& constraints,
for (iter = constraints.begin(); iter != constraints.end(); ++iter) {
bool value = false;
if (!rtc::FromString(iter->value, &value)) {
success = false;
if (!rtc::FromString(iter->value, &value))
continue;
}
if (iter->key == MediaConstraintsInterface::kEchoCancellation)
options->echo_cancellation.Set(value);
@ -79,10 +76,7 @@ bool FromConstraints(const MediaConstraintsInterface::Constraints& constraints,
options->typing_detection.Set(value);
else if (iter->key == MediaConstraintsInterface::kAudioMirroring)
options->stereo_swapping.Set(value);
else
success = false;
}
return success;
}
} // namespace
@ -106,12 +100,9 @@ void LocalAudioSource::Initialize(
// constraints.
FromConstraints(constraints->GetOptional(), &options_);
cricket::AudioOptions audio_options;
if (!FromConstraints(constraints->GetMandatory(), &audio_options)) {
source_state_ = kEnded;
return;
}
options_.SetAll(audio_options);
cricket::AudioOptions mandatory_options;
FromConstraints(constraints->GetMandatory(), &mandatory_options);
options_.SetAll(mandatory_options);
source_state_ = kLive;
}

View File

@ -118,7 +118,8 @@ TEST(LocalAudioSourceTest, InvalidMandatory) {
LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
&constraints);
EXPECT_EQ(MediaSourceInterface::kEnded, source->state());
EXPECT_EQ(MediaSourceInterface::kLive, source->state());
bool value;
EXPECT_FALSE(source->options().highpass_filter.Get(&value));
EXPECT_TRUE(source->options().highpass_filter.Get(&value));
EXPECT_FALSE(value);
}