Index: webrtc/media/base/adaptedvideosource.cc |
diff --git a/webrtc/media/base/adaptedvideosource.cc b/webrtc/media/base/adaptedvideosource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..156c0b19fc6a739226298e83886cdc6245011d01 |
--- /dev/null |
+++ b/webrtc/media/base/adaptedvideosource.cc |
@@ -0,0 +1,70 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/media/base/adaptedvideosource.h" |
+ |
+namespace rtc { |
+ |
+AdaptedVideoSource::AdaptedVideoSource() : enable_video_adapter_(true) {} |
+ |
+bool AdaptedVideoSource::AdaptFrame(int width, |
+ int height, |
+ int64_t camera_time_us, |
+ int64_t system_time_us, |
+ int* out_width, |
+ int* out_height, |
+ int* crop_width, |
+ int* crop_height, |
+ int* crop_x, |
+ int* crop_y, |
+ int64_t* translated_camera_time_us) { |
+ int64_t offset_us = |
+ translated_camera_time_us |
+ ? timestamp_aligner_.UpdateOffset(camera_time_us, system_time_us) |
+ : 0; |
+ |
+ if (!frame_wanted()) { |
+ return false; |
+ } |
+ |
+ if (enable_video_adapter_) { |
+ if (!video_adapter_.AdaptFrameResolution( |
+ width, height, camera_time_us * rtc::kNumNanosecsPerMicrosec, |
+ crop_width, crop_height, out_width, out_height)) { |
+ // VideoAdapter dropped the frame. |
+ return false; |
+ } |
+ *crop_x = (width - *crop_width) / 2; |
+ *crop_y = (height - *crop_height) / 2; |
+ } else { |
+ *out_width = width; |
+ *out_height = height; |
+ *crop_width = width; |
+ *crop_height = height; |
+ *crop_x = 0; |
+ *crop_y = 0; |
+ } |
+ |
+ if (translated_camera_time_us) { |
+ *translated_camera_time_us = timestamp_aligner_.ClipTimestamp( |
+ camera_time_us + offset_us, system_time_us); |
+ } |
+ return true; |
+} |
+ |
+// TODO(nisse): OK to call OnResolutionRequest while holding |
+// sinks_and_wants_lock_? |
+void AdaptedVideoSource::UpdateWants() { |
+ VideoBroadcaster::UpdateWants(); |
+ video_adapter_.OnResolutionRequest(current_wants_.max_pixel_count, |
+ current_wants_.max_pixel_count_step_up); |
+} |
+ |
+} // namespace rtc |