Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: ppapi/shared_impl/ppb_video_capture_shared.cc

Issue 9234064: Implement device enumeration for PPB_VideoCapture_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/ppb_video_capture_shared.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/ppb_video_capture_shared.h"
6
7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
10 #include "ppapi/shared_impl/ppb_resource_array_shared.h"
11
12 namespace ppapi {
13
14 PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(PP_Instance instance)
15 : Resource(OBJECT_IS_IMPL, instance),
16 open_state_(BEFORE_OPEN),
17 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
18 devices_(NULL),
19 resource_object_type_(OBJECT_IS_IMPL) {
20 }
21
22 PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(
23 const HostResource& host_resource)
24 : Resource(OBJECT_IS_PROXY, host_resource),
25 open_state_(BEFORE_OPEN),
26 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
27 devices_(NULL),
28 resource_object_type_(OBJECT_IS_PROXY) {
29 }
30
31 PPB_VideoCapture_Shared::~PPB_VideoCapture_Shared() {
32 }
33
34 thunk::PPB_VideoCapture_API* PPB_VideoCapture_Shared::AsPPB_VideoCapture_API() {
35 return this;
36 }
37
38 int32_t PPB_VideoCapture_Shared::EnumerateDevices(
39 PP_Resource* devices,
40 PP_CompletionCallback callback) {
41 if (!callback.func)
42 return PP_ERROR_BLOCKS_MAIN_THREAD;
43 if (TrackedCallback::IsPending(enumerate_devices_callback_))
44 return PP_ERROR_INPROGRESS;
45
46 return InternalEnumerateDevices(devices, callback);
47 }
48
49 int32_t PPB_VideoCapture_Shared::Open(
50 const std::string& device_id,
51 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
52 uint32_t buffer_count,
53 PP_CompletionCallback callback) {
54 if (open_state_ != BEFORE_OPEN)
55 return PP_ERROR_FAILED;
56
57 if (TrackedCallback::IsPending(open_callback_))
58 return PP_ERROR_INPROGRESS;
59
60 return InternalOpen(device_id, requested_info, buffer_count, callback);
61 }
62
63 int32_t PPB_VideoCapture_Shared::StartCapture() {
64 if (open_state_ != OPENED ||
65 !SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false)) {
66 return PP_ERROR_FAILED;
67 }
68
69 return InternalStartCapture();
70 }
71
72 int32_t PPB_VideoCapture_Shared::ReuseBuffer(uint32_t buffer) {
73 return InternalReuseBuffer(buffer);
74 }
75
76 int32_t PPB_VideoCapture_Shared::StopCapture() {
77 if (open_state_ != OPENED ||
78 !SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, false)) {
79 return PP_ERROR_FAILED;
80 }
81
82 return InternalStopCapture();
83 }
84
85 void PPB_VideoCapture_Shared::Close() {
86 if (open_state_ == CLOSED)
87 return;
88
89 InternalClose();
90 open_state_ = CLOSED;
91
92 if (TrackedCallback::IsPending(open_callback_))
93 open_callback_->PostAbort();
94 }
95
96 int32_t PPB_VideoCapture_Shared::StartCapture0_1(
97 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
98 uint32_t buffer_count) {
99 if (open_state_ == BEFORE_OPEN) {
100 if (TrackedCallback::IsPending(open_callback_))
101 return PP_ERROR_FAILED;
102 open_state_ = OPENED;
103 } else if (open_state_ == CLOSED) {
104 return PP_ERROR_FAILED;
105 }
106
107 if (!SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false))
108 return PP_ERROR_FAILED;
109
110 return InternalStartCapture0_1(requested_info, buffer_count);
111 }
112
113 const std::vector<DeviceRefData>& PPB_VideoCapture_Shared::GetDeviceRefData(
114 ) const {
115 return InternalGetDeviceRefData();
116 }
117
118 void PPB_VideoCapture_Shared::OnEnumerateDevicesComplete(
119 int32_t result,
120 const std::vector<DeviceRefData>& devices) {
121 DCHECK(TrackedCallback::IsPending(enumerate_devices_callback_));
122
123 if (result == PP_OK && devices_) {
124 *devices_ = PPB_DeviceRef_Shared::CreateResourceArray(
125 resource_object_type_, pp_instance(), devices);
126 }
127 devices_ = NULL;
128
129 TrackedCallback::ClearAndRun(&enumerate_devices_callback_, result);
130 }
131
132 void PPB_VideoCapture_Shared::OnOpenComplete(int32_t result) {
133 if (open_state_ == BEFORE_OPEN && result == PP_OK)
134 open_state_ = OPENED;
135
136 // The callback may have been aborted by Close(), or the open operation is
137 // completed synchronously.
138 if (TrackedCallback::IsPending(open_callback_))
139 TrackedCallback::ClearAndRun(&open_callback_, result);
140 }
141
142 bool PPB_VideoCapture_Shared::SetStatus(PP_VideoCaptureStatus_Dev status,
143 bool forced) {
144 if (!forced) {
145 switch (status) {
146 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
147 if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPING)
148 return false;
149 break;
150 case PP_VIDEO_CAPTURE_STATUS_STARTING:
151 if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPED)
152 return false;
153 break;
154 case PP_VIDEO_CAPTURE_STATUS_STARTED:
155 switch (status_) {
156 case PP_VIDEO_CAPTURE_STATUS_STARTING:
157 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
158 break;
159 default:
160 return false;
161 }
162 break;
163 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
164 switch (status_) {
165 case PP_VIDEO_CAPTURE_STATUS_STARTING:
166 case PP_VIDEO_CAPTURE_STATUS_STARTED:
167 break;
168 default:
169 return false;
170 }
171 break;
172 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
173 switch (status_) {
174 case PP_VIDEO_CAPTURE_STATUS_STARTING:
175 case PP_VIDEO_CAPTURE_STATUS_STARTED:
176 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
177 break;
178 default:
179 return false;
180 }
181 break;
182 }
183 }
184
185 status_ = status;
186 return true;
187 }
188
189 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_video_capture_shared.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698