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