annotate recpt1/recpt1.c @ 7:407af34cfbd9

now falls back to encrypted recording when b25 decoder is not available
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 17 Feb 2009 11:52:26 +0900
parents d898fd27547f
children 6da603afd363
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
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
27 /* lookup frequency conversion table*/
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++){
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
34 /* return entry number in the table when strings match and
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
35 * lengths are same. */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
36 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
37 strlen(channel)) == 0) &&
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
38 (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
39 return &isdb_t_conv_table[lp];
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
40 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
41 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
42 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
45 QUEUE_T *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
46 create_queue(size_t size)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
48 QUEUE_T *p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
49 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
51 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char));
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
53 if(p_queue != NULL) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
54 p_queue->size = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
55 p_queue->no_full = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
56 p_queue->no_empty = 0;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
57 pthread_mutex_init(&p_queue->mutex, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
58 pthread_cond_init(&p_queue->cond_full, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
59 pthread_cond_init(&p_queue->cond_empty, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
60 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
62 return p_queue;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
65 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
66 destroy_queue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
68 if(!p_queue)
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
69 return;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
70
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
71 pthread_mutex_destroy(&p_queue->mutex);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
72 pthread_cond_destroy(&p_queue->cond_full);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
73 pthread_cond_destroy(&p_queue->cond_empty);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
74 free(p_queue);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
77 /* 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
78 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
79 enqueue(QUEUE_T *p_queue, BUFSZ *data)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
81 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
82 /* entered critical section */
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
84 /* wait until queue is not full */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
85 while(!p_queue->no_full) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
86 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
87 fprintf(stderr, "Full\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
88 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
90 p_queue->buffer[p_queue->in] = data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
92 p_queue->in++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
93 p_queue->in %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
95 p_queue->no_full--;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
96 p_queue->no_empty++;
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
97
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
98 /* leaving critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
99 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
100 pthread_cond_signal(&p_queue->cond_empty);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
103 /* 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
104 BUFSZ *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
105 dequeue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
107 BUFSZ *buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
109 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
110 /* entered the critical section*/
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
112 /* wait until queue is filled */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
113 while (!p_queue->no_empty) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
114 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
115 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
117 /* take buffer address */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
118 buffer = p_queue->buffer[p_queue->out];
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
120 /* move location marker to next position */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
121 p_queue->out++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
122 p_queue->out %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
124 /* update flags */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
125 p_queue->no_full++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
126 p_queue->no_empty--;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
128 /* leaving the critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
129 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
130 pthread_cond_signal(&p_queue->cond_full);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
132 return buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
135 /* this function will be reader thread */
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
136 void *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
137 write_func(void *p)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
139 thread_data *data = (thread_data *)p;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
140 QUEUE_T *p_queue = data->queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
141 decoder *dec = data->decoder;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
142 int wfd = data->fd;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
143 int use_b25 = dec ? 1 : 0;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
144 BUFSZ *buf;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
145 ARIB_STD_B25_BUFFER sbuf, dbuf;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
146 int code;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
147
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
148 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
149 buf = dequeue(p_queue);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
150 /* no entry in the queue */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
151 if(buf == NULL){
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
152 close(wfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
153 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
154 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
156 sbuf.data = buf->buffer;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
157 sbuf.size = buf->size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
158
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
159 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
160 /* write data to output file*/
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
161 code = b25_decode(dec, &sbuf, &dbuf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
162 if(code < 0) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
163 fprintf(stderr, "b25_decode failed\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
164 close(wfd);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
165 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
166 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
167 write(wfd, dbuf.data, dbuf.size);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
168 free(buf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
169 } else {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
170 write(wfd, sbuf.data, sbuf.size);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
171 free(buf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
172 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
173
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
174 /* normal exit */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
175 if((f_exit) && (!p_queue->no_empty)) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
176 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
177 code = b25_finish(dec, &sbuf, &dbuf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
178 if(code < 0) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
179 fprintf(stderr, "b25_finish failed\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
180 close(wfd);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
181 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
182 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
183 write(wfd, dbuf.data, dbuf.size);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
184 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
185 close(wfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
186 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
187 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
188 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
190 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
193 int
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
194 main(int argc, char **argv)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
196 int fd, wfd;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
197 int lp;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
198 int recsec;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
199 time_t start_time, cur_time;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
200 FREQUENCY freq;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
201 ISDB_T_FREQ_CONV_TABLE *ptr;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
202 pthread_t dequeue_threads;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
203 QUEUE_T *p_queue = create_queue(MAX_QUEUE);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
204 BUFSZ *bufptr;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
205 decoder *dec = NULL;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
206 thread_data tdata;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
207 decoder_options dopt;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
209 int use_b25 = 0;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
210 int result;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
211 int option_index;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
212 struct option long_options[] = {
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 { "B25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
215 { "round", 1, NULL, 'r'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
216 { "strip", 0, NULL, 's'},
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 { "EMM", 0, NULL, 'm'}
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
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
221 dopt.round = 4;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
222 dopt.strip = 0;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
223 dopt.emm = 0;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
224
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
225 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
226 switch(result) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
227 case 'b':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
228 use_b25 = 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
229 fprintf(stderr, "using B25...\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
230 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
231 case 's':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
232 dopt.strip = 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
233 fprintf(stderr, "enable B25 strip\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
234 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
235 case 'm':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
236 dopt.emm = 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
237 fprintf(stderr, "enable B25 emm processing\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
238 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
239 case 'r':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
240 dopt.round = atoi(optarg);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
241 fprintf(stderr, "set round %d\n", dopt.round);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
242 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
243 case ':':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
244 fprintf(stderr, "%c needs value\n", result);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
245 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
246 case '?':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
247 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
248 break;
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
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
252 if(argc - optind < 3) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
253 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
254 printf("channel =\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
255 printf("151ch¡§BSÄ«Æü\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
256 printf("161ch¡§BS-i\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
257 printf("191ch¡§WOWOW\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
258 printf("171ch¡§BS¥¸¥ã¥Ñ¥ó\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
259 printf("200ch¡§¥¹¥¿¡¼¥Á¥ã¥ó¥Í¥ë\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
260 printf("211ch¡§BS11¥Ç¥¸¥¿¥ë\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
261 printf("222ch¡§TwellV\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
262 printf("141ch¡§BSÆü¥Æ¥ì\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
263 printf("181ch¡§BS¥Õ¥¸\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
264 printf("101ch¡§NHK±ÒÀ±Âè1ÊüÁ÷(BS1)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
265 printf("102ch¡§NHK±ÒÀ±Âè2ÊüÁ÷(BS2)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
266 printf("103ch¡§NHK¥Ï¥¤¥Ó¥¸¥ç¥ó(BShi)\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
267 printf("CS2-CS24¡§CS¥Á¥ã¥ó¥Í¥ë\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
268 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
269 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
270 ptr = searchrecoff(argv[optind]);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
271 if(ptr == NULL){
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
272 printf("Channel Select Error(%s)\n", argv[optind]);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
273 return 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
274 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
275
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
276 freq.frequencyno = ptr->set_freq;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
277 freq.slot = ptr->add_freq;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
278
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
279 if(ptr->type == CHTYPE_SATELLITE) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
280 for(lp = 0; lp < 2; lp++) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
281 fd = open(bsdev[lp], O_RDONLY);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
282 if(fd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
283 break;
4
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 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
286 if(fd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
287 fprintf(stderr, "Device Open Error\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
288 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
289 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
290 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
291 for(lp = 0; lp < 2; lp++) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
292 fd = open(isdb_t_dev[lp], O_RDONLY);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
293 if(fd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
294 break;
4
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 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
297 if(fd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
298 fprintf(stderr, "Device Open Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
299 return 1;
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 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
302 recsec = atoi(argv[optind + 1]);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
303
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
304 /* initialize decoder */
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
305 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
306 dec = b25_startup(&dopt);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
307 if(!dec) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
308 fprintf(stderr, "cannot start b25 decoder\n");
7
407af34cfbd9 now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 6
diff changeset
309 fprintf(stderr, "fall back to encrypted recording\n");
407af34cfbd9 now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 6
diff changeset
310 use_b25 = 0;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
311 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
312 }
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
313
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
314 /* open output file */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
315 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
316 if(wfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
317 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
318 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
319 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
320
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
321 if(ioctl(fd, SET_CHANNEL, &freq) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
322 fprintf(stderr, "Tuner Select Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
323 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
324 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
325
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
326 /* make reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
327 tdata.queue = p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
328 tdata.decoder = dec;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
329 tdata.fd = wfd;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
330 pthread_create(&dequeue_threads, NULL, write_func, &tdata);
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
331
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
332 /* start recording */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
333 if(ioctl(fd, START_REC, 0) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
334 fprintf(stderr, "Tuner Start Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
335 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
336 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
337
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
338 time(&start_time);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
339
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
340 /* read from tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
341 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
342 time(&cur_time);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
343 bufptr = malloc(sizeof(BUFSZ));
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
344 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
345 if(bufptr->size <= 0) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
346 if((cur_time - start_time) >= recsec) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
347 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
348 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
349 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
350 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
351 continue;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
352 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
353 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
354 enqueue(p_queue, bufptr);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
355
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
356 /* stop recording */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
357 if((cur_time - start_time) >= recsec) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
358 ioctl(fd, STOP_REC, 0);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
359 /* read remaining data */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
360 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
361 bufptr = malloc(sizeof(BUFSZ));
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
362 bufptr->size = read(fd, bufptr->buffer, MAX_READ_SIZE);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
363 if(bufptr->size <= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
364 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
365 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
366 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
367 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
368 enqueue(p_queue, bufptr);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
369 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
370 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
371 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
372 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
373 /* close tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
374 close(fd);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
375
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
376 /* wait reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
377 pthread_join(dequeue_threads, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
378 destroy_queue(p_queue);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
379
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
380 /* release decoder */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
381 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
382 b25_shutdown(dec);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
383 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
384
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
385 return 0;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
386 }