Audio desync fixed (I hope). Start of Pi build.
This commit is contained in:
parent
675e54462b
commit
dc5f3e6716
4 changed files with 27 additions and 13 deletions
|
@ -21,9 +21,10 @@
|
||||||
|
|
||||||
|
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
G_PLATFORM=mingw
|
G_PLATFORM=pi
|
||||||
|
# G_PLATFORM=mingw
|
||||||
# G_PLATFORM=linux
|
# G_PLATFORM=linux
|
||||||
G_BITS=64
|
G_BITS=32
|
||||||
G_THIRDPARTY=$(pwd)/thirdparty
|
G_THIRDPARTY=$(pwd)/thirdparty
|
||||||
G_DEST="$(pwd)/../thirdparty-build/${G_PLATFORM}/${G_BITS}"
|
G_DEST="$(pwd)/../thirdparty-build/${G_PLATFORM}/${G_BITS}"
|
||||||
else
|
else
|
||||||
|
@ -38,6 +39,16 @@ G_L="---------------------------------------------------------------------------
|
||||||
|
|
||||||
# Work out compiler settings
|
# Work out compiler settings
|
||||||
case "${G_PLATFORM}" in
|
case "${G_PLATFORM}" in
|
||||||
|
pi)
|
||||||
|
G_CROSS_HOME="/opt/cross/pi/32bit/bin"
|
||||||
|
G_OS="linux"
|
||||||
|
G_CCOMPILER="${G_CROSS_HOME}/arm-unknown-linux-gnueabi-gcc"
|
||||||
|
G_CPPCOMPILER="${G_CROSS_HOME}/arm-unknown-linux-gnueabi-g++"
|
||||||
|
G_CROSS="arm-unknown-linux-gnueabi"
|
||||||
|
G_LUAPLAT="posix"
|
||||||
|
G_ARCH="armv6"
|
||||||
|
;;
|
||||||
|
|
||||||
linux)
|
linux)
|
||||||
G_OS="linux"
|
G_OS="linux"
|
||||||
G_CCOMPILER="gcc"
|
G_CCOMPILER="gcc"
|
||||||
|
@ -315,7 +326,7 @@ autoBuild libFLAC.a SDL2_mixer/external/flac-1.3.3
|
||||||
autoBuild libvorbis.a SDL2_mixer/external/libvorbis-1.3.6
|
autoBuild libvorbis.a SDL2_mixer/external/libvorbis-1.3.6
|
||||||
|
|
||||||
# === ModPlug ===
|
# === ModPlug ===
|
||||||
autoBuild libmodplug.a SDL2_mixer/external/libmodplug-0.8.9.0
|
autoBuild libmodplug.a SDL2_mixer/external/libmodplug-0.8.9.0 "ac_cv_c_bigendian=no"
|
||||||
|
|
||||||
# === MPG123 ===
|
# === MPG123 ===
|
||||||
autoBuild libmpg123.a SDL2_mixer/external/mpg123-1.25.13
|
autoBuild libmpg123.a SDL2_mixer/external/mpg123-1.25.13
|
||||||
|
|
|
@ -667,8 +667,8 @@ distclean-generic:
|
||||||
maintainer-clean-generic:
|
maintainer-clean-generic:
|
||||||
@echo "This command is intended for maintainers to use"
|
@echo "This command is intended for maintainers to use"
|
||||||
@echo "it deletes files that may require special tools to rebuild."
|
@echo "it deletes files that may require special tools to rebuild."
|
||||||
@FLaC__HAS_DOXYGEN_FALSE@install-data-local:
|
|
||||||
@FLaC__HAS_DOXYGEN_FALSE@distclean-local:
|
@FLaC__HAS_DOXYGEN_FALSE@distclean-local:
|
||||||
|
@FLaC__HAS_DOXYGEN_FALSE@install-data-local:
|
||||||
@FLaC__HAS_DOXYGEN_FALSE@uninstall-local:
|
@FLaC__HAS_DOXYGEN_FALSE@uninstall-local:
|
||||||
clean: clean-recursive
|
clean: clean-recursive
|
||||||
|
|
||||||
|
|
|
@ -394,9 +394,9 @@ distclean-generic:
|
||||||
maintainer-clean-generic:
|
maintainer-clean-generic:
|
||||||
@echo "This command is intended for maintainers to use"
|
@echo "This command is intended for maintainers to use"
|
||||||
@echo "it deletes files that may require special tools to rebuild."
|
@echo "it deletes files that may require special tools to rebuild."
|
||||||
@HAVE_DOXYGEN_FALSE@clean-local:
|
|
||||||
@HAVE_DOXYGEN_FALSE@uninstall-local:
|
|
||||||
@HAVE_DOXYGEN_FALSE@install-data-local:
|
@HAVE_DOXYGEN_FALSE@install-data-local:
|
||||||
|
@HAVE_DOXYGEN_FALSE@uninstall-local:
|
||||||
|
@HAVE_DOXYGEN_FALSE@clean-local:
|
||||||
clean: clean-am
|
clean: clean-am
|
||||||
|
|
||||||
clean-am: clean-generic clean-libtool clean-local mostlyclean-am
|
clean-am: clean-generic clean-libtool clean-local mostlyclean-am
|
||||||
|
|
|
@ -56,6 +56,7 @@ typedef struct VideoPlayerS {
|
||||||
int64_t frameDeltaTime;
|
int64_t frameDeltaTime;
|
||||||
int64_t lastFrameTime;
|
int64_t lastFrameTime;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
|
int64_t audioDelta;
|
||||||
int64_t audioPosition;
|
int64_t audioPosition;
|
||||||
Uint16 audioFormat;
|
Uint16 audioFormat;
|
||||||
Uint32 lastTickTime;
|
Uint32 lastTickTime;
|
||||||
|
@ -542,12 +543,14 @@ int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture) {
|
||||||
int64_t count = 0;
|
int64_t count = 0;
|
||||||
VideoPlayerT *v = NULL;
|
VideoPlayerT *v = NULL;
|
||||||
|
|
||||||
|
|
||||||
// Get our player structure
|
// Get our player structure
|
||||||
HASH_FIND_INT(_videoPlayerHash, &playerHandle, v);
|
HASH_FIND_INT(_videoPlayerHash, &playerHandle, v);
|
||||||
if (!v) utilDie("No video player at index %d in videoUpdate.", playerHandle);
|
if (!v) utilDie("No video player at index %d in videoUpdate.", playerHandle);
|
||||||
|
|
||||||
// Handle video frames (and time)
|
// Handle video frames (and time)
|
||||||
if ((SDL_GetTicks() - v->lastTickTime >= v->frameDeltaTime) || v->resetTime) {
|
if ((SDL_GetTicks() - v->lastTickTime >= v->frameDeltaTime) || (v->audioDelta > (v->audioProps->SampleRate / 2)) || v->resetTime) {
|
||||||
|
|
||||||
v->lastTickTime = SDL_GetTicks();
|
v->lastTickTime = SDL_GetTicks();
|
||||||
|
|
||||||
if (v->frameData) {
|
if (v->frameData) {
|
||||||
|
@ -557,10 +560,13 @@ int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture) {
|
||||||
*texture = v->videoTexture;
|
*texture = v->videoTexture;
|
||||||
result = v->frame;
|
result = v->frame;
|
||||||
|
|
||||||
|
// Used to determine if we should play two frames rapidly to catch up to audio
|
||||||
|
v->audioDelta = v->audioPosition - (int64_t)((double)v->timestamp * 0.001 * (double)v->audioProps->SampleRate);
|
||||||
|
|
||||||
v->frameData = FFMS_GetFrame(v->videoSource, v->frame, &v->errInfo);
|
v->frameData = FFMS_GetFrame(v->videoSource, v->frame, &v->errInfo);
|
||||||
if (v->frameData == NULL) utilDie("%s", v->errInfo.Buffer);
|
if (v->frameData == NULL) utilDie("%s", v->errInfo.Buffer);
|
||||||
v->frameInfo = FFMS_GetFrameInfo(FFMS_GetTrackFromVideo(v->videoSource), v->frame);
|
v->frameInfo = FFMS_GetFrameInfo(FFMS_GetTrackFromVideo(v->videoSource), v->frame);
|
||||||
v->timestamp = (int64_t)((v->frameInfo->PTS * v->videoTimeBase->Num) / (double)v->videoTimeBase->Den); // Convert to milliseconds
|
v->timestamp = (int64_t)((double)v->frameInfo->PTS * (double)v->videoTimeBase->Num / (double)v->videoTimeBase->Den); // Convert to milliseconds
|
||||||
v->frameDeltaTime = v->timestamp - v->lastFrameTime;
|
v->frameDeltaTime = v->timestamp - v->lastFrameTime;
|
||||||
v->lastFrameTime = v->timestamp;
|
v->lastFrameTime = v->timestamp;
|
||||||
|
|
||||||
|
@ -576,8 +582,9 @@ int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture) {
|
||||||
SDL_AudioStreamClear(v->audioStream);
|
SDL_AudioStreamClear(v->audioStream);
|
||||||
v->lastTickTime = 0;
|
v->lastTickTime = 0;
|
||||||
v->frameDeltaTime = 0;
|
v->frameDeltaTime = 0;
|
||||||
v->audioPosition = (int64_t)((double)(v->timestamp * 0.001) * (double)v->audioProps->SampleRate);
|
v->audioPosition = (int64_t)((double)v->timestamp * 0.001 * (double)v->audioProps->SampleRate);
|
||||||
v->resetTime = false;
|
v->resetTime = false;
|
||||||
|
v->audioDelta = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,10 +602,6 @@ int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture) {
|
||||||
if (FFMS_GetAudio(v->audioSource, v->audioBuffer, v->audioPosition, count, &v->errInfo)) utilDie("%s", v->errInfo.Buffer);
|
if (FFMS_GetAudio(v->audioSource, v->audioBuffer, v->audioPosition, count, &v->errInfo)) utilDie("%s", v->errInfo.Buffer);
|
||||||
// Feed it to the mixer stream
|
// Feed it to the mixer stream
|
||||||
if (SDL_AudioStreamPut(v->audioStream, v->audioBuffer, (int32_t)(count * v->audioSampleSize)) < 0) utilDie("%s", SDL_GetError());
|
if (SDL_AudioStreamPut(v->audioStream, v->audioBuffer, (int32_t)(count * v->audioSampleSize)) < 0) utilDie("%s", SDL_GetError());
|
||||||
|
|
||||||
//int64_t temp = (int64_t)((double)(v->timestamp * 0.001) * (double)v->audioProps->SampleRate);
|
|
||||||
//utilSay("A: %ld C: %ld D: %ld W: %ld", v->audioPosition, temp, v->audioPosition - temp, SDL_AudioStreamAvailable(v->audioStream));
|
|
||||||
|
|
||||||
v->audioPosition += count;
|
v->audioPosition += count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue