comparison recpt1/recpt1.c @ 34:3f2487de156e

should not loop if tuner device is specified.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 05 Mar 2009 01:05:32 +0900
parents f25820d90249
children b17f95181af4
comparison
equal deleted inserted replaced
33:f25820d90249 34:3f2487de156e
622 622
623 freq.frequencyno = ptr->set_freq; 623 freq.frequencyno = ptr->set_freq;
624 freq.slot = ptr->add_freq; 624 freq.slot = ptr->add_freq;
625 625
626 /* open tuner */ 626 /* open tuner */
627 /* 1. specified tuner device */ 627 /* case 1: specified tuner device */
628 if(device) { 628 if(device) {
629 tfd = open(device, O_RDONLY); 629 tfd = open(device, O_RDONLY);
630 if(tfd < 0) { 630 if(tfd < 0) {
631 fprintf(stderr, "Cannot open tuner device: %s\n", device); 631 fprintf(stderr, "Cannot open tuner device: %s\n", device);
632 return 1; 632 return 1;
633 } 633 }
634 } 634
635 635 /* power on LNB */
636 /* 2. loop around available devices */ 636 if(ptr->type == CHTYPE_SATELLITE) {
637 if(ptr->type == CHTYPE_SATELLITE) { 637 if(ioctl(tfd, LNB_ENABLE, 0) < 0) {
638 tuner = bsdev; 638 close(tfd);
639 num_devs = NUM_BSDEV; 639 fprintf(stderr, "Power on LNB failed: %s\n", device);
640 return 1;
641 }
642 }
643
644 /* tune to specified channel */
645 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
646 close(tfd);
647 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device);
648 return 1;
649 }
640 } 650 }
641 else { 651 else {
642 tuner = isdb_t_dev; 652 /* case 2: loop around available devices */
643 num_devs = NUM_ISDB_T_DEV; 653 if(ptr->type == CHTYPE_SATELLITE) {
644 } 654 tuner = bsdev;
645 655 num_devs = NUM_BSDEV;
646 for(lp = 0; lp < num_devs; lp++) { 656 }
647 tfd = open(tuner[lp], O_RDONLY); 657 else {
648 if(tfd >= 0) { 658 tuner = isdb_t_dev;
649 /* power on LNB */ 659 num_devs = NUM_ISDB_T_DEV;
650 if(ptr->type == CHTYPE_SATELLITE) { 660 }
651 if(ioctl(tfd, LNB_ENABLE, 0) < 0) { 661
662 for(lp = 0; lp < num_devs; lp++) {
663 tfd = open(tuner[lp], O_RDONLY);
664 if(tfd >= 0) {
665 /* power on LNB */
666 if(ptr->type == CHTYPE_SATELLITE) {
667 if(ioctl(tfd, LNB_ENABLE, 0) < 0) {
668 close(tfd);
669 tfd = -1;
670 continue;
671 }
672 }
673
674 /* tune to specified channel */
675 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
652 close(tfd); 676 close(tfd);
677 tfd = -1;
653 continue; 678 continue;
654 } 679 }
655 } 680
656 681 break; /* found suitable tuner */
657 /* tune to specified channel */ 682 }
658 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { 683 }
659 close(tfd); 684
660 continue; 685 /* all tuners cannot be used */
661 } 686 if(tfd < 0) {
662 687 fprintf(stderr, "Cannot tune to the specified channel\n");
663 break; /* found suitable tuner */ 688 return 1;
664 } 689 }
665 close(tfd);
666 tfd = -1;
667 }
668
669 /* all tuners cannot be used */
670 if(tfd < 0) {
671 fprintf(stderr, "Could not tune to the specified channel\n");
672 return 1;
673 } 690 }
674 691
675 /* show signal strength */ 692 /* show signal strength */
676 calc_cn(tfd, ptr->type); 693 calc_cn(tfd, ptr->type);
677 694
693 } 710 }
694 else { 711 else {
695 if(!fileless) { 712 if(!fileless) {
696 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); 713 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
697 if(wfd < 0) { 714 if(wfd < 0) {
698 fprintf(stderr, "Could not open output file: %s\n", 715 fprintf(stderr, "Cannot open output file: %s\n",
699 argv[optind + 2]); 716 argv[optind + 2]);
700 return 1; 717 return 1;
701 } 718 }
702 } 719 }
703 } 720 }
704 721
705 /* initialize decoder */ 722 /* initialize decoder */
706 if(use_b25) { 723 if(use_b25) {
707 dec = b25_startup(&dopt); 724 dec = b25_startup(&dopt);
708 if(!dec) { 725 if(!dec) {
709 fprintf(stderr, "Could not start b25 decoder\n"); 726 fprintf(stderr, "Cannot start b25 decoder\n");
710 fprintf(stderr, "Fall back to encrypted recording\n"); 727 fprintf(stderr, "Fall back to encrypted recording\n");
711 use_b25 = 0; 728 use_b25 = 0;
712 } 729 }
713 } 730 }
714 731
754 tdata.signal_thread = signal_thread; 771 tdata.signal_thread = signal_thread;
755 pthread_create(&reader_thread, NULL, reader_func, &tdata); 772 pthread_create(&reader_thread, NULL, reader_func, &tdata);
756 773
757 /* start recording */ 774 /* start recording */
758 if(ioctl(tfd, START_REC, 0) < 0) { 775 if(ioctl(tfd, START_REC, 0) < 0) {
759 fprintf(stderr, "Tuner could not start recording\n"); 776 fprintf(stderr, "Tuner cannot start recording\n");
760 return 1; 777 return 1;
761 } 778 }
762 779
763 fprintf(stderr, "Recording...\n"); 780 fprintf(stderr, "Recording...\n");
764 781