Mercurial > pt1
annotate recpt1/recpt1.c @ 2:8ac7c59fefc9
added b25 decode functionality
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 16 Feb 2009 21:40:16 +0900 |
parents | 29f3b2bbbd67 |
children | 6801fe7e04ff |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <sys/types.h> | |
3 #include <sys/stat.h> | |
4 #include <fcntl.h> | |
5 #include <time.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <pthread.h> | |
9 #include <unistd.h> | |
10 | |
11 #include <sys/ioctl.h> | |
12 #include "pt1_ioctl.h" | |
13 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
14 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
15 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
16 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
17 /* globals */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
18 int wfd; // ファイル書き込み用 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
19 int f_exit = FALSE ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
20 decoder *dec; |
0 | 21 |
22 | |
23 // 周波数テーブル変換 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
24 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
25 searchrecoff(char *channel) |
0 | 26 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
27 int lp ; |
0 | 28 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
29 for(lp = 0 ; lp < 113 ; lp++){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
30 // 文字列&長さ一致したら周波数テーブル番号を返却する |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
31 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
32 strlen(channel)) == 0) && |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
33 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
34 return &isdb_t_conv_table[lp] ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
35 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
36 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
37 return NULL ; |
0 | 38 } |
39 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
40 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
41 create_queue(size_t size) |
0 | 42 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
43 QUEUE_T* p_queue; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
44 int memsize = sizeof(QUEUE_T) + (size * sizeof(BUFSZ)); |
0 | 45 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
46 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 47 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
48 if(p_queue != NULL){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
49 p_queue->size = size; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
50 p_queue->no_full = size; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
51 p_queue->no_empty = 0; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
52 pthread_mutex_init(&p_queue->mutex, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
53 pthread_cond_init(&p_queue->cond_full, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
54 pthread_cond_init(&p_queue->cond_empty, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
55 } |
0 | 56 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
57 return p_queue; |
0 | 58 } |
59 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
60 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
61 destroy_queue(QUEUE_T *p_queue) |
0 | 62 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
63 if(p_queue != NULL){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
64 pthread_mutex_destroy(&p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
65 pthread_cond_destroy(&p_queue->cond_full); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
66 pthread_cond_destroy(&p_queue->cond_empty); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
67 free(p_queue); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
68 } |
0 | 69 } |
70 | |
71 // 関数名: enqueue | |
72 // キューにデータを入れる | |
73 // データが満タンな場合は、ブロックします | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
74 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
75 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 76 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
77 pthread_mutex_lock(&p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
78 // -- ここから、クリティカルセクション -- |
0 | 79 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
80 // 満タンじゃなくなるまで待つ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
81 while(!p_queue->no_full) { |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
82 pthread_cond_wait(&p_queue->cond_full, &p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
83 printf("Full\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
84 } |
0 | 85 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
86 p_queue->buffer[p_queue->in] = data; |
0 | 87 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
88 p_queue->in++; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
89 p_queue->in %= p_queue->size; |
0 | 90 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
91 p_queue->no_full--; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
92 p_queue->no_empty++; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
93 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
94 pthread_mutex_unlock(&p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
95 pthread_cond_signal(&p_queue->cond_empty); |
0 | 96 } |
97 | |
98 // 関数名: dequeue | |
99 // キューにデータを入れる | |
100 // データが満タンな場合は、ブロックします | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
101 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
102 dequeue(QUEUE_T *p_queue) |
0 | 103 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
104 void *result; |
0 | 105 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
106 pthread_mutex_lock(&p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
107 // -- ここから、クリティカルセクション -- |
0 | 108 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
109 // 空っぽじゃなくなるまで待つ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
110 while (!p_queue->no_empty) { |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
111 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
112 } |
0 | 113 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
114 // データを取り出す |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
115 result = p_queue->buffer[p_queue->out]; |
0 | 116 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
117 // 次にデータを取り出す場所をインクリメント |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
118 p_queue->out++; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
119 p_queue->out %= p_queue->size; |
0 | 120 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
121 // フラグの更新 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
122 p_queue->no_full++; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
123 p_queue->no_empty--; |
0 | 124 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
125 // -- ここまで、クリティカルセクション -- |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
126 pthread_mutex_unlock(&p_queue->mutex); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
127 pthread_cond_signal(&p_queue->cond_full); |
0 | 128 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
129 return result; |
0 | 130 } |
131 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
132 /* this function will be a writing thread */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
133 void * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
134 write_func(void *p) |
0 | 135 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
136 QUEUE_T *p_queue = (QUEUE_T*)p; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
137 BUFSZ *ptr ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
138 ARIB_STD_B25_BUFFER sbuf, dbuf; |
0 | 139 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
140 while(1){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
141 ptr = dequeue(p_queue); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
142 /* no entry in the queue */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
143 if(ptr == NULL){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
144 close(wfd); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
145 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
146 } |
0 | 147 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
148 sbuf.data = ptr->buffer; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
149 sbuf.size = ptr->size; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
150 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
151 /* write data to output file*/ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
152 b25_decode(dec, &sbuf, &dbuf); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
153 write(wfd, dbuf.data, dbuf.size); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
154 free(ptr); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
155 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
156 /* normal exit */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
157 if((f_exit) && (!p_queue->no_empty)){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
158 b25_finish(dec, &sbuf, &dbuf); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
159 write(wfd, dbuf.data, dbuf.size); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
160 close(wfd); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
161 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
162 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
163 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
164 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
165 return NULL; |
0 | 166 } |
167 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
168 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
169 main(int argc, char **argv) |
0 | 170 { |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
171 int fd ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
172 int lp ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
173 int recsec ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
174 time_t start_time ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
175 time_t cur_time ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
176 FREQUENCY freq; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
177 ISDB_T_FREQ_CONV_TABLE *ptr ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
178 pthread_t dequeue_threads; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
179 QUEUE_T *p_queue = create_queue(MAX_QUEUE); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
180 BUFSZ *bufptr ; |
0 | 181 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
182 if(argc < 4){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
183 printf("Usage %s: channel recsec destfile\n", argv[0]); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
184 printf("channel =\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
185 printf("151ch:BS朝日\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
186 printf("161ch:BS-i\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
187 printf("171ch:BSジャパン\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
188 printf("211ch:BS11デジタル\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
189 printf("222ch:TwellV\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
190 printf("141ch:BS日テレ\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
191 printf("181ch:BSフジ\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
192 printf("101ch:NHK衛星第1放送(BS1)\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
193 printf("102ch:NHK衛星第2放送(BS2)\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
194 printf("103ch:NHKハイビジョン(BShi)\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
195 return 1; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
196 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
197 ptr = searchrecoff(argv[1]); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
198 if(ptr == NULL){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
199 printf("Channel Select Error(%s)\n", argv[1]); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
200 return 1 ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
201 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
202 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
203 freq.frequencyno = ptr->set_freq ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
204 freq.slot = ptr->add_freq ; |
0 | 205 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
206 if(ptr->type == CHTYPE_SATELLITE){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
207 for(lp = 0 ; lp < 2 ; lp++){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
208 fd = open(bsdev[lp], O_RDONLY); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
209 if(fd >= 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
210 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
211 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
212 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
213 if(fd < 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
214 printf("Device Open Error\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
215 return 1; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
216 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
217 }else{ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
218 for(lp = 0 ; lp < 2 ; lp++){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
219 fd = open(isdb_t_dev[lp], O_RDONLY); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
220 if(fd >= 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
221 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
222 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
223 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
224 if(fd < 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
225 printf("Device Open Error\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
226 return 1; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
227 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
228 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
229 recsec = atoi(argv[2]); |
0 | 230 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
231 /* initialize decoder */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
232 dec = b25_startup(); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
233 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
234 /* open output file */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
235 wfd = open64(argv[3], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
236 if(wfd < 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
237 printf("Output File Open Error(%s)\n", argv[3]); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
238 return 0; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
239 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
240 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
241 if(ioctl(fd, SET_CHANNEL, &freq) < 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
242 printf("Tuner Select Error\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
243 return 0 ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
244 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
245 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
246 /* make reading thread */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
247 pthread_create(&dequeue_threads, NULL, write_func, p_queue); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
248 if(ioctl(fd, START_REC, 0) < 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
249 printf("Tuner Start Error\n"); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
250 return 0 ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
251 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
252 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
253 time(&start_time); |
0 | 254 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
255 /* read-write loop */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
256 while(1){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
257 time(&cur_time); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
258 bufptr = calloc(1, sizeof(BUFSZ)); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
259 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
260 if(bufptr->size <= 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
261 if((cur_time - start_time) >= recsec){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
262 f_exit = TRUE ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
263 enqueue(p_queue, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
264 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
265 }else{ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
266 continue ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
267 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
268 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
269 enqueue(p_queue, bufptr); |
0 | 270 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
271 if((cur_time - start_time) >= recsec){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
272 ioctl(fd, STOP_REC, 0); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
273 //なくなるまでデータを読み出す |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
274 while(1){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
275 bufptr = calloc(1, sizeof(BUFSZ)); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
276 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
277 if(bufptr->size <= 0){ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
278 f_exit = TRUE ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
279 enqueue(p_queue, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
280 break ; |
0 | 281 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
282 enqueue(p_queue, bufptr); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
283 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
284 break ; |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
285 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
286 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
287 close(fd); /* close tuner */ |
0 | 288 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
289 /* wait reading thread */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
290 pthread_join(dequeue_threads, NULL); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
291 destroy_queue(p_queue); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
292 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
293 /* release decoder */ |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
294 b25_shutdown(dec); |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
295 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
296 return 0 ; |
0 | 297 } |