Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / ppapi / proxy / video_capture_resource.h
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 #ifndef PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_
6 #define PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_
7
8 #include "base/compiler_specific.h"
9 #include "ppapi/c/dev/ppp_video_capture_dev.h"
10 #include "ppapi/proxy/device_enumeration_resource_helper.h"
11 #include "ppapi/proxy/plugin_resource.h"
12 #include "ppapi/thunk/ppb_video_capture_api.h"
13
14 namespace ppapi {
15 namespace proxy {
16
17 class VideoCaptureResource
18     : public PluginResource,
19       public ::ppapi::thunk::PPB_VideoCapture_API {
20  public:
21   VideoCaptureResource(Connection connection,
22                        PP_Instance instance,
23                        PluginDispatcher* dispatcher);
24   virtual ~VideoCaptureResource();
25
26   // PluginResource override.
27   virtual thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() override {
28     return this;
29   }
30
31   // PPB_VideoCapture_API implementation.
32   virtual int32_t EnumerateDevices(
33       const PP_ArrayOutput& output,
34       scoped_refptr<TrackedCallback> callback) override;
35   virtual int32_t MonitorDeviceChange(
36       PP_MonitorDeviceChangeCallback callback,
37       void* user_data) override;
38   virtual int32_t Open(const std::string& device_id,
39                        const PP_VideoCaptureDeviceInfo_Dev& requested_info,
40                        uint32_t buffer_count,
41                        scoped_refptr<TrackedCallback> callback) override;
42   virtual int32_t StartCapture() override;
43   virtual int32_t ReuseBuffer(uint32_t buffer) override;
44   virtual int32_t StopCapture() override;
45   virtual void Close() override;
46   virtual int32_t EnumerateDevicesSync(const PP_ArrayOutput& devices) override;
47
48  protected:
49   // Resource override.
50   virtual void LastPluginRefWasDeleted() override;
51
52  private:
53   enum OpenState {
54     BEFORE_OPEN,
55     OPENED,
56     CLOSED
57   };
58
59   // PluginResource overrides.
60   virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
61                                const IPC::Message& msg) override;
62
63   void OnPluginMsgOnDeviceInfo(const ResourceMessageReplyParams& params,
64                                const struct PP_VideoCaptureDeviceInfo_Dev& info,
65                                const std::vector<HostResource>& buffers,
66                                uint32_t buffer_size);
67   void OnPluginMsgOnStatus(const ResourceMessageReplyParams& params,
68                            uint32_t status);
69   void OnPluginMsgOnError(const ResourceMessageReplyParams& params,
70                           uint32_t error);
71   void OnPluginMsgOnBufferReady(const ResourceMessageReplyParams& params,
72                                 uint32_t buffer);
73
74   void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params);
75
76   void SetBufferInUse(uint32_t buffer_index);
77
78   // Points to the C interface of client implementation.
79   const PPP_VideoCapture_Dev* ppp_video_capture_impl_;
80
81   // Indicates that the i-th buffer is currently in use.
82   std::vector<bool> buffer_in_use_;
83
84   // Holds a reference of the callback so that Close() can cancel it.
85   scoped_refptr<TrackedCallback> open_callback_;
86   OpenState open_state_;
87
88   DeviceEnumerationResourceHelper enumeration_helper_;
89
90   DISALLOW_COPY_AND_ASSIGN(VideoCaptureResource);
91 };
92
93 }  // namespace proxy
94 }  // namespace ppapi
95
96 #endif  // PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_