| 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(int device_id, |
| 126 const media::VideoCaptureSessionId& session_id); |
| 127 void OnEncodingCapabilityFound( |
| 128 int device_id, |
| 129 const media::VideoEncodingCapability& capability); |
| 130 void DoEncodingCapabilityFoundOnIOThread( |
| 131 int device_id, |
| 132 const media::VideoEncodingCapability& capability); |
| 133 |
| 134 // IPC message: Start the encoded bitstream on the VideoCaptureDevice |
| 135 // referenced by |session_id|. |device_id| is an id created y |
| 136 // VideoCaptureMessageFilter to identify a session between a |
| 137 // VideoCaptureMessageFilter and a VideoCaptureHost. |
| 138 void OnCreateBitstream(int device_id, |
| 139 const media::VideoCaptureSessionId& session_id, |
| 140 const media::VideoEncodingParameters& params); |
| 141 |
| 142 // IPC message: Stop capture on device referenced by |device_id|. |
| 143 void OnDestroyBitstream(int device_id); |
| 144 |
| 145 // IPC message: Attempt to configure the encoded bitstream output from the |
| 146 // device referenced by |device_id|. |
| 147 void OnTryConfigureBitstream( |
| 148 int device_id, |
| 149 const media::RuntimeVideoEncodingParameters& params); |
| 150 |
| 151 // IPC message: Receive an empty buffer from renderer. Send it to device |
| 152 // referenced by |device_id|. |
| 153 void OnBitstreamBufferConsumed(int device_id, int buffer_id); |
| 154 |
| 107 // Send a newly created buffer to the VideoCaptureMessageFilter. | 155 // Send a newly created buffer to the VideoCaptureMessageFilter. |
| 108 void DoSendNewBufferOnIOThread( | 156 void DoSendNewBufferOnIOThread( |
| 109 const VideoCaptureControllerID& controller_id, | 157 const VideoCaptureControllerID& controller_id, |
| 110 base::SharedMemoryHandle handle, | 158 base::SharedMemoryHandle handle, |
| 111 int length, | 159 int length, |
| 112 int buffer_id); | 160 int buffer_id); |
| 113 | 161 |
| 114 // Send a filled buffer to the VideoCaptureMessageFilter. | 162 // Send a filled buffer to the VideoCaptureMessageFilter. |
| 115 void DoSendFilledBufferOnIOThread( | 163 void DoSendFilledBufferOnIOThread( |
| 116 const VideoCaptureControllerID& controller_id, | 164 const VideoCaptureControllerID& controller_id, |
| 117 int buffer_id, | 165 int buffer_id, |
| 118 base::Time timestamp); | 166 size_t size, |
| 167 base::Time timestamp, |
| 168 bool key_frame); |
| 169 |
| 170 // Handle error coming from VideoCaptureDevice. |
| 171 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); |
| 119 | 172 |
| 120 // Send information about frame resolution and frame rate | 173 // Send information about frame resolution and frame rate |
| 121 // to the VideoCaptureMessageFilter. | 174 // to the VideoCaptureMessageFilter. |
| 122 void DoSendFrameInfoOnIOThread( | 175 void DoSendFrameInfoOnIOThread( |
| 123 const VideoCaptureControllerID& controller_id, | 176 const VideoCaptureControllerID& controller_id, |
| 124 int width, | 177 const media::VideoCaptureParams& params, |
| 125 int height, | 178 const std::vector<base::SharedMemoryHandle>& buffers, |
| 126 int frame_per_second); | 179 size_t buffer_size); |
| 127 | 180 void DoSendEncodedFrameInfoOnIOThread( |
| 128 // Handle error coming from VideoCaptureDevice. | 181 const VideoCaptureControllerID& controller_id, |
| 129 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id); | 182 const media::VideoEncodingParameters& params, |
| 183 const std::vector<base::SharedMemoryHandle>& buffers, |
| 184 size_t buffer_size); |
| 130 | 185 |
| 131 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); | 186 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id); |
| 132 | 187 |
| 188 void DoBitstreamConfigChangedOnIOThread( |
| 189 const VideoCaptureControllerID& controller_id, |
| 190 const media::RuntimeVideoEncodingParameters& params); |
| 191 |
| 133 void DeleteVideoCaptureControllerOnIOThread( | 192 void DeleteVideoCaptureControllerOnIOThread( |
| 134 const VideoCaptureControllerID& controller_id); | 193 const VideoCaptureControllerID& controller_id); |
| 135 | 194 |
| 136 // Returns the video capture manager. This is a virtual function so that | 195 // Returns the video capture manager. This is a virtual function so that |
| 137 // the unit tests can inject their own MediaStreamManager. | 196 // the unit tests can inject their own MediaStreamManager. |
| 138 virtual VideoCaptureManager* GetVideoCaptureManager(); | 197 virtual VideoCaptureManager* GetVideoCaptureManager(); |
| 139 | 198 |
| 140 struct Entry; | 199 struct Entry; |
| 141 typedef std::map<VideoCaptureControllerID, Entry*> EntryMap; | 200 typedef std::map<VideoCaptureControllerID, Entry*> EntryMap; |
| 142 // A map of VideoCaptureControllerID to its state and VideoCaptureController. | 201 // A map of VideoCaptureControllerID to its state and VideoCaptureController. |
| 143 EntryMap entries_; | 202 EntryMap entries_; |
| 144 | 203 |
| 145 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); | 204 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost); |
| 146 }; | 205 }; |
| 147 | 206 |
| 148 } // namespace content | 207 } // namespace content |
| 149 | 208 |
| 150 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ | 209 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_ |
| OLD | NEW |