mirror of https://github.com/mgba-emu/mgba.git
FFmpeg: Fix overflow and general issues with audio encoding
This commit is contained in:
parent
f36caedb95
commit
f2ce0d11dc
1
CHANGES
1
CHANGES
|
@ -17,6 +17,7 @@ Bugfixes:
|
||||||
- Windows: Fix VDir.rewind
|
- Windows: Fix VDir.rewind
|
||||||
- SDL: Fix game crash check
|
- SDL: Fix game crash check
|
||||||
- SDL: Fix race condition with audio thread when starting
|
- SDL: Fix race condition with audio thread when starting
|
||||||
|
- FFmpeg: Fix overflow and general issues with audio encoding
|
||||||
Misc:
|
Misc:
|
||||||
- Qt: Improved HiDPI support
|
- Qt: Improved HiDPI support
|
||||||
- Feature: Support ImageMagick 7
|
- Feature: Support ImageMagick 7
|
||||||
|
|
|
@ -389,27 +389,27 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
|
||||||
encoder->audioBuffer[encoder->currentAudioSample * 2] = left;
|
encoder->audioBuffer[encoder->currentAudioSample * 2] = left;
|
||||||
encoder->audioBuffer[encoder->currentAudioSample * 2 + 1] = right;
|
encoder->audioBuffer[encoder->currentAudioSample * 2 + 1] = right;
|
||||||
|
|
||||||
++encoder->currentAudioFrame;
|
|
||||||
++encoder->currentAudioSample;
|
++encoder->currentAudioSample;
|
||||||
|
|
||||||
if ((encoder->currentAudioSample * 4) < encoder->audioBufferSize) {
|
if (encoder->currentAudioSample * 4 < encoder->audioBufferSize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int channelSize = 2 * av_get_bytes_per_sample(encoder->audio->sample_fmt);
|
int channelSize = 2 * av_get_bytes_per_sample(encoder->audio->sample_fmt);
|
||||||
avresample_convert(encoder->resampleContext,
|
avresample_convert(encoder->resampleContext, 0, 0, 0,
|
||||||
0, 0, 0,
|
|
||||||
(uint8_t**) &encoder->audioBuffer, 0, encoder->audioBufferSize / 4);
|
(uint8_t**) &encoder->audioBuffer, 0, encoder->audioBufferSize / 4);
|
||||||
|
|
||||||
|
encoder->currentAudioSample = 0;
|
||||||
if (avresample_available(encoder->resampleContext) < encoder->audioFrame->nb_samples) {
|
if (avresample_available(encoder->resampleContext) < encoder->audioFrame->nb_samples) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||||
av_frame_make_writable(encoder->audioFrame);
|
av_frame_make_writable(encoder->audioFrame);
|
||||||
#endif
|
#endif
|
||||||
avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize);
|
int samples = avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize);
|
||||||
|
|
||||||
encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame - encoder->currentAudioSample, encoder->audio->time_base, encoder->audioStream->time_base);
|
encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame, encoder->audio->time_base, encoder->audioStream->time_base);
|
||||||
encoder->currentAudioSample = 0;
|
encoder->currentAudioFrame += samples;
|
||||||
|
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
av_init_packet(&packet);
|
av_init_packet(&packet);
|
||||||
|
|
Loading…
Reference in New Issue