Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm

Issue 2695203004: Clean up RTCVideoFrame (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 int _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 - (int)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*)convertToI420 {
daniela-webrtc 2017/02/17 16:26:34 This method might not be safe from memory manageme
daniela-webrtc 2017/02/20 12:17:27 Ok, I've done bit more thinking about this. I thin
magjed_webrtc 2017/02/20 16:16:44 Done.
98 if (!_i420Buffer) { 64 if (!_videoBuffer->native_handle())
99 _i420Buffer = _videoBuffer->native_handle() 65 return self;
100 ? _videoBuffer->NativeToI420Buffer() 66 return [[RTCVideoFrame alloc]
101 : _videoBuffer; 67 initWithVideoBuffer:_videoBuffer->NativeToI420Buffer()
102 } 68 rotation:_rotation
69 timeStampNs:_timeStampNs];
103 } 70 }
104 71
105 #pragma mark - Private 72 #pragma mark - Private
106 73
107 - (instancetype)initWithVideoBuffer: 74 - (instancetype)initWithVideoBuffer:
108 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer 75 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer
109 rotation:(webrtc::VideoRotation)rotation 76 rotation:(int)rotation
110 timeStampNs:(int64_t)timeStampNs { 77 timeStampNs:(int64_t)timeStampNs {
111 if (self = [super init]) { 78 if (self = [super init]) {
112 _videoBuffer = videoBuffer; 79 _videoBuffer = videoBuffer;
113 _rotation = rotation; 80 _rotation = rotation;
114 _timeStampNs = timeStampNs; 81 _timeStampNs = timeStampNs;
115 } 82 }
116 return self; 83 return self;
117 } 84 }
118 85
119 - (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer {
120 [self convertBufferIfNeeded];
121 return _i420Buffer;
122 }
123
124 @end 86 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698