| 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/renderer/pepper/pepper_device_enumeration_event_handler.h" | 5 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | 8 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 ppapi::DeviceRefData FromStreamDeviceInfo( | 14 ppapi::DeviceRefData FromStreamDeviceInfo(const StreamDeviceInfo& info) { |
| 15 const media_stream::StreamDeviceInfo& info) { | |
| 16 ppapi::DeviceRefData data; | 15 ppapi::DeviceRefData data; |
| 17 data.id = info.device_id; | 16 data.id = info.device_id; |
| 18 data.name = info.name; | 17 data.name = info.name; |
| 19 data.type = PepperDeviceEnumerationEventHandler::FromMediaStreamType( | 18 data.type = PepperDeviceEnumerationEventHandler::FromMediaStreamType( |
| 20 info.stream_type); | 19 info.stream_type); |
| 21 return data; | 20 return data; |
| 22 } | 21 } |
| 23 | 22 |
| 24 } // namespace | 23 } // namespace |
| 25 | 24 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 | 39 |
| 41 int PepperDeviceEnumerationEventHandler::RegisterOpenDeviceCallback( | 40 int PepperDeviceEnumerationEventHandler::RegisterOpenDeviceCallback( |
| 42 const PepperPluginDelegateImpl::OpenDeviceCallback& callback) { | 41 const PepperPluginDelegateImpl::OpenDeviceCallback& callback) { |
| 43 open_callbacks_[next_id_] = callback; | 42 open_callbacks_[next_id_] = callback; |
| 44 return next_id_++; | 43 return next_id_++; |
| 45 } | 44 } |
| 46 | 45 |
| 47 void PepperDeviceEnumerationEventHandler::OnStreamGenerated( | 46 void PepperDeviceEnumerationEventHandler::OnStreamGenerated( |
| 48 int request_id, | 47 int request_id, |
| 49 const std::string& label, | 48 const std::string& label, |
| 50 const media_stream::StreamDeviceInfoArray& audio_device_array, | 49 const StreamDeviceInfoArray& audio_device_array, |
| 51 const media_stream::StreamDeviceInfoArray& video_device_array) { | 50 const StreamDeviceInfoArray& video_device_array) { |
| 52 } | 51 } |
| 53 | 52 |
| 54 void PepperDeviceEnumerationEventHandler::OnStreamGenerationFailed( | 53 void PepperDeviceEnumerationEventHandler::OnStreamGenerationFailed( |
| 55 int request_id) { | 54 int request_id) { |
| 56 } | 55 } |
| 57 | 56 |
| 58 void PepperDeviceEnumerationEventHandler::OnDevicesEnumerated( | 57 void PepperDeviceEnumerationEventHandler::OnDevicesEnumerated( |
| 59 int request_id, | 58 int request_id, |
| 60 const media_stream::StreamDeviceInfoArray& device_array) { | 59 const StreamDeviceInfoArray& device_array) { |
| 61 NotifyDevicesEnumerated(request_id, true, device_array); | 60 NotifyDevicesEnumerated(request_id, true, device_array); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void PepperDeviceEnumerationEventHandler::OnDevicesEnumerationFailed( | 63 void PepperDeviceEnumerationEventHandler::OnDevicesEnumerationFailed( |
| 65 int request_id) { | 64 int request_id) { |
| 66 NotifyDevicesEnumerated(request_id, false, | 65 NotifyDevicesEnumerated(request_id, false, StreamDeviceInfoArray()); |
| 67 media_stream::StreamDeviceInfoArray()); | |
| 68 } | 66 } |
| 69 | 67 |
| 70 void PepperDeviceEnumerationEventHandler::OnDeviceOpened( | 68 void PepperDeviceEnumerationEventHandler::OnDeviceOpened( |
| 71 int request_id, | 69 int request_id, |
| 72 const std::string& label, | 70 const std::string& label, |
| 73 const media_stream::StreamDeviceInfo& device_info) { | 71 const StreamDeviceInfo& device_info) { |
| 74 NotifyDeviceOpened(request_id, true, label); | 72 NotifyDeviceOpened(request_id, true, label); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void PepperDeviceEnumerationEventHandler::OnDeviceOpenFailed(int request_id) { | 75 void PepperDeviceEnumerationEventHandler::OnDeviceOpenFailed(int request_id) { |
| 78 NotifyDeviceOpened(request_id, false, ""); | 76 NotifyDeviceOpened(request_id, false, ""); |
| 79 } | 77 } |
| 80 | 78 |
| 81 // static | 79 // static |
| 82 media_stream::MediaStreamType | 80 MediaStreamType PepperDeviceEnumerationEventHandler::FromPepperDeviceType( |
| 83 PepperDeviceEnumerationEventHandler::FromPepperDeviceType( | |
| 84 PP_DeviceType_Dev type) { | 81 PP_DeviceType_Dev type) { |
| 85 switch (type) { | 82 switch (type) { |
| 86 case PP_DEVICETYPE_DEV_INVALID: | 83 case PP_DEVICETYPE_DEV_INVALID: |
| 87 return MEDIA_NO_SERVICE; | 84 return MEDIA_NO_SERVICE; |
| 88 case PP_DEVICETYPE_DEV_AUDIOCAPTURE: | 85 case PP_DEVICETYPE_DEV_AUDIOCAPTURE: |
| 89 return MEDIA_DEVICE_AUDIO_CAPTURE; | 86 return MEDIA_DEVICE_AUDIO_CAPTURE; |
| 90 case PP_DEVICETYPE_DEV_VIDEOCAPTURE: | 87 case PP_DEVICETYPE_DEV_VIDEOCAPTURE: |
| 91 return MEDIA_DEVICE_VIDEO_CAPTURE; | 88 return MEDIA_DEVICE_VIDEO_CAPTURE; |
| 92 default: | 89 default: |
| 93 NOTREACHED(); | 90 NOTREACHED(); |
| 94 return MEDIA_NO_SERVICE; | 91 return MEDIA_NO_SERVICE; |
| 95 } | 92 } |
| 96 } | 93 } |
| 97 | 94 |
| 98 // static | 95 // static |
| 99 PP_DeviceType_Dev PepperDeviceEnumerationEventHandler::FromMediaStreamType( | 96 PP_DeviceType_Dev PepperDeviceEnumerationEventHandler::FromMediaStreamType( |
| 100 media_stream::MediaStreamType type) { | 97 MediaStreamType type) { |
| 101 switch (type) { | 98 switch (type) { |
| 102 case MEDIA_NO_SERVICE: | 99 case MEDIA_NO_SERVICE: |
| 103 return PP_DEVICETYPE_DEV_INVALID; | 100 return PP_DEVICETYPE_DEV_INVALID; |
| 104 case MEDIA_DEVICE_AUDIO_CAPTURE: | 101 case MEDIA_DEVICE_AUDIO_CAPTURE: |
| 105 return PP_DEVICETYPE_DEV_AUDIOCAPTURE; | 102 return PP_DEVICETYPE_DEV_AUDIOCAPTURE; |
| 106 case MEDIA_DEVICE_VIDEO_CAPTURE: | 103 case MEDIA_DEVICE_VIDEO_CAPTURE: |
| 107 return PP_DEVICETYPE_DEV_VIDEOCAPTURE; | 104 return PP_DEVICETYPE_DEV_VIDEOCAPTURE; |
| 108 default: | 105 default: |
| 109 NOTREACHED(); | 106 NOTREACHED(); |
| 110 return PP_DEVICETYPE_DEV_INVALID; | 107 return PP_DEVICETYPE_DEV_INVALID; |
| 111 } | 108 } |
| 112 } | 109 } |
| 113 | 110 |
| 114 void PepperDeviceEnumerationEventHandler::NotifyDevicesEnumerated( | 111 void PepperDeviceEnumerationEventHandler::NotifyDevicesEnumerated( |
| 115 int request_id, | 112 int request_id, |
| 116 bool succeeded, | 113 bool succeeded, |
| 117 const media_stream::StreamDeviceInfoArray& device_array) { | 114 const StreamDeviceInfoArray& device_array) { |
| 118 EnumerateCallbackMap::iterator iter = enumerate_callbacks_.find(request_id); | 115 EnumerateCallbackMap::iterator iter = enumerate_callbacks_.find(request_id); |
| 119 if (iter == enumerate_callbacks_.end()) { | 116 if (iter == enumerate_callbacks_.end()) { |
| 120 // This might be enumerated result sent before StopEnumerateDevices is | 117 // This might be enumerated result sent before StopEnumerateDevices is |
| 121 // called since EnumerateDevices is persistent request. | 118 // called since EnumerateDevices is persistent request. |
| 122 return; | 119 return; |
| 123 } | 120 } |
| 124 | 121 |
| 125 webkit::ppapi::PluginDelegate::EnumerateDevicesCallback callback = | 122 webkit::ppapi::PluginDelegate::EnumerateDevicesCallback callback = |
| 126 iter->second; | 123 iter->second; |
| 127 enumerate_callbacks_.erase(iter); | 124 enumerate_callbacks_.erase(iter); |
| 128 | 125 |
| 129 std::vector<ppapi::DeviceRefData> devices; | 126 std::vector<ppapi::DeviceRefData> devices; |
| 130 if (succeeded) { | 127 if (succeeded) { |
| 131 devices.reserve(device_array.size()); | 128 devices.reserve(device_array.size()); |
| 132 for (media_stream::StreamDeviceInfoArray::const_iterator info = | 129 for (StreamDeviceInfoArray::const_iterator info = |
| 133 device_array.begin(); info != device_array.end(); ++info) { | 130 device_array.begin(); info != device_array.end(); ++info) { |
| 134 devices.push_back(FromStreamDeviceInfo(*info)); | 131 devices.push_back(FromStreamDeviceInfo(*info)); |
| 135 } | 132 } |
| 136 } | 133 } |
| 137 callback.Run(request_id, succeeded, devices); | 134 callback.Run(request_id, succeeded, devices); |
| 138 } | 135 } |
| 139 | 136 |
| 140 void PepperDeviceEnumerationEventHandler::NotifyDeviceOpened( | 137 void PepperDeviceEnumerationEventHandler::NotifyDeviceOpened( |
| 141 int request_id, | 138 int request_id, |
| 142 bool succeeded, | 139 bool succeeded, |
| 143 const std::string& label) { | 140 const std::string& label) { |
| 144 OpenCallbackMap::iterator iter = open_callbacks_.find(request_id); | 141 OpenCallbackMap::iterator iter = open_callbacks_.find(request_id); |
| 145 if (iter == open_callbacks_.end()) { | 142 if (iter == open_callbacks_.end()) { |
| 146 NOTREACHED(); | 143 NOTREACHED(); |
| 147 return; | 144 return; |
| 148 } | 145 } |
| 149 | 146 |
| 150 PepperPluginDelegateImpl::OpenDeviceCallback callback = iter->second; | 147 PepperPluginDelegateImpl::OpenDeviceCallback callback = iter->second; |
| 151 open_callbacks_.erase(iter); | 148 open_callbacks_.erase(iter); |
| 152 | 149 |
| 153 callback.Run(request_id, succeeded, label); | 150 callback.Run(request_id, succeeded, label); |
| 154 } | 151 } |
| 155 | 152 |
| 156 } // namespace content | 153 } // namespace content |
| OLD | NEW |