Mercurial > pt1.oyama
annotate recpt1/recpt1.c @ 13:003fe2470af8
reorganized options:
- 0 as recsec means indefinite recording.
- now --udp option works as switch to enable udp broadcasting.
- --host option has been added. this option specifies hostname to connect via udp socket.
- when --udp option is specified, output file may not be specified.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 24 Feb 2009 17:22:06 +0900 |
parents | 4615eaf04415 |
children | cad940a903f5 |
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> |
0 | 12 |
8 | 13 #include <netdb.h> |
14 #include <arpa/inet.h> | |
15 #include <netinet/in.h> | |
16 | |
3 | 17 #include <sys/ioctl.h> |
18 #include "pt1_ioctl.h" | |
0 | 19 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
20 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
21 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
22 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
23 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
24 int f_exit = FALSE; |
0 | 25 |
8 | 26 typedef struct sock_data { |
27 int sfd; /* socket fd */ | |
28 struct sockaddr_in addr; | |
29 } sock_data; | |
30 | |
3 | 31 typedef struct thread_data { |
4 | 32 QUEUE_T *queue; |
33 decoder *decoder; | |
8 | 34 int wfd; /* output file fd */ |
35 sock_data *sock_data; | |
3 | 36 } thread_data; |
0 | 37 |
6 | 38 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
39 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
40 searchrecoff(char *channel) |
0 | 41 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
42 int lp; |
0 | 43 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
44 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++){ |
6 | 45 /* return entry number in the table when strings match and |
46 * lengths are same. */ | |
4 | 47 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
48 strlen(channel)) == 0) && | |
49 (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
|
50 return &isdb_t_conv_table[lp]; |
4 | 51 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
52 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
53 return NULL; |
0 | 54 } |
55 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
56 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
57 create_queue(size_t size) |
0 | 58 { |
4 | 59 QUEUE_T *p_queue; |
8 | 60 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 61 |
4 | 62 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 63 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
64 if(p_queue != NULL) { |
4 | 65 p_queue->size = size; |
66 p_queue->no_full = size; | |
67 p_queue->no_empty = 0; | |
68 pthread_mutex_init(&p_queue->mutex, NULL); | |
69 pthread_cond_init(&p_queue->cond_full, NULL); | |
70 pthread_cond_init(&p_queue->cond_empty, NULL); | |
71 } | |
0 | 72 |
4 | 73 return p_queue; |
0 | 74 } |
75 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
76 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
77 destroy_queue(QUEUE_T *p_queue) |
0 | 78 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
79 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
80 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
81 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
82 pthread_mutex_destroy(&p_queue->mutex); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
83 pthread_cond_destroy(&p_queue->cond_full); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
84 pthread_cond_destroy(&p_queue->cond_empty); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
85 free(p_queue); |
0 | 86 } |
87 | |
3 | 88 /* 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
|
89 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
90 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 91 { |
4 | 92 pthread_mutex_lock(&p_queue->mutex); |
93 /* entered critical section */ | |
0 | 94 |
4 | 95 /* wait until queue is not full */ |
96 while(!p_queue->no_full) { | |
97 pthread_cond_wait(&p_queue->cond_full, &p_queue->mutex); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
98 fprintf(stderr, "Full\n"); |
4 | 99 } |
0 | 100 |
4 | 101 p_queue->buffer[p_queue->in] = data; |
0 | 102 |
4 | 103 p_queue->in++; |
104 p_queue->in %= p_queue->size; | |
0 | 105 |
4 | 106 p_queue->no_full--; |
107 p_queue->no_empty++; | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
108 |
4 | 109 /* leaving critical section */ |
110 pthread_mutex_unlock(&p_queue->mutex); | |
111 pthread_cond_signal(&p_queue->cond_empty); | |
0 | 112 } |
113 | |
3 | 114 /* 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
|
115 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
116 dequeue(QUEUE_T *p_queue) |
0 | 117 { |
8 | 118 BUFSZ *buffer; |
0 | 119 |
4 | 120 pthread_mutex_lock(&p_queue->mutex); |
121 /* entered the critical section*/ | |
0 | 122 |
4 | 123 /* wait until queue is filled */ |
124 while (!p_queue->no_empty) { | |
125 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex); | |
126 } | |
0 | 127 |
4 | 128 /* take buffer address */ |
129 buffer = p_queue->buffer[p_queue->out]; | |
0 | 130 |
6 | 131 /* move location marker to next position */ |
4 | 132 p_queue->out++; |
133 p_queue->out %= p_queue->size; | |
0 | 134 |
4 | 135 /* update flags */ |
136 p_queue->no_full++; | |
137 p_queue->no_empty--; | |
0 | 138 |
4 | 139 /* leaving the critical section */ |
140 pthread_mutex_unlock(&p_queue->mutex); | |
141 pthread_cond_signal(&p_queue->cond_full); | |
0 | 142 |
4 | 143 return buffer; |
0 | 144 } |
145 | |
6 | 146 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
147 void * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
148 write_func(void *p) |
0 | 149 { |
4 | 150 thread_data *data = (thread_data *)p; |
151 QUEUE_T *p_queue = data->queue; | |
152 decoder *dec = data->decoder; | |
8 | 153 int wfd = data->wfd; |
13 | 154 int use_b25 = dec ? TRUE : FALSE; |
155 int use_udp = data->sock_data ? TRUE : FALSE; | |
156 int fileless = FALSE; | |
157 int sfd = -1; | |
8 | 158 struct sockaddr *addr = NULL; |
159 BUFSZ *buf; | |
4 | 160 ARIB_STD_B25_BUFFER sbuf, dbuf; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
161 int code; |
4 | 162 |
13 | 163 if(wfd == -1) |
164 fileless = TRUE; | |
165 | |
8 | 166 if(use_udp) { |
167 sfd = data->sock_data->sfd; | |
168 addr = (struct sockaddr *)&data->sock_data->addr; | |
169 } | |
170 | |
4 | 171 while(1) { |
13 | 172 |
173 if(fileless) { | |
174 | |
175 buf = dequeue(p_queue); | |
176 /* no entry in the queue */ | |
177 if(buf == NULL) { | |
178 break; | |
179 } | |
180 | |
181 sbuf.data = buf->buffer; | |
182 sbuf.size = buf->size; | |
183 | |
184 if(use_b25) { | |
185 /* write data to output file*/ | |
186 code = b25_decode(dec, &sbuf, &dbuf); | |
187 if(code < 0) { | |
188 fprintf(stderr, "b25_decode failed\n"); | |
189 break; | |
190 } | |
0 | 191 |
13 | 192 if(use_udp && sfd != -1) { |
193 sendto(sfd, dbuf.data, dbuf.size, 0, | |
194 addr, sizeof(struct sockaddr_in)); | |
195 } | |
196 free(buf); | |
197 } else { | |
198 if(use_udp && sfd != -1) { | |
199 sendto(sfd, sbuf.data, sbuf.size, 0, | |
200 addr, sizeof(struct sockaddr_in)); | |
201 } | |
202 free(buf); | |
203 } | |
4 | 204 |
13 | 205 /* normal exit */ |
206 if((f_exit) && (!p_queue->no_empty)) { | |
207 if(use_b25) { | |
208 code = b25_finish(dec, &sbuf, &dbuf); | |
209 if(code < 0) { | |
210 fprintf(stderr, "b25_finish failed\n"); | |
211 close(sfd); | |
212 break; | |
213 } | |
214 | |
215 if(use_udp && sfd != -1) { | |
216 sendto(sfd, dbuf.data, dbuf.size, 0, | |
217 addr, sizeof(struct sockaddr_in)); | |
218 } | |
219 } | |
220 close(sfd); | |
221 break; | |
222 } | |
223 } /* fileless */ | |
224 else { | |
225 | |
226 buf = dequeue(p_queue); | |
227 /* no entry in the queue */ | |
228 if(buf == NULL) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
229 close(wfd); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
230 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
231 } |
8 | 232 |
13 | 233 sbuf.data = buf->buffer; |
234 sbuf.size = buf->size; | |
8 | 235 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
236 if(use_b25) { |
13 | 237 /* write data to output file*/ |
238 code = b25_decode(dec, &sbuf, &dbuf); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
239 if(code < 0) { |
13 | 240 fprintf(stderr, "b25_decode failed\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
241 close(wfd); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
242 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
243 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
244 write(wfd, dbuf.data, dbuf.size); |
8 | 245 |
13 | 246 if(use_udp && sfd != -1) { |
8 | 247 sendto(sfd, dbuf.data, dbuf.size, 0, |
248 addr, sizeof(struct sockaddr_in)); | |
249 } | |
13 | 250 free(buf); |
251 } else { | |
252 write(wfd, sbuf.data, sbuf.size); | |
253 | |
254 if(use_udp && sfd != -1) { | |
255 sendto(sfd, sbuf.data, sbuf.size, 0, | |
256 addr, sizeof(struct sockaddr_in)); | |
257 } | |
258 free(buf); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
259 } |
13 | 260 |
261 /* normal exit */ | |
262 if((f_exit) && (!p_queue->no_empty)) { | |
263 if(use_b25) { | |
264 code = b25_finish(dec, &sbuf, &dbuf); | |
265 if(code < 0) { | |
266 fprintf(stderr, "b25_finish failed\n"); | |
267 close(wfd); | |
268 close(sfd); | |
269 break; | |
270 } | |
271 write(wfd, dbuf.data, dbuf.size); | |
272 | |
273 if(use_udp && sfd != -1) { | |
274 sendto(sfd, dbuf.data, dbuf.size, 0, | |
275 addr, sizeof(struct sockaddr_in)); | |
276 } | |
277 } | |
278 close(wfd); | |
279 close(sfd); | |
280 break; | |
281 } | |
4 | 282 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
283 } |
0 | 284 |
4 | 285 return NULL; |
0 | 286 } |
287 | |
8 | 288 void |
289 show_usage(char *cmd) | |
290 { | |
13 | 291 fprintf(stderr, "Usage: %s [--b25 [--round N] [--strip] [--EMM]] [--udp [--host hostname --port port]] channel recsec destfile\n", cmd); |
292 } | |
293 | |
294 void | |
295 show_channels(void) | |
296 { | |
297 printf("Channel List:\n"); | |
298 printf("151ch¡§BS Asahi\n"); | |
299 printf("161ch¡§BS-i\n"); | |
300 printf("191ch¡§WOWOW\n"); | |
301 printf("171ch¡§BS Japan\n"); | |
302 printf("200ch¡§Star Channel\n"); | |
303 printf("211ch¡§BS11 Digital\n"); | |
304 printf("222ch¡§TwellV\n"); | |
305 printf("141ch¡§BS Nittele\n"); | |
306 printf("181ch¡§BS Fuji\n"); | |
307 printf("101ch¡§NHK BS1\n"); | |
308 printf("102ch¡§NHK BS2\n"); | |
309 printf("103ch¡§NHK BShi\n"); | |
310 printf("CS2-CS24¡§CS Channels\n"); | |
8 | 311 } |
312 | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
313 float |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
314 getsignal_isdb_s(int signal) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
315 { |
13 | 316 /* apply linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
317 static const float afLevelTable[] = { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
318 24.07f, // 00 00 0 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
319 24.07f, // 10 00 4096 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
320 18.61f, // 20 00 8192 18.61dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
321 15.21f, // 30 00 12288 15.21dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
322 12.50f, // 40 00 16384 12.50dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
323 10.19f, // 50 00 20480 10.19dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
324 8.140f, // 60 00 24576 8.140dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
325 6.270f, // 70 00 28672 6.270dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
326 4.550f, // 80 00 32768 4.550dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
327 3.730f, // 88 00 34816 3.730dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
328 3.630f, // 88 FF 35071 3.630dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
329 2.940f, // 90 00 36864 2.940dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
330 1.420f, // A0 00 40960 1.420dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
331 0.000f // B0 00 45056 -0.01dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
332 }; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
333 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
334 unsigned char sigbuf[4]; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
335 memset(sigbuf, '\0', sizeof(sigbuf)); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
336 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
337 sigbuf[1] = (signal & 0xFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
338 |
13 | 339 /* calculate signal level */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
340 if(sigbuf[0] <= 0x10U){ |
13 | 341 /* clipped maximum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
342 return 24.07f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
343 } else if (sigbuf[0] >= 0xB0U) { |
13 | 344 /* clipped minimum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
345 return 0.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
346 } else { |
13 | 347 /* linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
348 const float fMixRate = |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
349 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
350 (unsigned short)sigbuf[0]) / 4096.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
351 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
352 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
353 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
354 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
355 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
356 void |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
357 calc_cn(int fd, int type) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
358 { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
359 int rc ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
360 double P ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
361 double CNR; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
362 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
363 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
364 printf("Tuner Select Error\n"); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
365 return ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
366 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
367 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
368 if(type == CHTYPE_GROUND) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
369 P = log10(5505024/(double)rc) * 10; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
370 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
|
371 (0.0398 * P * P) + (0.5491 * P)+3.0965; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
372 printf("Signal=%fdB\n", CNR); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
373 } else { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
374 CNR = getsignal_isdb_s(rc); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
375 printf("Signal=%fdB\n", CNR); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
376 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
377 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
378 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
379 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
380 main(int argc, char **argv) |
0 | 381 { |
8 | 382 int tfd, wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
383 int lp; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
384 int recsec; |
13 | 385 int indefinite = FALSE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
386 time_t start_time, cur_time; |
4 | 387 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
388 ISDB_T_FREQ_CONV_TABLE *ptr; |
4 | 389 pthread_t dequeue_threads; |
390 QUEUE_T *p_queue = create_queue(MAX_QUEUE); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
391 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
392 decoder *dec = NULL; |
4 | 393 thread_data tdata; |
8 | 394 decoder_options dopt = { |
395 4, /* round */ | |
396 0, /* strip */ | |
397 0 /* emm */ | |
398 }; | |
0 | 399 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
400 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
401 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
402 struct option long_options[] = { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
403 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
404 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
405 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
406 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
407 { "emm", 0, NULL, 'm'}, |
8 | 408 { "EMM", 0, NULL, 'm'}, |
13 | 409 { "udp", 0, NULL, 'u'}, |
410 { "host", 1, NULL, 'h'}, | |
411 { "port", 1, NULL, 'p'}, | |
412 {0, 0, 0, 0} /* terminate */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
413 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
414 |
13 | 415 int use_b25 = FALSE; |
416 int use_udp = FALSE; | |
417 int fileless = FALSE; | |
8 | 418 char *host_to = NULL; |
419 int port_to = 1234; | |
420 sock_data *sdata = NULL; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
421 |
13 | 422 while((result = getopt_long(argc, argv, "br:smuh:p:", long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
423 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
424 case 'b': |
13 | 425 use_b25 = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
426 fprintf(stderr, "using B25...\n"); |
8 | 427 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
428 case 's': |
13 | 429 dopt.strip = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
430 fprintf(stderr, "enable B25 strip\n"); |
8 | 431 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
432 case 'm': |
13 | 433 dopt.emm = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
434 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 435 break; |
13 | 436 case 'u': |
437 use_udp = TRUE; | |
438 host_to = "localhost"; | |
439 fprintf(stderr, "enable UDP broadcasting\n"); | |
440 break; | |
441 /* | |
442 case ':': | |
443 fprintf(stderr, "%c needs value\n", result); | |
444 break; | |
445 */ | |
446 case '?': | |
447 show_usage(argv[0]); | |
448 break; | |
449 | |
450 | |
451 /* following options require argument */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
452 case 'r': |
8 | 453 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
454 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
455 break; |
13 | 456 case 'h': |
457 use_udp = TRUE; | |
8 | 458 host_to = optarg; |
459 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
460 break; | |
461 case 'p': | |
462 port_to = atoi(optarg); | |
463 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
464 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
465 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
466 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
467 |
8 | 468 if(argc - optind < 3) { |
13 | 469 if(argc - optind == 2 && use_udp) { |
470 fprintf(stderr, "fileless udp broadcasting\n"); | |
471 fileless = TRUE; | |
472 wfd = -1; | |
473 } | |
474 else { | |
475 show_usage(argv[0]); | |
476 show_channels(); | |
477 return 1; | |
478 } | |
4 | 479 } |
13 | 480 |
481 /* get channel */ | |
8 | 482 ptr = searchrecoff(argv[optind]); |
483 if(ptr == NULL){ | |
13 | 484 fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]); |
8 | 485 return 1; |
486 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
487 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
488 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
489 freq.slot = ptr->add_freq; |
0 | 490 |
4 | 491 if(ptr->type == CHTYPE_SATELLITE) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
492 for(lp = 0; lp < 2; lp++) { |
8 | 493 tfd = open(bsdev[lp], O_RDONLY); |
494 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
495 break; |
4 | 496 } |
497 } | |
8 | 498 if(tfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
499 fprintf(stderr, "Device Open Error\n"); |
4 | 500 return 1; |
501 } | |
502 } else { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
503 for(lp = 0; lp < 2; lp++) { |
8 | 504 tfd = open(isdb_t_dev[lp], O_RDONLY); |
505 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
506 break; |
4 | 507 } |
508 } | |
8 | 509 if(tfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
510 fprintf(stderr, "Device Open Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
511 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
512 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
513 } |
13 | 514 |
515 /* get recsec */ | |
8 | 516 recsec = atoi(argv[optind + 1]); |
13 | 517 if(recsec == 0) |
518 indefinite = TRUE; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
519 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
520 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
521 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
522 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
523 if(!dec) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
524 fprintf(stderr, "cannot start b25 decoder\n"); |
7
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
525 fprintf(stderr, "fall back to encrypted recording\n"); |
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
526 use_b25 = 0; |
4 | 527 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
528 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
529 |
8 | 530 /* initialize udp connection */ |
531 if(use_udp) { | |
532 sdata = calloc(1, sizeof(sock_data)); | |
533 struct in_addr ia; | |
534 ia.s_addr = inet_addr(host_to); | |
535 if(ia.s_addr == INADDR_NONE) { | |
536 struct hostent *hoste = gethostbyname(host_to); | |
537 if(!hoste) { | |
538 perror("failed to get host by name"); | |
539 return 1; | |
540 } | |
541 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
542 } | |
543 sdata->addr.sin_family = AF_INET; | |
544 sdata->addr.sin_port = htons (port_to); | |
545 sdata->addr.sin_addr.s_addr = ia.s_addr; | |
546 if((sdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { | |
547 perror("socket"); | |
548 return 1; | |
549 } | |
550 } | |
551 | |
4 | 552 /* open output file */ |
13 | 553 if(!fileless) { |
554 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); | |
555 if(wfd < 0) { | |
556 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]); | |
557 return 1; | |
558 } | |
4 | 559 } |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
560 if(ptr->type == CHTYPE_SATELLITE){ |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
561 if(ioctl(tfd, LNB_ENABLE, 0) < 0){ |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
562 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
563 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
564 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
565 |
8 | 566 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
567 fprintf(stderr, "Tuner Select Error\n"); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
568 calc_cn(tfd, ptr->type); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
569 return 1; |
4 | 570 } |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
571 calc_cn(tfd, ptr->type); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
572 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
573 /* make reader thread */ |
4 | 574 tdata.queue = p_queue; |
575 tdata.decoder = dec; | |
8 | 576 tdata.wfd = wfd; |
577 tdata.sock_data = sdata; | |
4 | 578 pthread_create(&dequeue_threads, NULL, write_func, &tdata); |
3 | 579 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
580 /* start recording */ |
8 | 581 if(ioctl(tfd, START_REC, 0) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
582 fprintf(stderr, "Tuner Start Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
583 return 1; |
4 | 584 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
585 |
4 | 586 time(&start_time); |
0 | 587 |
4 | 588 /* read from tuner */ |
589 while(1) { | |
590 time(&cur_time); | |
591 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 592 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 593 if(bufptr->size <= 0) { |
13 | 594 if((cur_time - start_time) >= recsec && !indefinite) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
595 f_exit = TRUE; |
4 | 596 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
597 break; |
4 | 598 } else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
599 continue; |
4 | 600 } |
601 } | |
602 enqueue(p_queue, bufptr); | |
0 | 603 |
4 | 604 /* stop recording */ |
13 | 605 if((cur_time - start_time) >= recsec && !indefinite) { |
8 | 606 ioctl(tfd, STOP_REC, 0); |
4 | 607 /* read remaining data */ |
608 while(1) { | |
609 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 610 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 611 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
612 f_exit = TRUE; |
4 | 613 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
614 break; |
4 | 615 } |
616 enqueue(p_queue, bufptr); | |
617 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
618 break; |
4 | 619 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
620 } |
4 | 621 /* close tuner */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
622 if(ptr->type == CHTYPE_SATELLITE){ |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
623 if(ioctl(tfd, LNB_DISABLE, 0) < 0){ |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
624 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
625 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
626 } |
8 | 627 close(tfd); |
0 | 628 |
6 | 629 /* wait reader thread */ |
4 | 630 pthread_join(dequeue_threads, NULL); |
631 destroy_queue(p_queue); | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
632 |
8 | 633 /* close socket */ |
634 if(use_udp) { | |
635 close(sdata->sfd); | |
636 free(sdata); | |
637 } | |
638 | |
4 | 639 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
640 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
641 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
642 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
643 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
644 return 0; |
0 | 645 } |