1 // Copyright 2015 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 #ifndef PPAPI_PROXY_CAMERA_DEVICE_RESOURCE_H_ 6 #define PPAPI_PROXY_CAMERA_DEVICE_RESOURCE_H_ 7 8 #include <stdint.h> 9 10 #include "base/macros.h" 11 #include "ppapi/c/pp_size.h" 12 #include "ppapi/c/private/pp_video_capture_format.h" 13 #include "ppapi/proxy/connection.h" 14 #include "ppapi/proxy/plugin_resource.h" 15 #include "ppapi/proxy/ppapi_proxy_export.h" 16 #include "ppapi/shared_impl/resource.h" 17 #include "ppapi/thunk/ppb_camera_device_api.h" 18 19 namespace ppapi { 20 namespace proxy { 21 22 class CameraCapabilitiesResource; 23 24 class PPAPI_PROXY_EXPORT CameraDeviceResource 25 : public PluginResource, 26 public thunk::PPB_CameraDevice_API { 27 public: 28 CameraDeviceResource(Connection connection, PP_Instance instance); 29 ~CameraDeviceResource() override; 30 31 // Resource overrides: AsPPB_CameraDevice_API()32 thunk::PPB_CameraDevice_API* AsPPB_CameraDevice_API() override { 33 return this; 34 } 35 36 // PPB_CameraDevice_API implementation. 37 int32_t Open(PP_Var device_id, 38 const scoped_refptr<TrackedCallback>& callback) override; 39 void Close() override; 40 int32_t GetCameraCapabilities( 41 PP_Resource* capabilities, 42 const scoped_refptr<TrackedCallback>& callback) override; 43 44 private: 45 enum class OpenState { BEFORE_OPEN, OPENED, CLOSED }; 46 47 void OnPluginMsgGetVideoCaptureFormatsReply( 48 PP_Resource* capabilities_output, 49 const ResourceMessageReplyParams& params, 50 const std::vector<PP_VideoCaptureFormat>& formats); 51 52 void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params); 53 is_opened()54 bool is_opened() const { return open_state_ == OpenState::OPENED; } 55 56 // Holds a reference of the callback so that Close() can cancel it. 57 scoped_refptr<TrackedCallback> open_callback_; 58 OpenState open_state_; 59 60 scoped_refptr<TrackedCallback> get_capabilities_callback_; 61 scoped_refptr<CameraCapabilitiesResource> camera_capabilities_; 62 63 DISALLOW_COPY_AND_ASSIGN(CameraDeviceResource); 64 }; 65 66 } // namespace proxy 67 } // namespace ppapi 68 69 #endif // PPAPI_PROXY_CAMERA_DEVICE_RESOURCE_H_ 70