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 BrowserRenderProcessHost, 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 // |
11 // Here's an example of a typical IPC dialog for video capture: | 11 // Here's an example of a typical IPC dialog for video capture: |
12 // | 12 // |
13 // Renderer VideoCaptureHost | 13 // Renderer VideoCaptureHost |
14 // | | | 14 // | | |
15 // | VideoCaptureHostMsg_Start > | | 15 // | VideoCaptureHostMsg_Start > | |
16 // | < VideoCaptureMsg_DeviceInfo | | 16 // | < VideoCaptureMsg_StateChanged | |
17 // | | | 17 // | (VIDEO_CAPTURE_STATE_STARTED) | |
18 // | < VideoCaptureMsg_StateChanged | | 18 // | < VideoCaptureMsg_NewBuffer(1) | |
19 // | (kStarted) | | 19 // | < VideoCaptureMsg_NewBuffer(2) | |
20 // | < VideoCaptureMsg_BufferReady | | 20 // | < VideoCaptureMsg_NewBuffer(3) | |
21 // | ... | | 21 // | | |
22 // | < VideoCaptureMsg_BufferReady | | 22 // | < VideoCaptureMsg_BufferReady(1) | |
23 // | ... | | 23 // | < VideoCaptureMsg_BufferReady(2) | |
24 // | VideoCaptureHostMsg_BufferReady > | | 24 // | VideoCaptureHostMsg_BufferReady(1) > | |
25 // | VideoCaptureHostMsg_BufferReady > | | 25 // | < VideoCaptureMsg_BufferReady(3) | |
26 // | | | 26 // | VideoCaptureHostMsg_BufferReady(2) > | |
27 // | ... | | 27 // | < VideoCaptureMsg_BufferReady(1) | |
28 // | | | 28 // | VideoCaptureHostMsg_BufferReady(3) > | |
29 // | < VideoCaptureMsg_BufferReady | | 29 // | < VideoCaptureMsg_BufferReady(2) | |
30 // | VideoCaptureHostMsg_Stop > | | 30 // | VideoCaptureHostMsg_BufferReady(1) > | |
31 // | VideoCaptureHostMsg_BufferReady > | | 31 // | ... | |
32 // | < VideoCaptureMsg_StateChanged | | 32 // | < VideoCaptureMsg_BufferReady(3) | |
33 // | (kStopped) | | 33 // | | |
34 // v v | 34 // | ... (resolution change) | |
| 35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated |
| 36 // | < VideoCaptureMsg_NewBuffer(4) | at a larger size, as |
| 37 // | < VideoCaptureMsg_BufferReady(4) | needed. |
| 38 // | VideoCaptureHostMsg_BufferReady(2) > | |
| 39 // | < VideoCaptureMsg_FreeBuffer(2) | |
| 40 // | < VideoCaptureMsg_NewBuffer(5) | |
| 41 // | < VideoCaptureMsg_BufferReady(5) | |
| 42 // | ... | |
| 43 // | | |
| 44 // | < VideoCaptureMsg_BufferReady | |
| 45 // | VideoCaptureHostMsg_Stop > | |
| 46 // | VideoCaptureHostMsg_BufferReady > | |
| 47 // | < VideoCaptureMsg_StateChanged | |
| 48 // | (VIDEO_CAPTURE_STATE_STOPPED) | |
| 49 // v v |
35 | 50 |
36 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 51 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
37 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 52 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
38 | 53 |
39 #include <map> | 54 #include <map> |
40 | 55 |
41 #include "base/memory/ref_counted.h" | 56 #include "base/memory/ref_counted.h" |
42 #include "base/memory/weak_ptr.h" | 57 #include "base/memory/weak_ptr.h" |
43 #include "base/sequenced_task_runner_helpers.h" | 58 #include "base/sequenced_task_runner_helpers.h" |
44 #include "content/browser/renderer_host/media/video_capture_controller.h" | 59 #include "content/browser/renderer_host/media/video_capture_controller.h" |
(...skipping 17 matching lines...) Expand all Loading... |
62 // BrowserMessageFilter implementation. | 77 // BrowserMessageFilter implementation. |
63 virtual void OnChannelClosing() OVERRIDE; | 78 virtual void OnChannelClosing() OVERRIDE; |
64 virtual void OnDestruct() const OVERRIDE; | 79 virtual void OnDestruct() const OVERRIDE; |
65 virtual bool OnMessageReceived(const IPC::Message& message, | 80 virtual bool OnMessageReceived(const IPC::Message& message, |
66 bool* message_was_ok) OVERRIDE; | 81 bool* message_was_ok) OVERRIDE; |
67 | 82 |
68 // VideoCaptureControllerEventHandler implementation. | 83 // VideoCaptureControllerEventHandler implementation. |
69 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE; | 84 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE; |
70 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 85 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
71 base::SharedMemoryHandle handle, | 86 base::SharedMemoryHandle handle, |
72 int length, int buffer_id) OVERRIDE; | 87 int length, |
73 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 88 int buffer_id) OVERRIDE; |
74 int buffer_id, | 89 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
75 base::Time timestamp) OVERRIDE; | 90 int buffer_id) OVERRIDE; |
76 virtual void OnFrameInfo( | 91 virtual void OnBufferReady( |
77 const VideoCaptureControllerID& id, | 92 const VideoCaptureControllerID& id, |
78 const media::VideoCaptureCapability& format) OVERRIDE; | 93 int buffer_id, |
79 virtual void OnFrameInfoChanged(const VideoCaptureControllerID& id, | 94 base::Time timestamp, |
80 int width, | 95 const media::VideoCaptureFormat& format) OVERRIDE; |
81 int height, | |
82 int frame_per_second) OVERRIDE; | |
83 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE; | 96 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE; |
84 | 97 |
85 private: | 98 private: |
86 friend class BrowserThread; | 99 friend class BrowserThread; |
87 friend class base::DeleteHelper<VideoCaptureHost>; | 100 friend class base::DeleteHelper<VideoCaptureHost>; |
88 friend class MockVideoCaptureHost; | 101 friend class MockVideoCaptureHost; |
89 friend class VideoCaptureHostTest; | 102 friend class VideoCaptureHostTest; |
90 | 103 |
91 virtual ~VideoCaptureHost(); | 104 virtual ~VideoCaptureHost(); |
92 | 105 |
93 // IPC message: Start capture on the VideoCaptureDevice referenced by | 106 // IPC message: Start capture on the VideoCaptureDevice referenced by |
94 // VideoCaptureParams::session_id. |device_id| is an id created by | 107 // VideoCaptureParams::session_id. |device_id| is an id created by |
95 // VideoCaptureMessageFilter to identify a session | 108 // VideoCaptureMessageFilter to identify a session |
96 // between a VideoCaptureMessageFilter and a VideoCaptureHost. | 109 // between a VideoCaptureMessageFilter and a VideoCaptureHost. |
97 void OnStartCapture(int device_id, | 110 void OnStartCapture(int device_id, |
98 const media::VideoCaptureParams& params); | 111 const media::VideoCaptureParams& params); |
99 void OnControllerAdded( | 112 void OnControllerAdded( |
100 int device_id, const media::VideoCaptureParams& params, | 113 int device_id, const media::VideoCaptureParams& params, |
101 const base::WeakPtr<VideoCaptureController>& controller); | 114 const base::WeakPtr<VideoCaptureController>& controller); |
102 void DoControllerAddedOnIOThread( | 115 void DoControllerAddedOnIOThread( |
103 int device_id, const media::VideoCaptureParams params, | 116 int device_id, const media::VideoCaptureParams& params, |
104 const base::WeakPtr<VideoCaptureController>& controller); | 117 const base::WeakPtr<VideoCaptureController>& controller); |
105 | 118 |
106 // IPC message: Stop capture on device referenced by |device_id|. | 119 // IPC message: Stop capture on device referenced by |device_id|. |
107 void OnStopCapture(int device_id); | 120 void OnStopCapture(int device_id); |
108 | 121 |
109 // IPC message: Pause capture on device referenced by |device_id|. | 122 // IPC message: Pause capture on device referenced by |device_id|. |
110 void OnPauseCapture(int device_id); | 123 void OnPauseCapture(int device_id); |
111 | 124 |
112 // IPC message: Receive an empty buffer from renderer. Send it to device | 125 // IPC message: Receive an empty buffer from renderer. Send it to device |
113 // referenced by |device_id|. | 126 // referenced by |device_id|. |
114 void OnReceiveEmptyBuffer(int device_id, int buffer_id); | 127 void OnReceiveEmptyBuffer(int device_id, int buffer_id); |
115 | 128 |
116 // Send a newly created buffer to the VideoCaptureMessageFilter. | 129 // Send a newly created buffer to the VideoCaptureMessageFilter. |
117 void DoSendNewBufferOnIOThread( | 130 void DoSendNewBufferOnIOThread( |
118 const VideoCaptureControllerID& controller_id, | 131 const VideoCaptureControllerID& controller_id, |
119 base::SharedMemoryHandle handle, | 132 base::SharedMemoryHandle handle, |
120 int length, | 133 int length, |
121 int buffer_id); | 134 int buffer_id); |
122 | 135 |
| 136 void DoSendFreeBufferOnIOThread( |
| 137 const VideoCaptureControllerID& controller_id, |
| 138 int buffer_id); |
| 139 |
123 // Send a filled buffer to the VideoCaptureMessageFilter. | 140 // Send a filled buffer to the VideoCaptureMessageFilter. |
124 void DoSendFilledBufferOnIOThread( | 141 void DoSendFilledBufferOnIOThread( |
125 const VideoCaptureControllerID& controller_id, | 142 const VideoCaptureControllerID& controller_id, |
126 int buffer_id, | 143 int buffer_id, |
127 base::Time timestamp); | 144 base::Time timestamp, |
128 | 145 const media::VideoCaptureFormat& format); |
129 // Send information about the capture parameters (resolution, frame rate etc) | |
130 // to the VideoCaptureMessageFilter. | |
131 void DoSendFrameInfoOnIOThread(const VideoCaptureControllerID& controller_id, | |
132 const media::VideoCaptureCapability& format); | |
133 | |
134 // Send newly changed information about frame resolution and frame rate | |
135 // to the VideoCaptureMessageFilter. | |
136 void DoSendFrameInfoChangedOnIOThread( | |
137 const VideoCaptureControllerID& controller_id, | |
138 int width, | |
139 int height, | |
140 int frame_per_second); | |
141 | 146 |
142 // Handle error coming from VideoCaptureDevice. | 147 // Handle error coming from VideoCaptureDevice. |
143 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); | 148 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); |
144 | 149 |
145 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); | 150 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); |
146 | 151 |
147 void DeleteVideoCaptureControllerOnIOThread( | 152 void DeleteVideoCaptureControllerOnIOThread( |
148 const VideoCaptureControllerID& controller_id); | 153 const VideoCaptureControllerID& controller_id); |
149 | 154 |
150 MediaStreamManager* media_stream_manager_; | 155 MediaStreamManager* media_stream_manager_; |
151 | 156 |
152 typedef std::map<VideoCaptureControllerID, | 157 typedef std::map<VideoCaptureControllerID, |
153 base::WeakPtr<VideoCaptureController> > EntryMap; | 158 base::WeakPtr<VideoCaptureController> > EntryMap; |
154 | 159 |
155 // A map of VideoCaptureControllerID to the VideoCaptureController to which it | 160 // A map of VideoCaptureControllerID to the VideoCaptureController to which it |
156 // 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 |
157 // the process of starting. | 162 // the process of starting. |
158 EntryMap entries_; | 163 EntryMap entries_; |
159 | 164 |
160 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); | 165 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); |
161 }; | 166 }; |
162 | 167 |
163 } // namespace content | 168 } // namespace content |
164 | 169 |
165 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 170 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
OLD | NEW |