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