[Threading] Queue expensive actions outside audio
Use delayed dispatching on expensive operations which occur every time the "heard" track end happens, and when audio metadata is changed by a stream, so that they are inserted into the main thread queue after the invoking callback returns control execution back to the audio thread. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
4a0b337936
commit
eaa73bc52f
|
@ -580,16 +580,19 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
|
||||||
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo {
|
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo {
|
||||||
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
|
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
|
||||||
|
|
||||||
[playlistController setCurrentEntry:pe];
|
// Delay the action until this function has returned to the audio thread
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
|
||||||
|
[self->playlistController setCurrentEntry:pe];
|
||||||
|
|
||||||
if(_eq)
|
if(self->_eq)
|
||||||
equalizerApplyGenre(_eq, [pe genre]);
|
equalizerApplyGenre(self->_eq, [pe genre]);
|
||||||
|
|
||||||
lastPosition = -10;
|
self->lastPosition = -10;
|
||||||
|
|
||||||
[self setPosition:0];
|
[self setPosition:0];
|
||||||
|
|
||||||
[self removeHDCD:nil];
|
[self removeHDCD:nil];
|
||||||
|
});
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
||||||
}
|
}
|
||||||
|
@ -677,7 +680,10 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
|
||||||
if (!pe) pe = [playlistController currentEntry];
|
if (!pe) pe = [playlistController currentEntry];
|
||||||
[pe setMetadata:info];
|
[pe setMetadata:info];
|
||||||
[playlistView refreshCurrentTrack:self];
|
[playlistView refreshCurrentTrack:self];
|
||||||
[self sendMetaData];
|
// Delay the action until this function has returned to the audio thread
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
|
||||||
|
[self sendMetaData];
|
||||||
|
});
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue