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 BrowserRenderProcessHost, 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 19 matching lines...) Expand all Loading... |
30 // | VideoCaptureHostMsg_Stop > | | 30 // | VideoCaptureHostMsg_Stop > | |
31 // | VideoCaptureHostMsg_BufferReady > | | 31 // | VideoCaptureHostMsg_BufferReady > | |
32 // | < VideoCaptureMsg_StateChanged | | 32 // | < VideoCaptureMsg_StateChanged | |
33 // | (kStopped) | | 33 // | (kStopped) | |
34 // v v | 34 // v v |
35 | 35 |
36 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 36 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
37 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 37 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
38 | 38 |
39 #include <map> | 39 #include <map> |
| 40 #include <vector> |
40 | 41 |
41 #include "base/memory/ref_counted.h" | 42 #include "base/memory/ref_counted.h" |
42 #include "base/sequenced_task_runner_helpers.h" | 43 #include "base/sequenced_task_runner_helpers.h" |
43 #include "content/browser/renderer_host/media/video_capture_controller.h" | 44 #include "content/browser/renderer_host/media/video_capture_controller.h" |
44 #include "content/common/content_export.h" | 45 #include "content/common/content_export.h" |
45 #include "content/public/browser/browser_message_filter.h" | 46 #include "content/public/browser/browser_message_filter.h" |
46 #include "ipc/ipc_message.h" | 47 #include "ipc/ipc_message.h" |
| 48 #include "media/video/capture/video_capture_types.h" |
| 49 |
| 50 namespace media { |
| 51 |
| 52 struct RuntimeVideoEncodingParameters; |
| 53 struct VideoEncodingParameters; |
| 54 |
| 55 } // namespace media |
47 | 56 |
48 namespace content { | 57 namespace content { |
49 | 58 |
50 class CONTENT_EXPORT VideoCaptureHost | 59 class CONTENT_EXPORT VideoCaptureHost |
51 : public BrowserMessageFilter, | 60 : public BrowserMessageFilter, |
52 public VideoCaptureControllerEventHandler { | 61 public VideoCaptureControllerEventHandler { |
53 public: | 62 public: |
54 VideoCaptureHost(); | 63 VideoCaptureHost(); |
55 | 64 |
56 // BrowserMessageFilter implementation. | 65 // BrowserMessageFilter implementation. |
57 virtual void OnChannelClosing() OVERRIDE; | 66 virtual void OnChannelClosing() OVERRIDE; |
58 virtual void OnDestruct() const OVERRIDE; | 67 virtual void OnDestruct() const OVERRIDE; |
59 virtual bool OnMessageReceived(const IPC::Message& message, | 68 virtual bool OnMessageReceived(const IPC::Message& message, |
60 bool* message_was_ok) OVERRIDE; | 69 bool* message_was_ok) OVERRIDE; |
61 | 70 |
62 // VideoCaptureControllerEventHandler implementation. | 71 // VideoCaptureControllerEventHandler implementation. |
63 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE; | 72 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE; |
64 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | |
65 base::SharedMemoryHandle handle, | |
66 int length, int buffer_id) OVERRIDE; | |
67 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 73 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
68 int buffer_id, | 74 int buffer_id, |
69 base::Time timestamp) OVERRIDE; | 75 size_t data_size, |
| 76 base::Time timestamp, |
| 77 bool key_frame) OVERRIDE; |
70 virtual void OnFrameInfo(const VideoCaptureControllerID& id, | 78 virtual void OnFrameInfo(const VideoCaptureControllerID& id, |
71 int width, | 79 const media::VideoCaptureParams& params, |
72 int height, | 80 const std::vector<base::SharedMemoryHandle>& buffers, |
73 int frame_per_second) OVERRIDE; | 81 size_t buffer_size) OVERRIDE; |
| 82 virtual void OnEncodedFrameInfo( |
| 83 const VideoCaptureControllerID& id, |
| 84 const media::VideoEncodingParameters& params, |
| 85 const std::vector<base::SharedMemoryHandle>& buffers, |
| 86 size_t buffer_size) OVERRIDE; |
| 87 virtual void OnBitstreamConfigChanged( |
| 88 const VideoCaptureControllerID& id, |
| 89 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
74 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE; | 90 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE; |
75 | 91 |
76 private: | 92 private: |
77 friend class BrowserThread; | 93 friend class BrowserThread; |
78 friend class base::DeleteHelper<VideoCaptureHost>; | 94 friend class base::DeleteHelper<VideoCaptureHost>; |
79 friend class MockVideoCaptureHost; | 95 friend class MockVideoCaptureHost; |
80 friend class VideoCaptureHostTest; | 96 friend class VideoCaptureHostTest; |
81 | 97 |
82 virtual ~VideoCaptureHost(); | 98 virtual ~VideoCaptureHost(); |
83 | 99 |
84 // IPC message: Start capture on the VideoCaptureDevice referenced by | 100 // IPC message: Start capture on the VideoCaptureDevice referenced by |
85 // VideoCaptureParams::session_id. |device_id| is an id created by | 101 // VideoCaptureParams::session_id. |device_id| is an id created by |
86 // VideoCaptureMessageFilter to identify a session | 102 // VideoCaptureMessageFilter to identify a session between a |
87 // between a VideoCaptureMessageFilter and a VideoCaptureHost. | 103 // VideoCaptureMessageFilter and a VideoCaptureHost. |
88 void OnStartCapture(int device_id, | 104 void OnStartCapture(int device_id, |
89 const media::VideoCaptureParams& params); | 105 const media::VideoCaptureParams& params); |
90 void OnControllerAdded( | 106 void OnControllerAdded( |
91 int device_id, const media::VideoCaptureParams& params, | 107 int device_id, const media::VideoCaptureParams& params, |
92 VideoCaptureController* controller); | 108 VideoCaptureController* controller); |
93 void DoControllerAddedOnIOThread( | 109 void DoControllerAddedOnIOThread( |
94 int device_id, const media::VideoCaptureParams params, | 110 int device_id, const media::VideoCaptureParams params, |
95 VideoCaptureController* controller); | 111 VideoCaptureController* controller); |
96 | 112 |
97 // IPC message: Stop capture on device referenced by |device_id|. | 113 // IPC message: Stop capture on device referenced by |device_id|. |
98 void OnStopCapture(int device_id); | 114 void OnStopCapture(int device_id); |
99 | 115 |
100 // IPC message: Pause capture on device referenced by |device_id|. | 116 // IPC message: Pause capture on device referenced by |device_id|. |
101 void OnPauseCapture(int device_id); | 117 void OnPauseCapture(int device_id); |
102 | 118 |
103 // IPC message: Receive an empty buffer from renderer. Send it to device | 119 // IPC message: Receive an empty buffer from renderer. Send it to device |
104 // referenced by |device_id|. | 120 // referenced by |device_id|. |
105 void OnReceiveEmptyBuffer(int device_id, int buffer_id); | 121 void OnReceiveEmptyBuffer(int device_id, int buffer_id); |
106 | 122 |
| 123 // IPC message: Request the encoding capabilities for the capture session |
| 124 // referenced by |session_id|. |
| 125 void OnGetCapability(const media::VideoCaptureSessionId& session_id); |
| 126 void OnEncodingCapabilityFound( |
| 127 const media::VideoCaptureSessionId& session_id, |
| 128 const media::VideoEncodingCapability& capability); |
| 129 void DoEncodingCapabilityFoundOnIOThread( |
| 130 const media::VideoCaptureSessionId& session_id, |
| 131 const media::VideoEncodingCapability& capability); |
| 132 |
| 133 // IPC message: Start the encoded bitstream on the VideoCaptureDevice |
| 134 // referenced by |session_id|. |device_id| is an id created y |
| 135 // VideoCaptureMessageFilter to identify a session between a |
| 136 // VideoCaptureMessageFilter and a VideoCaptureHost. |
| 137 void OnCreateBitstream(int device_id, |
| 138 const media::VideoCaptureSessionId& session_id, |
| 139 const media::VideoEncodingParameters& params); |
| 140 |
| 141 // IPC message: Stop capture on device referenced by |device_id|. |
| 142 void OnDestroyBitstream(int device_id); |
| 143 |
| 144 // IPC message: Attempt to configure the encoded bitstream output from the |
| 145 // device referenced by |device_id|. |
| 146 void OnTryConfigureBitstream( |
| 147 int device_id, |
| 148 const media::RuntimeVideoEncodingParameters& params); |
| 149 |
| 150 // IPC message: Receive an empty buffer from renderer. Send it to device |
| 151 // referenced by |device_id|. |
| 152 void OnBitstreamBufferConsumed(int device_id, int buffer_id); |
| 153 |
107 // Send a newly created buffer to the VideoCaptureMessageFilter. | 154 // Send a newly created buffer to the VideoCaptureMessageFilter. |
108 void DoSendNewBufferOnIOThread( | 155 void DoSendNewBufferOnIOThread( |
109 const VideoCaptureControllerID& controller_id, | 156 const VideoCaptureControllerID& controller_id, |
110 base::SharedMemoryHandle handle, | 157 base::SharedMemoryHandle handle, |
111 int length, | 158 int length, |
112 int buffer_id); | 159 int buffer_id); |
113 | 160 |
114 // Send a filled buffer to the VideoCaptureMessageFilter. | 161 // Send a filled buffer to the VideoCaptureMessageFilter. |
115 void DoSendFilledBufferOnIOThread( | 162 void DoSendFilledBufferOnIOThread( |
116 const VideoCaptureControllerID& controller_id, | 163 const VideoCaptureControllerID& controller_id, |
117 int buffer_id, | 164 int buffer_id, |
118 base::Time timestamp); | 165 size_t size, |
| 166 base::Time timestamp, |
| 167 bool key_frame); |
| 168 |
| 169 // Handle error coming from VideoCaptureDevice. |
| 170 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); |
119 | 171 |
120 // Send information about frame resolution and frame rate | 172 // Send information about frame resolution and frame rate |
121 // to the VideoCaptureMessageFilter. | 173 // to the VideoCaptureMessageFilter. |
122 void DoSendFrameInfoOnIOThread( | 174 void DoSendFrameInfoOnIOThread( |
123 const VideoCaptureControllerID& controller_id, | 175 const VideoCaptureControllerID& controller_id, |
124 int width, | 176 const media::VideoCaptureParams& params, |
125 int height, | 177 const std::vector<base::SharedMemoryHandle>& buffers, |
126 int frame_per_second); | 178 size_t buffer_size); |
127 | 179 void DoSendEncodedFrameInfoOnIOThread( |
128 // Handle error coming from VideoCaptureDevice. | 180 const VideoCaptureControllerID& controller_id, |
129 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); | 181 const media::VideoEncodingParameters& params, |
| 182 const std::vector<base::SharedMemoryHandle>& buffers, |
| 183 size_t buffer_size); |
130 | 184 |
131 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); | 185 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); |
132 | 186 |
| 187 void DoBitstreamConfigChangedOnIOThread( |
| 188 const VideoCaptureControllerID& controller_id, |
| 189 const media::RuntimeVideoEncodingParameters& params); |
| 190 |
133 void DeleteVideoCaptureControllerOnIOThread( | 191 void DeleteVideoCaptureControllerOnIOThread( |
134 const VideoCaptureControllerID& controller_id); | 192 const VideoCaptureControllerID& controller_id); |
135 | 193 |
136 // Returns the video capture manager. This is a virtual function so that | 194 // Returns the video capture manager. This is a virtual function so that |
137 // the unit tests can inject their own MediaStreamManager. | 195 // the unit tests can inject their own MediaStreamManager. |
138 virtual VideoCaptureManager* GetVideoCaptureManager(); | 196 virtual VideoCaptureManager* GetVideoCaptureManager(); |
139 | 197 |
140 struct Entry; | 198 struct Entry; |
141 typedef std::map<VideoCaptureControllerID, Entry*> EntryMap; | 199 typedef std::map<VideoCaptureControllerID, Entry*> EntryMap; |
142 // A map of VideoCaptureControllerID to its state and VideoCaptureController. | 200 // A map of VideoCaptureControllerID to its state and VideoCaptureController. |
143 EntryMap entries_; | 201 EntryMap entries_; |
144 | 202 |
145 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); | 203 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); |
146 }; | 204 }; |
147 | 205 |
148 } // namespace content | 206 } // namespace content |
149 | 207 |
150 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 208 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
OLD | NEW |