FFmpeg Input: Fix format changes

Format changes should only occur on whole packet intervals.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-02-07 19:37:06 -08:00
parent 90ce0e5ae4
commit 4fd24838fa
1 changed files with 18 additions and 14 deletions

View File

@ -553,6 +553,24 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence) {
seekBytesSkip -= minSkipped;
}
int _channels = codecCtx->channels;
uint32_t _channelConfig = (uint32_t)codecCtx->channel_layout;
float _frequency = codecCtx->sample_rate;
if(_channels != channels ||
_channelConfig != channelConfig ||
_frequency != frequency) {
if(bytesRead > 0) {
break;
} else {
channels = _channels;
channelConfig = _channelConfig;
frequency = _frequency;
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
}
}
int toConsume = FFMIN((dataSize - bytesConsumedFromDecodedFrame), (bytesToRead - bytesRead));
// copy decoded samples to Cog's buffer
@ -575,20 +593,6 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence) {
bytesRead += toConsume;
}
int _channels = codecCtx->channels;
uint32_t _channelConfig = (uint32_t)codecCtx->channel_layout;
float _frequency = codecCtx->sample_rate;
if(_channels != channels ||
_channelConfig != channelConfig ||
_frequency != frequency) {
channels = _channels;
channelConfig = _channelConfig;
frequency = _frequency;
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
}
int framesReadNow = bytesRead / frameSize;
if(totalFrames && (framesRead + framesReadNow > totalFrames))
framesReadNow = (int)(totalFrames - framesRead);