rtmp、rtc推拉流支持加密

This commit is contained in:
caleb
2026-04-07 16:35:04 +08:00
parent bc56b7851d
commit 88800334ec
19 changed files with 370 additions and 147 deletions

View File

@@ -15,10 +15,11 @@ typedef NS_OPTIONS(NSUInteger, AVSettingsFieldMask) {
AVSettingsFieldStreamId = 1 << 0, // Show Stream ID field
AVSettingsFieldNickname = 1 << 1, // Show Nickname field
AVSettingsFieldVideoParams = 1 << 2, // Show video params (codec, resolution, fps, bitrate)
AVSettingsFieldXorKey = 1 << 3, // Show XOR encryption key field
// Convenient combinations
AVSettingsFieldBasicPull = AVSettingsFieldStreamId | AVSettingsFieldNickname, // For pull page
AVSettingsFieldAll = AVSettingsFieldStreamId | AVSettingsFieldNickname | AVSettingsFieldVideoParams // For push page
AVSettingsFieldAll = AVSettingsFieldStreamId | AVSettingsFieldNickname | AVSettingsFieldVideoParams | AVSettingsFieldXorKey // For push page
};
@interface AVSettingsView : UIView

View File

@@ -21,6 +21,7 @@
@property (nonatomic, strong) UITextField *fpsField;
@property (nonatomic, strong) UITextField *maxBitrateField;
@property (nonatomic, strong) UITextField *minBitrateField;
@property (nonatomic, strong) UITextField *xorKeyField;
@property (nonatomic, strong) NSLayoutConstraint *containerCenterYConstraint;
@property (nonatomic, weak) UITextField *activeTextField; //
@@ -194,6 +195,37 @@
topOffset += 40 + spacing;
}
// XOR Key (after nickname, before video params)
if (self.fieldsMask & AVSettingsFieldXorKey) {
UILabel *xorKeyLabel = [[UILabel alloc] init];
xorKeyLabel.text = @"加密密钥 (Hex)";
xorKeyLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
[contentView addSubview:xorKeyLabel];
xorKeyLabel.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[xorKeyLabel.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:20],
[xorKeyLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor constant:topOffset]
]];
topOffset += 20;
_xorKeyField = [[UITextField alloc] init];
_xorKeyField.placeholder = @"如 AABBCCDD留空不加密";
_xorKeyField.borderStyle = UITextBorderStyleRoundedRect;
_xorKeyField.autocapitalizationType = UITextAutocapitalizationTypeNone;
_xorKeyField.autocorrectionType = UITextAutocorrectionTypeNo;
_xorKeyField.delegate = self;
_xorKeyField.returnKeyType = UIReturnKeyDone;
[contentView addSubview:_xorKeyField];
_xorKeyField.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[_xorKeyField.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:20],
[_xorKeyField.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:-20],
[_xorKeyField.topAnchor constraintEqualToAnchor:contentView.topAnchor constant:topOffset],
[_xorKeyField.heightAnchor constraintEqualToConstant:40]
]];
topOffset += 40 + spacing;
}
// Video parameters (conditional)
if (self.fieldsMask & AVSettingsFieldVideoParams) {
// Resolution
@@ -373,6 +405,14 @@
if (_minBitrateField) {
_minBitrateField.text = [NSString stringWithFormat:@"%ld", (long)(config.videoMinBitRate / 1000)];
}
if (_xorKeyField) {
// Load from config first, fallback to cached value
NSString *key = config.xorKey;
if (key.length == 0) {
key = [[NSUserDefaults standardUserDefaults] stringForKey:@"selly_xor_key_cache"];
}
_xorKeyField.text = key ?: @"";
}
self.frame = viewController.view.bounds;
self.alpha = 0;
@@ -428,6 +468,17 @@
self.tempConfig.videoMinBitRate = minBitrate * 1000; // Convert kbps to bps
}
if (_xorKeyField) {
NSString *key = [_xorKeyField.text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
self.tempConfig.xorKey = key.length > 0 ? key : nil;
// Cache for next time
if (key.length > 0) {
[[NSUserDefaults standardUserDefaults] setObject:key forKey:@"selly_xor_key_cache"];
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"selly_xor_key_cache"];
}
}
if (self.callback) {
self.callback(self.tempConfig);
}