@@ -288,7 +288,6 @@ void FlutterMediaStream::GetUserVideo(const EncodableMap& constraints,
288288 if (!video_capturer.get ())
289289 return ;
290290
291-
292291 video_capturer->StartCapture ();
293292
294293 const char * video_source_label = " video_input" ;
@@ -333,10 +332,11 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
333332
334333 for (uint16_t i = 0 ; i < nb_audio_devices; i++) {
335334 base_->audio_device_ ->RecordingDeviceName (i, strNameUTF8, strGuidUTF8);
335+ std::string device_id = strlen (strGuidUTF8) > 0 ? std::string (strGuidUTF8)
336+ : std::string (strNameUTF8);
336337 EncodableMap audio;
337338 audio[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8));
338- audio[EncodableValue (" deviceId" )] =
339- EncodableValue (std::string (strGuidUTF8));
339+ audio[EncodableValue (" deviceId" )] = EncodableValue (device_id);
340340 audio[EncodableValue (" facing" )] = " " ;
341341 audio[EncodableValue (" kind" )] = " audioinput" ;
342342 sources.push_back (EncodableValue (audio));
@@ -345,10 +345,11 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
345345 nb_audio_devices = base_->audio_device_ ->PlayoutDevices ();
346346 for (uint16_t i = 0 ; i < nb_audio_devices; i++) {
347347 base_->audio_device_ ->PlayoutDeviceName (i, strNameUTF8, strGuidUTF8);
348+ std::string device_id = strlen (strGuidUTF8) > 0 ? std::string (strGuidUTF8)
349+ : std::string (strNameUTF8);
348350 EncodableMap audio;
349351 audio[EncodableValue (" label" )] = EncodableValue (std::string (strNameUTF8));
350- audio[EncodableValue (" deviceId" )] =
351- EncodableValue (std::string (strGuidUTF8));
352+ audio[EncodableValue (" deviceId" )] = EncodableValue (device_id);
352353 audio[EncodableValue (" facing" )] = " " ;
353354 audio[EncodableValue (" kind" )] = " audiooutput" ;
354355 sources.push_back (EncodableValue (audio));
@@ -373,13 +374,16 @@ void FlutterMediaStream::GetSources(std::unique_ptr<MethodResultProxy> result) {
373374void FlutterMediaStream::SelectAudioOutput (
374375 const std::string& device_id,
375376 std::unique_ptr<MethodResultProxy> result) {
376- char strPlayoutName [256 ];
377- char strPlayoutGuid [256 ];
377+ char deviceName [256 ];
378+ char deviceGuid [256 ];
378379 int playout_devices = base_->audio_device_ ->PlayoutDevices ();
379380 bool found = false ;
380381 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) {
383387 base_->audio_device_ ->SetPlayoutDevice (i);
384388 found = true ;
385389 break ;
@@ -395,14 +399,16 @@ void FlutterMediaStream::SelectAudioOutput(
395399void FlutterMediaStream::SelectAudioInput (
396400 const std::string& device_id,
397401 std::unique_ptr<MethodResultProxy> result) {
398- char strPlayoutName [256 ];
399- char strPlayoutGuid [256 ];
402+ char deviceName [256 ];
403+ char deviceGuid [256 ];
400404 int playout_devices = base_->audio_device_ ->RecordingDevices ();
401405 bool found = false ;
402406 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) {
406412 base_->audio_device_ ->SetRecordingDevice (i);
407413 found = true ;
408414 break ;
@@ -538,14 +544,14 @@ void FlutterMediaStream::MediaStreamTrackDispose(
538544 if (track->id ().std_string () == track_id) {
539545 stream->RemoveTrack (track);
540546
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);
546554 }
547- base_->video_capturers_ .erase (track_id);
548- }
549555 }
550556 }
551557 }
0 commit comments