@@ -58,29 +58,83 @@ void addDefaultAudioConstraints(
58
58
audioConstraints->AddOptionalConstraint (" googDAEchoCancellation" , " true" );
59
59
}
60
60
61
+ std::string getSourceIdConstraint (const EncodableMap& mediaConstraints) {
62
+ auto it = mediaConstraints.find (EncodableValue (" optional" ));
63
+ if (it != mediaConstraints.end () &&
64
+ TypeIs<EncodableList>(it->second )) {
65
+ EncodableList optional = GetValue<EncodableList>(it->second );
66
+ for (size_t i = 0 , size = optional.size (); i < size; i++) {
67
+ if (TypeIs<EncodableMap>(optional[i])) {
68
+ EncodableMap option = GetValue<EncodableMap>(optional[i]);
69
+ auto it2 = option.find (EncodableValue (" sourceId" ));
70
+ if (it2 != option.end () && TypeIs<std::string>(it2->second )) {
71
+ return GetValue<std::string>(it2->second );
72
+ }
73
+ }
74
+ }
75
+ }
76
+ return " " ;
77
+ }
78
+
79
+ std::string getDeviceIdConstraint (const EncodableMap& mediaConstraints) {
80
+ auto it = mediaConstraints.find (EncodableValue (" deviceId" ));
81
+ if (it != mediaConstraints.end () && TypeIs<std::string>(it->second )) {
82
+ return GetValue<std::string>(it->second );
83
+ }
84
+ return " " ;
85
+ }
86
+
61
87
void FlutterMediaStream::GetUserAudio (const EncodableMap& constraints,
62
88
scoped_refptr<RTCMediaStream> stream,
63
89
EncodableMap& params) {
64
90
bool enable_audio = false ;
65
91
scoped_refptr<RTCMediaConstraints> audioConstraints;
92
+ std::string sourceId;
93
+ std::string deviceId;
66
94
auto it = constraints.find (EncodableValue (" audio" ));
67
95
if (it != constraints.end ()) {
68
96
EncodableValue audio = it->second ;
69
97
if (TypeIs<bool >(audio)) {
70
98
audioConstraints = RTCMediaConstraints::Create ();
71
99
addDefaultAudioConstraints (audioConstraints);
72
100
enable_audio = GetValue<bool >(audio);
101
+ sourceId = " " ;
102
+ deviceId = " " ;
73
103
}
74
104
if (TypeIs<EncodableMap>(audio)) {
105
+ EncodableMap localMap = GetValue<EncodableMap>(audio);
106
+ sourceId = getSourceIdConstraint (localMap);
107
+ deviceId = getDeviceIdConstraint (localMap);
75
108
audioConstraints =
76
- base_->ParseMediaConstraints (GetValue<EncodableMap>(audio) );
109
+ base_->ParseMediaConstraints (localMap );
77
110
enable_audio = true ;
78
111
}
79
112
}
80
113
81
- // TODO: Select audio device by sourceId,
114
+ // Selecting audio input device by sourceId and audio output device by deviceId
82
115
83
116
if (enable_audio) {
117
+ char strRecordingName[256 ];
118
+ char strRecordingGuid[256 ];
119
+ int playout_devices = base_->audio_device_ ->PlayoutDevices ();
120
+ int recording_devices = base_->audio_device_ ->RecordingDevices ();
121
+
122
+ for (uint16_t i = 0 ; i < recording_devices; i++) {
123
+ base_->audio_device_ ->RecordingDeviceName (i, strRecordingName, strRecordingGuid);
124
+ if (sourceId != " " && sourceId == strRecordingGuid) {
125
+ base_->audio_device_ ->SetRecordingDevice (i);
126
+ }
127
+ }
128
+
129
+ char strPlayoutName[256 ];
130
+ char strPlayoutGuid[256 ];
131
+ for (uint16_t i = 0 ; i < playout_devices; i++) {
132
+ base_->audio_device_ ->PlayoutDeviceName (i, strPlayoutName, strPlayoutGuid);
133
+ if (deviceId != " " && deviceId == strPlayoutGuid) {
134
+ base_->audio_device_ ->SetPlayoutDevice (i);
135
+ }
136
+ }
137
+
84
138
scoped_refptr<RTCAudioSource> source =
85
139
base_->factory_ ->CreateAudioSource (" audio_input" );
86
140
std::string uuid = base_->GenerateUUID ();
@@ -112,24 +166,6 @@ std::string getFacingMode(const EncodableMap& mediaConstraints) {
112
166
: " " ;
113
167
}
114
168
115
- std::string getSourceIdConstraint (const EncodableMap& mediaConstraints) {
116
- auto it = mediaConstraints.find (EncodableValue (" optional" ));
117
- if (it != mediaConstraints.end () &&
118
- TypeIs<EncodableList>(it->second )) {
119
- EncodableList optional = GetValue<EncodableList>(it->second );
120
- for (size_t i = 0 , size = optional.size (); i < size; i++) {
121
- if (TypeIs<EncodableMap>(optional[i])) {
122
- EncodableMap option = GetValue<EncodableMap>(optional[i]);
123
- auto it2 = option.find (EncodableValue (" sourceId" ));
124
- if (it2 != option.end () && TypeIs<std::string>(it2->second )) {
125
- return GetValue<std::string>(it2->second );
126
- }
127
- }
128
- }
129
- }
130
- return " " ;
131
- }
132
-
133
169
EncodableValue getConstrainInt (const EncodableMap& constraints, const std::string& key) {
134
170
EncodableValue value;
135
171
auto it = constraints.find (EncodableValue (key));
@@ -265,8 +301,8 @@ void FlutterMediaStream::GetSources(
265
301
for (uint16_t i = 0 ; i < nb_audio_devices; i++) {
266
302
base_->audio_device_ ->PlayoutDeviceName (i, strNameUTF8, strGuidUTF8);
267
303
EncodableMap audio;
268
- audio[EncodableValue (" label" )] = EncodableValue (std::string (strGuidUTF8 ));
269
- audio[EncodableValue (" deviceId" )] = EncodableValue (std::string (strNameUTF8 ));
304
+ audio[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8 ));
305
+ audio[EncodableValue (" deviceId" )] = EncodableValue (std::string (strGuidUTF8 ));
270
306
audio[EncodableValue (" facing" )] = " " ;
271
307
audio[EncodableValue (" kind" )] = " audiooutput" ;
272
308
sources.push_back (EncodableValue (audio));
@@ -276,8 +312,8 @@ void FlutterMediaStream::GetSources(
276
312
for (int i = 0 ; i < nb_video_devices; i++) {
277
313
base_->video_device_ ->GetDeviceName (i, strNameUTF8, 128 , strGuidUTF8, 128 );
278
314
EncodableMap video;
279
- video[EncodableValue (" label" )] = EncodableValue (std::string (strGuidUTF8 ));
280
- video[EncodableValue (" deviceId" )] = EncodableValue (std::string (strNameUTF8 ));
315
+ video[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8 ));
316
+ video[EncodableValue (" deviceId" )] = EncodableValue (std::string (strGuidUTF8 ));
281
317
video[EncodableValue (" facing" )] = i == 1 ? " front" : " back" ;
282
318
video[EncodableValue (" kind" )] = " videoinput" ;
283
319
sources.push_back (EncodableValue (video));
0 commit comments