annotate recpt1/recpt1.c @ 135:2b057f249811

imported bs_ch patch
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 25 Apr 2013 15:02:28 +0900
parents b14397800eae
children 61ff9cabf962
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
1 /* -*- tab-width: 4; indent-tabs-mode: nil -*- */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
2 #include <stdio.h>
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
3 #include <fcntl.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
4 #include <sys/types.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
5 #include <sys/stat.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
6 #include <time.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
7 #include <stdlib.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
8 #include <string.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
9 #include <pthread.h>
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
10 #include <math.h>
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
11 #include <unistd.h>
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
12 #include <getopt.h>
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
13 #include <signal.h>
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
14 #include <errno.h>
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
15 #include <sys/time.h>
47
edd904628e2f a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 43
diff changeset
16 #include <ctype.h>
61
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
17 #include <libgen.h>
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
19 #include <netdb.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
20 #include <arpa/inet.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
21 #include <netinet/in.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
22
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
23 #include <sys/ioctl.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
24 #include "pt1_ioctl.h"
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
26 #include "config.h"
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
27 #include "decoder.h"
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
28 #include "recpt1.h"
43
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
29 #include "version.h"
61
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
30 #include "mkpath.h"
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
31
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
32 #include <sys/ipc.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
33 #include <sys/msg.h>
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
34 #include "pt1_dev.h"
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
35 #include "tssplitter_lite.h"
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
36
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
37 /* maximum write length at once */
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
38 #define SIZE_CHANK 1316
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
39
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
40 /* ipc message size */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
41 #define MSGSZ 255
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42
135
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
43 #define ISDB_T_NODE_LIMIT 24 // 32:ARIB limit 24:program maximum
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
44 #define ISDB_T_SLOT_LIMIT 8
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
45
21
b63f5c100e5a made recpt1 link against b25 shared object.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 18
diff changeset
46 /* type definitions */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
47 typedef int boolean;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
48
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
49 typedef struct sock_data {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
50 int sfd; /* socket fd */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
51 struct sockaddr_in addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
52 } sock_data;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
53
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
54 typedef struct thread_data {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
55 QUEUE_T *queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
56 decoder *decoder;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
57 decoder_options *dopt;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
58 int ch;
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
59 int lnb; /* LNB voltage */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
60 int tfd; /* tuner fd */
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
61 int wfd; /* output file fd */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
62 ISDB_T_FREQ_CONV_TABLE *table;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
63 sock_data *sock_data;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
64 pthread_t signal_thread;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
65 int recsec;
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
66 time_t start_time;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
67 boolean indefinite;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
68 int msqid;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
69 splitter *splitter;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
70 } thread_data;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
71
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
72 typedef struct msgbuf {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
73 long mtype;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
74 char mtext[MSGSZ];
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
75 } message_buf;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
76
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
77 /* globals */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
78 boolean f_exit = FALSE;
135
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
79 char bs_channel_buf[8];
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
80 ISDB_T_FREQ_CONV_TABLE isdb_t_conv_set = { 0, CHTYPE_SATELLITE, 0, bs_channel_buf };
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
81
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
82 /* prototypes */
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
83 ISDB_T_FREQ_CONV_TABLE *searchrecoff(char *channel);
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
84 void calc_cn(int fd, int type);
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
85 int tune(char *channel, thread_data *tdata, char *device);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
86 int close_tuner(thread_data *tdata);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
87
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
88
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
89 /* ipc message receive */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
90 void *
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
91 mq_recv(void *t)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
92 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
93 thread_data *tdata = (thread_data *)t;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
94 message_buf rbuf;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
95 char channel[16];
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
96 int ch = 0, recsec = 0, time_to_add = 0;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
97
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
98 while(1) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
99 if(msgrcv(tdata->msqid, &rbuf, MSGSZ, 1, 0) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
100 return NULL;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
101 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
102
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
103 sscanf(rbuf.mtext, "ch=%s t=%d e=%d", channel, &recsec, &time_to_add);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
104 ch = atoi(channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
105 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
106
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
107 if(ch && tdata->ch != ch) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
108 #if 0
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
109 /* re-initialize decoder */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
110 if(tdata->decoder) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
111 // b25_finish(tdata->decoder);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
112 b25_shutdown(tdata->decoder);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
113 tdata->decoder = b25_startup(tdata->dopt);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
114 if(!tdata->decoder) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
115 fprintf(stderr, "Cannot start b25 decoder\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
116 fprintf(stderr, "Fall back to encrypted recording\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
117 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
118 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
119 #endif
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
120 int current_type = tdata->table->type;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
121 ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(channel);
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
122 if (table == NULL) {
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
123 fprintf(stderr, "Invalid Channel: %s\n", channel);
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
124 goto CHECK_TIME_TO_ADD;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
125 }
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
126 tdata->table = table;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
127
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
128 /* stop stream */
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
129 ioctl(tdata->tfd, STOP_REC, 0);
88
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
130
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
131 /* wait for remainder */
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
132 while(tdata->queue->num_used > 0) {
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
133 usleep(10000);
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
134 }
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
135
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
136 if (tdata->table->type != current_type) {
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
137 /* re-open device */
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
138 if(close_tuner(tdata) != 0)
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
139 return NULL;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
140
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
141 tune(channel, tdata, NULL);
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
142 } else {
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
143 /* SET_CHANNEL only */
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
144 const FREQUENCY freq = {
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
145 .frequencyno = tdata->table->set_freq,
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
146 .slot = tdata->table->add_freq,
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
147 };
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
148 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
149 fprintf(stderr, "Cannot tune to the specified channel\n");
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
150 tdata->ch = 0;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
151 goto CHECK_TIME_TO_ADD;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
152 }
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
153 tdata->ch = ch;
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
154 calc_cn(tdata->tfd, tdata->table->type);
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
155 }
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
156 /* restart recording */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
157 if(ioctl(tdata->tfd, START_REC, 0) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
158 fprintf(stderr, "Tuner cannot start recording\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
159 return NULL;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
160 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
161 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
162
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
163 CHECK_TIME_TO_ADD:
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
164 if(time_to_add) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
165 tdata->recsec += time_to_add;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
166 fprintf(stderr, "Extended %d sec\n", time_to_add);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
167 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
168
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
169 if(recsec) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
170 time_t cur_time;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
171 time(&cur_time);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
172 if(cur_time - tdata->start_time > recsec) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
173 f_exit = TRUE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
174 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
175 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
176 tdata->recsec = recsec;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
177 fprintf(stderr, "Total recording time = %d sec\n", recsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
178 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
179 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
180
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
181 if(f_exit)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
182 return NULL;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
183 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
184 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
185
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
187 /* lookup frequency conversion table*/
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
188 ISDB_T_FREQ_CONV_TABLE *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
189 searchrecoff(char *channel)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
191 int lp;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192
135
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
193 if(channel[0] == 'B' && channel[1] == 'S') {
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
194 int node = 0;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
195 int slot = 0;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
196 char *bs_ch;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
197
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
198 bs_ch = channel + 2;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
199 while(isdigit(*bs_ch)) {
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
200 node *= 10;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
201 node += *bs_ch++ - '0';
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
202 }
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
203 if(*bs_ch == '_' && (node&0x01) && node < ISDB_T_NODE_LIMIT) {
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
204 if(isdigit(*++bs_ch)) {
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
205 slot = *bs_ch - '0';
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
206 if(*++bs_ch == '\0' && slot < ISDB_T_SLOT_LIMIT) {
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
207 isdb_t_conv_set.set_freq = node / 2;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
208 isdb_t_conv_set.add_freq = slot;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
209 sprintf(bs_channel_buf, "BS%d_%d", node, slot);
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
210 return &isdb_t_conv_set;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
211 }
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
212 }
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
213 }
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
214 return NULL;
2b057f249811 imported bs_ch patch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 133
diff changeset
215 }
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
216 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) {
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
217 /* return entry number in the table when strings match and
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
218 * lengths are same. */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
219 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
220 strlen(channel)) == 0) &&
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
221 (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
222 return &isdb_t_conv_table[lp];
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
223 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
224 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
225 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
228 QUEUE_T *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
229 create_queue(size_t size)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
230 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
231 QUEUE_T *p_queue;
127
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
232 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ*);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
233
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
234 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char));
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
235
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
236 if(p_queue != NULL) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
237 p_queue->size = size;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
238 p_queue->num_avail = size;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
239 p_queue->num_used = 0;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
240 pthread_mutex_init(&p_queue->mutex, NULL);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
241 pthread_cond_init(&p_queue->cond_avail, NULL);
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
242 pthread_cond_init(&p_queue->cond_used, NULL);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
243 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
244
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
245 return p_queue;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
246 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
247
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
248 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
249 destroy_queue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
251 if(!p_queue)
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
252 return;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
253
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
254 pthread_mutex_destroy(&p_queue->mutex);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
255 pthread_cond_destroy(&p_queue->cond_avail);
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
256 pthread_cond_destroy(&p_queue->cond_used);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
257 free(p_queue);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
258 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
260 /* 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
261 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
262 enqueue(QUEUE_T *p_queue, BUFSZ *data)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
263 {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
264 struct timeval now;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
265 struct timespec spec;
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
266 int retry_count = 0;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
267
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
268 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
269 /* entered critical section */
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
270
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
271 /* wait while queue is full */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
272 while(p_queue->num_avail == 0) {
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
273
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
274 gettimeofday(&now, NULL);
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
275 spec.tv_sec = now.tv_sec + 1;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
276 spec.tv_nsec = now.tv_usec * 1000;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
277
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
278 pthread_cond_timedwait(&p_queue->cond_avail,
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
279 &p_queue->mutex, &spec);
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
280 retry_count++;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
281 if(retry_count > 60) {
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
282 f_exit = TRUE;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
283 }
25
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
284 if(f_exit) {
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
285 pthread_mutex_unlock(&p_queue->mutex);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
286 return;
25
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
287 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
288 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
289
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
290 p_queue->buffer[p_queue->in] = data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
291
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
292 /* move position marker for input to next position */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
293 p_queue->in++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
294 p_queue->in %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
295
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
296 /* update counters */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
297 p_queue->num_avail--;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
298 p_queue->num_used++;
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
299
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
300 /* leaving critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
301 pthread_mutex_unlock(&p_queue->mutex);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
302 pthread_cond_signal(&p_queue->cond_used);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
303 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
305 /* 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
306 BUFSZ *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
307 dequeue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
308 {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
309 struct timeval now;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
310 struct timespec spec;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
311 BUFSZ *buffer;
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
312 int retry_count = 0;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
313
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
314 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
315 /* entered the critical section*/
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
316
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
317 /* wait while queue is empty */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
318 while(p_queue->num_used == 0) {
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
319
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
320 gettimeofday(&now, NULL);
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
321 spec.tv_sec = now.tv_sec + 1;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
322 spec.tv_nsec = now.tv_usec * 1000;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
323
27
763cf84d2dc7 fixed a bug that waited for wrong cond variable
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 26
diff changeset
324 pthread_cond_timedwait(&p_queue->cond_used,
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
325 &p_queue->mutex, &spec);
125
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
326 retry_count++;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
327 if(retry_count > 60) {
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
328 f_exit = TRUE;
a910b49dfbee work in progress improvement:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 110
diff changeset
329 }
25
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
330 if(f_exit) {
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
331 pthread_mutex_unlock(&p_queue->mutex);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
332 return NULL;
25
011cb9337729 - avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 24
diff changeset
333 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
334 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
335
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
336 /* take buffer address */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
337 buffer = p_queue->buffer[p_queue->out];
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
338
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
339 /* move position marker for output to next position */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
340 p_queue->out++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
341 p_queue->out %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
342
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
343 /* update counters */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
344 p_queue->num_avail++;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
345 p_queue->num_used--;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
346
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
347 /* leaving the critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
348 pthread_mutex_unlock(&p_queue->mutex);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
349 pthread_cond_signal(&p_queue->cond_avail);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
350
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
351 return buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
352 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
353
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
354 /* this function will be reader thread */
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
355 void *
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
356 reader_func(void *p)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
357 {
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
358 thread_data *data = (thread_data *)p;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
359 QUEUE_T *p_queue = data->queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
360 decoder *dec = data->decoder;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
361 splitter *splitter = data->splitter;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
362 int wfd = data->wfd;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
363 boolean use_b25 = dec ? TRUE : FALSE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
364 boolean use_udp = data->sock_data ? TRUE : FALSE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
365 boolean fileless = FALSE;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
366 boolean use_splitter = splitter ? TRUE : FALSE;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
367 int sfd = -1;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
368 pthread_t signal_thread = data->signal_thread;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
369 struct sockaddr_in *addr = NULL;
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
370 BUFSZ *qbuf;
127
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
371 static splitbuf_t splitbuf;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
372 ARIB_STD_B25_BUFFER sbuf, dbuf, buf;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
373 int code;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
374 int split_select_finish = TSS_ERROR;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
375
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
376 buf.size = 0;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
377 buf.data = NULL;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
378 splitbuf.size = 0;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
379
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
380 if(wfd == -1)
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
381 fileless = TRUE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
382
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
383 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
384 sfd = data->sock_data->sfd;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
385 addr = &data->sock_data->addr;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
386 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
387
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
388 while(1) {
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
389 ssize_t wc = 0;
39
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
390 int file_err = 0;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
391 qbuf = dequeue(p_queue);
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
392 /* no entry in the queue */
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
393 if(qbuf == NULL) {
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
394 break;
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
395 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
396
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
397 sbuf.data = qbuf->buffer;
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
398 sbuf.size = qbuf->size;
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
399
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
400 buf = sbuf; /* default */
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
401
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
402 if(use_b25) {
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
403 code = b25_decode(dec, &sbuf, &dbuf);
85
28ba9315a30c falls back to encrypted recording when b25_decode fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 84
diff changeset
404 if(code < 0) {
103
387d18563ef8 temporary workaround: disable splitter if decoder is disabled.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 100
diff changeset
405 fprintf(stderr, "b25_decode failed (code=%d). fall back to encrypted recording.\n", code);
387d18563ef8 temporary workaround: disable splitter if decoder is disabled.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 100
diff changeset
406 use_b25 = FALSE;
85
28ba9315a30c falls back to encrypted recording when b25_decode fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 84
diff changeset
407 }
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
408 else
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
409 buf = dbuf;
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
410 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
411
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
412
104
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
413 if(use_splitter) {
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
414 splitbuf.size = 0;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
415
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
416 while(buf.size) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
417 /* $BJ,N%BP>](BPID$B$NCj=P(B */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
418 if(split_select_finish != TSS_SUCCESS) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
419 split_select_finish = split_select(splitter, &buf);
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
420 if(split_select_finish == TSS_NULL) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
421 /* malloc$B%(%i!<H/@8(B */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
422 fprintf(stderr, "split_select malloc failed\n");
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
423 use_splitter = FALSE;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
424 goto fin;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
425 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
426 else if(split_select_finish != TSS_SUCCESS) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
427 /* $BJ,N%BP>](BPID$B$,40A4$KCj=P$G$-$k$^$G=PNO$7$J$$(B
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
428 * 1$BICDxEYM>M5$r8+$k$H$$$$$+$b(B
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
429 */
110
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
430 time_t cur_time;
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
431 time(&cur_time);
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
432 if(cur_time - data->start_time > 4) {
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
433 use_splitter = FALSE;
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
434 goto fin;
d89f0da0a7e4 do not stuck on split_select() more than 4 sec.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 105
diff changeset
435 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
436 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
437 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
438 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
439 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
440 code = split_ts(splitter, &buf, &splitbuf);
127
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
441 if(code == TSS_NULL) {
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
442 fprintf(stderr, "PMT reading..\n");
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
443 }
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
444 else if(code != TSS_SUCCESS) {
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
445 fprintf(stderr, "split_ts failed\n");
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
446 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
447 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
448
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
449 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
450 } /* while */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
451
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
452 buf.size = splitbuf.size;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
453 buf.data = splitbuf.buffer;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
454 fin:
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
455 ;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
456 } /* if */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
457
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
458
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
459 if(!fileless) {
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
460 /* write data to output file */
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
461 int size_remain = buf.size;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
462 int offset = 0;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
463
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
464 while(size_remain > 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
465 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
466
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
467 wc = write(wfd, buf.data + offset, ws);
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
468 if(wc < 0) {
39
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
469 perror("write");
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
470 file_err = 1;
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
471 pthread_kill(signal_thread,
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
472 errno == EPIPE ? SIGPIPE : SIGUSR2);
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
473 break;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
474 }
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
475 size_remain -= wc;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
476 offset += wc;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
477 }
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
478 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
479
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
480 if(use_udp && sfd != -1) {
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
481 /* write data to socket */
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
482 int size_remain = buf.size;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
483 int offset = 0;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
484 while(size_remain > 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
485 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
486 wc = write(sfd, buf.data + offset, ws);
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
487 if(wc < 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
488 if(errno == EPIPE)
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
489 pthread_kill(signal_thread, SIGPIPE);
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
490 break;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
491 }
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
492 size_remain -= wc;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
493 offset += wc;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
494 }
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
495 }
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
496
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
497 free(qbuf);
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
498 qbuf = NULL;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
499
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
500 /* normal exit */
84
1b61fd7c6fde should just shutdown when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 81
diff changeset
501 if((f_exit && !p_queue->num_used) || file_err) {
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
502
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
503 buf = sbuf; /* default */
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
504
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
505 if(use_b25) {
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
506 code = b25_finish(dec, &sbuf, &dbuf);
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
507 if(code < 0)
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
508 fprintf(stderr, "b25_finish failed\n");
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
509 else
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
510 buf = dbuf;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
511 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
512
104
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
513 if(use_splitter) {
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
514 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
515 code = split_ts(splitter, &buf, &splitbuf);
127
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
516 if(code == TSS_NULL) {
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
517 split_select_finish = TSS_ERROR;
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
518 fprintf(stderr, "PMT reading..\n");
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
519 }
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
520 else if(code != TSS_SUCCESS) {
8e0f7191b92e Imported PID re-acquisition code by Toshiyuki Kawashima
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 125
diff changeset
521 fprintf(stderr, "split_ts failed\n");
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
522 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
523 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
524
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
525 buf.data = splitbuf.buffer;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
526 buf.size = splitbuf.size;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
527 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
528
84
1b61fd7c6fde should just shutdown when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 81
diff changeset
529 if(!fileless && !file_err) {
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
530 wc = write(wfd, buf.data, buf.size);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
531 if(wc < 0) {
39
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
532 perror("write");
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
533 file_err = 1;
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
534 pthread_kill(signal_thread,
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
535 errno == EPIPE ? SIGPIPE : SIGUSR2);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
536 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
537 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
538
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
539 if(use_udp && sfd != -1) {
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
540 wc = write(sfd, buf.data, buf.size);
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
541 if(wc < 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
542 if(errno == EPIPE)
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
543 pthread_kill(signal_thread, SIGPIPE);
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
544 }
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
545 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
546
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
547 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
548 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
549 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
550
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
551 time_t cur_time;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
552 time(&cur_time);
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
553 fprintf(stderr, "Recorded %dsec\n",
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
554 (int)(cur_time - data->start_time));
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
555
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
556 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
557 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
558
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
559 void
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
560 show_usage(char *cmd)
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
561 {
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
562 #ifdef HAVE_LIBARIB25
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 97
diff changeset
563 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] channel rectime destfile\n", cmd);
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
564 #else
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 97
diff changeset
565 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] channel rectime destfile\n", cmd);
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
566 #endif
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
567 fprintf(stderr, "\n");
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
568 fprintf(stderr, "Remarks:\n");
38
3228f5cde349 recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 35
diff changeset
569 fprintf(stderr, "if rectime is '-', records indefinitely.\n");
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
570 fprintf(stderr, "if destfile is '-', stdout is used for output.\n");
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
571 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
572
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
573 void
15
1b0883b02b4f fixed typo
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 14
diff changeset
574 show_options(void)
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
575 {
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
576 fprintf(stderr, "Options:\n");
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
577 #ifdef HAVE_LIBARIB25
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
578 fprintf(stderr, "--b25: Decrypt using BCAS card\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
579 fprintf(stderr, " --round N: Specify round number\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
580 fprintf(stderr, " --strip: Strip null stream\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
581 fprintf(stderr, " --EMM: Instruct EMM operation\n");
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
582 #endif
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
583 fprintf(stderr, "--udp: Turn on udp broadcasting\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
584 fprintf(stderr, " --addr hostname: Hostname or address to connect\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
585 fprintf(stderr, " --port portnumber: Port number to connect\n");
32
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
586 fprintf(stderr, "--device devicefile: Specify devicefile to use\n");
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
587 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n");
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 97
diff changeset
588 fprintf(stderr, "--sid SID1,SID2,...: Specify SID number in CSV format (101,102,...)\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
589 fprintf(stderr, "--help: Show this help\n");
43
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
590 fprintf(stderr, "--version: Show version\n");
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
591 fprintf(stderr, "--list: Show channel list\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
592 }
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
593
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
594 void
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
595 show_channels(void)
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
596 {
59
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
597 FILE *f;
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
598 char *home;
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
599 char buf[255], filename[255];
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
600
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
601 fprintf(stderr, "Available Channels:\n");
59
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
602
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
603 home = getenv("HOME");
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
604 sprintf(filename, "%s/.recpt1-channels", home);
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
605 f = fopen(filename, "r");
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
606 if(f) {
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
607 while(fgets(buf, 255, f))
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
608 fprintf(stderr, "%s", buf);
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
609 fclose(f);
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
610 }
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
611 else
67
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
612 fprintf(stderr, "13-62: Terrestrial Channels\n");
59
aeb885ed4e7e recpt1 shows list of terrestrial channels if .recpt1-channels is available in the home directory.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 57
diff changeset
613
67
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
614 fprintf(stderr, "101ch: NHK BS1\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
615 fprintf(stderr, "102ch: NHK BS2\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
616 fprintf(stderr, "103ch: NHK BShi\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
617 fprintf(stderr, "141ch: BS Nittele\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
618 fprintf(stderr, "151ch: BS Asahi\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
619 fprintf(stderr, "161ch: BS-TBS\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
620 fprintf(stderr, "171ch: BS Japan\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
621 fprintf(stderr, "181ch: BS Fuji\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
622 fprintf(stderr, "191ch: WOWOW\n");
87
0b00d22b0d1c accept wowow2/3 and BS-hi temporal channels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 85
diff changeset
623 fprintf(stderr, "192ch: WOWOW2\n");
0b00d22b0d1c accept wowow2/3 and BS-hi temporal channels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 85
diff changeset
624 fprintf(stderr, "193ch: WOWOW3\n");
67
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
625 fprintf(stderr, "200ch: Star Channel\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
626 fprintf(stderr, "211ch: BS11 Digital\n");
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
627 fprintf(stderr, "222ch: TwellV\n");
97
4d201756c593 - restore channel conversion table
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
628 fprintf(stderr, "C13-C63: CATV Channels\n");
67
18108d097707 replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 63
diff changeset
629 fprintf(stderr, "CS2-CS24: CS Channels\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
630 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
631
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
632 float
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
633 getsignal_isdb_s(int signal)
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
634 {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
635 /* apply linear interpolation */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
636 static const float afLevelTable[] = {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
637 24.07f, // 00 00 0 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
638 24.07f, // 10 00 4096 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
639 18.61f, // 20 00 8192 18.61dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
640 15.21f, // 30 00 12288 15.21dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
641 12.50f, // 40 00 16384 12.50dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
642 10.19f, // 50 00 20480 10.19dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
643 8.140f, // 60 00 24576 8.140dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
644 6.270f, // 70 00 28672 6.270dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
645 4.550f, // 80 00 32768 4.550dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
646 3.730f, // 88 00 34816 3.730dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
647 3.630f, // 88 FF 35071 3.630dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
648 2.940f, // 90 00 36864 2.940dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
649 1.420f, // A0 00 40960 1.420dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
650 0.000f // B0 00 45056 -0.01dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
651 };
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
652
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
653 unsigned char sigbuf[4];
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
654 memset(sigbuf, '\0', sizeof(sigbuf));
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
655 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
656 sigbuf[1] = (signal & 0xFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
657
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
658 /* calculate signal level */
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
659 if(sigbuf[0] <= 0x10U) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
660 /* clipped maximum */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
661 return 24.07f;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
662 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
663 else if (sigbuf[0] >= 0xB0U) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
664 /* clipped minimum */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
665 return 0.0f;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
666 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
667 else {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
668 /* linear interpolation */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
669 const float fMixRate =
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
670 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) |
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
671 (unsigned short)sigbuf[0]) / 4096.0f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
672 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) +
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
673 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
674 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
675 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
676
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
677 void
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
678 calc_cn(int fd, int type)
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
679 {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
680 int rc ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
681 double P ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
682 double CNR;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
683
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
684 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) {
62
c6a5c844c7fd make some messages go stderr instead of stdout.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 61
diff changeset
685 fprintf(stderr, "Tuner Select Error\n");
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
686 return ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
687 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
688
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
689 if(type == CHTYPE_GROUND) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
690 P = log10(5505024/(double)rc) * 10;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
691 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) +
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
692 (0.0398 * P * P) + (0.5491 * P)+3.0965;
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
693 fprintf(stderr, "C/N = %fdB\n", CNR);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
694 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
695 else {
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
696 CNR = getsignal_isdb_s(rc);
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
697 fprintf(stderr, "C/N = %fdB\n", CNR);
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
698 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
699 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
700
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
701 void
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
702 cleanup(thread_data *tdata)
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
703 {
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
704 /* stop recording */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
705 ioctl(tdata->tfd, STOP_REC, 0);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
706
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
707 /* xxx need mutex? */
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
708 f_exit = TRUE;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
709
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
710 pthread_cond_signal(&tdata->queue->cond_avail);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
711 pthread_cond_signal(&tdata->queue->cond_used);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
712 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
713
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
714 /* will be signal handler thread */
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
715 void *
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
716 process_signals(void *data)
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
717 {
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
718 sigset_t waitset;
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
719 int sig;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
720 thread_data *tdata = (thread_data *)data;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
721
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
722 sigemptyset(&waitset);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
723 sigaddset(&waitset, SIGPIPE);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
724 sigaddset(&waitset, SIGINT);
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
725 sigaddset(&waitset, SIGTERM);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
726 sigaddset(&waitset, SIGUSR1);
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
727 sigaddset(&waitset, SIGUSR2);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
728
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
729 sigwait(&waitset, &sig);
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
730
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
731 switch(sig) {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
732 case SIGPIPE:
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
733 fprintf(stderr, "\nSIGPIPE received. cleaning up...\n");
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
734 cleanup(tdata);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
735 break;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
736 case SIGINT:
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
737 fprintf(stderr, "\nSIGINT received. cleaning up...\n");
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
738 cleanup(tdata);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
739 break;
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
740 case SIGTERM:
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
741 fprintf(stderr, "\nSIGTERM received. cleaning up...\n");
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
742 cleanup(tdata);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
743 break;
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
744 case SIGUSR1: /* normal exit*/
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
745 cleanup(tdata);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
746 break;
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
747 case SIGUSR2: /* error */
39
b03685d25fee recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 38
diff changeset
748 fprintf(stderr, "Detected an error. cleaning up...\n");
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
749 cleanup(tdata);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
750 break;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
751 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
752
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
753 return NULL; /* dummy */
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
754 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
755
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
756 void
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
757 init_signal_handlers(pthread_t *signal_thread, thread_data *tdata)
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
758 {
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
759 sigset_t blockset;
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
760
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
761 sigemptyset(&blockset);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
762 sigaddset(&blockset, SIGPIPE);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
763 sigaddset(&blockset, SIGINT);
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
764 sigaddset(&blockset, SIGTERM);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
765 sigaddset(&blockset, SIGUSR1);
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
766 sigaddset(&blockset, SIGUSR2);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
767
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
768 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
769 fprintf(stderr, "pthread_sigmask() failed.\n");
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
770
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
771 pthread_create(signal_thread, NULL, process_signals, tdata);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
772 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
773
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
774 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
775 tune(char *channel, thread_data *tdata, char *device)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
776 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
777 char **tuner;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
778 int num_devs;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
779 int lp;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
780 FREQUENCY freq;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
781
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
782 /* get channel */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
783 tdata->table = searchrecoff(channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
784 if(tdata->table == NULL) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
785 fprintf(stderr, "Invalid Channel: %s\n", channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
786 return 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
787 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
788
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
789 freq.frequencyno = tdata->table->set_freq;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
790 freq.slot = tdata->table->add_freq;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
791
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
792 /* open tuner */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
793 /* case 1: specified tuner device */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
794 if(device) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
795 tdata->tfd = open(device, O_RDONLY);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
796 if(tdata->tfd < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
797 fprintf(stderr, "Cannot open tuner device: %s\n", device);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
798 return 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
799 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
800
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
801 /* power on LNB */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
802 if(tdata->table->type == CHTYPE_SATELLITE) {
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
803 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
804 fprintf(stderr, "Power on LNB failed: %s\n", device);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
805 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
806 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
807
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
808 /* tune to specified channel */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
809 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
810 close(tdata->tfd);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
811 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
812 return 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
813 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
814 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
815 tdata->ch = atoi(channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
816 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
817 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
818 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
819 /* case 2: loop around available devices */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
820 if(tdata->table->type == CHTYPE_SATELLITE) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
821 tuner = bsdev;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
822 num_devs = NUM_BSDEV;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
823 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
824 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
825 tuner = isdb_t_dev;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
826 num_devs = NUM_ISDB_T_DEV;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
827 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
828
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
829 for(lp = 0; lp < num_devs; lp++) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
830 tdata->tfd = open(tuner[lp], O_RDONLY);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
831 if(tdata->tfd >= 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
832 /* power on LNB */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
833 if(tdata->table->type == CHTYPE_SATELLITE) {
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
834 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
89
d74bcf2d255d do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 88
diff changeset
835 fprintf(stderr, "Warning: Power on LNB failed: %s\n", tuner[lp]);
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
836 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
837 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
838
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
839 /* tune to specified channel */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
840 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
841 close(tdata->tfd);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
842 tdata->tfd = -1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
843 continue;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
844 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
845
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
846 break; /* found suitable tuner */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
847 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
848 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
849
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
850 /* all tuners cannot be used */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
851 if(tdata->tfd < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
852 fprintf(stderr, "Cannot tune to the specified channel\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
853 return 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
854 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
855 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
856 tdata->ch = atoi(channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
857 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
858 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
859
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
860 /* show signal strength */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
861 calc_cn(tdata->tfd, tdata->table->type);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
862
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
863 return 0; /* success */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
864 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
865
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
866 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
867 parse_time(char *rectimestr, thread_data *tdata)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
868 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
869 /* indefinite */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
870 if(!strcmp("-", rectimestr)) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
871 tdata->indefinite = TRUE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
872 tdata->recsec = -1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
873 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
874 /* colon */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
875 else if(strchr(rectimestr, ':')) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
876 int n1, n2, n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
877 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
878 tdata->recsec = n1 * 3600 + n2 * 60 + n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
879 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
880 tdata->recsec = n1 * 3600 + n2 * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
881 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
882 /* HMS */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
883 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
884 char *tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
885 char *p1, *p2;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
886
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
887 tmpstr = strdup(rectimestr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
888 p1 = tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
889 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
890 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
891
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
892 /* hour */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
893 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
894 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
895 tdata->recsec += atoi(p1) * 3600;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
896 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
897 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
898 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
899 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
900
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
901 /* minute */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
902 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
903 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
904 tdata->recsec += atoi(p1) * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
905 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
906 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
907 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
908 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
909
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
910 /* second */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
911 tdata->recsec += atoi(p1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
912
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
913 free(tmpstr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
914 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
915
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
916 return 0; /* success */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
917 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
918
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
919 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
920 close_tuner(thread_data *tdata)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
921 {
89
d74bcf2d255d do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 88
diff changeset
922 int rv = 0;
d74bcf2d255d do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 88
diff changeset
923
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
924 if(tdata->table->type == CHTYPE_SATELLITE) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
925 if(ioctl(tdata->tfd, LNB_DISABLE, 0) < 0) {
89
d74bcf2d255d do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 88
diff changeset
926 rv = 1;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
927 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
928 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
929 close(tdata->tfd);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
930
89
d74bcf2d255d do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 88
diff changeset
931 return rv;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
932 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
933
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
934 int
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
935 main(int argc, char **argv)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
936 {
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
937 time_t cur_time;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
938 pthread_t signal_thread;
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
939 pthread_t reader_thread;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
940 pthread_t ipc_thread;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
941 QUEUE_T *p_queue = create_queue(MAX_QUEUE);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
942 BUFSZ *bufptr;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
943 decoder *dec = NULL;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
944 splitter *splitter = NULL;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
945 static thread_data tdata;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
946 decoder_options dopt = {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
947 4, /* round */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
948 0, /* strip */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
949 0 /* emm */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
950 };
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
951 tdata.dopt = &dopt;
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
952 tdata.lnb = 0;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
953
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
954 int result;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
955 int option_index;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
956 struct option long_options[] = {
74
b6607f6e2851 good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 67
diff changeset
957 #ifdef HAVE_LIBARIB25
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
958 { "b25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
959 { "B25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
960 { "round", 1, NULL, 'r'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
961 { "strip", 0, NULL, 's'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
962 { "emm", 0, NULL, 'm'},
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
963 { "EMM", 0, NULL, 'm'},
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
964 #endif
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
965 { "LNB", 1, NULL, 'n'},
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
966 { "lnb", 1, NULL, 'n'},
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
967 { "udp", 0, NULL, 'u'},
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
968 { "addr", 1, NULL, 'a'},
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
969 { "port", 1, NULL, 'p'},
32
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
970 { "device", 1, NULL, 'd'},
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
971 { "help", 0, NULL, 'h'},
43
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
972 { "version", 0, NULL, 'v'},
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
973 { "list", 0, NULL, 'l'},
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 97
diff changeset
974 { "sid", 1, NULL, 'i'},
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
975 {0, 0, NULL, 0} /* terminate */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
976 };
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
977
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
978 boolean use_b25 = FALSE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
979 boolean use_udp = FALSE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
980 boolean fileless = FALSE;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
981 boolean use_stdout = FALSE;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
982 boolean use_splitter = FALSE;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
983 char *host_to = NULL;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
984 int port_to = 1234;
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
985 sock_data *sockdata = NULL;
32
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
986 char *device = NULL;
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
987 int val;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
988 char *voltage[] = {"0V", "11V", "15V"};
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
989 char *sid_list = NULL;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
990
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 97
diff changeset
991 while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvli:",
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
992 long_options, &option_index)) != -1) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
993 switch(result) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
994 case 'b':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
995 use_b25 = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
996 fprintf(stderr, "using B25...\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
997 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
998 case 's':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
999 dopt.strip = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1000 fprintf(stderr, "enable B25 strip\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1001 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1002 case 'm':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1003 dopt.emm = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1004 fprintf(stderr, "enable B25 emm processing\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1005 break;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1006 case 'u':
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1007 use_udp = TRUE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1008 host_to = "localhost";
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1009 fprintf(stderr, "enable UDP broadcasting\n");
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1010 break;
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1011 case 'h':
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1012 fprintf(stderr, "\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1013 show_usage(argv[0]);
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1014 fprintf(stderr, "\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1015 show_options();
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1016 fprintf(stderr, "\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1017 show_channels();
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1018 fprintf(stderr, "\n");
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1019 exit(0);
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1020 break;
43
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
1021 case 'v':
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
1022 fprintf(stderr, "%s %s\n", argv[0], version);
91
2b55985bbb4c - adapt date format to driver's one
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 89
diff changeset
1023 fprintf(stderr, "recorder command for PT1/2 digital tuner.\n");
43
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
1024 exit(0);
9b36fdf7d5d0 show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 42
diff changeset
1025 break;
57
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1026 case 'l':
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1027 show_channels();
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1028 exit(0);
d3929562b8e7 - added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 49
diff changeset
1029 break;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1030 /* following options require argument */
81
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1031 case 'n':
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1032 val = atoi(optarg);
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1033 switch(val) {
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1034 case 11:
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1035 tdata.lnb = 1;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1036 break;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1037 case 15:
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1038 tdata.lnb = 2;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1039 break;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1040 default:
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1041 tdata.lnb = 0;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1042 break;
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1043 }
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1044 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]);
6e3bb2c0c5b6 add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 78
diff changeset
1045 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1046 case 'r':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1047 dopt.round = atoi(optarg);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1048 fprintf(stderr, "set round %d\n", dopt.round);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1049 break;
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1050 case 'a':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1051 use_udp = TRUE;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1052 host_to = optarg;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1053 fprintf(stderr, "UDP destination address: %s\n", host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1054 break;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1055 case 'p':
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1056 port_to = atoi(optarg);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1057 fprintf(stderr, "UDP port: %d\n", port_to);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1058 break;
32
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
1059 case 'd':
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
1060 device = optarg;
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
1061 fprintf(stderr, "using device: %s\n", device);
6004fe4f37f9 adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 28
diff changeset
1062 break;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1063 case 'i':
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1064 use_splitter = TRUE;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1065 sid_list = optarg;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1066 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1067 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1068 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1069
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1070 if(argc - optind < 3) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1071 if(argc - optind == 2 && use_udp) {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1072 fprintf(stderr, "Fileless UDP broadcasting\n");
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1073 fileless = TRUE;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1074 tdata.wfd = -1;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1075 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1076 else {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1077 fprintf(stderr, "Arguments are necessary!\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
1078 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1079 return 1;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1080 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1081 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
1082
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1083 fprintf(stderr, "pid = %d\n", getpid());
34
3f2487de156e should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 33
diff changeset
1084
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1085 /* tune */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1086 if(tune(argv[optind], &tdata, device) != 0)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1087 return 1;
47
edd904628e2f a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 43
diff changeset
1088
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1089 /* set recsec */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1090 if(parse_time(argv[optind + 1], &tdata) != 0)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1091 return 1;
48
c8051f6da2ab now recpt1 accepts formats like 1:20:05 (hh:mm:ss) or 1:20 (hh:mm).
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 47
diff changeset
1092
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1093 /* open output file */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1094 char *destfile = argv[optind + 2];
38
3228f5cde349 recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 35
diff changeset
1095 if(destfile && !strcmp("-", destfile)) {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1096 use_stdout = TRUE;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1097 tdata.wfd = 1; /* stdout */
38
3228f5cde349 recpt1 now accepts 1[HhMmSs] as recording duration. formats like 1Hour or 1hour are also be accepted.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 35
diff changeset
1098 }
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1099 else {
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1100 if(!fileless) {
61
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
1101 int status;
63
ca419e61f7f2 fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 62
diff changeset
1102 char *path = strdup(argv[optind + 2]);
ca419e61f7f2 fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 62
diff changeset
1103 char *dir = dirname(path);
61
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
1104 status = mkpath(dir, 0777);
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
1105 if(status == -1)
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
1106 perror("mkpath");
63
ca419e61f7f2 fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 62
diff changeset
1107 free(path);
61
f1553492e8bb ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 59
diff changeset
1108
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1109 tdata.wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1110 if(tdata.wfd < 0) {
34
3f2487de156e should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 33
diff changeset
1111 fprintf(stderr, "Cannot open output file: %s\n",
33
f25820d90249 make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 32
diff changeset
1112 argv[optind + 2]);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1113 return 1;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1114 }
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1115 }
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1116 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1117
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1118 /* initialize decoder */
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1119 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1120 dec = b25_startup(&dopt);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1121 if(!dec) {
34
3f2487de156e should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 33
diff changeset
1122 fprintf(stderr, "Cannot start b25 decoder\n");
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1123 fprintf(stderr, "Fall back to encrypted recording\n");
103
387d18563ef8 temporary workaround: disable splitter if decoder is disabled.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 100
diff changeset
1124 use_b25 = FALSE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1125 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1126 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1127 /* initialize splitter */
103
387d18563ef8 temporary workaround: disable splitter if decoder is disabled.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 100
diff changeset
1128 if(use_splitter) {
104
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
1129 splitter = split_startup(sid_list);
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
1130 if(splitter->sid_list == NULL) {
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
1131 fprintf(stderr, "Cannot start TS splitter\n");
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 103
diff changeset
1132 return 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1133 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1134 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1135
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1136 /* initialize udp connection */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1137 if(use_udp) {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1138 sockdata = calloc(1, sizeof(sock_data));
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1139 struct in_addr ia;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1140 ia.s_addr = inet_addr(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1141 if(ia.s_addr == INADDR_NONE) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1142 struct hostent *hoste = gethostbyname(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1143 if(!hoste) {
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1144 perror("gethostbyname");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1145 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1146 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1147 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1148 }
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1149 if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1150 perror("socket");
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1151 return 1;
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1152 }
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1153
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1154 sockdata->addr.sin_family = AF_INET;
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1155 sockdata->addr.sin_port = htons (port_to);
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1156 sockdata->addr.sin_addr.s_addr = ia.s_addr;
28
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1157
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1158 if(connect(sockdata->sfd, (struct sockaddr *)&sockdata->addr,
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1159 sizeof(sockdata->addr)) < 0) {
97c820e30737 limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27
diff changeset
1160 perror("connect");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1161 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1162 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1163 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1164
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1165 /* prepare thread data */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1166 tdata.queue = p_queue;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1167 tdata.decoder = dec;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1168 tdata.splitter = splitter;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1169 tdata.sock_data = sockdata;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1170
33
f25820d90249 make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 32
diff changeset
1171 /* spawn signal handler thread */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1172 init_signal_handlers(&signal_thread, &tdata);
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1173
33
f25820d90249 make recpt1 try other tuner devices when it fails to tune a tuner to the specified channel.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 32
diff changeset
1174 /* spawn reader thread */
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1175 tdata.signal_thread = signal_thread;
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1176 pthread_create(&reader_thread, NULL, reader_func, &tdata);
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
1177
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1178 /* spawn ipc thread */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1179 key_t key;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1180 key = (key_t)getpid();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1181
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1182 if ((tdata.msqid = msgget(key, IPC_CREAT | 0666)) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1183 perror("msgget");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1184 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1185 pthread_create(&ipc_thread, NULL, mq_recv, &tdata);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1186
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1187 /* start recording */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1188 if(ioctl(tdata.tfd, START_REC, 0) < 0) {
34
3f2487de156e should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 33
diff changeset
1189 fprintf(stderr, "Tuner cannot start recording\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1190 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1191 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1192
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1193 fprintf(stderr, "Recording...\n");
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1194
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1195 time(&tdata.start_time);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1196
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1197 /* read from tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1198 while(1) {
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1199 if(f_exit)
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1200 break;
26
c6264c15f39d simplify reader_func()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 25
diff changeset
1201
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1202 time(&cur_time);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1203 bufptr = malloc(sizeof(BUFSZ));
88
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1204 if(!bufptr) {
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1205 f_exit = TRUE;
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1206 break;
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1207 }
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1208 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1209 if(bufptr->size <= 0) {
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1210 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1211 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1212 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1213 break;
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1214 }
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1215 else {
133
b14397800eae imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 127
diff changeset
1216 free(bufptr);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1217 continue;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1218 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1219 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1220 enqueue(p_queue, bufptr);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1221
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1222 /* stop recording */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1223 time(&cur_time);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1224 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1225 ioctl(tdata.tfd, STOP_REC, 0);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1226 /* read remaining data */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1227 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1228 bufptr = malloc(sizeof(BUFSZ));
88
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1229 if(!bufptr) {
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1230 f_exit = TRUE;
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1231 break;
59065b569eec improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 87
diff changeset
1232 }
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1233 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1234 if(bufptr->size <= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1235 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1236 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1237 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1238 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1239 enqueue(p_queue, bufptr);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1240 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1241 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1242 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1243 }
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1244
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1245 /* delete message queue*/
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1246 msgctl(tdata.msqid, IPC_RMID, NULL);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1247
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1248 pthread_kill(signal_thread, SIGUSR1);
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1249
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1250 /* wait for threads */
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1251 pthread_join(reader_thread, NULL);
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1252 pthread_join(signal_thread, NULL);
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1253 pthread_join(ipc_thread, NULL);
24
f2cce7becf52 fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 21
diff changeset
1254
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1255 /* close tuner */
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1256 if(close_tuner(&tdata) != 0)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1257 return 1;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1258
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1259 /* release queue */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1260 destroy_queue(p_queue);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1261
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1262 /* close output file */
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1263 if(!use_stdout)
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 74
diff changeset
1264 close(tdata.wfd);
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1265
16
ecb85bde67b1 added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 15
diff changeset
1266 /* free socket data */
18
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1267 if(use_udp) {
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1268 close(sockdata->sfd);
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1269 free(sockdata);
84ff6ef710ea - support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 17
diff changeset
1270 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
1271
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
1272 /* release decoder */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1273 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1274 b25_shutdown(dec);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1275 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1276 if(use_splitter) {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1277 split_shutdown(splitter);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 91
diff changeset
1278 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
1279
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
1280 return 0;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1281 }