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

Unified Diff: ppapi/proxy/image_capture_resource.cc

Issue 848863002: PPAPI: implement GetSupportedPreviewSizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error on Linux build Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/image_capture_resource.cc
diff --git a/ppapi/proxy/image_capture_resource.cc b/ppapi/proxy/image_capture_resource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a23c553e16134be5e4c38ef20d2849c1050804ec
--- /dev/null
+++ b/ppapi/proxy/image_capture_resource.cc
@@ -0,0 +1,168 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/image_capture_resource.h"
+
+#include "ppapi/proxy/camera_capabilities_resource.h"
+#include "ppapi/proxy/image_capture_config_resource.h"
+#include "ppapi/proxy/plugin_globals.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_buffer_proxy.h"
+#include "ppapi/shared_impl/proxy_lock.h"
+#include "ppapi/shared_impl/var.h"
+
+namespace ppapi {
+namespace proxy {
+
+ImageCaptureResource::ImageCaptureResource(Connection connection,
+ PP_Instance instance)
+ : PluginResource(connection, instance),
+ open_state_(BEFORE_OPEN),
+ get_capabilities_output_(NULL) {
+ SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create());
+}
+
+ImageCaptureResource::~ImageCaptureResource() {
+}
+
+void ImageCaptureResource::OnReplyReceived(
+ const ResourceMessageReplyParams& params,
+ const IPC::Message& msg) {
+ if (params.sequence()) {
+ PluginResource::OnReplyReceived(params, msg);
+ return;
+ }
+
+ PPAPI_BEGIN_MESSAGE_MAP(ImageCaptureResource, msg)
+
wuchengli 2015/01/19 14:05:03 remove extra blank line
Justin Chuang 2015/01/26 15:00:51 Done.
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED())
wuchengli 2015/01/19 14:05:03 You mean everything should be already handled in l
Justin Chuang 2015/01/26 15:00:51 I think keeping it as-as is okay.
+ PPAPI_END_MESSAGE_MAP()
+}
+
+int32_t ImageCaptureResource::Open(PP_Var camera_source_id,
+ scoped_refptr<TrackedCallback> callback) {
+ if (open_state_ != BEFORE_OPEN)
+ return PP_ERROR_FAILED;
+
+ if (TrackedCallback::IsPending(open_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ scoped_refptr<StringVar> source_string_var;
+ source_string_var = StringVar::FromPPVar(camera_source_id);
+ if (!source_string_var.get() || source_string_var->value().size() == 0)
+ return PP_ERROR_BADARGUMENT;
+
+ open_callback_ = callback;
+
+ Call<PpapiPluginMsg_ImageCapture_OpenReply>(
+ RENDERER,
+ PpapiHostMsg_ImageCapture_Open(source_string_var->value()),
+ base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply,
+ base::Unretained(this)));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void ImageCaptureResource::Close() {
+ if (open_state_ == CLOSED)
+ return;
+
+ if (TrackedCallback::IsPending(open_callback_)) {
+ open_callback_->PostAbort();
+ open_callback_ = NULL;
+ }
+
+ if (TrackedCallback::IsPending(get_capabilities_callback_)) {
+ *get_capabilities_output_ = 0;
+ get_capabilities_callback_->PostAbort();
+ get_capabilities_callback_ = NULL;
+ get_capabilities_output_ = NULL;
+ }
+
+ Post(RENDERER, PpapiHostMsg_ImageCapture_Close());
+
+ open_state_ = CLOSED;
+}
+
+int32_t ImageCaptureResource::SetConfig(
+ PP_Resource config,
+ scoped_refptr<TrackedCallback> callback) {
+ return PP_ERROR_NOTSUPPORTED;
+}
+
+int32_t ImageCaptureResource::GetConfig(
+ PP_Resource* config,
+ scoped_refptr<TrackedCallback> callback) {
+ return PP_ERROR_NOTSUPPORTED;
+}
+
+int32_t ImageCaptureResource::GetCameraCapabilities(
+ PP_Resource* capabilities,
+ scoped_refptr<TrackedCallback> callback) {
+ if (!IsOpened())
+ return PP_ERROR_FAILED;
+
+ if (TrackedCallback::IsPending(get_capabilities_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ if (camera_capabilities_.get()) {
+ *capabilities = camera_capabilities_->GetReference();
+ return PP_OK;
+ }
+
+ get_capabilities_output_ = capabilities;
+ get_capabilities_callback_ = callback;
+ Call<PpapiPluginMsg_ImageCapture_GetPreviewSizesReply>(
+ RENDERER,
+ PpapiPluginMsg_ImageCapture_GetPreviewSizes(),
+ base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply,
+ base::Unretained(this)));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t ImageCaptureResource::ReuseBuffers() {
+ return PP_ERROR_NOTSUPPORTED;
+}
+
+int32_t ImageCaptureResource::CaptureStillImage(
+ PPB_ImageCapture_Private_ShutterCallback shutter_callback,
+ PPB_ImageCapture_Private_PreviewCallback preview_callback,
+ PPB_ImageCapture_Private_JpegCallback jpeg_callback,
+ PPB_ImageCapture_Private_ErrorCallback error_callback,
+ uint64_t* sequence_id) {
+ return PP_ERROR_NOTSUPPORTED;
+}
+
+void ImageCaptureResource::OnPluginMsgOpenReply(
+ const ResourceMessageReplyParams& params) {
+ if (open_state_ == BEFORE_OPEN && params.result() == PP_OK)
+ open_state_ = OPENED;
+
+ // The callback may have been aborted by Close().
+ if (TrackedCallback::IsPending(open_callback_))
+ open_callback_->Run(params.result());
+}
+
+void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply(
+ const ResourceMessageReplyParams& params,
+ const std::vector<PP_Size>& preview_sizes) {
+ // TODO(jchuang): support query of JPEG sizes, too.
wuchengli 2015/01/19 14:05:03 Remove TODO.
Justin Chuang 2015/01/26 15:00:51 Why not keep it?
+ if (!TrackedCallback::IsPending(get_capabilities_callback_))
+ return;
+
+ // Return camera capabilities.
+ int32_t result = params.result();
+ scoped_refptr<TrackedCallback> callback;
+ callback.swap(get_capabilities_callback_);
+ if (result == PP_OK) {
+ camera_capabilities_ = new CameraCapabilitiesResource(pp_instance());
+ camera_capabilities_->SetPreviewSizes(preview_sizes);
+ *get_capabilities_output_ = camera_capabilities_->GetReference();
+ }
+ get_capabilities_output_ = NULL;
+ callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED);
+}
+
+} // namespace proxy
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698