OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "content/common/content_export.h" |
| 12 #include "content/common/media/media_devices.mojom.h" |
| 13 #include "content/renderer/media/media_stream_constraints_util.h" |
| 14 |
| 15 namespace blink { |
| 16 class WebMediaConstraints; |
| 17 } |
| 18 |
| 19 namespace content { |
| 20 |
| 21 using AudioDeviceCaptureCapabilities = |
| 22 std::vector<::mojom::AudioInputDeviceCapabilitiesPtr>; |
| 23 |
| 24 // This function implements the SelectSettings algorithm for audio tracks as |
| 25 // described in https://w3c.github.io/mediacapture-main/#dfn-selectsettings |
| 26 // The algorithm starts with a set containing all possible candidate settings |
| 27 // based on hardware capabilities (passed via the |capabilities| parameter) and |
| 28 // supported values for properties not involved in device selection. Candidates |
| 29 // that do not support the basic constraint set from |constraints| are removed. |
| 30 // If the set of candidates is empty after this step, the function returns an |
| 31 // AudioCaptureSettings object without value and whose failed_constraint_name() |
| 32 // method returns the name of one of the (possibly many) constraints that could |
| 33 // not be satisfied or an empty string if the set of candidates was initially |
| 34 // empty (e.g., if there are no devices in the system). |
| 35 // After the basic constraint set is applied, advanced constraint sets are |
| 36 // applied. If no candidates can satisfy an advanced set, the advanced set is |
| 37 // ignored, otherwise the candidates that cannot satisfy the advanced set are |
| 38 // removed. |
| 39 // Once all constraint sets are applied, the result is selected from the |
| 40 // remaining candidates by giving preference to candidates closest to the ideal |
| 41 // values specified in the basic constraint set, or using default |
| 42 // implementation-specific values. |
| 43 // The result includes the following properties: |
| 44 // * Device. A device is chosen using the device_id, sample_rate, sample_size, |
| 45 // and channel_count constraints. If multiple devices satisfy the constraints |
| 46 // preference is given to the default device (system defined or chosen by |
| 47 // user preferences). If the default device is not included in the valid |
| 48 // candidates, the first valid device in the list obtained by querying the |
| 49 // system capabilities is chosen. For content capture, no real audio input |
| 50 // devices are used and the sample_rate, sample_size and channel_count |
| 51 // constraints are ignored. In content capture, the deviceId constraint is |
| 52 // supported and is interpreted by the system as a string that indicates, |
| 53 // for example, which tab to capture. Validation for that "device" ID is |
| 54 // performed by the getUserMedia implementation. To decide between content |
| 55 // or device capture, the value of the special media_stream_source constraint |
| 56 // is used. |
| 57 // * Audio features: the hotword_enabled, disable_local_echo and |
| 58 // render_to_associated_sink constraints can be used to enable the |
| 59 // corresponding audio feature. If not specified, their default value is |
| 60 // false. |
| 61 // * Audio processing. The remaining constraints are used to control audio |
| 62 // processing. This is how audio-processing properties are set for device |
| 63 // capture(see the content::AudioProcessingProperties struct) : |
| 64 // - enable_sw_echo_cancellation: If the selected device has hardware echo |
| 65 // cancellation, software echo cancellation is disabled regardless of |
| 66 // any constraint values. Otherwise, it is enabled by default unless |
| 67 // either the echo_cancellation or the goog_echo_cancellation constraint |
| 68 // has a final value of false after applying all constraint sets. Note |
| 69 // that if these constraints have contradictory values, SelectSettings |
| 70 // fails and returns no value. |
| 71 // - disable_hw_echo_cancellation: For devices that have hardware echo |
| 72 // cancellation, the feature is disabled if the echo_cancellation or |
| 73 // goog_echo_cancellation constraints have a final value of false. |
| 74 // - goog_audio_mirroring: This property is mapped directly from the final |
| 75 // value of the goog_audio_mirroring constraint. If no value is |
| 76 // explicitly specified, the default value is false. |
| 77 // The remaining audio-processing properties are directly mapped from the |
| 78 // final value of the corresponding constraints. If no value is explicitly |
| 79 // specified, the default value is the same as the final value of the |
| 80 // echo_cancellation constraint. If the echo_cancellation constraint is |
| 81 // not explicitly specified, the default value is implementation defined |
| 82 // (see content::AudioProcessingProperties). |
| 83 // For content capture the rules are the same, but all properties are false |
| 84 // by default, regardless of the value of the echo_cancellation constraint. |
| 85 // Note that it is important to distinguish between audio properties and |
| 86 // constraints. Constraints are an input to SelectSettings, while properties |
| 87 // are part of the output. The value for most boolean properties comes |
| 88 // directly from a corresponding boolean constraint, but this is not true for |
| 89 // all constraints and properties. For example, the echo_cancellation and |
| 90 // goog_echo_cancellation constraints are not directly mapped to any |
| 91 // property, but they, together with hardware characteristics, influence the |
| 92 // enabling and disabling of software and hardware echo cancellation. |
| 93 // Moreover, the echo_cancellation constraint influences most other |
| 94 // audio-processing properties for which no explicit value is provided in |
| 95 // their corresponding constraints. |
| 96 AudioCaptureSettings CONTENT_EXPORT |
| 97 SelectSettingsAudioCapture(const AudioDeviceCaptureCapabilities& capabilities, |
| 98 const blink::WebMediaConstraints& constraints); |
| 99 |
| 100 } // namespace content |
| 101 |
| 102 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_ |
OLD | NEW |