OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // VideoCaptureImpl represents a capture device in renderer process. It provides | 5 // VideoCaptureImpl represents a capture device in renderer process. It provides |
6 // interfaces for clients to Start/Stop capture. It also communicates to clients | 6 // interfaces for clients to Start/Stop capture. It also communicates to clients |
7 // when buffer is ready, state of capture device is changed. | 7 // when buffer is ready, state of capture device is changed. |
8 | 8 |
9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // VideoCaptureMessageFilter::Delegate interface. | 36 // VideoCaptureMessageFilter::Delegate interface. |
37 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 37 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
38 int length, int buffer_id); | 38 int length, int buffer_id); |
39 virtual void OnBufferReceived(int buffer_id, base::Time timestamp); | 39 virtual void OnBufferReceived(int buffer_id, base::Time timestamp); |
40 virtual void OnStateChanged(const media::VideoCapture::State& state); | 40 virtual void OnStateChanged(const media::VideoCapture::State& state); |
41 virtual void OnDeviceInfoReceived( | 41 virtual void OnDeviceInfoReceived( |
42 const media::VideoCaptureParams& device_info); | 42 const media::VideoCaptureParams& device_info); |
43 virtual void OnDelegateAdded(int32 device_id); | 43 virtual void OnDelegateAdded(int32 device_id); |
44 | 44 |
45 bool pending_start() { | |
46 return (new_params_.width > 0 && new_params_.height > 0); | |
47 } | |
48 | |
49 private: | 45 private: |
50 friend class VideoCaptureImplManager; | 46 friend class VideoCaptureImplManager; |
51 friend class VideoCaptureImplTest; | 47 friend class VideoCaptureImplTest; |
52 friend class MockVideoCaptureImpl; | 48 friend class MockVideoCaptureImpl; |
53 | 49 |
54 struct DIBBuffer { | 50 struct DIBBuffer; |
55 public: | |
56 DIBBuffer(base::SharedMemory* d, | |
57 media::VideoCapture::VideoFrameBuffer* ptr); | |
58 ~DIBBuffer(); | |
59 | |
60 base::SharedMemory* dib; | |
61 scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory; | |
62 }; | |
63 | 51 |
64 VideoCaptureImpl(media::VideoCaptureSessionId id, | 52 VideoCaptureImpl(media::VideoCaptureSessionId id, |
65 scoped_refptr<base::MessageLoopProxy> ml_proxy, | 53 scoped_refptr<base::MessageLoopProxy> ml_proxy, |
66 VideoCaptureMessageFilter* filter); | 54 VideoCaptureMessageFilter* filter); |
67 virtual ~VideoCaptureImpl(); | 55 virtual ~VideoCaptureImpl(); |
68 | 56 |
69 void DoStartCapture(media::VideoCapture::EventHandler* handler, | 57 void DoStartCapture(media::VideoCapture::EventHandler* handler, |
70 const VideoCaptureCapability& capability); | 58 const VideoCaptureCapability& capability); |
71 void DoStopCapture(media::VideoCapture::EventHandler* handler); | 59 void DoStopCapture(media::VideoCapture::EventHandler* handler); |
72 void DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer); | 60 void DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer); |
73 | 61 |
74 void DoBufferCreated(base::SharedMemoryHandle handle, | 62 void DoBufferCreated(base::SharedMemoryHandle handle, |
75 int length, int buffer_id); | 63 int length, int buffer_id); |
76 void DoBufferReceived(int buffer_id, base::Time timestamp); | 64 void DoBufferReceived(int buffer_id, base::Time timestamp); |
77 void DoStateChanged(const media::VideoCapture::State& state); | 65 void DoStateChanged(const media::VideoCapture::State& state); |
78 void DoDeviceInfoReceived(const media::VideoCaptureParams& device_info); | 66 void DoDeviceInfoReceived(const media::VideoCaptureParams& device_info); |
79 void DoDelegateAdded(int32 device_id); | 67 void DoDelegateAdded(int32 device_id); |
80 | 68 |
81 void Init(); | 69 void Init(); |
82 void DeInit(base::Closure task); | 70 void DeInit(base::Closure task); |
83 void StopDevice(); | 71 void StopDevice(); |
84 void RestartCapture(); | 72 void RestartCapture(); |
85 void StartCaptureInternal(); | 73 void StartCaptureInternal(); |
86 void AddDelegateOnIOThread(); | 74 void AddDelegateOnIOThread(); |
87 void RemoveDelegateOnIOThread(base::Closure task); | 75 void RemoveDelegateOnIOThread(base::Closure task); |
88 virtual void Send(IPC::Message* message); | 76 virtual void Send(IPC::Message* message); |
89 | 77 |
90 // Helpers. | 78 // Helpers. |
91 bool CapabilityMatchesParameters(const VideoCaptureCapability& capability, | 79 bool ClientHasDIB(); |
92 const media::VideoCaptureParams& params); | |
93 | 80 |
94 scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 81 scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
95 scoped_refptr<base::MessageLoopProxy> ml_proxy_; | 82 scoped_refptr<base::MessageLoopProxy> ml_proxy_; |
96 int device_id_; | 83 int device_id_; |
97 | 84 |
98 // Pool of DIBs. | 85 // Pool of DIBs. |
99 typedef std::map<int, DIBBuffer*> CachedDIB; | 86 typedef std::map<int /* buffer_id */, DIBBuffer*> CachedDIB; |
100 CachedDIB cached_dibs_; | 87 CachedDIB cached_dibs_; |
101 | 88 |
102 // DIBs at client side. The mapped value |int| means number of clients which | |
103 // hold this dib. | |
104 typedef std::map<media::VideoCapture::VideoFrameBuffer*, int> ClientSideDIB; | |
105 ClientSideDIB client_side_dibs_; | |
106 | |
107 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> | 89 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> |
108 ClientInfo; | 90 ClientInfo; |
109 ClientInfo clients_; | 91 ClientInfo clients_; |
110 std::list<media::VideoCapture::EventHandler*> master_clients_; | |
111 | 92 |
112 ClientInfo pending_clients_; | 93 ClientInfo clients_pending_on_filter_; |
perkj_chrome
2011/11/01 09:45:44
Consider using one map with all clients but add a
| |
94 ClientInfo clients_pending_on_restart_; | |
113 | 95 |
114 media::VideoFrame::Format video_type_; | 96 media::VideoFrame::Format video_type_; |
115 | 97 |
116 // The parameter is being used in current capture session. A capture session | 98 // The parameter is being used in current capture session. A capture session |
117 // starts with StartCapture and ends with StopCapture. | 99 // starts with StartCapture and ends with StopCapture. |
118 media::VideoCaptureParams current_params_; | 100 media::VideoCaptureParams current_params_; |
119 | 101 |
120 // The information about the device sent from browser process side. | 102 // The information about the device sent from browser process side. |
121 media::VideoCaptureParams device_info_; | 103 media::VideoCaptureParams device_info_; |
122 bool device_info_available_; | 104 bool device_info_available_; |
123 | 105 |
124 // The parameter will be used in next capture session. | |
125 media::VideoCaptureParams new_params_; | |
126 State state_; | 106 State state_; |
127 | 107 |
128 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 108 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
129 }; | 109 }; |
130 | 110 |
131 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); | 111 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); |
132 | 112 |
133 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 113 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |