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

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

Issue 1017503002: VideoCaptureHost/VideoCaptureControllerEventHandler cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/base::TimeTicks/const base::TimeTicks&/, reinstalling OnEnded()/OnError->Do.. allowing for Delete… Created 5 years, 9 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 // 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 15 matching lines...) Expand all
26 // | VideoCaptureHostMsg_BufferReady(2) > | 26 // | VideoCaptureHostMsg_BufferReady(2) > |
27 // | < VideoCaptureMsg_BufferReady(1) | 27 // | < VideoCaptureMsg_BufferReady(1) |
28 // | VideoCaptureHostMsg_BufferReady(3) > | 28 // | VideoCaptureHostMsg_BufferReady(3) > |
29 // | < VideoCaptureMsg_BufferReady(2) | 29 // | < VideoCaptureMsg_BufferReady(2) |
30 // | VideoCaptureHostMsg_BufferReady(1) > | 30 // | VideoCaptureHostMsg_BufferReady(1) > |
31 // | ... | 31 // | ... |
32 // | < VideoCaptureMsg_BufferReady(3) | 32 // | < VideoCaptureMsg_BufferReady(3) |
33 // | | 33 // | |
34 // | ... (resolution change) | 34 // | ... (resolution change) |
35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated 35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated
36 // | < VideoCaptureMsg_NewBuffer(4) | at 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 // | 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/memory/ref_counted.h" 56 #include "base/memory/ref_counted.h"
57 #include "base/memory/weak_ptr.h" 57 #include "base/memory/weak_ptr.h"
58 #include "base/sequenced_task_runner_helpers.h" 58 #include "base/sequenced_task_runner_helpers.h"
59 #include "content/browser/renderer_host/media/video_capture_controller.h" 59 #include "content/browser/renderer_host/media/video_capture_controller.h"
60 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
60 #include "content/common/content_export.h" 61 #include "content/common/content_export.h"
61 #include "content/public/browser/browser_message_filter.h" 62 #include "content/public/browser/browser_message_filter.h"
62 #include "ipc/ipc_message.h" 63 #include "ipc/ipc_message.h"
63 64
64 namespace content { 65 namespace content {
65 class MediaStreamManager; 66 class MediaStreamManager;
66 67
67 class CONTENT_EXPORT VideoCaptureHost 68 class CONTENT_EXPORT VideoCaptureHost
68 : public BrowserMessageFilter, 69 : public BrowserMessageFilter,
69 public VideoCaptureControllerEventHandler { 70 public VideoCaptureControllerEventHandler {
70 public: 71 public:
71 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager); 72 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager);
72 73
73 // BrowserMessageFilter implementation. 74 // BrowserMessageFilter implementation.
74 void OnChannelClosing() override; 75 void OnChannelClosing() override;
75 void OnDestruct() const override; 76 void OnDestruct() const override;
76 bool OnMessageReceived(const IPC::Message& message) override; 77 bool OnMessageReceived(const IPC::Message& message) override;
77 78
78 // VideoCaptureControllerEventHandler implementation. 79 // VideoCaptureControllerEventHandler implementation.
79 void OnError(const VideoCaptureControllerID& id) override; 80 void OnError(VideoCaptureControllerID id) override;
80 void OnBufferCreated(const VideoCaptureControllerID& id, 81 void OnBufferCreated(VideoCaptureControllerID id,
81 base::SharedMemoryHandle handle, 82 base::SharedMemoryHandle handle,
82 int length, 83 int length,
83 int buffer_id) override; 84 int buffer_id) override;
84 void OnBufferDestroyed(const VideoCaptureControllerID& id, 85 void OnBufferDestroyed(VideoCaptureControllerID id,
85 int buffer_id) override; 86 int buffer_id) override;
86 void OnBufferReady(const VideoCaptureControllerID& id, 87 void OnBufferReady(VideoCaptureControllerID id,
87 int buffer_id, 88 int buffer_id,
88 const gfx::Size& coded_size, 89 const gfx::Size& coded_size,
89 const gfx::Rect& visible_rect, 90 const gfx::Rect& visible_rect,
90 base::TimeTicks timestamp, 91 const base::TimeTicks& timestamp,
91 scoped_ptr<base::DictionaryValue> metadata) override; 92 scoped_ptr<base::DictionaryValue> metadata) override;
92 void OnMailboxBufferReady( 93 void OnMailboxBufferReady(
93 const VideoCaptureControllerID& id, 94 VideoCaptureControllerID id,
94 int buffer_id, 95 int buffer_id,
95 const gpu::MailboxHolder& mailbox_holder, 96 const gpu::MailboxHolder& mailbox_holder,
96 const gfx::Size& packed_frame_size, 97 const gfx::Size& packed_frame_size,
97 base::TimeTicks timestamp, 98 const base::TimeTicks& timestamp,
98 scoped_ptr<base::DictionaryValue> metadata) override; 99 scoped_ptr<base::DictionaryValue> metadata) override;
99 void OnEnded(const VideoCaptureControllerID& id) override; 100 void OnEnded(VideoCaptureControllerID id) override;
100 101
101 private: 102 private:
102 friend class BrowserThread; 103 friend class BrowserThread;
103 friend class base::DeleteHelper<VideoCaptureHost>; 104 friend class base::DeleteHelper<VideoCaptureHost>;
104 friend class MockVideoCaptureHost; 105 friend class MockVideoCaptureHost;
105 friend class VideoCaptureHostTest; 106 friend class VideoCaptureHostTest;
106 107
108 void DoError(VideoCaptureControllerID id);
109 void DoEnded(VideoCaptureControllerID id);
110
107 ~VideoCaptureHost() override; 111 ~VideoCaptureHost() override;
108 112
109 // IPC message: Start capture on the VideoCaptureDevice referenced by 113 // IPC message: Start capture on the VideoCaptureDevice referenced by
110 // |session_id|. |device_id| is an id created by VideoCaptureMessageFilter 114 // |device_id|. |session_id| is an id created by VideoCaptureMessageFilter
111 // to identify a session between a VideoCaptureMessageFilter and a 115 // to identify a session between a VideoCaptureMessageFilter and a
112 // VideoCaptureHost. 116 // VideoCaptureHost.
113 void OnStartCapture(int device_id, 117 void OnStartCapture(int device_id,
114 media::VideoCaptureSessionId session_id, 118 media::VideoCaptureSessionId session_id,
115 const media::VideoCaptureParams& params); 119 const media::VideoCaptureParams& params);
116 void OnControllerAdded( 120 void OnControllerAdded(
117 int device_id, 121 int device_id,
118 const base::WeakPtr<VideoCaptureController>& controller); 122 const base::WeakPtr<VideoCaptureController>& controller);
119 void DoControllerAddedOnIOThread(
120 int device_id,
121 const base::WeakPtr<VideoCaptureController>& controller);
122 123
123 // IPC message: Stop capture on device referenced by |device_id|. 124 // IPC message: Stop capture on device referenced by |device_id|.
124 void OnStopCapture(int device_id); 125 void OnStopCapture(int device_id);
125 126
126 // IPC message: Pause capture on device referenced by |device_id|. 127 // IPC message: Pause capture on device referenced by |device_id|.
127 void OnPauseCapture(int device_id); 128 void OnPauseCapture(int device_id);
128 129
129 void OnResumeCapture(int device_id, 130 void OnResumeCapture(int device_id,
130 media::VideoCaptureSessionId session_id, 131 media::VideoCaptureSessionId session_id,
131 const media::VideoCaptureParams& params); 132 const media::VideoCaptureParams& params);
132 133
133 // IPC message: Receive an empty buffer from renderer. Send it to device 134 // IPC message: Receive an empty buffer from renderer. Send it to device
134 // referenced by |device_id|. 135 // referenced by |device_id|.
135 void OnReceiveEmptyBuffer(int device_id, int buffer_id, uint32 sync_point); 136 void OnReceiveEmptyBuffer(int device_id, int buffer_id, uint32 sync_point);
136 137
137 // IPC message: Get supported formats referenced by |capture_session_id|. 138 // IPC message: Get supported formats referenced by |capture_session_id|.
138 // |device_id| is needed for message back-routing purposes. 139 // |device_id| is needed for message back-routing purposes.
139 void OnGetDeviceSupportedFormats( 140 void OnGetDeviceSupportedFormats(
140 int device_id, 141 int device_id,
141 media::VideoCaptureSessionId capture_session_id); 142 media::VideoCaptureSessionId capture_session_id);
142 143
143 // IPC message: Get a device's currently in use format(s), referenced by 144 // IPC message: Get a device's currently in use format(s), referenced by
144 // |capture_session_id|. |device_id| is needed for message back-routing 145 // |capture_session_id|. |device_id| is needed for message back-routing
145 // purposes. 146 // purposes.
146 void OnGetDeviceFormatsInUse( 147 void OnGetDeviceFormatsInUse(int device_id,
147 int device_id, 148 media::VideoCaptureSessionId capture_session_id);
148 media::VideoCaptureSessionId capture_session_id);
149
150 // Sends a newly created buffer to the VideoCaptureMessageFilter.
151 void DoSendNewBufferOnIOThread(
152 const VideoCaptureControllerID& controller_id,
153 base::SharedMemoryHandle handle,
154 int length,
155 int buffer_id);
156
157 void DoSendFreeBufferOnIOThread(
158 const VideoCaptureControllerID& controller_id,
159 int buffer_id);
160
161 // Sends a filled buffer to the VideoCaptureMessageFilter.
162 void DoSendFilledBufferOnIOThread(
163 const VideoCaptureControllerID& controller_id,
164 int buffer_id,
165 const gfx::Size& coded_size,
166 const gfx::Rect& visible_rect,
167 base::TimeTicks timestamp,
168 scoped_ptr<base::DictionaryValue> metadata);
169
170 // Sends a filled texture mailbox buffer to the VideoCaptureMessageFilter.
171 void DoSendFilledMailboxBufferOnIOThread(
172 const VideoCaptureControllerID& controller_id,
173 int buffer_id,
174 const gpu::MailboxHolder& mailbox_holder,
175 const gfx::Size& packed_frame_size,
176 base::TimeTicks timestamp,
177 scoped_ptr<base::DictionaryValue> metadata);
178
179 // Handles error coming from VideoCaptureDevice.
180 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id);
181
182 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id);
183 149
184 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is 150 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is
185 // true if this is triggered by VideoCaptureControllerEventHandler::OnError. 151 // true if this is triggered by VideoCaptureControllerEventHandler::OnError.
186 void DeleteVideoCaptureControllerOnIOThread( 152 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id,
187 const VideoCaptureControllerID& controller_id, bool on_error); 153 bool on_error);
188 154
189 MediaStreamManager* media_stream_manager_; 155 MediaStreamManager* const media_stream_manager_;
190 156
191 typedef std::map<VideoCaptureControllerID, 157 typedef std::map<VideoCaptureControllerID,
192 base::WeakPtr<VideoCaptureController> > EntryMap; 158 base::WeakPtr<VideoCaptureController>> EntryMap;
193 159
194 // A map of VideoCaptureControllerID to the VideoCaptureController to which it 160 // A map of VideoCaptureControllerID to the VideoCaptureController to which it
195 // is connected. An entry in this map holds a null controller while it is in 161 // is connected. An entry in this map holds a null controller while it is in
196 // the process of starting. 162 // the process of starting.
197 EntryMap entries_; 163 EntryMap entries_;
198 164
199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); 165 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
200 }; 166 };
201 167
202 } // namespace content 168 } // namespace content
203 169
204 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ 170 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698