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; }
cdrom_file *cdrom_open(const char *inputfile) { int i; cdrom_file *file; UINT32 physofs; /* allocate memory for the CD-ROM file */ file = (cdrom_file *)malloc(sizeof(cdrom_file)); if (file == NULL) return NULL; /* setup the CDROM module and get the disc info */ chd_error err = chdcd_parse_toc(inputfile, &file->cdtoc, &file->track_info); if (err != CHDERR_NONE) { fprintf(stderr, "Error reading input file: %s\n", chd_error_string(err)); return NULL; } /* fill in the data */ file->chd = NULL; file->hunksectors = 1; file->cachehunk = -1; LOG(("CD has %d tracks\n", file->cdtoc.numtrks)); for (i = 0; i < file->cdtoc.numtrks; i++) { file_error filerr = core_fopen(file->track_info.fname[i], OPEN_FLAG_READ, &file->fhandle[i]); if (filerr != FILERR_NONE) { fprintf(stderr, "Unable to open file: %s\n", file->track_info.fname[i]); return NULL; } } /* calculate the starting frame for each track, keeping in mind that CHDMAN pads tracks out with extra frames to fit hunk size boundries */ physofs = 0; for (i = 0; i < file->cdtoc.numtrks; i++) { file->cdtoc.tracks[i].physframeofs = physofs; file->cdtoc.tracks[i].chdframeofs = 0; physofs += file->cdtoc.tracks[i].frames; LOG(("Track %02d is format %d subtype %d datasize %d subsize %d frames %d extraframes %d physofs %d chdofs %d\n", i+1, file->cdtoc.tracks[i].trktype, file->cdtoc.tracks[i].subtype, file->cdtoc.tracks[i].datasize, file->cdtoc.tracks[i].subsize, file->cdtoc.tracks[i].frames, file->cdtoc.tracks[i].extraframes, file->cdtoc.tracks[i].physframeofs, file->cdtoc.tracks[i].chdframeofs)); } /* fill out dummy entries for the last track to help our search */ file->cdtoc.tracks[i].physframeofs = physofs; file->cdtoc.tracks[i].chdframeofs = 0; /* allocate a cache */ file->cache = (UINT8 *)malloc(CD_FRAME_SIZE); if (file->cache == NULL) { free(file); return NULL; } return file; }