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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/Video/objcvideotracksource.mm

Issue 2890513002: Revert of Split iOS sdk in to separate targets (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(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/Video/objcvideotracksource.h"
12
13 #import "RTCVideoFrame+Private.h"
14
15 #include "webrtc/api/video/i420_buffer.h"
16 #include "webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h"
17
18 namespace webrtc {
19
20 ObjcVideoTrackSource::ObjcVideoTrackSource() {}
21
22 void ObjcVideoTrackSource::OnOutputFormatRequest(int width, int height, int fps) {
23 cricket::VideoFormat format(width, height, cricket::VideoFormat::FpsToInterval (fps), 0);
24 video_adapter()->OnOutputFormatRequest(format);
25 }
26
27 void ObjcVideoTrackSource::OnCapturedFrame(RTCVideoFrame* frame) {
28 const int64_t timestamp_us = frame.timeStampNs / rtc::kNumNanosecsPerMicrosec;
29 const int64_t translated_timestamp_us =
30 timestamp_aligner_.TranslateTimestamp(timestamp_us, rtc::TimeMicros());
31
32 int adapted_width;
33 int adapted_height;
34 int crop_width;
35 int crop_height;
36 int crop_x;
37 int crop_y;
38 if (!AdaptFrame(frame.width, frame.height, timestamp_us, &adapted_width, &adap ted_height,
39 &crop_width, &crop_height, &crop_x, &crop_y)) {
40 return;
41 }
42
43 rtc::scoped_refptr<VideoFrameBuffer> buffer;
44 if (adapted_width == frame.width && adapted_height == frame.height) {
45 // No adaption - optimized path.
46 buffer = frame.videoBuffer;
47 } else if (frame.nativeHandle) {
48 // Adapted CVPixelBuffer frame.
49 buffer = new rtc::RefCountedObject<CoreVideoFrameBuffer>(
50 static_cast<CVPixelBufferRef>(frame.nativeHandle), adapted_width, adapte d_height,
51 crop_width, crop_height, crop_x, crop_y);
52 } else {
53 // Adapted I420 frame.
54 // TODO(magjed): Optimize this I420 path.
55 rtc::scoped_refptr<I420Buffer> i420_buffer = I420Buffer::Create(adapted_widt h, adapted_height);
56 i420_buffer->CropAndScaleFrom(*frame.videoBuffer, crop_x, crop_y, crop_width , crop_height);
57 buffer = i420_buffer;
58 }
59
60 // Applying rotation is only supported for legacy reasons and performance is
61 // not critical here.
62 webrtc::VideoRotation rotation = static_cast<webrtc::VideoRotation>(frame.rota tion);
63 if (apply_rotation() && rotation != kVideoRotation_0) {
64 buffer = I420Buffer::Rotate(*buffer->NativeToI420Buffer(), rotation);
65 rotation = kVideoRotation_0;
66 }
67
68 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_timestamp_us));
69 }
70
71 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698