[Inputs] Severely reduce metadata update intervals
The Vorbis, Opus, MAD MPEG, and especially the FFmpeg inputs needed to have their metadata update intervals severely reduced, to reduce CPU usage, especially on files with lots of tags. Interval reduced to only once per second. Signed-off-by: Christopher Snowhill <kode54@gmail.com>xcode15
parent
41e87e3830
commit
81d31dbe58
|
@ -43,6 +43,9 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence);
|
|||
AVFrame *lastDecodedFrame;
|
||||
AVPacket *lastReadPacket;
|
||||
|
||||
int metadataUpdateInterval;
|
||||
int metadataUpdateCount;
|
||||
|
||||
BOOL metadataUpdated;
|
||||
|
||||
AudioChunk *prebufferedChunk;
|
||||
|
|
|
@ -435,6 +435,9 @@ static uint8_t reverse_bits[0x100];
|
|||
endOfStream = NO;
|
||||
endOfAudio = NO;
|
||||
|
||||
metadataUpdateInterval = codecCtx->sample_rate;
|
||||
metadataUpdateCount = 0;
|
||||
|
||||
if(rawDSD) {
|
||||
totalFrames *= 8;
|
||||
}
|
||||
|
@ -899,14 +902,18 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
|
|||
}
|
||||
}
|
||||
|
||||
[self updateMetadata];
|
||||
|
||||
int framesReadNow = bytesRead / frameSize;
|
||||
if(totalFrames && (framesRead + framesReadNow > totalFrames))
|
||||
framesReadNow = (int)(totalFrames - framesRead);
|
||||
|
||||
framesRead += framesReadNow;
|
||||
|
||||
metadataUpdateCount += framesReadNow;
|
||||
if(metadataUpdateCount >= metadataUpdateInterval) {
|
||||
metadataUpdateCount -= metadataUpdateInterval;
|
||||
[self updateMetadata];
|
||||
}
|
||||
|
||||
id audioChunkClass = NSClassFromString(@"AudioChunk");
|
||||
AudioChunk *chunk = [[audioChunkClass alloc] initWithProperties:[self properties]];
|
||||
[chunk assignSamples:buffer frameCount:framesReadNow];
|
||||
|
|
|
@ -49,6 +49,9 @@
|
|||
long framesToSkip;
|
||||
int layer;
|
||||
|
||||
int metadataUpdateInterval;
|
||||
int metadataUpdateCount;
|
||||
|
||||
NSString *genre;
|
||||
NSString *album;
|
||||
NSString *artist;
|
||||
|
|
|
@ -461,6 +461,11 @@
|
|||
DLog(@"Decoding first frame: %i", r);
|
||||
} while(r == 0);
|
||||
|
||||
if(r != -1) {
|
||||
metadataUpdateInterval = sampleRate;
|
||||
metadataUpdateCount = 0;
|
||||
}
|
||||
|
||||
return (r == -1 ? NO : YES);
|
||||
}
|
||||
|
||||
|
@ -472,6 +477,9 @@
|
|||
framesToSkip = _startPadding;
|
||||
}
|
||||
|
||||
metadataUpdateInterval = sampleRate;
|
||||
metadataUpdateCount = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -730,7 +738,11 @@
|
|||
[self syncFormat];
|
||||
}
|
||||
|
||||
metadataUpdateCount += chunk ? [chunk frameCount] : 0;
|
||||
if(metadataUpdateCount >= metadataUpdateInterval) {
|
||||
metadataUpdateCount -= metadataUpdateInterval;
|
||||
[self updateMetadata];
|
||||
}
|
||||
|
||||
// DLog(@"Read: %i/%i", bytesRead, size);
|
||||
return chunk;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
int channels;
|
||||
long totalFrames;
|
||||
|
||||
int metadataUpdateInterval;
|
||||
int metadataUpdateCount;
|
||||
|
||||
NSDictionary *metaDict;
|
||||
NSDictionary *icyMetaDict;
|
||||
|
||||
|
|
|
@ -129,6 +129,9 @@ opus_int64 sourceTell(void *_stream) {
|
|||
|
||||
[self updateMetadata];
|
||||
|
||||
metadataUpdateInterval = 48000;
|
||||
metadataUpdateCount = 0;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -269,7 +272,11 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
|
|||
|
||||
} while(total != size && numread != 0);
|
||||
|
||||
metadataUpdateCount += total / channels;
|
||||
if(metadataUpdateCount >= metadataUpdateInterval) {
|
||||
metadataUpdateCount -= metadataUpdateInterval;
|
||||
[self updateIcyMetadata];
|
||||
}
|
||||
|
||||
id audioChunkClass = NSClassFromString(@"AudioChunk");
|
||||
AudioChunk *chunk = [[audioChunkClass alloc] initWithProperties:[self properties]];
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
float frequency;
|
||||
long totalFrames;
|
||||
|
||||
int metadataUpdateInterval;
|
||||
int metadataUpdateCount;
|
||||
|
||||
NSDictionary *metaDict;
|
||||
NSDictionary *icyMetaDict;
|
||||
|
||||
|
|
|
@ -109,6 +109,9 @@ long sourceTell(void *datasource) {
|
|||
|
||||
[self updateMetadata];
|
||||
|
||||
metadataUpdateInterval = frequency;
|
||||
metadataUpdateCount = 0;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -215,6 +218,9 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
|
|||
channels = vi->channels;
|
||||
frequency = vi->rate;
|
||||
|
||||
metadataUpdateInterval = frequency;
|
||||
metadataUpdateCount = 0;
|
||||
|
||||
[self willChangeValueForKey:@"properties"];
|
||||
[self didChangeValueForKey:@"properties"];
|
||||
|
||||
|
@ -254,7 +260,11 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
|
|||
|
||||
} while(total != frames && numread != 0);
|
||||
|
||||
metadataUpdateCount += total;
|
||||
if(metadataUpdateCount >= metadataUpdateInterval) {
|
||||
metadataUpdateCount -= metadataUpdateInterval;
|
||||
[self updateIcyMetadata];
|
||||
}
|
||||
|
||||
[chunk assignSamples:buffer frameCount:total];
|
||||
|
||||
|
|
Loading…
Reference in New Issue