Skip to content

Commit

Permalink
whatever
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Dec 27, 2024
1 parent 260a187 commit 7faaf26
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 23 deletions.
4 changes: 1 addition & 3 deletions extras/menus/arkMenu/src/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ Browser::Browser(){
if (psp_model == PSP_11000 || ftp_driver == NULL){
pEntries[FTP_DIR] = NULL;
}

/*

if (IS_VITA(ark_config) || psp_model == PSP_GO){
if (!sceUmdCheckMedium())
pEntries[UMD_DIR] = NULL;
}
*/

if (ark_config->exec_mode == PS_VITA)
pEntries[USB_DEV] = NULL;
Expand Down
2 changes: 1 addition & 1 deletion extras/menus/arkMenu/src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool Entry::isMusic(const char* path){

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

Entry::~Entry(){
Expand Down
80 changes: 68 additions & 12 deletions extras/menus/arkMenu/src/multimedia/mpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ int work = 1;
bool playAT3;
bool playMPEG;
bool playMPEGAudio = true;
bool is_mps = false;

int at3_thread_started = 0;

Expand All @@ -105,12 +106,36 @@ SceOff MPEGcounter = 0;
int MPEGstart = 0;

Entry* entry = NULL;
u8* ringbuf = NULL;

bool run = 0;

int dx;
int dy;

bool mps_header_injected = false;
u8 mps_header[] = {
0x50, 0x53, 0x4D, 0x46, 0x30, 0x30, 0x30, 0x34, 0x00, 0x00, 0x08, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x4E, 0x00, 0x00, 0x00, 0x01, 0x5F, 0x90, 0x00, 0x00, 0x00, 0x69, 0x6F, 0x75,
0x00, 0x00, 0x61, 0xA8, 0x00, 0x01, 0x5F, 0x90, 0x02, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00,
0x00, 0x01, 0x5F, 0x90, 0x00, 0x00, 0x00, 0x69, 0x6F, 0x75, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22,
0x00, 0x02, 0xE0, 0x00, 0x21, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x11,
0x00, 0x00, 0xBD, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

static void copyHeader(void* pData){
memset(pData, 0, 2048);
memcpy(pData, mps_header, sizeof(mps_header));
memcpy((u8*)pData+12, &MPEGsize, sizeof(MPEGsize));
memcpy((u8*)pData+92, &m_iLastTimeStamp, sizeof(m_iLastTimeStamp));
memcpy((u8*)pData+118, &m_iLastTimeStamp, sizeof(m_iLastTimeStamp));
}

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

Expand All @@ -133,7 +158,20 @@ SceInt32 RingbufferCallbackFromBuffer(ScePVoid pData, SceInt32 iNumPackets, SceP
SceInt32 RingbufferCallbackFromFile(ScePVoid pData, SceInt32 iNumPackets, ScePVoid pParam)
{

int res = 0;

if (is_mps && MPEGcounter == 0 && !mps_header_injected){
printf("faking header for mps\n");
copyHeader(pData);
mps_header_injected = true;
if (iNumPackets == 1) return 1;
res = 1;
iNumPackets--;
pData = (u8*)pData+2048;
}

if (MPEGcounter >= MPEGsize){
printf("reset MPEGcounter (%d, %d)\n", MPEGcounter, MPEGsize);
MPEGcounter = 0;
sceIoLseek(mpegfd, 0, PSP_SEEK_SET);
}
Expand All @@ -142,27 +180,39 @@ SceInt32 RingbufferCallbackFromFile(ScePVoid pData, SceInt32 iNumPackets, ScePVo
if (MPEGcounter + toRead > MPEGsize)
toRead = MPEGsize-MPEGcounter;

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

sceIoRead(mpegfd, pData, toRead);

MPEGcounter += toRead;

return toRead/2048;
printf("MPEGcounter: %d\n");

return res+iNumPackets;
}

SceInt32 ParseHeader()
{
int retVal;

char * pHeader = (char *)malloc(2048);

if (MPEGsize < 2048)
{
goto error;
}

if (MPEGdata)

if (is_mps){
m_MpegStreamOffset = 0;
m_iLastTimeStamp = -1;
m_MpegStreamSize = MPEGsize;
MPEGcounter = 0;
MPEGstart = 0;
copyHeader(pHeader);
}
else if (MPEGdata){
memcpy(pHeader, MPEGdata, 2048);
}
else if (mpegfd >= 0){
printf("reading header from file\n");
sceIoLseek32(mpegfd, 0, SEEK_SET);
Expand Down Expand Up @@ -207,11 +257,7 @@ SceInt32 ParseHeader()

void mpegInit(sceMpegRingbufferCB RingbufferCallback) {

m_RingbufferPackets = 100; //0x3C0;
// 0x3C0 -> 2065920 bytes
// 100 -> 215200 bytes

static u8 ringbuf[215200]; // use static buffer
m_RingbufferPackets = 0x3C0;

int status = 0;
status |= sceUtilityLoadModule(PSP_MODULE_AV_ATRAC3PLUS);
Expand All @@ -226,7 +272,7 @@ void mpegInit(sceMpegRingbufferCB RingbufferCallback) {
m_RingbufferSize = sceMpegRingbufferQueryMemSize(m_RingbufferPackets);

m_MpegMemSize = sceMpegQueryMemSize(0);
m_RingbufferData = ringbuf; //malloc(m_RingbufferSize);
m_RingbufferData = malloc(m_RingbufferSize);
m_MpegMemData = malloc(m_MpegMemSize);
res = sceMpegRingbufferConstruct(&m_Ringbuffer, m_RingbufferPackets, m_RingbufferData, m_RingbufferSize, RingbufferCallback, MPEGdata);
printf("sceMpegRingbufferConstruct: %p\n", res);
Expand Down Expand Up @@ -334,7 +380,7 @@ SceVoid mpegShutdown()
sceUtilityUnloadModule(PSP_MODULE_AV_ATRAC3PLUS);

if (m_pEsBufferAtrac != NULL) free(m_pEsBufferAtrac);
//if (m_RingbufferData != NULL) free(m_RingbufferData); // This crashes....double free or corruption?
if (m_RingbufferData != NULL) free(m_RingbufferData); // This crashes....double free or corruption?
if (m_MpegMemData != NULL) free(m_MpegMemData);

}
Expand Down Expand Up @@ -382,7 +428,16 @@ void mpegPlayVideoFile(const char* path){

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


string ext = common::getExtension(path);
if (ext == "mps"){
printf("mps detected\n");
is_mps = true;
}
else {
is_mps = false;
}

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
Expand All @@ -397,6 +452,7 @@ void mpegPlayVideoFile(const char* path){
dx = 0;
dy = 0;
MPEGcounter = MPEGstart = 0;
mps_header_injected = false;
sceIoLseek(mpegfd, 0, PSP_SEEK_SET);

// init and start MPEG
Expand Down
12 changes: 6 additions & 6 deletions extras/menus/arkMenu/src/multimedia/mpeg_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int T_Decoder(SceSize _args, void *_argp)
if (D->Audio->m_iFullBuffers < D->Audio->m_iNumBuffers)
{
retVal = sceMpegGetAtracAu(&D->m_Mpeg, D->m_MpegStreamAtrac, D->m_MpegAuAtrac, &unknown);
//printf("sceMpegGetAtracAu: %p\n", retVal);
printf("sceMpegGetAtracAu: %p\n", retVal);
if (retVal != 0)
{
playMPEGAudio = false;
Expand All @@ -133,13 +133,13 @@ int T_Decoder(SceSize _args, void *_argp)
memset(D->Audio->m_pAudioBuffer[D->Audio->m_iDecodeBuffer], 0, m_MpegAtracOutSize);

retVal = sceMpegAtracDecode(&D->m_Mpeg, D->m_MpegAuAtrac, D->Audio->m_pAudioBuffer[D->Audio->m_iDecodeBuffer], iInitAudio);
//printf("sceMpegAtracDecode: %p\n", retVal);
printf("sceMpegAtracDecode: %p\n", retVal);
if (retVal != 0)
{
break;
}

if (D->m_MpegAuAtrac->iPts == 0xFFFFFFFF) {
if (D->m_MpegAuAtrac->iPts < 0) {
m_iAudioCurrentTimeStamp += D->m_iAudioFrameDuration;
} else {
m_iAudioCurrentTimeStamp = D->m_MpegAuAtrac->iPts;
Expand Down Expand Up @@ -180,7 +180,7 @@ int T_Decoder(SceSize _args, void *_argp)
{

retVal = sceMpegGetAvcAu(&D->m_Mpeg, D->m_MpegStreamAVC, D->m_MpegAuAVC, &unknown);
//if (retVal >= 0) printf("sceMpegGetAvcAu: %p\n", retVal);
printf("sceMpegGetAvcAu: %p\n", retVal);
if ((SceUInt32)retVal == 0x80618001)
{
if (!IsRingbufferFull(D->Reader))
Expand All @@ -199,13 +199,13 @@ int T_Decoder(SceSize _args, void *_argp)
if (m_iVideoCurrentTimeStamp >= D->m_iLastTimeStamp - D->m_iVideoFrameDuration) break;

retVal = sceMpegAvcDecode(&D->m_Mpeg, D->m_MpegAuAVC, D->Video->m_iBufferWidth, &D->Video->m_pVideoBuffer[D->Video->m_iPlayBuffer], &iVideoStatus);
//if (retVal >= 0) printf("sceMpegAvcDecode: %p\n", retVal);
printf("sceMpegAvcDecode: %p\n", retVal);
if (retVal != 0)
{
break;
}

if (D->m_MpegAuAVC->iPts == 0xFFFFFFFF) {
if (D->m_MpegAuAVC->iPts < 0) {
m_iVideoCurrentTimeStamp += 0x0BBC;
} else {
m_iVideoCurrentTimeStamp = D->m_MpegAuAVC->iPts;
Expand Down
2 changes: 1 addition & 1 deletion extras/menus/arkMenu/src/multimedia/mpeg_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SceInt32 InitReader()

Reader.m_StreamSize = m_MpegStreamSize;
Reader.m_Ringbuffer = &m_Ringbuffer;
Reader.m_RingbufferPackets = m_RingbufferPackets;
Reader.m_RingbufferPackets = m_RingbufferPackets;
Reader.m_Status = 0;
Reader.m_TotalBytes = 0;

Expand Down

0 comments on commit 7faaf26

Please sign in to comment.