1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Reduce number of frames dynamic allocation and fix leak

This commit is contained in:
Filip Gawin 2018-08-21 23:53:30 +02:00 committed by Daniel Evans
parent 6aa9b3a1b7
commit 3cd9c7722a

View File

@ -150,7 +150,7 @@ void SoundSource::loadFromFile(const rwfs::path& filePath) {
}
#else
AVFrame* resampled = nullptr;
AVFrame* resampled = av_frame_alloc();
while (av_read_frame(formatContext, &readingPacket) == 0) {
if (readingPacket.stream_index == audioStream->index) {
@ -191,7 +191,6 @@ void SoundSource::loadFromFile(const rwfs::path& filePath) {
// Decode audio packet
if (receiveFrame == 0 && sendPacket == 0) {
// Write samples to audio buffer
resampled = av_frame_alloc();
resampled->channel_layout = AV_CH_LAYOUT_STEREO;
resampled->sample_rate = frame->sample_rate;
resampled->format = kOutputFMT;
@ -216,6 +215,9 @@ void SoundSource::loadFromFile(const rwfs::path& filePath) {
}
}
/// Free all data used by the resampled frame.
av_frame_free(&resampled);
#endif
// Cleanup