static FLAC__StreamDecoderReadStatus file_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) { struct cdtoc *t = (struct cdtoc*)client_data; if (zfile_ftell (t->handle) >= zfile_size (t->handle)) return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; return zfile_fread (buffer, *bytes, 1, t->handle) ? FLAC__STREAM_DECODER_READ_STATUS_CONTINUE : FLAC__STREAM_DECODER_READ_STATUS_ABORT; }
zchunk_t * get_chunk (char *path, uint64_t chunk_size, uint64_t offset) { printf("[ST] GET CHUNK\n"); char *path_new = malloc(strlen("./syncfolder/") + strlen(path) + 1); path_new[0] = '\0'; strcat(path_new, "./syncfolder/"); strcat(path_new, path); if (zsys_file_exists (path_new)) { printf("[ST] File exist\n"); zfile_t *file = zfile_new (".", path_new); if (zfile_is_readable (file)) { printf("[ST] File read\n"); zfile_input (file); if (zfile_size (path_new) > offset) { zchunk_t *chunk = zfile_read (file, chunk_size, offset); zfile_destroy (&file); return chunk; } else { return NULL; } } } else { printf("[ST] File %s not exist\n", path_new); } return NULL; }
int zfile_test (bool verbose) { printf (" * zfile: "); // @selftest int rc = zfile_delete ("nosuchfile"); assert (rc == -1); rc = zfile_exists ("nosuchfile"); assert (rc != true); rc = (int) zfile_size ("nosuchfile"); assert (rc == -1); // @end printf ("OK\n"); return 0; }
static FLAC__bool file_eof_callback (const FLAC__StreamDecoder *decoder, void *client_data) { struct cdtoc *t = (struct cdtoc*)client_data; return zfile_ftell (t->handle) >= zfile_size (t->handle); }
static FLAC__StreamDecoderLengthStatus file_len_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) { struct cdtoc *t = (struct cdtoc*)client_data; *stream_length = zfile_size (t->handle); return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; }
static int parsemds (struct cdunit *cdu, struct zfile *zmds, const TCHAR *img) { MDS_Header *head; struct cdtoc *t; uae_u8 *mds = NULL; uae_u64 size; MDS_SessionBlock *sb; write_log (_T("MDS TOC: '%s'\n"), img); size = zfile_size (zmds); mds = xmalloc (uae_u8, size); if (!mds) goto end; if (zfile_fread (mds, size, 1, zmds) != 1) goto end; head = (MDS_Header*)mds; if (!memcmp (&head, MEDIA_DESCRIPTOR, strlen (MEDIA_DESCRIPTOR))) goto end; if (head->version[0] != 1) { write_log (_T("unsupported MDS version %d, only v.1 supported\n"), head->version[0]); goto end; } sb = (MDS_SessionBlock*)(mds + head->sessions_blocks_offset); cdu->tracks = sb->last_track - sb->first_track + 1; for (int i = 0; i < sb->num_all_blocks; i++) { MDS_TrackBlock *tb = (MDS_TrackBlock*)(mds + sb->tracks_blocks_offset + i * sizeof (MDS_TrackBlock)); int point = tb->point; int tracknum = -1; if (point == 0xa2) tracknum = cdu->tracks; else if (point >= 1 && point <= 99) tracknum = point - 1; if (tracknum >= 0) { MDS_Footer *footer = tb->footer_offset == 0 ? NULL : (MDS_Footer*)(mds + tb->footer_offset); MDS_TrackExtraBlock *teb = tb->extra_offset == 0 ? NULL : (MDS_TrackExtraBlock*)(mds + tb->extra_offset); t = &cdu->toc[tracknum]; t->adr = tb->adr_ctl >> 4; t->ctrl = tb->adr_ctl & 15; if (point == 0xa2) t->address = sb->session_end; else t->address = tb->start_sector; t->track = point; t->offset = tb->start_offset; t->size = tb->sector_size; if (point >= 100) continue; if (footer) { TCHAR *fname = NULL; if (footer->widechar_filename == 0) fname = au ((char*)(mds + footer->filename_offset)); else fname = my_strdup ((TCHAR*)(mds + footer->filename_offset)); if (fname[0] == '*' && fname[1] == '.') { TCHAR newname[MAX_DPATH]; _tcscpy (newname, img); TCHAR *ext = _tcsrchr (newname, '.'); if (ext) _tcscpy (ext, fname + 1); xfree (fname); fname = my_strdup (newname); } t->handle = zfile_fopen (fname, _T("rb"), ZFD_NORMAL); t->fname = my_strdup (fname); if (t->handle) t->filesize = zfile_size (t->handle); } if (tb->subchannel && t->handle) { t->suboffset = t->size; t->subcode = 1; // interleaved t->subhandle = zfile_dup (t->handle); t->skipsize = SUB_CHANNEL_SIZE; t->size -= SUB_CHANNEL_SIZE; } if ((t->ctrl & 0x0c) != 4) t->enctype = AUDENC_PCM; } }