blob: d590a5f7fc394b137d81fd9daa561d78f706befa [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 <AVFoundation/AVFoundation.h>
12#import <WebRTC/RTCMacros.h>
13
14NS_ASSUME_NONNULL_BEGIN
15
16@protocol RTCI420Buffer;
17
18// RTCVideoFrameBuffer is an ObjectiveC version of webrtc::VideoFrameBuffer.
19RTC_EXPORT
20@protocol RTCVideoFrameBuffer <NSObject>
21
22@property(nonatomic, readonly) int width;
23@property(nonatomic, readonly) int height;
24
25- (id<RTCI420Buffer>)toI420;
26
27@end
28
29/** Protocol for RTCVideoFrameBuffers containing YUV planar data. */
30@protocol RTCYUVPlanarBuffer <RTCVideoFrameBuffer>
31
32@property(nonatomic, readonly) int chromaWidth;
33@property(nonatomic, readonly) int chromaHeight;
34@property(nonatomic, readonly) const uint8_t *dataY;
35@property(nonatomic, readonly) const uint8_t *dataU;
36@property(nonatomic, readonly) const uint8_t *dataV;
37@property(nonatomic, readonly) int strideY;
38@property(nonatomic, readonly) int strideU;
39@property(nonatomic, readonly) int strideV;
40
Piotr (Peter) Slatala0b71c292018-04-18 12:42:30 -070041- (instancetype)initWithWidth:(int)width
42 height:(int)height
43 dataY:(const uint8_t *)dataY
44 dataU:(const uint8_t *)dataU
45 dataV:(const uint8_t *)dataV;
Anders Carlssone5960ce2017-06-22 15:26:30 +020046- (instancetype)initWithWidth:(int)width height:(int)height;
47- (instancetype)initWithWidth:(int)width
48 height:(int)height
49 strideY:(int)strideY
50 strideU:(int)strideU
51 strideV:(int)strideV;
52
53@end
54
55/** Extension of the YUV planar data buffer with mutable data access */
56@protocol RTCMutableYUVPlanarBuffer <RTCYUVPlanarBuffer>
57
58@property(nonatomic, readonly) uint8_t *mutableDataY;
59@property(nonatomic, readonly) uint8_t *mutableDataU;
60@property(nonatomic, readonly) uint8_t *mutableDataV;
61
62@end
63
64/** Protocol for RTCYUVPlanarBuffers containing I420 data */
65@protocol RTCI420Buffer <RTCYUVPlanarBuffer>
66@end
67
68/** Extension of the I420 buffer with mutable data access */
69@protocol RTCMutableI420Buffer <RTCI420Buffer, RTCMutableYUVPlanarBuffer>
70@end
71
72/** RTCVideoFrameBuffer containing a CVPixelBufferRef */
VladimirTechMan26afe212017-06-29 09:11:10 -070073RTC_EXPORT
Anders Carlssone5960ce2017-06-22 15:26:30 +020074@interface RTCCVPixelBuffer : NSObject <RTCVideoFrameBuffer>
75
76@property(nonatomic, readonly) CVPixelBufferRef pixelBuffer;
andersc151aa6b2017-08-25 01:33:18 -070077@property(nonatomic, readonly) int cropX;
78@property(nonatomic, readonly) int cropY;
Anders Carlssonfe9d8172018-04-03 11:40:39 +020079@property(nonatomic, readonly) int cropWidth;
80@property(nonatomic, readonly) int cropHeight;
Anders Carlssone5960ce2017-06-22 15:26:30 +020081
Anders Carlssonf3ee3b72017-10-23 15:23:00 +020082+ (NSSet<NSNumber *> *)supportedPixelFormats;
83
Anders Carlssone5960ce2017-06-22 15:26:30 +020084- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer;
85- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
86 adaptedWidth:(int)adaptedWidth
87 adaptedHeight:(int)adaptedHeight
88 cropWidth:(int)cropWidth
89 cropHeight:(int)cropHeight
90 cropX:(int)cropX
91 cropY:(int)cropY;
92
93- (BOOL)requiresCropping;
94- (BOOL)requiresScalingToWidth:(int)width height:(int)height;
95- (int)bufferSizeForCroppingAndScalingToWidth:(int)width height:(int)height;
Anders Carlssonfe9d8172018-04-03 11:40:39 +020096
Anders Carlssone5960ce2017-06-22 15:26:30 +020097/** The minimum size of the |tmpBuffer| must be the number of bytes returned from the
98 * bufferSizeForCroppingAndScalingToWidth:height: method.
Anders Carlssonfe9d8172018-04-03 11:40:39 +020099 * If that size is 0, the |tmpBuffer| may be nil.
Anders Carlssone5960ce2017-06-22 15:26:30 +0200100 */
Anders Carlssonfe9d8172018-04-03 11:40:39 +0200101- (BOOL)cropAndScaleTo:(CVPixelBufferRef)outputPixelBuffer
102 withTempBuffer:(nullable uint8_t *)tmpBuffer;
Anders Carlssone5960ce2017-06-22 15:26:30 +0200103
104@end
105
106/** RTCI420Buffer implements the RTCI420Buffer protocol */
VladimirTechMan26afe212017-06-29 09:11:10 -0700107RTC_EXPORT
Anders Carlssone5960ce2017-06-22 15:26:30 +0200108@interface RTCI420Buffer : NSObject <RTCI420Buffer>
109@end
110
111/** Mutable version of RTCI420Buffer */
VladimirTechMan26afe212017-06-29 09:11:10 -0700112RTC_EXPORT
Anders Carlssone5960ce2017-06-22 15:26:30 +0200113@interface RTCMutableI420Buffer : RTCI420Buffer <RTCMutableI420Buffer>
114@end
115
116NS_ASSUME_NONNULL_END