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"
25 class PepperPlatformVideoCapture
;
26 class RendererPpapiHostImpl
;
28 class PepperVideoCaptureHost
: public ppapi::host::ResourceHost
{
30 PepperVideoCaptureHost(RendererPpapiHostImpl
* host
,
32 PP_Resource resource
);
34 ~PepperVideoCaptureHost() override
;
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.
51 // Called when video capture has stopped. There will be no more
55 // Called when video capture has paused.
58 // Called when video capture cannot be started because of an error.
61 // Called when a video frame is ready.
62 void OnFrameReady(const scoped_refptr
<media::VideoFrame
>& frame
);
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
,
72 int32_t OnStopCapture(ppapi::host::HostMessageContext
* context
);
73 int32_t OnClose(ppapi::host::HostMessageContext
* context
);
75 int32_t StopCapture();
77 void PostErrorReply();
78 void AllocBuffers(const gfx::Size
& resolution
, int frame_rate
);
79 void ReleaseBuffers();
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.
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_