int LPP_UtilsGameShareInit(const char *filepath, const char *name) { sceNetAdhocMatchingInit(32*1024); memset(&lpp_UtilsGameShareParams, 0, sizeof(lpp_UtilsGameShareParams)); lpp_UtilsGameShareParams.base.size = sizeof(lpp_UtilsGameShareParams); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &lpp_UtilsGameShareParams.base.language); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &lpp_UtilsGameShareParams.base.buttonSwap); lpp_UtilsGameShareParams.base.graphicsThread = 17; lpp_UtilsGameShareParams.base.accessThread = 19; lpp_UtilsGameShareParams.base.fontThread = 18; lpp_UtilsGameShareParams.base.soundThread = 16; size_t lsize = 0; SceUID fd = sceIoOpen(filepath, PSP_O_RDONLY, 0777); if(fd < 0) return -1; lsize = sceIoLseek32(fd, 0, PSP_SEEK_END); u8 *buffer = (u8*)malloc(lsize); if(buffer == null) { sceIoClose(fd); return -1; } sceIoLseek32(fd, 0, PSP_SEEK_SET); int read = sceIoRead(fd, buffer,lsize); if(read < lsize) { sceIoClose(fd); free(buffer); return -1; } sceIoClose(fd); buffer[276] = 0x57; strncpy((char *)&buffer[320], name, 127); kuKernelMemcpy(&lpp_UtilsGameShareParams.name, "GameShar", 8); lpp_UtilsGameShareParams.mode = 1; lpp_UtilsGameShareParams.datatype = 2; lpp_UtilsGameShareParams.data = buffer; lpp_UtilsGameShareParams.datasize = lsize; int res = sceUtilityGameSharingInitStart(&lpp_UtilsGameShareParams); if(res == 0) return 1; return (res); }
/*static*/global void *my_file_fopen(void)/*const char *my_file_common_name*/ /*, const char *dummy*/ { SceUID fd; fd = sceIoOpen((char *)my_file_common_name, PSP_O_RDONLY, 0777); // ファイルを開く if (0 == fd) // 開けなかったらエラー { goto error111; } file_size = sceIoLseek32(fd, 0, PSP_SEEK_END); // (実シーク位置を最後に移動させて)ファイルのサイズを調べる。 file_seek = 0; // 仮想シーク位置を先頭に移動。 malloc_buf = malloc(file_size); // ファイルのサイズ分のメモリを(取得して)確保する。 if (NULL == malloc_buf) // メモリが確保出来ない場合はエラー { sceIoClose(fd); goto error111; } sceIoLseek32(fd, 0, PSP_SEEK_SET); // 実シーク位置を先頭に移動。 sceIoRead(fd, malloc_buf, file_size); // 一気に全部メモリに読み込む。 sceIoClose(fd); // my_buf = malloc_buf; // return (malloc_buf); error111: return (NULL); // 失敗 }
pgeObj *pgeObjLoad(const char *filename) { int fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) return NULL; long filesize; filesize = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); unsigned char *data = pgeMalloc(filesize); if(!data) return NULL; sceIoRead(fd, data, filesize); sceIoClose(fd); pgeObj *obj = pgeObjLoadInternal(data, filesize); if(data) pgeFree(data); return obj; }
buffered_reader_t *buffered_reader_open(const char *path, int32_t buffer_size, int32_t seek_mode) { buffered_reader_t *reader = malloc(sizeof(buffered_reader_t)); long long result; if (reader == 0) return 0; memset(reader, 0, sizeof(buffered_reader_t)); reader->cache_enabled = 1; reader->handle = -1; reader->buffer_size = buffer_size; reader->seek_mode = seek_mode; reader->buffer_0 = malloc_64(reader->buffer_size); if (reader->buffer_0 == 0) { buffered_reader_close(reader); return 0; } reader->buffer_1 = malloc_64(reader->buffer_size); if (reader->buffer_1 == 0) { buffered_reader_close(reader); return 0; } reader->buffer_2 = malloc_64(reader->buffer_size); if (reader->buffer_2 == 0) { buffered_reader_close(reader); return 0; } reader->handle = sceIoOpen(path, PSP_O_RDONLY, 0777); if (reader->handle < 0) { buffered_reader_close(reader); return 0; } if (sceIoChangeAsyncPriority(reader->handle, 0x10) < 0) { buffered_reader_close(reader); return 0; } reader->length = sceIoLseek32(reader->handle, 0, PSP_SEEK_END); reader->first_buffer = reader->buffer_0; reader->second_buffer = reader->buffer_1; reader->third_buffer = reader->buffer_2; sceIoLseek32(reader->handle, reader->position_0, PSP_SEEK_SET); sceIoReadAsync(reader->handle, reader->first_buffer, reader->position_1 - reader->position_0); sceIoWaitAsync(reader->handle, &result); sceIoLseek32(reader->handle, reader->position_1, PSP_SEEK_SET); sceIoReadAsync(reader->handle, reader->second_buffer, reader->position_2 - reader->position_1); sceIoWaitAsync(reader->handle, &result); sceIoLseek32(reader->handle, reader->position_2, PSP_SEEK_SET); sceIoReadAsync(reader->handle, reader->third_buffer, reader->position_3 - reader->position_2); return reader; }
int32_t buffered_reader_length(buffered_reader_t * reader) { if (!reader->cache_enabled) { int32_t pos, end; pos = sceIoLseek32(reader->handle, 0, PSP_SEEK_CUR); end = sceIoLseek32(reader->handle, 0, PSP_SEEK_END); sceIoLseek32(reader->handle, pos, PSP_SEEK_SET); return end; } return reader->length; }
void vfsFileSeek(VIRTUAL_FILE *f, int offset, int whence) { // int oldOffset = sceIoLseek32(_file_, 0, SEEK_CUR); // if (!(offset == 0 && whence == SEEK_CUR)) // sceIoLseek32(_file_, offset, whence); sceIoLseek32(_file_, offset, whence); f->userData &= ~FLAG_EOF; }
/* * Function to resume the IO stream (called by Power Manager) */ int PspIoStream::resume() { DEBUG_ENTER_FUNC(); int ret = 0; _suspendCount--; // We reopen our file descriptor _handle = sceIoOpen(_path.c_str(), _writeMode ? PSP_O_RDWR | PSP_O_CREAT : PSP_O_RDONLY, 0777); // open if (_handle <= 0) { _errorSuspend = ResumeError; _errorPos = _pos; } // Resume our previous position if needed if (_handle > 0 && _pos > 0) { ret = sceIoLseek32(_handle, _pos, PSP_SEEK_SET); _physicalPos = _pos; if (ret < 0) { // Check for problem _errorSuspend = ResumeError; _errorPos = _pos; _errorHandle = _handle; } } return ret; }
u32 sceIoLseek32Async(int id, int offset, int whence) { DEBUG_LOG(HLE, "sceIoLseek32Async(%d) sorta implemented", id); sceIoLseek32(id, offset, whence); __IoCompleteAsyncIO(id); return 0; }
static int check_file_is_encrypted(int fd) { int ret; u32 k1; char p[8 + 64], *buf; k1 = pspSdkSetK1(0); buf = (char*)((((u32)p) & ~(64-1)) + 64); ret = sceIoRead(fd, buf, 8); pspSdkSetK1(k1); sceIoLseek32(fd, 0, PSP_SEEK_SET); if (ret != 8) return 0; if (!memcmp(buf, g_drm_magic_1, sizeof(g_drm_magic_1))) { return 1; } if (!memcmp(buf, g_drm_magic_2, sizeof(g_drm_magic_2))) { return 1; } #if 0 printk("%s: buf:\n", __func__); hexdump(buf, 8); #endif return 0; }
void sceIoLseek32Async() { DEBUG_LOG(HLE,"sceIoLseek32Async(%d) sorta implemented",PARAM(0)); sceIoLseek32(); __IoCompleteAsyncIO(PARAM(0)); RETURN(0); }
int32_t buffered_reader_position(buffered_reader_t * reader) { if (!reader->cache_enabled) { return sceIoLseek32(reader->handle, 0, PSP_SEEK_CUR); } return reader->current_position; }
bool JMP3::fillBuffers() { //JLOG("Start JMP3::fillBuffers"); if (!init_done) { JLOG("JMP3::fillBuffers called but init_done is false!"); return false; } #ifdef MP3_SUPPORT SceUChar8* dest; SceInt32 length; SceInt32 pos; int ret = sceMp3GetInfoToAddStreamData(m_mp3Handle, &dest, &length, &pos); if (ret < 0) return false; if (sceIoLseek32(m_fileHandle, pos, SEEK_SET) < 0) { // Re-open the file because file handel can be invalidated by suspend/resume. sceIoClose(m_fileHandle); m_fileHandle = sceIoOpen(m_fileName, PSP_O_RDONLY, 0777); if (m_fileHandle < 0) return false; if (sceIoLseek32(m_fileHandle, 0, SEEK_END) != m_fileSize || sceIoLseek32(m_fileHandle, pos, SEEK_SET) < 0) { sceIoClose(m_fileHandle); m_fileHandle = -1; return false; } } int readLength = sceIoRead(m_fileHandle, dest, length); if (readLength < 0) return false; ret = sceMp3NotifyAddStreamData(m_mp3Handle, readLength); if (ret < 0) return false; #endif //JLOG("End JMP3::fillBuffers"); return true; }
bool PspIoStream::physicalSeekFromCur(int32 offset) { int ret = sceIoLseek32(_handle, offset, PSP_SEEK_CUR); if (ret < 0) { _error = true; PSP_ERROR("failed to seek in file[%s] to [%x]. Error[%x]\n", _path.c_str(), offset, ret); return false; } _physicalPos += offset; return true; }
int MP3ME_resume(){ if (MP3ME_suspendPosition >= 0){ MP3ME_handle = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); if (MP3ME_handle >= 0){ MP3ME_filePos = MP3ME_suspendPosition; sceIoLseek32(MP3ME_handle, MP3ME_filePos, PSP_SEEK_SET); MP3ME_isPlaying = MP3ME_suspendIsPlaying; } } MP3ME_suspendPosition = -1; return 0; }
int MP3_Play (void) { if ( mp3_play ) return mp3_play; sceIoLseek32(mp3_file_handle, mp3_data_start, PSP_SEEK_SET); mp3_pause = 0; mp3_play = 1; int ret = sceKernelStartThread(mp3_audio_thread, 0, 0); if ( ret != 0 ) { mp3_play = 0; return 0; } return 1; }
static int myIoReadAsync(int fd, u8 *buf, int size) { int ret; u32 pos; u32 k1; k1 = pspSdkSetK1(0); pos = sceIoLseek32(fd, 0, SEEK_CUR); ret = sceIoReadAsync(fd, buf, size); printk("%s: 0x%08X 0x%08X 0x%08X -> 0x%08X\n", __func__, (uint)fd, (uint)pos, size, ret); pspSdkSetK1(k1); return ret; }
static int get_icon0_status(void) { u32 icon0_offset = 0; int result = ICON0_MISSING; SceUID fd = -1;; const char *filename; u8 p[40 + 64], *header; header = (u8*)((((u32)p) & ~(64-1)) + 64); filename = sceKernelInitFileName(); if(filename == NULL) { goto exit; } fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) { printk("%s: sceIoOpen %s -> 0x%08X\n", __func__, filename, fd); goto exit; } sceIoRead(fd, header, 40); icon0_offset = *(u32*)(header+0x0c); sceIoLseek32(fd, icon0_offset, PSP_SEEK_SET); sceIoRead(fd, header, 40); if(*(u32*)(header+4) == 0xA1A0A0D) { if ( *(u32*)(header+0xc) == 0x52444849 && // IHDR *(u32*)(header+0x10) == 0x50000000 && // *(u32*)(header+0x14) == *(u32*)(header+0x10) ) { result = ICON0_OK; } else { result = ICON0_CORRUPTED; } } else { result = ICON0_MISSING; } printk("%s: PNG file status -> %d\n", __func__, result); exit: if(fd >= 0) { sceIoClose(fd); } return result; }
//Seek next valid frame //NOTE: this function comes from Music prx 0.55 source // all credits goes to joek2100. int MP3ME_SeekNextFrameMP3(SceUID fd) { int offset = 0; unsigned char buf[1024]; unsigned char *pBuffer; int i; int size = 0; offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR); sceIoRead(fd, buf, sizeof(buf)); if (!strncmp((char*)buf, "ID3", 3) || !strncmp((char*)buf, "ea3", 3)) //skip past id3v2 header, which can cause a false sync to be found { //get the real size from the syncsafe int size = buf[6]; size = (size<<7) | buf[7]; size = (size<<7) | buf[8]; size = (size<<7) | buf[9]; size += 10; if (buf[5] & 0x10) //has footer size += 10; } sceIoLseek32(fd, offset, PSP_SEEK_SET); //now seek for a sync while(1) { offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR); size = sceIoRead(fd, buf, sizeof(buf)); if (size <= 2)//at end of file return -1; if (!strncmp((char*)buf, "EA3", 3))//oma mp3 files have non-safe ints in the EA3 header { sceIoLseek32(fd, (buf[4]<<8)+buf[5], PSP_SEEK_CUR); continue; } pBuffer = buf; for( i = 0; i < size; i++) { //if this is a valid frame sync (0xe0 is for mpeg version 2.5,2+1) if ( (pBuffer[i] == 0xff) && ((pBuffer[i+1] & 0xE0) == 0xE0)) { offset += i; sceIoLseek32(fd, offset, PSP_SEEK_SET); return offset; } } //go back two bytes to catch any syncs that on the boundary sceIoLseek32(fd, -2, PSP_SEEK_CUR); } }
void FillBuffer(int channel) { SceUChar8* dst; int num; int pos; sceMp3GetInfoToAddStreamData(streamsSceMp3[channel].handle,&dst,&num,&pos); if (streamsSceMp3[channel].lastPosition>pos) { if (!streamsSceMp3[channel].autoloop) { streamsSceMp3[channel].paused=TRUE; streamsSceMp3[channel].stopReason=PSPAALIB_STOP_END_OF_STREAM; } } streamsSceMp3[channel].lastPosition=pos; sceIoLseek32(streamsSceMp3[channel].file,pos,PSP_SEEK_SET); int read=sceIoRead(streamsSceMp3[channel].file,(char*)dst,num); sceMp3NotifyAddStreamData(streamsSceMp3[channel].handle,read); }
int32_t buffered_reader_enable_cache(buffered_reader_t * reader, int32_t enabled) { int32_t prev; prev = reader->cache_enabled; if (!prev && enabled) { buffered_reader_reset_buffer(reader, buffered_reader_position(reader)); } else if (prev && !enabled) { long long result; sceIoWaitAsync(reader->handle, &result); sceIoLseek32(reader->handle, buffered_reader_position(reader), PSP_SEEK_SET); } reader->cache_enabled = enabled; return prev; }
//读取一段文件,以'换行_S'为结束 static int read_sect(int cur, PspFile *pf) { int readsize; sceIoLseek32(pf->fd, cur, PSP_SEEK_SET); readsize = sceIoRead(pf->fd, pf->buf, READDB_SECT); if(readsize<READDB_SECT){ if(readsize>0) pf->buf[readsize]=0; return 0; } int i=DB_SECT; while(1){ //if(memcmp(pf->buf+i,pattern,3)==0) break; if(pf->buf[i]==0x0A && pf->buf[i+1]=='_' && pf->buf[i+2]=='S') break; i++; } pf->buf[i+1]=0; return (cur+i+1); }
int fillStreamBuffer( int fd, int handle ) { char* dst; int write; int pos; // Get Info on the stream (where to fill to, how much to fill, where to fill from) int status = sceMp3GetInfoToAddStreamData( handle, &dst, &write, &pos); if (status<0) { ERRORMSG("ERROR: sceMp3GetInfoToAddStreamData returned 0x%08X\n", status); } // Seek file to position requested status = sceIoLseek32( fd, pos, SEEK_SET ); if (status<0) { ERRORMSG("ERROR: sceIoLseek32 returned 0x%08X\n", status); } // Read the amount of data int read = sceIoRead( fd, dst, write ); if (read < 0) { ERRORMSG("ERROR: Could not read from file - 0x%08X\n", read); } if (read==0) { // End of file? return 0; } // Notify mp3 library about how much we really wrote to the stream buffer status = sceMp3NotifyAddStreamData( handle, read ); if (status<0) { ERRORMSG("ERROR: sceMp3NotifyAddStreamData returned 0x%08X\n", status); } return (pos>0); }
static int myIoIoctl(SceUID fd, unsigned int cmd, void * indata, int inlen, void * outdata, int outlen) { int ret; if(cmd == 0x04100001) { printk("%s: setting PGD key\n", __func__); hexdump(indata, inlen); } if(cmd == 0x04100002) { printk("%s: setting PGD offset: 0x%08X\n", __func__, *(uint*)indata); } if (g_is_custom_ps1 || (g_plain_doc_fd >= 0 && g_plain_doc_fd == fd)) { if (cmd == 0x04100001) { ret = 0; printk("%s: [FAKE] 0x%08X 0x%08X -> 0x%08X\n", __func__, fd, cmd, ret); goto exit; } if (cmd == 0x04100002) { ret = sceIoLseek32(fd, *(u32*)indata, PSP_SEEK_SET); if(ret < 0) { printk("%s: sceIoLseek32 -> 0x%08X\n", __func__, ret); } ret = 0; printk("%s: [FAKE] 0x%08X 0x%08X -> 0x%08X\n", __func__, fd, cmd, ret); goto exit; } } ret = sceIoIoctl(fd, cmd, indata, inlen, outdata, outlen); exit: printk("%s: 0x%08X -> 0x%08X\n", __func__, fd, ret); return ret; }
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData) { MFCALLSTACK; MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData."); MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData; int access = ((pOpenData->openFlags&MFOF_Read) ? PSP_O_RDONLY : NULL) | ((pOpenData->openFlags&MFOF_Write) ? PSP_O_WRONLY|PSP_O_CREAT|PSP_O_TRUNC : NULL); MFDebug_Assert(access, "Neither MFOF_Read nor MFOF_Write specified."); const char *pFilename = MFStr("%s/%s", gPSPSystemPath, pNative->pFilename); SceUID hFile = sceIoOpen(pFilename, access, 0777); if(hFile < 0) { MFDebug_Warn(4, MFStr("File does not exist: '%s'", pFilename)); return -1; } pFile->pFilesysData = (void*)hFile; pFile->createFlags = pOpenData->openFlags; pFile->offset = 0; // find file length SceOff fileSize = sceIoLseek(hFile, 0, SEEK_END); // TODO: something's very wrong with this line! :/ // MFDebug_Assert(fileSize < 2147483648LL, MFStr("Error opening file '%s', Fuji does not support files larger than 2,147,483,647 bytes.", pFilename)); pFile->length = (int64)fileSize; // return to start of file sceIoLseek32(hFile, 0, SEEK_SET); #if defined(_DEBUG) MFString_Copy(pFile->fileIdentifier, pFilename); #endif return 0; }
static char *fill_asynchronous_buffer(struct mp4_read_struct *reader, struct mp4_asynchronous_buffer *p, SceUID handle, int track_id, unsigned int trunk_index) { mp4info_track_t* track = reader->file.info->tracks[track_id]; int i, j; for( i = 0; i < track->stsc_entry_count-1; i++ ) { if ( (trunk_index+1) >= track->stsc_first_chunk[i] && (trunk_index+1) < track->stsc_first_chunk[i+1] ) break; } p->first_sample = 0; for( j = 0; j < i; j++ ) { p->first_sample += ( ( track->stsc_first_chunk[j+1] - track->stsc_first_chunk[j] ) * track->stsc_samples_per_chunk[j] ); } p->first_sample += ( ( (trunk_index+1) - track->stsc_first_chunk[i] ) * track->stsc_samples_per_chunk[i] ); p->last_sample = p->first_sample + track->stsc_samples_per_chunk[i] - 1; p->trunk_size = 0; for(i = p->first_sample; i <= p->last_sample; i++) { p->sample_buffer[i-p->first_sample] = p->buffer + p->trunk_size; p->trunk_size += ( track->stsz_sample_size ? track->stsz_sample_size : track->stsz_sample_size_table[i]); } p->trunk_position = track->stco_chunk_offset[trunk_index]; p->trunk_index = trunk_index; if (sceIoLseek32(handle, p->trunk_position, PSP_SEEK_SET) != p->trunk_position) { return("fill_asynchronous_buffer: seek failed"); } if (sceIoReadAsync(handle, p->sample_buffer[0], p->trunk_size) < 0) { return("fill_asynchronous_buffer: read failed"); } return(0); }
static int myIoRead(int fd, u8 *buf, int size) { int ret; u32 pos; u32 k1; k1 = pspSdkSetK1(0); if(fd != RIF_MAGIC_FD && fd != ACT_DAT_FD) { pos = sceIoLseek32(fd, 0, SEEK_CUR); } else { pos = 0; } if(g_keys_bin_found || g_is_custom_ps1) { if(fd == RIF_MAGIC_FD) { size = 152; printk("%s: fake rif content %d\n", __func__, size); memset(buf, 0, size); strcpy((char*)(buf+0x10), PGD_ID); ret = size; goto exit; } else if (fd == ACT_DAT_FD) { printk("%s: fake act.dat content %d\n", __func__, size); memset(buf, 0, size); ret = size; goto exit; } } ret = sceIoRead(fd, buf, size); if(ret != size) { goto exit; } if (size == 4) { u32 magic; magic = 0x464C457F; // ~ELF if(0 == memcmp(buf, &magic, sizeof(magic))) { magic = 0x5053507E; // ~PSP memcpy(buf, &magic, sizeof(magic)); printk("%s: patch ~ELF -> ~PSP\n", __func__); } ret = size; goto exit; } if(size == sizeof(g_icon_png)) { u32 png_signature = 0x474E5089; if(g_icon0_status == ICON0_MISSING || ((g_icon0_status == ICON0_CORRUPTED) && 0 == memcmp(buf, &png_signature, 4))) { printk("%s: fakes a PNG for icon0\n", __func__); memcpy(buf, g_icon_png, size); ret = size; goto exit; } } if (g_is_custom_ps1 && size >= 0x420 && buf[0x41B] == 0x27 && buf[0x41C] == 0x19 && buf[0x41D] == 0x22 && buf[0x41E] == 0x41 && buf[0x41A] == buf[0x41F]) { buf[0x41B] = 0x55; printk("%s: unknown patch loc_6c\n", __func__); } exit: pspSdkSetK1(k1); printk("%s: fd=0x%08X pos=0x%08X size=%d -> 0x%08X\n", __func__, (uint)fd, (uint)pos, (int)size, ret); return ret; }
static u32 is_custom_ps1(void) { SceUID fd = -1; const char *filename; int result, ret; u32 psar_offset, pgd_offset, *magic; u8 p[40 + 64], *header; header = (u8*)((((u32)p) & ~(64-1)) + 64); filename = sceKernelInitFileName(); result = 0; if(filename == NULL) { result = 0; goto exit; } fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) { printk("%s: sceIoOpen %s -> 0x%08X\n", __func__, filename, fd); result = 0; goto exit; } ret = sceIoRead(fd, header, 40); if(ret != 40) { printk("%s: sceIoRead -> 0x%08X\n", __func__, ret); result = 0; goto exit; } psar_offset = *(u32*)(header+0x24); sceIoLseek32(fd, psar_offset, PSP_SEEK_SET); ret = sceIoRead(fd, header, 40); if(ret != 40) { printk("%s: sceIoRead -> 0x%08X\n", __func__, ret); result = 0; goto exit; } pgd_offset = psar_offset; if(0 == memcmp(header, "PSTITLE", sizeof("PSTITLE")-1)) { pgd_offset += 0x200; } else { pgd_offset += 0x400; } sceIoLseek32(fd, pgd_offset, PSP_SEEK_SET); ret = sceIoRead(fd, header, 4); if(ret != 4) { printk("%s: sceIoRead -> 0x%08X\n", __func__, ret); result = 0; goto exit; } magic = (u32*)header; // PGD offset if(*magic != 0x44475000) { printk("%s: custom pops found\n", __func__); result = 1; } exit: if(fd >= 0) { sceIoClose(fd); } return result; }
int vfsFileTell(VIRTUAL_FILE *f) { return sceIoLseek32(_file_, 0, SEEK_CUR); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Private functions: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Decode thread: int decodeThread(SceSize args, void *argp){ int res; unsigned char MP3ME_header_buf[4]; int MP3ME_header; int version; int bitrate; int padding; int frame_size; int size; int offset = 0; sceAudiocodecReleaseEDRAM(MP3ME_codec_buffer); //Fix: ReleaseEDRAM at the end is not enough to play another mp3. MP3ME_threadActive = 1; MP3ME_threadExited = 0; OutputBuffer_flip = 0; OutputPtrME = OutputBuffer[0]; MP3ME_handle = sceIoOpen(MP3ME_Name, PSP_O_RDONLY, 0777); if (MP3ME_handle < 0) MP3ME_threadActive = 0; //now search for the first sync byte, tells us where the mp3 stream starts size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_SET); data_start = ID3v2TagSize(MP3ME_Name); sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); data_start = MP3ME_SeekNextFrameMP3(MP3ME_handle); if (data_start < 0) MP3ME_threadActive = 0; size -= data_start; memset(MP3ME_codec_buffer, 0, sizeof(MP3ME_codec_buffer)); if ( sceAudiocodecCheckNeedMem(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; if ( sceAudiocodecGetEDRAM(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; getEDRAM = 1; if ( sceAudiocodecInit(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; MP3ME_eof = 0; while (MP3ME_threadActive){ while( !MP3ME_eof && MP3ME_isPlaying ) { MP3ME_filePos = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_CUR); if ( sceIoRead( MP3ME_handle, MP3ME_header_buf, 4 ) != 4 ){ MP3ME_isPlaying = 0; MP3ME_threadActive = 0; continue; } MP3ME_header = MP3ME_header_buf[0]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[1]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[2]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[3]; bitrate = (MP3ME_header & 0xf000) >> 12; padding = (MP3ME_header & 0x200) >> 9; version = (MP3ME_header & 0x180000) >> 19; samplerate = samplerates[version][ (MP3ME_header & 0xC00) >> 10 ]; if ((bitrate > 14) || (version == 1) || (samplerate == 0) || (bitrate == 0))//invalid frame, look for the next one { data_start = MP3ME_SeekNextFrameMP3(MP3ME_handle); if(data_start < 0) { MP3ME_eof = 1; continue; } size -= (data_start - offset); offset = data_start; continue; } if (version == 3) //mpeg-1 { sample_per_frame = 1152; frame_size = 144000*bitrates[bitrate]/samplerate + padding; }else{ sample_per_frame = 576; frame_size = 72000*bitrates_v2[bitrate]/samplerate + padding; } sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); //seek back size -= frame_size; if ( size <= 0) { MP3ME_eof = 1; continue; } //since we check for eof above, this can only happen when the file // handle has been invalidated by syspend/resume/usb if ( sceIoRead( MP3ME_handle, MP3ME_input_buffer, frame_size ) != frame_size ){ //Resume from suspend: if ( MP3ME_handle >= 0 ){ sceIoClose(MP3ME_handle); MP3ME_handle = -1; } MP3ME_handle = sceIoOpen(MP3ME_Name, PSP_O_RDONLY, 0777); if (MP3ME_handle < 0){ MP3ME_isPlaying = 0; MP3ME_threadActive = 0; continue; } size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); sceIoLseek32(MP3ME_handle, offset, PSP_SEEK_SET); data_start = offset; continue; } data_start += frame_size; offset = data_start; MP3ME_codec_buffer[6] = (unsigned long)MP3ME_input_buffer; MP3ME_codec_buffer[8] = (unsigned long)MP3ME_output_buffer; MP3ME_codec_buffer[7] = MP3ME_codec_buffer[10] = frame_size; MP3ME_codec_buffer[9] = sample_per_frame * 4; res = sceAudiocodecDecode(MP3ME_codec_buffer, 0x1002); if ( res < 0 ) { //instead of quitting see if the next frame can be decoded //helps play files with an invalid frame //we must look for a valid frame, the offset above may be wrong data_start = MP3ME_SeekNextFrameMP3(MP3ME_handle); if(data_start < 0) { MP3ME_eof = 1; continue; } size -= (data_start - offset); offset = data_start; continue; } MP3ME_playingTime += (float)sample_per_frame/(float)samplerate; //Output: memcpy( OutputPtrME, MP3ME_output_buffer, sample_per_frame*4); OutputPtrME += (sample_per_frame * 4); if( OutputPtrME + (sample_per_frame * 4) > &OutputBuffer[OutputBuffer_flip][OUTPUT_BUFFER_SIZE]) { audioOutput(PSP_AUDIO_VOLUME_MAX, OutputBuffer[OutputBuffer_flip]); OutputBuffer_flip ^= 1; OutputPtrME = OutputBuffer[OutputBuffer_flip]; } } sceKernelDelayThread(10000); // Not sure if necessary or purpose } if (getEDRAM) sceAudiocodecReleaseEDRAM(MP3ME_codec_buffer); if ( MP3ME_handle >= 0){ sceIoClose(MP3ME_handle); MP3ME_handle = -1; } MP3ME_threadExited = 1; return 0; }
bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) { JLOG("Start JMP3::load"); if (!init_done) { JLOG("JMP3::load called but init_done is false!"); return false; } #ifdef MP3_SUPPORT m_inBufferSize = inBufferSize; //m_inBuffer = new char[m_inBufferSize]; //if (!m_inBuffer) // return false; m_outBufferSize = outBufferSize; //m_outBuffer = new short[outBufferSize]; //if (!m_outBuffer) // return false; m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777); if (m_fileHandle < 0) return false; // Memorise the full path for reloading with decode thread. if ( getcwd(m_fileName, sizeof(m_fileName)) ){ int len = strnlen(m_fileName, sizeof(m_fileName)); if (len + filename.size() <= sizeof(m_fileName) - 2){ m_fileName[len++] = '/'; strcpy(m_fileName + len, filename.c_str()); }else{ m_fileName[0] = 0; } } int ret = sceMp3InitResource(); if (ret < 0) return false; SceMp3InitArg initArgs; int fileSize = sceIoLseek32(m_fileHandle, 0, SEEK_END); sceIoLseek32(m_fileHandle, 0, SEEK_SET); m_fileSize = fileSize; int id3tagsize = GetID3TagSize((char*)filename.c_str()); initArgs.unk1 = 0; initArgs.unk2 = 0; initArgs.mp3StreamStart = id3tagsize; initArgs.mp3StreamEnd = fileSize-(id3tagsize); initArgs.mp3BufSize = m_inBufferSize; initArgs.mp3Buf = (SceVoid*) m_inBuffer; initArgs.pcmBufSize = m_outBufferSize; initArgs.pcmBuf = (SceVoid*) m_outBuffer; m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs); if (m_mp3Handle < 0) return false; // Alright we are all set up, let's fill the first buffer. bool _filled= fillBuffers(); if (! _filled) return false; // Start this bitch up! int start = sceMp3Init(m_mp3Handle); if (start < 0) return false; m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle); m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle); #endif JLOG("End JMP3::load"); return true; }