Skip to content

Commit

Permalink
Merge branch 'video_player'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Dec 27, 2024
2 parents a320d94 + 15fea30 commit 63ead33
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 64 deletions.
1 change: 1 addition & 0 deletions extras/menus/arkMenu/include/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Entry{
static bool isTXT(const char* path);
static bool isIMG(const char* path);
static bool isMusic(const char* path);
static bool isVideo(const char* path);

static bool getSfoParam(unsigned char* sfo_buffer, int buf_size, char* param_name, unsigned char* var, int* var_size);

Expand Down
3 changes: 2 additions & 1 deletion extras/menus/arkMenu/include/multimedia/mpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "entry.h"

bool mpegStart(Entry* e, int x, int y);
bool mpegPlayGamePMF(Entry* e, int x, int y);
void mpegPlayVideoFile(const char* path);

#endif
5 changes: 3 additions & 2 deletions extras/menus/arkMenu/include/multimedia/mpeg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct VideoThreadData

SceInt32 m_iWidth;
SceInt32 m_iHeight;
SceInt32 m_iBufferWidth;

} VideoThreadData;

Expand Down Expand Up @@ -159,8 +160,8 @@ extern bool playMPEG;
extern bool playMPEGAudio;

extern void* MPEGdataL;
extern int MPEGsize;
extern int MPEGcounter;
extern SceOff MPEGsize;
extern SceOff MPEGcounter;

extern Entry* entry;

Expand Down
6 changes: 6 additions & 0 deletions extras/menus/arkMenu/src/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "texteditor.h"
#include "image_viewer.h"
#include "music_player.h"
#include "mpeg.h"

#define ROOT_DIR "ms0:/" // Initial directory
#define GO_ROOT "ef0:/" // PSP Go initial directory
Expand Down Expand Up @@ -169,6 +170,11 @@ void Browser::update(Entry* ent, bool skip_prompt){
else if (Entry::isARK(e->getPath().c_str())) {
installTheme();
}
else if (Entry::isVideo(e->getPath().c_str())){
SystemMgr::pauseDraw();
mpegPlayVideoFile(e->getPath().c_str());
SystemMgr::resumeDraw();
}
else if (e->getFileType() == FOLDER){
string full_path = e->getFullPath();
this->cwd = full_path;
Expand Down
7 changes: 6 additions & 1 deletion extras/menus/arkMenu/src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ bool Entry::isMusic(const char* path){
return (ext == "mp3");
}

bool Entry::isVideo(const char* path){
string ext = common::getExtension(path);
return (ext == "mp4" || ext == "mpg" || ext == "mpeg" || ext == "pmf");
}

Entry::~Entry(){
}

Expand Down Expand Up @@ -299,7 +304,7 @@ bool Entry::pmfPrompt(){
bool pmfPlayback = entry->getIcon1() != NULL || entry->getSnd() != NULL;

if (pmfPlayback && !MusicPlayer::isPlaying()){
ret = mpegStart(entry, 20, 92);
ret = mpegPlayGamePMF(entry, 20, 92);
}
else{
Controller control;
Expand Down
171 changes: 127 additions & 44 deletions extras/menus/arkMenu/src/multimedia/mpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@

#define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) & 0x0000FF00) << 8) | (((x) & 0x00FF0000) >> 8))

typedef struct {
int packets;
uint packetsRead;
uint packetsWritten;
uint packetsFree;
uint packetSize;
void* data;
uint callback;
void* callbackParameter;
void* dataUpperBound;
int semaId;
SceMpeg* mpeg;
} _SceMpegRingbuffer;

typedef struct {
uint magic1;
uint magic2;
uint magic3;
uint unk_m1;
void* ringbuffer_start;
void* ringbuffer_end;
} _SceMpeg;

int retVal;
SceMpegAvcMode m_MpegAvcMode;

Expand Down Expand Up @@ -76,8 +99,9 @@ bool playMPEGAudio = true;
int at3_thread_started = 0;

void* MPEGdata = NULL;
int MPEGsize = 0;
int MPEGcounter = 0;
SceUID mpegfd = -1;
SceOff MPEGsize = 0;
SceOff MPEGcounter = 0;
int MPEGstart = 0;

Entry* entry = NULL;
Expand All @@ -87,7 +111,7 @@ bool run = 0;
int dx;
int dy;

SceInt32 RingbufferCallback(ScePVoid pData, SceInt32 iNumPackets, ScePVoid pParam)
SceInt32 RingbufferCallbackFromBuffer(ScePVoid pData, SceInt32 iNumPackets, ScePVoid pParam)
{

if (MPEGcounter >= MPEGsize)
Expand All @@ -106,6 +130,27 @@ SceInt32 RingbufferCallback(ScePVoid pData, SceInt32 iNumPackets, ScePVoid pPara
return toRead/2048;
}

SceInt32 RingbufferCallbackFromFile(ScePVoid pData, SceInt32 iNumPackets, ScePVoid pParam)
{

if (MPEGcounter >= MPEGsize){
MPEGcounter = 0;
sceIoLseek(mpegfd, 0, PSP_SEEK_SET);
}

int toRead = iNumPackets*2048;
if (MPEGcounter + toRead > MPEGsize)
toRead = MPEGsize-MPEGcounter;

//printf("reading %d bytes at %d\n", toRead, MPEGcounter);

sceIoRead(mpegfd, pData, toRead);

MPEGcounter += toRead;

return toRead/2048;
}

SceInt32 ParseHeader()
{
int retVal;
Expand All @@ -116,58 +161,51 @@ SceInt32 ParseHeader()
goto error;
}

memcpy(pHeader, MPEGdata, 2048);
if (MPEGdata)
memcpy(pHeader, MPEGdata, 2048);
else if (mpegfd >= 0){
printf("reading header from file\n");
sceIoLseek32(mpegfd, 0, SEEK_SET);
sceIoRead(mpegfd, pHeader, 2048);
}
else {
retVal = -1;
goto error;
}

m_iLastTimeStamp = *(int*)(pHeader + 80 + 12);
m_iLastTimeStamp = SWAPINT(m_iLastTimeStamp);

retVal = sceMpegQueryStreamOffset(&m_Mpeg, pHeader, &m_MpegStreamOffset);
if (retVal != 0)
{
goto error;
m_MpegStreamOffset = 0;
printf("sceMpegQueryStreamOffset: %p\n", retVal);
m_iLastTimeStamp = -1;
//goto error;
}

retVal = sceMpegQueryStreamSize(pHeader, &m_MpegStreamSize);
if (retVal != 0)
{
goto error;
m_MpegStreamSize = MPEGsize;
printf("sceMpegQueryStreamSize: %p\n", retVal);
//goto error;
}

m_iLastTimeStamp = *(int*)(pHeader + 80 + 12);
m_iLastTimeStamp = SWAPINT(m_iLastTimeStamp);

free(pHeader);

MPEGcounter = MPEGstart = m_MpegStreamOffset;
if (mpegfd >= 0) sceIoLseek(mpegfd, MPEGcounter, PSP_SEEK_SET);
return 0;

error:
free(pHeader);
return -1;
}

typedef struct {
int packets;
uint packetsRead;
uint packetsWritten;
uint packetsFree;
uint packetSize;
void* data;
uint callback;
void* callbackParameter;
void* dataUpperBound;
int semaId;
SceMpeg* mpeg;
} _SceMpegRingbuffer;

typedef struct {
uint magic1;
uint magic2;
uint magic3;
uint unk_m1;
void* ringbuffer_start;
void* ringbuffer_end;
} _SceMpeg;


void mpegInit() {
void mpegInit(sceMpegRingbufferCB RingbufferCallback) {

m_RingbufferPackets = 100; //0x3C0;
// 0x3C0 -> 2065920 bytes
Expand All @@ -179,19 +217,26 @@ void mpegInit() {
status |= sceUtilityLoadModule(PSP_MODULE_AV_ATRAC3PLUS);
status |= sceUtilityLoadModule(PSP_MODULE_AV_MPEGBASE);
status |= sceUtilityLoadModule(PSP_MODULE_AV_VAUDIO);
status |= sceUtilityLoadModule(PSP_MODULE_AV_AAC);

sceMpegInit();
int res;

res = sceMpegInit();
printf("sceMpegInit: %p\n", res);
m_RingbufferSize = sceMpegRingbufferQueryMemSize(m_RingbufferPackets);

m_MpegMemSize = sceMpegQueryMemSize(0);
m_RingbufferData = ringbuf; //malloc(m_RingbufferSize);
m_MpegMemData = malloc(m_MpegMemSize);
sceMpegRingbufferConstruct(&m_Ringbuffer, m_RingbufferPackets, m_RingbufferData, m_RingbufferSize, &RingbufferCallback, MPEGdata);
sceMpegCreate(&m_Mpeg, m_MpegMemData, m_MpegMemSize, &m_Ringbuffer, BUFFER_WIDTH, 0, 0);

res = sceMpegRingbufferConstruct(&m_Ringbuffer, m_RingbufferPackets, m_RingbufferData, m_RingbufferSize, RingbufferCallback, MPEGdata);
printf("sceMpegRingbufferConstruct: %p\n", res);
res = sceMpegCreate(&m_Mpeg, m_MpegMemData, m_MpegMemSize, &m_Ringbuffer, BUFFER_WIDTH, 0, 0);
printf("sceMpegCreate: %p\n", res);

m_MpegAvcMode.iUnk0 = -1;
m_MpegAvcMode.iPixelFormat = 3;
sceMpegAvcDecodeMode(&m_Mpeg, &m_MpegAvcMode);
res = sceMpegAvcDecodeMode(&m_Mpeg, &m_MpegAvcMode);
printf("sceMpegAvcDecodeMode: %p\n", res);
}

void mpegLoad() {
Expand All @@ -202,9 +247,12 @@ void mpegLoad() {
m_MpegStreamAtrac = sceMpegRegistStream(&m_Mpeg, 1, 0);
m_pEsBufferAVC = sceMpegMallocAvcEsBuf(&m_Mpeg);
retVal = sceMpegInitAu(&m_Mpeg, m_pEsBufferAVC, &m_MpegAuAVC);
printf("sceMpegInitAu: %p\n", retVal);
retVal = sceMpegQueryAtracEsSize(&m_Mpeg, &m_MpegAtracEsSize, &m_MpegAtracOutSize);
printf("sceMpegQueryAtracEsSize: %p\n", retVal);
m_pEsBufferAtrac = memalign(64, m_MpegAtracEsSize);
retVal = sceMpegInitAu(&m_Mpeg, m_pEsBufferAtrac, &m_MpegAuAtrac);
printf("sceMpegInitAu: %p\n", retVal);
}

int mpegPlay(){
Expand Down Expand Up @@ -280,6 +328,7 @@ SceVoid mpegShutdown()
sceMpegRingbufferDestruct(&m_Ringbuffer);
sceMpegFinish();

sceUtilityUnloadModule(PSP_MODULE_AV_AAC);
sceUtilityUnloadModule(PSP_MODULE_AV_VAUDIO);
sceUtilityUnloadModule(PSP_MODULE_AV_MPEGBASE);
sceUtilityUnloadModule(PSP_MODULE_AV_ATRAC3PLUS);
Expand All @@ -292,17 +341,13 @@ SceVoid mpegShutdown()

void T_mpeg(){
work = 1;
// init and start MPEG
mpegInit();
mpegLoad();
while (work){
MPEGcounter = MPEGstart; // reset MPEG to play on loop
mpegPlay(); // play MPEG
}
mpegShutdown(); // shutdown MPEG
}

bool mpegStart(Entry* e, int x, int y){
bool mpegPlayGamePMF(Entry* e, int x, int y){
void* mpegData = e->getIcon1();
int mpegSize = e->getIcon1Size();
void* at3data = e->getSnd();
Expand All @@ -314,6 +359,7 @@ bool mpegStart(Entry* e, int x, int y){
if (!playAT3 && !playMPEG)
return false; // we need to play something
entry = e;
mpegfd = -1;
MPEGdata = mpegData;
MPEGsize = mpegSize;
AT3->at3_data = (char*)at3data;
Expand All @@ -322,7 +368,44 @@ bool mpegStart(Entry* e, int x, int y){
at3_thread_started = 0;
dx = x;
dy = y;
T_mpeg();

// init and start MPEG
mpegInit(RingbufferCallbackFromBuffer);
mpegLoad();
T_mpeg(); // do play
mpegShutdown(); // shutdown MPEG

return run;
}

void mpegPlayVideoFile(const char* path){

mpegfd = sceIoOpen(path, PSP_O_RDONLY, 0777);
if (mpegfd < 0) return;

printf("play video file %s\n", path);
playAT3 = false; // are we gonna play an at3 file? nope
playMPEG = true; // are we gonna play a mpeg file too? of course we are
playMPEGAudio = true;
entry = NULL;
MPEGdata = NULL;
MPEGsize = sceIoLseek(mpegfd, 0, SEEK_END);
AT3->at3_data = NULL;
AT3->at3_size = 0;
at3_started = 0;
at3_thread_started = 0;
dx = 0;
dy = 0;
MPEGcounter = MPEGstart = 0;
sceIoLseek(mpegfd, 0, PSP_SEEK_SET);

// init and start MPEG
printf("mpeg init\n");
mpegInit(RingbufferCallbackFromFile);
printf("mpeg loade\n");
mpegLoad();
printf("mpeg loop\n");
T_mpeg(); // do play
printf("mpeg shutdown\n");
mpegShutdown(); // shutdown MPEG
}
Loading

0 comments on commit 63ead33

Please sign in to comment.