mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-05 19:28:46 +02:00
Fix resample
This commit is contained in:
parent
4464802051
commit
da1629328f
1 changed files with 23 additions and 8 deletions
|
|
@ -111,22 +111,37 @@
|
|||
return nil;
|
||||
}
|
||||
|
||||
int64_t outSamples = (int64_t)frameImpl->nb_samples * (int64_t)_ratio;
|
||||
// Cap at 8M samples per frame: ~10× larger than any legitimate codec
|
||||
// frame × resample ratio, bounds the per-frame buffer to ~32 MB (s16 stereo),
|
||||
// and rejects pathological inputs (e.g. 1 Hz source with a 65 KB FLAC block).
|
||||
if (outSamples <= 0 || outSamples > 8 * 1024 * 1024) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
int bufSize = av_samples_get_buffer_size(NULL,
|
||||
(int)_destinationChannelCount,
|
||||
frameImpl->nb_samples * (int)_ratio,
|
||||
(int)outSamples,
|
||||
(enum AVSampleFormat)_destinationSampleFormat,
|
||||
1);
|
||||
|
||||
if (!_buffer || _bufferSize < bufSize) {
|
||||
_bufferSize = bufSize;
|
||||
_buffer = realloc(_buffer, _bufferSize);
|
||||
if (bufSize <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
if (!_buffer || _bufferSize < bufSize) {
|
||||
void *newBuffer = realloc(_buffer, bufSize);
|
||||
if (!newBuffer) {
|
||||
return nil;
|
||||
}
|
||||
_buffer = newBuffer;
|
||||
_bufferSize = bufSize;
|
||||
}
|
||||
|
||||
Byte *outbuf[2] = { _buffer, 0 };
|
||||
|
||||
|
||||
int numFrames = swr_convert(_context,
|
||||
outbuf,
|
||||
frameImpl->nb_samples * (int)_ratio,
|
||||
(int)outSamples,
|
||||
(const uint8_t **)frameImpl->data,
|
||||
frameImpl->nb_samples);
|
||||
if (numFrames <= 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue