| 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" |
| 41 | 42 |
| 42 namespace base { | 43 namespace base { |
| 43 class MessageLoopProxy; | 44 class MessageLoopProxy; |
| 44 } | 45 } |
| 45 | 46 |
| 46 namespace content { | 47 namespace content { |
| 47 | 48 |
| 48 class CONTENT_EXPORT VideoCaptureImpl | 49 class CONTENT_EXPORT VideoCaptureImpl |
| 49 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { | 50 : public media::VideoCapture, |
| 51 public VideoCaptureMessageFilter::Delegate, |
| 52 public media::EncodedVideoSource { |
| 50 public: | 53 public: |
| 51 // media::VideoCapture interface. | 54 // media::VideoCapture interface. |
| 52 virtual void StartCapture( | 55 virtual void StartCapture( |
| 53 media::VideoCapture::EventHandler* handler, | 56 media::VideoCapture::EventHandler* handler, |
| 54 const media::VideoCaptureCapability& capability) OVERRIDE; | 57 const media::VideoCaptureCapability& capability) OVERRIDE; |
| 55 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | 58 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; |
| 56 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; | 59 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; |
| 57 virtual bool CaptureStarted() OVERRIDE; | 60 virtual bool CaptureStarted() OVERRIDE; |
| 58 virtual int CaptureWidth() OVERRIDE; | 61 virtual int CaptureWidth() OVERRIDE; |
| 59 virtual int CaptureHeight() OVERRIDE; | 62 virtual int CaptureHeight() OVERRIDE; |
| 60 virtual int CaptureFrameRate() OVERRIDE; | 63 virtual int CaptureFrameRate() OVERRIDE; |
| 61 | 64 |
| 62 // VideoCaptureMessageFilter::Delegate interface. | 65 // VideoCaptureMessageFilter::Delegate interface. |
| 63 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 66 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| 64 int length, int buffer_id) OVERRIDE; | 67 int length, int buffer_id) OVERRIDE; |
| 65 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; | 68 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; |
| 66 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; | 69 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
| 67 virtual void OnDeviceInfoReceived( | 70 virtual void OnDeviceInfoReceived( |
| 68 const media::VideoCaptureParams& device_info) OVERRIDE; | 71 const media::VideoCaptureParams& device_info) OVERRIDE; |
| 69 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; | 72 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
| 73 virtual void OnEncodingCapabilitiesAvailable( |
| 74 const media::VideoEncodingCapabilities& capabilities) OVERRIDE; |
| 75 virtual void OnEncodedBitstreamOpened( |
| 76 const media::VideoEncodingParameters& params, |
| 77 const std::vector<base::SharedMemoryHandle>& buffers, |
| 78 uint32 buffer_size) OVERRIDE; |
| 79 virtual void OnEncodedBitstreamClosed() OVERRIDE; |
| 80 virtual void OnEncodingConfigChanged( |
| 81 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
| 82 virtual void OnEncodedBufferReady( |
| 83 int buffer_id, |
| 84 uint32 size, |
| 85 const media::BufferEncodingMetadata& metadata) OVERRIDE; |
| 86 |
| 87 // media::EncodedVideoSource interface. |
| 88 virtual void RequestCapabilities( |
| 89 const RequestCapabilitiesCallback& callback) OVERRIDE; |
| 90 virtual void OpenBitstream( |
| 91 media::EncodedVideoSource::Client* client, |
| 92 const media::VideoEncodingParameters& params) OVERRIDE; |
| 93 virtual void CloseBitstream() OVERRIDE; |
| 94 virtual void ReturnBitstreamBuffer( |
| 95 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) OVERRIDE; |
| 96 virtual void TrySetBitstreamConfig( |
| 97 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
| 70 | 98 |
| 71 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 99 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 72 virtual void SuspendCapture(bool suspend); | 100 virtual void SuspendCapture(bool suspend); |
| 73 | 101 |
| 74 private: | 102 private: |
| 75 friend class VideoCaptureImplManager; | 103 friend class VideoCaptureImplManager; |
| 76 friend class VideoCaptureImplTest; | 104 friend class VideoCaptureImplTest; |
| 77 friend class MockVideoCaptureImpl; | 105 friend class MockVideoCaptureImpl; |
| 78 | 106 |
| 79 struct DIBBuffer; | 107 struct DIBBuffer; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 94 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, | 122 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
| 95 int length, int buffer_id); | 123 int length, int buffer_id); |
| 96 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); | 124 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); |
| 97 void DoStateChangedOnCaptureThread(VideoCaptureState state); | 125 void DoStateChangedOnCaptureThread(VideoCaptureState state); |
| 98 void DoDeviceInfoReceivedOnCaptureThread( | 126 void DoDeviceInfoReceivedOnCaptureThread( |
| 99 const media::VideoCaptureParams& device_info); | 127 const media::VideoCaptureParams& device_info); |
| 100 void DoDelegateAddedOnCaptureThread(int32 device_id); | 128 void DoDelegateAddedOnCaptureThread(int32 device_id); |
| 101 | 129 |
| 102 void DoSuspendCaptureOnCaptureThread(bool suspend); | 130 void DoSuspendCaptureOnCaptureThread(bool suspend); |
| 103 | 131 |
| 132 void StartFetchCapabilities(); |
| 133 void DoRequestCapabilitiesOnCaptureThread( |
| 134 const RequestCapabilitiesCallback& callback); |
| 135 void DoOpenBitstreamOnCaptureThread( |
| 136 media::EncodedVideoSource::Client* client, |
| 137 const media::VideoEncodingParameters& params); |
| 138 void DoCloseBitstreamOnCaptureThread(); |
| 139 void DoNotifyBitstreamOpenedOnCaptureThread( |
| 140 const media::VideoEncodingParameters& params, |
| 141 const std::vector<base::SharedMemoryHandle>& buffers, |
| 142 uint32 buffer_size); |
| 143 void DoNotifyBitstreamClosedOnCaptureThread(); |
| 144 void DoNotifyBitstreamConfigChangedOnCaptureThread( |
| 145 const media::RuntimeVideoEncodingParameters& params); |
| 146 void DoNotifyBitstreamBufferReadyOnCaptureThread( |
| 147 int buffer_id, uint32 size, |
| 148 const media::BufferEncodingMetadata& metadata); |
| 149 void DoNotifyCapabilitiesAvailableOnCaptureThread( |
| 150 const media::VideoEncodingCapabilities& capabilities); |
| 151 |
| 104 void Init(); | 152 void Init(); |
| 105 void DeInit(base::Closure task); | 153 void DeInit(base::Closure task); |
| 106 void DoDeInitOnCaptureThread(base::Closure task); | 154 void DoDeInitOnCaptureThread(base::Closure task); |
| 107 void StopDevice(); | 155 void StopDevice(); |
| 108 void RestartCapture(); | 156 void RestartCapture(); |
| 109 void StartCaptureInternal(); | 157 void StartCaptureInternal(); |
| 110 void AddDelegateOnIOThread(); | 158 void AddDelegateOnIOThread(); |
| 111 void RemoveDelegateOnIOThread(base::Closure task); | 159 void RemoveDelegateOnIOThread(base::Closure task); |
| 112 virtual void Send(IPC::Message* message); | 160 virtual void Send(IPC::Message* message); |
| 113 | 161 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 136 // starts with StartCapture and ends with StopCapture. | 184 // starts with StartCapture and ends with StopCapture. |
| 137 media::VideoCaptureParams current_params_; | 185 media::VideoCaptureParams current_params_; |
| 138 | 186 |
| 139 // The information about the device sent from browser process side. | 187 // The information about the device sent from browser process side. |
| 140 media::VideoCaptureParams device_info_; | 188 media::VideoCaptureParams device_info_; |
| 141 bool device_info_available_; | 189 bool device_info_available_; |
| 142 | 190 |
| 143 bool suspended_; | 191 bool suspended_; |
| 144 VideoCaptureState state_; | 192 VideoCaptureState state_; |
| 145 | 193 |
| 194 // Video encoding capabilities as reported by the device. |
| 195 media::VideoEncodingCapabilities encoding_caps_; |
| 196 // Callback for RequestCapabilities(). |
| 197 RequestCapabilitiesCallback encoding_caps_callback_; |
| 198 // Pointer to the EVS client. |
| 199 media::EncodedVideoSource::Client* encoded_video_source_client_; |
| 200 // Bitstream buffers returned by the video capture device. Unowned. |
| 201 std::vector<base::SharedMemory*> bitstream_buffers_; |
| 202 // |bitstream_open_| is set to true when renderer receives BitstreamOpened |
| 203 // message acknowledging an OpenBitstream request, and is set to false when |
| 204 // the EVS client requests to close bitstream, or when renderer receives |
| 205 // BitstreamClosed message from the browser procses. |
| 206 bool bitstream_open_; |
| 207 |
| 146 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 208 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 147 }; | 209 }; |
| 148 | 210 |
| 149 } // namespace content | 211 } // namespace content |
| 150 | 212 |
| 151 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 213 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |