From f23391578fb19204a6f2d064cefcb7023b1f58ec Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 14 Aug 2016 17:24:29 -0700 Subject: [PATCH 1/3] Psmf: Ignore stream size with old PsmfPlayer libs. Until 5.50, the stream size was not used. See #6574. --- Core/HLE/sceKernelModule.cpp | 7 ++++++ Core/HLE/scePsmf.cpp | 42 ++++++++++++++++++++++++------------ Core/HLE/scePsmf.h | 1 + 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 1e62f3b46ff1..db4a7f13b3e7 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -51,6 +51,7 @@ #include "Core/HLE/sceKernelThread.h" #include "Core/HLE/sceKernelMemory.h" #include "Core/HLE/sceMpeg.h" +#include "Core/HLE/scePsmf.h" #include "Core/HLE/sceIo.h" #include "Core/HLE/KernelWaitHelpers.h" #include "Core/ELF/ParamSFO.h" @@ -1065,6 +1066,9 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, bool fromT if (!strcmp(head->modname, "sceMpeg_library")) { __MpegLoadModule(ver); } + if (!strcmp(head->modname, "scePsmfP_library") || !strcmp(head->modname, "scePsmfPlayer")) { + __PsmfPlayerLoadModule(head->devkitversion); + } } const u8 *in = ptr; @@ -1421,6 +1425,9 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, bool fromT if (!strcmp(modinfo->name, "sceMpeg_library")) { __MpegLoadModule(modinfo->moduleVersion); } + if (!strcmp(modinfo->name, "scePsmfP_library") || !strcmp(modinfo->name, "scePsmfPlayer")) { + __PsmfPlayerLoadModule(devkitVersion); + } } error = 0; diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 5025dc36d2ac..2198d1f21ae3 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -50,10 +50,11 @@ const int PSMF_PLAYER_WARMUP_FRAMES = 3; static const int VIDEO_FRAME_DURATION_TS = 3003; -int audioSamples = 2048; -int audioSamplesBytes = audioSamples * 4; -int videoPixelMode = GE_CMODE_32BIT_ABGR8888; -int videoLoopStatus = PSMF_PLAYER_CONFIG_NO_LOOP; +static const int audioSamples = 2048; +static const int audioSamplesBytes = audioSamples * 4; +static int videoPixelMode = GE_CMODE_32BIT_ABGR8888; +static int videoLoopStatus = PSMF_PLAYER_CONFIG_NO_LOOP; +static int psmfPlayerLibVersion = 0; enum PsmfPlayerError { ERROR_PSMF_NOT_INITIALIZED = 0x80615001, @@ -647,14 +648,17 @@ static PsmfPlayer *getPsmfPlayer(u32 psmfplayer) return 0; } -void __PsmfInit() -{ +void __PsmfInit() { videoPixelMode = GE_CMODE_32BIT_ABGR8888; videoLoopStatus = PSMF_PLAYER_CONFIG_NO_LOOP; + psmfPlayerLibVersion = 0; } -void __PsmfDoState(PointerWrap &p) -{ +void __PsmfPlayerLoadModule(int devkitVersion) { + psmfPlayerLibVersion = devkitVersion; +} + +void __PsmfDoState(PointerWrap &p) { auto s = p.Section("scePsmf", 1); if (!s) return; @@ -662,19 +666,23 @@ void __PsmfDoState(PointerWrap &p) p.Do(psmfMap); } -void __PsmfPlayerDoState(PointerWrap &p) -{ - auto s = p.Section("scePsmfPlayer", 1); +void __PsmfPlayerDoState(PointerWrap &p) { + auto s = p.Section("scePsmfPlayer", 1, 2); if (!s) return; p.Do(psmfPlayerMap); p.Do(videoPixelMode); p.Do(videoLoopStatus); + if (s >= 2) { + p.Do(psmfPlayerLibVersion); + } else { + // Assume the latest, which is what we were emulating before. + psmfPlayerLibVersion = 0x06060010; + } } -void __PsmfShutdown() -{ +void __PsmfShutdown() { for (auto it = psmfMap.begin(), end = psmfMap.end(); it != end; ++it) delete it->second; for (auto it = psmfPlayerMap.begin(), end = psmfPlayerMap.end(); it != end; ++it) @@ -1233,7 +1241,13 @@ static int _PsmfPlayerSetPsmfOffset(u32 psmfPlayer, const char *filename, int of int mpegoffset = *(s32_be *)(buf + PSMF_STREAM_OFFSET_OFFSET); psmfplayer->readSize = size - mpegoffset; - psmfplayer->streamSize = *(s32_be *)(buf + PSMF_STREAM_SIZE_OFFSET); + if (psmfPlayerLibVersion >= 0x05050010) { + psmfplayer->streamSize = *(s32_be *)(buf + PSMF_STREAM_SIZE_OFFSET); + } else { + // Older versions just read until the end of the file. + PSPFileInfo info = pspFileSystem.GetFileInfo(filename); + psmfplayer->streamSize = info.size - offset - mpegoffset; + } psmfplayer->fileoffset = offset + mpegoffset; psmfplayer->mediaengine->loadStream(buf, 2048, std::max(2048 * 500, tempbufSize)); _PsmfPlayerFillRingbuffer(psmfplayer); diff --git a/Core/HLE/scePsmf.h b/Core/HLE/scePsmf.h index 31cf34646c83..324896247017 100644 --- a/Core/HLE/scePsmf.h +++ b/Core/HLE/scePsmf.h @@ -21,6 +21,7 @@ void Register_scePsmf(); void Register_scePsmfPlayer(); void __PsmfInit(); +void __PsmfPlayerLoadModule(int devkitVersion); void __PsmfDoState(PointerWrap &p); void __PsmfPlayerDoState(PointerWrap &p); void __PsmfShutdown(); From 00a379e9f043884b13b537cb1c945a67defb8a5c Mon Sep 17 00:00:00 2001 From: sum2012 Date: Tue, 16 Aug 2016 03:57:36 +0800 Subject: [PATCH 2/3] Psmf: Ignore last timestamp with old PsmfPlayer libs Until 5.50 Fix #6574 --- Core/HLE/scePsmf.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 2198d1f21ae3..0b6e39e4058b 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -232,9 +232,14 @@ class PsmfPlayer { } bool HasReachedEnd() { - bool videoPtsEnd = (s64)psmfPlayerAvcAu.pts >= (s64)totalDurationTimestamp - VIDEO_FRAME_DURATION_TS; - // If we're out of video data and have no audio, it's over even if the pts isn't there yet. - return videoPtsEnd || (mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData()); + if (psmfPlayerLibVersion >= 0x05050010) { + bool videoPtsEnd = (s64)psmfPlayerAvcAu.pts >= (s64)totalDurationTimestamp - VIDEO_FRAME_DURATION_TS; + // If we're out of video data and have no audio, it's over even if the pts isn't there yet. + return videoPtsEnd || (mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData()); + } + else {// Older versions just read until the end of the file. + return (mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData()); + } } u32 filehandle; From a0484dce6595f398947220c492e5b8763836591b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 15 Aug 2016 21:00:10 -0700 Subject: [PATCH 3/3] Psmf: Use packets for end in all versions. Turns out no version of the library looks at the pts for the end. --- Core/HLE/scePsmf.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 0b6e39e4058b..c665cc44907e 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -232,14 +232,8 @@ class PsmfPlayer { } bool HasReachedEnd() { - if (psmfPlayerLibVersion >= 0x05050010) { - bool videoPtsEnd = (s64)psmfPlayerAvcAu.pts >= (s64)totalDurationTimestamp - VIDEO_FRAME_DURATION_TS; - // If we're out of video data and have no audio, it's over even if the pts isn't there yet. - return videoPtsEnd || (mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData()); - } - else {// Older versions just read until the end of the file. - return (mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData()); - } + // The pts are ignored - the end is when we're out of data. + return mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData(); } u32 filehandle;