From 7faaf2698466ff530c0ed4dc962d91697bab283f Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Fri, 27 Dec 2024 23:19:10 +0100 Subject: [PATCH] whatever --- extras/menus/arkMenu/src/browser.cpp | 4 +- extras/menus/arkMenu/src/entry.cpp | 2 +- extras/menus/arkMenu/src/multimedia/mpeg.cpp | 80 ++++++++++++++++--- .../arkMenu/src/multimedia/mpeg_decoder.cpp | 12 +-- .../arkMenu/src/multimedia/mpeg_reader.cpp | 2 +- 5 files changed, 77 insertions(+), 23 deletions(-) diff --git a/extras/menus/arkMenu/src/browser.cpp b/extras/menus/arkMenu/src/browser.cpp index fc72642d9..6658b447a 100644 --- a/extras/menus/arkMenu/src/browser.cpp +++ b/extras/menus/arkMenu/src/browser.cpp @@ -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; diff --git a/extras/menus/arkMenu/src/entry.cpp b/extras/menus/arkMenu/src/entry.cpp index b2cdb157b..5536652fc 100644 --- a/extras/menus/arkMenu/src/entry.cpp +++ b/extras/menus/arkMenu/src/entry.cpp @@ -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(){ diff --git a/extras/menus/arkMenu/src/multimedia/mpeg.cpp b/extras/menus/arkMenu/src/multimedia/mpeg.cpp index cf72647a1..5f9df075d 100644 --- a/extras/menus/arkMenu/src/multimedia/mpeg.cpp +++ b/extras/menus/arkMenu/src/multimedia/mpeg.cpp @@ -95,6 +95,7 @@ int work = 1; bool playAT3; bool playMPEG; bool playMPEGAudio = true; +bool is_mps = false; int at3_thread_started = 0; @@ -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) { @@ -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); } @@ -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); @@ -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); @@ -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); @@ -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); } @@ -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 @@ -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 diff --git a/extras/menus/arkMenu/src/multimedia/mpeg_decoder.cpp b/extras/menus/arkMenu/src/multimedia/mpeg_decoder.cpp index f0a7d11ee..a7399744d 100644 --- a/extras/menus/arkMenu/src/multimedia/mpeg_decoder.cpp +++ b/extras/menus/arkMenu/src/multimedia/mpeg_decoder.cpp @@ -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; @@ -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; @@ -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)) @@ -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; diff --git a/extras/menus/arkMenu/src/multimedia/mpeg_reader.cpp b/extras/menus/arkMenu/src/multimedia/mpeg_reader.cpp index 4392366f7..6d4b4d4c1 100644 --- a/extras/menus/arkMenu/src/multimedia/mpeg_reader.cpp +++ b/extras/menus/arkMenu/src/multimedia/mpeg_reader.cpp @@ -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;