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 |
| 10 // relays operation of capture device to browser process and receives response |
| 11 // from browser process. |
| 12 |
9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 13 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 14 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
11 | 15 |
12 #include <list> | 16 #include <list> |
13 #include <map> | 17 #include <map> |
14 | 18 |
15 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
16 #include "content/common/media/video_capture.h" | 20 #include "content/common/media/video_capture.h" |
17 #include "content/renderer/media/video_capture_message_filter.h" | 21 #include "content/renderer/media/video_capture_message_filter.h" |
18 #include "media/video/capture/video_capture.h" | 22 #include "media/video/capture/video_capture.h" |
(...skipping 25 matching lines...) Expand all Loading... |
44 virtual void OnDeviceInfoReceived( | 48 virtual void OnDeviceInfoReceived( |
45 const media::VideoCaptureParams& device_info) OVERRIDE; | 49 const media::VideoCaptureParams& device_info) OVERRIDE; |
46 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; | 50 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
47 | 51 |
48 private: | 52 private: |
49 friend class VideoCaptureImplManager; | 53 friend class VideoCaptureImplManager; |
50 friend class VideoCaptureImplTest; | 54 friend class VideoCaptureImplTest; |
51 friend class MockVideoCaptureImpl; | 55 friend class MockVideoCaptureImpl; |
52 | 56 |
53 struct DIBBuffer; | 57 struct DIBBuffer; |
| 58 typedef std::map<media::VideoCapture::EventHandler*, |
| 59 media::VideoCaptureCapability> ClientInfo; |
54 | 60 |
55 VideoCaptureImpl(media::VideoCaptureSessionId id, | 61 VideoCaptureImpl(media::VideoCaptureSessionId id, |
56 base::MessageLoopProxy* capture_message_loop_proxy, | 62 base::MessageLoopProxy* capture_message_loop_proxy, |
57 VideoCaptureMessageFilter* filter); | 63 VideoCaptureMessageFilter* filter); |
58 virtual ~VideoCaptureImpl(); | 64 virtual ~VideoCaptureImpl(); |
59 | 65 |
60 void DoStartCapture(media::VideoCapture::EventHandler* handler, | 66 void DoStartCaptureOnCaptureThread( |
61 const media::VideoCaptureCapability& capability); | 67 media::VideoCapture::EventHandler* handler, |
62 void DoStopCapture(media::VideoCapture::EventHandler* handler); | 68 const media::VideoCaptureCapability& capability); |
63 void DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer); | 69 void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler); |
| 70 void DoFeedBufferOnCaptureThread(scoped_refptr<VideoFrameBuffer> buffer); |
64 | 71 |
65 void DoBufferCreated(base::SharedMemoryHandle handle, | 72 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
66 int length, int buffer_id); | 73 int length, int buffer_id); |
67 void DoBufferReceived(int buffer_id, base::Time timestamp); | 74 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); |
68 void DoStateChanged(video_capture::State state); | 75 void DoStateChangedOnCaptureThread(video_capture::State state); |
69 void DoDeviceInfoReceived(const media::VideoCaptureParams& device_info); | 76 void DoDeviceInfoReceivedOnCaptureThread( |
70 void DoDelegateAdded(int32 device_id); | 77 const media::VideoCaptureParams& device_info); |
| 78 void DoDelegateAddedOnCaptureThread(int32 device_id); |
71 | 79 |
72 void Init(); | 80 void Init(); |
73 void DeInit(base::Closure task); | 81 void DeInit(base::Closure task); |
74 void DoDeInit(base::Closure task); | 82 void DoDeInitOnCaptureThread(base::Closure task); |
75 void StopDevice(); | 83 void StopDevice(); |
76 void RestartCapture(); | 84 void RestartCapture(); |
77 void StartCaptureInternal(); | 85 void StartCaptureInternal(); |
78 void AddDelegateOnIOThread(); | 86 void AddDelegateOnIOThread(); |
79 void RemoveDelegateOnIOThread(base::Closure task); | 87 void RemoveDelegateOnIOThread(base::Closure task); |
80 virtual void Send(IPC::Message* message); | 88 virtual void Send(IPC::Message* message); |
81 | 89 |
82 // Helpers. | 90 // Helpers. |
83 bool ClientHasDIB(); | 91 bool ClientHasDIB(); |
| 92 bool RemoveClient(media::VideoCapture::EventHandler* handler, |
| 93 ClientInfo& clients); |
84 | 94 |
85 scoped_refptr<VideoCaptureMessageFilter> message_filter_; | 95 scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
86 scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; | 96 scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; |
87 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 97 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
88 int device_id_; | 98 int device_id_; |
89 | 99 |
90 // Pool of DIBs. | 100 // Pool of DIBs. The key is buffer_id. |
91 typedef std::map<int /* buffer_id */, DIBBuffer*> CachedDIB; | 101 typedef std::map<int, DIBBuffer*> CachedDIB; |
92 CachedDIB cached_dibs_; | 102 CachedDIB cached_dibs_; |
93 | 103 |
94 typedef std::map<media::VideoCapture::EventHandler*, | |
95 media::VideoCaptureCapability> ClientInfo; | |
96 ClientInfo clients_; | 104 ClientInfo clients_; |
97 | 105 |
98 ClientInfo clients_pending_on_filter_; | 106 ClientInfo clients_pending_on_filter_; |
99 ClientInfo clients_pending_on_restart_; | 107 ClientInfo clients_pending_on_restart_; |
100 | 108 |
101 media::VideoCaptureCapability::Format video_type_; | 109 media::VideoCaptureCapability::Format video_type_; |
102 | 110 |
103 // The parameter is being used in current capture session. A capture session | 111 // The parameter is being used in current capture session. A capture session |
104 // starts with StartCapture and ends with StopCapture. | 112 // starts with StartCapture and ends with StopCapture. |
105 media::VideoCaptureParams current_params_; | 113 media::VideoCaptureParams current_params_; |
106 | 114 |
107 // The information about the device sent from browser process side. | 115 // The information about the device sent from browser process side. |
108 media::VideoCaptureParams device_info_; | 116 media::VideoCaptureParams device_info_; |
109 bool device_info_available_; | 117 bool device_info_available_; |
110 | 118 |
111 video_capture::State state_; | 119 video_capture::State state_; |
112 | 120 |
113 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | 121 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
114 }; | 122 }; |
115 | 123 |
116 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | 124 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |