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 | |||||
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCVideoFrame+Private.h" |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 12 | |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 13 | @implementation RTCVideoFrame { |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 14 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer; |
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 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 19 | - (int)width { |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 20 | return _videoBuffer->width(); |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 21 | } |
22 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 23 | - (int)height { |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 24 | return _videoBuffer->height(); |
25 | } | ||||
26 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 27 | - (RTCVideoRotation)rotation { |
28 | return _rotation; | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 29 | } |
30 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 31 | - (const uint8_t *)dataY { |
32 | return _videoBuffer->DataY(); | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 33 | } |
34 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 35 | - (const uint8_t *)dataU { |
36 | return _videoBuffer->DataU(); | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 37 | } |
38 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 39 | - (const uint8_t *)dataV { |
40 | return _videoBuffer->DataV(); | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 41 | } |
42 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 43 | - (int)strideY { |
44 | return _videoBuffer->StrideY(); | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 45 | } |
46 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 47 | - (int)strideU { |
48 | return _videoBuffer->StrideU(); | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 49 | } |
50 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 51 | - (int)strideV { |
52 | return _videoBuffer->StrideV(); | ||||
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 53 | } |
54 | |||||
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 55 | - (int64_t)timeStampNs { |
56 | return _timeStampNs; | ||||
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 57 | } |
58 | |||||
59 | - (CVPixelBufferRef)nativeHandle { | ||||
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 60 | return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle()); |
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 61 | } |
62 | |||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 63 | - (RTCVideoFrame *)newI420VideoFrame { |
64 | return [[RTCVideoFrame alloc] | ||||
65 | initWithVideoBuffer:_videoBuffer->NativeToI420Buffer() | ||||
66 | rotation:_rotation | ||||
67 | timeStampNs:_timeStampNs]; | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 68 | } |
69 | |||||
70 | #pragma mark - Private | ||||
71 | |||||
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 72 | - (instancetype)initWithVideoBuffer: |
73 | (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer | ||||
magjed | 7ee5125 | 2017-02-21 04:19:46 -0800 | [diff] [blame^] | 74 | rotation:(RTCVideoRotation)rotation |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 75 | timeStampNs:(int64_t)timeStampNs { |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 76 | if (self = [super init]) { |
magjed | fb372f0 | 2016-08-10 07:58:29 -0700 | [diff] [blame] | 77 | _videoBuffer = videoBuffer; |
78 | _rotation = rotation; | ||||
79 | _timeStampNs = timeStampNs; | ||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 80 | } |
81 | return self; | ||||
82 | } | ||||
83 | |||||
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 84 | @end |