Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: content/browser/renderer_host/media/video_capture_host.h

Issue 2410383002: VideoCapture: more migration IPC-->mojo, part 6 (Closed)
Patch Set: Comment correction Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 //
5 // VideoCaptureHost serves video capture related messages from
6 // VideoCaptureMessageFilter which lives inside the render process.
7 //
8 // This class is owned by RenderProcessHostImpl, and instantiated on UI
9 // thread, but all other operations and method calls happen on IO thread.
10 //
11 // Here's an example of a typical IPC dialog for video capture:
12 //
13 // Renderer VideoCaptureHost
14 // | |
15 // | --------- StartCapture --------> |
16 // | <------ VideoCaptureObserver ------ |
17 // | ::StateChanged(STARTED) |
18 // | < VideoCaptureMsg_NewBuffer(1) |
19 // | < VideoCaptureMsg_NewBuffer(2) |
20 // | < VideoCaptureMsg_NewBuffer(3) |
21 // | |
22 // | <-------- OnBufferReady(1) --------- |
23 // | <-------- OnBufferReady(2) --------- |
24 // | -------- ReleaseBuffer(1) ---------> |
25 // | <-------- OnBufferReady(3) --------- |
26 // | -------- ReleaseBuffer(2) ---------> |
27 // | <-------- OnBufferReady(1) --------- |
28 // | -------- ReleaseBuffer(3) ---------> |
29 // | <-------- OnBufferReady(2) --------- |
30 // | -------- ReleaseBuffer(1) ---------> |
31 // | ... |
32 // | <-------- OnBufferReady(3) --------- |
33 // = =
34 // | ... (resolution change) |
35 // | <------ OnBufferDestroyed(3) ------- | Buffers are re-allocated
36 // | < VideoCaptureMsg_NewBuffer(4) | with a larger size, as
37 // | <-------- OnBufferReady(4) --------- | needed.
38 // | -------- ReleaseBuffer(2) ---------> |
39 // | <------ OnBufferDestroyed(2) ------- |
40 // | < VideoCaptureMsg_NewBuffer(5) |
41 // | <-------- OnBufferReady(5) --------- |
42 // = ... =
43 // | |
44 // | < VideoCaptureMsg_BufferReady |
45 // | --------- StopCapture ---------> |
46 // | -------- ReleaseBuffer(n) ---------> |
47 // | <------ VideoCaptureObserver ------ |
48 // | ::StateChanged(STOPPED) |
49 // v v
50 4
51 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
52 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
53 7
54 #include <map> 8 #include <map>
55 9
56 #include "base/macros.h" 10 #include "base/macros.h"
57 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
58 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
59 #include "base/sequenced_task_runner_helpers.h" 13 #include "base/sequenced_task_runner_helpers.h"
60 #include "content/browser/renderer_host/media/video_capture_controller.h" 14 #include "content/browser/renderer_host/media/video_capture_controller.h"
61 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 15 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
62 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
63 #include "content/common/video_capture.mojom.h" 17 #include "content/common/video_capture.mojom.h"
64 #include "content/public/browser/browser_associated_interface.h" 18 #include "content/public/browser/browser_associated_interface.h"
65 #include "content/public/browser/browser_message_filter.h" 19 #include "content/public/browser/browser_message_filter.h"
66 #include "ipc/ipc_message.h" 20 #include "ipc/ipc_message.h"
67 21
68 namespace content { 22 namespace content {
69 class MediaStreamManager; 23 class MediaStreamManager;
70 24
25 // VideoCaptureHost is the IO thread browser process communication endpoint
26 // between a renderer process (which can initiate and receive a video capture
27 // stream) and a VideoCaptureController in the browser process (which provides
28 // the stream from a video device). Every remote client is identified via a
29 // unique |device_id|, and is paired with a single VideoCaptureController.
30 //
31 // This class is owned by RenderProcessHostImpl, and instantiated on UI thread,
32 // but all other operations and method calls happen on IO thread.
71 class CONTENT_EXPORT VideoCaptureHost 33 class CONTENT_EXPORT VideoCaptureHost
72 : public BrowserMessageFilter, 34 : public BrowserMessageFilter,
73 public VideoCaptureControllerEventHandler, 35 public VideoCaptureControllerEventHandler,
74 public BrowserAssociatedInterface<mojom::VideoCaptureHost>, 36 public BrowserAssociatedInterface<mojom::VideoCaptureHost>,
75 public mojom::VideoCaptureHost { 37 public mojom::VideoCaptureHost {
76 public: 38 public:
77 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); 39 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager);
78 40
41 private:
42 friend class BrowserThread;
43 friend class base::DeleteHelper<VideoCaptureHost>;
44 friend class VideoCaptureHostTest;
45
46 ~VideoCaptureHost() override;
47
79 // BrowserMessageFilter implementation. 48 // BrowserMessageFilter implementation.
80 void OnChannelClosing() override; 49 void OnChannelClosing() override;
81 void OnDestruct() const override; 50 void OnDestruct() const override;
82 bool OnMessageReceived(const IPC::Message& message) override; 51 bool OnMessageReceived(const IPC::Message& message) override;
83 52
84 // VideoCaptureControllerEventHandler implementation. 53 // VideoCaptureControllerEventHandler implementation.
85 void OnError(VideoCaptureControllerID id) override; 54 void OnError(VideoCaptureControllerID id) override;
86 void OnBufferCreated(VideoCaptureControllerID id, 55 void OnBufferCreated(VideoCaptureControllerID id,
87 base::SharedMemoryHandle handle, 56 mojo::ScopedSharedBufferHandle handle,
88 int length, 57 int length,
89 int buffer_id) override; 58 int buffer_id) override;
90 void OnBufferDestroyed(VideoCaptureControllerID id, 59 void OnBufferDestroyed(VideoCaptureControllerID id,
91 int buffer_id) override; 60 int buffer_id) override;
92 void OnBufferReady(VideoCaptureControllerID id, 61 void OnBufferReady(VideoCaptureControllerID id,
93 int buffer_id, 62 int buffer_id,
94 const scoped_refptr<media::VideoFrame>& frame) override; 63 const scoped_refptr<media::VideoFrame>& frame) override;
95 void OnEnded(VideoCaptureControllerID id) override; 64 void OnEnded(VideoCaptureControllerID id) override;
96 65
97 private:
98 friend class BrowserThread;
99 friend class base::DeleteHelper<VideoCaptureHost>;
100 friend class MockVideoCaptureHost;
101 friend class VideoCaptureHostTest;
102
103 void DoError(VideoCaptureControllerID id);
104 void DoEnded(VideoCaptureControllerID id);
105
106 ~VideoCaptureHost() override;
107
108 // mojom::VideoCaptureHost implementation 66 // mojom::VideoCaptureHost implementation
109 void Start(int32_t device_id, 67 void Start(int32_t device_id,
110 int32_t session_id, 68 int32_t session_id,
111 const media::VideoCaptureParams& params, 69 const media::VideoCaptureParams& params,
112 mojom::VideoCaptureObserverPtr observer) override; 70 mojom::VideoCaptureObserverPtr observer) override;
113 void Stop(int32_t device_id) override; 71 void Stop(int32_t device_id) override;
114 void Pause(int32_t device_id) override; 72 void Pause(int32_t device_id) override;
115 void Resume(int32_t device_id, 73 void Resume(int32_t device_id,
116 int32_t session_id, 74 int32_t session_id,
117 const media::VideoCaptureParams& params) override; 75 const media::VideoCaptureParams& params) override;
118 void RequestRefreshFrame(int32_t device_id) override; 76 void RequestRefreshFrame(int32_t device_id) override;
119 void ReleaseBuffer(int32_t device_id, 77 void ReleaseBuffer(int32_t device_id,
120 int32_t buffer_id, 78 int32_t buffer_id,
121 const gpu::SyncToken& sync_token, 79 const gpu::SyncToken& sync_token,
122 double consumer_resource_utilization) override; 80 double consumer_resource_utilization) override;
123 void GetDeviceSupportedFormats( 81 void GetDeviceSupportedFormats(
124 int32_t device_id, 82 int32_t device_id,
125 int32_t session_id, 83 int32_t session_id,
126 const GetDeviceSupportedFormatsCallback& callback) override; 84 const GetDeviceSupportedFormatsCallback& callback) override;
127 void GetDeviceFormatsInUse( 85 void GetDeviceFormatsInUse(
128 int32_t device_id, 86 int32_t device_id,
129 int32_t session_id, 87 int32_t session_id,
130 const GetDeviceFormatsInUseCallback& callback) override; 88 const GetDeviceFormatsInUseCallback& callback) override;
131 89
90 void DoError(VideoCaptureControllerID id);
91 void DoEnded(VideoCaptureControllerID id);
92
93 // Bound as callback for VideoCaptureManager::StartCaptureForClient().
132 void OnControllerAdded( 94 void OnControllerAdded(
133 int device_id, 95 int device_id,
134 const base::WeakPtr<VideoCaptureController>& controller); 96 const base::WeakPtr<VideoCaptureController>& controller);
135 97
136 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is 98 // Helper function that deletes the controller and tells VideoCaptureManager
137 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. 99 // to StopCaptureForClient(). |on_error| is true if this is triggered by
100 // VideoCaptureControllerEventHandler::OnError.
138 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id, 101 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id,
139 bool on_error); 102 bool on_error);
140 103
141 MediaStreamManager* const media_stream_manager_; 104 MediaStreamManager* const media_stream_manager_;
142 105
143 // A map of VideoCaptureControllerID to the VideoCaptureController to which it 106 // A map of VideoCaptureControllerID to the VideoCaptureController to which it
144 // is connected. An entry in this map holds a null controller while it is in 107 // is connected. An entry in this map holds a null controller while it is in
145 // the process of starting. 108 // the process of starting.
146 std::map<VideoCaptureControllerID, base::WeakPtr<VideoCaptureController>> 109 std::map<VideoCaptureControllerID, base::WeakPtr<VideoCaptureController>>
147 controllers_; 110 controllers_;
148 111
149 // VideoCaptureObservers map, each one is used and should be valid between 112 // VideoCaptureObservers map, each one is used and should be valid between
150 // Start() and the corresponding Stop(). 113 // Start() and the corresponding Stop().
151 std::map<int32_t, mojom::VideoCaptureObserverPtr> device_id_to_observer_map_; 114 std::map<int32_t, mojom::VideoCaptureObserverPtr> device_id_to_observer_map_;
152 115
153 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); 116 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
154 }; 117 };
155 118
156 } // namespace content 119 } // namespace content
157 120
158 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ 121 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698