comparison recpt1/recpt1.c @ 33:f25820d90249

make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 03 Mar 2009 17:59:17 +0900
parents 6004fe4f37f9
children 3f2487de156e
comparison
equal deleted inserted replaced
32:6004fe4f37f9 33:f25820d90249
548 int use_stdout = FALSE; 548 int use_stdout = FALSE;
549 char *host_to = NULL; 549 char *host_to = NULL;
550 int port_to = 1234; 550 int port_to = 1234;
551 sock_data *sockdata = NULL; 551 sock_data *sockdata = NULL;
552 char *device = NULL; 552 char *device = NULL;
553 char **tuner;
554 int num_devs;
553 555
554 while((result = getopt_long(argc, argv, "br:smua:p:d:h", 556 while((result = getopt_long(argc, argv, "br:smua:p:d:h",
555 long_options, &option_index)) != -1) { 557 long_options, &option_index)) != -1) {
556 switch(result) { 558 switch(result) {
557 case 'b': 559 case 'b':
612 } 614 }
613 615
614 /* get channel */ 616 /* get channel */
615 ptr = searchrecoff(argv[optind]); 617 ptr = searchrecoff(argv[optind]);
616 if(ptr == NULL) { 618 if(ptr == NULL) {
617 fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]); 619 fprintf(stderr, "Invalid Channel: %s\n", argv[optind]);
618 return 1; 620 return 1;
619 } 621 }
620 622
621 freq.frequencyno = ptr->set_freq; 623 freq.frequencyno = ptr->set_freq;
622 freq.slot = ptr->add_freq; 624 freq.slot = ptr->add_freq;
623 625
626 /* open tuner */
627 /* 1. specified tuner device */
628 if(device) {
629 tfd = open(device, O_RDONLY);
630 if(tfd < 0) {
631 fprintf(stderr, "Cannot open tuner device: %s\n", device);
632 return 1;
633 }
634 }
635
636 /* 2. loop around available devices */
624 if(ptr->type == CHTYPE_SATELLITE) { 637 if(ptr->type == CHTYPE_SATELLITE) {
625 if(device) { 638 tuner = bsdev;
626 tfd = open(device, O_RDONLY); 639 num_devs = NUM_BSDEV;
627 if(tfd < 0) { 640 }
628 fprintf(stderr, "Cannot open tuner\n"); 641 else {
629 return 1; 642 tuner = isdb_t_dev;
630 } 643 num_devs = NUM_ISDB_T_DEV;
631 } 644 }
632 else { 645
633 for(lp = 0; lp < NUM_BSDEV; lp++) { 646 for(lp = 0; lp < num_devs; lp++) {
634 tfd = open(bsdev[lp], O_RDONLY); 647 tfd = open(tuner[lp], O_RDONLY);
635 if(tfd >= 0) { 648 if(tfd >= 0) {
636 break; 649 /* power on LNB */
650 if(ptr->type == CHTYPE_SATELLITE) {
651 if(ioctl(tfd, LNB_ENABLE, 0) < 0) {
652 close(tfd);
653 continue;
637 } 654 }
638 } 655 }
639 if(tfd < 0) { 656
640 fprintf(stderr, "Cannot open tuner\n"); 657 /* tune to specified channel */
641 return 1; 658 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
642 } 659 close(tfd);
643 } 660 continue;
644 } 661 }
645 else { 662
646 if(device) { 663 break; /* found suitable tuner */
647 tfd = open(device, O_RDONLY); 664 }
648 if(tfd < 0) { 665 close(tfd);
649 fprintf(stderr, "Cannot open tuner\n"); 666 tfd = -1;
650 return 1; 667 }
651 } 668
652 } 669 /* all tuners cannot be used */
653 else { 670 if(tfd < 0) {
654 for(lp = 0; lp < NUM_ISDB_T_DEV; lp++) { 671 fprintf(stderr, "Could not tune to the specified channel\n");
655 tfd = open(isdb_t_dev[lp], O_RDONLY); 672 return 1;
656 if(tfd >= 0) { 673 }
657 break; 674
658 } 675 /* show signal strength */
659 } 676 calc_cn(tfd, ptr->type);
660 if(tfd < 0) {
661 fprintf(stderr, "Cannot open tuner\n");
662 return 1;
663 }
664 }
665 }
666 677
667 /* get recsec */ 678 /* get recsec */
668 char *recsecstr = argv[optind + 1]; 679 char *recsecstr = argv[optind + 1];
669 if(!strcmp("-", recsecstr)) { 680 if(!strcmp("-", recsecstr)) {
670 indefinite = TRUE; 681 indefinite = TRUE;
682 } 693 }
683 else { 694 else {
684 if(!fileless) { 695 if(!fileless) {
685 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); 696 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
686 if(wfd < 0) { 697 if(wfd < 0) {
687 fprintf(stderr, "Could not open output file(%s)\n", argv[optind + 2]); 698 fprintf(stderr, "Could not open output file: %s\n",
699 argv[optind + 2]);
688 return 1; 700 return 1;
689 } 701 }
690 } 702 }
691 } 703 }
692 704
727 perror("connect"); 739 perror("connect");
728 return 1; 740 return 1;
729 } 741 }
730 } 742 }
731 743
732 /* setup tuner */ 744 /* spawn signal handler thread */
733 if(ptr->type == CHTYPE_SATELLITE) {
734 if(ioctl(tfd, LNB_ENABLE, 0) < 0) {
735 return 0 ;
736 }
737 }
738
739 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
740 fprintf(stderr, "Could not tune to the specified channel\n");
741 calc_cn(tfd, ptr->type);
742 return 1;
743 }
744 calc_cn(tfd, ptr->type);
745
746 /* init signal handler thread */
747 sdata.queue = p_queue; 745 sdata.queue = p_queue;
748 sdata.tfd = tfd; 746 sdata.tfd = tfd;
749 init_signal_handlers(&signal_thread, &sdata); 747 init_signal_handlers(&signal_thread, &sdata);
750 748
751 /* make reader thread */ 749 /* spawn reader thread */
752 tdata.queue = p_queue; 750 tdata.queue = p_queue;
753 tdata.decoder = dec; 751 tdata.decoder = dec;
754 tdata.wfd = wfd; 752 tdata.wfd = wfd;
755 tdata.sock_data = sockdata; 753 tdata.sock_data = sockdata;
756 tdata.signal_thread = signal_thread; 754 tdata.signal_thread = signal_thread;