static void *open_chd(const char *filename, movie_info *info) { int fps, fpsfrac, width, height, interlaced, channels, rate; char metadata[256]; chd_error chderr; chd_file *chd; /* open the file */ chderr = chd_open(filename, CHD_OPEN_READ, NULL, &chd); if (chderr != CHDERR_NONE) { fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr)); return NULL; } /* get the metadata */ chderr = chd_get_metadata(chd, AV_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL); if (chderr != CHDERR_NONE) { fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr)); chd_close(chd); return NULL; } /* extract the info */ if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7) { fprintf(stderr, "Improperly formatted metadata\n"); chd_close(chd); return NULL; } /* extract movie info */ info->framerate = (fps * 1000000 + fpsfrac) / 1000000.0; info->numframes = chd_get_header(chd)->totalhunks; info->width = width; info->height = height; info->samplerate = rate; info->channels = channels; /* convert to an interlaced frame */ chdinterlaced = interlaced; if (interlaced) { info->framerate /= 2; info->numframes = (info->numframes + 1) / 2; info->height *= 2; } return chd; }
struct hard_disk_file *hard_disk_open(struct chd_file *chd) { int cylinders, heads, sectors, sectorbytes; struct hard_disk_file *file; char metadata[256]; UINT32 metatag; UINT32 count; /* punt if no CHD */ if (!chd) return NULL; /* read the hard disk metadata */ metatag = HARD_DISK_STANDARD_METADATA; count = chd_get_metadata(chd, &metatag, 0, metadata, sizeof(metadata)); if (count == 0) return NULL; /* parse the metadata */ if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §orbytes) != 4) return NULL; /* allocate memory for the hard disk file */ file = malloc(sizeof(struct hard_disk_file)); if (!file) return NULL; /* fill in the data */ file->chd = chd; file->info.cylinders = cylinders; file->info.heads = heads; file->info.sectors = sectors; file->info.sectorbytes = sectorbytes; file->hunksectors = chd_get_header(chd)->hunkbytes / file->info.sectorbytes; file->cachehunk = -1; /* allocate a cache */ file->cache = malloc(chd_get_header(chd)->hunkbytes); if (!file->cache) { free(file); return NULL; } return file; }
hard_disk_file *hard_disk_open(chd_file *chd) { int cylinders, heads, sectors, sectorbytes; hard_disk_file *file; char metadata[256]; chd_error err; /* punt if no CHD */ if (chd == NULL) return NULL; /* read the hard disk metadata */ err = chd_get_metadata(chd, HARD_DISK_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL); if (err != CHDERR_NONE) return NULL; /* parse the metadata */ if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §orbytes) != 4) return NULL; /* allocate memory for the hard disk file */ file = (hard_disk_file *)malloc(sizeof(hard_disk_file)); if (file == NULL) return NULL; /* fill in the data */ file->chd = chd; file->info.cylinders = cylinders; file->info.heads = heads; file->info.sectors = sectors; file->info.sectorbytes = sectorbytes; file->hunksectors = chd_get_header(chd)->hunkbytes / file->info.sectorbytes; file->cachehunk = -1; /* allocate a cache */ file->cache = (UINT8 *)malloc(chd_get_header(chd)->hunkbytes); if (file->cache == NULL) { free(file); return NULL; } return file; }
bool CHDDisc::TryOpen(wchar* file) { chd_error err=chd_open(file,CHD_OPEN_READ,0,&chd); if (err!=CHDERR_NONE) return false; const chd_header* head = chd_get_header(chd); hunkbytes = head->hunkbytes; hunk_mem = new u8[hunkbytes]; old_hunk=0xFFFFFFF; sph = hunkbytes/(2352+96); if (hunkbytes%(2352+96)!=0) return false; u32 tag; u8 flags; char temp[512]; u32 temp_len; u32 total_frames=150; u32 total_secs=0; u32 total_hunks=0; for(;;) { err=chd_get_metadata(chd,CDROM_TRACK_METADATA2_TAG,tracks.size(),temp,sizeof(temp),&temp_len,&tag,&flags); if (err!=CHDERR_NONE) break; //"TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d PREGAP:%d PGTYPE:%s PGSUB:%s POSTGAP:%d" char type[64],subtype[32],pgtype[32],pgsub[32]; int tkid,frames,pregap,postgap; sscanf(temp,CDROM_TRACK_METADATA2_FORMAT,&tkid,type,subtype,&frames,&pregap,pgtype,pgsub,&postgap); if (tkid!=(tracks.size()+1) || (strcmp(type,"MODE1_RAW")!=0 && strcmp(type,"AUDIO")!=0) || strcmp(subtype,"NONE")!=0 || pregap!=0 || postgap!=0) return false; printf("%s\n",temp); Track t; t.StartFAD=total_frames; total_frames+=frames; t.EndFAD=total_frames-1; t.ADDR=0; t.CTRL=strcmp(type,"AUDIO")==0?0:4; t.file = new CHDTrack(this,t.StartFAD,total_hunks); total_hunks+=frames/sph; if (frames%sph) total_hunks++; tracks.push_back(t); } if (total_frames!=549300 || tracks.size()<3) return false; FillGDSession(); return true; }