OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "media/video/capture/video_capture.h" | 13 #include "media/video/capture/video_capture.h" |
14 #include "ppapi/c/dev/ppp_video_capture_dev.h" | 14 #include "ppapi/c/dev/ppp_video_capture_dev.h" |
15 #include "ppapi/shared_impl/resource.h" | 15 #include "ppapi/shared_impl/resource.h" |
16 #include "ppapi/shared_impl/tracked_callback.h" | |
16 #include "ppapi/thunk/ppb_video_capture_api.h" | 17 #include "ppapi/thunk/ppb_video_capture_api.h" |
17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 18 #include "webkit/plugins/ppapi/plugin_delegate.h" |
18 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 19 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
19 | 20 |
20 struct PP_VideoCaptureDeviceInfo_Dev; | 21 struct PP_VideoCaptureDeviceInfo_Dev; |
21 | 22 |
22 namespace webkit { | 23 namespace webkit { |
23 namespace ppapi { | 24 namespace ppapi { |
24 | 25 |
25 class PPB_VideoCapture_Impl : public ::ppapi::Resource, | 26 class PPB_VideoCapture_Impl |
26 public ::ppapi::thunk::PPB_VideoCapture_API, | 27 : public ::ppapi::Resource, |
27 public media::VideoCapture::EventHandler { | 28 public ::ppapi::thunk::PPB_VideoCapture_API, |
29 public PluginDelegate::PlatformVideoCaptureEventHandler { | |
28 public: | 30 public: |
29 explicit PPB_VideoCapture_Impl(PP_Instance instance); | 31 explicit PPB_VideoCapture_Impl(PP_Instance instance); |
30 virtual ~PPB_VideoCapture_Impl(); | 32 virtual ~PPB_VideoCapture_Impl(); |
31 | 33 |
32 bool Init(); | 34 bool Init(); |
33 | 35 |
34 // Resource overrides. | 36 // Resource overrides. |
35 virtual PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; | 37 virtual PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; |
36 virtual void LastPluginRefWasDeleted() OVERRIDE; | |
37 | 38 |
38 // PPB_VideoCapture implementation. | 39 // PPB_VideoCapture_API implementation. |
40 virtual int32_t EnumerateDevices(PP_CompletionCallback callback) OVERRIDE; | |
41 virtual PP_Resource GetDevices() OVERRIDE; | |
39 virtual int32_t StartCapture( | 42 virtual int32_t StartCapture( |
43 const std::string& device_id, | |
40 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | 44 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
41 uint32_t buffer_count) OVERRIDE; | 45 uint32_t buffer_count) OVERRIDE; |
42 virtual int32_t ReuseBuffer(uint32_t buffer) OVERRIDE; | 46 virtual int32_t ReuseBuffer(uint32_t buffer) OVERRIDE; |
43 virtual int32_t StopCapture() OVERRIDE; | 47 virtual int32_t StopCapture() OVERRIDE; |
48 virtual const std::vector<::ppapi::DeviceRefData>& GetDeviceRefData( | |
49 ) const OVERRIDE; | |
44 | 50 |
45 // media::VideoCapture::EventHandler implementation. | 51 // PluginDelegate::PlatformVideoCaptureEventHandler implementation. |
46 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE; | 52 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE; |
47 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE; | 53 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE; |
48 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE; | 54 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE; |
49 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE; | 55 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE; |
50 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE; | 56 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE; |
51 virtual void OnBufferReady( | 57 virtual void OnBufferReady( |
52 media::VideoCapture* capture, | 58 media::VideoCapture* capture, |
53 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) OVERRIDE; | 59 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) OVERRIDE; |
54 virtual void OnDeviceInfoReceived( | 60 virtual void OnDeviceInfoReceived( |
55 media::VideoCapture* capture, | 61 media::VideoCapture* capture, |
56 const media::VideoCaptureParams& device_info) OVERRIDE; | 62 const media::VideoCaptureParams& device_info) OVERRIDE; |
63 virtual void OnInitialized(media::VideoCapture* capture, | |
64 bool succeeded) OVERRIDE; | |
57 | 65 |
58 private: | 66 private: |
59 void ReleaseBuffers(); | 67 void ReleaseBuffers(); |
60 void SendStatus(); | 68 void SendStatus(); |
61 | 69 |
62 scoped_ptr<PluginDelegate::PlatformVideoCapture> platform_video_capture_; | 70 void ClearCachedDeviceResourceArray(); |
71 void DetachPlatformVideoCapture(); | |
72 | |
73 void OnEnumerateDevicesComplete( | |
74 int request_id, | |
75 bool succeeded, | |
76 const std::vector<::ppapi::DeviceRefData>& devices); | |
77 | |
78 scoped_refptr<PluginDelegate::PlatformVideoCapture> platform_video_capture_; | |
63 | 79 |
64 size_t buffer_count_hint_; | 80 size_t buffer_count_hint_; |
65 struct BufferInfo { | 81 struct BufferInfo { |
66 BufferInfo(); | 82 BufferInfo(); |
67 ~BufferInfo(); | 83 ~BufferInfo(); |
68 | 84 |
69 bool in_use; | 85 bool in_use; |
70 void* data; | 86 void* data; |
71 scoped_refptr<PPB_Buffer_Impl> buffer; | 87 scoped_refptr<PPB_Buffer_Impl> buffer; |
72 }; | 88 }; |
73 std::vector<BufferInfo> buffers_; | 89 std::vector<BufferInfo> buffers_; |
74 | 90 |
75 const PPP_VideoCapture_Dev* ppp_videocapture_; | 91 const PPP_VideoCapture_Dev* ppp_videocapture_; |
76 PP_VideoCaptureStatus_Dev status_; | 92 PP_VideoCaptureStatus_Dev status_; |
77 | 93 |
78 // Signifies that the plugin has given up all its refs, but the object is | 94 scoped_refptr<::ppapi::TrackedCallback> enumerate_devices_callback_; |
79 // still alive, possibly because the backend hasn't released the object as | 95 |
80 // |EventHandler| yet. It can be removed if/when |EventHandler| is made to be | 96 base::WeakPtrFactory<PPB_VideoCapture_Impl> weak_ptr_factory_; |
piman
2012/01/28 08:26:55
Same here: do we need this, given that the class i
yzshen1
2012/01/29 21:58:32
I prefer using weak pointer in this case. I would
| |
81 // refcounted (and made into a "member" of this object instead). | 97 |
82 bool is_dead_; | 98 // A resource array holding the enumeration result. When nonzero, we're |
99 // holding a reference to it. | |
100 PP_Resource devices_; | |
101 std::vector<::ppapi::DeviceRefData> devices_data_; | |
102 | |
103 media::VideoCapture::VideoCaptureCapability capability_; | |
83 | 104 |
84 DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Impl); | 105 DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Impl); |
85 }; | 106 }; |
86 | 107 |
87 } // namespace ppapi | 108 } // namespace ppapi |
88 } // namespace webkit | 109 } // namespace webkit |
89 | 110 |
90 #endif // WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ | 111 #endif // WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |