blob: 2848f2b45e231dfb1c3e719a4dc4be251f56d99b [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 Carlssonfe9d8172018-04-03 11:40:39 +020092- (rtc::scoped_refptr<webrtc::I420BufferInterface>)nativeI420Buffer {
93 return _i420Buffer;
94}
95
Anders Carlssone5960ce2017-06-22 15:26:30 +020096@end
97
98@implementation RTCMutableI420Buffer
99
100- (uint8_t *)mutableDataY {
101 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataY();
102}
103
104- (uint8_t *)mutableDataU {
105 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataU();
106}
107
108- (uint8_t *)mutableDataV {
109 return static_cast<webrtc::I420Buffer *>(_i420Buffer.get())->MutableDataV();
110}
111
112@end