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