| 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 |
| 11 // from browser process. | 11 // from browser process. |
| 12 | 12 |
| 13 // The media::VideoCapture and VideoCaptureMessageFilter::Delegate are | 13 // The media::VideoCapture and VideoCaptureMessageFilter::Delegate are |
| 14 // asynchronous interfaces, which means callers can call those interfaces | 14 // asynchronous interfaces, which means callers can call those interfaces |
| 15 // from any threads without worrying about thread safety. | 15 // from any threads without worrying about thread safety. |
| 16 // The |capture_message_loop_proxy_| is the working thread of VideoCaptureImpl. | 16 // The |capture_message_loop_proxy_| is the working thread of VideoCaptureImpl. |
| 17 // All non-const members are accessed only on that working thread. | 17 // All non-const members are accessed only on that working thread. |
| 18 | 18 |
| 19 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 19 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 20 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 20 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 21 | 21 |
| 22 #include <list> | 22 #include <list> |
| 23 #include <map> | 23 #include <map> |
| 24 | 24 |
| 25 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
| 26 #include "content/common/media/video_capture.h" | 26 #include "content/common/media/video_capture.h" |
| 27 #include "content/renderer/media/video_capture_message_filter.h" | 27 #include "content/renderer/media/video_capture_message_filter.h" |
| 28 #include "media/video/capture/video_capture.h" | 28 #include "media/video/capture/video_capture.h" |
| 29 #include "media/video/capture/video_capture_types.h" | 29 #include "media/video/capture/video_capture_types.h" |
| 30 #include "media/video/encoded_video_source.h" |
| 30 | 31 |
| 31 namespace base { | 32 namespace base { |
| 32 class MessageLoopProxy; | 33 class MessageLoopProxy; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 | 37 |
| 37 class CONTENT_EXPORT VideoCaptureImpl | 38 class CONTENT_EXPORT VideoCaptureImpl |
| 38 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { | 39 : public media::VideoCapture, |
| 40 public VideoCaptureMessageFilter::Delegate, |
| 41 public media::EncodedVideoSource { |
| 39 public: | 42 public: |
| 40 // media::VideoCapture interface. | 43 // media::VideoCapture interface. |
| 41 virtual void StartCapture( | 44 virtual void StartCapture( |
| 42 media::VideoCapture::EventHandler* handler, | 45 media::VideoCapture::EventHandler* handler, |
| 43 const media::VideoCaptureCapability& capability) OVERRIDE; | 46 const media::VideoCaptureCapability& capability) OVERRIDE; |
| 44 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | 47 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; |
| 45 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; | 48 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; |
| 46 virtual bool CaptureStarted() OVERRIDE; | 49 virtual bool CaptureStarted() OVERRIDE; |
| 47 virtual int CaptureWidth() OVERRIDE; | 50 virtual int CaptureWidth() OVERRIDE; |
| 48 virtual int CaptureHeight() OVERRIDE; | 51 virtual int CaptureHeight() OVERRIDE; |
| 49 virtual int CaptureFrameRate() OVERRIDE; | 52 virtual int CaptureFrameRate() OVERRIDE; |
| 50 | 53 |
| 51 // VideoCaptureMessageFilter::Delegate interface. | 54 // VideoCaptureMessageFilter::Delegate interface. |
| 52 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 55 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| 53 int length, int buffer_id) OVERRIDE; | 56 int length, int buffer_id) OVERRIDE; |
| 54 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; | 57 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; |
| 55 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; | 58 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
| 56 virtual void OnDeviceInfoReceived( | 59 virtual void OnDeviceInfoReceived( |
| 57 const media::VideoCaptureParams& device_info) OVERRIDE; | 60 const media::VideoCaptureParams& device_info) OVERRIDE; |
| 58 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; | 61 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
| 62 virtual void OnCapabilitiesAvailable( |
| 63 const media::VideoEncodingCapabilities& capabilities) OVERRIDE; |
| 64 virtual void OnBitstreamOpened( |
| 65 const media::VideoEncodingParameters& params, |
| 66 const std::map<int, base::SharedMemoryHandle>& handles) OVERRIDE; |
| 67 virtual void OnBitstreamClosed() OVERRIDE; |
| 68 virtual void OnBitstreamConfigChanged( |
| 69 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
| 70 virtual void OnBitstreamReady( |
| 71 int buffer_id, |
| 72 int size, |
| 73 const media::BufferEncodingMetadata& metadata) OVERRIDE; |
| 74 |
| 75 // media::EncoderVideoSource interface. |
| 76 virtual void RequestCapabilities( |
| 77 const RequestCapabilitiesCallback& callback) OVERRIDE; |
| 78 virtual void OpenBitstream( |
| 79 media::EncodedVideoSource::Client* client, |
| 80 const media::VideoEncodingParameters& params) OVERRIDE; |
| 81 virtual void CloseBitstream() OVERRIDE; |
| 82 virtual void ReturnBitstreamBuffer( |
| 83 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) OVERRIDE; |
| 84 virtual void TrySetBitstreamConfig( |
| 85 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; |
| 59 | 86 |
| 60 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 87 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 61 virtual void SuspendCapture(bool suspend); | 88 virtual void SuspendCapture(bool suspend); |
| 62 | 89 |
| 63 private: | 90 private: |
| 64 friend class VideoCaptureImplManager; | 91 friend class VideoCaptureImplManager; |
| 65 friend class VideoCaptureImplTest; | 92 friend class VideoCaptureImplTest; |
| 66 friend class MockVideoCaptureImpl; | 93 friend class MockVideoCaptureImpl; |
| 67 | 94 |
| 68 struct DIBBuffer; | 95 struct DIBBuffer; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 83 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, | 110 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
| 84 int length, int buffer_id); | 111 int length, int buffer_id); |
| 85 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); | 112 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); |
| 86 void DoStateChangedOnCaptureThread(VideoCaptureState state); | 113 void DoStateChangedOnCaptureThread(VideoCaptureState state); |
| 87 void DoDeviceInfoReceivedOnCaptureThread( | 114 void DoDeviceInfoReceivedOnCaptureThread( |
| 88 const media::VideoCaptureParams& device_info); | 115 const media::VideoCaptureParams& device_info); |
| 89 void DoDelegateAddedOnCaptureThread(int32 device_id); | 116 void DoDelegateAddedOnCaptureThread(int32 device_id); |
| 90 | 117 |
| 91 void DoSuspendCaptureOnCaptureThread(bool suspend); | 118 void DoSuspendCaptureOnCaptureThread(bool suspend); |
| 92 | 119 |
| 120 void StartFetchCapabilities(); |
| 121 void DoStartFetchCapabilitiesOnCaptureThread(); |
| 122 void DoOpenBitstreamOnCaptureThread( |
| 123 const media::VideoEncodingParameters& params); |
| 124 void DoCloseBitstreamOnCaptureThread(); |
| 125 void DoReturnBitstreamBufferOnCaptureThread(int buffer_id); |
| 126 void DoTrySetBitstreamConfigOnCaptureThread( |
| 127 const media::RuntimeVideoEncodingParameters& params); |
| 128 void DoNotifyBitstreamOpenedOnCaptureThread( |
| 129 const media::VideoEncodingParameters& params, |
| 130 const std::map<int, base::SharedMemoryHandle>& buffers); |
| 131 void DoNotifyBitstreamClosedOnCaptureThread(); |
| 132 void DoNotifyBitstreamConfigChangedOnCaptureThread( |
| 133 const media::RuntimeVideoEncodingParameters& params); |
| 134 void DoNotifyBitstreamBufferReadyOnCaptureThread( |
| 135 int buffer_id, int size, |
| 136 const media::BufferEncodingMetadata& metadata); |
| 137 |
| 93 void Init(); | 138 void Init(); |
| 94 void DeInit(base::Closure task); | 139 void DeInit(base::Closure task); |
| 95 void DoDeInitOnCaptureThread(base::Closure task); | 140 void DoDeInitOnCaptureThread(base::Closure task); |
| 96 void StopDevice(); | 141 void StopDevice(); |
| 97 void RestartCapture(); | 142 void RestartCapture(); |
| 98 void StartCaptureInternal(); | 143 void StartCaptureInternal(); |
| 99 void AddDelegateOnIOThread(); | 144 void AddDelegateOnIOThread(); |
| 100 void RemoveDelegateOnIOThread(base::Closure task); | 145 void RemoveDelegateOnIOThread(base::Closure task); |
| 101 virtual void Send(IPC::Message* message); | 146 virtual void Send(IPC::Message* message); |
| 102 | 147 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 125 // starts with StartCapture and ends with StopCapture. | 170 // starts with StartCapture and ends with StopCapture. |
| 126 media::VideoCaptureParams current_params_; | 171 media::VideoCaptureParams current_params_; |
| 127 | 172 |
| 128 // The information about the device sent from browser process side. | 173 // The information about the device sent from browser process side. |
| 129 media::VideoCaptureParams device_info_; | 174 media::VideoCaptureParams device_info_; |
| 130 bool device_info_available_; | 175 bool device_info_available_; |
| 131 | 176 |
| 132 bool suspended_; | 177 bool suspended_; |
| 133 VideoCaptureState state_; | 178 VideoCaptureState state_; |
| 134 | 179 |
| 180 // Video encoding capabilities as reported by the device. |
| 181 media::VideoEncodingCapabilities capabilities_; |
| 182 // Callback for RequestCapabilities(). |
| 183 RequestCapabilitiesCallback callback_; |
| 184 // Pointer to the EVS client. |
| 185 media::EncodedVideoSource::Client* client_; |
| 186 // Bitstream buffers returned by the video capture device. |
| 187 std::map<int, base::SharedMemory*> buffers_; |
| 188 |
| 135 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 189 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 136 }; | 190 }; |
| 137 | 191 |
| 138 } // namespace content | 192 } // namespace content |
| 139 | 193 |
| 140 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 194 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |