OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/media/base/adaptedvideosource.h" |
| 12 |
| 13 namespace rtc { |
| 14 |
| 15 AdaptedVideoSource::AdaptedVideoSource() : enable_video_adapter_(true) {} |
| 16 |
| 17 bool AdaptedVideoSource::AdaptFrame(int width, |
| 18 int height, |
| 19 int64_t camera_time_us, |
| 20 int64_t system_time_us, |
| 21 int* out_width, |
| 22 int* out_height, |
| 23 int* crop_width, |
| 24 int* crop_height, |
| 25 int* crop_x, |
| 26 int* crop_y, |
| 27 int64_t* translated_camera_time_us) { |
| 28 int64_t offset_us = |
| 29 translated_camera_time_us |
| 30 ? timestamp_aligner_.UpdateOffset(camera_time_us, system_time_us) |
| 31 : 0; |
| 32 |
| 33 if (!frame_wanted()) { |
| 34 return false; |
| 35 } |
| 36 |
| 37 if (enable_video_adapter_) { |
| 38 if (!video_adapter_.AdaptFrameResolution( |
| 39 width, height, camera_time_us * rtc::kNumNanosecsPerMicrosec, |
| 40 crop_width, crop_height, out_width, out_height)) { |
| 41 // VideoAdapter dropped the frame. |
| 42 return false; |
| 43 } |
| 44 *crop_x = (width - *crop_width) / 2; |
| 45 *crop_y = (height - *crop_height) / 2; |
| 46 } else { |
| 47 *out_width = width; |
| 48 *out_height = height; |
| 49 *crop_width = width; |
| 50 *crop_height = height; |
| 51 *crop_x = 0; |
| 52 *crop_y = 0; |
| 53 } |
| 54 |
| 55 if (translated_camera_time_us) { |
| 56 *translated_camera_time_us = timestamp_aligner_.ClipTimestamp( |
| 57 camera_time_us + offset_us, system_time_us); |
| 58 } |
| 59 return true; |
| 60 } |
| 61 |
| 62 // TODO(nisse): OK to call OnResolutionRequest while holding |
| 63 // sinks_and_wants_lock_? |
| 64 void AdaptedVideoSource::UpdateWants() { |
| 65 VideoBroadcaster::UpdateWants(); |
| 66 video_adapter_.OnResolutionRequest(current_wants_.max_pixel_count, |
| 67 current_wants_.max_pixel_count_step_up); |
| 68 } |
| 69 |
| 70 } // namespace rtc |
OLD | NEW |