OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/proxy/image_capture_resource.h" | |
6 | |
7 #include "ppapi/proxy/camera_capabilities_resource.h" | |
8 #include "ppapi/proxy/image_capture_config_resource.h" | |
9 #include "ppapi/proxy/plugin_globals.h" | |
10 #include "ppapi/proxy/plugin_resource_tracker.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/proxy/ppb_buffer_proxy.h" | |
13 #include "ppapi/shared_impl/proxy_lock.h" | |
14 #include "ppapi/shared_impl/var.h" | |
15 | |
16 namespace ppapi { | |
17 namespace proxy { | |
18 | |
19 ImageCaptureResource::ImageCaptureResource(Connection connection, | |
20 PP_Instance instance) | |
21 : PluginResource(connection, instance), | |
22 open_state_(BEFORE_OPEN), | |
23 get_capabilities_output_(NULL) { | |
24 SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create()); | |
25 } | |
26 | |
27 ImageCaptureResource::~ImageCaptureResource() { | |
28 } | |
29 | |
30 void ImageCaptureResource::OnReplyReceived( | |
31 const ResourceMessageReplyParams& params, | |
32 const IPC::Message& msg) { | |
33 if (params.sequence()) { | |
34 PluginResource::OnReplyReceived(params, msg); | |
35 return; | |
36 } | |
37 | |
38 PPAPI_BEGIN_MESSAGE_MAP(ImageCaptureResource, msg) | |
39 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED()) | |
dmichael (off chromium)
2015/01/28 00:00:36
If you're not actually handling any messages here,
wuchengli
2015/01/29 13:52:14
+1
Justin Chuang
2015/02/02 08:43:44
Done.
| |
40 PPAPI_END_MESSAGE_MAP() | |
41 } | |
42 | |
43 int32_t ImageCaptureResource::Open(PP_Var camera_source_id, | |
44 scoped_refptr<TrackedCallback> callback) { | |
45 if (open_state_ != BEFORE_OPEN) | |
46 return PP_ERROR_FAILED; | |
47 | |
48 if (TrackedCallback::IsPending(open_callback_)) | |
49 return PP_ERROR_INPROGRESS; | |
50 | |
51 scoped_refptr<StringVar> source_string_var; | |
52 source_string_var = StringVar::FromPPVar(camera_source_id); | |
53 if (!source_string_var.get() || source_string_var->value().size() == 0) | |
dmichael (off chromium)
2015/01/28 00:00:36
no need to say ".get()"
and ".empty()" is better t
Justin Chuang
2015/02/02 08:43:44
Done.
| |
54 return PP_ERROR_BADARGUMENT; | |
55 | |
56 open_callback_ = callback; | |
57 | |
58 Call<PpapiPluginMsg_ImageCapture_OpenReply>( | |
59 RENDERER, | |
60 PpapiHostMsg_ImageCapture_Open(source_string_var->value()), | |
61 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply, | |
62 base::Unretained(this))); | |
63 return PP_OK_COMPLETIONPENDING; | |
64 } | |
65 | |
66 void ImageCaptureResource::Close() { | |
67 if (open_state_ == CLOSED) | |
68 return; | |
69 | |
70 if (TrackedCallback::IsPending(open_callback_)) { | |
71 open_callback_->PostAbort(); | |
72 open_callback_ = NULL; | |
73 } | |
74 | |
75 if (TrackedCallback::IsPending(get_capabilities_callback_)) { | |
76 *get_capabilities_output_ = 0; | |
77 get_capabilities_callback_->PostAbort(); | |
78 get_capabilities_callback_ = NULL; | |
79 get_capabilities_output_ = NULL; | |
80 } | |
81 | |
82 Post(RENDERER, PpapiHostMsg_ImageCapture_Close()); | |
83 | |
84 open_state_ = CLOSED; | |
85 } | |
86 | |
87 int32_t ImageCaptureResource::SetConfig( | |
88 PP_Resource config, | |
89 scoped_refptr<TrackedCallback> callback) { | |
90 return PP_ERROR_NOTSUPPORTED; | |
91 } | |
92 | |
93 int32_t ImageCaptureResource::GetConfig( | |
94 PP_Resource* config, | |
95 scoped_refptr<TrackedCallback> callback) { | |
96 return PP_ERROR_NOTSUPPORTED; | |
97 } | |
98 | |
99 int32_t ImageCaptureResource::GetCameraCapabilities( | |
100 PP_Resource* capabilities, | |
101 scoped_refptr<TrackedCallback> callback) { | |
102 if (!IsOpened()) | |
103 return PP_ERROR_FAILED; | |
104 | |
105 if (TrackedCallback::IsPending(get_capabilities_callback_)) | |
106 return PP_ERROR_INPROGRESS; | |
107 | |
108 if (camera_capabilities_.get()) { | |
109 *capabilities = camera_capabilities_->GetReference(); | |
110 return PP_OK; | |
111 } | |
112 | |
113 get_capabilities_output_ = capabilities; | |
114 get_capabilities_callback_ = callback; | |
115 Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>( | |
116 RENDERER, | |
117 PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes(), | |
118 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply, | |
119 base::Unretained(this))); | |
120 return PP_OK_COMPLETIONPENDING; | |
121 } | |
122 | |
123 int32_t ImageCaptureResource::ReuseBuffers() { | |
124 return PP_ERROR_NOTSUPPORTED; | |
125 } | |
126 | |
127 int32_t ImageCaptureResource::CaptureStillImage( | |
128 PPB_ImageCapture_Private_ShutterCallback shutter_callback, | |
129 PPB_ImageCapture_Private_PreviewCallback preview_callback, | |
130 PPB_ImageCapture_Private_JpegCallback jpeg_callback, | |
131 PPB_ImageCapture_Private_ErrorCallback error_callback, | |
132 uint64_t* sequence_id) { | |
133 return PP_ERROR_NOTSUPPORTED; | |
134 } | |
135 | |
136 void ImageCaptureResource::OnPluginMsgOpenReply( | |
137 const ResourceMessageReplyParams& params) { | |
138 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK) | |
139 open_state_ = OPENED; | |
140 | |
141 // The callback may have been aborted by Close(). | |
142 if (TrackedCallback::IsPending(open_callback_)) | |
143 open_callback_->Run(params.result()); | |
144 } | |
145 | |
146 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply( | |
147 const ResourceMessageReplyParams& params, | |
148 const std::vector<PP_Size>& preview_sizes) { | |
149 // TODO(jchuang): support query of JPEG sizes, too. | |
150 if (!TrackedCallback::IsPending(get_capabilities_callback_)) | |
151 return; | |
152 | |
153 // Return camera capabilities. | |
154 int32_t result = params.result(); | |
155 scoped_refptr<TrackedCallback> callback; | |
156 callback.swap(get_capabilities_callback_); | |
157 if (result == PP_OK) { | |
158 camera_capabilities_ = new CameraCapabilitiesResource(pp_instance()); | |
159 camera_capabilities_->SetPreviewSizes(preview_sizes); | |
160 *get_capabilities_output_ = camera_capabilities_->GetReference(); | |
161 } | |
162 get_capabilities_output_ = NULL; | |
163 callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED); | |
164 } | |
165 | |
166 } // namespace proxy | |
167 } // namespace ppapi | |
OLD | NEW |