@@ -288,7 +288,6 @@ void FlutterMediaStream::GetUserVideo(const EncodableMap& constraints,
288
288
if (!video_capturer.get ())
289
289
return ;
290
290
291
-
292
291
video_capturer->StartCapture ();
293
292
294
293
const char * video_source_label = " video_input" ;
@@ -333,10 +332,11 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
333
332
334
333
for (uint16_t i = 0 ; i < nb_audio_devices; i++) {
335
334
base_->audio_device_ ->RecordingDeviceName (i, strNameUTF8, strGuidUTF8);
335
+ std::string device_id = strlen (strGuidUTF8) > 0 ? std::string (strGuidUTF8)
336
+ : std::string (strNameUTF8);
336
337
EncodableMap audio;
337
338
audio[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8));
338
- audio[EncodableValue (" deviceId" )] =
339
- EncodableValue (std::string (strGuidUTF8));
339
+ audio[EncodableValue (" deviceId" )] = EncodableValue (device_id);
340
340
audio[EncodableValue (" facing" )] = " " ;
341
341
audio[EncodableValue (" kind" )] = " audioinput" ;
342
342
sources.push_back (EncodableValue (audio));
@@ -345,10 +345,11 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
345
345
nb_audio_devices = base_->audio_device_ ->PlayoutDevices ();
346
346
for (uint16_t i = 0 ; i < nb_audio_devices; i++) {
347
347
base_->audio_device_ ->PlayoutDeviceName (i, strNameUTF8, strGuidUTF8);
348
+ std::string device_id = strlen (strGuidUTF8) > 0 ? std::string (strGuidUTF8)
349
+ : std::string (strNameUTF8);
348
350
EncodableMap audio;
349
351
audio[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8));
350
- audio[EncodableValue (" deviceId" )] =
351
- EncodableValue (std::string (strGuidUTF8));
352
+ audio[EncodableValue (" deviceId" )] = EncodableValue (device_id);
352
353
audio[EncodableValue (" facing" )] = " " ;
353
354
audio[EncodableValue (" kind" )] = " audiooutput" ;
354
355
sources.push_back (EncodableValue (audio));
@@ -373,13 +374,16 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
373
374
void FlutterMediaStream::SelectAudioOutput (
374
375
const std::string& device_id,
375
376
std::unique_ptr<MethodResultProxy> result) {
376
- char strPlayoutName [256 ];
377
- char strPlayoutGuid [256 ];
377
+ char deviceName [256 ];
378
+ char deviceGuid [256 ];
378
379
int playout_devices = base_->audio_device_ ->PlayoutDevices ();
379
380
bool found = false ;
380
381
for (uint16_t i = 0 ; i < playout_devices; i++) {
381
- base_->audio_device_ ->PlayoutDeviceName (i, strPlayoutName, strPlayoutGuid);
382
- if (device_id != " " && device_id == strPlayoutGuid) {
382
+ base_->audio_device_ ->PlayoutDeviceName (i, deviceName, deviceGuid);
383
+ std::string cur_device_id = strlen (deviceGuid) > 0
384
+ ? std::string (deviceGuid)
385
+ : std::string (deviceName);
386
+ if (device_id != " " && device_id == cur_device_id) {
383
387
base_->audio_device_ ->SetPlayoutDevice (i);
384
388
found = true ;
385
389
break ;
@@ -395,14 +399,16 @@ void FlutterMediaStream::SelectAudioOutput(
395
399
void FlutterMediaStream::SelectAudioInput (
396
400
const std::string& device_id,
397
401
std::unique_ptr<MethodResultProxy> result) {
398
- char strPlayoutName [256 ];
399
- char strPlayoutGuid [256 ];
402
+ char deviceName [256 ];
403
+ char deviceGuid [256 ];
400
404
int playout_devices = base_->audio_device_ ->RecordingDevices ();
401
405
bool found = false ;
402
406
for (uint16_t i = 0 ; i < playout_devices; i++) {
403
- base_->audio_device_ ->RecordingDeviceName (i, strPlayoutName,
404
- strPlayoutGuid);
405
- if (device_id != " " && device_id == strPlayoutGuid) {
407
+ base_->audio_device_ ->RecordingDeviceName (i, deviceName, deviceGuid);
408
+ std::string cur_device_id = strlen (deviceGuid) > 0
409
+ ? std::string (deviceGuid)
410
+ : std::string (deviceName);
411
+ if (device_id != " " && device_id == cur_device_id) {
406
412
base_->audio_device_ ->SetRecordingDevice (i);
407
413
found = true ;
408
414
break ;
@@ -538,14 +544,14 @@ void FlutterMediaStream::MediaStreamTrackDispose(
538
544
if (track->id ().std_string () == track_id) {
539
545
stream->RemoveTrack (track);
540
546
541
- if (base_->video_capturers_ .find (track_id) !=
542
- base_->video_capturers_ .end ()) {
543
- auto video_capture = base_->video_capturers_ [track_id];
544
- if (video_capture->CaptureStarted ()) {
545
- video_capture->StopCapture ();
547
+ if (base_->video_capturers_ .find (track_id) !=
548
+ base_->video_capturers_ .end ()) {
549
+ auto video_capture = base_->video_capturers_ [track_id];
550
+ if (video_capture->CaptureStarted ()) {
551
+ video_capture->StopCapture ();
552
+ }
553
+ base_->video_capturers_ .erase (track_id);
546
554
}
547
- base_->video_capturers_ .erase (track_id);
548
- }
549
555
}
550
556
}
551
557
}
0 commit comments