blob: a428a8d6cbb915dac61b5df2cb12a33c70a0ded3 [file] [log] [blame]
Anders Carlssone5960ce2017-06-22 15:26:30 +02001/*
2 * Copyright 2017 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 "WebRTC/RTCVideoFrameBuffer.h"
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "api/video/i420_buffer.h"
Anders Carlssone5960ce2017-06-22 15:26:30 +020014
15@implementation RTCI420Buffer {
16 @protected
17 rtc::scoped_refptr<webrtc::I420BufferInterface> _i420Buffer;
18}
19
20- (instancetype)initWithWidth:(int)width height:(int)height {
21 if (self = [super init]) {
22 _i420Buffer = webrtc::I420Buffer::Create(width, height);
23 }
24
25 return self;
26}
27
28- (instancetype)initWithWidth:(int)width
29 height:(int)height
30 strideY:(int)strideY
31 strideU:(int)strideU
32 strideV:(int)strideV {
33 if (self = [super init]) {
34 _i420Buffer = webrtc::I420Buffer::Create(width, height, strideY, strideU, strideV);
35 }
36
37 return self;
38}
39
40- (instancetype)initWithFrameBuffer:(rtc::scoped_refptr<webrtc::I420BufferInterface>)i420Buffer {
41 if (self = [super init]) {
42 _i420Buffer = i420Buffer;
43 }
44
45 return self;
46}
47
48- (int)width {
49 return _i420Buffer->width();
50}
51
52- (int)height {
53 return _i420Buffer->height();
54}
55
56- (int)strideY {
57 return _i420Buffer->StrideY();
58}
59
60- (int)strideU {
61 return _i420Buffer->StrideU();
62}
63
64- (int)strideV {
65 return _i420Buffer->StrideV();
66}
67
68- (int)chromaWidth {
69 return _i420Buffer->ChromaWidth();
70}
71
72- (int)chromaHeight {
73 return _i420Buffer->ChromaHeight();
74}
75
76- (const uint8_t *)dataY {
77 return _i420Buffer->DataY();
78}
79
80- (const uint8_t *)dataU {
81 return _i420Buffer->DataU();
82}
83
84- (const uint8_t *)dataV {
85 return _i420Buffer->DataV();
86}
87
88- (id<RTCI420Buffer>)toI420 {
89 return self;
90}
91
Anders Carlssone5960ce2017-06-22 15:26:30 +020092@end
93
94@implementation RTCMutableI420Buffer
95
96- (uint8_t *)mutableDataY {
97 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataY();
98}
99
100- (uint8_t *)mutableDataU {
101 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataU();
102}
103
104- (uint8_t *)mutableDataV {
105 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataV();
106}
107
108@end