blob: cf4216e8258cf6a49f1a9d79433dfdc563d32b85 [file] [log] [blame]
Jon Hjelle78234952016-01-11 09:47:07 -08001/*
2 * Copyright 2015 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
anderscf9f448b2017-08-17 02:31:55 -070011#import "WebRTC/RTCVideoFrame.h"
12#import "WebRTC/RTCVideoFrameBuffer.h"
magjedc3c46242017-02-21 05:28:48 -080013
Jon Hjelle78234952016-01-11 09:47:07 -080014@implementation RTCVideoFrame {
magjed7ee51252017-02-21 04:19:46 -080015 RTCVideoRotation _rotation;
magjedfb372f02016-08-10 07:58:29 -070016 int64_t _timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -080017}
18
Anders Carlssone5960ce2017-06-22 15:26:30 +020019@synthesize buffer = _buffer;
kthelgasonfb143122017-07-25 07:55:58 -070020@synthesize timeStamp;
Anders Carlssone5960ce2017-06-22 15:26:30 +020021
magjed7ee51252017-02-21 04:19:46 -080022- (int)width {
Anders Carlssone5960ce2017-06-22 15:26:30 +020023 return _buffer.width;
Jon Hjelle78234952016-01-11 09:47:07 -080024}
25
magjed7ee51252017-02-21 04:19:46 -080026- (int)height {
Anders Carlssone5960ce2017-06-22 15:26:30 +020027 return _buffer.height;
magjedfb372f02016-08-10 07:58:29 -070028}
29
magjed7ee51252017-02-21 04:19:46 -080030- (RTCVideoRotation)rotation {
31 return _rotation;
Jon Hjelle78234952016-01-11 09:47:07 -080032}
33
magjedfb372f02016-08-10 07:58:29 -070034- (int64_t)timeStampNs {
35 return _timeStampNs;
tkchin7d06a8c2016-04-04 14:10:43 -070036}
37
magjed7ee51252017-02-21 04:19:46 -080038- (RTCVideoFrame *)newI420VideoFrame {
Anders Carlssone5960ce2017-06-22 15:26:30 +020039 return [[RTCVideoFrame alloc] initWithBuffer:[_buffer toI420]
40 rotation:_rotation
41 timeStampNs:_timeStampNs];
Jon Hjelle78234952016-01-11 09:47:07 -080042}
43
magjedc3c46242017-02-21 05:28:48 -080044- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
45 rotation:(RTCVideoRotation)rotation
46 timeStampNs:(int64_t)timeStampNs {
Anders Carlssone5960ce2017-06-22 15:26:30 +020047 return [self initWithBuffer:[[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer]
48 rotation:rotation
49 timeStampNs:timeStampNs];
magjedc3c46242017-02-21 05:28:48 -080050}
51
52- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
53 scaledWidth:(int)scaledWidth
54 scaledHeight:(int)scaledHeight
55 cropWidth:(int)cropWidth
56 cropHeight:(int)cropHeight
57 cropX:(int)cropX
58 cropY:(int)cropY
59 rotation:(RTCVideoRotation)rotation
60 timeStampNs:(int64_t)timeStampNs {
Anders Carlssone5960ce2017-06-22 15:26:30 +020061 RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer
62 adaptedWidth:scaledWidth
63 adaptedHeight:scaledHeight
64 cropWidth:cropWidth
65 cropHeight:cropHeight
66 cropX:cropX
67 cropY:cropY];
68 return [self initWithBuffer:rtcPixelBuffer rotation:rotation timeStampNs:timeStampNs];
magjedc3c46242017-02-21 05:28:48 -080069}
70
Anders Carlssone5960ce2017-06-22 15:26:30 +020071- (instancetype)initWithBuffer:(id<RTCVideoFrameBuffer>)buffer
72 rotation:(RTCVideoRotation)rotation
73 timeStampNs:(int64_t)timeStampNs {
Jon Hjelle78234952016-01-11 09:47:07 -080074 if (self = [super init]) {
Anders Carlssone5960ce2017-06-22 15:26:30 +020075 _buffer = buffer;
magjedfb372f02016-08-10 07:58:29 -070076 _rotation = rotation;
77 _timeStampNs = timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -080078 }
Anders Carlsson0789dab2017-06-21 08:41:26 +000079
Anders Carlssone5960ce2017-06-22 15:26:30 +020080 return self;
Anders Carlsson1cfeb432017-06-22 13:06:39 +000081}
82
Jon Hjelle78234952016-01-11 09:47:07 -080083@end