Mercurial > pt1
annotate recpt1/recpt1.c @ 75:1d1d616cde98
build fix
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 28 Nov 2009 02:06:16 +0900 |
parents | b6607f6e2851 |
children | 5a0126d8af17 |
rev | line source |
---|---|
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1 #include <stdio.h> |
3 | 2 #include <fcntl.h> |
3 #include <sys/types.h> | |
4 #include <sys/stat.h> | |
5 #include <time.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <pthread.h> | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
9 #include <math.h> |
3 | 10 #include <unistd.h> |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
11 #include <getopt.h> |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
12 #include <signal.h> |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
13 #include <errno.h> |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
14 #include <sys/time.h> |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
15 #include <ctype.h> |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
16 #include <libgen.h> |
0 | 17 |
8 | 18 #include <netdb.h> |
19 #include <arpa/inet.h> | |
20 #include <netinet/in.h> | |
21 | |
3 | 22 #include <sys/ioctl.h> |
23 #include "pt1_ioctl.h" | |
0 | 24 |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
25 #include "config.h" |
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
26 #include "decoder.h" |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
27 #include "recpt1.h" |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
28 #include "version.h" |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
29 #include "mkpath.h" |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
30 |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
31 /* maximum write length at once */ |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
32 #define SIZE_CHANK 1316 |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
33 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
34 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
35 int f_exit = FALSE; |
0 | 36 |
21
b63f5c100e5a
made recpt1 link against b25 shared object.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
37 /* type definitions */ |
8 | 38 typedef struct sock_data { |
39 int sfd; /* socket fd */ | |
40 struct sockaddr_in addr; | |
41 } sock_data; | |
42 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
43 typedef struct reader_thread_data { |
4 | 44 QUEUE_T *queue; |
45 decoder *decoder; | |
8 | 46 int wfd; /* output file fd */ |
47 sock_data *sock_data; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
48 pthread_t signal_thread; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
49 } reader_thread_data; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
50 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
51 typedef struct signal_thread_data { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
52 QUEUE_T *queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
53 int tfd; /* tuner fd */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
54 } signal_thread_data; |
0 | 55 |
6 | 56 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
57 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
58 searchrecoff(char *channel) |
0 | 59 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
60 int lp; |
0 | 61 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
62 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) { |
6 | 63 /* return entry number in the table when strings match and |
64 * lengths are same. */ | |
4 | 65 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
66 strlen(channel)) == 0) && | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
67 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
68 return &isdb_t_conv_table[lp]; |
4 | 69 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
70 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
71 return NULL; |
0 | 72 } |
73 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
74 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
75 create_queue(size_t size) |
0 | 76 { |
4 | 77 QUEUE_T *p_queue; |
8 | 78 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 79 |
4 | 80 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 81 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
82 if(p_queue != NULL) { |
4 | 83 p_queue->size = size; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
84 p_queue->num_avail = size; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
85 p_queue->num_used = 0; |
4 | 86 pthread_mutex_init(&p_queue->mutex, NULL); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
87 pthread_cond_init(&p_queue->cond_avail, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
88 pthread_cond_init(&p_queue->cond_used, NULL); |
4 | 89 } |
0 | 90 |
4 | 91 return p_queue; |
0 | 92 } |
93 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
94 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
95 destroy_queue(QUEUE_T *p_queue) |
0 | 96 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
97 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
98 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
99 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
100 pthread_mutex_destroy(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
101 pthread_cond_destroy(&p_queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
102 pthread_cond_destroy(&p_queue->cond_used); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
103 free(p_queue); |
0 | 104 } |
105 | |
3 | 106 /* enqueue data. this function will block if queue is full. */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
107 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
108 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 109 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
110 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
111 struct timespec spec; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
112 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
113 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
114 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
115 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
116 |
4 | 117 pthread_mutex_lock(&p_queue->mutex); |
118 /* entered critical section */ | |
0 | 119 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
120 /* wait while queue is full */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
121 while(p_queue->num_avail == 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
122 pthread_cond_timedwait(&p_queue->cond_avail, |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
123 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
124 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
125 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
126 return; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
127 } |
4 | 128 } |
0 | 129 |
4 | 130 p_queue->buffer[p_queue->in] = data; |
0 | 131 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
132 /* move position marker for input to next position */ |
4 | 133 p_queue->in++; |
134 p_queue->in %= p_queue->size; | |
0 | 135 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
136 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
137 p_queue->num_avail--; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
138 p_queue->num_used++; |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
139 |
4 | 140 /* leaving critical section */ |
141 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
142 pthread_cond_signal(&p_queue->cond_used); |
0 | 143 } |
144 | |
3 | 145 /* dequeue data. this function will block if queue is empty. */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
146 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
147 dequeue(QUEUE_T *p_queue) |
0 | 148 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
149 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
150 struct timespec spec; |
8 | 151 BUFSZ *buffer; |
0 | 152 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
153 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
154 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
155 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
156 |
4 | 157 pthread_mutex_lock(&p_queue->mutex); |
158 /* entered the critical section*/ | |
0 | 159 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
160 /* wait while queue is empty */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
161 while(p_queue->num_used == 0) { |
27
763cf84d2dc7
fixed a bug that waited for wrong cond variable
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
26
diff
changeset
|
162 pthread_cond_timedwait(&p_queue->cond_used, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
163 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
164 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
165 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
166 return NULL; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
167 } |
4 | 168 } |
0 | 169 |
4 | 170 /* take buffer address */ |
171 buffer = p_queue->buffer[p_queue->out]; | |
0 | 172 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
173 /* move position marker for output to next position */ |
4 | 174 p_queue->out++; |
175 p_queue->out %= p_queue->size; | |
0 | 176 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
177 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
178 p_queue->num_avail++; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
179 p_queue->num_used--; |
0 | 180 |
4 | 181 /* leaving the critical section */ |
182 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
183 pthread_cond_signal(&p_queue->cond_avail); |
0 | 184 |
4 | 185 return buffer; |
0 | 186 } |
187 | |
6 | 188 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
189 void * |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
190 reader_func(void *p) |
0 | 191 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
192 reader_thread_data *data = (reader_thread_data *)p; |
4 | 193 QUEUE_T *p_queue = data->queue; |
194 decoder *dec = data->decoder; | |
8 | 195 int wfd = data->wfd; |
13 | 196 int use_b25 = dec ? TRUE : FALSE; |
197 int use_udp = data->sock_data ? TRUE : FALSE; | |
198 int fileless = FALSE; | |
199 int sfd = -1; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
200 pthread_t signal_thread = data->signal_thread; |
26 | 201 struct sockaddr_in *addr = NULL; |
202 BUFSZ *qbuf; | |
203 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
204 int code; |
4 | 205 |
13 | 206 if(wfd == -1) |
207 fileless = TRUE; | |
208 | |
8 | 209 if(use_udp) { |
210 sfd = data->sock_data->sfd; | |
26 | 211 addr = &data->sock_data->addr; |
8 | 212 } |
213 | |
4 | 214 while(1) { |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
215 ssize_t wc = 0; |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
216 int file_err = 0; |
26 | 217 qbuf = dequeue(p_queue); |
218 /* no entry in the queue */ | |
219 if(qbuf == NULL) { | |
220 break; | |
221 } | |
13 | 222 |
26 | 223 sbuf.data = qbuf->buffer; |
224 sbuf.size = qbuf->size; | |
225 | |
226 buf = sbuf; /* default */ | |
227 | |
228 if(use_b25) { | |
229 code = b25_decode(dec, &sbuf, &dbuf); | |
230 if(code < 0) | |
231 fprintf(stderr, "b25_decode failed\n"); | |
232 else | |
233 buf = dbuf; | |
234 } | |
13 | 235 |
26 | 236 if(!fileless) { |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
237 /* write data to output file */ |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
238 int size_remain = buf.size; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
239 int offset = 0; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
240 while(size_remain > 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
241 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
242 wc = write(wfd, buf.data + offset, ws); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
243 if(wc < 0) { |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
244 perror("write"); |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
245 file_err = 1; |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
246 pthread_kill(signal_thread, |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
247 errno == EPIPE ? SIGPIPE : SIGUSR2); |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
248 break; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
249 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
250 size_remain -= wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
251 offset += wc; |
13 | 252 } |
26 | 253 } |
13 | 254 |
26 | 255 if(use_udp && sfd != -1) { |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
256 /* write data to socket */ |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
257 int size_remain = buf.size; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
258 int offset = 0; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
259 while(size_remain > 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
260 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
261 wc = write(sfd, buf.data + offset, ws); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
262 if(wc < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
263 if(errno == EPIPE) |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
264 pthread_kill(signal_thread, SIGPIPE); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
265 break; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
266 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
267 size_remain -= wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
268 offset += wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
269 } |
26 | 270 } |
271 | |
272 free(qbuf); | |
273 | |
274 /* normal exit */ | |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
275 if(f_exit && !p_queue->num_used && !file_err) { |
26 | 276 |
277 buf = sbuf; /* default */ | |
13 | 278 |
279 if(use_b25) { | |
26 | 280 code = b25_finish(dec, &sbuf, &dbuf); |
281 if(code < 0) | |
282 fprintf(stderr, "b25_finish failed\n"); | |
283 else | |
284 buf = dbuf; | |
13 | 285 } |
4 | 286 |
26 | 287 if(!fileless) { |
288 wc = write(wfd, buf.data, buf.size); | |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
289 if(wc < 0) { |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
290 perror("write"); |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
291 file_err = 1; |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
292 pthread_kill(signal_thread, |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
293 errno == EPIPE ? SIGPIPE : SIGUSR2); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
294 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
295 } |
13 | 296 |
26 | 297 if(use_udp && sfd != -1) { |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
298 wc = write(sfd, buf.data, buf.size); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
299 if(wc < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
300 if(errno == EPIPE) |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
301 pthread_kill(signal_thread, SIGPIPE); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
302 } |
26 | 303 } |
13 | 304 |
26 | 305 break; |
4 | 306 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
307 } |
0 | 308 |
4 | 309 return NULL; |
0 | 310 } |
311 | |
8 | 312 void |
313 show_usage(char *cmd) | |
314 { | |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
315 #ifdef HAVE_LIBARIB25 |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
316 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] channel rectime destfile\n", cmd); |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
317 #else |
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
318 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] channel rectime destfile\n", cmd); |
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
319 #endif |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
320 fprintf(stderr, "\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
321 fprintf(stderr, "Remarks:\n"); |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
322 fprintf(stderr, "if rectime is '-', records indefinitely.\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
323 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); |
13 | 324 } |
325 | |
326 void | |
15 | 327 show_options(void) |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
328 { |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
329 fprintf(stderr, "Options:\n"); |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
330 #ifdef HAVE_LIBARIB25 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
331 fprintf(stderr, "--b25: Decrypt using BCAS card\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
332 fprintf(stderr, " --round N: Specify round number\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
333 fprintf(stderr, " --strip: Strip null stream\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
334 fprintf(stderr, " --EMM: Instruct EMM operation\n"); |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
335 #endif |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
336 fprintf(stderr, "--udp: Turn on udp broadcasting\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
337 fprintf(stderr, " --addr hostname: Hostname or address to connect\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
338 fprintf(stderr, " --port portnumber: Port number to connect\n"); |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
339 fprintf(stderr, "--device devicefile: Specify devicefile to use\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
340 fprintf(stderr, "--help: Show this help\n"); |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
341 fprintf(stderr, "--version: Show version\n"); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
342 fprintf(stderr, "--list: Show channel list\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
343 } |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
344 void |
13 | 345 show_channels(void) |
346 { | |
59
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
347 FILE *f; |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
348 char *home; |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
349 char buf[255], filename[255]; |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
350 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
351 fprintf(stderr, "Available Channels:\n"); |
59
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
352 |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
353 home = getenv("HOME"); |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
354 sprintf(filename, "%s/.recpt1-channels", home); |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
355 f = fopen(filename, "r"); |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
356 if(f) { |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
357 while(fgets(buf, 255, f)) |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
358 fprintf(stderr, "%s", buf); |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
359 fclose(f); |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
360 } |
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
361 else |
67
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
362 fprintf(stderr, "13-62: Terrestrial Channels\n"); |
59
aeb885ed4e7e
recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
57
diff
changeset
|
363 |
67
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
364 fprintf(stderr, "101ch: NHK BS1\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
365 fprintf(stderr, "102ch: NHK BS2\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
366 fprintf(stderr, "103ch: NHK BShi\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
367 fprintf(stderr, "141ch: BS Nittele\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
368 fprintf(stderr, "151ch: BS Asahi\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
369 fprintf(stderr, "161ch: BS-TBS\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
370 fprintf(stderr, "171ch: BS Japan\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
371 fprintf(stderr, "181ch: BS Fuji\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
372 fprintf(stderr, "191ch: WOWOW\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
373 fprintf(stderr, "200ch: Star Channel\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
374 fprintf(stderr, "211ch: BS11 Digital\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
375 fprintf(stderr, "222ch: TwellV\n"); |
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
376 fprintf(stderr, "CS2-CS24: CS Channels\n"); |
8 | 377 } |
378 | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
379 float |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
380 getsignal_isdb_s(int signal) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
381 { |
13 | 382 /* apply linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
383 static const float afLevelTable[] = { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
384 24.07f, // 00 00 0 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
385 24.07f, // 10 00 4096 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
386 18.61f, // 20 00 8192 18.61dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
387 15.21f, // 30 00 12288 15.21dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
388 12.50f, // 40 00 16384 12.50dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
389 10.19f, // 50 00 20480 10.19dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
390 8.140f, // 60 00 24576 8.140dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
391 6.270f, // 70 00 28672 6.270dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
392 4.550f, // 80 00 32768 4.550dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
393 3.730f, // 88 00 34816 3.730dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
394 3.630f, // 88 FF 35071 3.630dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
395 2.940f, // 90 00 36864 2.940dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
396 1.420f, // A0 00 40960 1.420dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
397 0.000f // B0 00 45056 -0.01dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
398 }; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
399 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
400 unsigned char sigbuf[4]; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
401 memset(sigbuf, '\0', sizeof(sigbuf)); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
402 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
403 sigbuf[1] = (signal & 0xFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
404 |
13 | 405 /* calculate signal level */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
406 if(sigbuf[0] <= 0x10U) { |
13 | 407 /* clipped maximum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
408 return 24.07f; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
409 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
410 else if (sigbuf[0] >= 0xB0U) { |
13 | 411 /* clipped minimum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
412 return 0.0f; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
413 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
414 else { |
13 | 415 /* linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
416 const float fMixRate = |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
417 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
418 (unsigned short)sigbuf[0]) / 4096.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
419 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
420 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
421 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
422 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
423 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
424 void |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
425 calc_cn(int fd, int type) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
426 { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
427 int rc ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
428 double P ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
429 double CNR; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
430 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
431 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
62
c6a5c844c7fd
make some messages go stderr instead of stdout.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
61
diff
changeset
|
432 fprintf(stderr, "Tuner Select Error\n"); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
433 return ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
434 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
435 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
436 if(type == CHTYPE_GROUND) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
437 P = log10(5505024/(double)rc) * 10; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
438 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
439 (0.0398 * P * P) + (0.5491 * P)+3.0965; |
62
c6a5c844c7fd
make some messages go stderr instead of stdout.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
61
diff
changeset
|
440 fprintf(stderr, "Signal=%fdB\n", CNR); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
441 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
442 else { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
443 CNR = getsignal_isdb_s(rc); |
62
c6a5c844c7fd
make some messages go stderr instead of stdout.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
61
diff
changeset
|
444 fprintf(stderr, "Signal=%fdB\n", CNR); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
445 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
446 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
447 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
448 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
449 cleanup(signal_thread_data *sdata) |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
450 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
451 /* stop recording */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
452 ioctl(sdata->tfd, STOP_REC, 0); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
453 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
454 /* restore LNB state */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
455 #if 0 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
456 if(ptr->type == CHTYPE_SATELLITE) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
457 if(ioctl(tfd, LNB_DISABLE, 0) < 0) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
458 return 0 ; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
459 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
460 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
461 #endif |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
462 /* xxx need mutex? */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
463 f_exit = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
464 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
465 pthread_cond_signal(&sdata->queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
466 pthread_cond_signal(&sdata->queue->cond_used); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
467 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
468 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
469 /* will be signal handler thread */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
470 void * |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
471 process_signals(void *data) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
472 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
473 sigset_t waitset; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
474 int sig; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
475 signal_thread_data *sdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
476 sdata = (signal_thread_data *)data; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
477 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
478 sigemptyset(&waitset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
479 sigaddset(&waitset, SIGPIPE); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
480 sigaddset(&waitset, SIGINT); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
481 sigaddset(&waitset, SIGTERM); |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
482 sigaddset(&waitset, SIGUSR1); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
483 sigaddset(&waitset, SIGUSR2); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
484 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
485 sigwait(&waitset, &sig); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
486 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
487 switch(sig) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
488 case SIGPIPE: |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
489 fprintf(stderr, "\nSIGPIPE received. cleaning up...\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
490 cleanup(sdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
491 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
492 case SIGINT: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
493 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
494 cleanup(sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
495 break; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
496 case SIGTERM: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
497 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
498 cleanup(sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
499 break; |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
500 case SIGUSR1: /* normal exit*/ |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
501 cleanup(sdata); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
502 break; |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
503 case SIGUSR2: /* error */ |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
504 fprintf(stderr, "Detected an error. cleaning up...\n"); |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
505 cleanup(sdata); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
506 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
507 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
508 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
509 return NULL; /* dummy */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
510 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
511 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
512 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
513 init_signal_handlers(pthread_t *signal_thread, signal_thread_data *sdata) |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
514 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
515 sigset_t blockset; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
516 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
517 sigemptyset(&blockset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
518 sigaddset(&blockset, SIGPIPE); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
519 sigaddset(&blockset, SIGINT); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
520 sigaddset(&blockset, SIGTERM); |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
521 sigaddset(&blockset, SIGUSR1); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
522 sigaddset(&blockset, SIGUSR2); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
523 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
524 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL)) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
525 fprintf(stderr, "pthread_sigmask() failed.\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
526 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
527 pthread_create(signal_thread, NULL, process_signals, sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
528 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
529 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
530 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
531 main(int argc, char **argv) |
0 | 532 { |
8 | 533 int tfd, wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
534 int lp; |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
535 int recsec = 0; |
13 | 536 int indefinite = FALSE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
537 time_t start_time, cur_time; |
4 | 538 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
539 ISDB_T_FREQ_CONV_TABLE *ptr; |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
540 pthread_t reader_thread; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
541 pthread_t signal_thread; |
4 | 542 QUEUE_T *p_queue = create_queue(MAX_QUEUE); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
543 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
544 decoder *dec = NULL; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
545 static reader_thread_data tdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
546 static signal_thread_data sdata; |
8 | 547 decoder_options dopt = { |
548 4, /* round */ | |
549 0, /* strip */ | |
550 0 /* emm */ | |
551 }; | |
0 | 552 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
553 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
554 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
555 struct option long_options[] = { |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
556 #ifdef HAVE_LIBARIB25 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
557 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
558 { "B25", 0, NULL, 'b'}, |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
559 #endif |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
560 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
561 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
562 { "emm", 0, NULL, 'm'}, |
8 | 563 { "EMM", 0, NULL, 'm'}, |
13 | 564 { "udp", 0, NULL, 'u'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
565 { "addr", 1, NULL, 'a'}, |
13 | 566 { "port", 1, NULL, 'p'}, |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
567 { "device", 1, NULL, 'd'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
568 { "help", 0, NULL, 'h'}, |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
569 { "version", 0, NULL, 'v'}, |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
570 { "list", 0, NULL, 'l'}, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
571 {0, 0, NULL, 0} /* terminate */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
572 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
573 |
13 | 574 int use_b25 = FALSE; |
575 int use_udp = FALSE; | |
576 int fileless = FALSE; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
577 int use_stdout = FALSE; |
8 | 578 char *host_to = NULL; |
579 int port_to = 1234; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
580 sock_data *sockdata = NULL; |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
581 char *device = NULL; |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
582 char **tuner; |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
583 int num_devs; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
584 |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
585 while((result = getopt_long(argc, argv, "br:smua:p:d:hvl", |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
586 long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
587 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
588 case 'b': |
13 | 589 use_b25 = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
590 fprintf(stderr, "using B25...\n"); |
8 | 591 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
592 case 's': |
13 | 593 dopt.strip = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
594 fprintf(stderr, "enable B25 strip\n"); |
8 | 595 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
596 case 'm': |
13 | 597 dopt.emm = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
598 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 599 break; |
13 | 600 case 'u': |
601 use_udp = TRUE; | |
602 host_to = "localhost"; | |
603 fprintf(stderr, "enable UDP broadcasting\n"); | |
604 break; | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
605 case 'h': |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
606 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
607 show_usage(argv[0]); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
608 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
609 show_options(); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
610 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
611 show_channels(); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
612 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
613 exit(0); |
13 | 614 break; |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
615 case 'v': |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
616 fprintf(stderr, "%s %s\n", argv[0], version); |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
617 fprintf(stderr, "recorder command for PT1 digital tuner.\n"); |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
618 exit(0); |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
619 break; |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
620 case 'l': |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
621 show_channels(); |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
622 exit(0); |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
623 break; |
13 | 624 /* following options require argument */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
625 case 'r': |
8 | 626 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
627 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
628 break; |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
629 case 'a': |
13 | 630 use_udp = TRUE; |
8 | 631 host_to = optarg; |
632 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
633 break; | |
634 case 'p': | |
635 port_to = atoi(optarg); | |
636 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
637 break; |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
638 case 'd': |
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
639 device = optarg; |
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
640 fprintf(stderr, "using device: %s\n", device); |
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
641 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
642 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
643 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
644 |
8 | 645 if(argc - optind < 3) { |
13 | 646 if(argc - optind == 2 && use_udp) { |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
647 fprintf(stderr, "Fileless UDP broadcasting\n"); |
13 | 648 fileless = TRUE; |
649 wfd = -1; | |
650 } | |
651 else { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
652 fprintf(stderr, "Arguments are necessary!\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
653 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
13 | 654 return 1; |
655 } | |
4 | 656 } |
13 | 657 |
658 /* get channel */ | |
8 | 659 ptr = searchrecoff(argv[optind]); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
660 if(ptr == NULL) { |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
661 fprintf(stderr, "Invalid Channel: %s\n", argv[optind]); |
8 | 662 return 1; |
663 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
664 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
665 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
666 freq.slot = ptr->add_freq; |
0 | 667 |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
668 /* open tuner */ |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
669 /* case 1: specified tuner device */ |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
670 if(device) { |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
671 tfd = open(device, O_RDONLY); |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
672 if(tfd < 0) { |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
673 fprintf(stderr, "Cannot open tuner device: %s\n", device); |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
674 return 1; |
4 | 675 } |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
676 |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
677 /* power on LNB */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
678 if(ptr->type == CHTYPE_SATELLITE) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
679 if(ioctl(tfd, LNB_ENABLE, 0) < 0) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
680 close(tfd); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
681 fprintf(stderr, "Power on LNB failed: %s\n", device); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
682 return 1; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
683 } |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
684 } |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
685 |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
686 /* tune to specified channel */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
687 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
688 close(tfd); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
689 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
690 return 1; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
691 } |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
692 } |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
693 else { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
694 /* case 2: loop around available devices */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
695 if(ptr->type == CHTYPE_SATELLITE) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
696 tuner = bsdev; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
697 num_devs = NUM_BSDEV; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
698 } |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
699 else { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
700 tuner = isdb_t_dev; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
701 num_devs = NUM_ISDB_T_DEV; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
702 } |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
703 |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
704 for(lp = 0; lp < num_devs; lp++) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
705 tfd = open(tuner[lp], O_RDONLY); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
706 if(tfd >= 0) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
707 /* power on LNB */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
708 if(ptr->type == CHTYPE_SATELLITE) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
709 if(ioctl(tfd, LNB_ENABLE, 0) < 0) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
710 close(tfd); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
711 tfd = -1; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
712 continue; |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
713 } |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
714 } |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
715 |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
716 /* tune to specified channel */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
717 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
718 close(tfd); |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
719 tfd = -1; |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
720 continue; |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
721 } |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
722 |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
723 break; /* found suitable tuner */ |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
724 } |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
725 } |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
726 |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
727 /* all tuners cannot be used */ |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
728 if(tfd < 0) { |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
729 fprintf(stderr, "Cannot tune to the specified channel\n"); |
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
730 return 1; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
731 } |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
732 } |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
733 |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
734 /* show signal strength */ |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
735 calc_cn(tfd, ptr->type); |
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
736 |
13 | 737 /* get recsec */ |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
738 char *rectimestr = argv[optind + 1]; |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
739 |
48
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
740 /* indefinite */ |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
741 if(!strcmp("-", rectimestr)) { |
13 | 742 indefinite = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
743 recsec = -1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
744 } |
48
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
745 /* colon */ |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
746 else if(strchr(rectimestr, ':')) { |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
747 int n1, n2, n3; |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
748 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3) |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
749 recsec = n1 * 3600 + n2 * 60 + n3; |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
750 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2) |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
751 recsec = n1 * 3600 + n2 * 60; |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
752 } |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
753 /* HMS */ |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
754 else { |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
755 char *tmpstr; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
756 char *p1, *p2; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
757 |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
758 tmpstr = strdup(rectimestr); |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
759 p1 = tmpstr; |
49
6bcdd17c12f6
fixed a crash bug in HMS support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
48
diff
changeset
|
760 while(*p1 && !isdigit(*p1)) |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
761 p1++; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
762 |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
763 /* hour */ |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
764 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) { |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
765 *p2 = '\0'; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
766 recsec += atoi(p1) * 3600; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
767 p1 = p2 + 1; |
49
6bcdd17c12f6
fixed a crash bug in HMS support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
48
diff
changeset
|
768 while(*p1 && !isdigit(*p1)) |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
769 p1++; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
770 } |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
771 |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
772 /* minute */ |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
773 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) { |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
774 *p2 = '\0'; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
775 recsec += atoi(p1) * 60; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
776 p1 = p2 + 1; |
49
6bcdd17c12f6
fixed a crash bug in HMS support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
48
diff
changeset
|
777 while(*p1 && !isdigit(*p1)) |
47
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
778 p1++; |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
779 } |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
780 |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
781 /* second */ |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
782 recsec += atoi(p1); |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
783 |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
784 free(tmpstr); |
edd904628e2f
a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
43
diff
changeset
|
785 } |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
786 |
48
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
787 /* fprintf(stderr, "recsec = %d\n", recsec); */ |
c8051f6da2ab
now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
47
diff
changeset
|
788 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
789 /* open output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
790 char *destfile = argv[optind + 2]; |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
791 if(destfile && !strcmp("-", destfile)) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
792 use_stdout = TRUE; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
793 wfd = 1; /* stdout */ |
38
3228f5cde349
recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
35
diff
changeset
|
794 } |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
795 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
796 if(!fileless) { |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
797 int status; |
63
ca419e61f7f2
fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
62
diff
changeset
|
798 char *path = strdup(argv[optind + 2]); |
ca419e61f7f2
fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
62
diff
changeset
|
799 char *dir = dirname(path); |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
800 status = mkpath(dir, 0777); |
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
801 if(status == -1) |
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
802 perror("mkpath"); |
63
ca419e61f7f2
fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
62
diff
changeset
|
803 free(path); |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
804 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
805 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
806 if(wfd < 0) { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
807 fprintf(stderr, "Cannot open output file: %s\n", |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
808 argv[optind + 2]); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
809 return 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
810 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
811 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
812 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
813 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
814 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
815 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
816 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
817 if(!dec) { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
818 fprintf(stderr, "Cannot start b25 decoder\n"); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
819 fprintf(stderr, "Fall back to encrypted recording\n"); |
7
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
820 use_b25 = 0; |
4 | 821 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
822 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
823 |
8 | 824 /* initialize udp connection */ |
825 if(use_udp) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
826 sockdata = calloc(1, sizeof(sock_data)); |
8 | 827 struct in_addr ia; |
828 ia.s_addr = inet_addr(host_to); | |
829 if(ia.s_addr == INADDR_NONE) { | |
830 struct hostent *hoste = gethostbyname(host_to); | |
831 if(!hoste) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
832 perror("gethostbyname"); |
8 | 833 return 1; |
834 } | |
835 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
836 } | |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
837 if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
838 perror("socket"); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
839 return 1; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
840 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
841 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
842 sockdata->addr.sin_family = AF_INET; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
843 sockdata->addr.sin_port = htons (port_to); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
844 sockdata->addr.sin_addr.s_addr = ia.s_addr; |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
845 |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
846 if(connect(sockdata->sfd, (struct sockaddr *)&sockdata->addr, |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
847 sizeof(sockdata->addr)) < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
848 perror("connect"); |
8 | 849 return 1; |
850 } | |
851 } | |
852 | |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
853 /* spawn signal handler thread */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
854 sdata.queue = p_queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
855 sdata.tfd = tfd; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
856 init_signal_handlers(&signal_thread, &sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
857 |
33
f25820d90249
make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
32
diff
changeset
|
858 /* spawn reader thread */ |
4 | 859 tdata.queue = p_queue; |
860 tdata.decoder = dec; | |
8 | 861 tdata.wfd = wfd; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
862 tdata.sock_data = sockdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
863 tdata.signal_thread = signal_thread; |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
864 pthread_create(&reader_thread, NULL, reader_func, &tdata); |
3 | 865 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
866 /* start recording */ |
8 | 867 if(ioctl(tfd, START_REC, 0) < 0) { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
868 fprintf(stderr, "Tuner cannot start recording\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
869 return 1; |
4 | 870 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
871 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
872 fprintf(stderr, "Recording...\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
873 |
4 | 874 time(&start_time); |
0 | 875 |
4 | 876 /* read from tuner */ |
877 while(1) { | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
878 if(f_exit) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
879 break; |
26 | 880 |
4 | 881 time(&cur_time); |
882 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 883 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 884 if(bufptr->size <= 0) { |
13 | 885 if((cur_time - start_time) >= recsec && !indefinite) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
886 f_exit = TRUE; |
4 | 887 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
888 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
889 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
890 else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
891 continue; |
4 | 892 } |
893 } | |
894 enqueue(p_queue, bufptr); | |
0 | 895 |
4 | 896 /* stop recording */ |
13 | 897 if((cur_time - start_time) >= recsec && !indefinite) { |
8 | 898 ioctl(tfd, STOP_REC, 0); |
4 | 899 /* read remaining data */ |
900 while(1) { | |
901 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 902 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 903 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
904 f_exit = TRUE; |
4 | 905 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
906 break; |
4 | 907 } |
908 enqueue(p_queue, bufptr); | |
909 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
910 break; |
4 | 911 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
912 } |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
913 |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
914 pthread_kill(signal_thread, SIGUSR1); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
915 |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
916 /* wait for threads */ |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
917 pthread_join(reader_thread, NULL); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
918 pthread_join(signal_thread, NULL); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
919 |
4 | 920 /* close tuner */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
921 if(ptr->type == CHTYPE_SATELLITE) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
922 if(ioctl(tfd, LNB_DISABLE, 0) < 0) { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
923 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
924 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
925 } |
8 | 926 close(tfd); |
0 | 927 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
928 /* release queue */ |
4 | 929 destroy_queue(p_queue); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
930 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
931 /* close output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
932 if(!use_stdout) |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
933 close(wfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
934 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
935 /* free socket data */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
936 if(use_udp) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
937 close(sockdata->sfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
938 free(sockdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
939 } |
8 | 940 |
4 | 941 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
942 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
943 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
944 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
945 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
946 return 0; |
0 | 947 } |