-
Notifications
You must be signed in to change notification settings - Fork 5
/
rke-replayd.xm
executable file
·141 lines (126 loc) · 4.62 KB
/
rke-replayd.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// rke-replayd.xm
// ReplayKitEverywhere
//
// Created by ester on 2018/1/30.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <notify.h>
NSString* RKEGetSettingValue(NSString *key, NSString *defaultValue) {
NSDictionary *setting = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.estertion.replaykiteverywhere.plist"];
if (setting == NULL) return defaultValue;
NSObject *value = [setting objectForKey:key];
if (value == NULL) return defaultValue;
NSString *valueStr;
if ([value isKindOfClass:[NSString class]]) {
valueStr = (NSString *)value;
} else if ([value isKindOfClass:[NSNumber class]]) {
valueStr = [(NSNumber *)value stringValue];
} else {
valueStr = defaultValue;
}
return valueStr;
}
%hookf(OSStatus, AudioQueueNewInput, AudioStreamBasicDescription *inFormat, AudioQueueInputCallback inCallbackProc, void *inUserData, CFRunLoopRef inCallbackRunLoop, CFStringRef inCallbackRunLoopMode, UInt32 inFlags, AudioQueueRef _Nullable *outAQ) {
inFormat->mBytesPerPacket = 4;
inFormat->mBytesPerFrame = 4;
inFormat->mChannelsPerFrame = 2;
NSString *quality = RKEGetSettingValue(@"quality", @"0");
if ([quality isEqualToString:@"2"] || [quality isEqualToString:@"3"] || [quality isEqualToString:@"4"]) {
inFormat->mSampleRate = 48000.0;
}
return %orig;
}
static NSDictionary *videoBitrate = @{
@"1": @4000000LL,
@"2": @8000000LL,
@"3": @15000000LL,
@"4": @25000000LL
};
static NSDictionary *audioBitrate = @{
@"1": @128000LL,
@"2": @256000LL,
@"3": @320000LL,
@"4": @320000LL
};
static NSDictionary *audioSampleRate = @{
@"1": @44100.0,
@"2": @48000.0,
@"3": @48000.0,
@"4": @48000.0
};
static bool supportHEVC = [[AVAssetExportSession allExportPresets] containsObject:@"AVAssetExportPresetHEVCHighestQuality"];
%hook AVAssetWriterInput
- (instancetype)initWithMediaType:(NSString *)mediaType outputSettings:(NSDictionary<NSString *, id> *)outputSettings {
NSString *quality = RKEGetSettingValue(@"quality", @"0");
if (videoBitrate[quality] != nil) {
NSMutableDictionary *modify = [outputSettings mutableCopy];
if ([mediaType isEqualToString:@"vide"]) {
NSLog(@"[ReplayKit Everywhere] Recording at quality level %@", quality);
NSMutableDictionary *compressModify = [modify[@"AVVideoCompressionPropertiesKey"] mutableCopy];
compressModify[AVVideoAverageBitRateKey] = videoBitrate[quality];
modify[@"AVVideoCompressionPropertiesKey"] = compressModify;
} else if ([mediaType isEqualToString:@"soun"]) {
modify[AVSampleRateKey] = audioSampleRate[quality];
modify[AVEncoderBitRateKey] = audioBitrate[quality];
}
outputSettings = [NSDictionary dictionaryWithDictionary:modify];
}
if (supportHEVC && [mediaType isEqualToString:@"vide"] && [RKEGetSettingValue(@"useHEVC", @"0") isEqualToString:@"1"]) {
NSMutableDictionary *modify = [outputSettings mutableCopy];
modify[AVVideoCodecKey] = @"hvc1";
NSMutableDictionary *compressModify = [modify[@"AVVideoCompressionPropertiesKey"] mutableCopy];
compressModify[AVVideoAverageBitRateKey] = [NSNumber numberWithLong:[(NSNumber*)compressModify[AVVideoAverageBitRateKey] longValue] * 3 / 4];
compressModify[AVVideoProfileLevelKey] = @"HEVC_Main_AutoLevel";
modify[@"AVVideoCompressionPropertiesKey"] = compressModify;
outputSettings = [NSDictionary dictionaryWithDictionary:modify];
}
return %orig(mediaType, outputSettings);
}
%end
%hook RPRecordingManager
-(bool)isExemptFromAcknowledgementAlert {
NSString *skipWarn = RKEGetSettingValue(@"skipWarn", @"0");
if ([skipWarn isEqualToString:@"0"]) {
return %orig;
} else {
return true;
}
}
-(bool)isExemptFromAcknowledgementAlertSession:(id)arg0 {
NSString *skipWarn = RKEGetSettingValue(@"skipWarn", @"0");
if ([skipWarn isEqualToString:@"0"]) {
return %orig;
} else {
return true;
}
}
-(bool)isApplicationInForegroundWithBundleIdentifier:(NSString*) id {
if ([RKEGetSettingValue(@"fix_foreground", @"0") isEqualToString:@"1"])
return true;
else
return %orig;
}
%end
// ios 14
%hook RPRecordSession
-(bool)shouldSupressAlert {
NSString *skipWarn = RKEGetSettingValue(@"skipWarn", @"0");
if ([skipWarn isEqualToString:@"0"]) {
return %orig;
} else {
return true;
}
}
%end
%ctor {
notify_post("com.estertion.replaykiteverywhere.replayd_started");
}
%hook FigScreenCaptureController
+(id)screenCaptureControllerWithSize:(CGRect)rect minIntervalBetweenFrames:(CMTime)interval {
interval.timescale = [UIScreen mainScreen].maximumFramesPerSecond;
return %orig;
}
%end