[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 <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-12 19:43:41 -07:00
parent e84065ff5c
commit 120a93465e
3 changed files with 12 additions and 12 deletions

View File

@ -83,7 +83,7 @@
bufferChain = [[BufferChain alloc] initWithController:self]; bufferChain = [[BufferChain alloc] initWithController:self];
[self notifyStreamChanged:userInfo]; [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; bufferChain = nil;
[self requestNextStream:userInfo]; [self requestNextStream:userInfo];
@ -101,8 +101,6 @@
bufferChain = [[BufferChain alloc] initWithController:self]; bufferChain = [[BufferChain alloc] initWithController:self];
} }
[bufferChain setUserInfo:userInfo];
if(time > 0.0) { if(time > 0.0) {
[output seek:time]; [output seek:time];
[bufferChain seek:time]; [bufferChain seek:time];
@ -276,8 +274,6 @@
} }
- (void)addChainToQueue:(BufferChain *)newChain { - (void)addChainToQueue:(BufferChain *)newChain {
[newChain setUserInfo:nextStreamUserInfo];
[newChain setShouldContinue:YES]; [newChain setShouldContinue:YES];
[newChain launchThreads]; [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(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 setStreamURL:nextStream];
[newChain setUserInfo:nextStreamUserInfo];
[self addChainToQueue:newChain]; [self addChainToQueue:newChain];
DLog(@"TRACK SET!!! %@", newChain); DLog(@"TRACK SET!!! %@", newChain);
@ -381,7 +376,7 @@
lastChain = nil; 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) { if(nextStream == nil) {
newChain = nil; newChain = nil;
atomic_fetch_sub(&refCount, 1); atomic_fetch_sub(&refCount, 1);

View File

@ -28,15 +28,16 @@
- (id)initWithController:(id)c; - (id)initWithController:(id)c;
- (void)buildChain; - (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 // 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 // Used when resetting the decoder on seek
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder - (BOOL)openWithDecoder:(id<CogDecoder>)decoder
withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputFormat:(AudioStreamBasicDescription)outputFormat
withOutputConfig:(uint32_t)outputConfig withOutputConfig:(uint32_t)outputConfig
withUserInfo:(id)userInfo
withRGInfo:(NSDictionary *)rgi; withRGInfo:(NSDictionary *)rgi;
- (void)seek:(double)time; - (void)seek:(double)time;

View File

@ -40,8 +40,9 @@
finalNode = converterNode; 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 setStreamURL:url];
[self setUserInfo:userInfo];
[self buildChain]; [self buildChain];
@ -81,8 +82,9 @@
return YES; 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!"); DLog(@"New buffer chain!");
[self setUserInfo:userInfo];
[self buildChain]; [self buildChain];
if(![inputNode openWithDecoder:[i decoder]]) if(![inputNode openWithDecoder:[i decoder]])
@ -113,9 +115,11 @@
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder - (BOOL)openWithDecoder:(id<CogDecoder>)decoder
withOutputFormat:(AudioStreamBasicDescription)outputFormat withOutputFormat:(AudioStreamBasicDescription)outputFormat
withOutputConfig:(uint32_t)outputConfig withOutputConfig:(uint32_t)outputConfig
withUserInfo:(id)userInfo
withRGInfo:(NSDictionary *)rgi; withRGInfo:(NSDictionary *)rgi;
{ {
DLog(@"New buffer chain!"); DLog(@"New buffer chain!");
[self setUserInfo:userInfo];
[self buildChain]; [self buildChain];
if(![inputNode openWithDecoder:decoder]) if(![inputNode openWithDecoder:decoder])