Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: webrtc/media/base/adaptedvideosource.cc

Issue 2318953005: New helper class AdaptedVideoSource. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/base/adaptedvideosource.h ('k') | webrtc/media/base/videocapturer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « webrtc/media/base/adaptedvideosource.h ('k') | webrtc/media/base/videocapturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698