OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 thread_checker_.DetachFromThread(); | 63 thread_checker_.DetachFromThread(); |
64 Construct(); | 64 Construct(); |
65 } | 65 } |
66 | 66 |
67 void VideoCapturer::Construct() { | 67 void VideoCapturer::Construct() { |
68 enable_camera_list_ = false; | 68 enable_camera_list_ = false; |
69 capture_state_ = CS_STOPPED; | 69 capture_state_ = CS_STOPPED; |
70 SignalFrameCaptured.connect(this, &VideoCapturer::OnFrameCaptured); | 70 SignalFrameCaptured.connect(this, &VideoCapturer::OnFrameCaptured); |
71 scaled_width_ = 0; | 71 scaled_width_ = 0; |
72 scaled_height_ = 0; | 72 scaled_height_ = 0; |
73 enable_video_adapter_ = true; | |
74 // There are lots of video capturers out there that don't call | 73 // There are lots of video capturers out there that don't call |
75 // set_frame_factory. We can either go change all of them, or we | 74 // set_frame_factory. We can either go change all of them, or we |
76 // can set this default. | 75 // can set this default. |
77 // TODO(pthatcher): Remove this hack and require the frame factory | 76 // TODO(pthatcher): Remove this hack and require the frame factory |
78 // to be passed in the constructor. | 77 // to be passed in the constructor. |
79 set_frame_factory(new WebRtcVideoFrameFactory()); | 78 set_frame_factory(new WebRtcVideoFrameFactory()); |
80 } | 79 } |
81 | 80 |
82 const std::vector<VideoFormat>* VideoCapturer::GetSupportedFormats() const { | 81 const std::vector<VideoFormat>* VideoCapturer::GetSupportedFormats() const { |
83 return &filtered_supported_formats_; | 82 return &filtered_supported_formats_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 fourcc_name = ""; | 160 fourcc_name = ""; |
162 break; | 161 break; |
163 } | 162 } |
164 } | 163 } |
165 | 164 |
166 std::ostringstream ss; | 165 std::ostringstream ss; |
167 ss << fourcc_name << captured_frame->width << "x" << captured_frame->height; | 166 ss << fourcc_name << captured_frame->width << "x" << captured_frame->height; |
168 return ss.str(); | 167 return ss.str(); |
169 } | 168 } |
170 | 169 |
| 170 bool VideoCapturer::enable_video_adapter() const { |
| 171 return !IsScreencast() && adapted_source_.enable_video_adapter(); |
| 172 } |
| 173 void VideoCapturer::set_enable_video_adapter(bool enable_video_adapter) { |
| 174 adapted_source_.set_enable_video_adapter( |
| 175 enable_video_adapter && !IsScreencast()); |
| 176 } |
| 177 |
171 void VideoCapturer::set_frame_factory(VideoFrameFactory* frame_factory) { | 178 void VideoCapturer::set_frame_factory(VideoFrameFactory* frame_factory) { |
172 frame_factory_.reset(frame_factory); | 179 frame_factory_.reset(frame_factory); |
173 if (frame_factory) { | 180 if (frame_factory) { |
174 frame_factory->SetApplyRotation(apply_rotation_); | 181 frame_factory->SetApplyRotation(apply_rotation_); |
175 } | 182 } |
176 } | 183 } |
177 | 184 |
178 bool VideoCapturer::GetInputSize(int* width, int* height) { | 185 bool VideoCapturer::GetInputSize(int* width, int* height) { |
179 rtc::CritScope cs(&frame_stats_crit_); | 186 rtc::CritScope cs(&frame_stats_crit_); |
180 if (!input_size_valid_) { | 187 if (!input_size_valid_) { |
181 return false; | 188 return false; |
182 } | 189 } |
183 *width = input_width_; | 190 *width = input_width_; |
184 *height = input_height_; | 191 *height = input_height_; |
185 | 192 |
186 return true; | 193 return true; |
187 } | 194 } |
188 | 195 |
189 void VideoCapturer::RemoveSink( | 196 void VideoCapturer::RemoveSink( |
190 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { | 197 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { |
191 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 198 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
192 broadcaster_.RemoveSink(sink); | 199 adapted_source_.RemoveSink(sink); |
193 OnSinkWantsChanged(broadcaster_.wants()); | 200 OnSinkWantsChanged(adapted_source_.wants()); |
194 } | 201 } |
195 | 202 |
196 void VideoCapturer::AddOrUpdateSink( | 203 void VideoCapturer::AddOrUpdateSink( |
197 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | 204 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
198 const rtc::VideoSinkWants& wants) { | 205 const rtc::VideoSinkWants& wants) { |
199 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 206 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
200 broadcaster_.AddOrUpdateSink(sink, wants); | 207 adapted_source_.AddOrUpdateSink(sink, wants); |
201 OnSinkWantsChanged(broadcaster_.wants()); | 208 OnSinkWantsChanged(adapted_source_.wants()); |
202 } | 209 } |
203 | 210 |
204 void VideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) { | 211 void VideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) { |
205 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 212 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
206 apply_rotation_ = wants.rotation_applied; | 213 apply_rotation_ = wants.rotation_applied; |
207 if (frame_factory_) { | 214 if (frame_factory_) { |
208 frame_factory_->SetApplyRotation(apply_rotation_); | 215 frame_factory_->SetApplyRotation(apply_rotation_); |
209 } | 216 } |
210 | |
211 if (video_adapter()) { | |
212 video_adapter()->OnResolutionRequest(wants.max_pixel_count, | |
213 wants.max_pixel_count_step_up); | |
214 } | |
215 } | |
216 | |
217 bool VideoCapturer::AdaptFrame(int width, | |
218 int height, | |
219 int64_t camera_time_us, | |
220 int64_t system_time_us, | |
221 int* out_width, | |
222 int* out_height, | |
223 int* crop_width, | |
224 int* crop_height, | |
225 int* crop_x, | |
226 int* crop_y, | |
227 int64_t* translated_camera_time_us) { | |
228 int64_t offset_us = | |
229 translated_camera_time_us | |
230 ? timestamp_aligner_.UpdateOffset(camera_time_us, system_time_us) | |
231 : 0; | |
232 | |
233 if (!broadcaster_.frame_wanted()) { | |
234 return false; | |
235 } | |
236 | |
237 if (enable_video_adapter_ && !IsScreencast()) { | |
238 if (!video_adapter_.AdaptFrameResolution( | |
239 width, height, camera_time_us * rtc::kNumNanosecsPerMicrosec, | |
240 crop_width, crop_height, out_width, out_height)) { | |
241 // VideoAdapter dropped the frame. | |
242 return false; | |
243 } | |
244 *crop_x = (width - *crop_width) / 2; | |
245 *crop_y = (height - *crop_height) / 2; | |
246 } else { | |
247 *out_width = width; | |
248 *out_height = height; | |
249 *crop_width = width; | |
250 *crop_height = height; | |
251 *crop_x = 0; | |
252 *crop_y = 0; | |
253 } | |
254 | |
255 if (translated_camera_time_us) { | |
256 *translated_camera_time_us = timestamp_aligner_.ClipTimestamp( | |
257 camera_time_us + offset_us, system_time_us); | |
258 } | |
259 return true; | |
260 } | 217 } |
261 | 218 |
262 void VideoCapturer::OnFrameCaptured(VideoCapturer*, | 219 void VideoCapturer::OnFrameCaptured(VideoCapturer*, |
263 const CapturedFrame* captured_frame) { | 220 const CapturedFrame* captured_frame) { |
264 int out_width; | 221 int out_width; |
265 int out_height; | 222 int out_height; |
266 int crop_width; | 223 int crop_width; |
267 int crop_height; | 224 int crop_height; |
268 int crop_x; | 225 int crop_x; |
269 int crop_y; | 226 int crop_y; |
270 | 227 |
271 // TODO(nisse): We don't do timestamp translation on this input | 228 // TODO(nisse): We don't do timestamp translation on this input |
272 // path. It seems straight-forward to enable translation, but that | 229 // path. It seems straight-forward to enable translation, but that |
273 // breaks the WebRtcVideoEngine2Test.PropagatesInputFrameTimestamp | 230 // breaks the WebRtcVideoEngine2Test.PropagatesInputFrameTimestamp |
274 // test. Probably not worth the effort to fix, instead, try to | 231 // test. Probably not worth the effort to fix, instead, try to |
275 // delete or refactor all code using VideoFrameFactory and | 232 // delete or refactor all code using VideoFrameFactory and |
276 // SignalCapturedFrame. | 233 // SignalCapturedFrame. |
277 if (!AdaptFrame(captured_frame->width, captured_frame->height, | 234 if (!adapted_source_.AdaptFrame( |
278 captured_frame->time_stamp / rtc::kNumNanosecsPerMicrosec, | 235 captured_frame->width, captured_frame->height, |
279 0, | 236 captured_frame->time_stamp / rtc::kNumNanosecsPerMicrosec, |
280 &out_width, &out_height, | 237 0, |
281 &crop_width, &crop_height, &crop_x, &crop_y, nullptr)) { | 238 &out_width, &out_height, |
| 239 &crop_width, &crop_height, &crop_x, &crop_y, nullptr)) { |
282 return; | 240 return; |
283 } | 241 } |
284 | 242 |
285 if (!frame_factory_) { | 243 if (!frame_factory_) { |
286 LOG(LS_ERROR) << "No video frame factory."; | 244 LOG(LS_ERROR) << "No video frame factory."; |
287 return; | 245 return; |
288 } | 246 } |
289 | 247 |
290 // TODO(nisse): Reorganize frame factory methods. crop_x and crop_y | 248 // TODO(nisse): Reorganize frame factory methods. crop_x and crop_y |
291 // are ignored for now. | 249 // are ignored for now. |
292 std::unique_ptr<VideoFrame> adapted_frame(frame_factory_->CreateAliasedFrame( | 250 std::unique_ptr<VideoFrame> adapted_frame(frame_factory_->CreateAliasedFrame( |
293 captured_frame, crop_width, crop_height, out_width, out_height)); | 251 captured_frame, crop_width, crop_height, out_width, out_height)); |
294 | 252 |
295 if (!adapted_frame) { | 253 if (!adapted_frame) { |
296 // TODO(fbarchard): LOG more information about captured frame attributes. | 254 // TODO(fbarchard): LOG more information about captured frame attributes. |
297 LOG(LS_ERROR) << "Couldn't convert to I420! " | 255 LOG(LS_ERROR) << "Couldn't convert to I420! " |
298 << "From " << ToString(captured_frame) << " To " | 256 << "From " << ToString(captured_frame) << " To " |
299 << out_width << " x " << out_height; | 257 << out_width << " x " << out_height; |
300 return; | 258 return; |
301 } | 259 } |
302 | 260 |
303 OnFrame(*adapted_frame, captured_frame->width, captured_frame->height); | 261 OnFrame(*adapted_frame, captured_frame->width, captured_frame->height); |
304 } | 262 } |
305 | 263 |
306 void VideoCapturer::OnFrame(const VideoFrame& frame, | 264 void VideoCapturer::OnFrame(const VideoFrame& frame, |
307 int orig_width, | 265 int orig_width, |
308 int orig_height) { | 266 int orig_height) { |
309 broadcaster_.OnFrame(frame); | 267 adapted_source_.OnFrame(frame); |
310 UpdateInputSize(orig_width, orig_height); | 268 UpdateInputSize(orig_width, orig_height); |
311 } | 269 } |
312 | 270 |
313 void VideoCapturer::SetCaptureState(CaptureState state) { | 271 void VideoCapturer::SetCaptureState(CaptureState state) { |
314 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 272 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
315 if (state == capture_state_) { | 273 if (state == capture_state_) { |
316 // Don't trigger a state changed callback if the state hasn't changed. | 274 // Don't trigger a state changed callback if the state hasn't changed. |
317 return; | 275 return; |
318 } | 276 } |
319 capture_state_ = state; | 277 capture_state_ = state; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 void VideoCapturer::UpdateInputSize(int width, int height) { | 409 void VideoCapturer::UpdateInputSize(int width, int height) { |
452 // Update stats protected from fetches from different thread. | 410 // Update stats protected from fetches from different thread. |
453 rtc::CritScope cs(&frame_stats_crit_); | 411 rtc::CritScope cs(&frame_stats_crit_); |
454 | 412 |
455 input_size_valid_ = true; | 413 input_size_valid_ = true; |
456 input_width_ = width; | 414 input_width_ = width; |
457 input_height_ = height; | 415 input_height_ = height; |
458 } | 416 } |
459 | 417 |
460 } // namespace cricket | 418 } // namespace cricket |
OLD | NEW |