/** * callback_c(cookie, buf, buflen): * Handle a chunk ${buf} of length ${buflen} from the chunk index stream of * the tape associated with the multitape write cookie ${cookie}. */ static int callback_c(void * cookie, uint8_t * buf, size_t buflen) { struct multitape_write_internal * d = cookie; return (handle_chunk(buf, buflen, &d->c, d->C)); }
int gavf_open_read(gavf_t * g, gavf_io_t * io) { char sig[8]; g->io = io; g->opt.flags &= ~(GAVF_OPT_FLAG_SYNC_INDEX| GAVF_OPT_FLAG_PACKET_INDEX); /* Initialize packet buffer */ gavf_io_init_buf_read(&g->pkt_io, &g->pkt_buf); gavf_io_init_buf_read(&g->meta_io, &g->meta_buf); /* Read up to the first sync header */ while(1) { if(gavf_io_read_data(g->io, (uint8_t*)sig, 8) < 8) return 0; if(!handle_chunk(g, sig)) return 0; if(g->first_sync_pos > 0) break; } gavf_footer_check(g); /* Dump stuff */ if(g->opt.flags & GAVF_OPT_FLAG_DUMP_HEADERS) { gavf_program_header_dump(&g->ph); if(g->cl) gavl_chapter_list_dump(g->cl); } if(g->opt.flags & GAVF_OPT_FLAG_DUMP_INDICES) { if((g->opt.flags & GAVF_OPT_FLAG_DUMP_INDICES) || (g->opt.flags & GAVF_OPT_FLAG_SYNC_INDEX)) gavf_sync_index_dump(&g->si); if((g->opt.flags & GAVF_OPT_FLAG_DUMP_INDICES) || (g->opt.flags & GAVF_OPT_FLAG_PACKET_INDEX)) gavf_packet_index_dump(&g->pi); } gavf_reset(g); if(!(g->opt.flags & GAVF_OPT_FLAG_ORIG_PTS)) calc_pts_offset(g); return 1; }
void descramble(uint8 *source, uint8 *dest, uint32 size) { load(source, 0); my_srand(size); /* Descramble 2 meg blocks for as long as possible, then gradually reduce the window down to 32 bytes (1 slice) */ for(uint32 chunksz = MAXCHUNK; chunksz >= 32; chunksz >>= 1) { while(size >= chunksz) { handle_chunk(dest, chunksz); size -= chunksz; dest += chunksz; } } /* !!! Load final incomplete slice */ if(size) load(dest, size); }