Chromium Code Reviews| 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 OnEncodingCapabilitiesAvailable( | |
| 63 const media::VideoEncodingCapabilities& capabilities) OVERRIDE; | |
| 64 virtual void OnEncodedBitstreamOpened( | |
| 65 const media::VideoEncodingParameters& params, | |
| 66 const std::vector<base::SharedMemoryHandle>& buffers, | |
| 67 uint32 buffer_size) OVERRIDE; | |
| 68 virtual void OnEncodedBitstreamClosed() OVERRIDE; | |
| 69 virtual void OnEncodingConfigChanged( | |
| 70 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; | |
| 71 virtual void OnEncodedBufferReady( | |
| 72 int buffer_id, | |
| 73 uint32 size, | |
| 74 const media::BufferEncodingMetadata& metadata) OVERRIDE; | |
| 75 | |
| 76 // media::EncodedVideoSource interface. | |
| 77 virtual void RequestCapabilities( | |
| 78 const RequestCapabilitiesCallback& callback) OVERRIDE; | |
| 79 virtual void OpenBitstream( | |
| 80 media::EncodedVideoSource::Client* client, | |
| 81 const media::VideoEncodingParameters& params) OVERRIDE; | |
| 82 virtual void CloseBitstream() OVERRIDE; | |
| 83 virtual void ReturnBitstreamBuffer( | |
| 84 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) OVERRIDE; | |
| 85 virtual void TrySetBitstreamConfig( | |
| 86 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; | |
| 59 | 87 |
| 60 // Stop/resume delivering video frames to clients, based on flag |suspend|. | 88 // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| 61 virtual void SuspendCapture(bool suspend); | 89 virtual void SuspendCapture(bool suspend); |
| 62 | 90 |
| 63 private: | 91 private: |
| 64 friend class VideoCaptureImplManager; | 92 friend class VideoCaptureImplManager; |
| 65 friend class VideoCaptureImplTest; | 93 friend class VideoCaptureImplTest; |
| 66 friend class MockVideoCaptureImpl; | 94 friend class MockVideoCaptureImpl; |
| 67 | 95 |
| 68 struct DIBBuffer; | 96 struct DIBBuffer; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 83 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, | 111 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
| 84 int length, int buffer_id); | 112 int length, int buffer_id); |
| 85 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); | 113 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); |
| 86 void DoStateChangedOnCaptureThread(VideoCaptureState state); | 114 void DoStateChangedOnCaptureThread(VideoCaptureState state); |
| 87 void DoDeviceInfoReceivedOnCaptureThread( | 115 void DoDeviceInfoReceivedOnCaptureThread( |
| 88 const media::VideoCaptureParams& device_info); | 116 const media::VideoCaptureParams& device_info); |
| 89 void DoDelegateAddedOnCaptureThread(int32 device_id); | 117 void DoDelegateAddedOnCaptureThread(int32 device_id); |
| 90 | 118 |
| 91 void DoSuspendCaptureOnCaptureThread(bool suspend); | 119 void DoSuspendCaptureOnCaptureThread(bool suspend); |
| 92 | 120 |
| 121 void StartFetchCapabilities(); | |
| 122 void DoRequestCapabilitiesOnCaptureThread( | |
| 123 const RequestCapabilitiesCallback& callback); | |
| 124 void DoOpenBitstreamOnCaptureThread( | |
| 125 media::EncodedVideoSource::Client* client, | |
| 126 const media::VideoEncodingParameters& params); | |
| 127 void DoCloseBitstreamOnCaptureThread(); | |
| 128 void DoNotifyBitstreamOpenedOnCaptureThread( | |
| 129 const media::VideoEncodingParameters& params, | |
| 130 const std::vector<base::SharedMemoryHandle>& buffers, | |
| 131 uint32 buffer_size); | |
| 132 void DoNotifyBitstreamClosedOnCaptureThread(); | |
| 133 void DoNotifyBitstreamConfigChangedOnCaptureThread( | |
| 134 const media::RuntimeVideoEncodingParameters& params); | |
| 135 void DoNotifyBitstreamBufferReadyOnCaptureThread( | |
| 136 int buffer_id, uint32 size, | |
| 137 const media::BufferEncodingMetadata& metadata); | |
| 138 void DoNotifyCapabilitiesAvailableOnCaptureThread( | |
| 139 const media::VideoEncodingCapabilities& capabilities); | |
| 140 | |
| 93 void Init(); | 141 void Init(); |
| 94 void DeInit(base::Closure task); | 142 void DeInit(base::Closure task); |
| 95 void DoDeInitOnCaptureThread(base::Closure task); | 143 void DoDeInitOnCaptureThread(base::Closure task); |
| 96 void StopDevice(); | 144 void StopDevice(); |
| 97 void RestartCapture(); | 145 void RestartCapture(); |
| 98 void StartCaptureInternal(); | 146 void StartCaptureInternal(); |
| 99 void AddDelegateOnIOThread(); | 147 void AddDelegateOnIOThread(); |
| 100 void RemoveDelegateOnIOThread(base::Closure task); | 148 void RemoveDelegateOnIOThread(base::Closure task); |
| 101 virtual void Send(IPC::Message* message); | 149 virtual void Send(IPC::Message* message); |
| 102 | 150 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 125 // starts with StartCapture and ends with StopCapture. | 173 // starts with StartCapture and ends with StopCapture. |
| 126 media::VideoCaptureParams current_params_; | 174 media::VideoCaptureParams current_params_; |
| 127 | 175 |
| 128 // The information about the device sent from browser process side. | 176 // The information about the device sent from browser process side. |
| 129 media::VideoCaptureParams device_info_; | 177 media::VideoCaptureParams device_info_; |
| 130 bool device_info_available_; | 178 bool device_info_available_; |
| 131 | 179 |
| 132 bool suspended_; | 180 bool suspended_; |
| 133 VideoCaptureState state_; | 181 VideoCaptureState state_; |
| 134 | 182 |
| 183 // Video encoding capabilities as reported by the device. | |
| 184 media::VideoEncodingCapabilities encoding_caps_; | |
| 185 // Callback for RequestCapabilities(). | |
| 186 RequestCapabilitiesCallback encoding_caps_callback_; | |
| 187 // Pointer to the EVS client. | |
| 188 media::EncodedVideoSource::Client* encoded_video_source_client_; | |
| 189 // Bitstream buffers returned by the video capture device. Unowned. | |
| 190 std::vector<base::SharedMemory*> bitstream_buffers_; | |
| 191 // |bitstream_opened_| is set to true when renderer receives BitstreamOpened | |
| 192 // message acknowledging an OpenBitstream request, and is set to false when | |
| 193 // the EVS client requests to close bitstream, or when renderer receives | |
| 194 // BitstreamClosed message from the browser procses. | |
| 195 bool bitstream_opened_; | |
|
Ami GONE FROM CHROMIUM
2013/06/18 20:56:27
s/ed// since this is temporal (once closed, it is
hshi1
2013/06/18 23:01:19
Done.
| |
| 196 | |
| 135 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 197 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 136 }; | 198 }; |
| 137 | 199 |
| 138 } // namespace content | 200 } // namespace content |
| 139 | 201 |
| 140 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 202 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |