| 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 // VideoCaptureImpl represents a capture device in renderer process. It provides | 5 // VideoCaptureImpl represents a capture device in renderer process. It provides |
| 6 // interfaces for clients to Start/Stop capture. It also communicates to clients | 6 // interfaces for clients to Start/Stop capture. It also communicates to clients |
| 7 // when buffer is ready, state of capture device is changed. | 7 // when buffer is ready, state of capture device is changed. |
| 8 | 8 |
| 9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which | 9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which |
| 10 // relays operation of capture device to browser process and receives response | 10 // relays operation of capture device to browser process and receives response |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 31 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 32 | 32 |
| 33 #include <list> | 33 #include <list> |
| 34 #include <map> | 34 #include <map> |
| 35 | 35 |
| 36 #include "content/common/content_export.h" | 36 #include "content/common/content_export.h" |
| 37 #include "content/common/media/video_capture.h" | 37 #include "content/common/media/video_capture.h" |
| 38 #include "content/renderer/media/video_capture_message_filter.h" | 38 #include "content/renderer/media/video_capture_message_filter.h" |
| 39 #include "media/video/capture/video_capture.h" | 39 #include "media/video/capture/video_capture.h" |
| 40 #include "media/video/capture/video_capture_types.h" | 40 #include "media/video/capture/video_capture_types.h" |
| 41 #include "media/video/encoded_video_source.h" | |
| 42 | 41 |
| 43 namespace base { | 42 namespace base { |
| 44 class MessageLoopProxy; | 43 class MessageLoopProxy; |
| 45 } | 44 } |
| 46 | 45 |
| 47 namespace content { | 46 namespace content { |
| 48 | 47 |
| 49 class CONTENT_EXPORT VideoCaptureImpl | 48 class CONTENT_EXPORT VideoCaptureImpl |
| 50 : public media::VideoCapture, | 49 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { |
| 51 public VideoCaptureMessageFilter::Delegate, | |
| 52 public media::EncodedVideoSource { | |
| 53 public: | 50 public: |
| 54 // media::VideoCapture interface. | 51 // media::VideoCapture interface. |
| 55 virtual void StartCapture( | 52 virtual void StartCapture( |
| 56 media::VideoCapture::EventHandler* handler, | 53 media::VideoCapture::EventHandler* handler, |
| 57 const media::VideoCaptureCapability& capability) OVERRIDE; | 54 const media::VideoCaptureCapability& capability) OVERRIDE; |
| 58 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | 55 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; |
| 59 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; | 56 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; |
| 60 virtual bool CaptureStarted() OVERRIDE; | 57 virtual bool CaptureStarted() OVERRIDE; |
| 61 virtual int CaptureWidth() OVERRIDE; | 58 virtual int CaptureWidth() OVERRIDE; |
| 62 virtual int CaptureHeight() OVERRIDE; | 59 virtual int CaptureHeight() OVERRIDE; |
| 63 virtual int CaptureFrameRate() OVERRIDE; | 60 virtual int CaptureFrameRate() OVERRIDE; |
| 64 | 61 |
| 65 // VideoCaptureMessageFilter::Delegate interface. | 62 // VideoCaptureMessageFilter::Delegate interface. |
| 66 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 63 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| 67 int length, int buffer_id) OVERRIDE; | 64 int length, int buffer_id) OVERRIDE; |
| 68 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; | 65 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; |
| 69 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; | 66 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
| 70 virtual void OnDeviceInfoReceived( | 67 virtual void OnDeviceInfoReceived( |
| 71 const media::VideoCaptureParams& device_info) OVERRIDE; | 68 const media::VideoCaptureParams& device_info) OVERRIDE; |
| 72 virtual void OnDeviceInfoChanged( | 69 virtual void OnDeviceInfoChanged( |
| 73 const media::VideoCaptureParams& device_info) OVERRIDE; | 70 const media::VideoCaptureParams& device_info) OVERRIDE; |
| 74 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; | 71 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
| 75 virtual void OnEncodingCapabilitiesAvailable( | |
| 76 const media::VideoEncodingCapabilities& capabilities) OVERRIDE; | |
| 77 virtual void OnEncodedBitstreamOpened( | |
| 78 const media::VideoEncodingParameters& params, | |
| 79 const std::vector<base::SharedMemoryHandle>& buffers, | |
| 80 uint32 buffer_size) OVERRIDE; | |
| 81 virtual void OnEncodedBitstreamClosed() OVERRIDE; | |
| 82 virtual void OnEncodingConfigChanged( | |
| 83 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; | |
| 84 virtual void OnEncodedBufferReady( | |
| 85 int buffer_id, | |
| 86 uint32 size, | |
| 87 const media::BufferEncodingMetadata& metadata) OVERRIDE; | |
| 88 | |
| 89 // media::EncodedVideoSource interface. | |
| 90 virtual void RequestCapabilities( | |
| 91 const RequestCapabilitiesCallback& callback) OVERRIDE; | |
| 92 virtual void OpenBitstream( | |
| 93 media::EncodedVideoSource::Client* client, | |
| 94 const media::VideoEncodingParameters& params) OVERRIDE; | |
| 95 virtual void CloseBitstream() OVERRIDE; | |
| 96 virtual void ReturnBitstreamBuffer( | |
| 97 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) OVERRIDE; | |
| 98 virtual void TrySetBitstreamConfig( | |
| 99 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; | |
| 100 virtual void RequestKeyFrame() OVERRIDE; | |
| 101 | 72 |
| 102 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 73 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 103 virtual void SuspendCapture(bool suspend); | 74 virtual void SuspendCapture(bool suspend); |
| 104 | 75 |
| 105 private: | 76 private: |
| 106 friend class VideoCaptureImplManager; | 77 friend class VideoCaptureImplManager; |
| 107 friend class VideoCaptureImplTest; | 78 friend class VideoCaptureImplTest; |
| 108 friend class MockVideoCaptureImpl; | 79 friend class MockVideoCaptureImpl; |
| 109 | 80 |
| 110 struct DIBBuffer; | 81 struct DIBBuffer; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 127 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); | 98 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); |
| 128 void DoStateChangedOnCaptureThread(VideoCaptureState state); | 99 void DoStateChangedOnCaptureThread(VideoCaptureState state); |
| 129 void DoDeviceInfoReceivedOnCaptureThread( | 100 void DoDeviceInfoReceivedOnCaptureThread( |
| 130 const media::VideoCaptureParams& device_info); | 101 const media::VideoCaptureParams& device_info); |
| 131 void DoDeviceInfoChangedOnCaptureThread( | 102 void DoDeviceInfoChangedOnCaptureThread( |
| 132 const media::VideoCaptureParams& device_info); | 103 const media::VideoCaptureParams& device_info); |
| 133 void DoDelegateAddedOnCaptureThread(int32 device_id); | 104 void DoDelegateAddedOnCaptureThread(int32 device_id); |
| 134 | 105 |
| 135 void DoSuspendCaptureOnCaptureThread(bool suspend); | 106 void DoSuspendCaptureOnCaptureThread(bool suspend); |
| 136 | 107 |
| 137 void StartFetchCapabilities(); | |
| 138 void DoRequestCapabilitiesOnCaptureThread( | |
| 139 const RequestCapabilitiesCallback& callback); | |
| 140 void DoOpenBitstreamOnCaptureThread( | |
| 141 media::EncodedVideoSource::Client* client, | |
| 142 const media::VideoEncodingParameters& params); | |
| 143 void DoCloseBitstreamOnCaptureThread(); | |
| 144 void DoNotifyBitstreamOpenedOnCaptureThread( | |
| 145 const media::VideoEncodingParameters& params, | |
| 146 const std::vector<base::SharedMemoryHandle>& buffers, | |
| 147 uint32 buffer_size); | |
| 148 void DoNotifyBitstreamClosedOnCaptureThread(); | |
| 149 void DoNotifyBitstreamConfigChangedOnCaptureThread( | |
| 150 const media::RuntimeVideoEncodingParameters& params); | |
| 151 void DoNotifyBitstreamBufferReadyOnCaptureThread( | |
| 152 int buffer_id, uint32 size, | |
| 153 const media::BufferEncodingMetadata& metadata); | |
| 154 void DoNotifyCapabilitiesAvailableOnCaptureThread( | |
| 155 const media::VideoEncodingCapabilities& capabilities); | |
| 156 | |
| 157 void Init(); | 108 void Init(); |
| 158 void DeInit(base::Closure task); | 109 void DeInit(base::Closure task); |
| 159 void DoDeInitOnCaptureThread(base::Closure task); | 110 void DoDeInitOnCaptureThread(base::Closure task); |
| 160 void StopDevice(); | 111 void StopDevice(); |
| 161 void RestartCapture(); | 112 void RestartCapture(); |
| 162 void StartCaptureInternal(); | 113 void StartCaptureInternal(); |
| 163 void AddDelegateOnIOThread(); | 114 void AddDelegateOnIOThread(); |
| 164 void RemoveDelegateOnIOThread(base::Closure task); | 115 void RemoveDelegateOnIOThread(base::Closure task); |
| 165 virtual void Send(IPC::Message* message); | 116 virtual void Send(IPC::Message* message); |
| 166 | 117 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 // to this class via DoStartCaptureOnCaptureThread. | 140 // to this class via DoStartCaptureOnCaptureThread. |
| 190 media::VideoCaptureCapability capture_format_; | 141 media::VideoCaptureCapability capture_format_; |
| 191 | 142 |
| 192 // The device's video capture format sent from browser process side. | 143 // The device's video capture format sent from browser process side. |
| 193 media::VideoCaptureParams device_info_; | 144 media::VideoCaptureParams device_info_; |
| 194 bool device_info_available_; | 145 bool device_info_available_; |
| 195 | 146 |
| 196 bool suspended_; | 147 bool suspended_; |
| 197 VideoCaptureState state_; | 148 VideoCaptureState state_; |
| 198 | 149 |
| 199 // Video encoding capabilities as reported by the device. | |
| 200 media::VideoEncodingCapabilities encoding_caps_; | |
| 201 // Callback for RequestCapabilities(). | |
| 202 RequestCapabilitiesCallback encoding_caps_callback_; | |
| 203 // Pointer to the EVS client. | |
| 204 media::EncodedVideoSource::Client* encoded_video_source_client_; | |
| 205 // Bitstream buffers returned by the video capture device. Unowned. | |
| 206 std::vector<base::SharedMemory*> bitstream_buffers_; | |
| 207 // |bitstream_open_| is set to true when renderer receives BitstreamOpened | |
| 208 // message acknowledging an OpenBitstream request, and is set to false when | |
| 209 // the EVS client requests to close bitstream, or when renderer receives | |
| 210 // BitstreamClosed message from the browser procses. | |
| 211 bool bitstream_open_; | |
| 212 | |
| 213 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 150 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 214 }; | 151 }; |
| 215 | 152 |
| 216 } // namespace content | 153 } // namespace content |
| 217 | 154 |
| 218 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 155 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |