| 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 // | --------- StopCapture ---------> | | 45 // | VideoCaptureHostMsg_Stop > | |
| 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" | |
| 65 #include "content/public/browser/browser_message_filter.h" | 63 #include "content/public/browser/browser_message_filter.h" |
| 66 #include "ipc/ipc_message.h" | 64 #include "ipc/ipc_message.h" |
| 67 | 65 |
| 68 namespace content { | 66 namespace content { |
| 69 class MediaStreamManager; | 67 class MediaStreamManager; |
| 70 | 68 |
| 71 class CONTENT_EXPORT VideoCaptureHost | 69 class CONTENT_EXPORT VideoCaptureHost |
| 72 : public BrowserMessageFilter, | 70 : public BrowserMessageFilter, |
| 73 public VideoCaptureControllerEventHandler, | 71 public VideoCaptureControllerEventHandler { |
| 74 public BrowserAssociatedInterface<mojom::VideoCaptureRendererToBrowser>, | |
| 75 public mojom::VideoCaptureRendererToBrowser { | |
| 76 public: | 72 public: |
| 77 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); | 73 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); |
| 78 | 74 |
| 79 // BrowserMessageFilter implementation. | 75 // BrowserMessageFilter implementation. |
| 80 void OnChannelClosing() override; | 76 void OnChannelClosing() override; |
| 81 void OnDestruct() const override; | 77 void OnDestruct() const override; |
| 82 bool OnMessageReceived(const IPC::Message& message) override; | 78 bool OnMessageReceived(const IPC::Message& message) override; |
| 83 | 79 |
| 84 // VideoCaptureControllerEventHandler implementation. | 80 // VideoCaptureControllerEventHandler implementation. |
| 85 void OnError(VideoCaptureControllerID id) override; | 81 void OnError(VideoCaptureControllerID id) override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 friend class BrowserThread; | 98 friend class BrowserThread; |
| 103 friend class base::DeleteHelper<VideoCaptureHost>; | 99 friend class base::DeleteHelper<VideoCaptureHost>; |
| 104 friend class MockVideoCaptureHost; | 100 friend class MockVideoCaptureHost; |
| 105 friend class VideoCaptureHostTest; | 101 friend class VideoCaptureHostTest; |
| 106 | 102 |
| 107 void DoError(VideoCaptureControllerID id); | 103 void DoError(VideoCaptureControllerID id); |
| 108 void DoEnded(VideoCaptureControllerID id); | 104 void DoEnded(VideoCaptureControllerID id); |
| 109 | 105 |
| 110 ~VideoCaptureHost() override; | 106 ~VideoCaptureHost() override; |
| 111 | 107 |
| 112 // IPC message handlers. | 108 // IPC message: Start capture on the VideoCaptureDevice referenced by |
| 109 // |device_id|. |session_id| is an id created by VideoCaptureMessageFilter |
| 110 // to identify a session between a VideoCaptureMessageFilter and a |
| 111 // VideoCaptureHost. |
| 113 void OnStartCapture(int device_id, | 112 void OnStartCapture(int device_id, |
| 114 media::VideoCaptureSessionId session_id, | 113 media::VideoCaptureSessionId session_id, |
| 115 const media::VideoCaptureParams& params); | 114 const media::VideoCaptureParams& params); |
| 115 void OnControllerAdded( |
| 116 int device_id, |
| 117 const base::WeakPtr<VideoCaptureController>& controller); |
| 118 |
| 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 |
| 116 void OnResumeCapture(int device_id, | 125 void OnResumeCapture(int device_id, |
| 117 media::VideoCaptureSessionId session_id, | 126 media::VideoCaptureSessionId session_id, |
| 118 const media::VideoCaptureParams& params); | 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. |
| 119 void OnRendererFinishedWithBuffer(int device_id, | 135 void OnRendererFinishedWithBuffer(int device_id, |
| 120 int buffer_id, | 136 int buffer_id, |
| 121 const gpu::SyncToken& sync_token, | 137 const gpu::SyncToken& sync_token, |
| 122 double consumer_resource_utilization); | 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. |
| 123 void OnGetDeviceSupportedFormats( | 142 void OnGetDeviceSupportedFormats( |
| 124 int device_id, | 143 int device_id, |
| 125 media::VideoCaptureSessionId capture_session_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. |
| 126 void OnGetDeviceFormatsInUse(int device_id, | 149 void OnGetDeviceFormatsInUse(int device_id, |
| 127 media::VideoCaptureSessionId capture_session_id); | 150 media::VideoCaptureSessionId capture_session_id); |
| 128 | 151 |
| 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 | |
| 134 void OnControllerAdded( | |
| 135 int device_id, | |
| 136 const base::WeakPtr<VideoCaptureController>& controller); | |
| 137 | |
| 138 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is | 152 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is |
| 139 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. | 153 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. |
| 140 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id, | 154 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id, |
| 141 bool on_error); | 155 bool on_error); |
| 142 | 156 |
| 143 MediaStreamManager* const media_stream_manager_; | 157 MediaStreamManager* const media_stream_manager_; |
| 144 | 158 |
| 159 typedef std::map<VideoCaptureControllerID, |
| 160 base::WeakPtr<VideoCaptureController>> EntryMap; |
| 161 |
| 145 // A map of VideoCaptureControllerID to the VideoCaptureController to which it | 162 // A map of VideoCaptureControllerID to the VideoCaptureController to which it |
| 146 // is connected. An entry in this map holds a null controller while it is in | 163 // is connected. An entry in this map holds a null controller while it is in |
| 147 // the process of starting. | 164 // the process of starting. |
| 148 std::map<VideoCaptureControllerID, base::WeakPtr<VideoCaptureController>> | 165 EntryMap entries_; |
| 149 controllers_; | |
| 150 | 166 |
| 151 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); | 167 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); |
| 152 }; | 168 }; |
| 153 | 169 |
| 154 } // namespace content | 170 } // namespace content |
| 155 | 171 |
| 156 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 172 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
| OLD | NEW |