| 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_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/common/media/video_capture.h" | 17 #include "content/common/media/video_capture.h" |
| 18 #include "content/common/video_capture.mojom.h" | 18 #include "content/common/video_capture.mojom.h" |
| 19 #include "content/public/renderer/media_stream_video_sink.h" | 19 #include "content/public/renderer/media_stream_video_sink.h" |
| 20 #include "content/renderer/media/video_capture_message_filter.h" | 20 #include "content/renderer/media/video_capture_message_filter.h" |
| 21 #include "media/base/video_capture_types.h" | 21 #include "media/base/video_capture_types.h" |
| 22 #include "mojo/public/cpp/bindings/binding.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 25 } // namespace base | 26 } // namespace base |
| 26 | 27 |
| 27 namespace media { | 28 namespace media { |
| 28 class VideoFrame; | 29 class VideoFrame; |
| 29 } // namespace media | 30 } // namespace media |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 // VideoCaptureImpl represents a capture device in renderer process. It provides | 34 // VideoCaptureImpl represents a capture device in renderer process. It provides |
| 34 // interfaces for clients to Start/Stop capture. It also communicates to clients | 35 // interfaces for clients to Start/Stop capture. It also communicates to clients |
| 35 // when buffer is ready, state of capture device is changed. | 36 // when buffer is ready, state of capture device is changed. |
| 36 | 37 |
| 37 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays | 38 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays |
| 38 // operation of a capture device to the browser process and receives responses | 39 // operation of a capture device to the browser process and receives responses |
| 39 // from browser process. | 40 // from browser process. |
| 40 // | 41 // |
| 41 // VideoCaptureImpl is an IO thread only object. See the comments in | 42 // VideoCaptureImpl is an IO thread only object. See the comments in |
| 42 // video_capture_impl_manager.cc for the lifetime of this object. | 43 // video_capture_impl_manager.cc for the lifetime of this object. |
| 43 // All methods must be called on the IO thread. | 44 // All methods must be called on the IO thread. |
| 44 // | 45 // |
| 45 // This is an internal class used by VideoCaptureImplManager only. Do not access | 46 // This is an internal class used by VideoCaptureImplManager only. Do not access |
| 46 // this directly. | 47 // this directly. |
| 47 class CONTENT_EXPORT VideoCaptureImpl | 48 class CONTENT_EXPORT VideoCaptureImpl |
| 48 : public VideoCaptureMessageFilter::Delegate { | 49 : public VideoCaptureMessageFilter::Delegate, |
| 50 public mojom::VideoCaptureObserver { |
| 49 public: | 51 public: |
| 50 VideoCaptureImpl( | 52 VideoCaptureImpl( |
| 51 media::VideoCaptureSessionId session_id, | 53 media::VideoCaptureSessionId session_id, |
| 52 VideoCaptureMessageFilter* filter, | 54 VideoCaptureMessageFilter* filter, |
| 53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); | 55 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| 54 ~VideoCaptureImpl() override; | 56 ~VideoCaptureImpl() override; |
| 55 | 57 |
| 56 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 58 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 57 void SuspendCapture(bool suspend); | 59 void SuspendCapture(bool suspend); |
| 58 | 60 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Contains information for a video capture client. Including parameters | 104 // Contains information for a video capture client. Including parameters |
| 103 // for capturing and callbacks to the client. | 105 // for capturing and callbacks to the client. |
| 104 struct ClientInfo { | 106 struct ClientInfo { |
| 105 ClientInfo(); | 107 ClientInfo(); |
| 106 ClientInfo(const ClientInfo& other); | 108 ClientInfo(const ClientInfo& other); |
| 107 ~ClientInfo(); | 109 ~ClientInfo(); |
| 108 media::VideoCaptureParams params; | 110 media::VideoCaptureParams params; |
| 109 VideoCaptureStateUpdateCB state_update_cb; | 111 VideoCaptureStateUpdateCB state_update_cb; |
| 110 VideoCaptureDeliverFrameCB deliver_frame_cb; | 112 VideoCaptureDeliverFrameCB deliver_frame_cb; |
| 111 }; | 113 }; |
| 112 typedef std::map<int, ClientInfo> ClientInfoMap; | 114 using ClientInfoMap = std::map<int, ClientInfo>; |
| 113 | 115 |
| 114 typedef base::Callback<void(const gpu::SyncToken& sync_token, | 116 using BufferFinishedCallback = |
| 115 double consumer_resource_utilization)> | 117 base::Callback<void(const gpu::SyncToken& sync_token, |
| 116 BufferFinishedCallback; | 118 double consumer_resource_utilization)>; |
| 117 | 119 |
| 118 // VideoCaptureMessageFilter::Delegate interface. | 120 // VideoCaptureMessageFilter::Delegate interface implementation. |
| 119 void OnBufferCreated(base::SharedMemoryHandle handle, | 121 void OnBufferCreated(base::SharedMemoryHandle handle, |
| 120 int length, | 122 int length, |
| 121 int buffer_id) override; | 123 int buffer_id) override; |
| 122 void OnBufferDestroyed(int buffer_id) override; | 124 void OnBufferDestroyed(int buffer_id) override; |
| 123 void OnBufferReceived(int buffer_id, | 125 void OnBufferReceived(int buffer_id, |
| 124 base::TimeDelta timestamp, | 126 base::TimeDelta timestamp, |
| 125 const base::DictionaryValue& metadata, | 127 const base::DictionaryValue& metadata, |
| 126 media::VideoPixelFormat pixel_format, | 128 media::VideoPixelFormat pixel_format, |
| 127 media::VideoFrame::StorageType storage_type, | 129 media::VideoFrame::StorageType storage_type, |
| 128 const gfx::Size& coded_size, | 130 const gfx::Size& coded_size, |
| 129 const gfx::Rect& visible_rect) override; | 131 const gfx::Rect& visible_rect) override; |
| 130 void OnStateChanged(VideoCaptureState state) override; | |
| 131 void OnDelegateAdded(int32_t device_id) override; | 132 void OnDelegateAdded(int32_t device_id) override; |
| 132 | 133 |
| 134 // mojom::VideoCaptureObserver implementation. |
| 135 void OnStateChanged(mojom::VideoCaptureState state) override; |
| 136 |
| 133 // Sends an IPC message to browser process when all clients are done with the | 137 // Sends an IPC message to browser process when all clients are done with the |
| 134 // buffer. | 138 // buffer. |
| 135 void OnClientBufferFinished(int buffer_id, | 139 void OnClientBufferFinished(int buffer_id, |
| 136 const scoped_refptr<ClientBuffer>& buffer, | 140 const scoped_refptr<ClientBuffer>& buffer, |
| 137 const gpu::SyncToken& release_sync_token, | 141 const gpu::SyncToken& release_sync_token, |
| 138 double consumer_resource_utilization); | 142 double consumer_resource_utilization); |
| 139 | 143 |
| 140 void StopDevice(); | 144 void StopDevice(); |
| 141 void RestartCapture(); | 145 void RestartCapture(); |
| 142 void StartCaptureInternal(); | 146 void StartCaptureInternal(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 162 std::unique_ptr<gpu::SyncToken> release_sync_token, | 166 std::unique_ptr<gpu::SyncToken> release_sync_token, |
| 163 const BufferFinishedCallback& callback_to_io_thread); | 167 const BufferFinishedCallback& callback_to_io_thread); |
| 164 | 168 |
| 165 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 169 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
| 166 int device_id_; | 170 int device_id_; |
| 167 const int session_id_; | 171 const int session_id_; |
| 168 | 172 |
| 169 mojom::VideoCaptureHostAssociatedPtr video_capture_host_; | 173 mojom::VideoCaptureHostAssociatedPtr video_capture_host_; |
| 170 mojom::VideoCaptureHost* video_capture_host_for_testing_; | 174 mojom::VideoCaptureHost* video_capture_host_for_testing_; |
| 171 | 175 |
| 176 mojo::Binding<mojom::VideoCaptureObserver> observer_binding_; |
| 177 |
| 172 // Buffers available for sending to the client. | 178 // Buffers available for sending to the client. |
| 173 typedef std::map<int32_t, scoped_refptr<ClientBuffer>> ClientBufferMap; | 179 typedef std::map<int32_t, scoped_refptr<ClientBuffer>> ClientBufferMap; |
| 174 ClientBufferMap client_buffers_; | 180 ClientBufferMap client_buffers_; |
| 175 | 181 |
| 176 ClientInfoMap clients_; | 182 ClientInfoMap clients_; |
| 177 ClientInfoMap clients_pending_on_filter_; | 183 ClientInfoMap clients_pending_on_filter_; |
| 178 ClientInfoMap clients_pending_on_restart_; | 184 ClientInfoMap clients_pending_on_restart_; |
| 179 | 185 |
| 180 // Member params_ represents the video format requested by the | 186 // Member params_ represents the video format requested by the |
| 181 // client to this class via StartCapture(). | 187 // client to this class via StartCapture(). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 195 // in |client_buffers_|. | 201 // in |client_buffers_|. |
| 196 // NOTE: Weak pointers must be invalidated before all other member variables. | 202 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 197 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; | 203 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; |
| 198 | 204 |
| 199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 205 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 200 }; | 206 }; |
| 201 | 207 |
| 202 } // namespace content | 208 } // namespace content |
| 203 | 209 |
| 204 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 210 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |