mamburu: Fix for a crash caused by some weird flacs that have multiple STREAMINFO metadata blocks with wrong values
parent
d5573c1e14
commit
613c71c41f
|
@ -29,6 +29,8 @@
|
||||||
int channels;
|
int channels;
|
||||||
float frequency;
|
float frequency;
|
||||||
long totalFrames;
|
long totalFrames;
|
||||||
|
|
||||||
|
BOOL hasStreamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSource:(id<CogSource>)s;
|
- (void)setSource:(id<CogSource>)s;
|
||||||
|
|
|
@ -148,10 +148,15 @@ FLAC__StreamDecoderWriteStatus WriteCallback(const FLAC__StreamDecoder *decoder,
|
||||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This callback is only called for STREAMINFO blocks
|
||||||
void MetadataCallback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
|
void MetadataCallback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
|
||||||
{
|
{
|
||||||
|
// Some flacs observed in the wild have multiple STREAMINFO metadata blocks,
|
||||||
|
// of which only first one has sane values, so only use values from the first STREAMINFO
|
||||||
|
// to determine stream format (this seems to be consistent with flac spec: http://flac.sourceforge.net/format.html)
|
||||||
FlacDecoder *flacDecoder = (FlacDecoder *)client_data;
|
FlacDecoder *flacDecoder = (FlacDecoder *)client_data;
|
||||||
|
|
||||||
|
if (!flacDecoder->hasStreamInfo) {
|
||||||
flacDecoder->channels = metadata->data.stream_info.channels;
|
flacDecoder->channels = metadata->data.stream_info.channels;
|
||||||
flacDecoder->frequency = metadata->data.stream_info.sample_rate;
|
flacDecoder->frequency = metadata->data.stream_info.sample_rate;
|
||||||
flacDecoder->bitsPerSample = metadata->data.stream_info.bits_per_sample;
|
flacDecoder->bitsPerSample = metadata->data.stream_info.bits_per_sample;
|
||||||
|
@ -160,6 +165,9 @@ void MetadataCallback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMeta
|
||||||
|
|
||||||
[flacDecoder willChangeValueForKey:@"properties"];
|
[flacDecoder willChangeValueForKey:@"properties"];
|
||||||
[flacDecoder didChangeValueForKey:@"properties"];
|
[flacDecoder didChangeValueForKey:@"properties"];
|
||||||
|
|
||||||
|
flacDecoder->hasStreamInfo = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
|
void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
|
||||||
|
|
Loading…
Reference in New Issue