Chromium Code Reviews| 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 relays | 9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays |
| 10 // operation of a capture device to the browser process and receives responses | 10 // operation of a capture device to the browser process and receives responses |
| 11 // from browser process. | 11 // from browser process. |
| 12 // | 12 // |
| 13 // All public methods of VideoCaptureImpl can be called on any thread. | 13 // VideoCaptureImpl is a IO thread only object. See the comments in |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/a IO/an IO/
Alpha Left Google
2014/04/23 18:48:33
Done.
| |
| 14 // Internally it runs on the IO thread. Clients of this class implement | 14 // video_capture_impl_manager.cc for the lifetime of this object. |
| 15 // interface media::VideoCapture::EventHandler which is called only on the IO | |
| 16 // thread. | |
| 17 // | 15 // |
| 18 // Implementation note: tasks are posted bound to Unretained(this) to the I/O | 16 // This is an internal class used by VideoCaptureImplManager only. Do not access |
| 19 // thread and this is safe (even though the I/O thread is scoped to the renderer | 17 // this directly. |
| 20 // process) because VideoCaptureImplManager only triggers deletion of its | |
| 21 // VideoCaptureImpl's by calling DeInit which detours through the I/O thread, so | |
| 22 // as long as nobody posts tasks after the DeInit() call is made, it is | |
| 23 // guaranteed none of these Unretained posted tasks will dangle after the delete | |
| 24 // goes through. The "as long as" is guaranteed by clients of | |
| 25 // VideoCaptureImplManager not using devices after they've released | |
| 26 // VideoCaptureHandle, which is a wrapper of this object. | |
| 27 | 18 |
| 28 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 19 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 29 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 20 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 30 | 21 |
| 31 #include <list> | 22 #include <list> |
| 32 #include <map> | 23 #include <map> |
| 33 | 24 |
| 34 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
| 26 #include "base/threading/thread_checker.h" | |
| 35 #include "content/common/content_export.h" | 27 #include "content/common/content_export.h" |
| 36 #include "content/common/media/video_capture.h" | 28 #include "content/common/media/video_capture.h" |
| 37 #include "content/renderer/media/video_capture_message_filter.h" | 29 #include "content/renderer/media/video_capture_message_filter.h" |
| 38 #include "media/video/capture/video_capture.h" | |
| 39 #include "media/video/capture/video_capture_types.h" | 30 #include "media/video/capture/video_capture_types.h" |
| 40 | 31 |
| 41 namespace base { | 32 namespace base { |
| 42 class MessageLoopProxy; | 33 class MessageLoopProxy; |
| 43 } // namespace base | 34 } // namespace base |
| 44 | 35 |
| 45 namespace gpu { | 36 namespace gpu { |
| 46 struct MailboxHolder; | 37 struct MailboxHolder; |
| 47 } // namespace gpu | 38 } // namespace gpu |
| 48 | 39 |
| 40 namespace media { | |
| 41 class VideoFrame; | |
| 42 } // namespace media | |
| 43 | |
| 49 namespace content { | 44 namespace content { |
| 50 | 45 |
| 51 class CONTENT_EXPORT VideoCaptureImpl | 46 class CONTENT_EXPORT VideoCaptureImpl |
| 52 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { | 47 : public VideoCaptureMessageFilter::Delegate { |
| 53 public: | 48 public: |
| 49 virtual ~VideoCaptureImpl(); | |
| 50 | |
| 51 private: | |
| 52 friend class VideoCaptureImplManager; | |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
why this?
Alpha Left Google
2014/04/23 18:48:33
Probably excessive. Changed it to a more public in
| |
| 53 friend class VideoCaptureImplTest; | |
| 54 friend class MockVideoCaptureImpl; | |
| 55 | |
| 56 class ClientBuffer; | |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
please doco all structs/classes.
Alpha Left Google
2014/04/23 18:48:33
Done.
| |
| 57 struct ClientInfo { | |
| 58 ClientInfo(); | |
| 59 ~ClientInfo(); | |
| 60 media::VideoCaptureParams params; | |
| 61 VideoCaptureStateUpdateCB state_update_cb; | |
| 62 VideoCaptureDeliverFrameCB deliver_frame_cb; | |
| 63 }; | |
| 64 typedef std::map<int, ClientInfo> ClientInfoMap; | |
| 65 | |
| 54 VideoCaptureImpl(media::VideoCaptureSessionId session_id, | 66 VideoCaptureImpl(media::VideoCaptureSessionId session_id, |
| 55 VideoCaptureMessageFilter* filter); | 67 VideoCaptureMessageFilter* filter); |
| 56 virtual ~VideoCaptureImpl(); | |
| 57 | 68 |
| 58 // Start listening to IPC messages. | 69 // Start listening to IPC messages. |
| 59 void Init(); | 70 void Init(); |
| 60 | 71 |
| 61 // Stop listening to IPC messages. Call |done_cb| when done. | 72 // Stop listening to IPC messages. |
| 62 void DeInit(base::Closure done_cb); | 73 void DeInit(); |
| 63 | 74 |
| 64 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 75 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 65 void SuspendCapture(bool suspend); | 76 void SuspendCapture(bool suspend); |
| 66 | 77 |
| 67 // media::VideoCapture interface. | 78 // Start capturing using the provided parameters. |
| 68 virtual void StartCapture( | 79 // |client_id| must be unique to this object. It is used later to |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
"unique" in the tab/renderer/browser ?
Alpha Left Google
2014/04/23 18:48:33
renderer. Documented.
| |
| 69 media::VideoCapture::EventHandler* handler, | 80 // stop receiving video frames. |
| 70 const media::VideoCaptureParams& params) OVERRIDE; | 81 // |status_update_cb| will be called when state changes. |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/status/state/
Alpha Left Google
2014/04/23 18:48:33
Done.
| |
| 71 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | 82 // |deliver_frame_cb| will be called when a frame is ready. |
| 72 virtual bool CaptureStarted() OVERRIDE; | 83 void StartCapture( |
| 73 virtual int CaptureFrameRate() OVERRIDE; | 84 int client_id, |
| 74 virtual void GetDeviceSupportedFormats( | 85 const media::VideoCaptureParams& params, |
| 75 const DeviceFormatsCallback& callback) OVERRIDE; | 86 const VideoCaptureStateUpdateCB& state_update_cb, |
| 76 virtual void GetDeviceFormatsInUse( | 87 const VideoCaptureDeliverFrameCB& deliver_frame_cb); |
| 77 const DeviceFormatsInUseCallback& callback) OVERRIDE; | 88 |
| 89 // Stop capturing. |client_id| is an identifier used to call StartCapture. | |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/an/the/
Alpha Left Google
2014/04/23 18:48:33
Done.
| |
| 90 void StopCapture(int client_id); | |
| 91 bool CaptureStarted(); | |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
why is this needed, given the state_updated_cb?
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
\n between methods, and doco all methods that aren
Alpha Left Google
2014/04/23 18:48:33
Removed.
| |
| 92 int CaptureFrameRate(); | |
|
Alpha Left Google
2014/04/23 18:48:33
Removed too.
| |
| 93 void GetDeviceSupportedFormats( | |
| 94 const VideoCaptureDeviceFormatsCB& callback); | |
| 95 void GetDeviceFormatsInUse( | |
| 96 const VideoCaptureDeviceFormatsCB& callback); | |
| 78 | 97 |
| 79 media::VideoCaptureSessionId session_id() const { return session_id_; } | 98 media::VideoCaptureSessionId session_id() const { return session_id_; } |
| 80 | 99 |
| 81 private: | |
| 82 friend class VideoCaptureImplTest; | |
| 83 friend class MockVideoCaptureImpl; | |
| 84 | |
| 85 class ClientBuffer; | |
| 86 typedef std::map<media::VideoCapture::EventHandler*, | |
| 87 media::VideoCaptureParams> ClientInfo; | |
| 88 | |
| 89 void InitOnIOThread(); | |
| 90 void DeInitOnIOThread(base::Closure done_cb); | |
| 91 void SuspendCaptureOnIOThread(bool suspend); | |
| 92 void StartCaptureOnIOThread( | |
| 93 media::VideoCapture::EventHandler* handler, | |
| 94 const media::VideoCaptureParams& params); | |
| 95 void StopCaptureOnIOThread(media::VideoCapture::EventHandler* handler); | |
| 96 void GetDeviceSupportedFormatsOnIOThread( | |
| 97 const DeviceFormatsCallback& callback); | |
| 98 void GetDeviceFormatsInUseOnIOThread( | |
| 99 const DeviceFormatsInUseCallback& callback); | |
| 100 | |
| 101 // VideoCaptureMessageFilter::Delegate interface. | 100 // VideoCaptureMessageFilter::Delegate interface. |
| 102 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 101 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| 103 int length, | 102 int length, |
| 104 int buffer_id) OVERRIDE; | 103 int buffer_id) OVERRIDE; |
| 105 virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; | 104 virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; |
| 106 virtual void OnBufferReceived(int buffer_id, | 105 virtual void OnBufferReceived(int buffer_id, |
| 107 const media::VideoCaptureFormat& format, | 106 const media::VideoCaptureFormat& format, |
| 108 base::TimeTicks) OVERRIDE; | 107 base::TimeTicks) OVERRIDE; |
| 109 virtual void OnMailboxBufferReceived(int buffer_id, | 108 virtual void OnMailboxBufferReceived(int buffer_id, |
| 110 const gpu::MailboxHolder& mailbox_holder, | 109 const gpu::MailboxHolder& mailbox_holder, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 123 const scoped_refptr<ClientBuffer>& buffer, | 122 const scoped_refptr<ClientBuffer>& buffer, |
| 124 scoped_ptr<gpu::MailboxHolder> mailbox_holder); | 123 scoped_ptr<gpu::MailboxHolder> mailbox_holder); |
| 125 | 124 |
| 126 void StopDevice(); | 125 void StopDevice(); |
| 127 void RestartCapture(); | 126 void RestartCapture(); |
| 128 void StartCaptureInternal(); | 127 void StartCaptureInternal(); |
| 129 | 128 |
| 130 virtual void Send(IPC::Message* message); | 129 virtual void Send(IPC::Message* message); |
| 131 | 130 |
| 132 // Helpers. | 131 // Helpers. |
| 133 bool RemoveClient(media::VideoCapture::EventHandler* handler, | 132 bool RemoveClient(int client_id, ClientInfoMap* clients); |
| 134 ClientInfo* clients); | |
| 135 | 133 |
| 136 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 134 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
| 137 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
| 138 int device_id_; | 135 int device_id_; |
| 139 const int session_id_; | 136 const int session_id_; |
| 140 | 137 |
| 141 // Vector of callbacks to be notified of device format enumerations, used only | 138 // Vector of callbacks to be notified of device format enumerations, used only |
| 142 // on IO Thread. | 139 // on IO Thread. |
| 143 std::vector<DeviceFormatsCallback> device_formats_callback_queue_; | 140 std::vector<VideoCaptureDeviceFormatsCB> device_formats_cb_queue_; |
| 144 // Vector of callbacks to be notified of a device's in use capture format(s), | 141 // Vector of callbacks to be notified of a device's in use capture format(s), |
| 145 // used only on IO Thread. | 142 // used only on IO Thread. |
| 146 std::vector<DeviceFormatsInUseCallback> device_formats_in_use_callback_queue_; | 143 std::vector<VideoCaptureDeviceFormatsCB> device_formats_in_use_cb_queue_; |
| 147 | 144 |
| 148 // Buffers available for sending to the client. | 145 // Buffers available for sending to the client. |
| 149 typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap; | 146 typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap; |
| 150 ClientBufferMap client_buffers_; | 147 ClientBufferMap client_buffers_; |
| 151 | 148 |
| 152 ClientInfo clients_; | 149 ClientInfoMap clients_; |
| 153 ClientInfo clients_pending_on_filter_; | 150 ClientInfoMap clients_pending_on_filter_; |
| 154 ClientInfo clients_pending_on_restart_; | 151 ClientInfoMap clients_pending_on_restart_; |
| 155 | 152 |
| 156 // Member params_ represents the video format requested by the | 153 // Member params_ represents the video format requested by the |
| 157 // client to this class via StartCapture(). | 154 // client to this class via StartCapture(). |
| 158 media::VideoCaptureParams params_; | 155 media::VideoCaptureParams params_; |
| 159 | 156 |
| 160 // The device's video capture format sent from browser process side. | 157 // The device's video capture format sent from browser process side. |
| 161 media::VideoCaptureFormat last_frame_format_; | 158 media::VideoCaptureFormat last_frame_format_; |
| 162 | 159 |
| 163 // The device's first captured frame timestamp sent from browser process side. | 160 // The device's first captured frame timestamp sent from browser process side. |
| 164 base::TimeTicks first_frame_timestamp_; | 161 base::TimeTicks first_frame_timestamp_; |
| 165 | 162 |
| 166 bool suspended_; | 163 bool suspended_; |
| 167 VideoCaptureState state_; | 164 VideoCaptureState state_; |
| 168 | 165 |
| 169 // WeakPtrFactory pointing back to |this| object, for use with | 166 // WeakPtrFactory pointing back to |this| object, for use with |
| 170 // media::VideoFrames constructed in OnBufferReceived() from buffers cached | 167 // media::VideoFrames constructed in OnBufferReceived() from buffers cached |
| 171 // in |client_buffers_|. | 168 // in |client_buffers_|. |
| 172 // NOTE: Weak pointers must be invalidated before all other member variables. | 169 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 173 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; | 170 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; |
| 174 | 171 |
| 172 // Bound to the thread where Init() is called. It should be the IO thread. | |
|
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
should go above the weakptrfactory above (see the
Alpha Left Google
2014/04/23 18:48:33
Done.
| |
| 173 base::ThreadChecker thread_checker_; | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 175 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace content | 178 } // namespace content |
| 179 | 179 |
| 180 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 180 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |