Mercurial > pt1
annotate recpt1/recpt1.c @ 5:97fd2315114e
- now it can handle options.
- applied channel patch.
- some cleanups.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 17 Feb 2009 05:58:36 +0900 |
parents | 43d177fa65c9 |
children | d898fd27547f |
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> | |
9 #include <unistd.h> | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
10 #include <getopt.h> |
0 | 11 |
3 | 12 #include <sys/ioctl.h> |
13 #include "pt1_ioctl.h" | |
0 | 14 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
15 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
16 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
17 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
18 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
19 int f_exit = FALSE; |
0 | 20 |
3 | 21 typedef struct thread_data { |
4 | 22 QUEUE_T *queue; |
23 decoder *decoder; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
24 int fd; |
3 | 25 } thread_data; |
0 | 26 |
27 // 周波数テーブル変換 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
28 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
29 searchrecoff(char *channel) |
0 | 30 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
31 int lp; |
0 | 32 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
33 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++){ |
4 | 34 // 文字列&長さ一致したら周波数テーブル番号を返却する |
35 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, | |
36 strlen(channel)) == 0) && | |
37 (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
|
38 return &isdb_t_conv_table[lp]; |
4 | 39 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
40 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
41 return NULL; |
0 | 42 } |
43 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
44 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
45 create_queue(size_t size) |
0 | 46 { |
4 | 47 QUEUE_T *p_queue; |
48 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); | |
0 | 49 |
4 | 50 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 51 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
52 if(p_queue != NULL) { |
4 | 53 p_queue->size = size; |
54 p_queue->no_full = size; | |
55 p_queue->no_empty = 0; | |
56 pthread_mutex_init(&p_queue->mutex, NULL); | |
57 pthread_cond_init(&p_queue->cond_full, NULL); | |
58 pthread_cond_init(&p_queue->cond_empty, NULL); | |
59 } | |
0 | 60 |
4 | 61 return p_queue; |
0 | 62 } |
63 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
64 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
65 destroy_queue(QUEUE_T *p_queue) |
0 | 66 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
67 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
68 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
69 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
70 pthread_mutex_destroy(&p_queue->mutex); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
71 pthread_cond_destroy(&p_queue->cond_full); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
72 pthread_cond_destroy(&p_queue->cond_empty); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
73 free(p_queue); |
0 | 74 } |
75 | |
3 | 76 /* 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
|
77 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
78 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 79 { |
4 | 80 pthread_mutex_lock(&p_queue->mutex); |
81 /* entered critical section */ | |
0 | 82 |
4 | 83 /* wait until queue is not full */ |
84 while(!p_queue->no_full) { | |
85 pthread_cond_wait(&p_queue->cond_full, &p_queue->mutex); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
86 fprintf(stderr, "Full\n"); |
4 | 87 } |
0 | 88 |
4 | 89 p_queue->buffer[p_queue->in] = data; |
0 | 90 |
4 | 91 p_queue->in++; |
92 p_queue->in %= p_queue->size; | |
0 | 93 |
4 | 94 p_queue->no_full--; |
95 p_queue->no_empty++; | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
96 |
4 | 97 /* leaving critical section */ |
98 pthread_mutex_unlock(&p_queue->mutex); | |
99 pthread_cond_signal(&p_queue->cond_empty); | |
0 | 100 } |
101 | |
3 | 102 /* 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
|
103 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
104 dequeue(QUEUE_T *p_queue) |
0 | 105 { |
4 | 106 BUFSZ *buffer; |
0 | 107 |
4 | 108 pthread_mutex_lock(&p_queue->mutex); |
109 /* entered the critical section*/ | |
0 | 110 |
4 | 111 /* wait until queue is filled */ |
112 while (!p_queue->no_empty) { | |
113 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex); | |
114 } | |
0 | 115 |
4 | 116 /* take buffer address */ |
117 buffer = p_queue->buffer[p_queue->out]; | |
0 | 118 |
4 | 119 // 次にデータを取り出す場所をインクリメント |
120 p_queue->out++; | |
121 p_queue->out %= p_queue->size; | |
0 | 122 |
4 | 123 /* update flags */ |
124 p_queue->no_full++; | |
125 p_queue->no_empty--; | |
0 | 126 |
4 | 127 /* leaving the critical section */ |
128 pthread_mutex_unlock(&p_queue->mutex); | |
129 pthread_cond_signal(&p_queue->cond_full); | |
0 | 130 |
4 | 131 return buffer; |
0 | 132 } |
133 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
134 /* this function will be a writing thread */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
135 void * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
136 write_func(void *p) |
0 | 137 { |
4 | 138 thread_data *data = (thread_data *)p; |
139 QUEUE_T *p_queue = data->queue; | |
140 decoder *dec = data->decoder; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
141 int wfd = data->fd; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
142 int use_b25 = dec ? 1 : 0; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
143 BUFSZ *buf; |
4 | 144 ARIB_STD_B25_BUFFER sbuf, dbuf; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
145 int code; |
4 | 146 |
147 while(1) { | |
148 buf = dequeue(p_queue); | |
149 /* no entry in the queue */ | |
150 if(buf == NULL){ | |
151 close(wfd); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
152 break; |
4 | 153 } |
0 | 154 |
4 | 155 sbuf.data = buf->buffer; |
156 sbuf.size = buf->size; | |
157 | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
158 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
159 /* write data to output file*/ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
160 code = b25_decode(dec, &sbuf, &dbuf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
161 if(code < 0) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
162 fprintf(stderr, "b25_decode failed\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
163 close(wfd); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
164 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
165 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
166 write(wfd, dbuf.data, dbuf.size); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
167 free(buf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
168 } else { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
169 write(wfd, sbuf.data, sbuf.size); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
170 free(buf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
171 } |
4 | 172 |
173 /* normal exit */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
174 if((f_exit) && (!p_queue->no_empty)) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
175 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
176 code = b25_finish(dec, &sbuf, &dbuf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
177 if(code < 0) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
178 fprintf(stderr, "b25_finish failed\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
179 close(wfd); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
180 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
181 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
182 write(wfd, dbuf.data, dbuf.size); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
183 } |
4 | 184 close(wfd); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
185 break; |
4 | 186 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
187 } |
0 | 188 |
4 | 189 return NULL; |
0 | 190 } |
191 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
192 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
193 main(int argc, char **argv) |
0 | 194 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
195 int fd, wfd; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
196 int lp; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
197 int recsec; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
198 time_t start_time, cur_time; |
4 | 199 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
200 ISDB_T_FREQ_CONV_TABLE *ptr; |
4 | 201 pthread_t dequeue_threads; |
202 QUEUE_T *p_queue = create_queue(MAX_QUEUE); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
203 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
204 decoder *dec = NULL; |
4 | 205 thread_data tdata; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
206 decoder_options dopt; |
0 | 207 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
208 int use_b25 = 0; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
209 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
210 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
211 struct option long_options[] = { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
212 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
213 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
214 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
215 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
216 { "emm", 0, NULL, 'm'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
217 { "EMM", 0, NULL, 'm'} |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
218 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
219 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
220 dopt.round = 4; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
221 dopt.strip = 0; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
222 dopt.emm = 0; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
223 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
224 while((result = getopt_long(argc, argv, "br:sm", long_options, &option_index)) != -1) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
225 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
226 case 'b': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
227 use_b25 = 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
228 fprintf(stderr, "using B25...\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
229 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
230 case 's': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
231 dopt.strip = 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
232 fprintf(stderr, "enable B25 strip\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
233 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
234 case 'm': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
235 dopt.emm = 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
236 fprintf(stderr, "enable B25 emm processing\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
237 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
238 case 'r': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
239 dopt.round = atoi(optarg); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
240 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
241 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
242 case ':': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
243 fprintf(stderr, "%c needs value\n", result); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
244 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
245 case '?': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
246 fprintf(stderr, "Usage: [--b25 [--round N] [--strip] [--EMM]] channel recsec destfile\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
247 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
248 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
249 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
250 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
251 if(argc - optind < 3) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
252 printf("Usage %s: [--b25 [--round N] [--strip] [--EMM]] channel recsec destfile\n", argv[0]); |
4 | 253 printf("channel =\n"); |
254 printf("151ch:BS朝日\n"); | |
255 printf("161ch:BS-i\n"); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
256 printf("191ch:WOWOW\n"); |
4 | 257 printf("171ch:BSジャパン\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
258 printf("200ch:スターチャンネル\n"); |
4 | 259 printf("211ch:BS11デジタル\n"); |
260 printf("222ch:TwellV\n"); | |
261 printf("141ch:BS日テレ\n"); | |
262 printf("181ch:BSフジ\n"); | |
263 printf("101ch:NHK衛星第1放送(BS1)\n"); | |
264 printf("102ch:NHK衛星第2放送(BS2)\n"); | |
265 printf("103ch:NHKハイビジョン(BShi)\n"); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
266 printf("CS2-CS24:CSチャンネル\n"); |
4 | 267 return 1; |
268 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
269 ptr = searchrecoff(argv[optind]); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
270 if(ptr == NULL){ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
271 printf("Channel Select Error(%s)\n", argv[optind]); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
272 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
273 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
274 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
275 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
276 freq.slot = ptr->add_freq; |
0 | 277 |
4 | 278 if(ptr->type == CHTYPE_SATELLITE) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
279 for(lp = 0; lp < 2; lp++) { |
4 | 280 fd = open(bsdev[lp], O_RDONLY); |
281 if(fd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
282 break; |
4 | 283 } |
284 } | |
285 if(fd < 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
286 fprintf(stderr, "Device Open Error\n"); |
4 | 287 return 1; |
288 } | |
289 } else { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
290 for(lp = 0; lp < 2; lp++) { |
4 | 291 fd = open(isdb_t_dev[lp], O_RDONLY); |
292 if(fd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
293 break; |
4 | 294 } |
295 } | |
296 if(fd < 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
297 fprintf(stderr, "Device Open Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
298 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
299 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
300 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
301 recsec = atoi(argv[optind + 1]); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
302 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
303 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
304 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
305 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
306 if(!dec) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
307 fprintf(stderr, "cannot start b25 decoder\n"); |
4 | 308 return 1; |
309 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
310 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
311 |
4 | 312 /* open output file */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
313 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
4 | 314 if(wfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
315 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
316 return 1; |
4 | 317 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
318 |
4 | 319 if(ioctl(fd, SET_CHANNEL, &freq) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
320 fprintf(stderr, "Tuner Select Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
321 return 1; |
4 | 322 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
323 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
324 /* make reader thread */ |
4 | 325 tdata.queue = p_queue; |
326 tdata.decoder = dec; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
327 tdata.fd = wfd; |
4 | 328 pthread_create(&dequeue_threads, NULL, write_func, &tdata); |
3 | 329 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
330 /* start recording */ |
4 | 331 if(ioctl(fd, START_REC, 0) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
332 fprintf(stderr, "Tuner Start Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
333 return 1; |
4 | 334 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
335 |
4 | 336 time(&start_time); |
0 | 337 |
4 | 338 /* read from tuner */ |
339 while(1) { | |
340 time(&cur_time); | |
341 bufptr = malloc(sizeof(BUFSZ)); | |
342 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE); | |
343 if(bufptr->size <= 0) { | |
344 if((cur_time - start_time) >= recsec) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
345 f_exit = TRUE; |
4 | 346 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
347 break; |
4 | 348 } else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
349 continue; |
4 | 350 } |
351 } | |
352 enqueue(p_queue, bufptr); | |
0 | 353 |
4 | 354 /* stop recording */ |
355 if((cur_time - start_time) >= recsec) { | |
356 ioctl(fd, STOP_REC, 0); | |
357 /* read remaining data */ | |
358 while(1) { | |
359 bufptr = malloc(sizeof(BUFSZ)); | |
360 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE); | |
361 if(bufptr->size <= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
362 f_exit = TRUE; |
4 | 363 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
364 break; |
4 | 365 } |
366 enqueue(p_queue, bufptr); | |
367 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
368 break; |
4 | 369 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
370 } |
4 | 371 /* close tuner */ |
372 close(fd); | |
0 | 373 |
4 | 374 /* wait reading thread */ |
375 pthread_join(dequeue_threads, NULL); | |
376 destroy_queue(p_queue); | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
377 |
4 | 378 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
379 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
380 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
381 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
382 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
383 return 0; |
0 | 384 } |