OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 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/sdk/objc/Framework/Classes/objcvideotracksource.h" | |
12 | |
13 #import "RTCVideoFrame+Private.h" | |
14 | |
15 #include "webrtc/common_video/include/corevideo_frame_buffer.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 ObjcVideoTrackSource::ObjcVideoTrackSource() {} | |
20 | |
21 void ObjcVideoTrackSource::OnOutputFormatRequest(int width, | |
22 int height, | |
23 int fps) { | |
24 cricket::VideoFormat format(width, height, | |
25 cricket::VideoFormat::FpsToInterval(fps), 0); | |
26 video_adapter()->OnOutputFormatRequest(format); | |
27 } | |
28 | |
29 void ObjcVideoTrackSource::OnCapturedFrame(RTCVideoFrame* frame) { | |
30 const int64_t timestamp_us = frame.timeStampNs / rtc::kNumNanosecsPerMicrosec; | |
31 const int64_t translated_timestamp_us = | |
32 timestamp_aligner_.TranslateTimestamp(timestamp_us, rtc::TimeMicros()); | |
33 | |
34 int captured_width = frame.width; | |
35 int captured_height = frame.height; | |
36 | |
37 int adapted_width; | |
38 int adapted_height; | |
39 int crop_width; | |
40 int crop_height; | |
41 int crop_x; | |
42 int crop_y; | |
43 if (!AdaptFrame(captured_width, captured_height, | |
44 timestamp_us, | |
45 &adapted_width, &adapted_height, | |
46 &crop_width, &crop_height, | |
47 &crop_x, &crop_y)) { | |
48 return; | |
49 } | |
50 | |
51 rtc::scoped_refptr<VideoFrameBuffer> buffer; | |
52 if (adapted_width == captured_width && adapted_height == captured_height) { | |
53 // No adaption - optimized path. | |
54 buffer = frame.videoBuffer; | |
55 } else if (frame.nativeHandle) { | |
56 // Adapted CVPixelBuffer frame. | |
57 buffer = new rtc::RefCountedObject<CoreVideoFrameBuffer>( | |
58 static_cast<CVPixelBufferRef>(frame.nativeHandle), | |
59 adapted_width, adapted_height, | |
60 crop_width, crop_height, | |
61 crop_x, crop_y); | |
62 } else { | |
63 // Adapted I420 frame. | |
64 // TODO(magjed): Optimize this I420 path. | |
65 rtc::scoped_refptr<I420Buffer> i420_buffer = | |
66 I420Buffer::Create(adapted_width, adapted_height); | |
67 i420_buffer->CropAndScaleFrom(*frame.videoBuffer, | |
68 crop_x, crop_y, | |
69 crop_width, crop_height); | |
70 buffer = i420_buffer; | |
71 } | |
72 | |
73 // Applying rotation is only supported for legacy reasons and performance is | |
74 // not critical here. | |
75 webrtc::VideoRotation rotation = | |
76 static_cast<webrtc::VideoRotation>(frame.rotation); | |
77 if (apply_rotation() && rotation != kVideoRotation_0) { | |
78 buffer = I420Buffer::Rotate(buffer->NativeToI420Buffer(), rotation); | |
79 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { | |
80 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...
| |
81 } | |
82 rotation = kVideoRotation_0; | |
83 } | |
84 | |
85 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_timestamp_us)); | |
86 } | |
87 | |
88 } // namespace webrtc | |
OLD | NEW |