blob: bfd768a66d9f027d2c920b49af3a94765b73f79e [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
72/** Callback block for encoder. */
magjed73c0eb52017-08-07 06:55:28 -070073typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame,
kthelgasonfb143122017-07-25 07:55:58 -070074 id<RTCCodecSpecificInfo> info,
75 RTCRtpFragmentationHeader *header);
76
77/** Callback block for decoder. */
78typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame);
79
magjed73c0eb52017-08-07 06:55:28 -070080typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) {
81 RTCVideoCodecModeRealtimeVideo,
82 RTCVideoCodecModeScreensharing,
83};
84
kthelgasonfb143122017-07-25 07:55:58 -070085/** Holds information to identify a codec. Corresponds to cricket::VideoCodec. */
86RTC_EXPORT
Anders Carlsson6bf43d22017-10-16 13:51:43 +020087@interface RTCVideoCodecInfo : NSObject <NSCoding>
kthelgasonfb143122017-07-25 07:55:58 -070088
andersc81bc5232017-08-18 06:34:09 -070089- (instancetype)init NS_UNAVAILABLE;
90
Kári Tristan Helgasone71f3672017-10-02 14:59:59 +020091- (instancetype)initWithName:(NSString *)name;
92
andersc81bc5232017-08-18 06:34:09 -070093- (instancetype)initWithName:(NSString *)name
94 parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
95 NS_DESIGNATED_INITIALIZER;
kthelgasonfb143122017-07-25 07:55:58 -070096
Kári Tristan Helgason3935c342017-09-28 15:08:47 +020097- (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info;
98
kthelgasonfb143122017-07-25 07:55:58 -070099@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. */
105RTC_EXPORT
106@interface RTCVideoEncoderSettings : NSObject
107
magjed8eab09c2017-07-31 02:56:35 -0700108@property(nonatomic, strong) NSString *name;
kthelgasonfb143122017-07-25 07:55:58 -0700109
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;
magjed73c0eb52017-08-07 06:55:28 -0700121@property(nonatomic, assign) RTCVideoCodecMode mode;
kthelgasonfb143122017-07-25 07:55:58 -0700122
123@end
124
magjed5dfac332017-08-01 08:07:59 -0700125/** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */
126RTC_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
kthelgasonfb143122017-07-25 07:55:58 -0700136/** Protocol for encoder implementations. */
137RTC_EXPORT
138@protocol RTCVideoEncoder <NSObject>
139
140- (void)setCallback:(RTCVideoEncoderCallback)callback;
141- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
142 numberOfCores:(int)numberOfCores;
143- (NSInteger)releaseEncoder;
kthelgasonfb143122017-07-25 07:55:58 -0700144- (NSInteger)encode:(RTCVideoFrame *)frame
145 codecSpecificInfo:(id<RTCCodecSpecificInfo>)info
146 frameTypes:(NSArray<NSNumber *> *)frameTypes;
magjed73c0eb52017-08-07 06:55:28 -0700147- (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate;
magjed5805c9d2017-08-02 05:26:28 -0700148- (NSString *)implementationName;
kthelgasonfb143122017-07-25 07:55:58 -0700149
magjed5dfac332017-08-01 08:07:59 -0700150/** 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
kthelgasonfb143122017-07-25 07:55:58 -0700155@end
156
157/** Protocol for decoder implementations. */
158RTC_EXPORT
159@protocol RTCVideoDecoder <NSObject>
160
161- (void)setCallback:(RTCVideoDecoderCallback)callback;
162- (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
163 numberOfCores:(int)numberOfCores;
164- (NSInteger)releaseDecoder;
kthelgasonfb143122017-07-25 07:55:58 -0700165- (NSInteger)decode:(RTCEncodedImage *)encodedImage
166 missingFrames:(BOOL)missingFrames
167 fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader
168 codecSpecificInfo:(__nullable id<RTCCodecSpecificInfo>)info
169 renderTimeMs:(int64_t)renderTimeMs;
magjed5805c9d2017-08-02 05:26:28 -0700170- (NSString *)implementationName;
magjed5dfac332017-08-01 08:07:59 -0700171
kthelgasonfb143122017-07-25 07:55:58 -0700172@end
173
174NS_ASSUME_NONNULL_END