Mercurial > pt1.oyama
changeset 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 |
files | recpt1/Makefile recpt1/recpt1.c recpt1/recpt1.h |
diffstat | 2 files changed, 51 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/recpt1/recpt1.c Tue Mar 03 05:30:25 2009 +0900 +++ b/recpt1/recpt1.c Tue Mar 03 17:59:17 2009 +0900 @@ -550,6 +550,8 @@ int port_to = 1234; sock_data *sockdata = NULL; char *device = NULL; + char **tuner; + int num_devs; while((result = getopt_long(argc, argv, "br:smua:p:d:h", long_options, &option_index)) != -1) { @@ -614,56 +616,65 @@ /* get channel */ ptr = searchrecoff(argv[optind]); if(ptr == NULL) { - fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]); + fprintf(stderr, "Invalid Channel: %s\n", argv[optind]); return 1; } freq.frequencyno = ptr->set_freq; freq.slot = ptr->add_freq; - if(ptr->type == CHTYPE_SATELLITE) { - if(device) { - tfd = open(device, O_RDONLY); - if(tfd < 0) { - fprintf(stderr, "Cannot open tuner\n"); - return 1; - } - } - else { - for(lp = 0; lp < NUM_BSDEV; lp++) { - tfd = open(bsdev[lp], O_RDONLY); - if(tfd >= 0) { - break; - } - } - if(tfd < 0) { - fprintf(stderr, "Cannot open tuner\n"); - return 1; - } + /* open tuner */ + /* 1. specified tuner device */ + if(device) { + tfd = open(device, O_RDONLY); + if(tfd < 0) { + fprintf(stderr, "Cannot open tuner device: %s\n", device); + return 1; } } + + /* 2. loop around available devices */ + if(ptr->type == CHTYPE_SATELLITE) { + tuner = bsdev; + num_devs = NUM_BSDEV; + } else { - if(device) { - tfd = open(device, O_RDONLY); - if(tfd < 0) { - fprintf(stderr, "Cannot open tuner\n"); - return 1; - } - } - else { - for(lp = 0; lp < NUM_ISDB_T_DEV; lp++) { - tfd = open(isdb_t_dev[lp], O_RDONLY); - if(tfd >= 0) { - break; + tuner = isdb_t_dev; + num_devs = NUM_ISDB_T_DEV; + } + + for(lp = 0; lp < num_devs; lp++) { + tfd = open(tuner[lp], O_RDONLY); + if(tfd >= 0) { + /* power on LNB */ + if(ptr->type == CHTYPE_SATELLITE) { + if(ioctl(tfd, LNB_ENABLE, 0) < 0) { + close(tfd); + continue; } } - if(tfd < 0) { - fprintf(stderr, "Cannot open tuner\n"); - return 1; + + /* tune to specified channel */ + if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { + close(tfd); + continue; } + + break; /* found suitable tuner */ } + close(tfd); + tfd = -1; } + /* all tuners cannot be used */ + if(tfd < 0) { + fprintf(stderr, "Could not tune to the specified channel\n"); + return 1; + } + + /* show signal strength */ + calc_cn(tfd, ptr->type); + /* get recsec */ char *recsecstr = argv[optind + 1]; if(!strcmp("-", recsecstr)) { @@ -684,7 +695,8 @@ if(!fileless) { wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); if(wfd < 0) { - fprintf(stderr, "Could not open output file(%s)\n", argv[optind + 2]); + fprintf(stderr, "Could not open output file: %s\n", + argv[optind + 2]); return 1; } } @@ -729,26 +741,12 @@ } } - /* setup tuner */ - if(ptr->type == CHTYPE_SATELLITE) { - if(ioctl(tfd, LNB_ENABLE, 0) < 0) { - return 0 ; - } - } - - if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { - fprintf(stderr, "Could not tune to the specified channel\n"); - calc_cn(tfd, ptr->type); - return 1; - } - calc_cn(tfd, ptr->type); - - /* init signal handler thread */ + /* spawn signal handler thread */ sdata.queue = p_queue; sdata.tfd = tfd; init_signal_handlers(&signal_thread, &sdata); - /* make reader thread */ + /* spawn reader thread */ tdata.queue = p_queue; tdata.decoder = dec; tdata.wfd = wfd;