blob: 9a5d3065d69d5754f6f0561ede712b0be974a9a9 [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"
Anders Carlsson9823ee42018-03-07 10:32:03 +010012
anderscf9f448b2017-08-17 02:31:55 -070013#import "WebRTC/RTCVideoFrameBuffer.h"
magjedc3c46242017-02-21 05:28:48 -080014
Jon Hjelle78234952016-01-11 09:47:07 -080015@implementation RTCVideoFrame {
magjed7ee51252017-02-21 04:19:46 -080016 RTCVideoRotation _rotation;
magjedfb372f02016-08-10 07:58:29 -070017 int64_t _timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -080018}
19
Anders Carlssone5960ce2017-06-22 15:26:30 +020020@synthesize buffer = _buffer;
kthelgasonfb143122017-07-25 07:55:58 -070021@synthesize timeStamp;
Anders Carlssone5960ce2017-06-22 15:26:30 +020022
magjed7ee51252017-02-21 04:19:46 -080023- (int)width {
Anders Carlssone5960ce2017-06-22 15:26:30 +020024 return _buffer.width;
Jon Hjelle78234952016-01-11 09:47:07 -080025}
26
magjed7ee51252017-02-21 04:19:46 -080027- (int)height {
Anders Carlssone5960ce2017-06-22 15:26:30 +020028 return _buffer.height;
magjedfb372f02016-08-10 07:58:29 -070029}
30
magjed7ee51252017-02-21 04:19:46 -080031- (RTCVideoRotation)rotation {
32 return _rotation;
Jon Hjelle78234952016-01-11 09:47:07 -080033}
34
magjedfb372f02016-08-10 07:58:29 -070035- (int64_t)timeStampNs {
36 return _timeStampNs;
tkchin7d06a8c2016-04-04 14:10:43 -070037}
38
magjed7ee51252017-02-21 04:19:46 -080039- (RTCVideoFrame *)newI420VideoFrame {
Anders Carlssone5960ce2017-06-22 15:26:30 +020040 return [[RTCVideoFrame alloc] initWithBuffer:[_buffer toI420]
41 rotation:_rotation
42 timeStampNs:_timeStampNs];
Jon Hjelle78234952016-01-11 09:47:07 -080043}
44
magjedc3c46242017-02-21 05:28:48 -080045- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
46 rotation:(RTCVideoRotation)rotation
47 timeStampNs:(int64_t)timeStampNs {
Anders Carlssone5960ce2017-06-22 15:26:30 +020048 return [self initWithBuffer:[[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer]
49 rotation:rotation
50 timeStampNs:timeStampNs];
magjedc3c46242017-02-21 05:28:48 -080051}
52
53- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
54 scaledWidth:(int)scaledWidth
55 scaledHeight:(int)scaledHeight
56 cropWidth:(int)cropWidth
57 cropHeight:(int)cropHeight
58 cropX:(int)cropX
59 cropY:(int)cropY
60 rotation:(RTCVideoRotation)rotation
61 timeStampNs:(int64_t)timeStampNs {
Anders Carlssone5960ce2017-06-22 15:26:30 +020062 RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer
63 adaptedWidth:scaledWidth
64 adaptedHeight:scaledHeight
65 cropWidth:cropWidth
66 cropHeight:cropHeight
67 cropX:cropX
68 cropY:cropY];
69 return [self initWithBuffer:rtcPixelBuffer rotation:rotation timeStampNs:timeStampNs];
magjedc3c46242017-02-21 05:28:48 -080070}
71
Anders Carlssone5960ce2017-06-22 15:26:30 +020072- (instancetype)initWithBuffer:(id<RTCVideoFrameBuffer>)buffer
73 rotation:(RTCVideoRotation)rotation
74 timeStampNs:(int64_t)timeStampNs {
Jon Hjelle78234952016-01-11 09:47:07 -080075 if (self = [super init]) {
Anders Carlssone5960ce2017-06-22 15:26:30 +020076 _buffer = buffer;
magjedfb372f02016-08-10 07:58:29 -070077 _rotation = rotation;
78 _timeStampNs = timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -080079 }
Anders Carlsson0789dab2017-06-21 08:41:26 +000080
Anders Carlssone5960ce2017-06-22 15:26:30 +020081 return self;
Anders Carlsson1cfeb432017-06-22 13:06:39 +000082}
83
Jon Hjelle78234952016-01-11 09:47:07 -080084@end