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 "media/base/video_frame.h" |
22 #include "mojo/public/cpp/bindings/binding.h" | 23 #include "mojo/public/cpp/bindings/binding.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
26 } // namespace base | 27 } // namespace base |
27 | 28 |
28 namespace media { | |
29 class VideoFrame; | |
30 } // namespace media | |
31 | |
32 namespace content { | 29 namespace content { |
33 | 30 |
34 // VideoCaptureImpl represents a capture device in renderer process. It provides | 31 // VideoCaptureImpl represents a capture device in renderer process. It provides |
35 // interfaces for clients to Start/Stop capture. It also communicates to clients | 32 // interfaces for clients to Start/Stop capture. It also communicates to clients |
36 // when buffer is ready, state of capture device is changed. | 33 // when buffer is ready, state of capture device is changed. |
37 | 34 // |
38 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays | 35 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter to receive |
39 // operation of a capture device to the browser process and receives responses | 36 // notification of the browser process being ready to communicate. |
40 // from browser process. | |
41 // | 37 // |
42 // VideoCaptureImpl is an IO thread only object. See the comments in | 38 // VideoCaptureImpl is an IO thread only object. See the comments in |
43 // video_capture_impl_manager.cc for the lifetime of this object. | 39 // video_capture_impl_manager.cc for the lifetime of this object. |
44 // All methods must be called on the IO thread. | 40 // All methods must be called on the IO thread. |
45 // | 41 // |
46 // This is an internal class used by VideoCaptureImplManager only. Do not access | 42 // This is an internal class used by VideoCaptureImplManager only. Do not access |
47 // this directly. | 43 // this directly. |
48 class CONTENT_EXPORT VideoCaptureImpl | 44 class CONTENT_EXPORT VideoCaptureImpl |
49 : public VideoCaptureMessageFilter::Delegate, | 45 : public VideoCaptureMessageFilter::Delegate, |
50 public mojom::VideoCaptureObserver { | 46 public mojom::VideoCaptureObserver { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Get capturing formats currently in use by this device. | 78 // Get capturing formats currently in use by this device. |
83 // |callback| will be invoked with the results. | 79 // |callback| will be invoked with the results. |
84 void GetDeviceFormatsInUse(const VideoCaptureDeviceFormatsCB& callback); | 80 void GetDeviceFormatsInUse(const VideoCaptureDeviceFormatsCB& callback); |
85 | 81 |
86 media::VideoCaptureSessionId session_id() const { return session_id_; } | 82 media::VideoCaptureSessionId session_id() const { return session_id_; } |
87 | 83 |
88 void SetVideoCaptureHostForTesting(mojom::VideoCaptureHost* service) { | 84 void SetVideoCaptureHostForTesting(mojom::VideoCaptureHost* service) { |
89 video_capture_host_for_testing_ = service; | 85 video_capture_host_for_testing_ = service; |
90 } | 86 } |
91 | 87 |
92 protected: | |
93 // Note: Overridden only by unit test subclasses. | |
94 virtual void Send(IPC::Message* message); | |
95 | |
96 private: | 88 private: |
97 friend class VideoCaptureImplTest; | 89 friend class VideoCaptureImplTest; |
98 friend class MockVideoCaptureImpl; | 90 friend class MockVideoCaptureImpl; |
99 | 91 |
100 // Carries a shared memory for transferring video frames from browser to | 92 // Carries a shared memory for transferring video frames from browser to |
101 // renderer. | 93 // renderer. |
102 class ClientBuffer; | 94 class ClientBuffer; |
103 | 95 |
104 // Contains information for a video capture client. Including parameters | 96 // Contains information for a video capture client. Including parameters |
105 // for capturing and callbacks to the client. | 97 // for capturing and callbacks to the client. |
106 struct ClientInfo { | 98 struct ClientInfo { |
107 ClientInfo(); | 99 ClientInfo(); |
108 ClientInfo(const ClientInfo& other); | 100 ClientInfo(const ClientInfo& other); |
109 ~ClientInfo(); | 101 ~ClientInfo(); |
110 media::VideoCaptureParams params; | 102 media::VideoCaptureParams params; |
111 VideoCaptureStateUpdateCB state_update_cb; | 103 VideoCaptureStateUpdateCB state_update_cb; |
112 VideoCaptureDeliverFrameCB deliver_frame_cb; | 104 VideoCaptureDeliverFrameCB deliver_frame_cb; |
113 }; | 105 }; |
114 using ClientInfoMap = std::map<int, ClientInfo>; | 106 using ClientInfoMap = std::map<int, ClientInfo>; |
115 | 107 |
116 using BufferFinishedCallback = | 108 using BufferFinishedCallback = |
117 base::Callback<void(const gpu::SyncToken& sync_token, | 109 base::Callback<void(const gpu::SyncToken& sync_token, |
118 double consumer_resource_utilization)>; | 110 double consumer_resource_utilization)>; |
119 | 111 |
120 // VideoCaptureMessageFilter::Delegate interface implementation. | 112 // VideoCaptureMessageFilter::Delegate interface implementation. |
121 void OnBufferCreated(base::SharedMemoryHandle handle, | |
122 int length, | |
123 int buffer_id) override; | |
124 void OnDelegateAdded(int32_t device_id) override; | 113 void OnDelegateAdded(int32_t device_id) override; |
125 | 114 |
126 // mojom::VideoCaptureObserver implementation. | 115 // mojom::VideoCaptureObserver implementation. |
127 void OnStateChanged(mojom::VideoCaptureState state) override; | 116 void OnStateChanged(mojom::VideoCaptureState state) override; |
| 117 void OnBufferCreated(int32_t buffer_id, |
| 118 mojo::ScopedSharedBufferHandle handle) override; |
128 void OnBufferReady(int32_t buffer_id, mojom::VideoFrameInfoPtr info) override; | 119 void OnBufferReady(int32_t buffer_id, mojom::VideoFrameInfoPtr info) override; |
129 void OnBufferDestroyed(int32_t buffer_id) override; | 120 void OnBufferDestroyed(int32_t buffer_id) override; |
130 | 121 |
131 // Sends an IPC message to browser process when all clients are done with the | 122 // Sends an IPC message to browser process when all clients are done with the |
132 // buffer. | 123 // buffer. |
133 void OnClientBufferFinished(int buffer_id, | 124 void OnClientBufferFinished(int buffer_id, |
134 const scoped_refptr<ClientBuffer>& buffer, | 125 const scoped_refptr<ClientBuffer>& buffer, |
135 const gpu::SyncToken& release_sync_token, | 126 const gpu::SyncToken& release_sync_token, |
136 double consumer_resource_utilization); | 127 double consumer_resource_utilization); |
137 | 128 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // in |client_buffers_|. | 186 // in |client_buffers_|. |
196 // NOTE: Weak pointers must be invalidated before all other member variables. | 187 // NOTE: Weak pointers must be invalidated before all other member variables. |
197 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; | 188 base::WeakPtrFactory<VideoCaptureImpl> weak_factory_; |
198 | 189 |
199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 190 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
200 }; | 191 }; |
201 | 192 |
202 } // namespace content | 193 } // namespace content |
203 | 194 |
204 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 195 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |