| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // VideoCaptureMessageFilter::Delegate interface. | 36 // VideoCaptureMessageFilter::Delegate interface. |
| 37 virtual void OnBufferCreated(base::SharedMemoryHandle handle, | 37 virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| 38 int length, int buffer_id); | 38 int length, int buffer_id); |
| 39 virtual void OnBufferReceived(int buffer_id, base::Time timestamp); | 39 virtual void OnBufferReceived(int buffer_id, base::Time timestamp); |
| 40 virtual void OnStateChanged(const media::VideoCapture::State& state); | 40 virtual void OnStateChanged(const media::VideoCapture::State& state); |
| 41 virtual void OnDeviceInfoReceived( | 41 virtual void OnDeviceInfoReceived( |
| 42 const media::VideoCaptureParams& device_info); | 42 const media::VideoCaptureParams& device_info); |
| 43 virtual void OnDelegateAdded(int32 device_id); | 43 virtual void OnDelegateAdded(int32 device_id); |
| 44 | 44 |
| 45 bool pending_start() { | |
| 46 return (new_params_.width > 0 && new_params_.height > 0); | |
| 47 } | |
| 48 | |
| 49 private: | 45 private: |
| 50 friend class VideoCaptureImplManager; | 46 friend class VideoCaptureImplManager; |
| 51 friend class VideoCaptureImplTest; | 47 friend class VideoCaptureImplTest; |
| 52 friend class MockVideoCaptureImpl; | 48 friend class MockVideoCaptureImpl; |
| 53 | 49 |
| 54 struct DIBBuffer { | 50 struct DIBBuffer; |
| 55 public: | |
| 56 DIBBuffer(base::SharedMemory* d, | |
| 57 media::VideoCapture::VideoFrameBuffer* ptr); | |
| 58 ~DIBBuffer(); | |
| 59 | |
| 60 base::SharedMemory* dib; | |
| 61 scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory; | |
| 62 }; | |
| 63 | 51 |
| 64 VideoCaptureImpl(media::VideoCaptureSessionId id, | 52 VideoCaptureImpl(media::VideoCaptureSessionId id, |
| 65 scoped_refptr<base::MessageLoopProxy> ml_proxy, | 53 scoped_refptr<base::MessageLoopProxy> ml_proxy, |
| 66 VideoCaptureMessageFilter* filter); | 54 VideoCaptureMessageFilter* filter); |
| 67 virtual ~VideoCaptureImpl(); | 55 virtual ~VideoCaptureImpl(); |
| 68 | 56 |
| 69 void DoStartCapture(media::VideoCapture::EventHandler* handler, | 57 void DoStartCapture(media::VideoCapture::EventHandler* handler, |
| 70 const VideoCaptureCapability& capability); | 58 const VideoCaptureCapability& capability); |
| 71 void DoStopCapture(media::VideoCapture::EventHandler* handler); | 59 void DoStopCapture(media::VideoCapture::EventHandler* handler); |
| 72 void DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer); | 60 void DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer); |
| 73 | 61 |
| 74 void DoBufferCreated(base::SharedMemoryHandle handle, | 62 void DoBufferCreated(base::SharedMemoryHandle handle, |
| 75 int length, int buffer_id); | 63 int length, int buffer_id); |
| 76 void DoBufferReceived(int buffer_id, base::Time timestamp); | 64 void DoBufferReceived(int buffer_id, base::Time timestamp); |
| 77 void DoStateChanged(const media::VideoCapture::State& state); | 65 void DoStateChanged(const media::VideoCapture::State& state); |
| 78 void DoDeviceInfoReceived(const media::VideoCaptureParams& device_info); | 66 void DoDeviceInfoReceived(const media::VideoCaptureParams& device_info); |
| 79 void DoDelegateAdded(int32 device_id); | 67 void DoDelegateAdded(int32 device_id); |
| 80 | 68 |
| 81 void Init(); | 69 void Init(); |
| 82 void DeInit(base::Closure task); | 70 void DeInit(base::Closure task); |
| 83 void StopDevice(); | 71 void StopDevice(); |
| 84 void RestartCapture(); | 72 void RestartCapture(); |
| 85 void StartCaptureInternal(); | 73 void StartCaptureInternal(); |
| 86 void AddDelegateOnIOThread(); | 74 void AddDelegateOnIOThread(); |
| 87 void RemoveDelegateOnIOThread(base::Closure task); | 75 void RemoveDelegateOnIOThread(base::Closure task); |
| 88 virtual void Send(IPC::Message* message); | 76 virtual void Send(IPC::Message* message); |
| 89 | 77 |
| 90 // Helpers. | 78 // Helpers. |
| 91 bool CapabilityMatchesParameters(const VideoCaptureCapability& capability, | 79 bool ClientHasDIB(); |
| 92 const media::VideoCaptureParams& params); | 80 void GetMaxWidthHeight(int& width, int& height); |
| 93 | 81 |
| 94 scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 82 scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
| 95 scoped_refptr<base::MessageLoopProxy> ml_proxy_; | 83 scoped_refptr<base::MessageLoopProxy> ml_proxy_; |
| 96 int device_id_; | 84 int device_id_; |
| 97 | 85 |
| 98 // Pool of DIBs. | 86 // Pool of DIBs. |
| 99 typedef std::map<int, DIBBuffer*> CachedDIB; | 87 typedef std::map<int, DIBBuffer*> CachedDIB; |
| 100 CachedDIB cached_dibs_; | 88 CachedDIB cached_dibs_; |
| 101 | 89 |
| 102 // DIBs at client side. The mapped value |int| means number of clients which | 90 // DIBs at client side. The mapped value |int| means number of clients which |
| 103 // hold this dib. | 91 // hold this dib. |
| 104 typedef std::map<media::VideoCapture::VideoFrameBuffer*, int> ClientSideDIB; | 92 typedef std::map<media::VideoCapture::VideoFrameBuffer*, int> ClientSideDIB; |
| 105 ClientSideDIB client_side_dibs_; | 93 ClientSideDIB client_side_dibs_; |
| 106 | 94 |
| 107 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> | 95 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> |
| 108 ClientInfo; | 96 ClientInfo; |
| 109 ClientInfo clients_; | 97 ClientInfo clients_; |
| 110 std::list<media::VideoCapture::EventHandler*> master_clients_; | |
| 111 | 98 |
| 112 ClientInfo pending_clients_; | 99 ClientInfo pending_clients_; |
| 113 | 100 |
| 114 media::VideoFrame::Format video_type_; | 101 media::VideoFrame::Format video_type_; |
| 115 | 102 |
| 116 // The parameter is being used in current capture session. A capture session | 103 // The parameter is being used in current capture session. A capture session |
| 117 // starts with StartCapture and ends with StopCapture. | 104 // starts with StartCapture and ends with StopCapture. |
| 118 media::VideoCaptureParams current_params_; | 105 media::VideoCaptureParams current_params_; |
| 119 | 106 |
| 120 // The information about the device sent from browser process side. | 107 // The information about the device sent from browser process side. |
| 121 media::VideoCaptureParams device_info_; | 108 media::VideoCaptureParams device_info_; |
| 122 bool device_info_available_; | 109 bool device_info_available_; |
| 123 | 110 |
| 124 // The parameter will be used in next capture session. | |
| 125 media::VideoCaptureParams new_params_; | |
| 126 State state_; | 111 State state_; |
| 127 | 112 |
| 128 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 113 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 129 }; | 114 }; |
| 130 | 115 |
| 131 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); | 116 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); |
| 132 | 117 |
| 133 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 118 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| OLD | NEW |