mamburu: Fix for a crash caused by some weird flacs that have multiple STREAMINFO metadata blocks with wrong values

CQTexperiment
Chris Moeller 2013-10-11 07:25:41 -07:00
parent d5573c1e14
commit 613c71c41f
2 changed files with 16 additions and 6 deletions

View File

@ -29,6 +29,8 @@
int channels;
float frequency;
long totalFrames;
BOOL hasStreamInfo;
}
- (void)setSource:(id<CogSource>)s;

View File

@ -148,18 +148,26 @@ FLAC__StreamDecoderWriteStatus WriteCallback(const FLAC__StreamDecoder *decoder,
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)
{
// 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->channels = metadata->data.stream_info.channels;
flacDecoder->frequency = metadata->data.stream_info.sample_rate;
flacDecoder->bitsPerSample = metadata->data.stream_info.bits_per_sample;
if (!flacDecoder->hasStreamInfo) {
flacDecoder->channels = metadata->data.stream_info.channels;
flacDecoder->frequency = metadata->data.stream_info.sample_rate;
flacDecoder->bitsPerSample = metadata->data.stream_info.bits_per_sample;
flacDecoder->totalFrames = metadata->data.stream_info.total_samples;
flacDecoder->totalFrames = metadata->data.stream_info.total_samples;
[flacDecoder willChangeValueForKey:@"properties"];
[flacDecoder didChangeValueForKey:@"properties"];
[flacDecoder willChangeValueForKey:@"properties"];
[flacDecoder didChangeValueForKey:@"properties"];
flacDecoder->hasStreamInfo = YES;
}
}
void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)