OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/renderer/media/media_stream_video_capturer_source.h" | 5 #include "content/renderer/media/media_stream_video_capturer_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "content/renderer/media/video_capture_impl_manager.h" | 9 #include "content/renderer/media/video_capture_impl_manager.h" |
10 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 struct SourceVideoFormat { | 15 struct SourceVideoFormat { |
16 int width; | 16 int width; |
17 int height; | 17 int height; |
18 int frame_rate; | 18 int frame_rate; |
19 }; | 19 }; |
20 | 20 |
21 // List of formats used if the source doesn't support capability enumeration. | 21 // List of formats used if the source doesn't support capability enumeration. |
22 const SourceVideoFormat kVideoFormats[] = { | 22 const SourceVideoFormat kVideoFormats[] = { |
23 {1920, 1080, 30}, | 23 {1920, 1080, 30}, |
tommi (sloooow) - chröme
2014/03/13 17:19:38
nit: can you un-indent these by 2 spaces?
mcasas
2014/03/14 08:06:39
Done.
| |
24 {1280, 720, 30}, | 24 {1280, 720, 30}, |
25 {960, 720, 30}, | 25 {960, 720, 30}, |
26 {640, 480, 30}, | 26 {640, 480, 30}, |
27 {640, 360, 30}, | 27 {640, 360, 30}, |
28 {320, 240, 30}, | 28 {320, 240, 30}, |
29 {320, 180, 30} | 29 {320, 180, 30} |
30 }; | 30 }; |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; | 67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; |
68 formats.push_back( | 68 formats.push_back( |
69 media::VideoCaptureFormat( | 69 media::VideoCaptureFormat( |
70 gfx::Size(width, height), | 70 gfx::Size(width, height), |
71 MediaStreamVideoSource::kDefaultFrameRate, | 71 MediaStreamVideoSource::kDefaultFrameRate, |
72 media::PIXEL_FORMAT_I420)); | 72 media::PIXEL_FORMAT_I420)); |
73 callback.Run(formats); | 73 callback.Run(formats); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 // This delegate implementation doesn't support capability enumeration. | 77 DCHECK(source_formats_callback_.is_null()); |
78 // We need to guess what it supports. | 78 source_formats_callback_ = callback; |
79 media::VideoCaptureFormats formats; | 79 capture_engine_->GetDeviceFormatsInUse(base::Bind( |
80 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | 80 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this)); |
81 formats.push_back( | |
82 media::VideoCaptureFormat( | |
83 gfx::Size(kVideoFormats[i].width, | |
84 kVideoFormats[i].height), | |
85 kVideoFormats[i].frame_rate, | |
86 media::PIXEL_FORMAT_I420)); | |
87 } | |
88 callback.Run(formats); | |
89 } | 81 } |
90 | 82 |
91 void VideoCapturerDelegate::StartDeliver( | 83 void VideoCapturerDelegate::StartDeliver( |
92 const media::VideoCaptureParams& params, | 84 const media::VideoCaptureParams& params, |
93 const NewFrameCallback& new_frame_callback, | 85 const NewFrameCallback& new_frame_callback, |
94 const StartedCallback& started_callback) { | 86 const StartedCallback& started_callback) { |
95 DCHECK(params.requested_format.IsValid()); | 87 DCHECK(params.requested_format.IsValid()); |
96 message_loop_proxy_ = base::MessageLoopProxy::current(); | 88 message_loop_proxy_ = base::MessageLoopProxy::current(); |
97 new_frame_callback_ = new_frame_callback; | 89 new_frame_callback_ = new_frame_callback; |
98 started_callback_ = started_callback; | 90 started_callback_ = started_callback; |
99 got_first_frame_ = false; | 91 got_first_frame_ = false; |
100 | 92 |
101 // Increase the reference count to ensure the object is not deleted until | 93 // Increase the reference count to ensure the object is not deleted until |
102 // it is unregistered in VideoCapturerDelegate::OnRemoved. | 94 // it is unregistered in VideoCapturerDelegate::OnRemoved. |
103 AddRef(); | 95 AddRef(); |
104 capture_engine_->StartCapture(this, params); | 96 capture_engine_->StartCapture(this, params); |
105 } | 97 } |
106 | 98 |
107 void VideoCapturerDelegate::StopDeliver() { | 99 void VideoCapturerDelegate::StopDeliver() { |
108 // Immediately make sure we don't provide more frames. | 100 // Immediately make sure we don't provide more frames. |
109 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; | 101 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; |
110 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); | 102 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); |
111 capture_engine_->StopCapture(this); | 103 capture_engine_->StopCapture(this); |
112 new_frame_callback_.Reset(); | 104 new_frame_callback_.Reset(); |
113 started_callback_.Reset(); | 105 started_callback_.Reset(); |
106 source_formats_callback_.Reset(); | |
114 } | 107 } |
115 | 108 |
116 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { | 109 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { |
117 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; | 110 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; |
118 } | 111 } |
119 | 112 |
120 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { | 113 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { |
121 } | 114 } |
122 | 115 |
123 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { | 116 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 new_frame_callback_.Run(frame); | 158 new_frame_callback_.Run(frame); |
166 } | 159 } |
167 } | 160 } |
168 | 161 |
169 void VideoCapturerDelegate::OnErrorOnCaptureThread( | 162 void VideoCapturerDelegate::OnErrorOnCaptureThread( |
170 media::VideoCapture* capture) { | 163 media::VideoCapture* capture) { |
171 if (!started_callback_.is_null()) | 164 if (!started_callback_.is_null()) |
172 started_callback_.Run(false); | 165 started_callback_.Run(false); |
173 } | 166 } |
174 | 167 |
168 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( | |
169 const media::VideoCaptureFormats& formats_in_use) { | |
170 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); | |
171 if (!formats_in_use.empty()) { | |
172 if (!source_formats_callback_.is_null()) | |
173 source_formats_callback_.Run(formats_in_use); | |
174 } else { | |
175 DCHECK(!source_formats_callback_.is_null()); | |
176 // If there are no formats in use, try to retrieve the whole list of them. | |
177 capture_engine_->GetDeviceSupportedFormats(base::Bind( | |
178 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, this)); | |
179 } | |
180 } | |
181 | |
182 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( | |
183 const media::VideoCaptureFormats& formats) { | |
184 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() | |
185 << " received"; | |
186 if (formats.size()) { | |
187 if (!source_formats_callback_.is_null()) | |
188 source_formats_callback_.Run(formats); | |
189 } else { | |
190 // The capture device doesn't seem to support capability enumeration, | |
191 // compose a fallback list of capabilities. | |
192 media::VideoCaptureFormats default_formats; | |
193 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | |
194 default_formats.push_back(media::VideoCaptureFormat( | |
195 gfx::Size(kVideoFormats[i].width, kVideoFormats[i].height), | |
196 kVideoFormats[i].frame_rate, | |
197 media::PIXEL_FORMAT_I420)); | |
198 } | |
199 if (!source_formats_callback_.is_null()) | |
200 source_formats_callback_.Run(default_formats); | |
tommi (sloooow) - chröme
2014/03/13 17:19:38
whenever we call source_formats_callback_.Run(), s
mcasas
2014/03/14 08:06:39
There should only be one call back, so Reset() is
| |
201 } | |
202 } | |
203 | |
175 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( | 204 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( |
176 const StreamDeviceInfo& device_info, | 205 const StreamDeviceInfo& device_info, |
177 const SourceStoppedCallback& stop_callback, | 206 const SourceStoppedCallback& stop_callback, |
178 const scoped_refptr<VideoCapturerDelegate>& delegate, | 207 const scoped_refptr<VideoCapturerDelegate>& delegate, |
179 MediaStreamDependencyFactory* factory) | 208 MediaStreamDependencyFactory* factory) |
180 : MediaStreamVideoSource(factory), | 209 : MediaStreamVideoSource(factory), |
181 delegate_(delegate) { | 210 delegate_(delegate) { |
182 SetDeviceInfo(device_info); | 211 SetDeviceInfo(device_info); |
183 SetStopCallback(stop_callback); | 212 SetStopCallback(stop_callback); |
184 } | 213 } |
(...skipping 19 matching lines...) Expand all Loading... | |
204 base::Unretained(this)), | 233 base::Unretained(this)), |
205 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, | 234 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, |
206 base::Unretained(this))); | 235 base::Unretained(this))); |
207 } | 236 } |
208 | 237 |
209 void MediaStreamVideoCapturerSource::StopSourceImpl() { | 238 void MediaStreamVideoCapturerSource::StopSourceImpl() { |
210 delegate_->StopDeliver(); | 239 delegate_->StopDeliver(); |
211 } | 240 } |
212 | 241 |
213 } // namespace content | 242 } // namespace content |
OLD | NEW |