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 "ppapi/cpp/dev/video_capture_dev.h" | 5 #include "ppapi/cpp/dev/video_capture_dev.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_video_capture_dev.h" | 7 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
10 #include "ppapi/cpp/dev/device_ref_dev.h" | 10 #include "ppapi/cpp/dev/device_ref_dev.h" |
11 #include "ppapi/cpp/dev/resource_array_dev.h" | 11 #include "ppapi/cpp/dev/resource_array_dev.h" |
12 #include "ppapi/cpp/instance_handle.h" | 12 #include "ppapi/cpp/instance_handle.h" |
13 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
14 #include "ppapi/cpp/module_impl.h" | 14 #include "ppapi/cpp/module_impl.h" |
15 | 15 |
16 namespace pp { | 16 namespace pp { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 template <> const char* interface_name<PPB_VideoCapture_Dev>() { | 20 template <> const char* interface_name<PPB_VideoCapture_Dev_0_2>() { |
21 return PPB_VIDEOCAPTURE_DEV_INTERFACE; | 21 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2; |
| 22 } |
| 23 |
| 24 template <> const char* interface_name<PPB_VideoCapture_Dev_0_1>() { |
| 25 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1; |
22 } | 26 } |
23 | 27 |
24 } // namespace | 28 } // namespace |
25 | 29 |
26 struct VideoCapture_Dev::EnumerateDevicesState { | 30 struct VideoCapture_Dev::EnumerateDevicesState { |
27 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices, | 31 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices, |
28 const CompletionCallback& in_callback, | 32 const CompletionCallback& in_callback, |
29 VideoCapture_Dev* in_video_capture) | 33 VideoCapture_Dev* in_video_capture) |
30 : devices_resource(0), | 34 : devices_resource(0), |
31 devices(in_devices), | 35 devices(in_devices), |
32 callback(in_callback), | 36 callback(in_callback), |
33 video_capture(in_video_capture) { | 37 video_capture(in_video_capture) { |
34 } | 38 } |
35 | 39 |
36 PP_Resource devices_resource; | 40 PP_Resource devices_resource; |
37 std::vector<DeviceRef_Dev>* devices; | 41 std::vector<DeviceRef_Dev>* devices; |
38 CompletionCallback callback; | 42 CompletionCallback callback; |
39 VideoCapture_Dev* video_capture; | 43 VideoCapture_Dev* video_capture; |
40 }; | 44 }; |
41 | 45 |
42 VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) | 46 VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) |
43 : enum_state_(NULL) { | 47 : enum_state_(NULL), |
44 if (!has_interface<PPB_VideoCapture_Dev>()) | 48 requested_info_(), |
45 return; | 49 buffer_count_(0) { |
46 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev>()->Create( | 50 if (has_interface<PPB_VideoCapture_Dev_0_2>()) { |
47 instance.pp_instance())); | 51 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create( |
| 52 instance.pp_instance())); |
| 53 } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) { |
| 54 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_1>()->Create( |
| 55 instance.pp_instance())); |
| 56 } |
48 } | 57 } |
49 | 58 |
50 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource) | 59 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource) |
51 : Resource(resource), | 60 : Resource(resource), |
52 enum_state_(NULL) { | 61 enum_state_(NULL), |
| 62 requested_info_(), |
| 63 buffer_count_(0) { |
53 } | 64 } |
54 | 65 |
55 VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other) | 66 VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other) |
56 : Resource(other), | 67 : Resource(other), |
57 enum_state_(NULL) { | 68 enum_state_(NULL), |
| 69 requested_info_(other.requested_info_), |
| 70 buffer_count_(other.buffer_count_) { |
58 } | 71 } |
59 | 72 |
60 VideoCapture_Dev::~VideoCapture_Dev() { | 73 VideoCapture_Dev::~VideoCapture_Dev() { |
61 AbortEnumerateDevices(); | 74 AbortEnumerateDevices(); |
62 } | 75 } |
63 | 76 |
64 VideoCapture_Dev& VideoCapture_Dev::operator=( | 77 VideoCapture_Dev& VideoCapture_Dev::operator=( |
65 const VideoCapture_Dev& other) { | 78 const VideoCapture_Dev& other) { |
66 AbortEnumerateDevices(); | 79 AbortEnumerateDevices(); |
67 | 80 |
68 Resource::operator=(other); | 81 Resource::operator=(other); |
| 82 requested_info_ = other.requested_info_; |
| 83 buffer_count_ = other.buffer_count_; |
69 return *this; | 84 return *this; |
70 } | 85 } |
71 | 86 |
72 // static | 87 // static |
73 bool VideoCapture_Dev::IsAvailable() { | 88 bool VideoCapture_Dev::IsAvailable() { |
74 return has_interface<PPB_VideoCapture_Dev>(); | 89 return has_interface<PPB_VideoCapture_Dev_0_2>() || |
| 90 has_interface<PPB_VideoCapture_Dev_0_1>(); |
75 } | 91 } |
76 | 92 |
77 int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices, | 93 int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices, |
78 const CompletionCallback& callback) { | 94 const CompletionCallback& callback) { |
79 if (!has_interface<PPB_VideoCapture_Dev>()) | 95 if (!has_interface<PPB_VideoCapture_Dev_0_2>()) |
80 return callback.MayForce(PP_ERROR_NOINTERFACE); | 96 return callback.MayForce(PP_ERROR_NOINTERFACE); |
81 if (!devices) | 97 if (!devices) |
82 return callback.MayForce(PP_ERROR_BADARGUMENT); | 98 return callback.MayForce(PP_ERROR_BADARGUMENT); |
83 if (!callback.pp_completion_callback().func) | 99 if (!callback.pp_completion_callback().func) |
84 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD); | 100 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD); |
85 if (enum_state_) | 101 if (enum_state_) |
86 return callback.MayForce(PP_ERROR_INPROGRESS); | 102 return callback.MayForce(PP_ERROR_INPROGRESS); |
87 | 103 |
88 // It will be deleted in OnEnumerateDevicesComplete(). | 104 // It will be deleted in OnEnumerateDevicesComplete(). |
89 enum_state_ = new EnumerateDevicesState(devices, callback, this); | 105 enum_state_ = new EnumerateDevicesState(devices, callback, this); |
90 return get_interface<PPB_VideoCapture_Dev>()->EnumerateDevices( | 106 return get_interface<PPB_VideoCapture_Dev_0_2>()->EnumerateDevices( |
91 pp_resource(), &enum_state_->devices_resource, | 107 pp_resource(), &enum_state_->devices_resource, |
92 PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete, | 108 PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete, |
93 enum_state_)); | 109 enum_state_)); |
94 } | 110 } |
95 | 111 |
96 int32_t VideoCapture_Dev::Open( | 112 int32_t VideoCapture_Dev::Open( |
97 const DeviceRef_Dev& device_ref, | 113 const DeviceRef_Dev& device_ref, |
98 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | 114 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
99 uint32_t buffer_count, | 115 uint32_t buffer_count, |
100 const CompletionCallback& callback) { | 116 const CompletionCallback& callback) { |
101 if (!has_interface<PPB_VideoCapture_Dev>()) | 117 if (has_interface<PPB_VideoCapture_Dev_0_2>()) { |
102 return callback.MayForce(PP_ERROR_NOINTERFACE); | 118 return get_interface<PPB_VideoCapture_Dev_0_2>()->Open( |
103 return get_interface<PPB_VideoCapture_Dev>()->Open( | 119 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count, |
104 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count, | 120 callback.pp_completion_callback()); |
105 callback.pp_completion_callback()); | 121 } |
| 122 |
| 123 if (has_interface<PPB_VideoCapture_Dev_0_1>()) { |
| 124 if (device_ref.is_null()) { |
| 125 requested_info_ = requested_info; |
| 126 buffer_count_ = buffer_count; |
| 127 return callback.MayForce(PP_OK); |
| 128 } |
| 129 return callback.MayForce(PP_ERROR_NOTSUPPORTED); |
| 130 } |
| 131 |
| 132 return callback.MayForce(PP_ERROR_NOINTERFACE); |
106 } | 133 } |
107 | 134 |
108 int32_t VideoCapture_Dev::StartCapture() { | 135 int32_t VideoCapture_Dev::StartCapture() { |
109 if (!has_interface<PPB_VideoCapture_Dev>()) | 136 if (has_interface<PPB_VideoCapture_Dev_0_2>()) { |
110 return PP_ERROR_NOINTERFACE; | 137 return get_interface<PPB_VideoCapture_Dev_0_2>()->StartCapture( |
111 return get_interface<PPB_VideoCapture_Dev>()->StartCapture(pp_resource()); | 138 pp_resource()); |
| 139 } |
| 140 |
| 141 if (has_interface<PPB_VideoCapture_Dev_0_1>()) { |
| 142 return get_interface<PPB_VideoCapture_Dev_0_1>()->StartCapture( |
| 143 pp_resource(), &requested_info_, buffer_count_); |
| 144 } |
| 145 |
| 146 return PP_ERROR_NOINTERFACE; |
112 } | 147 } |
113 | 148 |
114 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) { | 149 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) { |
115 if (!has_interface<PPB_VideoCapture_Dev>()) | 150 if (has_interface<PPB_VideoCapture_Dev_0_2>()) { |
116 return PP_ERROR_NOINTERFACE; | 151 return get_interface<PPB_VideoCapture_Dev_0_2>()->ReuseBuffer(pp_resource(), |
117 return get_interface<PPB_VideoCapture_Dev>()->ReuseBuffer( | 152 buffer); |
118 pp_resource(), buffer); | 153 } |
| 154 |
| 155 if (has_interface<PPB_VideoCapture_Dev_0_1>()) { |
| 156 return get_interface<PPB_VideoCapture_Dev_0_1>()->ReuseBuffer(pp_resource(), |
| 157 buffer); |
| 158 } |
| 159 |
| 160 return PP_ERROR_NOINTERFACE; |
119 } | 161 } |
120 | 162 |
121 int32_t VideoCapture_Dev::StopCapture() { | 163 int32_t VideoCapture_Dev::StopCapture() { |
122 if (!has_interface<PPB_VideoCapture_Dev>()) | 164 if (has_interface<PPB_VideoCapture_Dev_0_2>()) { |
123 return PP_ERROR_NOINTERFACE; | 165 return get_interface<PPB_VideoCapture_Dev_0_2>()->StopCapture( |
124 return get_interface<PPB_VideoCapture_Dev>()->StopCapture(pp_resource()); | 166 pp_resource()); |
| 167 } |
| 168 |
| 169 if (has_interface<PPB_VideoCapture_Dev_0_1>()) { |
| 170 return get_interface<PPB_VideoCapture_Dev_0_1>()->StopCapture( |
| 171 pp_resource()); |
| 172 } |
| 173 |
| 174 return PP_ERROR_NOINTERFACE; |
125 } | 175 } |
126 | 176 |
127 void VideoCapture_Dev::Close() { | 177 void VideoCapture_Dev::Close() { |
128 if (has_interface<PPB_VideoCapture_Dev>()) | 178 if (has_interface<PPB_VideoCapture_Dev_0_2>()) |
129 get_interface<PPB_VideoCapture_Dev>()->Close(pp_resource()); | 179 get_interface<PPB_VideoCapture_Dev_0_2>()->Close(pp_resource()); |
130 } | 180 } |
131 | 181 |
132 void VideoCapture_Dev::AbortEnumerateDevices() { | 182 void VideoCapture_Dev::AbortEnumerateDevices() { |
133 if (enum_state_) { | 183 if (enum_state_) { |
134 enum_state_->devices = NULL; | 184 enum_state_->devices = NULL; |
135 Module::Get()->core()->CallOnMainThread(0, enum_state_->callback, | 185 Module::Get()->core()->CallOnMainThread(0, enum_state_->callback, |
136 PP_ERROR_ABORTED); | 186 PP_ERROR_ABORTED); |
137 enum_state_->video_capture = NULL; | 187 enum_state_->video_capture = NULL; |
138 enum_state_ = NULL; | 188 enum_state_ = NULL; |
139 } | 189 } |
(...skipping 22 matching lines...) Expand all Loading... |
162 | 212 |
163 if (need_to_callback) { | 213 if (need_to_callback) { |
164 enum_state->video_capture->enum_state_ = NULL; | 214 enum_state->video_capture->enum_state_ = NULL; |
165 enum_state->callback.Run(result); | 215 enum_state->callback.Run(result); |
166 } | 216 } |
167 | 217 |
168 delete enum_state; | 218 delete enum_state; |
169 } | 219 } |
170 | 220 |
171 } // namespace pp | 221 } // namespace pp |
OLD | NEW |