static int gif_seek_data(UINT32 fh,long offset, UINT32 origin) { #ifdef ENABLE_PE_CACHE if(gif_cache_id >= 0) { pe_cache_seek(gif_cache_id, (off_t)offset, origin); return 0; } #endif #ifndef ENABLE_PE_CACHE FILE *fp = (FILE*)fh; if(fp == NULL) { return -1; } fseek(fp, (off_t)offset, origin); #endif return 0; }
static int ogg_get_song_info(char *filename, MusicInfo *music_info) { int status = 3; FILE *file; unsigned long file_length; int bitrate; double song_time; OggVorbis_File temp_ogg; PE_DBG_PRINTF("MusicEngine: ==> ogg_get_song_info()! \n"); if ((!filename) || (!music_info) || (!ogg_file)) { PE_DBG_PRINTF("MusicEngine: ogg_get_song_info() invalid parameter filename or music_info or ogg_file!\n"); return -1; } #ifndef ENABLE_PE_CACHE file = fopen(filename, "rb"); // get_song_info打开文件 if (!file) { PE_DBG_PRINTF("MusicEngine: ogg_get_song_info() fopen failed! \n"); return -1; } fseek(file, 0, SEEK_END); file_length = ftell(file); music_info->file_length = file_length; fseek(file, 0, SEEK_SET); #else ogg_info_cache_id = pe_cache_open(filename, NULL, OGG_CACHE_SIZE, OGG_BLOCK_SIZE); if (0 > ogg_info_cache_id) { libc_printf("<%d><%s> pe_cache_open failed!\n", __LINE__, __FUNCTION__); return -1; } file = (FILE *)(((UINT32)ogg_info_cache_id | PE_CACHE_ID_TAG)); pe_cache_seek(ogg_info_cache_id, 0, SEEK_END); file_length = pe_cache_tell(ogg_info_cache_id); music_info->file_length = file_length; pe_cache_seek(ogg_info_cache_id, 0, SEEK_SET); #endif if(ov_open(file, &temp_ogg, NULL, 0) < 0) // 如果这里紧跟着调用ov的函数,则里面的文件系统函数都是stdio,不是pe_cache { PE_DBG_PRINTF("Input does not appear to be an Ogg bitstream.\n"); #ifndef ENABLE_PE_CACHE fclose(file); #else pe_cache_close(ogg_info_cache_id); ogg_info_cache_id = -1; #endif return -1; } song_time = ov_time_total(&temp_ogg, -1); if (song_time < 0) { PE_DBG_PRINTF("Can not get song time from Ogg bitstream.\n"); song_time = 0; } music_info->time = song_time / 1000; ov_clear(&temp_ogg); // get_song_info完毕,在这里close文件 PE_DBG_PRINTF("MusicEngine: <== ogg_get_song_info()! \n"); return status; }