blob: e9dd234c34439d83fc55739ecb8e1538c89a39a0 [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;
Kári Tristan Helgason117c4822017-10-18 14:22:22 +020023
kthelgasonfb143122017-07-25 07:55:58 -070024/** Represents an encoded frame's type. */
25typedef NS_ENUM(NSUInteger, RTCFrameType) {
magjed73c0eb52017-08-07 06:55:28 -070026 RTCFrameTypeEmptyFrame = 0,
27 RTCFrameTypeAudioFrameSpeech = 1,
28 RTCFrameTypeAudioFrameCN = 2,
29 RTCFrameTypeVideoFrameKey = 3,
30 RTCFrameTypeVideoFrameDelta = 4,
31};
32
33typedef NS_ENUM(NSUInteger, RTCVideoContentType) {
34 RTCVideoContentTypeUnspecified,
35 RTCVideoContentTypeScreenshare,
kthelgasonfb143122017-07-25 07:55:58 -070036};
37
38/** Represents an encoded frame. Corresponds to webrtc::EncodedImage. */
39RTC_EXPORT
40@interface RTCEncodedImage : NSObject
41
42@property(nonatomic, strong) NSData *buffer;
magjed43467b02017-09-12 02:29:43 -070043@property(nonatomic, assign) int32_t encodedWidth;
44@property(nonatomic, assign) int32_t encodedHeight;
kthelgasonfb143122017-07-25 07:55:58 -070045@property(nonatomic, assign) uint32_t timeStamp;
magjed43467b02017-09-12 02:29:43 -070046@property(nonatomic, assign) int64_t captureTimeMs;
47@property(nonatomic, assign) int64_t ntpTimeMs;
sprangba050a62017-08-18 02:51:12 -070048@property(nonatomic, assign) uint8_t flags;
magjed43467b02017-09-12 02:29:43 -070049@property(nonatomic, assign) int64_t encodeStartMs;
50@property(nonatomic, assign) int64_t encodeFinishMs;
kthelgasonfb143122017-07-25 07:55:58 -070051@property(nonatomic, assign) RTCFrameType frameType;
magjed43467b02017-09-12 02:29:43 -070052@property(nonatomic, assign) RTCVideoRotation rotation;
kthelgasonfb143122017-07-25 07:55:58 -070053@property(nonatomic, assign) BOOL completeFrame;
magjed8eab09c2017-07-31 02:56:35 -070054@property(nonatomic, strong) NSNumber *qp;
magjed73c0eb52017-08-07 06:55:28 -070055@property(nonatomic, assign) RTCVideoContentType contentType;
kthelgasonfb143122017-07-25 07:55:58 -070056
57@end
58
59/** Information for header. Corresponds to webrtc::RTPFragmentationHeader. */
60RTC_EXPORT
61@interface RTCRtpFragmentationHeader : NSObject
62
63@property(nonatomic, strong) NSArray<NSNumber *> *fragmentationOffset;
64@property(nonatomic, strong) NSArray<NSNumber *> *fragmentationLength;
65@property(nonatomic, strong) NSArray<NSNumber *> *fragmentationTimeDiff;
66@property(nonatomic, strong) NSArray<NSNumber *> *fragmentationPlType;
67
68@end
69
70/** Implement this protocol to pass codec specific info from the encoder.
71 * Corresponds to webrtc::CodecSpecificInfo.
72 */
73RTC_EXPORT
74@protocol RTCCodecSpecificInfo <NSObject>
75
76@end
77
78/** Callback block for encoder. */
magjed73c0eb52017-08-07 06:55:28 -070079typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame,
kthelgasonfb143122017-07-25 07:55:58 -070080 id<RTCCodecSpecificInfo> info,
81 RTCRtpFragmentationHeader *header);
82
83/** Callback block for decoder. */
84typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame);
85
magjed73c0eb52017-08-07 06:55:28 -070086typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) {
87 RTCVideoCodecModeRealtimeVideo,
88 RTCVideoCodecModeScreensharing,
89};
90
kthelgasonfb143122017-07-25 07:55:58 -070091/** Holds information to identify a codec. Corresponds to cricket::VideoCodec. */
92RTC_EXPORT
Anders Carlsson6bf43d22017-10-16 13:51:43 +020093@interface RTCVideoCodecInfo : NSObject <NSCoding>
kthelgasonfb143122017-07-25 07:55:58 -070094
andersc81bc5232017-08-18 06:34:09 -070095- (instancetype)init NS_UNAVAILABLE;
96
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020097- (instancetype)initWithName:(NSString *)name;
98
andersc81bc5232017-08-18 06:34:09 -070099- (instancetype)initWithName:(NSString *)name
100 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
101 NS_DESIGNATED_INITIALIZER;
kthelgasonfb143122017-07-25 07:55:58 -0700102
Kári Tristan Helgason3935c342017-09-28 15:08:47 +0200103- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info;
104
kthelgasonfb143122017-07-25 07:55:58 -0700105@property(nonatomic, readonly) NSString *name;
106@property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *parameters;
107
108@end
109
110/** Settings for encoder. Corresponds to webrtc::VideoCodec. */
111RTC_EXPORT
112@interface RTCVideoEncoderSettings : NSObject
113
magjed8eab09c2017-07-31 02:56:35 -0700114@property(nonatomic, strong) NSString *name;
kthelgasonfb143122017-07-25 07:55:58 -0700115
116@property(nonatomic, assign) unsigned short width;
117@property(nonatomic, assign) unsigned short height;
118
119@property(nonatomic, assign) unsigned int startBitrate; // kilobits/sec.
120@property(nonatomic, assign) unsigned int maxBitrate;
121@property(nonatomic, assign) unsigned int minBitrate;
122@property(nonatomic, assign) unsigned int targetBitrate;
123
124@property(nonatomic, assign) uint32_t maxFramerate;
125
126@property(nonatomic, assign) unsigned int qpMax;
magjed73c0eb52017-08-07 06:55:28 -0700127@property(nonatomic, assign) RTCVideoCodecMode mode;
kthelgasonfb143122017-07-25 07:55:58 -0700128
129@end
130
magjed5dfac332017-08-01 08:07:59 -0700131/** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */
132RTC_EXPORT
133@interface RTCVideoEncoderQpThresholds : NSObject
134
135- (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high;
136
137@property(nonatomic, readonly) NSInteger low;
138@property(nonatomic, readonly) NSInteger high;
139
140@end
141
kthelgasonfb143122017-07-25 07:55:58 -0700142/** Protocol for encoder implementations. */
143RTC_EXPORT
144@protocol RTCVideoEncoder <NSObject>
145
146- (void)setCallback:(RTCVideoEncoderCallback)callback;
147- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
148 numberOfCores:(int)numberOfCores;
149- (NSInteger)releaseEncoder;
kthelgasonfb143122017-07-25 07:55:58 -0700150- (NSInteger)encode:(RTCVideoFrame *)frame
Peter Hanspersd9b64cd2018-01-12 16:16:18 +0100151 codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
kthelgasonfb143122017-07-25 07:55:58 -0700152 frameTypes:(NSArray<NSNumber *> *)frameTypes;
magjed73c0eb52017-08-07 06:55:28 -0700153- (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate;
magjed5805c9d2017-08-02 05:26:28 -0700154- (NSString *)implementationName;
kthelgasonfb143122017-07-25 07:55:58 -0700155
magjed5dfac332017-08-01 08:07:59 -0700156/** Returns QP scaling settings for encoder. The quality scaler adjusts the resolution in order to
157 * keep the QP from the encoded images within the given range. Returning nil from this function
158 * disables quality scaling. */
159- (RTCVideoEncoderQpThresholds *)scalingSettings;
160
kthelgasonfb143122017-07-25 07:55:58 -0700161@end
162
163/** Protocol for decoder implementations. */
164RTC_EXPORT
165@protocol RTCVideoDecoder <NSObject>
166
167- (void)setCallback:(RTCVideoDecoderCallback)callback;
168- (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
Anders Carlsson2a1bbc32018-04-04 12:49:43 +0200169 numberOfCores:(int)numberOfCores
170 DEPRECATED_MSG_ATTRIBUTE("use startDecodeWithNumberOfCores: instead");
kthelgasonfb143122017-07-25 07:55:58 -0700171- (NSInteger)releaseDecoder;
kthelgasonfb143122017-07-25 07:55:58 -0700172- (NSInteger)decode:(RTCEncodedImage *)encodedImage
173 missingFrames:(BOOL)missingFrames
174 fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader
Peter Hanspersd9b64cd2018-01-12 16:16:18 +0100175 codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
kthelgasonfb143122017-07-25 07:55:58 -0700176 renderTimeMs:(int64_t)renderTimeMs;
magjed5805c9d2017-08-02 05:26:28 -0700177- (NSString *)implementationName;
magjed5dfac332017-08-01 08:07:59 -0700178
Anders Carlsson2a1bbc32018-04-04 12:49:43 +0200179// TODO(andersc): Make non-optional when `startDecodeWithSettings:numberOfCores:` is removed.
180@optional
181- (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores;
182
kthelgasonfb143122017-07-25 07:55:58 -0700183@end
184
185NS_ASSUME_NONNULL_END