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[] = {{1920, 1080, 30}, |
23 {1920, 1080, 30}, | 23 {1280, 720, 30}, |
24 {1280, 720, 30}, | 24 {960, 720, 30}, |
25 {960, 720, 30}, | 25 {640, 480, 30}, |
26 {640, 480, 30}, | 26 {640, 360, 30}, |
27 {640, 360, 30}, | 27 {320, 240, 30}, |
28 {320, 240, 30}, | 28 {320, 180, 30}}; |
29 {320, 180, 30} | |
30 }; | |
31 | 29 |
32 } // namespace | 30 } // namespace |
33 | 31 |
34 namespace content { | 32 namespace content { |
35 | 33 |
36 VideoCapturerDelegate::VideoCapturerDelegate( | 34 VideoCapturerDelegate::VideoCapturerDelegate( |
37 const StreamDeviceInfo& device_info) | 35 const StreamDeviceInfo& device_info) |
38 : session_id_(device_info.session_id), | 36 : session_id_(device_info.session_id), |
39 capture_engine_( | 37 capture_engine_( |
40 RenderThreadImpl::current()->video_capture_impl_manager() | 38 RenderThreadImpl::current()->video_capture_impl_manager() |
(...skipping 26 matching lines...) Expand all Loading... | |
67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; | 65 max_requested_height : MediaStreamVideoSource::kDefaultHeight; |
68 formats.push_back( | 66 formats.push_back( |
69 media::VideoCaptureFormat( | 67 media::VideoCaptureFormat( |
70 gfx::Size(width, height), | 68 gfx::Size(width, height), |
71 MediaStreamVideoSource::kDefaultFrameRate, | 69 MediaStreamVideoSource::kDefaultFrameRate, |
72 media::PIXEL_FORMAT_I420)); | 70 media::PIXEL_FORMAT_I420)); |
73 callback.Run(formats); | 71 callback.Run(formats); |
74 return; | 72 return; |
75 } | 73 } |
76 | 74 |
77 // This delegate implementation doesn't support capability enumeration. | 75 DCHECK(source_formats_callback_.is_null()); |
78 // We need to guess what it supports. | 76 source_formats_callback_ = callback; |
79 media::VideoCaptureFormats formats; | 77 capture_engine_->GetDeviceFormatsInUse(base::Bind( |
80 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | 78 &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 } | 79 } |
90 | 80 |
91 void VideoCapturerDelegate::StartDeliver( | 81 void VideoCapturerDelegate::StartDeliver( |
92 const media::VideoCaptureParams& params, | 82 const media::VideoCaptureParams& params, |
93 const NewFrameCallback& new_frame_callback, | 83 const NewFrameCallback& new_frame_callback, |
94 const StartedCallback& started_callback) { | 84 const StartedCallback& started_callback) { |
95 DCHECK(params.requested_format.IsValid()); | 85 DCHECK(params.requested_format.IsValid()); |
96 message_loop_proxy_ = base::MessageLoopProxy::current(); | 86 message_loop_proxy_ = base::MessageLoopProxy::current(); |
97 new_frame_callback_ = new_frame_callback; | 87 new_frame_callback_ = new_frame_callback; |
98 started_callback_ = started_callback; | 88 started_callback_ = started_callback; |
99 got_first_frame_ = false; | 89 got_first_frame_ = false; |
100 | 90 |
101 // Increase the reference count to ensure the object is not deleted until | 91 // Increase the reference count to ensure the object is not deleted until |
102 // it is unregistered in VideoCapturerDelegate::OnRemoved. | 92 // it is unregistered in VideoCapturerDelegate::OnRemoved. |
103 AddRef(); | 93 AddRef(); |
104 capture_engine_->StartCapture(this, params); | 94 capture_engine_->StartCapture(this, params); |
105 } | 95 } |
106 | 96 |
107 void VideoCapturerDelegate::StopDeliver() { | 97 void VideoCapturerDelegate::StopDeliver() { |
108 // Immediately make sure we don't provide more frames. | 98 // Immediately make sure we don't provide more frames. |
109 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; | 99 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; |
110 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); | 100 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); |
111 capture_engine_->StopCapture(this); | 101 capture_engine_->StopCapture(this); |
112 new_frame_callback_.Reset(); | 102 new_frame_callback_.Reset(); |
113 started_callback_.Reset(); | 103 started_callback_.Reset(); |
104 source_formats_callback_.Reset(); | |
114 } | 105 } |
115 | 106 |
116 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { | 107 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { |
117 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; | 108 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; |
118 } | 109 } |
119 | 110 |
120 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { | 111 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { |
121 } | 112 } |
122 | 113 |
123 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { | 114 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); | 156 new_frame_callback_.Run(frame); |
166 } | 157 } |
167 } | 158 } |
168 | 159 |
169 void VideoCapturerDelegate::OnErrorOnCaptureThread( | 160 void VideoCapturerDelegate::OnErrorOnCaptureThread( |
170 media::VideoCapture* capture) { | 161 media::VideoCapture* capture) { |
171 if (!started_callback_.is_null()) | 162 if (!started_callback_.is_null()) |
172 started_callback_.Run(false); | 163 started_callback_.Run(false); |
173 } | 164 } |
174 | 165 |
166 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( | |
167 const media::VideoCaptureFormats& formats_in_use) { | |
168 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); | |
169 if (!source_formats_callback_.is_null()) | |
170 return; | |
171 if (!formats_in_use.empty()) { | |
172 source_formats_callback_.Run(formats_in_use); | |
173 source_formats_callback_.Reset(); | |
174 } else { | |
175 // If there are no formats in use, try to retrieve the whole list of them. | |
perkj_chrome
2014/03/17 11:05:40
nit: of supported formats
mcasas
2014/03/17 15:12:59
Done.
| |
176 capture_engine_->GetDeviceSupportedFormats(base::Bind( | |
177 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, this)); | |
178 } | |
179 } | |
180 | |
181 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( | |
182 const media::VideoCaptureFormats& formats) { | |
183 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() | |
184 << " received"; | |
185 if (!source_formats_callback_.is_null()) | |
tommi (sloooow) - chröme
2014/03/17 11:56:22
if we get here and source_formats_callback_ is nul
mcasas
2014/03/17 15:12:59
Done.
| |
186 return; | |
187 if (formats.size()) { | |
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 source_formats_callback_.Run(default_formats); | |
200 } | |
201 source_formats_callback_.Reset(); | |
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 |