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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (frame_factory_) { | 207 if (frame_factory_) { |
208 frame_factory_->SetApplyRotation(apply_rotation_); | 208 frame_factory_->SetApplyRotation(apply_rotation_); |
209 } | 209 } |
210 | 210 |
211 if (video_adapter()) { | 211 if (video_adapter()) { |
212 video_adapter()->OnResolutionRequest(wants.max_pixel_count, | 212 video_adapter()->OnResolutionRequest(wants.max_pixel_count, |
213 wants.max_pixel_count_step_up); | 213 wants.max_pixel_count_step_up); |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
| 217 bool VideoCapturer::AdaptFrame(int width, |
| 218 int height, |
| 219 int* out_width, |
| 220 int* out_height, |
| 221 int* crop_width, |
| 222 int* crop_height, |
| 223 int* crop_x, |
| 224 int* crop_y) { |
| 225 if (!broadcaster_.frame_wanted()) { |
| 226 return false; |
| 227 } |
| 228 |
| 229 if (enable_video_adapter_ && !IsScreencast()) { |
| 230 if (!video_adapter_.AdaptFrameResolution( |
| 231 width, height, crop_width, crop_height, out_width, out_height)) { |
| 232 // VideoAdapter dropped the frame. |
| 233 return false; |
| 234 } |
| 235 *crop_x = (width - *crop_width) / 2; |
| 236 *crop_y = (height - *crop_height) / 2; |
| 237 } else { |
| 238 *out_width = width; |
| 239 *out_height = height; |
| 240 *crop_width = width; |
| 241 *crop_height = height; |
| 242 *crop_x = 0; |
| 243 *crop_y = 0; |
| 244 } |
| 245 return true; |
| 246 } |
| 247 |
217 void VideoCapturer::OnFrameCaptured(VideoCapturer*, | 248 void VideoCapturer::OnFrameCaptured(VideoCapturer*, |
218 const CapturedFrame* captured_frame) { | 249 const CapturedFrame* captured_frame) { |
219 if (!broadcaster_.frame_wanted()) { | 250 int out_width; |
| 251 int out_height; |
| 252 int crop_width; |
| 253 int crop_height; |
| 254 int crop_x; |
| 255 int crop_y; |
| 256 |
| 257 if (!AdaptFrame(captured_frame->width, captured_frame->height, |
| 258 &out_width, &out_height, |
| 259 &crop_width, &crop_height, &crop_x, &crop_y)) { |
220 return; | 260 return; |
221 } | 261 } |
222 | 262 |
223 int cropped_width = captured_frame->width; | |
224 int cropped_height = captured_frame->height; | |
225 int out_width = captured_frame->width; | |
226 int out_height = captured_frame->height; | |
227 if (enable_video_adapter_ && !IsScreencast()) { | |
228 video_adapter_.AdaptFrameResolution( | |
229 captured_frame->width, captured_frame->height, | |
230 &cropped_width, &cropped_height, | |
231 &out_width, &out_height); | |
232 if (out_width == 0 || out_height == 0) { | |
233 // VideoAdapter dropped the frame. | |
234 return; | |
235 } | |
236 } | |
237 | |
238 if (!frame_factory_) { | 263 if (!frame_factory_) { |
239 LOG(LS_ERROR) << "No video frame factory."; | 264 LOG(LS_ERROR) << "No video frame factory."; |
240 return; | 265 return; |
241 } | 266 } |
242 | 267 |
243 // TODO(nisse): Reorganize frame factory methods. | 268 // TODO(nisse): Reorganize frame factory methods. crop_x and crop_y |
| 269 // are ignored for now. |
244 std::unique_ptr<VideoFrame> adapted_frame(frame_factory_->CreateAliasedFrame( | 270 std::unique_ptr<VideoFrame> adapted_frame(frame_factory_->CreateAliasedFrame( |
245 captured_frame, cropped_width, cropped_height, out_width, out_height)); | 271 captured_frame, crop_width, crop_height, out_width, out_height)); |
246 | 272 |
247 if (!adapted_frame) { | 273 if (!adapted_frame) { |
248 // TODO(fbarchard): LOG more information about captured frame attributes. | 274 // TODO(fbarchard): LOG more information about captured frame attributes. |
249 LOG(LS_ERROR) << "Couldn't convert to I420! " | 275 LOG(LS_ERROR) << "Couldn't convert to I420! " |
250 << "From " << ToString(captured_frame) << " To " | 276 << "From " << ToString(captured_frame) << " To " |
251 << out_width << " x " << out_height; | 277 << out_width << " x " << out_height; |
252 return; | 278 return; |
253 } | 279 } |
254 | 280 |
255 OnFrame(this, adapted_frame.get()); | 281 OnFrame(*adapted_frame, captured_frame->width, captured_frame->height); |
256 UpdateInputSize(captured_frame); | |
257 } | 282 } |
258 | 283 |
259 void VideoCapturer::OnFrame(VideoCapturer* capturer, const VideoFrame* frame) { | 284 void VideoCapturer::OnFrame(const VideoFrame& frame, |
260 broadcaster_.OnFrame(*frame); | 285 int orig_width, |
| 286 int orig_height) { |
| 287 broadcaster_.OnFrame(frame); |
| 288 UpdateInputSize(orig_width, orig_height); |
261 } | 289 } |
262 | 290 |
263 void VideoCapturer::SetCaptureState(CaptureState state) { | 291 void VideoCapturer::SetCaptureState(CaptureState state) { |
264 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 292 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
265 if (state == capture_state_) { | 293 if (state == capture_state_) { |
266 // Don't trigger a state changed callback if the state hasn't changed. | 294 // Don't trigger a state changed callback if the state hasn't changed. |
267 return; | 295 return; |
268 } | 296 } |
269 capture_state_ = state; | 297 capture_state_ = state; |
270 SignalStateChange(this, capture_state_); | 298 SignalStateChange(this, capture_state_); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 419 |
392 bool VideoCapturer::ShouldFilterFormat(const VideoFormat& format) const { | 420 bool VideoCapturer::ShouldFilterFormat(const VideoFormat& format) const { |
393 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 421 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
394 if (!enable_camera_list_) { | 422 if (!enable_camera_list_) { |
395 return false; | 423 return false; |
396 } | 424 } |
397 return format.width > max_format_->width || | 425 return format.width > max_format_->width || |
398 format.height > max_format_->height; | 426 format.height > max_format_->height; |
399 } | 427 } |
400 | 428 |
401 void VideoCapturer::UpdateInputSize(const CapturedFrame* captured_frame) { | 429 void VideoCapturer::UpdateInputSize(int width, int height) { |
402 // Update stats protected from fetches from different thread. | 430 // Update stats protected from fetches from different thread. |
403 rtc::CritScope cs(&frame_stats_crit_); | 431 rtc::CritScope cs(&frame_stats_crit_); |
404 | 432 |
405 input_size_valid_ = true; | 433 input_size_valid_ = true; |
406 input_width_ = captured_frame->width; | 434 input_width_ = width; |
407 input_height_ = captured_frame->height; | 435 input_height_ = height; |
408 } | 436 } |
409 | 437 |
410 } // namespace cricket | 438 } // namespace cricket |
OLD | NEW |