Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 using webrtc::MediaSourceInterface; | 36 using webrtc::MediaSourceInterface; |
| 37 | 37 |
| 38 namespace webrtc { | 38 namespace webrtc { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Convert constraints to audio options. Return false if constraints are | 42 // Convert constraints to audio options. Return false if constraints are |
| 43 // invalid. | 43 // invalid. |
| 44 void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, | 44 void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, |
| 45 cricket::AudioOptions* options) { | 45 cricket::AudioOptions* options) { |
| 46 MediaConstraintsInterface::Constraints::const_iterator iter; | |
| 47 | |
| 48 // This design relies on the fact that all the audio constraints are actually | 46 // This design relies on the fact that all the audio constraints are actually |
| 49 // "options", i.e. boolean-valued and always satisfiable. If the constraints | 47 // "options", i.e. boolean-valued and always satisfiable. If the constraints |
| 50 // are extended to include non-boolean values or actual format constraints, | 48 // are extended to include non-boolean values or actual format constraints, |
| 51 // a different algorithm will be required. | 49 // a different algorithm will be required. |
| 52 for (iter = constraints.begin(); iter != constraints.end(); ++iter) { | 50 for (const auto& constraint : constraints) { |
| 53 bool value = false; | 51 bool value = false; |
| 54 | 52 |
| 55 if (!rtc::FromString(iter->value, &value)) | 53 if (!rtc::FromString(constraint.value, &value)) |
| 56 continue; | 54 continue; |
| 57 | 55 |
| 58 if (iter->key == MediaConstraintsInterface::kEchoCancellation) | 56 struct { |
| 59 options->echo_cancellation.Set(value); | 57 const char* name; |
| 60 else if (iter->key == | 58 cricket::Settable<bool>& value; |
| 61 MediaConstraintsInterface::kExperimentalEchoCancellation) | 59 } key_to_value[] = { |
|
tommi
2015/06/09 08:50:11
You could move this outside the loop (e.g. top of
hlundin-webrtc
2015/06/09 09:02:09
Done.
| |
| 62 options->experimental_aec.Set(value); | 60 {MediaConstraintsInterface::kEchoCancellation, |
| 63 else if (iter->key == MediaConstraintsInterface::kDAEchoCancellation) | 61 options->echo_cancellation}, |
| 64 options->delay_agnostic_aec.Set(value); | 62 // Both kExperimentalEchoCancellation (old) and |
| 65 else if (iter->key == MediaConstraintsInterface::kAutoGainControl) | 63 // kExtendedFilterEchoCancellation (new) translate to |
| 66 options->auto_gain_control.Set(value); | 64 // extended_filter_aec |
| 67 else if (iter->key == | 65 // option being set. This is to manage the transition from the old to |
| 68 MediaConstraintsInterface::kExperimentalAutoGainControl) | 66 // the |
| 69 options->experimental_agc.Set(value); | 67 // new without breaking dependent code. |
| 70 else if (iter->key == MediaConstraintsInterface::kNoiseSuppression) | 68 {MediaConstraintsInterface::kExperimentalEchoCancellation, |
| 71 options->noise_suppression.Set(value); | 69 options->extended_filter_aec}, |
| 72 else if (iter->key == | 70 {MediaConstraintsInterface::kExtendedFilterEchoCancellation, |
| 73 MediaConstraintsInterface::kExperimentalNoiseSuppression) | 71 options->extended_filter_aec}, |
| 74 options->experimental_ns.Set(value); | 72 {MediaConstraintsInterface::kDAEchoCancellation, |
| 75 else if (iter->key == MediaConstraintsInterface::kHighpassFilter) | 73 options->delay_agnostic_aec}, |
| 76 options->highpass_filter.Set(value); | 74 {MediaConstraintsInterface::kAutoGainControl, |
| 77 else if (iter->key == MediaConstraintsInterface::kTypingNoiseDetection) | 75 options->auto_gain_control}, |
| 78 options->typing_detection.Set(value); | 76 {MediaConstraintsInterface::kExperimentalAutoGainControl, |
| 79 else if (iter->key == MediaConstraintsInterface::kAudioMirroring) | 77 options->experimental_agc}, |
| 80 options->stereo_swapping.Set(value); | 78 {MediaConstraintsInterface::kNoiseSuppression, |
| 81 else if (iter->key == MediaConstraintsInterface::kAecDump) | 79 options->noise_suppression}, |
| 82 options->aec_dump.Set(value); | 80 {MediaConstraintsInterface::kExperimentalNoiseSuppression, |
| 81 options->experimental_ns}, | |
| 82 {MediaConstraintsInterface::kHighpassFilter, options->highpass_filter}, | |
| 83 {MediaConstraintsInterface::kTypingNoiseDetection, | |
| 84 options->typing_detection}, | |
| 85 {MediaConstraintsInterface::kAudioMirroring, options->stereo_swapping}, | |
| 86 {MediaConstraintsInterface::kAecDump, options->aec_dump}}; | |
|
tommi
2015/06/09 08:50:11
nit: Move }; to the next line
hlundin-webrtc
2015/06/09 09:02:09
Nope. This is clang format. I'm not fighting that
hlundin-webrtc
2015/06/09 14:00:18
Ok, ok. I picked a fight with the windmill anyway.
kwiberg-webrtc
2015/06/09 14:16:37
Don't worry---I'm sure it'll be a breeze!
| |
| 87 | |
| 88 for (auto& entry : key_to_value) { | |
| 89 if (constraint.key.compare(entry.name) == 0) | |
| 90 entry.value.Set(value); | |
| 91 } | |
| 83 } | 92 } |
| 84 } | 93 } |
| 85 | 94 |
| 86 } // namespace | 95 } // namespace |
| 87 | 96 |
| 88 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create( | 97 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create( |
| 89 const PeerConnectionFactoryInterface::Options& options, | 98 const PeerConnectionFactoryInterface::Options& options, |
| 90 const MediaConstraintsInterface* constraints) { | 99 const MediaConstraintsInterface* constraints) { |
| 91 rtc::scoped_refptr<LocalAudioSource> source( | 100 rtc::scoped_refptr<LocalAudioSource> source( |
| 92 new rtc::RefCountedObject<LocalAudioSource>()); | 101 new rtc::RefCountedObject<LocalAudioSource>()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 104 // constraints. | 113 // constraints. |
| 105 FromConstraints(constraints->GetOptional(), &options_); | 114 FromConstraints(constraints->GetOptional(), &options_); |
| 106 | 115 |
| 107 cricket::AudioOptions mandatory_options; | 116 cricket::AudioOptions mandatory_options; |
| 108 FromConstraints(constraints->GetMandatory(), &mandatory_options); | 117 FromConstraints(constraints->GetMandatory(), &mandatory_options); |
| 109 options_.SetAll(mandatory_options); | 118 options_.SetAll(mandatory_options); |
| 110 source_state_ = kLive; | 119 source_state_ = kLive; |
| 111 } | 120 } |
| 112 | 121 |
| 113 } // namespace webrtc | 122 } // namespace webrtc |
| OLD | NEW |