OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCVideoFrame+Private.h" | 11 #import "RTCVideoFrame+Private.h" |
12 | 12 |
13 #include <memory> | |
14 | |
15 #include "webrtc/api/video/video_rotation.h" | |
16 | |
17 @implementation RTCVideoFrame { | 13 @implementation RTCVideoFrame { |
18 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer; | 14 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer; |
19 webrtc::VideoRotation _rotation; | 15 RTCVideoRotation _rotation; |
20 int64_t _timeStampNs; | 16 int64_t _timeStampNs; |
21 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer; | |
22 } | 17 } |
23 | 18 |
24 - (size_t)width { | 19 - (int)width { |
25 return _videoBuffer->width(); | 20 return _videoBuffer->width(); |
26 } | 21 } |
27 | 22 |
28 - (size_t)height { | 23 - (int)height { |
29 return _videoBuffer->height(); | 24 return _videoBuffer->height(); |
30 } | 25 } |
31 | 26 |
32 - (int)rotation { | 27 - (RTCVideoRotation)rotation { |
33 return static_cast<int>(_rotation); | 28 return _rotation; |
34 } | 29 } |
35 | 30 |
36 // TODO(nisse): chromaWidth and chromaHeight are used only in | 31 - (const uint8_t *)dataY { |
37 // RTCOpenGLVideoRenderer.mm. Update, and then delete these | 32 return _videoBuffer->DataY(); |
38 // properties. | |
39 - (size_t)chromaWidth { | |
40 return (self.width + 1) / 2; | |
41 } | 33 } |
42 | 34 |
43 - (size_t)chromaHeight { | 35 - (const uint8_t *)dataU { |
44 return (self.height + 1) / 2; | 36 return _videoBuffer->DataU(); |
45 } | 37 } |
46 | 38 |
47 - (const uint8_t *)yPlane { | 39 - (const uint8_t *)dataV { |
48 if (!self.i420Buffer) { | 40 return _videoBuffer->DataV(); |
49 return nullptr; | |
50 } | |
51 return self.i420Buffer->DataY(); | |
52 } | 41 } |
53 | 42 |
54 - (const uint8_t *)uPlane { | 43 - (int)strideY { |
55 if (!self.i420Buffer) { | 44 return _videoBuffer->StrideY(); |
56 return nullptr; | |
57 } | |
58 return self.i420Buffer->DataU(); | |
59 } | 45 } |
60 | 46 |
61 - (const uint8_t *)vPlane { | 47 - (int)strideU { |
62 if (!self.i420Buffer) { | 48 return _videoBuffer->StrideU(); |
63 return nullptr; | |
64 } | |
65 return self.i420Buffer->DataV(); | |
66 } | 49 } |
67 | 50 |
68 - (int32_t)yPitch { | 51 - (int)strideV { |
69 if (!self.i420Buffer) { | 52 return _videoBuffer->StrideV(); |
70 return 0; | |
71 } | |
72 return self.i420Buffer->StrideY(); | |
73 } | |
74 | |
75 - (int32_t)uPitch { | |
76 if (!self.i420Buffer) { | |
77 return 0; | |
78 } | |
79 return self.i420Buffer->StrideU(); | |
80 } | |
81 | |
82 - (int32_t)vPitch { | |
83 if (!self.i420Buffer) { | |
84 return 0; | |
85 } | |
86 return self.i420Buffer->StrideV(); | |
87 } | 53 } |
88 | 54 |
89 - (int64_t)timeStampNs { | 55 - (int64_t)timeStampNs { |
90 return _timeStampNs; | 56 return _timeStampNs; |
91 } | 57 } |
92 | 58 |
93 - (CVPixelBufferRef)nativeHandle { | 59 - (CVPixelBufferRef)nativeHandle { |
94 return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle()); | 60 return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle()); |
95 } | 61 } |
96 | 62 |
97 - (void)convertBufferIfNeeded { | 63 - (RTCVideoFrame *)newI420VideoFrame { |
98 if (!_i420Buffer) { | 64 return [[RTCVideoFrame alloc] |
99 _i420Buffer = _videoBuffer->native_handle() | 65 initWithVideoBuffer:_videoBuffer->NativeToI420Buffer() |
100 ? _videoBuffer->NativeToI420Buffer() | 66 rotation:_rotation |
101 : _videoBuffer; | 67 timeStampNs:_timeStampNs]; |
102 } | |
103 } | 68 } |
104 | 69 |
105 #pragma mark - Private | 70 #pragma mark - Private |
106 | 71 |
107 - (instancetype)initWithVideoBuffer: | 72 - (instancetype)initWithVideoBuffer: |
108 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer | 73 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer |
109 rotation:(webrtc::VideoRotation)rotation | 74 rotation:(RTCVideoRotation)rotation |
110 timeStampNs:(int64_t)timeStampNs { | 75 timeStampNs:(int64_t)timeStampNs { |
111 if (self = [super init]) { | 76 if (self = [super init]) { |
112 _videoBuffer = videoBuffer; | 77 _videoBuffer = videoBuffer; |
113 _rotation = rotation; | 78 _rotation = rotation; |
114 _timeStampNs = timeStampNs; | 79 _timeStampNs = timeStampNs; |
115 } | 80 } |
116 return self; | 81 return self; |
117 } | 82 } |
118 | 83 |
119 - (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer { | |
120 [self convertBufferIfNeeded]; | |
121 return _i420Buffer; | |
122 } | |
123 | |
124 @end | 84 @end |
OLD | NEW |