comparison mplayer.c @ 1467:f352e1e951ba

stream opening -> open.c, initialframes ignored
author arpi
date Thu, 09 Aug 2001 01:17:24 +0000
parents 7845f6d7c4ba
children 6f9167f0fcca
comparison
equal deleted inserted replaced
1466:7845f6d7c4ba 1467:f352e1e951ba
71 #ifdef HAVE_LIRC 71 #ifdef HAVE_LIRC
72 #include "lirc_mp.h" 72 #include "lirc_mp.h"
73 #endif 73 #endif
74 74
75 #include "help_mp.h" 75 #include "help_mp.h"
76
77 #ifdef STREAMING
78 #include "url.h"
79 #include "network.h"
80 static URL_t* url;
81 #endif
82 76
83 77
84 #define DEBUG if(0) 78 #define DEBUG if(0)
85 #ifdef HAVE_GUI 79 #ifdef HAVE_GUI
86 int nogui=1; 80 int nogui=1;
383 } 377 }
384 #endif 378 #endif
385 exit_player(NULL); 379 exit_player(NULL);
386 } 380 }
387 381
388 extern int vcd_get_track_end(int fd,int track); 382 extern stream_t* open_stream(char* filename,int vcd_track,int* file_format);
383
389 extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height); 384 extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
390 385
391 // dec_audio.c: 386 // dec_audio.c:
392 extern int init_audio(sh_audio_t *sh_audio); 387 extern int init_audio(sh_audio_t *sh_audio);
393 extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen); 388 extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen);
456 char* filename=NULL; //"MI2-Trailer.avi"; 451 char* filename=NULL; //"MI2-Trailer.avi";
457 stream_t* stream=NULL; 452 stream_t* stream=NULL;
458 int file_format=DEMUXER_TYPE_UNKNOWN; 453 int file_format=DEMUXER_TYPE_UNKNOWN;
459 // 454 //
460 int delay_corrected=1; 455 int delay_corrected=1;
461 #ifdef VCD_CACHE
462 int vcd_cache_size=128;
463 #endif
464 #ifdef __FreeBSD__
465 int bsize = VCD_SECTOR_SIZE;
466 #endif
467 char* title="MPlayer"; 456 char* title="MPlayer";
468 457
469 // movie info: 458 // movie info:
470 int out_fmt=0; 459 int out_fmt=0;
471 460
481 //float a_frame=0; // Audio 470 //float a_frame=0; // Audio
482 471
483 float rel_seek_secs=0; 472 float rel_seek_secs=0;
484 473
485 int i; 474 int i;
486 int f; // filedes 475 int use_stdin=0; //int f; // filedes
487 476
488 printf("%s",banner_text); 477 printf("%s",banner_text);
489 478
490 #ifdef HAVE_GUI 479 #ifdef HAVE_GUI
491 if ( nogui ) 480 if ( nogui )
623 // check .sub 612 // check .sub
624 if(sub_name){ 613 if(sub_name){
625 subtitles=sub_read_file(sub_name); 614 subtitles=sub_read_file(sub_name);
626 if(!subtitles) fprintf(stderr,"Can't load subtitles: %s\n",sub_name); 615 if(!subtitles) fprintf(stderr,"Can't load subtitles: %s\n",sub_name);
627 } else { 616 } else {
628 if ( sub_auto ) 617 if(sub_auto) // auto load sub file ...
629 { 618 subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) );
630 // auto load sub file ... 619 if(!subtitles) subtitles=sub_read_file(get_path("default.sub")); // try default
631 subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) ); 620 }
632 } 621 #endif
633 if ( subtitles == NULL ) subtitles=sub_read_file(get_path("default.sub")); // try default: 622
634 } 623 stream=open_stream(filename,vcd_track,&file_format);
635 #endif 624 if(!stream) return 1; // error...
636 625 use_stdin=(!strcmp(filename,"-"));
637 if(vcd_track){
638 //============ Open VideoCD track ==============
639 int ret,ret2;
640 f=open(filename,O_RDONLY);
641 if(f<0){ fprintf(stderr,"CD-ROM Device '%s' not found!\n",filename);return 1; }
642 vcd_read_toc(f);
643 ret2=vcd_get_track_end(f,vcd_track);
644 if(ret2<0){ fprintf(stderr,"Error selecting VCD track! (get)\n");return 1;}
645 ret=vcd_seek_to_track(f,vcd_track);
646 if(ret<0){ fprintf(stderr,"Error selecting VCD track! (seek)\n");return 1;}
647 seek_to_byte+=ret;
648 if(verbose) printf("VCD start byte position: 0x%X end: 0x%X\n",seek_to_byte,ret2);
649 #ifdef VCD_CACHE
650 vcd_cache_init(vcd_cache_size);
651 #endif
652 #ifdef __FreeBSD__
653 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
654 perror ( "Error in CDRIOCSETBLOCKSIZE");
655 }
656 #endif
657 stream=new_stream(f,STREAMTYPE_VCD);
658 stream->start_pos=ret;
659 stream->end_pos=ret2;
660 } else {
661 //============ Open plain FILE ============
662 off_t len;
663 if(!strcmp(filename,"-")){
664 // read from stdin
665 printf("Reading from stdin...\n");
666 f=0; // 0=stdin
667 stream=new_stream(f,STREAMTYPE_STREAM);
668 } else {
669 #ifdef STREAMING
670 url = url_new(filename);
671 if(url==NULL) {
672 // failed to create a new URL, so it's not an URL (or a malformed URL)
673 #endif
674 f=open(filename,O_RDONLY);
675 if(f<0){ fprintf(stderr,"File not found: '%s'\n",filename);return 1; }
676 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
677 if (len == -1)
678 perror("Error: lseek failed to obtain video file size");
679 else
680 if(verbose)
681 #ifdef _LARGEFILE_SOURCE
682 printf("File size is %lld bytes\n", (long long)len);
683 #else
684 printf("File size is %u bytes\n", (unsigned int)len);
685 #endif
686 stream=new_stream(f,STREAMTYPE_FILE);
687 stream->end_pos=len;
688 #ifdef STREAMING
689 } else {
690 file_format=autodetectProtocol( url, &f );
691 if( file_format==DEMUXER_TYPE_UNKNOWN ) {
692 fprintf(stderr,"Unable to open URL: %s\n", filename);
693 url_free(url);
694 return 1;
695 } else {
696 f=streaming_start( &url, f, file_format );
697 if(f<0){ fprintf(stderr,"Unable to open URL: %s\n", url->url); return 1; }
698 printf("Connected to server: %s\n", url->hostname );
699 }
700 stream=new_stream(f,STREAMTYPE_STREAM);
701 }
702 #endif
703 }
704 }
705 626
706 #ifdef HAVE_LIBCSS 627 #ifdef HAVE_LIBCSS
707 if (dvdimportkey) { 628 if (dvdimportkey) {
708 if (dvd_import_key(dvdimportkey)) { 629 if (dvd_import_key(dvdimportkey)) {
709 fprintf(stderr,"Error processing DVD KEY.\n"); 630 fprintf(stderr,"Error processing DVD KEY.\n");
1060 { 981 {
1061 #endif 982 #endif
1062 #ifdef USE_TERMCAP 983 #ifdef USE_TERMCAP
1063 load_termcap(NULL); // load key-codes 984 load_termcap(NULL); // load key-codes
1064 #endif 985 #endif
1065 if(f) getch2_enable(); 986 if(!use_stdin) getch2_enable();
1066 #ifdef HAVE_GUI 987 #ifdef HAVE_GUI
1067 } 988 }
1068 #endif 989 #endif
1069 990
1070 //========= Catch terminate signals: ================ 991 //========= Catch terminate signals: ================
1445 } else { 1366 } else {
1446 if(!delay_corrected && d_audio->pts){ 1367 if(!delay_corrected && d_audio->pts){
1447 // float x=d_audio->pts-d_video->pts-(delay); 1368 // float x=d_audio->pts-d_video->pts-(delay);
1448 float x=d_audio->pts-d_video->pts-(delay+audio_delay); 1369 float x=d_audio->pts-d_video->pts-(delay+audio_delay);
1449 float y=-(delay+audio_delay); 1370 float y=-(delay+audio_delay);
1450 printf("Initial PTS delay: %5.3f sec (calculated: %5.3f) audio_delay=%5.3f\n",x,y,audio_delay); 1371 float bps_a_pts=(ds_tell(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->wf->nAvgBytesPerSec;
1451 initial_pts_delay+=x; 1372 float bps_v_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
1452 audio_delay+=x; 1373 printf("Initial PTS delay: %5.3f sec ->%5.3f (bps: %5.3f) audio_delay=%5.3f\n",x,2*sh_video->frametime,bps_a_pts-bps_v_pts-(delay+audio_delay),audio_delay);
1374 x=2*sh_video->frametime;
1375 // initial_pts_delay+=x; audio_delay+=x;
1453 delay_corrected=1; 1376 delay_corrected=1;
1454 if(verbose) 1377 if(verbose)
1455 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n", 1378 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n",
1456 audio_delay,delay,d_audio->pts,d_video->pts); 1379 audio_delay,delay,d_audio->pts,d_video->pts);
1457 } 1380 }
1560 #endif 1483 #endif
1561 while( 1484 while(
1562 #ifdef HAVE_LIRC 1485 #ifdef HAVE_LIRC
1563 lirc_mp_getinput()<=0 && 1486 lirc_mp_getinput()<=0 &&
1564 #endif 1487 #endif
1565 (!f || getch2(20)<=0) && mplayer_get_key()<=0){ 1488 (use_stdin || getch2(20)<=0) && mplayer_get_key()<=0){
1566 #ifndef USE_LIBVO2 1489 #ifndef USE_LIBVO2
1567 video_out->check_events(); 1490 video_out->check_events();
1568 #endif 1491 #endif
1569 if(!f) usec_sleep(1000); // do not eat the CPU 1492 if(use_stdin) usec_sleep(1000); // do not eat the CPU
1570 } 1493 }
1571 osd_function=OSD_PLAY; 1494 osd_function=OSD_PLAY;
1572 #ifdef HAVE_GUI 1495 #ifdef HAVE_GUI
1573 } else while( osd_function != OSD_PLAY ) usec_sleep( 1000 ); 1496 } else while( osd_function != OSD_PLAY ) usec_sleep( 1000 );
1574 #endif 1497 #endif
1586 { int c; 1509 { int c;
1587 while( 1510 while(
1588 #ifdef HAVE_LIRC 1511 #ifdef HAVE_LIRC
1589 (c=lirc_mp_getinput())>0 || 1512 (c=lirc_mp_getinput())>0 ||
1590 #endif 1513 #endif
1591 (f && (c=getch2(0))>0) || (c=mplayer_get_key())>0) switch(c){ 1514 (!use_stdin && (c=getch2(0))>0) || (c=mplayer_get_key())>0) switch(c){
1592 // seek 10 sec 1515 // seek 10 sec
1593 case KEY_RIGHT: 1516 case KEY_RIGHT:
1594 osd_function=OSD_FFW; 1517 osd_function=OSD_FFW;
1595 rel_seek_secs+=10;break; 1518 rel_seek_secs+=10;break;
1596 case KEY_LEFT: 1519 case KEY_LEFT: