Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psmf: Ignore stream size with old PsmfPlayer libs #8914

Merged
merged 4 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 30 additions & 17 deletions Core/HLE/scePsmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -231,9 +232,8 @@ 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());
// The pts are ignored - the end is when we're out of data.
return mediaengine->IsVideoEnd() && mediaengine->IsNoAudioData();
}

u32 filehandle;
Expand Down Expand Up @@ -647,34 +647,41 @@ 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;

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)
Expand Down Expand Up @@ -1233,7 +1240,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);
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/scePsmf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();