[Audio Threads] Remove workgroup code
As it doesn't seem to work properly on Intel machines, anyway. It just leads to pointless crashes, and doesn't seem to serve any purpose. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
3156aad9e1
commit
4a269f05a1
|
@ -451,9 +451,7 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes
|
|||
usleep(500);
|
||||
}
|
||||
@autoreleasepool {
|
||||
[self startWorkslice];
|
||||
amountConverted = [self convert:writeBuf amount:CHUNK_SIZE];
|
||||
[self endWorkslice];
|
||||
}
|
||||
if(!amountConverted) {
|
||||
if(paused) {
|
||||
|
|
|
@ -189,9 +189,7 @@ static void *kInputNodeContext = &kInputNodeContext;
|
|||
int framesToRead = CHUNK_SIZE - amountInBuffer;
|
||||
int framesRead;
|
||||
@autoreleasepool {
|
||||
[self startWorkslice];
|
||||
framesRead = [decoder readAudio:((char *)inputBuffer) + bytesInBuffer frames:framesToRead];
|
||||
[self endWorkslice];
|
||||
}
|
||||
|
||||
if(framesRead > 0 && !seekError) {
|
||||
|
|
|
@ -29,15 +29,10 @@
|
|||
BOOL shouldContinue;
|
||||
BOOL endOfStream; // All data is now in buffer
|
||||
BOOL initialBufferFilled;
|
||||
BOOL isRealtime, isRealtimeError, isDeadlineError; // If was successfully set realtime, or if error
|
||||
|
||||
AudioStreamBasicDescription nodeFormat;
|
||||
uint32_t nodeChannelConfig;
|
||||
BOOL nodeLossless;
|
||||
|
||||
int64_t intervalMachLength;
|
||||
os_workgroup_interval_t workgroup, wg;
|
||||
os_workgroup_join_token_s wgToken;
|
||||
}
|
||||
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
||||
|
||||
|
@ -49,11 +44,6 @@
|
|||
- (void)process; // Should be overwriten by subclass
|
||||
- (void)threadEntry:(id _Nullable)arg;
|
||||
|
||||
- (BOOL)followWorkgroup;
|
||||
- (void)leaveWorkgroup;
|
||||
- (void)startWorkslice;
|
||||
- (void)endWorkslice;
|
||||
|
||||
- (void)launchThread;
|
||||
|
||||
- (void)setShouldReset:(BOOL)s;
|
||||
|
|
|
@ -131,19 +131,6 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
|
|||
nodeChannelConfig = 0;
|
||||
nodeLossless = NO;
|
||||
|
||||
if(@available(macOS 12, *)) {
|
||||
// Get the mach time info.
|
||||
struct mach_timebase_info timeBaseInfo;
|
||||
mach_timebase_info(&timeBaseInfo);
|
||||
|
||||
// The frequency of the clock is: (timeBaseInfo.denom / timeBaseInfo.numer) * kOneNanosecond
|
||||
const double nanoSecFrequency = (double)(timeBaseInfo.denom) / (double)(timeBaseInfo.numer);
|
||||
const double frequency = nanoSecFrequency * kOneNanosecond;
|
||||
|
||||
// Convert the interval time in seconds to mach time length.
|
||||
intervalMachLength = (int64_t)(kIOIntervalTime * frequency);
|
||||
}
|
||||
|
||||
[self setPreviousNode:p];
|
||||
}
|
||||
|
||||
|
@ -205,79 +192,7 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
|
|||
|
||||
- (void)threadEntry:(id)arg {
|
||||
@autoreleasepool {
|
||||
if([self followWorkgroup]) {
|
||||
[self process];
|
||||
[self leaveWorkgroup];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)followWorkgroup {
|
||||
if(@available(macOS 12, *)) {
|
||||
if(!wg) {
|
||||
if(!workgroup) {
|
||||
workgroup = AudioWorkIntervalCreate([[NSString stringWithFormat:@"%@ Work Interval %@", [self className], self] UTF8String], clockId, &attr);
|
||||
isRealtimeError = !SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self()));
|
||||
isRealtime = !isRealtimeError;
|
||||
}
|
||||
wg = workgroup;
|
||||
if(wg && !isRealtimeError) {
|
||||
int result = os_workgroup_join(wg, &wgToken);
|
||||
isDeadlineError = NO;
|
||||
if(result == 0) return YES;
|
||||
if(result == EALREADY) {
|
||||
DLog(@"Thread already in workgroup");
|
||||
return NO;
|
||||
} else {
|
||||
DLog(@"Cannot join workgroup, error %d", result);
|
||||
isRealtimeError = YES;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
return wg != nil && !isRealtimeError;
|
||||
} else {
|
||||
if(!isRealtime && !isRealtimeError) {
|
||||
isRealtimeError = SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self()));
|
||||
isRealtime = !isRealtimeError;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)leaveWorkgroup {
|
||||
if(@available(macOS 12, *)) {
|
||||
if(wg && wgToken.sig && !isRealtimeError) {
|
||||
os_workgroup_leave(wg, &wgToken);
|
||||
bzero(&wgToken, sizeof(wgToken));
|
||||
wg = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startWorkslice {
|
||||
if(@available(macOS 12, *)) {
|
||||
if(wg && !isRealtimeError && !isDeadlineError) {
|
||||
const uint64_t currentTime = mach_absolute_time();
|
||||
const uint64_t deadline = currentTime + intervalMachLength;
|
||||
int result = os_workgroup_interval_start(wg, currentTime, deadline, nil);
|
||||
if(result != 0) {
|
||||
DLog(@"Deadline error = %d", result);
|
||||
isDeadlineError = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)endWorkslice {
|
||||
if(@available(macOS 12, *)) {
|
||||
if(wg && !isRealtimeError && !isDeadlineError) {
|
||||
int result = os_workgroup_interval_finish(wg, nil);
|
||||
if(result != 0) {
|
||||
DLog(@"Deadline end error = %d", result);
|
||||
isDeadlineError = YES;
|
||||
}
|
||||
}
|
||||
[self process];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue