Mercurial > pt1
annotate recpt1/recpt1.c @ 27:763cf84d2dc7
fixed a bug that waited for wrong cond variable
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 28 Feb 2009 04:21:31 +0900 |
parents | c6264c15f39d |
children | 97c820e30737 |
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> |
0 | 15 |
8 | 16 #include <netdb.h> |
17 #include <arpa/inet.h> | |
18 #include <netinet/in.h> | |
19 | |
3 | 20 #include <sys/ioctl.h> |
21 #include "pt1_ioctl.h" | |
0 | 22 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
23 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
24 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
25 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
26 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
27 int f_exit = FALSE; |
0 | 28 |
21
b63f5c100e5a
made recpt1 link against b25 shared object.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
29 /* type definitions */ |
8 | 30 typedef struct sock_data { |
31 int sfd; /* socket fd */ | |
32 struct sockaddr_in addr; | |
33 } sock_data; | |
34 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
35 typedef struct reader_thread_data { |
4 | 36 QUEUE_T *queue; |
37 decoder *decoder; | |
8 | 38 int wfd; /* output file fd */ |
39 sock_data *sock_data; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
40 pthread_t signal_thread; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
41 } reader_thread_data; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
42 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
43 typedef struct signal_thread_data { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
44 QUEUE_T *queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
45 int tfd; /* tuner fd */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
46 } signal_thread_data; |
0 | 47 |
6 | 48 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
49 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
50 searchrecoff(char *channel) |
0 | 51 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
52 int lp; |
0 | 53 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
54 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) { |
6 | 55 /* return entry number in the table when strings match and |
56 * lengths are same. */ | |
4 | 57 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
58 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
|
59 (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
|
60 return &isdb_t_conv_table[lp]; |
4 | 61 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
62 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
63 return NULL; |
0 | 64 } |
65 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
66 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
67 create_queue(size_t size) |
0 | 68 { |
4 | 69 QUEUE_T *p_queue; |
8 | 70 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 71 |
4 | 72 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 73 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
74 if(p_queue != NULL) { |
4 | 75 p_queue->size = size; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
76 p_queue->num_avail = size; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
77 p_queue->num_used = 0; |
4 | 78 pthread_mutex_init(&p_queue->mutex, NULL); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
79 pthread_cond_init(&p_queue->cond_avail, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
80 pthread_cond_init(&p_queue->cond_used, NULL); |
4 | 81 } |
0 | 82 |
4 | 83 return p_queue; |
0 | 84 } |
85 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
86 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
87 destroy_queue(QUEUE_T *p_queue) |
0 | 88 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
89 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
90 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
91 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
92 pthread_mutex_destroy(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
93 pthread_cond_destroy(&p_queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
94 pthread_cond_destroy(&p_queue->cond_used); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
95 free(p_queue); |
0 | 96 } |
97 | |
3 | 98 /* 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
|
99 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
100 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 101 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
102 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
103 struct timespec spec; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
104 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
105 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
106 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
107 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
108 |
4 | 109 pthread_mutex_lock(&p_queue->mutex); |
110 /* entered critical section */ | |
0 | 111 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
112 /* wait while queue is full */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
113 while(p_queue->num_avail == 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
114 pthread_cond_timedwait(&p_queue->cond_avail, |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
115 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
116 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
117 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
118 return; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
119 } |
4 | 120 } |
0 | 121 |
4 | 122 p_queue->buffer[p_queue->in] = data; |
0 | 123 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
124 /* move position marker for input to next position */ |
4 | 125 p_queue->in++; |
126 p_queue->in %= p_queue->size; | |
0 | 127 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
128 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
129 p_queue->num_avail--; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
130 p_queue->num_used++; |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
131 |
4 | 132 /* leaving critical section */ |
133 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
134 pthread_cond_signal(&p_queue->cond_used); |
0 | 135 } |
136 | |
3 | 137 /* 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
|
138 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
139 dequeue(QUEUE_T *p_queue) |
0 | 140 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
141 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
142 struct timespec spec; |
8 | 143 BUFSZ *buffer; |
0 | 144 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
145 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
146 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
147 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
148 |
4 | 149 pthread_mutex_lock(&p_queue->mutex); |
150 /* entered the critical section*/ | |
0 | 151 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
152 /* wait while queue is empty */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
153 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
|
154 pthread_cond_timedwait(&p_queue->cond_used, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
155 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
156 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
157 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
158 return NULL; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
159 } |
4 | 160 } |
0 | 161 |
4 | 162 /* take buffer address */ |
163 buffer = p_queue->buffer[p_queue->out]; | |
0 | 164 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
165 /* move position marker for output to next position */ |
4 | 166 p_queue->out++; |
167 p_queue->out %= p_queue->size; | |
0 | 168 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
169 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
170 p_queue->num_avail++; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
171 p_queue->num_used--; |
0 | 172 |
4 | 173 /* leaving the critical section */ |
174 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
175 pthread_cond_signal(&p_queue->cond_avail); |
0 | 176 |
4 | 177 return buffer; |
0 | 178 } |
179 | |
6 | 180 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
181 void * |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
182 reader_func(void *p) |
0 | 183 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
184 reader_thread_data *data = (reader_thread_data *)p; |
4 | 185 QUEUE_T *p_queue = data->queue; |
186 decoder *dec = data->decoder; | |
8 | 187 int wfd = data->wfd; |
13 | 188 int use_b25 = dec ? TRUE : FALSE; |
189 int use_udp = data->sock_data ? TRUE : FALSE; | |
190 int fileless = FALSE; | |
191 int sfd = -1; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
192 pthread_t signal_thread = data->signal_thread; |
26 | 193 struct sockaddr_in *addr = NULL; |
194 BUFSZ *qbuf; | |
195 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
196 int code; |
4 | 197 |
13 | 198 if(wfd == -1) |
199 fileless = TRUE; | |
200 | |
8 | 201 if(use_udp) { |
202 sfd = data->sock_data->sfd; | |
26 | 203 addr = &data->sock_data->addr; |
8 | 204 } |
205 | |
4 | 206 while(1) { |
26 | 207 ssize_t wc; |
208 qbuf = dequeue(p_queue); | |
209 /* no entry in the queue */ | |
210 if(qbuf == NULL) { | |
211 break; | |
212 } | |
13 | 213 |
26 | 214 sbuf.data = qbuf->buffer; |
215 sbuf.size = qbuf->size; | |
216 | |
217 buf = sbuf; /* default */ | |
218 | |
219 if(use_b25) { | |
220 /* write data to output file*/ | |
221 code = b25_decode(dec, &sbuf, &dbuf); | |
222 if(code < 0) | |
223 fprintf(stderr, "b25_decode failed\n"); | |
224 else | |
225 buf = dbuf; | |
226 } | |
13 | 227 |
26 | 228 if(!fileless) { |
229 wc = write(wfd, buf.data, buf.size); | |
230 if(wc < 0) { | |
231 if(errno == EPIPE) | |
232 pthread_kill(signal_thread, SIGPIPE); | |
233 else | |
234 pthread_kill(signal_thread, SIGUSR2); | |
13 | 235 } |
26 | 236 } |
13 | 237 |
26 | 238 if(use_udp && sfd != -1) { |
239 sendto(sfd, buf.data, buf.size, 0, | |
240 (struct sockaddr *)addr, sizeof(*addr)); | |
241 } | |
242 | |
243 free(qbuf); | |
244 | |
245 /* normal exit */ | |
246 if((f_exit) && (!p_queue->num_used)) { | |
247 | |
248 buf = sbuf; /* default */ | |
13 | 249 |
250 if(use_b25) { | |
26 | 251 code = b25_finish(dec, &sbuf, &dbuf); |
252 if(code < 0) | |
253 fprintf(stderr, "b25_finish failed\n"); | |
254 else | |
255 buf = dbuf; | |
13 | 256 } |
4 | 257 |
26 | 258 if(!fileless) { |
259 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
|
260 if(wc < 0) { |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
261 if(errno == EPIPE) |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
262 pthread_kill(signal_thread, SIGPIPE); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
263 else |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
264 pthread_kill(signal_thread, SIGUSR2); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
265 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
266 } |
13 | 267 |
26 | 268 if(use_udp && sfd != -1) { |
269 sendto(sfd, buf.data, buf.size, 0, | |
270 (struct sockaddr *)addr, sizeof(*addr)); | |
271 } | |
13 | 272 |
26 | 273 break; |
4 | 274 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
275 } |
0 | 276 |
4 | 277 return NULL; |
0 | 278 } |
279 | |
8 | 280 void |
281 show_usage(char *cmd) | |
282 { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
283 fprintf(stderr, "\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
284 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] channel recsec destfile\n", cmd); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
285 fprintf(stderr, "\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
286 fprintf(stderr, "Remarks:\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
287 fprintf(stderr, "if recsec is '-', records indefinitely.\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
288 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
289 fprintf(stderr, "\n"); |
13 | 290 } |
291 | |
292 void | |
15 | 293 show_options(void) |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
294 { |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
295 fprintf(stderr, "Options:\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
296 fprintf(stderr, "--b25: Decrypt using BCAS card\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
297 fprintf(stderr, " --round N: Specify round number\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
298 fprintf(stderr, " --strip: Strip null stream\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
299 fprintf(stderr, " --EMM: Instruct EMM operation\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
300 fprintf(stderr, "--udp: Turn on udp broadcasting\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
301 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
|
302 fprintf(stderr, " --port portnumber: Port number to connect\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
303 fprintf(stderr, "--help: Show this help\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
304 fprintf(stderr, "\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
305 } |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
306 void |
13 | 307 show_channels(void) |
308 { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
309 fprintf(stderr, "Available Channels:\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
310 fprintf(stderr, "13-52¡§Terrestrial Channels\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
311 fprintf(stderr, "151ch¡§BS Asahi\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
312 fprintf(stderr, "161ch¡§BS-i\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
313 fprintf(stderr, "191ch¡§WOWOW\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
314 fprintf(stderr, "171ch¡§BS Japan\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
315 fprintf(stderr, "200ch¡§Star Channel\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
316 fprintf(stderr, "211ch¡§BS11 Digital\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
317 fprintf(stderr, "222ch¡§TwellV\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
318 fprintf(stderr, "141ch¡§BS Nittele\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
319 fprintf(stderr, "181ch¡§BS Fuji\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
320 fprintf(stderr, "101ch¡§NHK BS1\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
321 fprintf(stderr, "102ch¡§NHK BS2\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
322 fprintf(stderr, "103ch¡§NHK BShi\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
323 fprintf(stderr, "CS2-CS24¡§CS Channels\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
324 fprintf(stderr, "\n"); |
8 | 325 } |
326 | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
327 float |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
328 getsignal_isdb_s(int signal) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
329 { |
13 | 330 /* apply linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
331 static const float afLevelTable[] = { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
332 24.07f, // 00 00 0 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
333 24.07f, // 10 00 4096 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
334 18.61f, // 20 00 8192 18.61dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
335 15.21f, // 30 00 12288 15.21dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
336 12.50f, // 40 00 16384 12.50dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
337 10.19f, // 50 00 20480 10.19dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
338 8.140f, // 60 00 24576 8.140dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
339 6.270f, // 70 00 28672 6.270dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
340 4.550f, // 80 00 32768 4.550dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
341 3.730f, // 88 00 34816 3.730dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
342 3.630f, // 88 FF 35071 3.630dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
343 2.940f, // 90 00 36864 2.940dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
344 1.420f, // A0 00 40960 1.420dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
345 0.000f // B0 00 45056 -0.01dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
346 }; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
347 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
348 unsigned char sigbuf[4]; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
349 memset(sigbuf, '\0', sizeof(sigbuf)); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
350 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
351 sigbuf[1] = (signal & 0xFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
352 |
13 | 353 /* 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
|
354 if(sigbuf[0] <= 0x10U) { |
13 | 355 /* clipped maximum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
356 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
|
357 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
358 else if (sigbuf[0] >= 0xB0U) { |
13 | 359 /* clipped minimum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
360 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
|
361 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
362 else { |
13 | 363 /* linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
364 const float fMixRate = |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
365 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
366 (unsigned short)sigbuf[0]) / 4096.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
367 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
368 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
369 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
370 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
371 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
372 void |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
373 calc_cn(int fd, int type) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
374 { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
375 int rc ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
376 double P ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
377 double CNR; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
378 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
379 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
380 printf("Tuner Select Error\n"); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
381 return ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
382 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
383 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
384 if(type == CHTYPE_GROUND) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
385 P = log10(5505024/(double)rc) * 10; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
386 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
|
387 (0.0398 * P * P) + (0.5491 * P)+3.0965; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
388 printf("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
|
389 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
390 else { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
391 CNR = getsignal_isdb_s(rc); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
392 printf("Signal=%fdB\n", CNR); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
393 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
394 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
395 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
396 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
397 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
|
398 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
399 /* stop recording */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
400 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
|
401 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
402 /* 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
|
403 #if 0 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
404 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
|
405 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
|
406 return 0 ; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
407 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
408 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
409 #endif |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
410 /* 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
|
411 f_exit = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
412 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
413 pthread_cond_signal(&sdata->queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
414 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
|
415 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
416 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
417 /* 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
|
418 void * |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
419 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
|
420 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
421 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
|
422 int sig; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
423 signal_thread_data *sdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
424 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
|
425 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
426 sigemptyset(&waitset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
433 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
|
434 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
435 switch(sig) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
436 case SIGPIPE: |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
437 fprintf(stderr, "\nSIGPIPE received. cleaning up...\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
438 cleanup(sdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
439 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
440 case SIGINT: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
441 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
442 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
|
443 break; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
444 case SIGTERM: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
445 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
446 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
|
447 break; |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
448 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
|
449 cleanup(sdata); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
450 break; |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
451 case SIGUSR2: /* error */ |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
452 fprintf(stderr, "\nSomething is wrong. cleaning up...\n"); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
453 cleanup(sdata); |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
454 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
455 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
456 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
457 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
|
458 } |
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 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
461 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
|
462 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
463 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
|
464 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
465 sigemptyset(&blockset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
472 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
|
473 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
|
474 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
475 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
|
476 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
477 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
478 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
479 main(int argc, char **argv) |
0 | 480 { |
8 | 481 int tfd, wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
482 int lp; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
483 int recsec; |
13 | 484 int indefinite = FALSE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
485 time_t start_time, cur_time; |
4 | 486 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
487 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
|
488 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
|
489 pthread_t signal_thread; |
4 | 490 QUEUE_T *p_queue = create_queue(MAX_QUEUE); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
491 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
492 decoder *dec = NULL; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
493 static reader_thread_data tdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
494 static signal_thread_data sdata; |
8 | 495 decoder_options dopt = { |
496 4, /* round */ | |
497 0, /* strip */ | |
498 0 /* emm */ | |
499 }; | |
0 | 500 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
501 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
502 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
503 struct option long_options[] = { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
504 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
505 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
506 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
507 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
508 { "emm", 0, NULL, 'm'}, |
8 | 509 { "EMM", 0, NULL, 'm'}, |
13 | 510 { "udp", 0, NULL, 'u'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
511 { "addr", 1, NULL, 'a'}, |
13 | 512 { "port", 1, NULL, 'p'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
513 { "help", 0, NULL, 'h'}, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
514 {0, 0, NULL, 0} /* terminate */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
515 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
516 |
13 | 517 int use_b25 = FALSE; |
518 int use_udp = FALSE; | |
519 int fileless = FALSE; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
520 int use_stdout = FALSE; |
8 | 521 char *host_to = NULL; |
522 int port_to = 1234; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
523 sock_data *sockdata = NULL; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
524 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
525 while((result = getopt_long(argc, argv, "br:smua:p:h", |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
526 long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
527 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
528 case 'b': |
13 | 529 use_b25 = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
530 fprintf(stderr, "using B25...\n"); |
8 | 531 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
532 case 's': |
13 | 533 dopt.strip = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
534 fprintf(stderr, "enable B25 strip\n"); |
8 | 535 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
536 case 'm': |
13 | 537 dopt.emm = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
538 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 539 break; |
13 | 540 case 'u': |
541 use_udp = TRUE; | |
542 host_to = "localhost"; | |
543 fprintf(stderr, "enable UDP broadcasting\n"); | |
544 break; | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
545 case 'h': |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
546 show_usage(argv[0]); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
547 show_options(); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
548 show_channels(); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
549 exit(0); |
13 | 550 break; |
551 /* following options require argument */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
552 case 'r': |
8 | 553 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
554 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
555 break; |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
556 case 'a': |
13 | 557 use_udp = TRUE; |
8 | 558 host_to = optarg; |
559 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
560 break; | |
561 case 'p': | |
562 port_to = atoi(optarg); | |
563 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
564 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
565 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
566 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
567 |
8 | 568 if(argc - optind < 3) { |
13 | 569 if(argc - optind == 2 && use_udp) { |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
570 fprintf(stderr, "Fileless UDP broadcasting\n"); |
13 | 571 fileless = TRUE; |
572 wfd = -1; | |
573 } | |
574 else { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
575 fprintf(stderr, "Arguments are necessary!\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
576 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
13 | 577 return 1; |
578 } | |
4 | 579 } |
13 | 580 |
581 /* get channel */ | |
8 | 582 ptr = searchrecoff(argv[optind]); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
583 if(ptr == NULL) { |
13 | 584 fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]); |
8 | 585 return 1; |
586 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
587 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
588 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
589 freq.slot = ptr->add_freq; |
0 | 590 |
4 | 591 if(ptr->type == CHTYPE_SATELLITE) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
592 for(lp = 0; lp < 2; lp++) { |
8 | 593 tfd = open(bsdev[lp], O_RDONLY); |
594 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
595 break; |
4 | 596 } |
597 } | |
8 | 598 if(tfd < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
599 fprintf(stderr, "Cannot open tuner\n"); |
4 | 600 return 1; |
601 } | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
602 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
603 else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
604 for(lp = 0; lp < 2; lp++) { |
8 | 605 tfd = open(isdb_t_dev[lp], O_RDONLY); |
606 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
607 break; |
4 | 608 } |
609 } | |
8 | 610 if(tfd < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
611 fprintf(stderr, "Cannot open tuner\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
612 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
613 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
614 } |
13 | 615 |
616 /* get recsec */ | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
617 char *recsecstr = argv[optind + 1]; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
618 if(!strcmp("-", recsecstr)) { |
13 | 619 indefinite = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
620 recsec = -1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
621 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
622 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
623 recsec = atoi(recsecstr); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
624 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
625 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
626 /* open output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
627 char *destfile = argv[optind + 2]; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
628 if(destfile && !strcmp("-", destfile)) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
629 use_stdout = TRUE; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
630 wfd = 1; /* stdout */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
631 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
632 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
633 if(!fileless) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
634 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
|
635 if(wfd < 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
636 fprintf(stderr, "Could not open output file(%s)\n", argv[optind + 2]); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
637 return 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
638 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
639 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
640 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
641 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
642 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
643 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
644 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
645 if(!dec) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
646 fprintf(stderr, "Could not start b25 decoder\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
647 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
|
648 use_b25 = 0; |
4 | 649 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
650 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
651 |
8 | 652 /* initialize udp connection */ |
653 if(use_udp) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
654 sockdata = calloc(1, sizeof(sock_data)); |
8 | 655 struct in_addr ia; |
656 ia.s_addr = inet_addr(host_to); | |
657 if(ia.s_addr == INADDR_NONE) { | |
658 struct hostent *hoste = gethostbyname(host_to); | |
659 if(!hoste) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
660 perror("gethostbyname"); |
8 | 661 return 1; |
662 } | |
663 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
664 } | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
665 sockdata->addr.sin_family = AF_INET; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
666 sockdata->addr.sin_port = htons (port_to); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
667 sockdata->addr.sin_addr.s_addr = ia.s_addr; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
668 if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { |
8 | 669 perror("socket"); |
670 return 1; | |
671 } | |
672 } | |
673 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
674 /* setup tuner */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
675 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
|
676 if(ioctl(tfd, LNB_ENABLE, 0) < 0) { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
677 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
678 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
679 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
680 |
8 | 681 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
682 fprintf(stderr, "Could not tune to the specified channel\n"); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
683 calc_cn(tfd, ptr->type); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
684 return 1; |
4 | 685 } |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
686 calc_cn(tfd, ptr->type); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
687 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
688 /* init signal handler thread */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
689 sdata.queue = p_queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
690 sdata.tfd = tfd; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
691 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
|
692 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
693 /* make reader thread */ |
4 | 694 tdata.queue = p_queue; |
695 tdata.decoder = dec; | |
8 | 696 tdata.wfd = wfd; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
697 tdata.sock_data = sockdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
698 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
|
699 pthread_create(&reader_thread, NULL, reader_func, &tdata); |
3 | 700 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
701 /* start recording */ |
8 | 702 if(ioctl(tfd, START_REC, 0) < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
703 fprintf(stderr, "Tuner could not start recording\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
704 return 1; |
4 | 705 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
706 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
707 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
|
708 |
4 | 709 time(&start_time); |
0 | 710 |
4 | 711 /* read from tuner */ |
712 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
|
713 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
|
714 break; |
26 | 715 |
4 | 716 time(&cur_time); |
717 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 718 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 719 if(bufptr->size <= 0) { |
13 | 720 if((cur_time - start_time) >= recsec && !indefinite) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
721 f_exit = TRUE; |
4 | 722 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
723 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
724 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
725 else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
726 continue; |
4 | 727 } |
728 } | |
729 enqueue(p_queue, bufptr); | |
0 | 730 |
4 | 731 /* stop recording */ |
13 | 732 if((cur_time - start_time) >= recsec && !indefinite) { |
8 | 733 ioctl(tfd, STOP_REC, 0); |
4 | 734 /* read remaining data */ |
735 while(1) { | |
736 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 737 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 738 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
739 f_exit = TRUE; |
4 | 740 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
741 break; |
4 | 742 } |
743 enqueue(p_queue, bufptr); | |
744 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
745 break; |
4 | 746 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
747 } |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
748 |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
749 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
|
750 |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
751 /* 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
|
752 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
|
753 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
|
754 |
4 | 755 /* 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
|
756 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
|
757 if(ioctl(tfd, LNB_DISABLE, 0) < 0) { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
758 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
759 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
760 } |
8 | 761 close(tfd); |
0 | 762 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
763 /* release queue */ |
4 | 764 destroy_queue(p_queue); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
765 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
766 /* close output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
767 if(!use_stdout) |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
768 close(wfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
769 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
770 /* free socket data */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
771 if(use_udp) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
772 close(sockdata->sfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
773 free(sockdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
774 } |
8 | 775 |
4 | 776 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
777 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
778 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
779 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
780 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
781 return 0; |
0 | 782 } |