OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/common/media/video_capture.h" |
10 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.h" |
11 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" | 13 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" |
12 #include "content/renderer/pepper/ppb_buffer_impl.h" | 14 #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 "media/video/capture/video_capture_types.h" |
15 #include "ppapi/c/dev/ppp_video_capture_dev.h" | 16 #include "ppapi/c/dev/ppp_video_capture_dev.h" |
16 #include "ppapi/host/host_message_context.h" | 17 #include "ppapi/host/host_message_context.h" |
17 #include "ppapi/host/resource_host.h" | 18 #include "ppapi/host/resource_host.h" |
18 | 19 |
| 20 namespace media { |
| 21 class VideoFrame; |
| 22 } // namespace media |
| 23 |
19 namespace content { | 24 namespace content { |
20 class PepperPlatformVideoCapture; | 25 class PepperPlatformVideoCapture; |
21 class RendererPpapiHostImpl; | 26 class RendererPpapiHostImpl; |
22 | 27 |
23 class PepperVideoCaptureHost : public ppapi::host::ResourceHost, | 28 class PepperVideoCaptureHost : public ppapi::host::ResourceHost { |
24 public media::VideoCapture::EventHandler { | |
25 public: | 29 public: |
26 PepperVideoCaptureHost(RendererPpapiHostImpl* host, | 30 PepperVideoCaptureHost(RendererPpapiHostImpl* host, |
27 PP_Instance instance, | 31 PP_Instance instance, |
28 PP_Resource resource); | 32 PP_Resource resource); |
29 | 33 |
30 virtual ~PepperVideoCaptureHost(); | 34 virtual ~PepperVideoCaptureHost(); |
31 | 35 |
32 bool Init(); | 36 bool Init(); |
33 | 37 |
34 virtual int32_t OnResourceMessageReceived( | 38 virtual int32_t OnResourceMessageReceived( |
35 const IPC::Message& msg, | 39 const IPC::Message& msg, |
36 ppapi::host::HostMessageContext* context) OVERRIDE; | 40 ppapi::host::HostMessageContext* context) OVERRIDE; |
37 | 41 |
38 void OnInitialized(media::VideoCapture* capture, bool succeeded); | 42 // These methods are called by PepperPlatformVideoCapture only. |
39 | 43 |
40 // media::VideoCapture::EventHandler | 44 // Called when video capture is initialized. We can start |
41 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE; | 45 // video capture if |succeeded| is true. |
42 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE; | 46 void OnInitialized(bool succeeded); |
43 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE; | 47 |
44 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE; | 48 // Called when video capture has started successfully. |
45 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE; | 49 void OnStarted(); |
46 virtual void OnFrameReady(media::VideoCapture* capture, | 50 |
47 const scoped_refptr<media::VideoFrame>& frame) | 51 // Called when video capture has stopped. There will be no more |
48 OVERRIDE; | 52 // frames delivered. |
| 53 void OnStopped(); |
| 54 |
| 55 // Called when video capture has paused. |
| 56 void OnPaused(); |
| 57 |
| 58 // Called when video capture cannot be started because of an error. |
| 59 void OnError(); |
| 60 |
| 61 // Called when a video frame is ready. |
| 62 void OnFrameReady(const scoped_refptr<media::VideoFrame>& frame, |
| 63 media::VideoCaptureFormat format); |
49 | 64 |
50 private: | 65 private: |
51 int32_t OnOpen(ppapi::host::HostMessageContext* context, | 66 int32_t OnOpen(ppapi::host::HostMessageContext* context, |
52 const std::string& device_id, | 67 const std::string& device_id, |
53 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | 68 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
54 uint32_t buffer_count); | 69 uint32_t buffer_count); |
55 int32_t OnStartCapture(ppapi::host::HostMessageContext* context); | 70 int32_t OnStartCapture(ppapi::host::HostMessageContext* context); |
56 int32_t OnReuseBuffer(ppapi::host::HostMessageContext* context, | 71 int32_t OnReuseBuffer(ppapi::host::HostMessageContext* context, |
57 uint32_t buffer); | 72 uint32_t buffer); |
58 int32_t OnStopCapture(ppapi::host::HostMessageContext* context); | 73 int32_t OnStopCapture(ppapi::host::HostMessageContext* context); |
59 int32_t OnClose(ppapi::host::HostMessageContext* context); | 74 int32_t OnClose(ppapi::host::HostMessageContext* context); |
60 | 75 |
61 int32_t StopCapture(); | 76 int32_t StopCapture(); |
62 int32_t Close(); | 77 int32_t Close(); |
63 void PostErrorReply(); | 78 void PostErrorReply(); |
64 void AllocBuffers(const gfx::Size& resolution, int frame_rate); | 79 void AllocBuffers(const gfx::Size& resolution, int frame_rate); |
65 void ReleaseBuffers(); | 80 void ReleaseBuffers(); |
66 void SendStatus(); | 81 void SendStatus(); |
67 | 82 |
68 void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info, | 83 void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info, |
69 uint32_t buffer_count); | 84 uint32_t buffer_count); |
70 | 85 |
71 void DetachPlatformVideoCapture(); | 86 void DetachPlatformVideoCapture(); |
72 | 87 |
73 bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced); | 88 bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced); |
74 | 89 |
75 scoped_refptr<PepperPlatformVideoCapture> platform_video_capture_; | 90 scoped_ptr<PepperPlatformVideoCapture> platform_video_capture_; |
76 | 91 |
77 // Buffers of video frame. | 92 // Buffers of video frame. |
78 struct BufferInfo { | 93 struct BufferInfo { |
79 BufferInfo(); | 94 BufferInfo(); |
80 ~BufferInfo(); | 95 ~BufferInfo(); |
81 | 96 |
82 bool in_use; | 97 bool in_use; |
83 void* data; | 98 void* data; |
84 scoped_refptr<PPB_Buffer_Impl> buffer; | 99 scoped_refptr<PPB_Buffer_Impl> buffer; |
85 }; | 100 }; |
(...skipping 11 matching lines...) Expand all Loading... |
97 ppapi::host::ReplyMessageContext open_reply_context_; | 112 ppapi::host::ReplyMessageContext open_reply_context_; |
98 | 113 |
99 PepperDeviceEnumerationHostHelper enumeration_helper_; | 114 PepperDeviceEnumerationHostHelper enumeration_helper_; |
100 | 115 |
101 DISALLOW_COPY_AND_ASSIGN(PepperVideoCaptureHost); | 116 DISALLOW_COPY_AND_ASSIGN(PepperVideoCaptureHost); |
102 }; | 117 }; |
103 | 118 |
104 } // namespace content | 119 } // namespace content |
105 | 120 |
106 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ | 121 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_ |
OLD | NEW |