OLD | NEW |
| (Empty) |
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 | |
11 #import "RTCVideoFrame.h" | |
12 | |
13 #include "webrtc/base/scoped_ptr.h" | |
14 | |
15 #import "webrtc/api/objc/RTCVideoFrame+Private.h" | |
16 | |
17 @implementation RTCVideoFrame { | |
18 rtc::scoped_ptr<cricket::VideoFrame> _videoFrame; | |
19 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer; | |
20 } | |
21 | |
22 - (size_t)width { | |
23 return _videoFrame->width(); | |
24 } | |
25 | |
26 - (size_t)height { | |
27 return _videoFrame->height(); | |
28 } | |
29 | |
30 // TODO(nisse): chromaWidth and chromaHeight are used only in | |
31 // RTCOpenGLVideoRenderer.mm. Update, and then delete these | |
32 // properties. | |
33 - (size_t)chromaWidth { | |
34 return (self.width + 1) / 2; | |
35 } | |
36 | |
37 - (size_t)chromaHeight { | |
38 return (self.height + 1) / 2; | |
39 } | |
40 | |
41 - (const uint8_t *)yPlane { | |
42 if (!self.i420Buffer) { | |
43 return nullptr; | |
44 } | |
45 return self.i420Buffer->data(webrtc::kYPlane); | |
46 } | |
47 | |
48 - (const uint8_t *)uPlane { | |
49 if (!self.i420Buffer) { | |
50 return nullptr; | |
51 } | |
52 return self.i420Buffer->data(webrtc::kUPlane); | |
53 } | |
54 | |
55 - (const uint8_t *)vPlane { | |
56 if (!self.i420Buffer) { | |
57 return nullptr; | |
58 } | |
59 return self.i420Buffer->data(webrtc::kVPlane); | |
60 } | |
61 | |
62 - (int32_t)yPitch { | |
63 if (!self.i420Buffer) { | |
64 return 0; | |
65 } | |
66 return self.i420Buffer->stride(webrtc::kYPlane); | |
67 } | |
68 | |
69 - (int32_t)uPitch { | |
70 if (!self.i420Buffer) { | |
71 return 0; | |
72 } | |
73 return self.i420Buffer->stride(webrtc::kUPlane); | |
74 } | |
75 | |
76 - (int32_t)vPitch { | |
77 if (!self.i420Buffer) { | |
78 return 0; | |
79 } | |
80 return self.i420Buffer->stride(webrtc::kVPlane); | |
81 } | |
82 | |
83 - (int64_t)timeStamp { | |
84 return _videoFrame->GetTimeStamp(); | |
85 } | |
86 | |
87 - (CVPixelBufferRef)nativeHandle { | |
88 return static_cast<CVPixelBufferRef>(_videoFrame->GetNativeHandle()); | |
89 } | |
90 | |
91 - (void)convertBufferIfNeeded { | |
92 if (!_i420Buffer) { | |
93 if (_videoFrame->GetNativeHandle()) { | |
94 // Convert to I420. | |
95 _i420Buffer = _videoFrame->video_frame_buffer()->NativeToI420Buffer(); | |
96 } else { | |
97 // Should already be I420. | |
98 _i420Buffer = _videoFrame->video_frame_buffer(); | |
99 } | |
100 } | |
101 } | |
102 | |
103 #pragma mark - Private | |
104 | |
105 - (instancetype)initWithNativeFrame:(const cricket::VideoFrame *)nativeFrame { | |
106 if (self = [super init]) { | |
107 // Keep a shallow copy of the video frame. The underlying frame buffer is | |
108 // not copied. | |
109 _videoFrame.reset(nativeFrame->Copy()); | |
110 } | |
111 return self; | |
112 } | |
113 | |
114 - (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer { | |
115 [self convertBufferIfNeeded]; | |
116 return _i420Buffer; | |
117 } | |
118 | |
119 @end | |
OLD | NEW |