RTCVideoCodec.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #import <Foundation/Foundation.h>
  11. #import <WebRTC/RTCMacros.h>
  12. #import <WebRTC/RTCVideoFrame.h>
  13. NS_ASSUME_NONNULL_BEGIN
  14. RTC_EXPORT extern NSString *const kRTCVideoCodecVp8Name;
  15. RTC_EXPORT extern NSString *const kRTCVideoCodecVp9Name;
  16. RTC_EXPORT extern NSString *const kRTCVideoCodecH264Name;
  17. RTC_EXPORT extern NSString *const kRTCLevel31ConstrainedHigh;
  18. RTC_EXPORT extern NSString *const kRTCLevel31ConstrainedBaseline;
  19. RTC_EXPORT extern NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedHigh;
  20. RTC_EXPORT extern NSString *const kRTCMaxSupportedH264ProfileLevelConstrainedBaseline;
  21. /** Represents an encoded frame's type. */
  22. typedef NS_ENUM(NSUInteger, RTCFrameType) {
  23. RTCFrameTypeEmptyFrame = 0,
  24. RTCFrameTypeAudioFrameSpeech = 1,
  25. RTCFrameTypeAudioFrameCN = 2,
  26. RTCFrameTypeVideoFrameKey = 3,
  27. RTCFrameTypeVideoFrameDelta = 4,
  28. };
  29. typedef NS_ENUM(NSUInteger, RTCVideoContentType) {
  30. RTCVideoContentTypeUnspecified,
  31. RTCVideoContentTypeScreenshare,
  32. };
  33. /** Represents an encoded frame. Corresponds to webrtc::EncodedImage. */
  34. RTC_EXPORT
  35. @interface RTCEncodedImage : NSObject
  36. @property(nonatomic, strong) NSData *buffer;
  37. @property(nonatomic, assign) int32_t encodedWidth;
  38. @property(nonatomic, assign) int32_t encodedHeight;
  39. @property(nonatomic, assign) uint32_t timeStamp;
  40. @property(nonatomic, assign) int64_t captureTimeMs;
  41. @property(nonatomic, assign) int64_t ntpTimeMs;
  42. @property(nonatomic, assign) uint8_t flags;
  43. @property(nonatomic, assign) int64_t encodeStartMs;
  44. @property(nonatomic, assign) int64_t encodeFinishMs;
  45. @property(nonatomic, assign) RTCFrameType frameType;
  46. @property(nonatomic, assign) RTCVideoRotation rotation;
  47. @property(nonatomic, assign) BOOL completeFrame;
  48. @property(nonatomic, strong) NSNumber *qp;
  49. @property(nonatomic, assign) RTCVideoContentType contentType;
  50. @end
  51. /** Information for header. Corresponds to webrtc::RTPFragmentationHeader. */
  52. RTC_EXPORT
  53. @interface RTCRtpFragmentationHeader : NSObject
  54. @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationOffset;
  55. @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationLength;
  56. @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationTimeDiff;
  57. @property(nonatomic, strong) NSArray<NSNumber *> *fragmentationPlType;
  58. @end
  59. /** Implement this protocol to pass codec specific info from the encoder.
  60. * Corresponds to webrtc::CodecSpecificInfo.
  61. */
  62. RTC_EXPORT
  63. @protocol RTCCodecSpecificInfo <NSObject>
  64. @end
  65. /** Callback block for encoder. */
  66. typedef BOOL (^RTCVideoEncoderCallback)(RTCEncodedImage *frame,
  67. id<RTCCodecSpecificInfo> info,
  68. RTCRtpFragmentationHeader *header);
  69. /** Callback block for decoder. */
  70. typedef void (^RTCVideoDecoderCallback)(RTCVideoFrame *frame);
  71. typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) {
  72. RTCVideoCodecModeRealtimeVideo,
  73. RTCVideoCodecModeScreensharing,
  74. };
  75. /** Holds information to identify a codec. Corresponds to webrtc::SdpVideoFormat. */
  76. RTC_EXPORT
  77. @interface RTCVideoCodecInfo : NSObject <NSCoding>
  78. - (instancetype)init NS_UNAVAILABLE;
  79. - (instancetype)initWithName:(NSString *)name;
  80. - (instancetype)initWithName:(NSString *)name
  81. parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
  82. NS_DESIGNATED_INITIALIZER;
  83. - (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info;
  84. @property(nonatomic, readonly) NSString *name;
  85. @property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *parameters;
  86. @end
  87. /** Settings for encoder. Corresponds to webrtc::VideoCodec. */
  88. RTC_EXPORT
  89. @interface RTCVideoEncoderSettings : NSObject
  90. @property(nonatomic, strong) NSString *name;
  91. @property(nonatomic, assign) unsigned short width;
  92. @property(nonatomic, assign) unsigned short height;
  93. @property(nonatomic, assign) unsigned int startBitrate; // kilobits/sec.
  94. @property(nonatomic, assign) unsigned int maxBitrate;
  95. @property(nonatomic, assign) unsigned int minBitrate;
  96. @property(nonatomic, assign) unsigned int targetBitrate;
  97. @property(nonatomic, assign) uint32_t maxFramerate;
  98. @property(nonatomic, assign) unsigned int qpMax;
  99. @property(nonatomic, assign) RTCVideoCodecMode mode;
  100. @end
  101. /** QP thresholds for encoder. Corresponds to webrtc::VideoEncoder::QpThresholds. */
  102. RTC_EXPORT
  103. @interface RTCVideoEncoderQpThresholds : NSObject
  104. - (instancetype)initWithThresholdsLow:(NSInteger)low high:(NSInteger)high;
  105. @property(nonatomic, readonly) NSInteger low;
  106. @property(nonatomic, readonly) NSInteger high;
  107. @end
  108. /** Protocol for encoder implementations. */
  109. RTC_EXPORT
  110. @protocol RTCVideoEncoder <NSObject>
  111. - (void)setCallback:(RTCVideoEncoderCallback)callback;
  112. - (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
  113. numberOfCores:(int)numberOfCores;
  114. - (NSInteger)releaseEncoder;
  115. - (NSInteger)encode:(RTCVideoFrame *)frame
  116. codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
  117. frameTypes:(NSArray<NSNumber *> *)frameTypes;
  118. - (int)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate;
  119. - (NSString *)implementationName;
  120. /** Returns QP scaling settings for encoder. The quality scaler adjusts the resolution in order to
  121. * keep the QP from the encoded images within the given range. Returning nil from this function
  122. * disables quality scaling. */
  123. - (RTCVideoEncoderQpThresholds *)scalingSettings;
  124. @end
  125. /** Protocol for decoder implementations. */
  126. RTC_EXPORT
  127. @protocol RTCVideoDecoder <NSObject>
  128. - (void)setCallback:(RTCVideoDecoderCallback)callback;
  129. - (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
  130. numberOfCores:(int)numberOfCores
  131. DEPRECATED_MSG_ATTRIBUTE("use startDecodeWithNumberOfCores: instead");
  132. - (NSInteger)releaseDecoder;
  133. - (NSInteger)decode:(RTCEncodedImage *)encodedImage
  134. missingFrames:(BOOL)missingFrames
  135. codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)info
  136. renderTimeMs:(int64_t)renderTimeMs;
  137. - (NSString *)implementationName;
  138. // TODO(andersc): Make non-optional when `startDecodeWithSettings:numberOfCores:` is removed.
  139. @optional
  140. - (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores;
  141. @end
  142. NS_ASSUME_NONNULL_END