Index: webrtc/sdk/objc/Framework/Classes/objcvideotracksource.mm |
diff --git a/webrtc/sdk/objc/Framework/Classes/objcvideotracksource.mm b/webrtc/sdk/objc/Framework/Classes/objcvideotracksource.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8df1a7abf4fbd34a3d2179ffd904c29217e4ef4 |
--- /dev/null |
+++ b/webrtc/sdk/objc/Framework/Classes/objcvideotracksource.mm |
@@ -0,0 +1,88 @@ |
+/* |
+ * Copyright (c) 2017 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/sdk/objc/Framework/Classes/objcvideotracksource.h" |
+ |
+#import "RTCVideoFrame+Private.h" |
+ |
+#include "webrtc/common_video/include/corevideo_frame_buffer.h" |
+ |
+namespace webrtc { |
+ |
+ObjcVideoTrackSource::ObjcVideoTrackSource() {} |
+ |
+void ObjcVideoTrackSource::OnOutputFormatRequest(int width, |
+ int height, |
+ int fps) { |
+ cricket::VideoFormat format(width, height, |
+ cricket::VideoFormat::FpsToInterval(fps), 0); |
+ video_adapter()->OnOutputFormatRequest(format); |
+} |
+ |
+void ObjcVideoTrackSource::OnCapturedFrame(RTCVideoFrame* frame) { |
+ const int64_t timestamp_us = frame.timeStampNs / rtc::kNumNanosecsPerMicrosec; |
+ const int64_t translated_timestamp_us = |
+ timestamp_aligner_.TranslateTimestamp(timestamp_us, rtc::TimeMicros()); |
+ |
+ int captured_width = frame.width; |
+ int captured_height = frame.height; |
+ |
+ int adapted_width; |
+ int adapted_height; |
+ int crop_width; |
+ int crop_height; |
+ int crop_x; |
+ int crop_y; |
+ if (!AdaptFrame(captured_width, captured_height, |
+ timestamp_us, |
+ &adapted_width, &adapted_height, |
+ &crop_width, &crop_height, |
+ &crop_x, &crop_y)) { |
+ return; |
+ } |
+ |
+ rtc::scoped_refptr<VideoFrameBuffer> buffer; |
+ if (adapted_width == captured_width && adapted_height == captured_height) { |
+ // No adaption - optimized path. |
+ buffer = frame.videoBuffer; |
+ } else if (frame.nativeHandle) { |
+ // Adapted CVPixelBuffer frame. |
+ buffer = new rtc::RefCountedObject<CoreVideoFrameBuffer>( |
+ static_cast<CVPixelBufferRef>(frame.nativeHandle), |
+ adapted_width, adapted_height, |
+ crop_width, crop_height, |
+ crop_x, crop_y); |
+ } else { |
+ // Adapted I420 frame. |
+ // TODO(magjed): Optimize this I420 path. |
+ rtc::scoped_refptr<I420Buffer> i420_buffer = |
+ I420Buffer::Create(adapted_width, adapted_height); |
+ i420_buffer->CropAndScaleFrom(*frame.videoBuffer, |
+ crop_x, crop_y, |
+ crop_width, crop_height); |
+ buffer = i420_buffer; |
+ } |
+ |
+ // Applying rotation is only supported for legacy reasons and performance is |
+ // not critical here. |
+ webrtc::VideoRotation rotation = |
+ static_cast<webrtc::VideoRotation>(frame.rotation); |
+ if (apply_rotation() && rotation != kVideoRotation_0) { |
+ buffer = I420Buffer::Rotate(buffer->NativeToI420Buffer(), rotation); |
+ if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { |
+ std::swap(captured_width, captured_height); |
sakal
2017/03/15 15:52:21
It doesn't look like this code is needed.
magjed_webrtc
2017/03/16 12:07:02
True, it's copy-pasted from another class...
|
+ } |
+ rotation = kVideoRotation_0; |
+ } |
+ |
+ OnFrame(webrtc::VideoFrame(buffer, rotation, translated_timestamp_us)); |
+} |
+ |
+} // namespace webrtc |