Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / pepper / pepper_video_capture_host.h
blob24061b5e750c577f179f867430bb3df7c304132d
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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/media/video_capture.h"
12 #include "content/public/renderer/renderer_ppapi_host.h"
13 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
14 #include "content/renderer/pepper/ppb_buffer_impl.h"
15 #include "media/base/video_capture_types.h"
16 #include "ppapi/c/dev/ppp_video_capture_dev.h"
17 #include "ppapi/host/host_message_context.h"
18 #include "ppapi/host/resource_host.h"
20 namespace media {
21 class VideoFrame;
22 } // namespace media
24 namespace content {
25 class PepperPlatformVideoCapture;
26 class RendererPpapiHostImpl;
28 class PepperVideoCaptureHost : public ppapi::host::ResourceHost {
29 public:
30 PepperVideoCaptureHost(RendererPpapiHostImpl* host,
31 PP_Instance instance,
32 PP_Resource resource);
34 ~PepperVideoCaptureHost() override;
36 bool Init();
38 int32_t OnResourceMessageReceived(
39 const IPC::Message& msg,
40 ppapi::host::HostMessageContext* context) override;
42 // These methods are called by PepperPlatformVideoCapture only.
44 // Called when video capture is initialized. We can start
45 // video capture if |succeeded| is true.
46 void OnInitialized(bool succeeded);
48 // Called when video capture has started successfully.
49 void OnStarted();
51 // Called when video capture has stopped. There will be no more
52 // frames delivered.
53 void OnStopped();
55 // Called when video capture has paused.
56 void OnPaused();
58 // Called when video capture cannot be started because of an error.
59 void OnError();
61 // Called when a video frame is ready.
62 void OnFrameReady(const scoped_refptr<media::VideoFrame>& frame);
64 private:
65 int32_t OnOpen(ppapi::host::HostMessageContext* context,
66 const std::string& device_id,
67 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
68 uint32_t buffer_count);
69 int32_t OnStartCapture(ppapi::host::HostMessageContext* context);
70 int32_t OnReuseBuffer(ppapi::host::HostMessageContext* context,
71 uint32_t buffer);
72 int32_t OnStopCapture(ppapi::host::HostMessageContext* context);
73 int32_t OnClose(ppapi::host::HostMessageContext* context);
75 int32_t StopCapture();
76 int32_t Close();
77 void PostErrorReply();
78 void AllocBuffers(const gfx::Size& resolution, int frame_rate);
79 void ReleaseBuffers();
80 void SendStatus();
82 void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info,
83 uint32_t buffer_count);
85 void DetachPlatformVideoCapture();
87 bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced);
89 scoped_ptr<PepperPlatformVideoCapture> platform_video_capture_;
91 // Buffers of video frame.
92 struct BufferInfo {
93 BufferInfo();
94 ~BufferInfo();
96 bool in_use;
97 void* data;
98 scoped_refptr<PPB_Buffer_Impl> buffer;
101 RendererPpapiHostImpl* renderer_ppapi_host_;
103 gfx::Size alloc_size_;
104 std::vector<BufferInfo> buffers_;
105 size_t buffer_count_hint_;
107 media::VideoCaptureParams video_capture_params_;
109 PP_VideoCaptureStatus_Dev status_;
111 ppapi::host::ReplyMessageContext open_reply_context_;
113 PepperDeviceEnumerationHostHelper enumeration_helper_;
115 DISALLOW_COPY_AND_ASSIGN(PepperVideoCaptureHost);
118 } // namespace content
120 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_