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