OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 options(options), | 202 options(options), |
203 salt_callback(salt_callback), | 203 salt_callback(salt_callback), |
204 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), | 204 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), |
205 audio_type_(MEDIA_NO_SERVICE), | 205 audio_type_(MEDIA_NO_SERVICE), |
206 video_type_(MEDIA_NO_SERVICE) { | 206 video_type_(MEDIA_NO_SERVICE) { |
207 } | 207 } |
208 | 208 |
209 ~DeviceRequest() {} | 209 ~DeviceRequest() {} |
210 | 210 |
211 void SetAudioType(MediaStreamType audio_type) { | 211 void SetAudioType(MediaStreamType audio_type) { |
212 DCHECK(IsAudioInputMediaType(audio_type) || | 212 DCHECK(IsAudioMediaType(audio_type) || audio_type == MEDIA_NO_SERVICE); |
213 audio_type == MEDIA_DEVICE_AUDIO_OUTPUT || | |
214 audio_type == MEDIA_NO_SERVICE); | |
215 audio_type_ = audio_type; | 213 audio_type_ = audio_type; |
216 } | 214 } |
217 | 215 |
218 MediaStreamType audio_type() const { return audio_type_; } | 216 MediaStreamType audio_type() const { return audio_type_; } |
219 | 217 |
220 void SetVideoType(MediaStreamType video_type) { | 218 void SetVideoType(MediaStreamType video_type) { |
221 DCHECK(IsVideoMediaType(video_type) || video_type == MEDIA_NO_SERVICE); | 219 DCHECK(IsVideoMediaType(video_type) || video_type == MEDIA_NO_SERVICE); |
222 video_type_ = video_type; | 220 video_type_ = video_type; |
223 } | 221 } |
224 | 222 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 int render_process_id, | 648 int render_process_id, |
651 int render_view_id, | 649 int render_view_id, |
652 const ResourceContext::SaltCallback& sc, | 650 const ResourceContext::SaltCallback& sc, |
653 int page_request_id, | 651 int page_request_id, |
654 MediaStreamType type, | 652 MediaStreamType type, |
655 const GURL& security_origin, | 653 const GURL& security_origin, |
656 bool have_permission) { | 654 bool have_permission) { |
657 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 655 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
658 DCHECK(requester); | 656 DCHECK(requester); |
659 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 657 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
660 type == MEDIA_DEVICE_VIDEO_CAPTURE || | 658 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
661 type == MEDIA_DEVICE_AUDIO_OUTPUT); | |
662 | 659 |
663 DeviceRequest* request = new DeviceRequest(requester, | 660 DeviceRequest* request = new DeviceRequest(requester, |
664 render_process_id, | 661 render_process_id, |
665 render_view_id, | 662 render_view_id, |
666 page_request_id, | 663 page_request_id, |
667 security_origin, | 664 security_origin, |
668 have_permission, | 665 have_permission, |
669 false, // user gesture | 666 false, // user gesture |
670 MEDIA_ENUMERATE_DEVICES, | 667 MEDIA_ENUMERATE_DEVICES, |
671 StreamOptions(), | 668 StreamOptions(), |
672 sc); | 669 sc); |
673 if (IsAudioInputMediaType(type) || type == MEDIA_DEVICE_AUDIO_OUTPUT) | 670 if (IsAudioMediaType(type)) |
674 request->SetAudioType(type); | 671 request->SetAudioType(type); |
675 else if (IsVideoMediaType(type)) | 672 else if (IsVideoMediaType(type)) |
676 request->SetVideoType(type); | 673 request->SetVideoType(type); |
677 | 674 |
678 const std::string& label = AddRequest(request); | 675 const std::string& label = AddRequest(request); |
679 // Post a task and handle the request asynchronously. The reason is that the | 676 // Post a task and handle the request asynchronously. The reason is that the |
680 // requester won't have a label for the request until this function returns | 677 // requester won't have a label for the request until this function returns |
681 // and thus can not handle a response. Using base::Unretained is safe since | 678 // and thus can not handle a response. Using base::Unretained is safe since |
682 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 679 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
683 // been stopped. | 680 // been stopped. |
684 BrowserThread::PostTask( | 681 BrowserThread::PostTask( |
685 BrowserThread::IO, FROM_HERE, | 682 BrowserThread::IO, FROM_HERE, |
686 base::Bind(&MediaStreamManager::DoEnumerateDevices, | 683 base::Bind(&MediaStreamManager::DoEnumerateDevices, |
687 base::Unretained(this), label)); | 684 base::Unretained(this), label)); |
688 return label; | 685 return label; |
689 } | 686 } |
690 | 687 |
691 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { | 688 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { |
692 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 689 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
693 DeviceRequest* request = FindRequest(label); | 690 DeviceRequest* request = FindRequest(label); |
694 if (!request) | 691 if (!request) |
695 return; // This can happen if the request has been canceled. | 692 return; // This can happen if the request has been canceled. |
696 | 693 |
697 if (request->audio_type() == MEDIA_DEVICE_AUDIO_OUTPUT) { | |
698 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); | |
699 DCHECK_GE(active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT], 0); | |
700 request->SetState(MEDIA_DEVICE_AUDIO_OUTPUT, MEDIA_REQUEST_STATE_REQUESTED); | |
701 if (active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT] == 0) { | |
702 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT]; | |
703 device_task_runner_->PostTask( | |
704 FROM_HERE, | |
705 base::Bind(&MediaStreamManager::EnumerateAudioOutputDevices, | |
706 base::Unretained(this), | |
707 label)); | |
708 } | |
709 return; | |
710 } | |
711 | |
712 MediaStreamType type; | 694 MediaStreamType type; |
713 EnumerationCache* cache; | 695 EnumerationCache* cache; |
714 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) { | 696 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) { |
715 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); | 697 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); |
716 type = MEDIA_DEVICE_AUDIO_CAPTURE; | 698 type = MEDIA_DEVICE_AUDIO_CAPTURE; |
717 cache = &audio_enumeration_cache_; | 699 cache = &audio_enumeration_cache_; |
718 } else { | 700 } else { |
719 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->video_type()); | 701 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->video_type()); |
720 DCHECK_EQ(MEDIA_NO_SERVICE, request->audio_type()); | 702 DCHECK_EQ(MEDIA_NO_SERVICE, request->audio_type()); |
721 type = MEDIA_DEVICE_VIDEO_CAPTURE; | 703 type = MEDIA_DEVICE_VIDEO_CAPTURE; |
722 cache = &video_enumeration_cache_; | 704 cache = &video_enumeration_cache_; |
723 } | 705 } |
724 | 706 |
725 if (!EnumerationRequired(cache, type)) { | 707 if (!EnumerationRequired(cache, type)) { |
726 // Cached device list of this type exists. Just send it out. | 708 // Cached device list of this type exists. Just send it out. |
727 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); | 709 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); |
728 request->devices = cache->devices; | 710 request->devices = cache->devices; |
729 FinalizeEnumerateDevices(label, request); | 711 FinalizeEnumerateDevices(label, request); |
730 } else { | 712 } else { |
731 StartEnumeration(request); | 713 StartEnumeration(request); |
732 } | 714 } |
733 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; | 715 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; |
734 } | 716 } |
735 | 717 |
736 void MediaStreamManager::EnumerateAudioOutputDevices( | |
737 const std::string& label) { | |
738 DCHECK(device_task_runner_->BelongsToCurrentThread()); | |
739 | |
740 scoped_ptr<media::AudioDeviceNames> device_names( | |
741 new media::AudioDeviceNames()); | |
742 audio_manager_->GetAudioOutputDeviceNames(device_names.get()); | |
743 StreamDeviceInfoArray devices; | |
744 for (media::AudioDeviceNames::iterator it = device_names->begin(); | |
745 it != device_names->end(); ++it) { | |
746 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_OUTPUT, | |
747 it->device_name, | |
748 it->unique_id); | |
749 devices.push_back(device); | |
750 } | |
751 | |
752 BrowserThread::PostTask( | |
753 BrowserThread::IO, FROM_HERE, | |
754 base::Bind(&MediaStreamManager::AudioOutputDevicesEnumerated, | |
755 base::Unretained(this), | |
756 devices)); | |
757 } | |
758 | |
759 void MediaStreamManager::AudioOutputDevicesEnumerated( | |
760 const StreamDeviceInfoArray& devices) { | |
761 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
762 DVLOG(1) << "AudioOutputDevicesEnumerated()"; | |
763 | |
764 std::string log_message = "New device enumeration result:\n" + | |
765 GetLogMessageString(MEDIA_DEVICE_AUDIO_OUTPUT, | |
766 devices); | |
767 SendMessageToNativeLog(log_message); | |
768 | |
769 // Publish the result for all requests waiting for device list(s). | |
770 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | |
771 ++it) { | |
772 if (it->second->state(MEDIA_DEVICE_AUDIO_OUTPUT) == | |
773 MEDIA_REQUEST_STATE_REQUESTED && | |
774 it->second->audio_type() == MEDIA_DEVICE_AUDIO_OUTPUT) { | |
775 DCHECK_EQ(MEDIA_ENUMERATE_DEVICES, it->second->request_type); | |
776 it->second->SetState(MEDIA_DEVICE_AUDIO_OUTPUT, | |
777 MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
778 it->second->devices = devices; | |
779 FinalizeEnumerateDevices(it->first, it->second); | |
780 } | |
781 } | |
782 | |
783 --active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT]; | |
784 DCHECK_GE(active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT], 0); | |
785 } | |
786 | |
787 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, | 718 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, |
788 int render_process_id, | 719 int render_process_id, |
789 int render_view_id, | 720 int render_view_id, |
790 const ResourceContext::SaltCallback& sc, | 721 const ResourceContext::SaltCallback& sc, |
791 int page_request_id, | 722 int page_request_id, |
792 const std::string& device_id, | 723 const std::string& device_id, |
793 MediaStreamType type, | 724 MediaStreamType type, |
794 const GURL& security_origin) { | 725 const GURL& security_origin) { |
795 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 726 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
796 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 727 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
797 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 728 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
798 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; | 729 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; |
799 StreamOptions options; | 730 StreamOptions options; |
800 if (IsAudioInputMediaType(type)) { | 731 if (IsAudioMediaType(type)) { |
801 options.audio_requested = true; | 732 options.audio_requested = true; |
802 options.mandatory_audio.push_back( | 733 options.mandatory_audio.push_back( |
803 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 734 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
804 } else if (IsVideoMediaType(type)) { | 735 } else if (IsVideoMediaType(type)) { |
805 options.video_requested = true; | 736 options.video_requested = true; |
806 options.mandatory_video.push_back( | 737 options.mandatory_video.push_back( |
807 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 738 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
808 } else { | 739 } else { |
809 NOTREACHED(); | 740 NOTREACHED(); |
810 } | 741 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 } | 957 } |
1027 } | 958 } |
1028 } | 959 } |
1029 return true; | 960 return true; |
1030 } | 961 } |
1031 | 962 |
1032 void MediaStreamManager::TranslateDeviceIdToSourceId( | 963 void MediaStreamManager::TranslateDeviceIdToSourceId( |
1033 DeviceRequest* request, | 964 DeviceRequest* request, |
1034 MediaStreamDevice* device) { | 965 MediaStreamDevice* device) { |
1035 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || | 966 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || |
1036 request->audio_type() == MEDIA_DEVICE_AUDIO_OUTPUT || | |
1037 request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { | 967 request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { |
1038 device->id = content::GetHMACForMediaDeviceID( | 968 device->id = content::GetHMACForMediaDeviceID( |
1039 request->salt_callback, | 969 request->salt_callback, |
1040 request->security_origin, | 970 request->security_origin, |
1041 device->id); | 971 device->id); |
1042 } | 972 } |
1043 } | 973 } |
1044 | 974 |
1045 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 975 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
1046 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 976 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 void MediaStreamManager::PostRequestToUI(const std::string& label, | 1053 void MediaStreamManager::PostRequestToUI(const std::string& label, |
1124 DeviceRequest* request) { | 1054 DeviceRequest* request) { |
1125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1055 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1126 DCHECK(request->UIRequest()); | 1056 DCHECK(request->UIRequest()); |
1127 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; | 1057 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; |
1128 | 1058 |
1129 const MediaStreamType audio_type = request->audio_type(); | 1059 const MediaStreamType audio_type = request->audio_type(); |
1130 const MediaStreamType video_type = request->video_type(); | 1060 const MediaStreamType video_type = request->video_type(); |
1131 | 1061 |
1132 // Post the request to UI and set the state. | 1062 // Post the request to UI and set the state. |
1133 if (IsAudioInputMediaType(audio_type)) | 1063 if (IsAudioMediaType(audio_type)) |
1134 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 1064 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
1135 if (IsVideoMediaType(video_type)) | 1065 if (IsVideoMediaType(video_type)) |
1136 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 1066 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
1137 | 1067 |
1138 if (use_fake_ui_) { | 1068 if (use_fake_ui_) { |
1139 if (!fake_ui_) | 1069 if (!fake_ui_) |
1140 fake_ui_.reset(new FakeMediaStreamUIProxy()); | 1070 fake_ui_.reset(new FakeMediaStreamUIProxy()); |
1141 | 1071 |
1142 MediaStreamDevices devices; | 1072 MediaStreamDevices devices; |
1143 if (audio_enumeration_cache_.valid) { | 1073 if (audio_enumeration_cache_.valid) { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, | 1334 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, |
1405 DeviceRequest* request) { | 1335 DeviceRequest* request) { |
1406 DVLOG(1) << "FinalizeGenerateStream label " << label; | 1336 DVLOG(1) << "FinalizeGenerateStream label " << label; |
1407 const StreamDeviceInfoArray& requested_devices = request->devices; | 1337 const StreamDeviceInfoArray& requested_devices = request->devices; |
1408 | 1338 |
1409 // Partition the array of devices into audio vs video. | 1339 // Partition the array of devices into audio vs video. |
1410 StreamDeviceInfoArray audio_devices, video_devices; | 1340 StreamDeviceInfoArray audio_devices, video_devices; |
1411 for (StreamDeviceInfoArray::const_iterator device_it = | 1341 for (StreamDeviceInfoArray::const_iterator device_it = |
1412 requested_devices.begin(); | 1342 requested_devices.begin(); |
1413 device_it != requested_devices.end(); ++device_it) { | 1343 device_it != requested_devices.end(); ++device_it) { |
1414 if (IsAudioInputMediaType(device_it->device.type)) { | 1344 if (IsAudioMediaType(device_it->device.type)) { |
1415 audio_devices.push_back(*device_it); | 1345 audio_devices.push_back(*device_it); |
1416 } else if (IsVideoMediaType(device_it->device.type)) { | 1346 } else if (IsVideoMediaType(device_it->device.type)) { |
1417 video_devices.push_back(*device_it); | 1347 video_devices.push_back(*device_it); |
1418 } else { | 1348 } else { |
1419 NOTREACHED(); | 1349 NOTREACHED(); |
1420 } | 1350 } |
1421 } | 1351 } |
1422 | 1352 |
1423 request->requester->StreamGenerated( | 1353 request->requester->StreamGenerated( |
1424 request->requesting_view_id, | 1354 request->requesting_view_id, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 StreamDeviceInfoArray* devices = &(request->devices); | 1487 StreamDeviceInfoArray* devices = &(request->devices); |
1558 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); | 1488 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); |
1559 device_it != devices->end(); ++device_it) { | 1489 device_it != devices->end(); ++device_it) { |
1560 if (device_it->device.type == stream_type && | 1490 if (device_it->device.type == stream_type && |
1561 device_it->session_id == capture_session_id) { | 1491 device_it->session_id == capture_session_id) { |
1562 CHECK(request->state(device_it->device.type) == | 1492 CHECK(request->state(device_it->device.type) == |
1563 MEDIA_REQUEST_STATE_OPENING); | 1493 MEDIA_REQUEST_STATE_OPENING); |
1564 // We've found a matching request. | 1494 // We've found a matching request. |
1565 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); | 1495 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); |
1566 | 1496 |
1567 if (IsAudioInputMediaType(device_it->device.type)) { | 1497 if (IsAudioMediaType(device_it->device.type)) { |
1568 // Store the native audio parameters in the device struct. | 1498 // Store the native audio parameters in the device struct. |
1569 // TODO(xians): Handle the tab capture sample rate/channel layout | 1499 // TODO(xians): Handle the tab capture sample rate/channel layout |
1570 // in AudioInputDeviceManager::Open(). | 1500 // in AudioInputDeviceManager::Open(). |
1571 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { | 1501 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { |
1572 const StreamDeviceInfo* info = | 1502 const StreamDeviceInfo* info = |
1573 audio_input_device_manager_->GetOpenedDeviceInfoById( | 1503 audio_input_device_manager_->GetOpenedDeviceInfoById( |
1574 device_it->session_id); | 1504 device_it->session_id); |
1575 device_it->device.input = info->device.input; | 1505 device_it->device.input = info->device.input; |
1576 device_it->device.matched_output = info->device.matched_output; | 1506 device_it->device.matched_output = info->device.matched_output; |
1577 } | 1507 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 request->devices.push_back(device_info); | 1790 request->devices.push_back(device_info); |
1861 | 1791 |
1862 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); | 1792 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |
1863 DVLOG(1) << "HandleAccessRequestResponse - opening device " | 1793 DVLOG(1) << "HandleAccessRequestResponse - opening device " |
1864 << ", {label = " << label << "}" | 1794 << ", {label = " << label << "}" |
1865 << ", {device_id = " << device_info.device.id << "}" | 1795 << ", {device_id = " << device_info.device.id << "}" |
1866 << ", {session_id = " << device_info.session_id << "}"; | 1796 << ", {session_id = " << device_info.session_id << "}"; |
1867 } | 1797 } |
1868 | 1798 |
1869 // Check whether we've received all stream types requested. | 1799 // Check whether we've received all stream types requested. |
1870 if (!found_audio && IsAudioInputMediaType(request->audio_type())) { | 1800 if (!found_audio && IsAudioMediaType(request->audio_type())) { |
1871 request->SetState(request->audio_type(), MEDIA_REQUEST_STATE_ERROR); | 1801 request->SetState(request->audio_type(), MEDIA_REQUEST_STATE_ERROR); |
1872 DVLOG(1) << "Set no audio found label " << label; | 1802 DVLOG(1) << "Set no audio found label " << label; |
1873 } | 1803 } |
1874 | 1804 |
1875 if (!found_video && IsVideoMediaType(request->video_type())) | 1805 if (!found_video && IsVideoMediaType(request->video_type())) |
1876 request->SetState(request->video_type(), MEDIA_REQUEST_STATE_ERROR); | 1806 request->SetState(request->video_type(), MEDIA_REQUEST_STATE_ERROR); |
1877 | 1807 |
1878 if (RequestDone(*request)) | 1808 if (RequestDone(*request)) |
1879 HandleRequestDone(label, request); | 1809 HandleRequestDone(label, request); |
1880 } | 1810 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 MediaObserver* media_observer = | 1858 MediaObserver* media_observer = |
1929 GetContentClient()->browser()->GetMediaObserver(); | 1859 GetContentClient()->browser()->GetMediaObserver(); |
1930 | 1860 |
1931 // Map the devices to MediaStreamDevices. | 1861 // Map the devices to MediaStreamDevices. |
1932 MediaStreamDevices new_devices; | 1862 MediaStreamDevices new_devices; |
1933 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | 1863 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
1934 it != devices.end(); ++it) { | 1864 it != devices.end(); ++it) { |
1935 new_devices.push_back(it->device); | 1865 new_devices.push_back(it->device); |
1936 } | 1866 } |
1937 | 1867 |
1938 if (IsAudioInputMediaType(stream_type)) { | 1868 if (IsAudioMediaType(stream_type)) { |
1939 MediaCaptureDevicesImpl::GetInstance()->OnAudioCaptureDevicesChanged( | 1869 MediaCaptureDevicesImpl::GetInstance()->OnAudioCaptureDevicesChanged( |
1940 new_devices); | 1870 new_devices); |
1941 if (media_observer) | 1871 if (media_observer) |
1942 media_observer->OnAudioCaptureDevicesChanged(); | 1872 media_observer->OnAudioCaptureDevicesChanged(); |
1943 } else if (IsVideoMediaType(stream_type)) { | 1873 } else if (IsVideoMediaType(stream_type)) { |
1944 MediaCaptureDevicesImpl::GetInstance()->OnVideoCaptureDevicesChanged( | 1874 MediaCaptureDevicesImpl::GetInstance()->OnVideoCaptureDevicesChanged( |
1945 new_devices); | 1875 new_devices); |
1946 if (media_observer) | 1876 if (media_observer) |
1947 media_observer->OnVideoCaptureDevicesChanged(); | 1877 media_observer->OnVideoCaptureDevicesChanged(); |
1948 } else { | 1878 } else { |
1949 NOTREACHED(); | 1879 NOTREACHED(); |
1950 } | 1880 } |
1951 } | 1881 } |
1952 | 1882 |
1953 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { | 1883 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { |
1954 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1884 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1955 | 1885 |
1956 const bool requested_audio = IsAudioInputMediaType(request.audio_type()); | 1886 const bool requested_audio = IsAudioMediaType(request.audio_type()); |
1957 const bool requested_video = IsVideoMediaType(request.video_type()); | 1887 const bool requested_video = IsVideoMediaType(request.video_type()); |
1958 | 1888 |
1959 const bool audio_done = | 1889 const bool audio_done = |
1960 !requested_audio || | 1890 !requested_audio || |
1961 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_DONE || | 1891 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_DONE || |
1962 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_ERROR; | 1892 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_ERROR; |
1963 if (!audio_done) | 1893 if (!audio_done) |
1964 return false; | 1894 return false; |
1965 | 1895 |
1966 const bool video_done = | 1896 const bool video_done = |
1967 !requested_video || | 1897 !requested_video || |
1968 request.state(request.video_type()) == MEDIA_REQUEST_STATE_DONE || | 1898 request.state(request.video_type()) == MEDIA_REQUEST_STATE_DONE || |
1969 request.state(request.video_type()) == MEDIA_REQUEST_STATE_ERROR; | 1899 request.state(request.video_type()) == MEDIA_REQUEST_STATE_ERROR; |
1970 if (!video_done) | 1900 if (!video_done) |
1971 return false; | 1901 return false; |
1972 | 1902 |
1973 return true; | 1903 return true; |
1974 } | 1904 } |
1975 | 1905 |
1976 MediaStreamProvider* MediaStreamManager::GetDeviceManager( | 1906 MediaStreamProvider* MediaStreamManager::GetDeviceManager( |
1977 MediaStreamType stream_type) { | 1907 MediaStreamType stream_type) { |
1978 if (IsVideoMediaType(stream_type)) { | 1908 if (IsVideoMediaType(stream_type)) { |
1979 return video_capture_manager(); | 1909 return video_capture_manager(); |
1980 } else if (IsAudioInputMediaType(stream_type)) { | 1910 } else if (IsAudioMediaType(stream_type)) { |
1981 return audio_input_device_manager(); | 1911 return audio_input_device_manager(); |
1982 } | 1912 } |
1983 NOTREACHED(); | 1913 NOTREACHED(); |
1984 return NULL; | 1914 return NULL; |
1985 } | 1915 } |
1986 | 1916 |
1987 void MediaStreamManager::OnDevicesChanged( | 1917 void MediaStreamManager::OnDevicesChanged( |
1988 base::SystemMonitor::DeviceType device_type) { | 1918 base::SystemMonitor::DeviceType device_type) { |
1989 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1919 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1990 | 1920 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1952 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
2023 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 1953 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
2024 window_id); | 1954 window_id); |
2025 break; | 1955 break; |
2026 } | 1956 } |
2027 } | 1957 } |
2028 } | 1958 } |
2029 } | 1959 } |
2030 | 1960 |
2031 } // namespace content | 1961 } // namespace content |
OLD | NEW |