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

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

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

Powered by Google App Engine
This is Rietveld 408576698