blob: 5bc6d66d1ee15374af7fa47aec1bbe023a6576b7 [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
Kári Tristan Helgasonfc313dc2017-10-20 11:01:22 +020018RTC_EXPORT extern NSString *const kRTCVideoCodecVp8Name;
19RTC_EXPORT extern NSString *const kRTCVideoCodecVp9Name;
20RTC_EXPORT extern NSString *const kRTCVideoCodecH264Name;
21RTC_EXPORT extern NSString *const kRTCLevel31ConstrainedHigh;
22RTC_EXPORT extern NSString *const kRTCLevel31ConstrainedBaseline;
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030023RTC_EXPORT extern NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedHigh;
24RTC_EXPORT extern NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedBaseline;
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020025
kthelgasonfb143122017-07-25 07:55:58 -070026/** Represents an encoded frame's type. */
27typedef NS_ENUM(NSUInteger, RTCFrameType) {
magjed73c0eb52017-08-07 06:55:28 -070028 RTCFrameTypeEmptyFrame = 0,
29 RTCFrameTypeAudioFrameSpeech = 1,
30 RTCFrameTypeAudioFrameCN = 2,
31 RTCFrameTypeVideoFrameKey = 3,
32 RTCFrameTypeVideoFrameDelta = 4,
33};
34
35typedef NS_ENUM(NSUInteger, RTCVideoContentType) {
36 RTCVideoContentTypeUnspecified,
37 RTCVideoContentTypeScreenshare,
kthelgasonfb143122017-07-25 07:55:58 -070038};
39
40/** Represents an encoded frame. Corresponds to webrtc::EncodedImage. */
41RTC_EXPORT
42@interface RTCEncodedImage : NSObject
43
44@property(nonatomic, strong) NSData *buffer;
magjed43467b02017-09-12 02:29:43 -070045@property(nonatomic, assign) int32_t encodedWidth;
46@property(nonatomic, assign) int32_t encodedHeight;
kthelgasonfb143122017-07-25 07:55:58 -070047@property(nonatomic, assign) uint32_t timeStamp;
magjed43467b02017-09-12 02:29:43 -070048@property(nonatomic, assign) int64_t captureTimeMs;
49@property(nonatomic, assign) int64_t ntpTimeMs;
sprangba050a62017-08-18 02:51:12 -070050@property(nonatomic, assign) uint8_t flags;
magjed43467b02017-09-12 02:29:43 -070051@property(nonatomic, assign) int64_t encodeStartMs;
52@property(nonatomic, assign) int64_t encodeFinishMs;
kthelgasonfb143122017-07-25 07:55:58 -070053@property(nonatomic, assign) RTCFrameType frameType;
magjed43467b02017-09-12 02:29:43 -070054@property(nonatomic, assign) RTCVideoRotation rotation;
kthelgasonfb143122017-07-25 07:55:58 -070055@property(nonatomic, assign) BOOL completeFrame;
magjed8eab09c2017-07-31 02:56:35 -070056@property(nonatomic, strong) NSNumber *qp;
magjed73c0eb52017-08-07 06:55:28 -070057@property(nonatomic, assign) RTCVideoContentType contentType;
kthelgasonfb143122017-07-25 07:55:58 -070058
59@end
60
61/** Information for header. Corresponds to webrtc::RTPFragmentationHeader. */
62RTC_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 */
75RTC_EXPORT
76@protocol RTCCodecSpecificInfo <NSObject>
77
78@end
79
80/** Callback block for encoder. */
magjed73c0eb52017-08-07 06:55:28 -070081typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame,
kthelgasonfb143122017-07-25 07:55:58 -070082 id<RTCCodecSpecificInfo> info,
83 RTCRtpFragmentationHeader *header);
84
85/** Callback block for decoder. */
86typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame);
87
magjed73c0eb52017-08-07 06:55:28 -070088typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) {
89 RTCVideoCodecModeRealtimeVideo,
90 RTCVideoCodecModeScreensharing,
91};
92
Magnus Jedvert8b4e92d2018-04-13 15:36:43 +020093/** Holds information to identify a codec. Corresponds to webrtc::SdpVideoFormat. */
kthelgasonfb143122017-07-25 07:55:58 -070094RTC_EXPORT
Anders Carlsson6bf43d22017-10-16 13:51:43 +020095@interface RTCVideoCodecInfo : NSObject <NSCoding>
kthelgasonfb143122017-07-25 07:55:58 -070096
andersc81bc5232017-08-18 06:34:09 -070097- (instancetype)init NS_UNAVAILABLE;
98
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020099- (instancetype)initWithName:(NSString *)name;
100
andersc81bc5232017-08-18 06:34:09 -0700101- (instancetype)initWithName:(NSString *)name
102 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
103 NS_DESIGNATED_INITIALIZER;
kthelgasonfb143122017-07-25 07:55:58 -0700104
Kári Tristan Helgason3935c342017-09-28 15:08:47 +0200105- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info;
106
kthelgasonfb143122017-07-25 07:55:58 -0700107@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. */
113RTC_EXPORT
114@interface RTCVideoEncoderSettings : NSObject
115
magjed8eab09c2017-07-31 02:56:35 -0700116@property(nonatomic, strong) NSString *name;
kthelgasonfb143122017-07-25 07:55:58 -0700117
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;
magjed73c0eb52017-08-07 06:55:28 -0700129@property(nonatomic, assign) RTCVideoCodecMode mode;
kthelgasonfb143122017-07-25 07:55:58 -0700130
131@end
132
magjed5dfac332017-08-01 08:07:59 -0700133/** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */
134RTC_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
kthelgasonfb143122017-07-25 07:55:58 -0700144/** Protocol for encoder implementations. */
145RTC_EXPORT
146@protocol RTCVideoEncoder <NSObject>
147
148- (void)setCallback:(RTCVideoEncoderCallback)callback;
149- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
150 numberOfCores:(int)numberOfCores;
151- (NSInteger)releaseEncoder;
kthelgasonfb143122017-07-25 07:55:58 -0700152- (NSInteger)encode:(RTCVideoFrame *)frame
Peter Hanspersd9b64cd2018-01-12 16:16:18 +0100153 codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
kthelgasonfb143122017-07-25 07:55:58 -0700154 frameTypes:(NSArray<NSNumber *> *)frameTypes;
magjed73c0eb52017-08-07 06:55:28 -0700155- (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate;
magjed5805c9d2017-08-02 05:26:28 -0700156- (NSString *)implementationName;
kthelgasonfb143122017-07-25 07:55:58 -0700157
magjed5dfac332017-08-01 08:07:59 -0700158/** 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
kthelgasonfb143122017-07-25 07:55:58 -0700163@end
164
165/** Protocol for decoder implementations. */
166RTC_EXPORT
167@protocol RTCVideoDecoder <NSObject>
168
169- (void)setCallback:(RTCVideoDecoderCallback)callback;
170- (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
Anders Carlsson2a1bbc32018-04-04 12:49:43 +0200171 numberOfCores:(int)numberOfCores
172 DEPRECATED_MSG_ATTRIBUTE("use startDecodeWithNumberOfCores: instead");
kthelgasonfb143122017-07-25 07:55:58 -0700173- (NSInteger)releaseDecoder;
kthelgasonfb143122017-07-25 07:55:58 -0700174- (NSInteger)decode:(RTCEncodedImage *)encodedImage
Yves Gerey665174f2018-06-19 15:03:05 +0200175 missingFrames:(BOOL)missingFrames
176 codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
177 renderTimeMs:(int64_t)renderTimeMs;
magjed5805c9d2017-08-02 05:26:28 -0700178- (NSString *)implementationName;
magjed5dfac332017-08-01 08:07:59 -0700179
Anders Carlsson2a1bbc32018-04-04 12:49:43 +0200180// TODO(andersc): Make non-optional when `startDecodeWithSettings:numberOfCores:` is removed.
181@optional
182- (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores;
183
kthelgasonfb143122017-07-25 07:55:58 -0700184@end
185
186NS_ASSUME_NONNULL_END