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