blob: 2f287ddb459eb26186fb8473b09cab6b7f634a08 [file] [log] [blame]
kthelgasonfb143122017-07-25 07:55:58 -07001/*
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>
magjed43467b02017-09-12 02:29:43 -070014#import <WebRTC/RTCVideoFrame.h>
kthelgasonfb143122017-07-25 07:55:58 -070015
16NS_ASSUME_NONNULL_BEGIN
17
18/** Represents an encoded frame's type. */
19typedef NS_ENUM(NSUInteger, RTCFrameType) {
magjed73c0eb52017-08-07 06:55:28 -070020 RTCFrameTypeEmptyFrame = 0,
21 RTCFrameTypeAudioFrameSpeech = 1,
22 RTCFrameTypeAudioFrameCN = 2,
23 RTCFrameTypeVideoFrameKey = 3,
24 RTCFrameTypeVideoFrameDelta = 4,
25};
26
27typedef NS_ENUM(NSUInteger, RTCVideoContentType) {
28 RTCVideoContentTypeUnspecified,
29 RTCVideoContentTypeScreenshare,
kthelgasonfb143122017-07-25 07:55:58 -070030};
31
32/** Represents an encoded frame. Corresponds to webrtc::EncodedImage. */
33RTC_EXPORT
34@interface RTCEncodedImage : NSObject
35
36@property(nonatomic, strong) NSData *buffer;
magjed43467b02017-09-12 02:29:43 -070037@property(nonatomic, assign) int32_t encodedWidth;
38@property(nonatomic, assign) int32_t encodedHeight;
kthelgasonfb143122017-07-25 07:55:58 -070039@property(nonatomic, assign) uint32_t timeStamp;
magjed43467b02017-09-12 02:29:43 -070040@property(nonatomic, assign) int64_t captureTimeMs;
41@property(nonatomic, assign) int64_t ntpTimeMs;
sprangba050a62017-08-18 02:51:12 -070042@property(nonatomic, assign) uint8_t flags;
magjed43467b02017-09-12 02:29:43 -070043@property(nonatomic, assign) int64_t encodeStartMs;
44@property(nonatomic, assign) int64_t encodeFinishMs;
kthelgasonfb143122017-07-25 07:55:58 -070045@property(nonatomic, assign) RTCFrameType frameType;
magjed43467b02017-09-12 02:29:43 -070046@property(nonatomic, assign) RTCVideoRotation rotation;
kthelgasonfb143122017-07-25 07:55:58 -070047@property(nonatomic, assign) BOOL completeFrame;
magjed8eab09c2017-07-31 02:56:35 -070048@property(nonatomic, strong) NSNumber *qp;
magjed73c0eb52017-08-07 06:55:28 -070049@property(nonatomic, assign) RTCVideoContentType contentType;
kthelgasonfb143122017-07-25 07:55:58 -070050
51@end
52
53/** Information for header. Corresponds to webrtc::RTPFragmentationHeader. */
54RTC_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 */
67RTC_EXPORT
68@protocol RTCCodecSpecificInfo <NSObject>
69
70@end
71
magjed73c0eb52017-08-07 06:55:28 -070072/** Class for H264 specific config. */
73typedef NS_ENUM(NSUInteger, RTCH264PacketizationMode) {
74 RTCH264PacketizationModeNonInterleaved = 0, // Mode 1 - STAP-A, FU-A is allowed
75 RTCH264PacketizationModeSingleNalUnit // Mode 0 - only single NALU allowed
76};
77
78RTC_EXPORT
79@interface RTCCodecSpecificInfoH264 : NSObject<RTCCodecSpecificInfo>
80
81@property(nonatomic, assign) RTCH264PacketizationMode packetizationMode;
82
83@end
84
kthelgasonfb143122017-07-25 07:55:58 -070085/** Callback block for encoder. */
magjed73c0eb52017-08-07 06:55:28 -070086typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame,
kthelgasonfb143122017-07-25 07:55:58 -070087 id<RTCCodecSpecificInfo> info,
88 RTCRtpFragmentationHeader *header);
89
90/** Callback block for decoder. */
91typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame);
92
magjed73c0eb52017-08-07 06:55:28 -070093typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) {
94 RTCVideoCodecModeRealtimeVideo,
95 RTCVideoCodecModeScreensharing,
96};
97
kthelgasonfb143122017-07-25 07:55:58 -070098/** Holds information to identify a codec. Corresponds to cricket::VideoCodec. */
99RTC_EXPORT
100@interface RTCVideoCodecInfo : NSObject
101
andersc81bc5232017-08-18 06:34:09 -0700102- (instancetype)init NS_UNAVAILABLE;
103
104- (instancetype)initWithName:(NSString *)name
105 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
106 NS_DESIGNATED_INITIALIZER;
kthelgasonfb143122017-07-25 07:55:58 -0700107
108@property(nonatomic, readonly) NSInteger payload;
109@property(nonatomic, readonly) NSString *name;
110@property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *parameters;
111
112@end
113
114/** Settings for encoder. Corresponds to webrtc::VideoCodec. */
115RTC_EXPORT
116@interface RTCVideoEncoderSettings : NSObject
117
magjed8eab09c2017-07-31 02:56:35 -0700118@property(nonatomic, strong) NSString *name;
kthelgasonfb143122017-07-25 07:55:58 -0700119
120@property(nonatomic, assign) unsigned short width;
121@property(nonatomic, assign) unsigned short height;
122
123@property(nonatomic, assign) unsigned int startBitrate; // kilobits/sec.
124@property(nonatomic, assign) unsigned int maxBitrate;
125@property(nonatomic, assign) unsigned int minBitrate;
126@property(nonatomic, assign) unsigned int targetBitrate;
127
128@property(nonatomic, assign) uint32_t maxFramerate;
129
130@property(nonatomic, assign) unsigned int qpMax;
magjed73c0eb52017-08-07 06:55:28 -0700131@property(nonatomic, assign) RTCVideoCodecMode mode;
kthelgasonfb143122017-07-25 07:55:58 -0700132
133@end
134
magjed5dfac332017-08-01 08:07:59 -0700135/** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */
136RTC_EXPORT
137@interface RTCVideoEncoderQpThresholds : NSObject
138
139- (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high;
140
141@property(nonatomic, readonly) NSInteger low;
142@property(nonatomic, readonly) NSInteger high;
143
144@end
145
kthelgasonfb143122017-07-25 07:55:58 -0700146/** Protocol for encoder implementations. */
147RTC_EXPORT
148@protocol RTCVideoEncoder <NSObject>
149
150- (void)setCallback:(RTCVideoEncoderCallback)callback;
151- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
152 numberOfCores:(int)numberOfCores;
153- (NSInteger)releaseEncoder;
kthelgasonfb143122017-07-25 07:55:58 -0700154- (NSInteger)encode:(RTCVideoFrame *)frame
155 codecSpecificInfo:(id<RTCCodecSpecificInfo>)info
156 frameTypes:(NSArray<NSNumber *> *)frameTypes;
magjed73c0eb52017-08-07 06:55:28 -0700157- (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate;
magjed5805c9d2017-08-02 05:26:28 -0700158- (NSString *)implementationName;
kthelgasonfb143122017-07-25 07:55:58 -0700159
magjed5dfac332017-08-01 08:07:59 -0700160/** Returns QP scaling settings for encoder. The quality scaler adjusts the resolution in order to
161 * keep the QP from the encoded images within the given range. Returning nil from this function
162 * disables quality scaling. */
163- (RTCVideoEncoderQpThresholds *)scalingSettings;
164
kthelgasonfb143122017-07-25 07:55:58 -0700165@end
166
167/** Protocol for decoder implementations. */
168RTC_EXPORT
169@protocol RTCVideoDecoder <NSObject>
170
171- (void)setCallback:(RTCVideoDecoderCallback)callback;
172- (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
173 numberOfCores:(int)numberOfCores;
174- (NSInteger)releaseDecoder;
kthelgasonfb143122017-07-25 07:55:58 -0700175- (NSInteger)decode:(RTCEncodedImage *)encodedImage
176 missingFrames:(BOOL)missingFrames
177 fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader
178 codecSpecificInfo:(__nullable id<RTCCodecSpecificInfo>)info
179 renderTimeMs:(int64_t)renderTimeMs;
magjed5805c9d2017-08-02 05:26:28 -0700180- (NSString *)implementationName;
magjed5dfac332017-08-01 08:07:59 -0700181
kthelgasonfb143122017-07-25 07:55:58 -0700182@end
183
184NS_ASSUME_NONNULL_END