| 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 // VideoCaptureController is the glue between VideoCaptureHost, | 5 // VideoCaptureController is the glue between VideoCaptureHost, |
| 6 // VideoCaptureManager and VideoCaptureDevice. | 6 // VideoCaptureManager and VideoCaptureDevice. |
| 7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and | 7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and |
| 8 // is responsible for keeping track of shared DIBs and filling them with I420 | 8 // is responsible for keeping track of shared DIBs and filling them with I420 |
| 9 // video frames for IPC communication between VideoCaptureHost and | 9 // video frames for IPC communication between VideoCaptureHost and |
| 10 // VideoCaptureMessageFilter. | 10 // VideoCaptureMessageFilter. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/memory/ref_counted.h" | 23 #include "base/memory/ref_counted.h" |
| 24 #include "base/process.h" | 24 #include "base/process.h" |
| 25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 26 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 26 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
| 27 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 27 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 28 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
| 29 #include "content/common/media/video_capture.h" | 29 #include "content/common/media/video_capture.h" |
| 30 #include "media/video/capture/video_capture.h" | 30 #include "media/video/capture/video_capture.h" |
| 31 #include "media/video/capture/video_capture_device.h" | 31 #include "media/video/capture/video_capture_device.h" |
| 32 #include "media/video/capture/video_capture_types.h" | 32 #include "media/video/capture/video_capture_types.h" |
| 33 #include "media/video/video_encode_types.h" |
| 33 | 34 |
| 34 namespace content { | 35 namespace content { |
| 35 class VideoCaptureManager; | 36 class VideoCaptureManager; |
| 36 class VideoCaptureBufferPool; | 37 class VideoCaptureBufferPool; |
| 37 | 38 |
| 38 class CONTENT_EXPORT VideoCaptureController | 39 class CONTENT_EXPORT VideoCaptureController |
| 39 : public base::RefCountedThreadSafe<VideoCaptureController>, | 40 : public base::RefCountedThreadSafe<VideoCaptureController>, |
| 40 public media::VideoCaptureDevice::EventHandler { | 41 public media::VideoCaptureDevice::EventHandler { |
| 41 public: | 42 public: |
| 42 VideoCaptureController(VideoCaptureManager* video_capture_manager); | 43 VideoCaptureController(VideoCaptureManager* video_capture_manager); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 // API called directly by VideoCaptureManager in case the device is | 61 // API called directly by VideoCaptureManager in case the device is |
| 61 // prematurely closed. | 62 // prematurely closed. |
| 62 void StopSession(int session_id); | 63 void StopSession(int session_id); |
| 63 | 64 |
| 64 // Return a buffer previously given in | 65 // Return a buffer previously given in |
| 65 // VideoCaptureControllerEventHandler::OnBufferReady. | 66 // VideoCaptureControllerEventHandler::OnBufferReady. |
| 66 void ReturnBuffer(const VideoCaptureControllerID& id, | 67 void ReturnBuffer(const VideoCaptureControllerID& id, |
| 67 VideoCaptureControllerEventHandler* event_handler, | 68 VideoCaptureControllerEventHandler* event_handler, |
| 68 int buffer_id); | 69 int buffer_id); |
| 69 | 70 |
| 71 // Attempt to configure the encoding parameters for an encoded bitstream. |
| 72 // Fails silently if the capture device does not support encoding. |
| 73 void TryConfigureEncodedBitstream( |
| 74 const media::RuntimeVideoEncodingParameters& params); |
| 75 |
| 70 // Implement media::VideoCaptureDevice::EventHandler. | 76 // Implement media::VideoCaptureDevice::EventHandler. |
| 71 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer() OVERRIDE; | 77 virtual scoped_refptr<media::VideoFrame> ReserveOutputVideoFrame() OVERRIDE; |
| 78 virtual scoped_refptr<media::EncodedBitstreamBuffer> |
| 79 ReserveOutputEncodedBitstreamBuffer() OVERRIDE; |
| 72 virtual void OnIncomingCapturedFrame(const uint8* data, | 80 virtual void OnIncomingCapturedFrame(const uint8* data, |
| 73 int length, | 81 int length, |
| 74 base::Time timestamp, | 82 base::Time timestamp, |
| 75 int rotation, | 83 int rotation, |
| 76 bool flip_vert, | 84 bool flip_vert, |
| 77 bool flip_horiz) OVERRIDE; | 85 bool flip_horiz) OVERRIDE; |
| 78 virtual void OnIncomingCapturedVideoFrame( | 86 virtual void OnIncomingCapturedVideoFrame( |
| 79 const scoped_refptr<media::VideoFrame>& frame, | 87 const scoped_refptr<media::VideoFrame>& frame, |
| 80 base::Time timestamp) OVERRIDE; | 88 base::Time timestamp) OVERRIDE; |
| 89 virtual void OnIncomingCapturedEncodedBitstreamBuffer( |
| 90 const scoped_refptr<media::EncodedBitstreamBuffer>& buffer, |
| 91 size_t data_size, |
| 92 base::Time timestamp) OVERRIDE; |
| 81 virtual void OnError() OVERRIDE; | 93 virtual void OnError() OVERRIDE; |
| 82 virtual void OnFrameInfo( | 94 virtual void OnFrameInfo( |
| 83 const media::VideoCaptureCapability& info) OVERRIDE; | 95 const media::VideoCaptureCapability& info) OVERRIDE; |
| 96 virtual void OnEncodedFrameInfo( |
| 97 const media::VideoEncodingParameters& info) OVERRIDE; |
| 98 virtual void OnBitstreamConfigChanged( |
| 99 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
| 84 | 100 |
| 85 // Reserve a media::VideoFrame in I420 format from a buffer pool. | 101 // Reserve a media::VideoFrame in I420 format from a buffer pool. |
| 86 static scoped_refptr<media::VideoFrame> ReserveI420VideoFrame( | 102 static scoped_refptr<media::VideoFrame> ReserveI420VideoFrame( |
| 87 VideoCaptureBufferPool* buffer_pool, const gfx::Size& size); | 103 VideoCaptureBufferPool* buffer_pool, const gfx::Size& size); |
| 88 | 104 |
| 105 // Reserve a media::EncodedBitstreaBuffer from a buffer pool. |
| 106 static scoped_refptr<media::EncodedBitstreamBuffer> |
| 107 ReserveEncodedBitstreamBuffer(VideoCaptureBufferPool* buffer_pool); |
| 108 |
| 89 protected: | 109 protected: |
| 90 virtual ~VideoCaptureController(); | 110 virtual ~VideoCaptureController(); |
| 91 | 111 |
| 92 private: | 112 private: |
| 93 friend class base::RefCountedThreadSafe<VideoCaptureController>; | 113 friend class base::RefCountedThreadSafe<VideoCaptureController>; |
| 94 | 114 |
| 95 struct ControllerClient; | 115 struct ControllerClient; |
| 96 typedef std::list<ControllerClient*> ControllerClients; | 116 typedef std::list<ControllerClient*> ControllerClients; |
| 97 | 117 |
| 98 // Callback when manager has stopped device. | 118 // Callback when manager has stopped device. |
| 99 void OnDeviceStopped(); | 119 void OnDeviceStopped(); |
| 100 | 120 |
| 101 // Worker functions on IO thread. | 121 // Worker functions on IO thread. |
| 102 void DoIncomingCapturedFrameOnIOThread( | 122 void DoIncomingCapturedVideoFrameOnIOThread( |
| 103 const scoped_refptr<media::VideoFrame>& captured_frame, | 123 const scoped_refptr<media::VideoFrame>& frame, |
| 104 base::Time timestamp); | 124 base::Time timestamp); |
| 105 void DoFrameInfoOnIOThread(); | 125 void DoIncomingCapturedEncodedBitstreamBufferOnIOThread( |
| 126 const scoped_refptr<media::EncodedBitstreamBuffer>& buffer, |
| 127 size_t data_size, |
| 128 base::Time timestamp); |
| 129 void DoIncomingCapturedSharedMemoryOnIOThread( |
| 130 base::SharedMemoryHandle reserved_handle, |
| 131 size_t data_size, |
| 132 base::Time timestamp); |
| 133 void DoFrameInfoOnIOThread(bool encoded); |
| 134 void DoBitstreamConfigChangedOnIOThread( |
| 135 const media::RuntimeVideoEncodingParameters& params); |
| 106 void DoErrorOnIOThread(); | 136 void DoErrorOnIOThread(); |
| 107 void DoDeviceStoppedOnIOThread(); | 137 void DoDeviceStoppedOnIOThread(); |
| 108 | 138 |
| 109 // Send frame info and init buffers to |client|. | 139 // Send frame info and init buffers to |client|. |
| 110 void SendFrameInfoAndBuffers(ControllerClient* client); | 140 void SendFrameInfoAndBuffers(ControllerClient* client); |
| 111 | 141 |
| 112 // Find a client of |id| and |handler| in |clients|. | 142 // Find a client of |id| and |handler| in |clients|. |
| 113 ControllerClient* FindClient( | 143 ControllerClient* FindClient( |
| 114 const VideoCaptureControllerID& id, | 144 const VideoCaptureControllerID& id, |
| 115 VideoCaptureControllerEventHandler* handler, | 145 VideoCaptureControllerEventHandler* handler, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 136 | 166 |
| 137 // All clients waiting for service. | 167 // All clients waiting for service. |
| 138 ControllerClients pending_clients_; | 168 ControllerClients pending_clients_; |
| 139 | 169 |
| 140 // The parameter that currently used for the capturing. | 170 // The parameter that currently used for the capturing. |
| 141 media::VideoCaptureParams current_params_; | 171 media::VideoCaptureParams current_params_; |
| 142 | 172 |
| 143 // It's modified on caller thread, assuming there is only one OnFrameInfo() | 173 // It's modified on caller thread, assuming there is only one OnFrameInfo() |
| 144 // call per StartCapture(). | 174 // call per StartCapture(). |
| 145 media::VideoCaptureCapability frame_info_; | 175 media::VideoCaptureCapability frame_info_; |
| 176 media::VideoEncodingParameters encoded_frame_info_; |
| 146 | 177 |
| 147 // Chopped pixels in width/height in case video capture device has odd numbers | 178 // Chopped pixels in width/height in case video capture device has odd numbers |
| 148 // for width/height. | 179 // for width/height. |
| 149 int chopped_width_; | 180 int chopped_width_; |
| 150 int chopped_height_; | 181 int chopped_height_; |
| 151 | 182 |
| 152 // It's accessed only on IO thread. | 183 // It's accessed only on IO thread. |
| 153 bool frame_info_available_; | 184 bool frame_info_available_; |
| 185 bool encoded_frame_info_available_; |
| 154 | 186 |
| 155 VideoCaptureManager* video_capture_manager_; | 187 VideoCaptureManager* video_capture_manager_; |
| 156 | 188 |
| 157 bool device_in_use_; | 189 bool device_in_use_; |
| 158 VideoCaptureState state_; | 190 VideoCaptureState state_; |
| 159 | 191 |
| 160 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); | 192 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); |
| 161 }; | 193 }; |
| 162 | 194 |
| 163 } // namespace content | 195 } // namespace content |
| 164 | 196 |
| 165 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 197 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |