Mercurial > mplayer.hg
comparison mplayer.c @ 1639:9423cb98e63f
initial multifile support
author | arpi |
---|---|
date | Wed, 22 Aug 2001 21:35:44 +0000 |
parents | 13aeaa05ac5e |
children | b7dae998505c |
comparison
equal
deleted
inserted
replaced
1638:671802bf867b | 1639:9423cb98e63f |
---|---|
313 // restore terminal: | 313 // restore terminal: |
314 #ifdef HAVE_GUI | 314 #ifdef HAVE_GUI |
315 if ( nogui ) | 315 if ( nogui ) |
316 #endif | 316 #endif |
317 getch2_disable(); | 317 getch2_disable(); |
318 | |
318 #ifdef USE_LIBVO2 | 319 #ifdef USE_LIBVO2 |
319 if(video_out) vo2_close(video_out); | 320 if(video_out) vo2_close(video_out); |
320 #else | 321 #else |
321 if(video_out) video_out->uninit(); | 322 if(video_out) video_out->uninit(); |
322 #endif | 323 #endif |
326 #ifdef HAVE_GUI | 327 #ifdef HAVE_GUI |
327 if ( nogui ) | 328 if ( nogui ) |
328 #endif | 329 #endif |
329 lirc_mp_cleanup(); | 330 lirc_mp_cleanup(); |
330 #endif | 331 #endif |
332 | |
331 exit(1); | 333 exit(1); |
332 } | 334 } |
333 | 335 |
334 static char* current_module=NULL; // for debugging | 336 static char* current_module=NULL; // for debugging |
335 | 337 |
459 mp_msg_init(MSGL_STATUS); | 461 mp_msg_init(MSGL_STATUS); |
460 | 462 |
461 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); | 463 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); |
462 | 464 |
463 #ifdef HAVE_GUI | 465 #ifdef HAVE_GUI |
464 if ( nogui ) | 466 if ( nogui ) { |
465 { | 467 #endif |
466 #endif | 468 |
467 parse_cfgfiles(); | 469 parse_cfgfiles(); |
468 if ((num_filenames=parse_command_line(conf, argc, argv, envp, &filenames)) < 0) exit(1); | 470 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); |
469 printf("XXX num_filenames: %d\n",num_filenames); | 471 if(num_filenames<0) exit(1); // error parsing cmdline |
470 curr_filename=0; | 472 if(!num_filenames && !vcd_track && !dvd_title){ |
471 filename=(num_filenames>0)?filenames[curr_filename]:NULL; | 473 // no file/vcd/dvd -> show HELP: |
472 | 474 printf("%s",help_text); |
473 mp_msg_init(verbose+MSGL_STATUS); | 475 exit(0); |
476 } | |
474 | 477 |
475 // Many users forget to include command line in bugreports... | 478 // Many users forget to include command line in bugreports... |
476 if(verbose){ | 479 if(verbose){ |
477 printf("CommandLine:"); | 480 printf("CommandLine:"); |
478 for(i=1;i<argc;i++)printf(" '%s'",argv[i]); | 481 for(i=1;i<argc;i++)printf(" '%s'",argv[i]); |
479 printf("\n"); | 482 printf("\n"); |
483 printf("num_filenames: %d\n",num_filenames); | |
480 } | 484 } |
481 | 485 |
482 #ifndef USE_LIBVO2 | 486 #ifndef USE_LIBVO2 |
483 if(video_driver && strcmp(video_driver,"help")==0){ | 487 if(video_driver && strcmp(video_driver,"help")==0){ |
484 printf("Available video output drivers:\n"); | 488 printf("Available video output drivers:\n"); |
499 printf("\t%s\t%s\n", info->short_name, info->name); | 503 printf("\t%s\t%s\n", info->short_name, info->name); |
500 } | 504 } |
501 printf("\n"); | 505 printf("\n"); |
502 exit(0); | 506 exit(0); |
503 } | 507 } |
508 | |
504 #ifdef HAVE_GUI | 509 #ifdef HAVE_GUI |
505 } | 510 } |
506 #endif | 511 #endif |
507 | 512 |
508 if(!filename){ | 513 mp_msg_init(verbose+MSGL_STATUS); |
509 if(!vcd_track && !dvd_title){ | 514 |
510 printf("%s",help_text); exit(0); | 515 //------ load global data first ------ |
511 } | 516 |
512 } | 517 // check codec.conf |
518 if(!parse_codec_cfg(get_path("codecs.conf"))){ | |
519 if(!parse_codec_cfg(DATADIR"/codecs.conf")){ | |
520 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf); | |
521 exit(1); | |
522 } | |
523 } | |
524 | |
525 // check font | |
526 #ifdef USE_OSD | |
527 if(font_name){ | |
528 vo_font=read_font_desc(font_name,font_factor,verbose>1); | |
529 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name); | |
530 } else { | |
531 // try default: | |
532 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1); | |
533 if(!vo_font) | |
534 vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1); | |
535 } | |
536 #endif | |
537 | |
538 #ifdef USE_SUB | |
539 // check .sub | |
540 if(sub_name){ | |
541 int l=strlen(sub_name); | |
542 if ((l>4) && ((0==strcmp(&sub_name[l-4],".utf")) | |
543 ||(0==strcmp(&sub_name[l-4],".UTF")))) | |
544 sub_utf8=1; | |
545 subtitles=sub_read_file(sub_name); | |
546 if(!subtitles) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,sub_name); | |
547 } else { | |
548 if(sub_auto && filename) // auto load sub file ... | |
549 subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) ); | |
550 if(!subtitles) subtitles=sub_read_file(get_path("default.sub")); // try default | |
551 } | |
552 #endif | |
553 | |
554 | |
555 #ifdef HAVE_LIRC | |
556 #ifdef HAVE_GUI | |
557 if ( nogui ) | |
558 #endif | |
559 lirc_mp_setup(); | |
560 #endif | |
561 | |
562 #ifdef USE_TERMCAP | |
563 load_termcap(NULL); // load key-codes | |
564 #endif | |
565 | |
566 //========= Catch terminate signals: ================ | |
567 // terminate requests: | |
568 signal(SIGTERM,exit_sighandler); // kill | |
569 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed | |
570 | |
571 #ifdef HAVE_GUI | |
572 if ( nogui ) | |
573 #endif | |
574 signal(SIGINT,exit_sighandler); // Interrupt from keyboard | |
575 | |
576 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
577 // fatal errors: | |
578 signal(SIGBUS,exit_sighandler); // bus error | |
579 signal(SIGSEGV,exit_sighandler); // segfault | |
580 signal(SIGILL,exit_sighandler); // illegal instruction | |
581 signal(SIGFPE,exit_sighandler); // floating point exc. | |
582 signal(SIGABRT,exit_sighandler); // abort() | |
583 | |
584 | |
585 // ******************* Now, let's see the per-file stuff ******************** | |
586 | |
587 curr_filename=0; | |
588 play_next_file: | |
589 filename=(num_filenames>0)?filenames[curr_filename]:NULL; | |
513 | 590 |
514 #ifdef USE_LIBVO2 | 591 #ifdef USE_LIBVO2 |
592 current_module="vo2_new"; | |
515 video_out=vo2_new(video_driver); | 593 video_out=vo2_new(video_driver); |
594 current_module=NULL; | |
516 #else | 595 #else |
517 // check video_out driver name: | 596 // check video_out driver name: |
518 if (video_driver) | 597 if (video_driver) |
519 if ((i = strcspn(video_driver, ":")) > 0) | 598 if ((i = strcspn(video_driver, ":")) > 0) |
520 { | 599 { |
539 } | 618 } |
540 } | 619 } |
541 #endif | 620 #endif |
542 if(!video_out){ | 621 if(!video_out){ |
543 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_InvalidVOdriver,video_driver?video_driver:"?"); | 622 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_InvalidVOdriver,video_driver?video_driver:"?"); |
544 return 0; | 623 exit_player(MSGTR_Exit_error); |
545 } | 624 } |
546 | 625 |
547 // check audio_out driver name: | 626 // check audio_out driver name: |
548 if (audio_driver) | 627 if (audio_driver) |
549 if ((i = strcspn(audio_driver, ":")) > 0) | 628 if ((i = strcspn(audio_driver, ":")) > 0) |
568 audio_out = audio_out_drivers[i];break; | 647 audio_out = audio_out_drivers[i];break; |
569 } | 648 } |
570 } | 649 } |
571 if (!audio_out){ | 650 if (!audio_out){ |
572 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_InvalidAOdriver,audio_driver); | 651 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_InvalidAOdriver,audio_driver); |
573 return 0; | 652 exit_player(MSGTR_Exit_error); |
574 } | 653 } |
575 /*DSP!! if(dsp) audio_out->control(AOCONTROL_SET_DEVICE,(int)dsp);*/ | 654 /*DSP!! if(dsp) audio_out->control(AOCONTROL_SET_DEVICE,(int)dsp);*/ |
576 | 655 |
577 // check codec.conf | 656 |
578 if(!parse_codec_cfg(get_path("codecs.conf"))){ | 657 current_module="open_stream"; |
579 if(!parse_codec_cfg(DATADIR"/codecs.conf")){ | |
580 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf); | |
581 exit(1); | |
582 } | |
583 } | |
584 | |
585 // check font | |
586 #ifdef USE_OSD | |
587 if(font_name){ | |
588 vo_font=read_font_desc(font_name,font_factor,verbose>1); | |
589 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name); | |
590 } else { | |
591 // try default: | |
592 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1); | |
593 if(!vo_font) | |
594 vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1); | |
595 } | |
596 #endif | |
597 | |
598 #ifdef USE_SUB | |
599 // check .sub | |
600 if(sub_name){ | |
601 int l=strlen(sub_name); | |
602 if ((l>4) && ((0==strcmp(&sub_name[l-4],".utf")) | |
603 ||(0==strcmp(&sub_name[l-4],".UTF")))) | |
604 sub_utf8=1; | |
605 subtitles=sub_read_file(sub_name); | |
606 if(!subtitles) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,sub_name); | |
607 } else { | |
608 if(sub_auto && filename) // auto load sub file ... | |
609 subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) ); | |
610 if(!subtitles) subtitles=sub_read_file(get_path("default.sub")); // try default | |
611 } | |
612 #endif | |
613 | |
614 stream=open_stream(filename,vcd_track,&file_format); | 658 stream=open_stream(filename,vcd_track,&file_format); |
615 if(!stream) return 1; // error... | 659 if(!stream) exit_player(MSGTR_Exit_error); // error... |
660 stream->start_pos+=seek_to_byte; | |
661 | |
616 use_stdin=filename && (!strcmp(filename,"-")); | 662 use_stdin=filename && (!strcmp(filename,"-")); |
617 stream->start_pos+=seek_to_byte; | |
618 | 663 |
619 #ifdef HAVE_LIBCSS | 664 #ifdef HAVE_LIBCSS |
665 current_module="libcss"; | |
620 if (dvdimportkey) { | 666 if (dvdimportkey) { |
621 if (dvd_import_key(dvdimportkey)) { | 667 if (dvd_import_key(dvdimportkey)) { |
622 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey); | 668 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey); |
623 exit(1); | 669 exit_player(MSGTR_Exit_error); |
624 } | 670 } |
625 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey); | 671 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey); |
626 } | 672 } |
627 if (dvd_auth_device) { | 673 if (dvd_auth_device) { |
628 // if (dvd_auth(dvd_auth_device,f)) { | 674 // if (dvd_auth(dvd_auth_device,f)) { |
629 if (dvd_auth(dvd_auth_device,filename)) { | 675 if (dvd_auth(dvd_auth_device,filename)) { |
630 GUI_MSG( mplErrorDVDAuth ) | 676 GUI_MSG( mplErrorDVDAuth ) |
631 exit(0); | 677 exit_player(MSGTR_Exit_error); |
632 } | 678 } |
633 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk); | 679 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk); |
634 } | 680 } |
635 #endif | 681 #endif |
636 | 682 |
637 //============ Open & Sync stream and detect file format =============== | 683 //============ Open & Sync stream and detect file format =============== |
638 | 684 |
639 if(!has_audio) audio_id=-2; // do NOT read audio packets... | 685 if(!has_audio) audio_id=-2; // do NOT read audio packets... |
640 | 686 |
687 current_module="demux_open"; | |
688 | |
641 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id); | 689 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id); |
642 if(!demuxer) exit(1); // ERROR | 690 if(!demuxer) exit_player(MSGTR_Exit_error); // ERROR |
643 | 691 |
644 file_format=demuxer->file_format; | 692 file_format=demuxer->file_format; |
645 | 693 |
646 d_audio=demuxer->audio; | 694 d_audio=demuxer->audio; |
647 d_video=demuxer->video; | 695 d_video=demuxer->video; |
649 | 697 |
650 // DUMP STREAMS: | 698 // DUMP STREAMS: |
651 if(stream_dump_type){ | 699 if(stream_dump_type){ |
652 FILE *f; | 700 FILE *f; |
653 demux_stream_t *ds=NULL; | 701 demux_stream_t *ds=NULL; |
702 current_module="dump"; | |
654 // select stream to dump | 703 // select stream to dump |
655 switch(stream_dump_type){ | 704 switch(stream_dump_type){ |
656 case 1: ds=d_audio;break; | 705 case 1: ds=d_audio;break; |
657 case 2: ds=d_video;break; | 706 case 2: ds=d_video;break; |
658 case 3: ds=d_dvdsub;break; | 707 case 3: ds=d_dvdsub;break; |
659 } | 708 } |
660 if(!ds){ | 709 if(!ds){ |
661 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedSteramMissing); | 710 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedSteramMissing); |
662 exit(1); | 711 exit_player(MSGTR_Exit_error); |
663 } | 712 } |
664 // disable other streams: | 713 // disable other streams: |
665 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; } | 714 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; } |
666 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; } | 715 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; } |
667 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; } | 716 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; } |
668 // let's dump it! | 717 // let's dump it! |
669 f=fopen(stream_dump_name?stream_dump_name:"stream.dump","wb"); | 718 f=fopen(stream_dump_name?stream_dump_name:"stream.dump","wb"); |
670 if(!f){ mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);exit(1); } | 719 if(!f){ |
720 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile); | |
721 exit_player(MSGTR_Exit_error); | |
722 } | |
671 while(!ds->eof){ | 723 while(!ds->eof){ |
672 unsigned char* start; | 724 unsigned char* start; |
673 int in_size=ds_get_packet(ds,&start); | 725 int in_size=ds_get_packet(ds,&start); |
674 if( (file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_ASF) | 726 if( (file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_ASF) |
675 && stream_dump_type==2) fwrite(&in_size,1,4,f); | 727 && stream_dump_type==2) fwrite(&in_size,1,4,f); |
676 if(in_size>0) fwrite(start,in_size,1,f); | 728 if(in_size>0) fwrite(start,in_size,1,f); |
677 } | 729 } |
678 fclose(f); | 730 fclose(f); |
679 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped); | 731 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped); |
680 exit(1); | 732 exit_player(MSGTR_Exit_eof); |
681 } | 733 } |
682 | 734 |
683 sh_audio=d_audio->sh; | 735 sh_audio=d_audio->sh; |
684 sh_video=d_video->sh; | 736 sh_video=d_video->sh; |
685 | 737 |
738 current_module="video_read_properties"; | |
739 | |
686 if(sh_video){ | 740 if(sh_video){ |
687 | 741 |
688 if(!video_read_properties(sh_video)) exit(1); // couldn't read header? | 742 if(!video_read_properties(sh_video)) exit_player(MSGTR_Exit_error); // couldn't read header? |
689 | 743 |
690 mp_msg(MSGT_CPLAYER,MSGL_INFO,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", | 744 mp_msg(MSGT_CPLAYER,MSGL_INFO,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
691 file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h, | 745 file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h, |
692 sh_video->fps,sh_video->frametime | 746 sh_video->fps,sh_video->frametime |
693 ); | 747 ); |
694 | 748 |
695 if(!sh_video->fps && !force_fps){ | 749 if(!sh_video->fps && !force_fps){ |
696 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_FPSnotspecified); | 750 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_FPSnotspecified); |
697 exit(1); | 751 exit_player(MSGTR_Exit_error); |
698 } | 752 } |
699 | 753 |
700 } | 754 } |
701 | 755 |
702 fflush(stdout); | 756 fflush(stdout); |
703 | 757 |
704 if(!sh_video){ | 758 if(!sh_video){ |
705 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NoVideoStream); | 759 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NoVideoStream); |
706 exit(1); | 760 exit_player(MSGTR_Exit_error); |
707 } | 761 } |
708 | 762 |
709 //================== Init AUDIO (codec) ========================== | 763 //================== Init AUDIO (codec) ========================== |
764 | |
765 current_module="init_audio_codec"; | |
766 | |
710 if(sh_audio){ | 767 if(sh_audio){ |
711 // Go through the codec.conf and find the best codec... | 768 // Go through the codec.conf and find the best codec... |
712 sh_audio->codec=NULL; | 769 sh_audio->codec=NULL; |
713 if(audio_family!=-1) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_TryForceAudioFmt,audio_family); | 770 if(audio_family!=-1) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_TryForceAudioFmt,audio_family); |
714 while(1){ | 771 while(1){ |
743 } | 800 } |
744 } | 801 } |
745 | 802 |
746 //================== Init VIDEO (codec & libvo) ========================== | 803 //================== Init VIDEO (codec & libvo) ========================== |
747 | 804 |
805 current_module="init_video_codec"; | |
806 | |
748 // Go through the codec.conf and find the best codec... | 807 // Go through the codec.conf and find the best codec... |
749 sh_video->codec=NULL; | 808 sh_video->codec=NULL; |
750 if(video_family!=-1) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_TryForceVideoFmt,video_family); | 809 if(video_family!=-1) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_TryForceVideoFmt,video_family); |
751 while(1){ | 810 while(1){ |
752 sh_video->codec=find_codec(sh_video->format, | 811 sh_video->codec=find_codec(sh_video->format, |
758 video_family=-1; | 817 video_family=-1; |
759 continue; | 818 continue; |
760 } | 819 } |
761 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); | 820 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); |
762 mp_msg(MSGT_CPLAYER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | 821 mp_msg(MSGT_CPLAYER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); |
763 exit(1); | 822 exit_player(MSGTR_Exit_error); |
764 } | 823 } |
765 // is next line needed anymore? - atmos :: | 824 // is next line needed anymore? - atmos :: |
766 if(!allow_dshow && sh_video->codec->driver==VFM_DSHOW) continue; // skip DShow | 825 if(!allow_dshow && sh_video->codec->driver==VFM_DSHOW) continue; // skip DShow |
767 else if(video_codec && strcmp(sh_video->codec->name,video_codec)) continue; | 826 else if(video_codec && strcmp(sh_video->codec->name,video_codec)) continue; |
768 else if(video_family!=-1 && sh_video->codec->driver!=video_family) continue; | 827 else if(video_family!=-1 && sh_video->codec->driver!=video_family) continue; |
783 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X\n",vo_format_name(out_fmt),ret); | 842 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X\n",vo_format_name(out_fmt),ret); |
784 if(ret) break; | 843 if(ret) break; |
785 } | 844 } |
786 if(i>=CODECS_MAX_OUTFMT){ | 845 if(i>=CODECS_MAX_OUTFMT){ |
787 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_VOincompCodec); | 846 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_VOincompCodec); |
788 exit(1); | 847 exit_player(MSGTR_Exit_error); |
789 } | 848 } |
790 sh_video->outfmtidx=i; | 849 sh_video->outfmtidx=i; |
791 | 850 |
792 if(flip==-1){ | 851 if(flip==-1){ |
793 // autodetect flipping | 852 // autodetect flipping |
799 | 858 |
800 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug1: out_fmt=%s\n",vo_format_name(out_fmt)); | 859 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug1: out_fmt=%s\n",vo_format_name(out_fmt)); |
801 | 860 |
802 if(!init_video(sh_video)){ | 861 if(!init_video(sh_video)){ |
803 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CouldntInitVideoCodec); | 862 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CouldntInitVideoCodec); |
804 exit(1); | 863 exit_player(MSGTR_Exit_error); |
805 } | 864 } |
806 | 865 |
807 if(auto_quality>0){ | 866 if(auto_quality>0){ |
808 // Auto quality option enabled | 867 // Auto quality option enabled |
809 output_quality=get_video_quality_max(sh_video); | 868 output_quality=get_video_quality_max(sh_video); |
818 // encode file!!! | 877 // encode file!!! |
819 FILE *encode_file=fopen(encode_name,"rb"); | 878 FILE *encode_file=fopen(encode_name,"rb"); |
820 if(encode_file){ | 879 if(encode_file){ |
821 fclose(encode_file); | 880 fclose(encode_file); |
822 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_EncodeFileExists,encode_name); | 881 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_EncodeFileExists,encode_name); |
823 return 0; | 882 exit_player(MSGTR_Exit_error); |
824 } | 883 } |
825 encode_file=fopen(encode_name,"wb"); | 884 encode_file=fopen(encode_name,"wb"); |
826 if(!encode_file){ | 885 if(!encode_file){ |
827 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantCreateEncodeFile); | 886 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantCreateEncodeFile); |
828 return 0; | 887 exit_player(MSGTR_Exit_error); |
829 } | 888 } |
830 write_avi_header_1(encode_file,mmioFOURCC('d', 'i', 'v', 'x'),sh_video->fps,sh_video->disp_w,sh_video->disp_h); | 889 write_avi_header_1(encode_file,mmioFOURCC('d', 'i', 'v', 'x'),sh_video->fps,sh_video->disp_w,sh_video->disp_h); |
831 fclose(encode_file); | 890 fclose(encode_file); |
832 encode_index_name=malloc(strlen(encode_name)+8); | 891 encode_index_name=malloc(strlen(encode_name)+8); |
833 strcpy(encode_index_name,encode_name); | 892 strcpy(encode_index_name,encode_name); |
841 // ========== Init keyboard FIFO (connection to libvo) ============ | 900 // ========== Init keyboard FIFO (connection to libvo) ============ |
842 | 901 |
843 make_pipe(&keyb_fifo_get,&keyb_fifo_put); | 902 make_pipe(&keyb_fifo_get,&keyb_fifo_put); |
844 | 903 |
845 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============ | 904 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============ |
905 | |
906 current_module="init_libvo"; | |
846 | 907 |
847 #ifdef X11_FULLSCREEN | 908 #ifdef X11_FULLSCREEN |
848 if(fullscreen){ | 909 if(fullscreen){ |
849 if(vo_init()){ | 910 if(vo_init()){ |
850 //if(verbose) printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen); | 911 //if(verbose) printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen); |
905 #ifdef USE_LIBVO2 | 966 #ifdef USE_LIBVO2 |
906 if(!vo2_start(video_out, | 967 if(!vo2_start(video_out, |
907 sh_video->disp_w,sh_video->disp_h,out_fmt,0, | 968 sh_video->disp_w,sh_video->disp_h,out_fmt,0, |
908 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3) )){ | 969 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3) )){ |
909 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO ); | 970 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO ); |
910 exit(1); | 971 exit_player(MSGTR_Exit_error); |
911 } | 972 } |
912 #else | 973 #else |
913 if(video_out->init(sh_video->disp_w,sh_video->disp_h, | 974 if(video_out->init(sh_video->disp_w,sh_video->disp_h, |
914 screen_size_x,screen_size_y, | 975 screen_size_x,screen_size_y, |
915 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), | 976 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), |
916 title,out_fmt)){ | 977 title,out_fmt)){ |
917 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO); | 978 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO); |
918 exit(1); | 979 exit_player(MSGTR_Exit_error); |
919 } | 980 } |
920 #endif | 981 #endif |
921 mp_msg(MSGT_CPLAYER,MSGL_V,"INFO: Video OUT driver init OK!\n"); | 982 mp_msg(MSGT_CPLAYER,MSGL_V,"INFO: Video OUT driver init OK!\n"); |
922 | 983 |
923 fflush(stdout); | 984 fflush(stdout); |
939 float AV_delay=0; // average of A-V timestamp differences | 1000 float AV_delay=0; // average of A-V timestamp differences |
940 double cvideo_base_vtime; | 1001 double cvideo_base_vtime; |
941 double cvideo_base_vframe; | 1002 double cvideo_base_vframe; |
942 double vdecode_time; | 1003 double vdecode_time; |
943 | 1004 |
944 #ifdef HAVE_LIRC | |
945 #ifdef HAVE_GUI | |
946 if ( nogui ) | |
947 #endif | |
948 lirc_mp_setup(); | |
949 #endif | |
950 | |
951 #ifdef HAVE_GUI | |
952 if ( nogui ) | |
953 { | |
954 #endif | |
955 #ifdef USE_TERMCAP | |
956 load_termcap(NULL); // load key-codes | |
957 #endif | |
958 if(!use_stdin) getch2_enable(); | |
959 #ifdef HAVE_GUI | |
960 } | |
961 #endif | |
962 | |
963 //========= Catch terminate signals: ================ | |
964 // terminate requests: | |
965 signal(SIGTERM,exit_sighandler); // kill | |
966 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed | |
967 | |
968 #ifdef HAVE_GUI | |
969 if ( nogui ) | |
970 #endif | |
971 signal(SIGINT,exit_sighandler); // Interrupt from keyboard | |
972 | |
973 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
974 // fatal errors: | |
975 signal(SIGBUS,exit_sighandler); // bus error | |
976 signal(SIGSEGV,exit_sighandler); // segfault | |
977 signal(SIGILL,exit_sighandler); // illegal instruction | |
978 signal(SIGFPE,exit_sighandler); // floating point exc. | |
979 signal(SIGABRT,exit_sighandler); // abort() | |
980 | 1005 |
981 //================ SETUP AUDIO ========================== | 1006 //================ SETUP AUDIO ========================== |
982 current_module="setup_audio"; | 1007 current_module="setup_audio"; |
983 | 1008 |
984 if(sh_audio){ | 1009 if(sh_audio){ |
1025 if(audio_out){ audio_out->uninit(); audio_out=NULL;} // close device | 1050 if(audio_out){ audio_out->uninit(); audio_out=NULL;} // close device |
1026 } | 1051 } |
1027 | 1052 |
1028 current_module=NULL; | 1053 current_module=NULL; |
1029 | 1054 |
1030 //==================== START PLAYING ======================= | 1055 if(file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! |
1031 | |
1032 if(file_format==DEMUXER_TYPE_AVI && sh_audio){ | |
1033 #if 0 | |
1034 //a_pts=d_audio->pts; | |
1035 if(verbose) printf("Initial frame delay A: %d V: %d\n",(int)sh_audio->audio.dwInitialFrames,(int)sh_video->video.dwInitialFrames); | |
1036 if(!pts_from_bps){ | |
1037 float x=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime; | |
1038 // audio_delay-=x; | |
1039 if(verbose) printf("AVI Initial frame delay: %5.3f\n",x); | |
1040 delay_corrected=0; // has to correct PTS diffs | |
1041 } | |
1042 if(verbose){ | |
1043 // printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f sh_audio->timer=%5.3f\n", | |
1044 // audio_delay,audio_buffer_delay,a_pts,sh_audio->timer); | |
1045 printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts); | |
1046 } | |
1047 d_video->pts=0;d_audio->pts=0; // PTS is outdated now! | |
1048 #endif | |
1049 } else { | |
1050 pts_from_bps=0; // it must be 0 for mpeg/asf ! | |
1051 } | |
1052 if(force_fps){ | 1056 if(force_fps){ |
1053 sh_video->fps=force_fps; | 1057 sh_video->fps=force_fps; |
1054 sh_video->frametime=1.0f/sh_video->fps; | 1058 sh_video->frametime=1.0f/sh_video->fps; |
1055 mp_msg(MSGT_CPLAYER,MSGL_INFO,"FPS forced to be %5.3f (ftime: %5.3f)\n",sh_video->fps,sh_video->frametime); | 1059 mp_msg(MSGT_CPLAYER,MSGL_INFO,"FPS forced to be %5.3f (ftime: %5.3f)\n",sh_video->fps,sh_video->frametime); |
1056 } | 1060 } |
1057 | 1061 |
1062 //==================== START PLAYING ======================= | |
1063 | |
1058 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout); | 1064 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout); |
1065 | |
1066 if(!use_stdin) getch2_enable(); // prepare stdin for hotkeys... | |
1059 | 1067 |
1060 InitTimer(); | 1068 InitTimer(); |
1061 | 1069 |
1062 total_time_usage_start=GetTimer(); | 1070 total_time_usage_start=GetTimer(); |
1063 | 1071 |
1079 | 1087 |
1080 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it! | 1088 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it! |
1081 //if(playsize>outburst) playsize=outburst; | 1089 //if(playsize>outburst) playsize=outburst; |
1082 | 1090 |
1083 // Update buffer if needed | 1091 // Update buffer if needed |
1092 current_module="decode_audio"; // Enter AUDIO decoder module | |
1084 t=GetTimer(); | 1093 t=GetTimer(); |
1085 current_module="decode_audio"; // Enter AUDIO decoder module | |
1086 while(sh_audio->a_buffer_len<playsize && !d_audio->eof){ | 1094 while(sh_audio->a_buffer_len<playsize && !d_audio->eof){ |
1087 int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len], | 1095 int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len], |
1088 playsize-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len); | 1096 playsize-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len); |
1089 if(ret>0) sh_audio->a_buffer_len+=ret; else break; | 1097 if(ret>0) sh_audio->a_buffer_len+=ret; else break; |
1090 } | 1098 } |
1515 audio_delay-=0.1; // decrease audio buffer delay | 1523 audio_delay-=0.1; // decrease audio buffer delay |
1516 if(sh_audio) sh_audio->timer+=0.1; | 1524 if(sh_audio) sh_audio->timer+=0.1; |
1517 break; | 1525 break; |
1518 // quit | 1526 // quit |
1519 case KEY_ESC: // ESC | 1527 case KEY_ESC: // ESC |
1528 case 'q': exit_player(MSGTR_Exit_quit); | |
1520 case KEY_ENTER: // ESC | 1529 case KEY_ENTER: // ESC |
1521 case 'q': exit_player(MSGTR_Exit_quit); | 1530 eof=1; // jump to next file |
1531 break; | |
1522 case 'g': grab_frames=2;break; | 1532 case 'g': grab_frames=2;break; |
1523 // pause | 1533 // pause |
1524 case 'p': | 1534 case 'p': |
1525 case ' ': | 1535 case ' ': |
1526 osd_function=OSD_PAUSE; | 1536 osd_function=OSD_PAUSE; |
1763 | 1773 |
1764 } // while(!eof) | 1774 } // while(!eof) |
1765 | 1775 |
1766 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof); | 1776 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof); |
1767 | 1777 |
1778 } | |
1779 | |
1780 ++curr_filename; | |
1781 if(curr_filename<num_filenames){ | |
1782 // partial uninit: | |
1783 | |
1784 // restore terminal: | |
1785 #ifdef HAVE_GUI | |
1786 if ( nogui ) | |
1787 #endif | |
1788 getch2_disable(); | |
1789 | |
1790 #ifdef USE_LIBVO2 | |
1791 if(video_out) vo2_close(video_out); | |
1792 #else | |
1793 if(video_out) video_out->uninit(); | |
1794 #endif | |
1795 video_out=NULL; | |
1796 if(audio_out) audio_out->uninit(); | |
1797 audio_out=NULL; | |
1798 // if(encode_name) avi_fixate(); | |
1799 | |
1800 goto play_next_file; | |
1801 } | |
1802 | |
1768 exit_player(MSGTR_Exit_eof); | 1803 exit_player(MSGTR_Exit_eof); |
1769 } | 1804 |
1770 return 1; | 1805 return 1; |
1771 } | 1806 } |