Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | NS_ASSUME_NONNULL_BEGIN |
| 15 | |
| 16 | @protocol RTCI420Buffer; |
| 17 | |
| 18 | // RTCVideoFrameBuffer is an ObjectiveC version of webrtc::VideoFrameBuffer. |
| 19 | RTC_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 | |
| 41 | - (instancetype)initWithWidth:(int)width height:(int)height; |
| 42 | - (instancetype)initWithWidth:(int)width |
| 43 | height:(int)height |
| 44 | strideY:(int)strideY |
| 45 | strideU:(int)strideU |
| 46 | strideV:(int)strideV; |
| 47 | |
| 48 | @end |
| 49 | |
| 50 | /** Extension of the YUV planar data buffer with mutable data access */ |
| 51 | @protocol RTCMutableYUVPlanarBuffer <RTCYUVPlanarBuffer> |
| 52 | |
| 53 | @property(nonatomic, readonly) uint8_t *mutableDataY; |
| 54 | @property(nonatomic, readonly) uint8_t *mutableDataU; |
| 55 | @property(nonatomic, readonly) uint8_t *mutableDataV; |
| 56 | |
| 57 | @end |
| 58 | |
| 59 | /** Protocol for RTCYUVPlanarBuffers containing I420 data */ |
| 60 | @protocol RTCI420Buffer <RTCYUVPlanarBuffer> |
| 61 | @end |
| 62 | |
| 63 | /** Extension of the I420 buffer with mutable data access */ |
| 64 | @protocol RTCMutableI420Buffer <RTCI420Buffer, RTCMutableYUVPlanarBuffer> |
| 65 | @end |
| 66 | |
| 67 | /** RTCVideoFrameBuffer containing a CVPixelBufferRef */ |
VladimirTechMan | 26afe21 | 2017-06-29 09:11:10 -0700 | [diff] [blame] | 68 | RTC_EXPORT |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 69 | @interface RTCCVPixelBuffer : NSObject <RTCVideoFrameBuffer> |
| 70 | |
| 71 | @property(nonatomic, readonly) CVPixelBufferRef pixelBuffer; |
andersc | 151aa6b | 2017-08-25 01:33:18 -0700 | [diff] [blame] | 72 | @property(nonatomic, readonly) int cropX; |
| 73 | @property(nonatomic, readonly) int cropY; |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 74 | |
| 75 | - (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer; |
| 76 | - (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer |
| 77 | adaptedWidth:(int)adaptedWidth |
| 78 | adaptedHeight:(int)adaptedHeight |
| 79 | cropWidth:(int)cropWidth |
| 80 | cropHeight:(int)cropHeight |
| 81 | cropX:(int)cropX |
| 82 | cropY:(int)cropY; |
| 83 | |
| 84 | - (BOOL)requiresCropping; |
| 85 | - (BOOL)requiresScalingToWidth:(int)width height:(int)height; |
| 86 | - (int)bufferSizeForCroppingAndScalingToWidth:(int)width height:(int)height; |
| 87 | /** The minimum size of the |tmpBuffer| must be the number of bytes returned from the |
| 88 | * bufferSizeForCroppingAndScalingToWidth:height: method. |
| 89 | */ |
| 90 | - (BOOL)cropAndScaleTo:(CVPixelBufferRef)outputPixelBuffer withTempBuffer:(uint8_t *)tmpBuffer; |
| 91 | |
| 92 | @end |
| 93 | |
| 94 | /** RTCI420Buffer implements the RTCI420Buffer protocol */ |
VladimirTechMan | 26afe21 | 2017-06-29 09:11:10 -0700 | [diff] [blame] | 95 | RTC_EXPORT |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 96 | @interface RTCI420Buffer : NSObject <RTCI420Buffer> |
| 97 | @end |
| 98 | |
| 99 | /** Mutable version of RTCI420Buffer */ |
VladimirTechMan | 26afe21 | 2017-06-29 09:11:10 -0700 | [diff] [blame] | 100 | RTC_EXPORT |
Anders Carlsson | e5960ce | 2017-06-22 15:26:30 +0200 | [diff] [blame] | 101 | @interface RTCMutableI420Buffer : RTCI420Buffer <RTCMutableI420Buffer> |
| 102 | @end |
| 103 | |
| 104 | NS_ASSUME_NONNULL_END |