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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1 #include <stdio.h>
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
2 #include <fcntl.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
3 #include <sys/types.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
4 #include <sys/stat.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
5 #include <time.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
6 #include <stdlib.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
7 #include <string.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
8 #include <pthread.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
12 #include <sys/ioctl.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
13 #include "pt1_ioctl.h"
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
21 typedef struct thread_data {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
22 QUEUE_T *queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
23 decoder *decoder;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
24 int fd;
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
25 } thread_data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
31 int lp;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
34 // 文字列&長さ一致したら周波数テーブル番号を返却する
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
35 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
36 strlen(channel)) == 0) &&
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
47 QUEUE_T *p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
48 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
50 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char));
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
52 if(p_queue != NULL) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
53 p_queue->size = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
54 p_queue->no_full = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
55 p_queue->no_empty = 0;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
56 pthread_mutex_init(&p_queue->mutex, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
57 pthread_cond_init(&p_queue->cond_full, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
58 pthread_cond_init(&p_queue->cond_empty, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
59 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
61 return p_queue;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
80 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
81 /* entered critical section */
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
83 /* wait until queue is not full */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
84 while(!p_queue->no_full) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
87 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
89 p_queue->buffer[p_queue->in] = data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
91 p_queue->in++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
92 p_queue->in %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
94 p_queue->no_full--;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
95 p_queue->no_empty++;
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
96
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
97 /* leaving critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
98 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
99 pthread_cond_signal(&p_queue->cond_empty);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
106 BUFSZ *buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
108 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
109 /* entered the critical section*/
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
111 /* wait until queue is filled */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
112 while (!p_queue->no_empty) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
113 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
114 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
116 /* take buffer address */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
117 buffer = p_queue->buffer[p_queue->out];
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
119 // 次にデータを取り出す場所をインクリメント
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
120 p_queue->out++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
121 p_queue->out %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
123 /* update flags */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
124 p_queue->no_full++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
125 p_queue->no_empty--;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
127 /* leaving the critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
128 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
129 pthread_cond_signal(&p_queue->cond_full);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
131 return buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
138 thread_data *data = (thread_data *)p;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
139 QUEUE_T *p_queue = data->queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
146
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
147 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
148 buf = dequeue(p_queue);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
149 /* no entry in the queue */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
150 if(buf == NULL){
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
151 close(wfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
152 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
153 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
155 sbuf.data = buf->buffer;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
156 sbuf.size = buf->size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
172
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
184 close(wfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
185 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
186 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
187 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
189 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
201 pthread_t dequeue_threads;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
253 printf("channel =\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
254 printf("151ch:BS朝日\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
259 printf("211ch:BS11デジタル\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
260 printf("222ch:TwellV\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
261 printf("141ch:BS日テレ\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
262 printf("181ch:BSフジ\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
263 printf("101ch:NHK衛星第1放送(BS1)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
264 printf("102ch:NHK衛星第2放送(BS2)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
267 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
277
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
280 fd = open(bsdev[lp], O_RDONLY);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
281 if(fd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
282 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
283 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
284 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
287 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
288 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
291 fd = open(isdb_t_dev[lp], O_RDONLY);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
292 if(fd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
293 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
294 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
295 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
308 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
317 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
318
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
325 tdata.queue = p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
328 pthread_create(&dequeue_threads, NULL, write_func, &tdata);
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
329
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
330 /* start recording */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
334 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
335
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
336 time(&start_time);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
337
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
338 /* read from tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
339 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
340 time(&cur_time);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
341 bufptr = malloc(sizeof(BUFSZ));
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
342 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
343 if(bufptr->size <= 0) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
346 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
347 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
348 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
349 continue;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
350 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
351 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
352 enqueue(p_queue, bufptr);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
353
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
354 /* stop recording */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
355 if((cur_time - start_time) >= recsec) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
356 ioctl(fd, STOP_REC, 0);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
357 /* read remaining data */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
358 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
359 bufptr = malloc(sizeof(BUFSZ));
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
360 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
363 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
364 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
365 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
366 enqueue(p_queue, bufptr);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
367 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
368 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
369 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
370 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
371 /* close tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
372 close(fd);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
373
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
374 /* wait reading thread */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
375 pthread_join(dequeue_threads, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
376 destroy_queue(p_queue);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
377
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
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
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
384 }