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 // VideoCaptureHost serves video capture related messages from | 5 // VideoCaptureHost serves video capture related messages from |
6 // VideoCaptureMessageFilter which lives inside the render process. | 6 // VideoCaptureMessageFilter which lives inside the render process. |
7 // | 7 // |
8 // This class is owned by RenderProcessHostImpl, and instantiated on UI | 8 // This class is owned by RenderProcessHostImpl, and instantiated on UI |
9 // thread, but all other operations and method calls happen on IO thread. | 9 // thread, but all other operations and method calls happen on IO thread. |
10 // | 10 // |
(...skipping 24 matching lines...) Expand all Loading... | |
35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated | 35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated |
36 // | < VideoCaptureMsg_NewBuffer(4) | with a larger size, as | 36 // | < VideoCaptureMsg_NewBuffer(4) | with a larger size, as |
37 // | < VideoCaptureMsg_BufferReady(4) | needed. | 37 // | < VideoCaptureMsg_BufferReady(4) | needed. |
38 // | VideoCaptureHostMsg_BufferReady(2) > | | 38 // | VideoCaptureHostMsg_BufferReady(2) > | |
39 // | < VideoCaptureMsg_FreeBuffer(2) | | 39 // | < VideoCaptureMsg_FreeBuffer(2) | |
40 // | < VideoCaptureMsg_NewBuffer(5) | | 40 // | < VideoCaptureMsg_NewBuffer(5) | |
41 // | < VideoCaptureMsg_BufferReady(5) | | 41 // | < VideoCaptureMsg_BufferReady(5) | |
42 // | ... | | 42 // | ... | |
43 // | | | 43 // | | |
44 // | < VideoCaptureMsg_BufferReady | | 44 // | < VideoCaptureMsg_BufferReady | |
45 // | VideoCaptureHostMsg_Stop > | | 45 // | --------- StopCapture ---------> | |
46 // | VideoCaptureHostMsg_BufferReady > | | 46 // | VideoCaptureHostMsg_BufferReady > | |
47 // | < VideoCaptureMsg_StateChanged | | 47 // | < VideoCaptureMsg_StateChanged | |
48 // | (VIDEO_CAPTURE_STATE_STOPPED) | | 48 // | (VIDEO_CAPTURE_STATE_STOPPED) | |
49 // v v | 49 // v v |
50 | 50 |
51 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 51 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
52 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 52 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
53 | 53 |
54 #include <map> | 54 #include <map> |
55 | 55 |
56 #include "base/macros.h" | 56 #include "base/macros.h" |
57 #include "base/memory/ref_counted.h" | 57 #include "base/memory/ref_counted.h" |
58 #include "base/memory/weak_ptr.h" | 58 #include "base/memory/weak_ptr.h" |
59 #include "base/sequenced_task_runner_helpers.h" | 59 #include "base/sequenced_task_runner_helpers.h" |
60 #include "content/browser/renderer_host/media/video_capture_controller.h" | 60 #include "content/browser/renderer_host/media/video_capture_controller.h" |
61 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 61 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
62 #include "content/common/content_export.h" | 62 #include "content/common/content_export.h" |
63 #include "content/common/video_capture.mojom.h" | |
64 #include "content/public/browser/browser_associated_interface.h" | |
63 #include "content/public/browser/browser_message_filter.h" | 65 #include "content/public/browser/browser_message_filter.h" |
64 #include "ipc/ipc_message.h" | 66 #include "ipc/ipc_message.h" |
65 | 67 |
66 namespace content { | 68 namespace content { |
67 class MediaStreamManager; | 69 class MediaStreamManager; |
68 | 70 |
69 class CONTENT_EXPORT VideoCaptureHost | 71 class CONTENT_EXPORT VideoCaptureHost |
70 : public BrowserMessageFilter, | 72 : public BrowserMessageFilter, |
71 public VideoCaptureControllerEventHandler { | 73 public VideoCaptureControllerEventHandler, |
74 public BrowserAssociatedInterface<mojom::VideoCaptureRendererToBrowser>, | |
75 public mojom::VideoCaptureRendererToBrowser { | |
72 public: | 76 public: |
73 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); | 77 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); |
74 | 78 |
75 // BrowserMessageFilter implementation. | 79 // BrowserMessageFilter implementation. |
76 void OnChannelClosing() override; | 80 void OnChannelClosing() override; |
77 void OnDestruct() const override; | 81 void OnDestruct() const override; |
78 bool OnMessageReceived(const IPC::Message& message) override; | 82 bool OnMessageReceived(const IPC::Message& message) override; |
79 | 83 |
80 // VideoCaptureControllerEventHandler implementation. | 84 // VideoCaptureControllerEventHandler implementation. |
81 void OnError(VideoCaptureControllerID id) override; | 85 void OnError(VideoCaptureControllerID id) override; |
(...skipping 16 matching lines...) Expand all Loading... | |
98 friend class BrowserThread; | 102 friend class BrowserThread; |
99 friend class base::DeleteHelper<VideoCaptureHost>; | 103 friend class base::DeleteHelper<VideoCaptureHost>; |
100 friend class MockVideoCaptureHost; | 104 friend class MockVideoCaptureHost; |
101 friend class VideoCaptureHostTest; | 105 friend class VideoCaptureHostTest; |
102 | 106 |
103 void DoError(VideoCaptureControllerID id); | 107 void DoError(VideoCaptureControllerID id); |
104 void DoEnded(VideoCaptureControllerID id); | 108 void DoEnded(VideoCaptureControllerID id); |
105 | 109 |
106 ~VideoCaptureHost() override; | 110 ~VideoCaptureHost() override; |
107 | 111 |
108 // IPC message: Start capture on the VideoCaptureDevice referenced by | 112 // IPC message handlers. |
109 // |device_id|. |session_id| is an id created by VideoCaptureMessageFilter | |
110 // to identify a session between a VideoCaptureMessageFilter and a | |
111 // VideoCaptureHost. | |
112 void OnStartCapture(int device_id, | 113 void OnStartCapture(int device_id, |
113 media::VideoCaptureSessionId session_id, | 114 media::VideoCaptureSessionId session_id, |
114 const media::VideoCaptureParams& params); | 115 const media::VideoCaptureParams& params); |
116 void OnResumeCapture(int device_id, | |
117 media::VideoCaptureSessionId session_id, | |
118 const media::VideoCaptureParams& params); | |
119 void OnRendererFinishedWithBuffer(int device_id, | |
120 int buffer_id, | |
121 const gpu::SyncToken& sync_token, | |
122 double consumer_resource_utilization); | |
123 void OnGetDeviceSupportedFormats( | |
124 int device_id, | |
125 media::VideoCaptureSessionId capture_session_id); | |
chfremer
2016/10/03 19:58:42
nit: Since we are already touching this code, we c
mcasas
2016/10/03 20:15:42
Absolutely! Im doing it in the next CL :)
| |
126 void OnGetDeviceFormatsInUse(int device_id, | |
127 media::VideoCaptureSessionId capture_session_id); | |
128 | |
129 // mojom::VideoCaptureRendererToBrowser implementation | |
130 void StopCapture(int32_t device_id) override; | |
131 void PauseCapture(int32_t device_id) override; | |
132 void RequestRefreshFrame(int32_t device_id) override; | |
133 | |
115 void OnControllerAdded( | 134 void OnControllerAdded( |
116 int device_id, | 135 int device_id, |
117 const base::WeakPtr<VideoCaptureController>& controller); | 136 const base::WeakPtr<VideoCaptureController>& controller); |
118 | 137 |
119 // IPC message: Stop capture on device referenced by |device_id|. | |
120 void OnStopCapture(int device_id); | |
121 | |
122 // IPC message: Pause capture on device referenced by |device_id|. | |
123 void OnPauseCapture(int device_id); | |
124 | |
125 void OnResumeCapture(int device_id, | |
126 media::VideoCaptureSessionId session_id, | |
127 const media::VideoCaptureParams& params); | |
128 | |
129 // IPC message: Requests that the video capture send a frame "soon" (e.g., to | |
130 // resolve picture loss or quality issues). | |
131 void OnRequestRefreshFrame(int device_id); | |
132 | |
133 // IPC message: Called when a renderer is finished using a buffer. Notifies | |
134 // the controller. | |
135 void OnRendererFinishedWithBuffer(int device_id, | |
136 int buffer_id, | |
137 const gpu::SyncToken& sync_token, | |
138 double consumer_resource_utilization); | |
139 | |
140 // IPC message: Get supported formats referenced by |capture_session_id|. | |
141 // |device_id| is needed for message back-routing purposes. | |
142 void OnGetDeviceSupportedFormats( | |
143 int device_id, | |
144 media::VideoCaptureSessionId capture_session_id); | |
145 | |
146 // IPC message: Get a device's currently in use format(s), referenced by | |
147 // |capture_session_id|. |device_id| is needed for message back-routing | |
148 // purposes. | |
149 void OnGetDeviceFormatsInUse(int device_id, | |
150 media::VideoCaptureSessionId capture_session_id); | |
151 | |
152 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is | 138 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is |
153 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. | 139 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. |
154 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id, | 140 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id, |
155 bool on_error); | 141 bool on_error); |
156 | 142 |
157 MediaStreamManager* const media_stream_manager_; | 143 MediaStreamManager* const media_stream_manager_; |
158 | 144 |
159 typedef std::map<VideoCaptureControllerID, | |
160 base::WeakPtr<VideoCaptureController>> EntryMap; | |
161 | |
162 // A map of VideoCaptureControllerID to the VideoCaptureController to which it | 145 // A map of VideoCaptureControllerID to the VideoCaptureController to which it |
163 // is connected. An entry in this map holds a null controller while it is in | 146 // is connected. An entry in this map holds a null controller while it is in |
164 // the process of starting. | 147 // the process of starting. |
165 EntryMap entries_; | 148 std::map<VideoCaptureControllerID, base::WeakPtr<VideoCaptureController>> |
149 controllers_; | |
166 | 150 |
167 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); | 151 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); |
168 }; | 152 }; |
169 | 153 |
170 } // namespace content | 154 } // namespace content |
171 | 155 |
172 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 156 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
OLD | NEW |