comparison libmpdemux/cue_read.c @ 15477:15f012150986

more efficient read() without memcpy()
author nicodvb
date Sun, 15 May 2005 07:59:30 +0000
parents 5eb4994a691f
children c4af653727eb
comparison
equal deleted inserted replaced
15476:5eb4994a691f 15477:15f012150986
322 *t = '\0'; 322 *t = '\0';
323 t = s; 323 t = s;
324 if (*t == '\0') 324 if (*t == '\0')
325 strcpy(t, "/"); 325 strcpy(t, "/");
326 } 326 }
327 printf ("dirname: %s\n", t); 327 mp_msg(MSGT_OPEN,MSGL_V,"dirname: %s\n", t);
328 strlcpy(bincue_path,t,sizeof( bincue_path )); 328 strlcpy(bincue_path,t,sizeof( bincue_path ));
329 329
330 330
331 /* no path at all? */ 331 /* no path at all? */
332 if (strcmp(bincue_path, ".") == 0) { 332 if (strcmp(bincue_path, ".") == 0) {
333 printf ("bincue_path: %s\n", bincue_path); 333 mp_msg(MSGT_OPEN,MSGL_V,"bincue_path: %s\n", bincue_path);
334 strlcpy(cue_filename,in_cue_filename,sizeof( cue_filename )); 334 strlcpy(cue_filename,in_cue_filename,sizeof( cue_filename ));
335 } else { 335 } else {
336 strlcpy(cue_filename,in_cue_filename + strlen(bincue_path) + 1, 336 strlcpy(cue_filename,in_cue_filename + strlen(bincue_path) + 1,
337 sizeof( cue_filename )); 337 sizeof( cue_filename ));
338 } 338 }
460 cue_current_pos.frame = tracks[track].frame; 460 cue_current_pos.frame = tracks[track].frame;
461 461
462 return 0; 462 return 0;
463 } 463 }
464 464
465 static int cue_read_raw(char *buf) {
466 unsigned long position;
467 int track = cue_current_pos.track - 1;
468
469 /* get the mode of the bin file part and calc the positon */
470 position = tracks[track].start_offset +
471 (cue_msf_2_sector(cue_current_pos.minute,
472 cue_current_pos.second,
473 cue_current_pos.frame) -
474 tracks[track].start_sector)
475 * cue_mode_2_sector_size(tracks[track].mode);
476
477 /* check if the track is at its end*/
478 if (position >= tracks[track+1].start_offset)
479 return -1;
480
481 if (lseek (fd_bin, position, SEEK_SET) == -1) {
482 mp_msg(MSGT_OPEN,MSGL_ERR,
483 "[bincue] unexpected end of bin file\n");
484 return -1;
485 }
486
487 if (!read (fd_bin, buf, VCD_SECTOR_SIZE))
488 return -1;
489 else
490 return VCD_SECTOR_DATA;
491 }
492
493
494
495 static int cue_vcd_seek_to_track (int track){ 465 static int cue_vcd_seek_to_track (int track){
496 cue_current_pos.track = track; 466 cue_current_pos.track = track;
497 467
498 if (cue_read_toc_entry ()) 468 if (cue_read_toc_entry ())
499 return -1; 469 return -1;
522 tracks[i].frame 492 tracks[i].frame
523 ); 493 );
524 } 494 }
525 } 495 }
526 496
527
528 static char vcd_buf[VCD_SECTOR_SIZE];
529
530 static int cue_vcd_read(stream_t *stream, char *mem, int size) { 497 static int cue_vcd_read(stream_t *stream, char *mem, int size) {
531 498 unsigned long position;
532 if (cue_read_raw(vcd_buf)==-1) return 0; // EOF? 499 int track = cue_current_pos.track - 1;
533 500 unsigned char tmp[VCD_SECTOR_OFFS];
534 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA); 501
502 position = tracks[track].start_offset +
503 (cue_msf_2_sector(cue_current_pos.minute,
504 cue_current_pos.second,
505 cue_current_pos.frame) -
506 tracks[track].start_sector)
507 * cue_mode_2_sector_size(tracks[track].mode);
508
509
510 if(position >= tracks[track+1].start_offset)
511 return 0;
512
513 if(lseek(fd_bin, position, SEEK_SET) == -1) {
514 mp_msg(MSGT_OPEN,MSGL_ERR, "[bincue] unexpected end of bin file\n");
515 return 0;
516 }
517
518 if(read(fd_bin, tmp, VCD_SECTOR_OFFS) != VCD_SECTOR_OFFS) {
519 mp_msg(MSGT_OPEN,MSGL_ERR, "[bincue] couldn't skip %d bytes before payload\n", VCD_SECTOR_OFFS);
520 return 0;
521 }
522
523 if(read(fd_bin, mem, VCD_SECTOR_DATA) != VCD_SECTOR_DATA) {
524 mp_msg(MSGT_OPEN,MSGL_ERR, "[bincue] couldn't read %d bytes of payload\n", VCD_SECTOR_DATA);
525 return 0;
526 }
535 527
536 cue_current_pos.frame++; 528 cue_current_pos.frame++;
537 if (cue_current_pos.frame==75){ 529 if (cue_current_pos.frame==75){
538 cue_current_pos.frame=0; 530 cue_current_pos.frame=0;
539 cue_current_pos.second++; 531 cue_current_pos.second++;