kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [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 <Foundation/Foundation.h> |
| 12 | |
| 13 | #import <WebRTC/RTCMacros.h> |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 14 | #import <WebRTC/RTCVideoFrame.h> |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 15 | |
| 16 | NS_ASSUME_NONNULL_BEGIN |
| 17 | |
| 18 | /** Represents an encoded frame's type. */ |
| 19 | typedef NS_ENUM(NSUInteger, RTCFrameType) { |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 20 | RTCFrameTypeEmptyFrame = 0, |
| 21 | RTCFrameTypeAudioFrameSpeech = 1, |
| 22 | RTCFrameTypeAudioFrameCN = 2, |
| 23 | RTCFrameTypeVideoFrameKey = 3, |
| 24 | RTCFrameTypeVideoFrameDelta = 4, |
| 25 | }; |
| 26 | |
| 27 | typedef NS_ENUM(NSUInteger, RTCVideoContentType) { |
| 28 | RTCVideoContentTypeUnspecified, |
| 29 | RTCVideoContentTypeScreenshare, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | /** Represents an encoded frame. Corresponds to webrtc::EncodedImage. */ |
| 33 | RTC_EXPORT |
| 34 | @interface RTCEncodedImage : NSObject |
| 35 | |
| 36 | @property(nonatomic, strong) NSData *buffer; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 37 | @property(nonatomic, assign) int32_t encodedWidth; |
| 38 | @property(nonatomic, assign) int32_t encodedHeight; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 39 | @property(nonatomic, assign) uint32_t timeStamp; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 40 | @property(nonatomic, assign) int64_t captureTimeMs; |
| 41 | @property(nonatomic, assign) int64_t ntpTimeMs; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 42 | @property(nonatomic, assign) uint8_t flags; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 43 | @property(nonatomic, assign) int64_t encodeStartMs; |
| 44 | @property(nonatomic, assign) int64_t encodeFinishMs; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 45 | @property(nonatomic, assign) RTCFrameType frameType; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 46 | @property(nonatomic, assign) RTCVideoRotation rotation; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 47 | @property(nonatomic, assign) BOOL completeFrame; |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 48 | @property(nonatomic, strong) NSNumber *qp; |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 49 | @property(nonatomic, assign) RTCVideoContentType contentType; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 50 | |
| 51 | @end |
| 52 | |
| 53 | /** Information for header. Corresponds to webrtc::RTPFragmentationHeader. */ |
| 54 | RTC_EXPORT |
| 55 | @interface RTCRtpFragmentationHeader : NSObject |
| 56 | |
| 57 | @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationOffset; |
| 58 | @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationLength; |
| 59 | @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationTimeDiff; |
| 60 | @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationPlType; |
| 61 | |
| 62 | @end |
| 63 | |
| 64 | /** Implement this protocol to pass codec specific info from the encoder. |
| 65 | * Corresponds to webrtc::CodecSpecificInfo. |
| 66 | */ |
| 67 | RTC_EXPORT |
| 68 | @protocol RTCCodecSpecificInfo <NSObject> |
| 69 | |
| 70 | @end |
| 71 | |
| 72 | /** Callback block for encoder. */ |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 73 | typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame, |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 74 | id<RTCCodecSpecificInfo> info, |
| 75 | RTCRtpFragmentationHeader *header); |
| 76 | |
| 77 | /** Callback block for decoder. */ |
| 78 | typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame); |
| 79 | |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 80 | typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) { |
| 81 | RTCVideoCodecModeRealtimeVideo, |
| 82 | RTCVideoCodecModeScreensharing, |
| 83 | }; |
| 84 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 85 | /** Holds information to identify a codec. Corresponds to cricket::VideoCodec. */ |
| 86 | RTC_EXPORT |
| 87 | @interface RTCVideoCodecInfo : NSObject |
| 88 | |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 89 | - (instancetype)init NS_UNAVAILABLE; |
| 90 | |
Kári Tristan Helgason | e71f367 | 2017-10-02 14:59:59 +0200 | [diff] [blame] | 91 | - (instancetype)initWithName:(NSString *)name; |
| 92 | |
andersc | 81bc523 | 2017-08-18 06:34:09 -0700 | [diff] [blame] | 93 | - (instancetype)initWithName:(NSString *)name |
| 94 | parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters |
| 95 | NS_DESIGNATED_INITIALIZER; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 96 | |
Kári Tristan Helgason | 3935c34 | 2017-09-28 15:08:47 +0200 | [diff] [blame] | 97 | - (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info; |
| 98 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 99 | @property(nonatomic, readonly) NSString *name; |
| 100 | @property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *parameters; |
| 101 | |
| 102 | @end |
| 103 | |
| 104 | /** Settings for encoder. Corresponds to webrtc::VideoCodec. */ |
| 105 | RTC_EXPORT |
| 106 | @interface RTCVideoEncoderSettings : NSObject |
| 107 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 108 | @property(nonatomic, strong) NSString *name; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 109 | |
| 110 | @property(nonatomic, assign) unsigned short width; |
| 111 | @property(nonatomic, assign) unsigned short height; |
| 112 | |
| 113 | @property(nonatomic, assign) unsigned int startBitrate; // kilobits/sec. |
| 114 | @property(nonatomic, assign) unsigned int maxBitrate; |
| 115 | @property(nonatomic, assign) unsigned int minBitrate; |
| 116 | @property(nonatomic, assign) unsigned int targetBitrate; |
| 117 | |
| 118 | @property(nonatomic, assign) uint32_t maxFramerate; |
| 119 | |
| 120 | @property(nonatomic, assign) unsigned int qpMax; |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 121 | @property(nonatomic, assign) RTCVideoCodecMode mode; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 122 | |
| 123 | @end |
| 124 | |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 125 | /** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */ |
| 126 | RTC_EXPORT |
| 127 | @interface RTCVideoEncoderQpThresholds : NSObject |
| 128 | |
| 129 | - (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high; |
| 130 | |
| 131 | @property(nonatomic, readonly) NSInteger low; |
| 132 | @property(nonatomic, readonly) NSInteger high; |
| 133 | |
| 134 | @end |
| 135 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 136 | /** Protocol for encoder implementations. */ |
| 137 | RTC_EXPORT |
| 138 | @protocol RTCVideoEncoder <NSObject> |
| 139 | |
| 140 | - (void)setCallback:(RTCVideoEncoderCallback)callback; |
| 141 | - (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings |
| 142 | numberOfCores:(int)numberOfCores; |
| 143 | - (NSInteger)releaseEncoder; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 144 | - (NSInteger)encode:(RTCVideoFrame *)frame |
| 145 | codecSpecificInfo:(id<RTCCodecSpecificInfo>)info |
| 146 | frameTypes:(NSArray<NSNumber *> *)frameTypes; |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 147 | - (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate; |
magjed | 5805c9d | 2017-08-02 05:26:28 -0700 | [diff] [blame] | 148 | - (NSString *)implementationName; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 149 | |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 150 | /** Returns QP scaling settings for encoder. The quality scaler adjusts the resolution in order to |
| 151 | * keep the QP from the encoded images within the given range. Returning nil from this function |
| 152 | * disables quality scaling. */ |
| 153 | - (RTCVideoEncoderQpThresholds *)scalingSettings; |
| 154 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 155 | @end |
| 156 | |
| 157 | /** Protocol for decoder implementations. */ |
| 158 | RTC_EXPORT |
| 159 | @protocol RTCVideoDecoder <NSObject> |
| 160 | |
| 161 | - (void)setCallback:(RTCVideoDecoderCallback)callback; |
| 162 | - (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings |
| 163 | numberOfCores:(int)numberOfCores; |
| 164 | - (NSInteger)releaseDecoder; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 165 | - (NSInteger)decode:(RTCEncodedImage *)encodedImage |
| 166 | missingFrames:(BOOL)missingFrames |
| 167 | fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader |
| 168 | codecSpecificInfo:(__nullable id<RTCCodecSpecificInfo>)info |
| 169 | renderTimeMs:(int64_t)renderTimeMs; |
magjed | 5805c9d | 2017-08-02 05:26:28 -0700 | [diff] [blame] | 170 | - (NSString *)implementationName; |
magjed | 5dfac33 | 2017-08-01 08:07:59 -0700 | [diff] [blame] | 171 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 172 | @end |
| 173 | |
| 174 | NS_ASSUME_NONNULL_END |