diff options
author | Sven Gothel <[email protected]> | 2023-10-15 07:10:15 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-10-15 07:10:15 +0200 |
commit | 2c80bb2e6eb12e155d747daf8a08362396d5e0fc (patch) | |
tree | d7c2d4854b281ef6b412490e46f6ae8c5956ee78 /src/jogl/native/libav/ffmpeg_impl_template.c | |
parent | b1956113f5601b0cc6ac525d3918a0dfa8d240af (diff) |
Bug 1472: Enhance GLMediaPlayer AV Sync: Fix FFMPEGMediaPlayer's audio resample: Use swr_get_out_samples(..) to calculate the required output sample count
Notable when playing audio with e.g. 24k sample rate on a 48k OpenAL ALAudioSink,
the sample duration was cut in half due to erroneous resampling missing half the required samples.
Using swr_get_out_samples(..) resolves this issue pre swr_convert(..), the resampling.
Diffstat (limited to 'src/jogl/native/libav/ffmpeg_impl_template.c')
-rw-r--r-- | src/jogl/native/libav/ffmpeg_impl_template.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/jogl/native/libav/ffmpeg_impl_template.c b/src/jogl/native/libav/ffmpeg_impl_template.c index e37347e3a..6141b4519 100644 --- a/src/jogl/native/libav/ffmpeg_impl_template.c +++ b/src/jogl/native/libav/ffmpeg_impl_template.c @@ -170,13 +170,15 @@ typedef struct SwrContext *(APIENTRYP SWR_ALLOC)(void); typedef int (APIENTRYP SWR_INIT)(struct SwrContext *s); typedef void (APIENTRYP SWR_FREE)(struct SwrContext **s); typedef int (APIENTRYP SWR_CONVERT)(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count); +typedef int (APIENTRYP SWR_GET_OUT_SAMPLES)(struct SwrContext *s, int in_samples); static AV_OPT_SET_SAMPLE_FMT sp_av_opt_set_sample_fmt; static SWR_ALLOC sp_swr_alloc; static SWR_INIT sp_swr_init; static SWR_FREE sp_swr_free; static SWR_CONVERT sp_swr_convert; -// count: +5 = 59 +static SWR_GET_OUT_SAMPLES sp_swr_get_out_samples; +// count: +6 = 60 // We use JNI Monitor Locking, since this removes the need // to statically link-in pthreads on window .. @@ -200,7 +202,7 @@ static SWR_CONVERT sp_swr_convert; #define MY_MUTEX_UNLOCK(e,s) #endif -#define SYMBOL_COUNT 59 +#define SYMBOL_COUNT 60 JNIEXPORT jboolean JNICALL FF_FUNC(initSymbols0) (JNIEnv *env, jobject instance, jobject jmutex_avcodec_openclose, jobject jSymbols, jint count) @@ -285,6 +287,7 @@ JNIEXPORT jboolean JNICALL FF_FUNC(initSymbols0) sp_swr_init = (SWR_INIT) (intptr_t) symbols[i++]; sp_swr_free = (SWR_FREE) (intptr_t) symbols[i++]; sp_swr_convert = (SWR_CONVERT) (intptr_t) symbols[i++]; + sp_swr_get_out_samples = (SWR_GET_OUT_SAMPLES) (intptr_t) symbols[i++]; (*env)->ReleasePrimitiveArrayCritical(env, jSymbols, symbols, 0); @@ -1337,7 +1340,7 @@ JNIEXPORT jint JNICALL FF_FUNC(readNextPacket0) uint8_t *tmp_out; int out_samples=-1, out_size, out_linesize; int osize = sp_av_get_bytes_per_sample( pAV->aSampleFmtOut ); - int nb_samples = pAFrameCurrent->nb_samples; + int nb_samples = sp_swr_get_out_samples(pAV->swResampleCtx, pAFrameCurrent->nb_samples); out_size = sp_av_samples_get_buffer_size(&out_linesize, pAV->aChannelsOut, |