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 // 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 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which | 9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays |
10 // relays operation of capture device to browser process and receives response | 10 // operation of a capture device to the browser process and receives responses |
11 // from browser process. | 11 // from browser process. |
12 | 12 |
13 // The media::VideoCapture and VideoCaptureMessageFilter::Delegate are | 13 // The media::VideoCapture and VideoCaptureMessageFilter::Delegate are |
14 // asynchronous interfaces, which means callers can call those interfaces | 14 // asynchronous interfaces, which means callers can call those interfaces |
15 // from any threads without worrying about thread safety. | 15 // from any threads without worrying about thread safety. |
16 // The |capture_message_loop_proxy_| is the working thread of VideoCaptureImpl. | 16 // The |capture_message_loop_proxy_| is the working thread of VideoCaptureImpl. |
17 // All non-const members are accessed only on that working thread. | 17 // All non-const members are accessed only on that working thread. |
18 // | 18 // |
19 // Implementation note: tasks are posted bound to Unretained(this) to both the | 19 // Implementation note: tasks are posted bound to Unretained(this) to both the |
20 // I/O and Capture threads and this is safe (even though the I/O thread is | 20 // I/O and Capture threads and this is safe (even though the I/O thread is |
(...skipping 24 matching lines...) Expand all Loading... |
45 } | 45 } |
46 | 46 |
47 namespace content { | 47 namespace content { |
48 | 48 |
49 class CONTENT_EXPORT VideoCaptureImpl | 49 class CONTENT_EXPORT VideoCaptureImpl |
50 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { | 50 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { |
51 public: | 51 public: |
52 // media::VideoCapture interface. | 52 // media::VideoCapture interface. |
53 virtual void StartCapture( | 53 virtual void StartCapture( |
54 media::VideoCapture::EventHandler* handler, | 54 media::VideoCapture::EventHandler* handler, |
55 const media::VideoCaptureCapability& capability) OVERRIDE; | 55 const media::VideoCaptureParams& params) OVERRIDE; |
56 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | 56 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; |
57 virtual bool CaptureStarted() OVERRIDE; | 57 virtual bool CaptureStarted() OVERRIDE; |
58 virtual int CaptureWidth() OVERRIDE; | 58 virtual int CaptureWidth() OVERRIDE; |
59 virtual int CaptureHeight() OVERRIDE; | 59 virtual int CaptureHeight() OVERRIDE; |
60 virtual int CaptureFrameRate() OVERRIDE; | 60 virtual int CaptureFrameRate() OVERRIDE; |
61 | 61 |
62 // VideoCaptureMessageFilter::Delegate interface. | 62 // VideoCaptureMessageFilter::Delegate interface. |
63 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 63 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
64 int length, int buffer_id) OVERRIDE; | 64 int length, |
65 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; | 65 int buffer_id) OVERRIDE; |
| 66 virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; |
| 67 virtual void OnBufferReceived( |
| 68 int buffer_id, |
| 69 base::Time timestamp, |
| 70 const media::VideoCaptureFormat& format) OVERRIDE; |
66 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; | 71 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
67 virtual void OnDeviceInfoReceived( | |
68 const media::VideoCaptureParams& device_info) OVERRIDE; | |
69 virtual void OnDeviceInfoChanged( | |
70 const media::VideoCaptureParams& device_info) OVERRIDE; | |
71 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; | 72 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
72 | 73 |
73 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 74 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
74 virtual void SuspendCapture(bool suspend); | 75 virtual void SuspendCapture(bool suspend); |
75 | 76 |
76 private: | 77 private: |
77 friend class VideoCaptureImplManager; | 78 friend class VideoCaptureImplManager; |
78 friend class VideoCaptureImplTest; | 79 friend class VideoCaptureImplTest; |
79 friend class MockVideoCaptureImpl; | 80 friend class MockVideoCaptureImpl; |
80 | 81 |
81 class ClientBuffer; | 82 class ClientBuffer; |
82 typedef std::map<media::VideoCapture::EventHandler*, | 83 typedef std::map<media::VideoCapture::EventHandler*, |
83 media::VideoCaptureCapability> ClientInfo; | 84 media::VideoCaptureParams> ClientInfo; |
84 | 85 |
85 VideoCaptureImpl(media::VideoCaptureSessionId id, | 86 VideoCaptureImpl(media::VideoCaptureSessionId session_id, |
86 base::MessageLoopProxy* capture_message_loop_proxy, | 87 base::MessageLoopProxy* capture_message_loop_proxy, |
87 VideoCaptureMessageFilter* filter); | 88 VideoCaptureMessageFilter* filter); |
88 virtual ~VideoCaptureImpl(); | 89 virtual ~VideoCaptureImpl(); |
89 | 90 |
90 void DoStartCaptureOnCaptureThread( | 91 void DoStartCaptureOnCaptureThread( |
91 media::VideoCapture::EventHandler* handler, | 92 media::VideoCapture::EventHandler* handler, |
92 const media::VideoCaptureCapability& capability); | 93 const media::VideoCaptureParams& params); |
93 void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler); | 94 void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler); |
94 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, | 95 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
95 int length, int buffer_id); | 96 int length, |
96 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); | 97 int buffer_id); |
| 98 void DoBufferDestroyedOnCaptureThread(int buffer_id); |
| 99 void DoBufferReceivedOnCaptureThread( |
| 100 int buffer_id, |
| 101 base::Time timestamp, |
| 102 const media::VideoCaptureFormat& format); |
97 void DoClientBufferFinishedOnCaptureThread( | 103 void DoClientBufferFinishedOnCaptureThread( |
98 int buffer_id, | 104 int buffer_id, |
99 const scoped_refptr<ClientBuffer>& buffer); | 105 const scoped_refptr<ClientBuffer>& buffer); |
100 void DoStateChangedOnCaptureThread(VideoCaptureState state); | 106 void DoStateChangedOnCaptureThread(VideoCaptureState state); |
101 void DoDeviceInfoReceivedOnCaptureThread( | |
102 const media::VideoCaptureParams& device_info); | |
103 void DoDeviceInfoChangedOnCaptureThread( | |
104 const media::VideoCaptureParams& device_info); | |
105 void DoDelegateAddedOnCaptureThread(int32 device_id); | 107 void DoDelegateAddedOnCaptureThread(int32 device_id); |
106 | 108 |
107 void DoSuspendCaptureOnCaptureThread(bool suspend); | 109 void DoSuspendCaptureOnCaptureThread(bool suspend); |
108 | 110 |
109 void Init(); | 111 void Init(); |
110 void DeInit(base::Closure task); | 112 void DeInit(base::Closure task); |
111 void DoDeInitOnCaptureThread(base::Closure task); | 113 void DoDeInitOnCaptureThread(base::Closure task); |
112 void StopDevice(); | 114 void StopDevice(); |
113 void RestartCapture(); | 115 void RestartCapture(); |
114 void StartCaptureInternal(); | 116 void StartCaptureInternal(); |
115 void AddDelegateOnIOThread(); | 117 void AddDelegateOnIOThread(); |
116 void RemoveDelegateOnIOThread(base::Closure task); | 118 void RemoveDelegateOnIOThread(base::Closure task); |
117 virtual void Send(IPC::Message* message); | 119 virtual void Send(IPC::Message* message); |
118 | 120 |
119 // Helpers. | 121 // Helpers. |
120 bool RemoveClient(media::VideoCapture::EventHandler* handler, | 122 bool RemoveClient(media::VideoCapture::EventHandler* handler, |
121 ClientInfo* clients); | 123 ClientInfo* clients); |
122 | 124 |
123 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 125 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
124 const scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; | 126 const scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; |
125 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 127 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
126 int device_id_; | 128 int device_id_; |
| 129 const int session_id_; |
127 | 130 |
128 // Buffers available for sending to the client. | 131 // Buffers available for sending to the client. |
129 typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap; | 132 typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap; |
130 ClientBufferMap client_buffers_; | 133 ClientBufferMap client_buffers_; |
131 // WeakPtrFactory pointing back to |this| object, for use with | 134 // WeakPtrFactory pointing back to |this| object, for use with |
132 // media::VideoFrames constructed in OnBufferReceived() from buffers cached | 135 // media::VideoFrames constructed in OnBufferReceived() from buffers cached |
133 // in |client_buffers_|. | 136 // in |client_buffers_|. |
134 base::WeakPtrFactory<VideoCaptureImpl> client_buffer_weak_this_factory_; | 137 base::WeakPtrFactory<VideoCaptureImpl> client_buffer_weak_this_factory_; |
135 | 138 |
136 ClientInfo clients_; | 139 ClientInfo clients_; |
137 | 140 |
138 ClientInfo clients_pending_on_filter_; | 141 ClientInfo clients_pending_on_filter_; |
139 ClientInfo clients_pending_on_restart_; | 142 ClientInfo clients_pending_on_restart_; |
140 | 143 |
141 media::VideoPixelFormat video_type_; | |
142 | |
143 // Member capture_format_ represents the video format requested by the client | 144 // Member capture_format_ represents the video format requested by the client |
144 // to this class via DoStartCaptureOnCaptureThread. | 145 // to this class via DoStartCaptureOnCaptureThread. |
145 media::VideoCaptureCapability capture_format_; | 146 media::VideoCaptureParams requested_params_; |
146 | 147 |
147 // The device's video capture format sent from browser process side. | 148 // The device's video capture format sent from browser process side. |
148 media::VideoCaptureParams device_info_; | 149 media::VideoCaptureFormat last_device_info_; |
149 bool device_info_available_; | |
150 | 150 |
151 bool suspended_; | 151 bool suspended_; |
152 VideoCaptureState state_; | 152 VideoCaptureState state_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 154 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
155 }; | 155 }; |
156 | 156 |
157 } // namespace content | 157 } // namespace content |
158 | 158 |
159 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 159 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |