Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
andersc | f9f448b | 2017-08-17 02:31:55 -0700 | [diff] [blame] | 11 | #import "WebRTC/RTCVideoFrame.h" |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 12 | |
andersc | f9f448b | 2017-08-17 02:31:55 -0700 | [diff] [blame] | 13 | #import "WebRTC/RTCVideoFrameBuffer.h" |
magjed | c3c4624 | 2017-02-21 05:28:48 -0800 | [diff] [blame] | 14 | |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 15 | @implementation RTCVideoFrame { |
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame] | 16 | RTCVideoRotation _rotation; |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 17 | int64_t _timeStampNs; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 18 | } |
| 19 | |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 20 | @synthesize buffer = _buffer; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 21 | @synthesize timeStamp; |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 22 | |
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame] | 23 | - (int)width { |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 24 | return _buffer.width; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 25 | } |
| 26 | |
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame] | 27 | - (int)height { |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 28 | return _buffer.height; |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 29 | } |
| 30 | |
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame] | 31 | - (RTCVideoRotation)rotation { |
| 32 | return _rotation; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 33 | } |
| 34 | |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 35 | - (int64_t)timeStampNs { |
| 36 | return _timeStampNs; |
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 37 | } |
| 38 | |
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame] | 39 | - (RTCVideoFrame *)newI420VideoFrame { |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 40 | return [[RTCVideoFrame alloc] initWithBuffer:[_buffer toI420] |
| 41 | rotation:_rotation |
| 42 | timeStampNs:_timeStampNs]; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 43 | } |
| 44 | |
magjed | c3c4624 | 2017-02-21 05:28:48 -0800 | [diff] [blame] | 45 | - (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer |
| 46 | rotation:(RTCVideoRotation)rotation |
| 47 | timeStampNs:(int64_t)timeStampNs { |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 48 | return [self initWithBuffer:[[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer] |
| 49 | rotation:rotation |
| 50 | timeStampNs:timeStampNs]; |
magjed | c3c4624 | 2017-02-21 05:28:48 -0800 | [diff] [blame] | 51 | } |
| 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 Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 62 | 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]; |
magjed | c3c4624 | 2017-02-21 05:28:48 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 72 | - (instancetype)initWithBuffer:(id<RTCVideoFrameBuffer>)buffer |
| 73 | rotation:(RTCVideoRotation)rotation |
| 74 | timeStampNs:(int64_t)timeStampNs { |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 75 | if (self = [super init]) { |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 76 | _buffer = buffer; |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 77 | _rotation = rotation; |
| 78 | _timeStampNs = timeStampNs; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 79 | } |
Anders Carlsson | 0789dab | 2017-06-21 08:41:26 +0000 | [diff] [blame] | 80 | |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 81 | return self; |
Anders Carlsson | 1cfeb43 | 2017-06-22 13:06:39 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 84 | @end |