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 CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ 6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/ref_counted.h" 10 #include "content/public/renderer/renderer_ppapi_host.h" 11 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" 12 #include "content/renderer/pepper/ppb_buffer_impl.h" 13 #include "media/video/capture/video_capture.h" 14 #include "media/video/capture/video_capture_types.h" 15 #include "ppapi/c/dev/ppp_video_capture_dev.h" 16 #include "ppapi/host/host_message_context.h" 17 #include "ppapi/host/resource_host.h" 18 19 namespace content { 20 class PepperPlatformVideoCapture; 21 class RendererPpapiHostImpl; 22 23 class PepperVideoCaptureHost 24 : public ppapi::host::ResourceHost, 25 public media::VideoCapture::EventHandler { 26 public: 27 PepperVideoCaptureHost(RendererPpapiHostImpl* host, 28 PP_Instance instance, 29 PP_Resource resource); 30 31 virtual ~PepperVideoCaptureHost(); 32 33 bool Init(); 34 35 virtual int32_t OnResourceMessageReceived( 36 const IPC::Message& msg, 37 ppapi::host::HostMessageContext* context) OVERRIDE; 38 39 void OnInitialized(media::VideoCapture* capture, bool succeeded); 40 41 // media::VideoCapture::EventHandler 42 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE; 43 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE; 44 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE; 45 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE; 46 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE; 47 virtual void OnBufferReady( 48 media::VideoCapture* capture, 49 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) OVERRIDE; 50 virtual void OnDeviceInfoReceived( 51 media::VideoCapture* capture, 52 const media::VideoCaptureParams& device_info) OVERRIDE; 53 54 private: 55 int32_t OnOpen(ppapi::host::HostMessageContext* context, 56 const std::string& device_id, 57 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 58 uint32_t buffer_count); 59 int32_t OnStartCapture(ppapi::host::HostMessageContext* context); 60 int32_t OnReuseBuffer(ppapi::host::HostMessageContext* context, 61 uint32_t buffer); 62 int32_t OnStopCapture(ppapi::host::HostMessageContext* context); 63 int32_t OnClose(ppapi::host::HostMessageContext* context); 64 65 int32_t StopCapture(); 66 int32_t Close(); 67 void ReleaseBuffers(); 68 void SendStatus(); 69 70 void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info, 71 uint32_t buffer_count); 72 73 void DetachPlatformVideoCapture(); 74 75 bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced); 76 77 scoped_refptr<PepperPlatformVideoCapture> platform_video_capture_; 78 79 // Buffers of video frame. 80 struct BufferInfo { 81 BufferInfo(); 82 ~BufferInfo(); 83 84 bool in_use; 85 void* data; 86 scoped_refptr<PPB_Buffer_Impl> buffer; 87 }; 88 89 RendererPpapiHostImpl* renderer_ppapi_host_; 90 91 std::vector<BufferInfo> buffers_; 92 size_t buffer_count_hint_; 93 94 media::VideoCaptureCapability capability_; 95 96 PP_VideoCaptureStatus_Dev status_; 97 98 ppapi::host::ReplyMessageContext open_reply_context_; 99 100 PepperDeviceEnumerationHostHelper enumeration_helper_; 101 102 DISALLOW_COPY_AND_ASSIGN(PepperVideoCaptureHost); 103 }; 104 105 } // namespace content 106 107 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ 108