From 120a93465e636de8e1b5498973c064dafc424fdc Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 12 Jun 2022 19:43:41 -0700 Subject: [PATCH] [Metadata Handling] Fix dynamic info updates Ensure that dynamic info updates, even on static files, only update the exact track they apply to, by atomically assigning the userInfo property before opening the decoder, so that callbacks to the player indicate the correct track and don't assume it's the one that's currently visibly playing. Fixes start of track metadata notifications from overwriting the previously playing track. Signed-off-by: Christopher Snowhill --- Audio/AudioPlayer.m | 11 +++-------- Audio/Chain/BufferChain.h | 5 +++-- Audio/Chain/BufferChain.m | 8 ++++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 21253b581..f5d366a45 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -83,7 +83,7 @@ bufferChain = [[BufferChain alloc] initWithController:self]; [self notifyStreamChanged:userInfo]; - while(![bufferChain open:url withOutputFormat:[output format] withOutputConfig:[output config] withRGInfo:rgi]) { + while(![bufferChain open:url withOutputFormat:[output format] withOutputConfig:[output config] withUserInfo:userInfo withRGInfo:rgi]) { bufferChain = nil; [self requestNextStream:userInfo]; @@ -101,8 +101,6 @@ bufferChain = [[BufferChain alloc] initWithController:self]; } - [bufferChain setUserInfo:userInfo]; - if(time > 0.0) { [output seek:time]; [bufferChain seek:time]; @@ -276,8 +274,6 @@ } - (void)addChainToQueue:(BufferChain *)newChain { - [newChain setUserInfo:nextStreamUserInfo]; - [newChain setShouldContinue:YES]; [newChain launchThreads]; @@ -365,9 +361,8 @@ } if(pathsEqual || ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]] && (([nextStream host] == nil && [[lastChain streamURL] host] == nil) || [[nextStream host] isEqualToString:[[lastChain streamURL] host]]) && [[nextStream path] isEqualToString:[[lastChain streamURL] path]])) { - if([lastChain setTrack:nextStream] && [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format] withOutputConfig:[output config] withRGInfo:nextStreamRGInfo]) { + if([lastChain setTrack:nextStream] && [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format] withOutputConfig:[output config] withUserInfo:nextStreamUserInfo withRGInfo:nextStreamRGInfo]) { [newChain setStreamURL:nextStream]; - [newChain setUserInfo:nextStreamUserInfo]; [self addChainToQueue:newChain]; DLog(@"TRACK SET!!! %@", newChain); @@ -381,7 +376,7 @@ lastChain = nil; - while(shouldContinue && ![newChain open:nextStream withOutputFormat:[output format] withOutputConfig:[output config] withRGInfo:nextStreamRGInfo]) { + while(shouldContinue && ![newChain open:nextStream withOutputFormat:[output format] withOutputConfig:[output config] withUserInfo:nextStreamUserInfo withRGInfo:nextStreamRGInfo]) { if(nextStream == nil) { newChain = nil; atomic_fetch_sub(&refCount, 1); diff --git a/Audio/Chain/BufferChain.h b/Audio/Chain/BufferChain.h index 8eb35a922..c2ae80961 100644 --- a/Audio/Chain/BufferChain.h +++ b/Audio/Chain/BufferChain.h @@ -28,15 +28,16 @@ - (id)initWithController:(id)c; - (void)buildChain; -- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withRGInfo:(NSDictionary *)rgi; +- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi; // Used when changing tracks to reuse the same decoder -- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withRGInfo:(NSDictionary *)rgi; +- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi; // Used when resetting the decoder on seek - (BOOL)openWithDecoder:(id)decoder withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig + withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi; - (void)seek:(double)time; diff --git a/Audio/Chain/BufferChain.m b/Audio/Chain/BufferChain.m index 1362d9ad5..62f1781b7 100644 --- a/Audio/Chain/BufferChain.m +++ b/Audio/Chain/BufferChain.m @@ -40,8 +40,9 @@ finalNode = converterNode; } -- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withRGInfo:(NSDictionary *)rgi { +- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi { [self setStreamURL:url]; + [self setUserInfo:userInfo]; [self buildChain]; @@ -81,8 +82,9 @@ return YES; } -- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withRGInfo:(NSDictionary *)rgi { +- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi { DLog(@"New buffer chain!"); + [self setUserInfo:userInfo]; [self buildChain]; if(![inputNode openWithDecoder:[i decoder]]) @@ -113,9 +115,11 @@ - (BOOL)openWithDecoder:(id)decoder withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputConfig:(uint32_t)outputConfig + withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi; { DLog(@"New buffer chain!"); + [self setUserInfo:userInfo]; [self buildChain]; if(![inputNode openWithDecoder:decoder])