RTCFrameCryptor.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2022 LiveKit
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import <WebRTC/RTCMacros.h>
  18. NS_ASSUME_NONNULL_BEGIN
  19. @class RTC_OBJC_TYPE(RTCRtpSender);
  20. @class RTC_OBJC_TYPE(RTCRtpReceiver);
  21. @class RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider);
  22. @class RTC_OBJC_TYPE(RTCFrameCryptor);
  23. @class RTC_OBJC_TYPE(RTCPeerConnectionFactory);
  24. typedef NS_ENUM(NSUInteger, RTCCyrptorAlgorithm) {
  25. RTCCyrptorAlgorithmAesGcm = 0,
  26. RTCCyrptorAlgorithmAesCbc,
  27. };
  28. typedef NS_ENUM(NSInteger, FrameCryptionState) {
  29. FrameCryptionStateNew = 0,
  30. FrameCryptionStateOk,
  31. FrameCryptionStateEncryptionFailed,
  32. FrameCryptionStateDecryptionFailed,
  33. FrameCryptionStateMissingKey,
  34. FrameCryptionStateKeyRatcheted,
  35. FrameCryptionStateInternalError,
  36. };
  37. RTC_OBJC_EXPORT
  38. @protocol RTC_OBJC_TYPE
  39. (RTCFrameCryptorDelegate)<NSObject>
  40. /** Called when the RTCFrameCryptor got errors. */
  41. - (void)frameCryptor
  42. : (RTC_OBJC_TYPE(RTCFrameCryptor) *)frameCryptor didStateChangeWithParticipantId
  43. : (NSString *)participantId withState : (FrameCryptionState)stateChanged;
  44. @end
  45. RTC_OBJC_EXPORT
  46. @interface RTC_OBJC_TYPE (RTCFrameCryptor) : NSObject
  47. @property(nonatomic, assign) BOOL enabled;
  48. @property(nonatomic, assign) int keyIndex;
  49. @property(nonatomic, readonly) NSString *participantId;
  50. @property(nonatomic, weak, nullable) id<RTC_OBJC_TYPE(RTCFrameCryptorDelegate)> delegate;
  51. - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
  52. rtpSender:(RTC_OBJC_TYPE(RTCRtpSender) *)sender
  53. participantId:(NSString *)participantId
  54. algorithm:(RTCCyrptorAlgorithm)algorithm
  55. keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider;
  56. - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
  57. rtpReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver
  58. participantId:(NSString *)participantId
  59. algorithm:(RTCCyrptorAlgorithm)algorithm
  60. keyProvider:(RTC_OBJC_TYPE(RTCFrameCryptorKeyProvider) *)keyProvider;
  61. @end
  62. NS_ASSUME_NONNULL_END