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