Mercurial > pt1.oyama
annotate src/recpt1.c @ 128:3a7d8d2f0585
modify configure for -lrt
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Tue, 05 Oct 2010 01:55:54 +0900 |
parents | 5a380559a61e |
children | 0db6ccf0fe31 |
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 -*- */ |
122 | 2 /* vim: set ts=4 sts=4 sw=4 expandtab number : */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
3 #include <stdio.h> |
3 | 4 #include <fcntl.h> |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <time.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <pthread.h> | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
11 #include <math.h> |
3 | 12 #include <unistd.h> |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
13 #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
|
14 #include <signal.h> |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
15 #include <errno.h> |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
16 #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
|
17 #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
|
18 #include <libgen.h> |
0 | 19 |
8 | 20 #include <netdb.h> |
21 #include <arpa/inet.h> | |
22 #include <netinet/in.h> | |
23 | |
3 | 24 #include <sys/ioctl.h> |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
25 #include <pt1_ioctl.h> |
0 | 26 |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
27 #include "config.h" |
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
28 #include "decoder.h" |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
29 #include "recpt1.h" |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
30 #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
|
31 #include "mkpath.h" |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
32 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
33 #include <sys/ipc.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
34 #include <sys/msg.h> |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
35 #include "pt1_dev.h" |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
36 #include "tssplitter_lite.h" |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
37 #include "ushare.h" |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
38 #include "trace.h" |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
39 |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
40 /* 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
|
41 #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
|
42 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
43 /* ipc message size */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
44 #define MSGSZ 255 |
0 | 45 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
46 typedef struct pt1_msgbuf { |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
47 long mtype; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
48 char mtext[MSGSZ]; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
49 } pt1_message_buf; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
50 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
51 /* globals */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
52 boolean f_exit = FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
53 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
54 /* prototypes */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
55 int tune(char *channel, thread_data *tdata, char *device); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
56 int close_tuner(thread_data *tdata); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
57 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
58 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
59 /* ipc message receive */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
60 void * |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
61 mq_recv(void *t) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
62 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
63 thread_data *tdata = (thread_data *)t; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
64 pt1_message_buf rbuf; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
65 char channel[16]; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
66 int ch = 0, recsec = 0, time_to_add = 0; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
67 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
68 while(1) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
69 if(msgrcv(tdata->msqid, &rbuf, MSGSZ, 1, 0) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
70 return NULL; |
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 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
73 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
|
74 ch = atoi(channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
75 // 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
|
76 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
77 if(ch && tdata->ch != ch) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
78 /* stop stream */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
79 ioctl(tdata->tfd, STOP_REC, 0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
80 #if 0 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
81 /* re-initialize decoder */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
82 if(tdata->decoder) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
83 // b25_finish(tdata->decoder); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
84 b25_shutdown(tdata->decoder); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
85 tdata->decoder = b25_startup(tdata->dopt); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
86 if(!tdata->decoder) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
87 fprintf(stderr, "Cannot start b25 decoder\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
88 fprintf(stderr, "Fall back to encrypted recording\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
89 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
90 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
91 #endif |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
92 /* tune to new channel */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
93 if(close_tuner(tdata) != 0) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
94 return NULL; |
88
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
95 |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
96 /* wait for remainder */ |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
97 while(tdata->queue->num_used > 0) { |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
98 usleep(10000); |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
99 } |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
100 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
101 tune(channel, tdata, NULL); |
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 /* restart recording */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
104 if(ioctl(tdata->tfd, START_REC, 0) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
105 fprintf(stderr, "Tuner cannot start recording\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
106 return NULL; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
107 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
108 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
109 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
110 if(time_to_add) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
111 tdata->recsec += time_to_add; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
112 fprintf(stderr, "Extended %d sec\n", time_to_add); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
113 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
114 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
115 if(recsec) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
116 time_t cur_time; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
117 time(&cur_time); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
118 if(cur_time - tdata->start_time > recsec) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
119 f_exit = TRUE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
120 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
121 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
122 tdata->recsec = recsec; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
123 fprintf(stderr, "Total recording time = %d sec\n", recsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
124 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
125 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
126 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
127 if(f_exit) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
128 return NULL; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
129 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
130 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
131 |
0 | 132 |
6 | 133 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
134 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
135 searchrecoff(char *channel) |
0 | 136 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
137 int lp; |
0 | 138 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
139 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) { |
6 | 140 /* return entry number in the table when strings match and |
141 * lengths are same. */ | |
4 | 142 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
143 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
|
144 (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
|
145 return &isdb_t_conv_table[lp]; |
4 | 146 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
147 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
148 return NULL; |
0 | 149 } |
150 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
151 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
152 create_queue(size_t size) |
0 | 153 { |
4 | 154 QUEUE_T *p_queue; |
8 | 155 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 156 |
4 | 157 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 158 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
159 if(p_queue != NULL) { |
4 | 160 p_queue->size = size; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
161 p_queue->num_avail = size; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
162 p_queue->num_used = 0; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
163 p_queue->in = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
164 p_queue->out = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
165 pthread_mutex_init(&p_queue->mutex, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
166 pthread_cond_init(&p_queue->cond_avail, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
167 pthread_cond_init(&p_queue->cond_used, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
168 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
169 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
170 return p_queue; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
171 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
172 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
173 STREAM_QUEUE_T * |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
174 create_stream_queue(size_t size) |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
175 { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
176 STREAM_QUEUE_T *p_queue; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
177 int memsize = sizeof(STREAM_QUEUE_T) + size * sizeof(ARIB_STD_B25_BUFFER); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
178 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
179 p_queue = (STREAM_QUEUE_T*)calloc(memsize, sizeof(char)); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
180 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
181 if(p_queue != NULL) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
182 p_queue->size = size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
183 p_queue->num_avail = size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
184 p_queue->num_used = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
185 p_queue->in = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
186 p_queue->out = 0; |
4 | 187 pthread_mutex_init(&p_queue->mutex, NULL); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
188 pthread_cond_init(&p_queue->cond_avail, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
189 pthread_cond_init(&p_queue->cond_used, NULL); |
4 | 190 } |
0 | 191 |
4 | 192 return p_queue; |
0 | 193 } |
194 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
195 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
196 destroy_queue(QUEUE_T *p_queue) |
0 | 197 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
198 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
199 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
200 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
201 pthread_mutex_destroy(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
202 pthread_cond_destroy(&p_queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
203 pthread_cond_destroy(&p_queue->cond_used); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
204 free(p_queue); |
0 | 205 } |
206 | |
125
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
207 void |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
208 destroy_stream_queue(STREAM_QUEUE_T *p_queue) |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
209 { |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
210 if(!p_queue) |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
211 return; |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
212 |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
213 pthread_mutex_destroy(&p_queue->mutex); |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
214 pthread_cond_destroy(&p_queue->cond_avail); |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
215 pthread_cond_destroy(&p_queue->cond_used); |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
216 free(p_queue); |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
217 } |
e413158cae13
Add ushare project files.
naoyan@johnstown.minaminoshima.org
parents:
124
diff
changeset
|
218 |
3 | 219 /* 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
|
220 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
221 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 222 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
223 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
224 struct timespec spec; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
225 //fprintf (stderr, "enqueue() start.\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
226 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
227 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
228 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
229 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
230 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
231 //fprintf (stderr, "enqueue() mutex lock try. num_used[%d] num_avail[%d]\n", p_queue->num_used, p_queue->num_avail); |
4 | 232 pthread_mutex_lock(&p_queue->mutex); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
233 //fprintf (stderr, "enqueue() mutex lock success. num_used[%d] num_avail[%d]\n", p_queue->num_used, p_queue->num_avail); |
4 | 234 /* entered critical section */ |
0 | 235 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
236 /* wait while queue is full */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
237 while(p_queue->num_avail == 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
238 pthread_cond_timedwait(&p_queue->cond_avail, |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
239 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
240 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
241 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
242 return; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
243 } |
4 | 244 } |
0 | 245 |
4 | 246 p_queue->buffer[p_queue->in] = data; |
0 | 247 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
248 /* move position marker for input to next position */ |
4 | 249 p_queue->in++; |
250 p_queue->in %= p_queue->size; | |
0 | 251 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
252 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
253 p_queue->num_avail--; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
254 p_queue->num_used++; |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
255 |
4 | 256 /* leaving critical section */ |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
257 //fprintf (stderr, "enqueue() mutex unlock. num_used[%d]\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
258 pthread_mutex_unlock(&p_queue->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
259 pthread_cond_signal(&p_queue->cond_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
260 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
261 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
262 /* |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
263 * stream_func()$B$N;HMQ$9$k(B enqueue() $B$O6u$-$,$J$$>l9g$K$O!"L58BBT$A$O$7$F$O$J$i$J$$!#(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
264 * $B6u$-$,$J$$>l9g$K$O!"(Bqueue$B$r=i4|2=$7$F$7$^$$!"C<Kv$X$NAw?.%G!<%?$r;E@Z$jD>$7$7$F$7$^$&J}$,%^%7!#(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
265 * $B$3$l$K$h$j!"C<Kv$X$NAw?.%G!<%?$O?tICJ,%9%-%C%W$9$k;v$K$J$k$,!"(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
266 * $B%P%C%U%!$OM-8B$G$"$j!"%9%H%j!<%`$G$"$k$N$G:F@8$5$lB3$1$k$3$H$rM%@h$9$k!#(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
267 */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
268 void |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
269 stream_enqueue(STREAM_QUEUE_T *p_queue, ARIB_STD_B25_BUFFER *data) |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
270 { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
271 struct timeval now; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
272 struct timespec spec; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
273 int i; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
274 //fprintf (stderr, "stream_enqueue() start.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
275 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
276 gettimeofday(&now, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
277 spec.tv_sec = now.tv_sec + 1; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
278 spec.tv_nsec = now.tv_usec * 1000; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
279 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
280 //fprintf (stderr, "stream_enqueue() mutex lock try. num_used[%d]\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
281 pthread_mutex_lock(&p_queue->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
282 //fprintf (stderr, "stream_enqueue() mutex lock success. num_used[%d]\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
283 /* entered critical section */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
284 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
285 if (p_queue->num_avail == 0) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
286 //fprintf (stderr, "stream_enqueue() num_used reach max[%d].\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
287 /* stream queue $B$O0lGU$K$J$C$?$i>C5n$7$F$7$^$&(B */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
288 for ( i=0; i < p_queue->size; i++ ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
289 if ( p_queue->buffer[i] != NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
290 free(p_queue->buffer[i]->data); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
291 p_queue->buffer[i]->data = NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
292 free(p_queue->buffer[i]); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
293 p_queue->buffer[i] = NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
294 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
295 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
296 p_queue->in = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
297 p_queue->out = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
298 p_queue->num_used = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
299 p_queue->num_avail = p_queue->size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
300 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
301 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
302 p_queue->buffer[p_queue->in] = data; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
303 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
304 /* move position marker for input to next position */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
305 p_queue->in++; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
306 p_queue->in %= p_queue->size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
307 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
308 /* update counters */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
309 p_queue->num_avail--; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
310 p_queue->num_used++; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
311 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
312 /* leaving critical section */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
313 //fprintf (stderr, "stream_enqueue() mutex unlock.\n"); |
4 | 314 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
315 pthread_cond_signal(&p_queue->cond_used); |
0 | 316 } |
317 | |
3 | 318 /* 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
|
319 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
320 dequeue(QUEUE_T *p_queue) |
0 | 321 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
322 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
323 struct timespec spec; |
8 | 324 BUFSZ *buffer; |
0 | 325 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
326 //fprintf (stderr, "dequeue() start.\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
327 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
328 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
329 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
330 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
331 //fprintf (stderr, "dequeue() mutex lock try. num_used[%d]\n", p_queue->num_used); |
4 | 332 pthread_mutex_lock(&p_queue->mutex); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
333 //fprintf (stderr, "dequeue() mutex lock success. num_used[%d]\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
334 /* entered the critical section*/ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
335 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
336 /* wait while queue is empty */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
337 while(p_queue->num_used == 0) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
338 pthread_cond_timedwait(&p_queue->cond_used, |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
339 &p_queue->mutex, &spec); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
340 if(f_exit) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
341 pthread_mutex_unlock(&p_queue->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
342 return NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
343 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
344 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
345 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
346 /* take buffer address */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
347 buffer = p_queue->buffer[p_queue->out]; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
348 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
349 /* move position marker for output to next position */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
350 p_queue->out++; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
351 p_queue->out %= p_queue->size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
352 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
353 /* update counters */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
354 p_queue->num_avail++; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
355 p_queue->num_used--; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
356 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
357 /* leaving the critical section */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
358 //fprintf (stderr, "dequeue() mutex unlock.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
359 pthread_mutex_unlock(&p_queue->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
360 pthread_cond_signal(&p_queue->cond_avail); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
361 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
362 return buffer; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
363 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
364 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
365 ARIB_STD_B25_BUFFER * |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
366 stream_dequeue(STREAM_QUEUE_T *p_queue) |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
367 { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
368 struct timeval now; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
369 struct timespec spec; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
370 ARIB_STD_B25_BUFFER *buffer; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
371 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
372 //fprintf (stderr, "stream_dequeue() start.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
373 gettimeofday(&now, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
374 spec.tv_sec = now.tv_sec + 1; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
375 spec.tv_nsec = now.tv_usec * 1000; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
376 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
377 //fprintf (stderr, "stream_dequeue() mutex lock try. num_used[%d]\n", p_queue->num_used); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
378 pthread_mutex_lock(&p_queue->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
379 //fprintf (stderr, "stream_dequeue() mutex lock success. num_used[%d]\n", p_queue->num_used); |
4 | 380 /* entered the critical section*/ |
0 | 381 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
382 /* wait while queue is empty */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
383 while(p_queue->num_used == 0) { |
27
763cf84d2dc7
fixed a bug that waited for wrong cond variable
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
26
diff
changeset
|
384 pthread_cond_timedwait(&p_queue->cond_used, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
385 &p_queue->mutex, &spec); |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
386 if(f_exit) { |
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
387 pthread_mutex_unlock(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
388 return NULL; |
25
011cb9337729
- avoid broken lock on exit
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
24
diff
changeset
|
389 } |
4 | 390 } |
0 | 391 |
4 | 392 /* take buffer address */ |
393 buffer = p_queue->buffer[p_queue->out]; | |
0 | 394 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
395 /* move position marker for output to next position */ |
4 | 396 p_queue->out++; |
397 p_queue->out %= p_queue->size; | |
0 | 398 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
399 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
400 p_queue->num_avail++; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
401 p_queue->num_used--; |
0 | 402 |
4 | 403 /* leaving the critical section */ |
404 pthread_mutex_unlock(&p_queue->mutex); | |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
405 //fprintf (stderr, "stream_dequeue() mutex unlock.\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
406 pthread_cond_signal(&p_queue->cond_avail); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
407 //fprintf (stderr, "dequeue() finish.\n"); |
0 | 408 |
4 | 409 return buffer; |
0 | 410 } |
411 | |
6 | 412 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
413 void * |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
414 reader_func(void *p) |
0 | 415 { |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
416 thread_data *data = (thread_data *)p; |
4 | 417 QUEUE_T *p_queue = data->queue; |
418 decoder *dec = data->decoder; | |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
419 splitter *splitter = data->splitter; |
8 | 420 int wfd = data->wfd; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
421 boolean use_b25 = dec ? TRUE : FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
422 boolean use_udp = data->sock_data ? TRUE : FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
423 boolean fileless = FALSE; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
424 boolean use_splitter = splitter ? TRUE : FALSE; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
425 boolean use_streaming = TRUE; // $BK\Ev$O0z?t$K$9$k$3$H(B |
13 | 426 int sfd = -1; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
427 pthread_t signal_thread = data->signal_thread; |
26 | 428 struct sockaddr_in *addr = NULL; |
429 BUFSZ *qbuf; | |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
430 ARIB_STD_B25_BUFFER *eqbuf; |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
431 splitbuf_t splitbuf; |
26 | 432 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
433 int code; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
434 int split_select_finish = TSS_ERROR; |
4 | 435 |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
436 buf.size = 0; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
437 buf.data = NULL; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
438 splitbuf.size = 0; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
439 |
13 | 440 if(wfd == -1) |
441 fileless = TRUE; | |
442 | |
8 | 443 if(use_udp) { |
444 sfd = data->sock_data->sfd; | |
26 | 445 addr = &data->sock_data->addr; |
8 | 446 } |
447 | |
4 | 448 while(1) { |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
449 // fprintf (stderr, "reader_func() while loop\n"); |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
450 ssize_t wc = 0; |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
451 int file_err = 0; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
452 //fprintf (stderr, "reader_func() dequeue() start.\n"); |
26 | 453 qbuf = dequeue(p_queue); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
454 //fprintf (stderr, "reader_func() dequeue() finish.\n"); |
26 | 455 /* no entry in the queue */ |
456 if(qbuf == NULL) { | |
457 break; | |
458 } | |
13 | 459 |
26 | 460 sbuf.data = qbuf->buffer; |
461 sbuf.size = qbuf->size; | |
462 | |
463 buf = sbuf; /* default */ | |
464 | |
465 if(use_b25) { | |
466 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
|
467 if(code < 0) { |
122 | 468 fprintf(stderr, "b25_decode failed (code=%d). fall back to encrypted recording.\n", code); |
469 use_b25 = FALSE; | |
85
28ba9315a30c
falls back to encrypted recording when b25_decode fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
84
diff
changeset
|
470 } |
26 | 471 else |
472 buf = dbuf; | |
473 } | |
13 | 474 |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
475 |
104
afd25d9ebef6
output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
103
diff
changeset
|
476 if(use_splitter) { |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
477 splitbuf.size = 0; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
478 |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
479 while(buf.size) { |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
480 /* $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
|
481 if(split_select_finish != TSS_SUCCESS) { |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
482 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
|
483 if(split_select_finish == TSS_NULL) { |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
484 /* malloc$B%(%i!<H/@8(B */ |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
485 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
|
486 use_splitter = FALSE; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
487 goto fin; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
488 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
489 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
|
490 /* $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
|
491 * 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
|
492 */ |
122 | 493 time_t cur_time; |
494 time(&cur_time); | |
495 if(cur_time - data->start_time > 4) { | |
496 use_splitter = FALSE; | |
497 goto fin; | |
498 } | |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
499 break; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
500 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
501 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
502 /* $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
|
503 code = split_ts(splitter, &buf, &splitbuf); |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
504 if(code != TSS_SUCCESS) { |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
505 fprintf(stderr, "split_ts failed\n"); |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
506 break; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
507 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
508 |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
509 break; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
510 } /* while */ |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
511 |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
512 buf.size = splitbuf.size; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
513 buf.data = splitbuf.buffer; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
514 fin: |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
515 ; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
516 } /* if */ |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
517 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
518 /* |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
519 * 2. reader_func$B2~B$E@(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
520 * 2.1 tdata->p_queue $B$+$i(B dequeue() $B$7$F%9%H%j!<%`$J%G!<%?$r<hF@$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
521 * 2.1.1 dequeue()$B$O(B tdata->p_queue->mutex $B$r(B lock/unlock $B$7$FFI$_9~$_;~$NF1;~99?7$rKI;_$7$F$$$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
522 * 2.2 tdata->stream_queue $B$K(B enqueue() $B$r<B9T$7$F(B http_stream $B$NBg85$H$9$k%G!<%?%P%C%U%!$N%3%T!<$r<B;\(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
523 * 2.2.1 http_stream$B$N%3%T!<85$H$9$k$?$a$N%P%C%U%!$r(Balloc$B$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
524 * 2.2.2 2.2.1$B$G(Balloc$B$7$?NN0h$K(B rader_func $B$,(B dequeue $B$7$?%9%H%j!<%`$J%G!<%?$r(Bmemcpy()$B$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
525 * 2.2.3 tdata->stream_queue $B$K(B 2.2.1 $B$N%]%$%s%?$r(B enqueue() $B$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
526 * 2.2.3.1 enqueue() $B$O(B tdata->stream_queue->mutex $B$r(B lock/unlock $B$7$F=q$-9~$_;~$NF1;~99?7$rKI;_$7$F$$$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
527 */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
528 //fprintf (stderr, "reader_func() buf.size[%d]\n", buf.size); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
529 if ( use_streaming && buf.size > 0 ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
530 do { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
531 eqbuf = malloc(sizeof(ARIB_STD_B25_BUFFER)); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
532 if ( eqbuf == NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
533 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
534 use_streaming = FALSE; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
535 break; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
536 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
537 eqbuf->data = malloc(buf.size); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
538 if ( eqbuf->data == NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
539 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
540 use_streaming = FALSE; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
541 break; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
542 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
543 eqbuf->size = buf.size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
544 memcpy(eqbuf->data, buf.data, buf.size); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
545 // $B$3$A$i$b0n$l$?$i>C5n$7$F$7$^$&(B stream_enqueue() $B$r;HMQ(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
546 stream_enqueue(data->stream_queue, eqbuf); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
547 } while(0); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
548 } |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
549 |
26 | 550 if(!fileless) { |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
551 /* 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
|
552 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
|
553 int offset = 0; |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
554 |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
555 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
|
556 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
|
557 |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
558 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
|
559 if(wc < 0) { |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
560 perror("write"); |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
561 file_err = 1; |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
562 pthread_kill(signal_thread, |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
563 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
|
564 break; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
565 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
566 size_remain -= wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
567 offset += wc; |
13 | 568 } |
26 | 569 } |
13 | 570 |
26 | 571 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
|
572 /* 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
|
573 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
|
574 int offset = 0; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 if(wc < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
579 if(errno == EPIPE) |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
580 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
|
581 break; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
582 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
583 size_remain -= wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
584 offset += wc; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
585 } |
26 | 586 } |
587 | |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
588 free(qbuf); |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
589 qbuf = NULL; |
26 | 590 |
591 /* normal exit */ | |
84
1b61fd7c6fde
should just shutdown when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
81
diff
changeset
|
592 if((f_exit && !p_queue->num_used) || file_err) { |
26 | 593 |
594 buf = sbuf; /* default */ | |
13 | 595 |
596 if(use_b25) { | |
26 | 597 code = b25_finish(dec, &sbuf, &dbuf); |
598 if(code < 0) | |
599 fprintf(stderr, "b25_finish failed\n"); | |
600 else | |
601 buf = dbuf; | |
13 | 602 } |
4 | 603 |
104
afd25d9ebef6
output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
103
diff
changeset
|
604 if(use_splitter) { |
99
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
605 /* $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
|
606 code = split_ts(splitter, &buf, &splitbuf); |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
607 if(code != TSS_SUCCESS) { |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
608 break; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
609 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
610 |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
611 buf.data = splitbuf.buffer; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
612 buf.size = splitbuf.size; |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
613 } |
3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
98
diff
changeset
|
614 |
84
1b61fd7c6fde
should just shutdown when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
81
diff
changeset
|
615 if(!fileless && !file_err) { |
26 | 616 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
|
617 if(wc < 0) { |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
618 perror("write"); |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
619 file_err = 1; |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
620 pthread_kill(signal_thread, |
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
621 errno == EPIPE ? SIGPIPE : SIGUSR2); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
622 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
623 } |
13 | 624 |
26 | 625 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
|
626 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
|
627 if(wc < 0) { |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
628 if(errno == EPIPE) |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
629 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
|
630 } |
26 | 631 } |
13 | 632 |
26 | 633 break; |
4 | 634 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
635 } |
0 | 636 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
637 time_t cur_time; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
638 time(&cur_time); |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
639 fprintf(stderr, "Recorded %dsec\n", |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
640 (int)(cur_time - data->start_time)); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
641 |
4 | 642 return NULL; |
0 | 643 } |
644 | |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
645 /* |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
646 * 3. stream_func() $B$O(B reader_func() $B$+$i%9%H%j!<%`8~$1$K%3%T!<$5$l$?%G!<%?$r!"%9%H%j!<%`%;%C%7%g%sKh$N(Bqueue$B$K%3%T!<$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
647 * 3.1 tdata->stream_queue $B$+$i(B dequeue $B$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
648 * 3.1.1 tdata->stream_queue->mutex $B$NFI$_9~$_;~$N(B lock/unlokc $B$,H/@8$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
649 * 3.2 tdata->streamer->mutex $B$r(B lock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
650 * 3.3 $B0J2<$r(B tdata->streamer->stream_nr $B$N?t$@$1%k!<%W(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
651 * 3.3.1 tdata->streamer->stream_session[N]->is_valid $B$,M-8z$+3NG'(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
652 * 3.3.2 tdata->streamer->stream_session[N]->p_queue $B$X$N%3%T!<MQ%P%C%U%!$N(Balloc |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
653 * 3.3.3 3.1$B$G(B dequeue $B$7$?%P%C%U%!$r(B3.3.2$B$G(B alloc $B$7$?%P%C%U%!$X(B memcpy() |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
654 * 3.3.4 tdata->streamer->stream_session[N]->p_queue $B$X(B enqueue() |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
655 * 3.3.4.1 tdata->streamer->stream_session[N]->p_queue->mutex $B$N(B lock/unlock $B$,H/@8(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
656 * 3.4 tdata->streamer->mutex $B$r(B unlock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
657 * stream_func()$B$N(B lock $B$9$k$b$N$H=g=x(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
658 * #1. tdata->stream_queue->mutex $B$N(Block/unlock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
659 * #2. tdata->streamer->mutex $B$r(B lock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
660 * #2.1 tdata->streamer->stream_session[N]->p_queue->mutex $B$N(B lock/unlock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
661 * #3. tdata->streamer->mutex $B$N(B unlock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
662 * $B>e5-$K4X$7$F!"(Block/unlock$B$,I,MW$JItJ,$H!"NN0h3NJ]$H%3%T!<$NCY$a$N=hM}$H$G(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
663 * $B@Z$jJ,$1$i$l$kItJ,$K$D$$$F$O@Z$jJ,$1$F$7$^$C$?$[$&$,$$$$$+$b!#(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
664 * $B%/%j%F%#%+%k%;%/%7%g%s$O!"%]%$%s%?A`:n$@$1$H$9$k$Y$-!#(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
665 */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
666 void * |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
667 stream_func(void *p) |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
668 { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
669 thread_data *data = (thread_data *)p; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
670 STREAM_QUEUE_T *p_queue = data->stream_queue; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
671 ARIB_STD_B25_BUFFER *qbuf = NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
672 ARIB_STD_B25_BUFFER *buf; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
673 int i; |
127
5a380559a61e
modify calclate bitrate mechanism.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
126
diff
changeset
|
674 clock_gettime(CLOCK_REALTIME, &data->streamer->start); |
5a380559a61e
modify calclate bitrate mechanism.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
126
diff
changeset
|
675 data->streamer->total_byte = 0; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
676 //fprintf (stderr, "stream_func(): start.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
677 |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
678 while(1) { |
126
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
679 if(f_exit) |
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
680 break; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
681 // 3.1 tdata->stream_queue $B$+$i(B dequeue $B$9$k(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
682 // dequeue $B$7$?%G!<%?$O(B ARIB_STD_B25_BUFFER |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
683 qbuf = stream_dequeue(p_queue); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
684 /* no entry in the queue */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
685 if(qbuf == NULL) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
686 //fprintf (stderr, "stream_func(): dequeue() return NULL pointer. streaming abort.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
687 continue; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
688 } |
127
5a380559a61e
modify calclate bitrate mechanism.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
126
diff
changeset
|
689 data->streamer->total_byte += qbuf->size; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
690 // $B%/%j%F%#%+%k%;%/%7%g%sD9$$$N$J$s$H$+$7$?$$$J$!!D(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
691 // ToDo: memcpy $B$H$+%/%j%F%#%+%k%;%/%7%g%s$N30$K=P$9(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
692 // 3.2 tdata->streamer->mutex $B$r(B lock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
693 //fprintf (stderr, "stream_func(): mutex lock try.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
694 pthread_mutex_lock(&data->streamer->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
695 //fprintf (stderr, "stream_func(): mutex lock success.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
696 // 3.3 $B0J2<$r(B tdata->streamer->stream_nr $B$N?t$@$1%k!<%W(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
697 for ( i=0; i < data->streamer->stream_nr; i++ ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
698 // 3.3.1 tdata->streamer->stream_session[N]->is_valid $B$,M-8z$+3NG'(B |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
699 if ( data->streamer->stream_session[i] != NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
700 if ( data->streamer->stream_session[i]->is_valid ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
701 // 3.3.2 tdata->streamer->stream_session[N]->p_queue $B$X$N%3%T!<MQ%P%C%U%!$N(Balloc |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
702 buf = malloc(sizeof(ARIB_STD_B25_BUFFER)); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
703 if ( buf == NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
704 pthread_mutex_unlock(&data->streamer->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
705 log_error ("stream_func(): alloc NULL pointer. streaming abort.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
706 return NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
707 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
708 buf->data = NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
709 buf->data = malloc(qbuf->size); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
710 if ( buf->data == NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
711 log_error ("Cannot malloc buf memory. streaming session_id[%d] abort.\n", i); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
712 pthread_mutex_unlock(&data->streamer->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
713 return NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
714 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
715 // 3.3.3 3.1$B$G(B dequeue $B$7$?%P%C%U%!$r(B3.3.2$B$G(B alloc $B$7$?%P%C%U%!$X(B memcpy() |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
716 memcpy(buf->data, qbuf->data, qbuf->size); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
717 buf->size = qbuf->size; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
718 // 3.3.4 tdata->streamer->stream_session[N]->p_queue $B$X(B enqueue() |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
719 stream_enqueue(data->streamer->stream_session[i]->p_queue, buf); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
720 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
721 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
722 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
723 // 3.4 tdata->streamer->mutex $B$r(B unlock |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
724 pthread_mutex_unlock(&data->streamer->mutex); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
725 free(qbuf->data); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
726 free(qbuf); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
727 //fprintf (stderr, "stream_func(): mutex unlock.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
728 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
729 return NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
730 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
731 |
8 | 732 void |
733 show_usage(char *cmd) | |
734 { | |
74
b6607f6e2851
good citizens never use gray code. wise people never watch TV.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
67
diff
changeset
|
735 #ifdef HAVE_LIBARIB25 |
122 | 736 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] 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
|
737 #else |
122 | 738 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] 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
|
739 #endif |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
740 fprintf(stderr, "\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
741 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
|
742 fprintf(stderr, "if rectime is '-', records indefinitely.\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
743 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); |
13 | 744 } |
745 | |
746 void | |
15 | 747 show_options(void) |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
748 { |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
749 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
|
750 #ifdef HAVE_LIBARIB25 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
751 fprintf(stderr, "--b25: Decrypt using BCAS card\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
752 fprintf(stderr, " --round N: Specify round number\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
753 fprintf(stderr, " --strip: Strip null stream\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
754 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
|
755 #endif |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
756 fprintf(stderr, "--udp: Turn on udp broadcasting\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
757 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
|
758 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
|
759 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
|
760 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
|
761 fprintf(stderr, "--sid SID1,SID2,...: Specify SID number in CSV format (101,102,...)\n"); |
121 | 762 fprintf(stderr, " --es filename: Specify ES out filename prefix\n"); |
122 | 763 fprintf(stderr, " --start_time YYYYMMDDHHMISS: Specify record start datetime\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
764 fprintf(stderr, "--help: Show this help\n"); |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
765 fprintf(stderr, "--version: Show version\n"); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
766 fprintf(stderr, "--list: Show channel list\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
767 } |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
768 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
769 void |
13 | 770 show_channels(void) |
771 { | |
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
|
772 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
|
773 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
|
774 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
|
775 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
776 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
|
777 |
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
|
778 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
|
779 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
|
780 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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 } |
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
|
786 else |
67
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
787 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
|
788 |
67
18108d097707
replaced full-width colon with half-width colon in channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
63
diff
changeset
|
789 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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 fprintf(stderr, "191ch: WOWOW\n"); |
87
0b00d22b0d1c
accept wowow2/3 and BS-hi temporal channels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
85
diff
changeset
|
798 fprintf(stderr, "192ch: WOWOW2\n"); |
0b00d22b0d1c
accept wowow2/3 and BS-hi temporal channels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
85
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 fprintf(stderr, "222ch: TwellV\n"); |
97
4d201756c593
- restore channel conversion table
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
96
diff
changeset
|
803 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
|
804 fprintf(stderr, "CS2-CS24: CS Channels\n"); |
8 | 805 } |
806 | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
807 float |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
808 getsignal_isdb_s(int signal) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
809 { |
13 | 810 /* apply linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
811 static const float afLevelTable[] = { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
812 24.07f, // 00 00 0 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
813 24.07f, // 10 00 4096 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
814 18.61f, // 20 00 8192 18.61dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
815 15.21f, // 30 00 12288 15.21dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
816 12.50f, // 40 00 16384 12.50dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
817 10.19f, // 50 00 20480 10.19dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
818 8.140f, // 60 00 24576 8.140dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
819 6.270f, // 70 00 28672 6.270dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
820 4.550f, // 80 00 32768 4.550dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
821 3.730f, // 88 00 34816 3.730dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
822 3.630f, // 88 FF 35071 3.630dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
823 2.940f, // 90 00 36864 2.940dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
824 1.420f, // A0 00 40960 1.420dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
825 0.000f // B0 00 45056 -0.01dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
826 }; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
827 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
828 unsigned char sigbuf[4]; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
829 memset(sigbuf, '\0', sizeof(sigbuf)); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
830 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
831 sigbuf[1] = (signal & 0xFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
832 |
13 | 833 /* 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
|
834 if(sigbuf[0] <= 0x10U) { |
13 | 835 /* clipped maximum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
836 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
|
837 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
838 else if (sigbuf[0] >= 0xB0U) { |
13 | 839 /* clipped minimum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
840 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
|
841 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
842 else { |
13 | 843 /* linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
844 const float fMixRate = |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
845 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
846 (unsigned short)sigbuf[0]) / 4096.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
847 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
848 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
849 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
850 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
851 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
852 void |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
853 calc_cn(int fd, int type) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
854 { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
855 int rc ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
856 double P ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
857 double CNR; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
858 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
859 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
|
860 fprintf(stderr, "Tuner Select Error\n"); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
861 return ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
862 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
863 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
864 if(type == CHTYPE_GROUND) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
865 P = log10(5505024/(double)rc) * 10; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
866 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
|
867 (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
|
868 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
|
869 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
870 else { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
871 CNR = getsignal_isdb_s(rc); |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
872 fprintf(stderr, "C/N = %fdB\n", CNR); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
873 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
874 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
875 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
876 void |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
877 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
|
878 { |
126
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
879 int use_dlna = TRUE; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
880 /* stop recording */ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
881 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
|
882 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
883 /* 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
|
884 f_exit = TRUE; |
126
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
885 if ( use_dlna ) { |
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
886 UPnPBreak(0); |
5dcaf3785ebe
fix process terminate problem.
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
887 } |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
888 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
889 pthread_cond_signal(&tdata->queue->cond_avail); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
890 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
|
891 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
892 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
893 /* 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
|
894 void * |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
895 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
|
896 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
897 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
|
898 int sig; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
899 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
|
900 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
901 sigemptyset(&waitset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
908 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
|
909 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
910 switch(sig) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
911 case SIGPIPE: |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
912 fprintf(stderr, "\nSIGPIPE received. cleaning up...\n"); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
913 cleanup(tdata); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
914 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
915 case SIGINT: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
916 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
917 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
|
918 break; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
919 case SIGTERM: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
920 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
921 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
|
922 break; |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
923 case SIGUSR1: /* normal exit*/ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
924 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
|
925 break; |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
926 case SIGUSR2: /* error */ |
39
b03685d25fee
recpt1 now shows error explanation when write() fails.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
38
diff
changeset
|
927 fprintf(stderr, "Detected an error. cleaning up...\n"); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
928 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
|
929 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
930 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
931 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
932 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
|
933 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
934 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
935 void |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
936 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
|
937 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
938 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
|
939 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
940 sigemptyset(&blockset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
941 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
|
942 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
|
943 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
|
944 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
|
945 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
|
946 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
947 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
|
948 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
|
949 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
950 pthread_create(signal_thread, NULL, process_signals, tdata); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
951 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
952 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
953 int |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
954 tune(char *channel, thread_data *tdata, char *device) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
955 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
956 char **tuner; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
957 int num_devs; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
958 int lp; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
959 FREQUENCY freq; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
960 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
961 /* get channel */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
962 tdata->table = searchrecoff(channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
963 if(tdata->table == NULL) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
964 fprintf(stderr, "Invalid Channel: %s\n", channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
965 return 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
966 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
967 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
968 freq.frequencyno = tdata->table->set_freq; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
969 freq.slot = tdata->table->add_freq; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
970 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
971 /* open tuner */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
972 /* case 1: specified tuner device */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
973 if(device) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
974 tdata->tfd = open(device, O_RDONLY); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
975 if(tdata->tfd < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
976 fprintf(stderr, "Cannot open tuner device: %s\n", device); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
977 return 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
978 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
979 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
980 /* power on LNB */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
981 if(tdata->table->type == CHTYPE_SATELLITE) { |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
982 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
|
983 fprintf(stderr, "Power on LNB failed: %s\n", device); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
984 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
985 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
986 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
987 /* tune to specified channel */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
988 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
989 close(tdata->tfd); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
990 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
|
991 return 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
992 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
993 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
994 tdata->ch = atoi(channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
995 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
996 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
997 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
998 /* case 2: loop around available devices */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
999 if(tdata->table->type == CHTYPE_SATELLITE) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1000 tuner = bsdev; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1001 num_devs = NUM_BSDEV; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1002 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1003 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1004 tuner = isdb_t_dev; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1005 num_devs = NUM_ISDB_T_DEV; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1006 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1007 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1008 for(lp = 0; lp < num_devs; lp++) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1009 tdata->tfd = open(tuner[lp], O_RDONLY); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1010 if(tdata->tfd >= 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1011 /* power on LNB */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1012 if(tdata->table->type == CHTYPE_SATELLITE) { |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1013 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
|
1014 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
|
1015 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1016 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1017 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1018 /* tune to specified channel */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1019 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1020 close(tdata->tfd); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1021 tdata->tfd = -1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1022 continue; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1023 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1024 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1025 break; /* found suitable tuner */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1026 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1027 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1028 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1029 /* all tuners cannot be used */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1030 if(tdata->tfd < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1031 fprintf(stderr, "Cannot tune to the specified channel\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1032 return 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1033 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1034 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1035 tdata->ch = atoi(channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1036 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1037 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1038 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1039 /* show signal strength */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1040 calc_cn(tdata->tfd, tdata->table->type); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1041 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1042 return 0; /* success */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1043 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1044 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1045 int |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1046 parse_time(char *rectimestr, thread_data *tdata) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1047 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1048 /* indefinite */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1049 if(!strcmp("-", rectimestr)) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1050 tdata->indefinite = TRUE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1051 tdata->recsec = -1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1052 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1053 /* colon */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1054 else if(strchr(rectimestr, ':')) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1055 int n1, n2, n3; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1056 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
|
1057 tdata->recsec = n1 * 3600 + n2 * 60 + n3; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1058 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1059 tdata->recsec = n1 * 3600 + n2 * 60; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1060 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1061 /* HMS */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1062 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1063 char *tmpstr; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1064 char *p1, *p2; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1065 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1066 tmpstr = strdup(rectimestr); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1067 p1 = tmpstr; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1068 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1069 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1070 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1071 /* hour */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1072 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1073 *p2 = '\0'; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1074 tdata->recsec += atoi(p1) * 3600; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1075 p1 = p2 + 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1076 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1077 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1078 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1079 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1080 /* minute */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1081 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1082 *p2 = '\0'; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1083 tdata->recsec += atoi(p1) * 60; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1084 p1 = p2 + 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1085 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1086 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1087 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1088 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1089 /* second */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1090 tdata->recsec += atoi(p1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1091 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1092 free(tmpstr); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1093 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1094 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1095 return 0; /* success */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1096 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1097 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1098 int |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1099 close_tuner(thread_data *tdata) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1100 { |
89
d74bcf2d255d
do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
88
diff
changeset
|
1101 int rv = 0; |
d74bcf2d255d
do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
88
diff
changeset
|
1102 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1103 if(tdata->table->type == CHTYPE_SATELLITE) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1104 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
|
1105 rv = 1; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1106 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1107 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1108 close(tdata->tfd); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1109 |
89
d74bcf2d255d
do not give up if LNB ioctl failed
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
88
diff
changeset
|
1110 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
|
1111 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1112 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1113 thread_data *gp_tdata; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1114 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1115 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1116 main(int argc, char **argv) |
0 | 1117 { |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1118 time_t cur_time; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1119 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
|
1120 pthread_t reader_thread; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1121 pthread_t stream_thread; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1122 pthread_t ipc_thread; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1123 pthread_t dlna_thread; |
4 | 1124 QUEUE_T *p_queue = create_queue(MAX_QUEUE); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1125 STREAM_QUEUE_T *stream_queue = create_stream_queue(MAX_QUEUE); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1126 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1127 decoder *dec = NULL; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1128 splitter *splitter = NULL; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1129 static thread_data tdata; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1130 gp_tdata = &tdata; |
8 | 1131 decoder_options dopt = { |
1132 4, /* round */ | |
1133 0, /* strip */ | |
1134 0 /* emm */ | |
1135 }; | |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1136 tdata.dopt = &dopt; |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1137 tdata.lnb = 0; |
0 | 1138 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1139 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1140 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1141 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
|
1142 #ifdef HAVE_LIBARIB25 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1143 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1144 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1145 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1146 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1147 { "emm", 0, NULL, 'm'}, |
8 | 1148 { "EMM", 0, NULL, 'm'}, |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1149 #endif |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1150 { "LNB", 1, NULL, 'n'}, |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1151 { "lnb", 1, NULL, 'n'}, |
13 | 1152 { "udp", 0, NULL, 'u'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1153 { "addr", 1, NULL, 'a'}, |
13 | 1154 { "port", 1, NULL, 'p'}, |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
1155 { "device", 1, NULL, 'd'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1156 { "help", 0, NULL, 'h'}, |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
1157 { "version", 0, NULL, 'v'}, |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1158 { "list", 0, NULL, 'l'}, |
98
3fd15032fd3a
tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
97
diff
changeset
|
1159 { "sid", 1, NULL, 'i'}, |
121 | 1160 { "SID", 1, NULL, 'i'}, |
1161 { "es", 1, NULL, 'e'}, | |
1162 { "ES", 1, NULL, 'e'}, | |
122 | 1163 { "start_time", 1, NULL, 'y'}, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1164 {0, 0, NULL, 0} /* terminate */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1165 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1166 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1167 boolean use_b25 = FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1168 boolean use_udp = FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1169 boolean fileless = FALSE; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1170 boolean use_stdout = FALSE; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1171 boolean use_splitter = FALSE; |
8 | 1172 char *host_to = NULL; |
1173 int port_to = 1234; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1174 sock_data *sockdata = NULL; |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
1175 char *device = NULL; |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1176 int val; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1177 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
|
1178 char *sid_list = NULL; |
121 | 1179 char *es_name_prefix = NULL; |
122 | 1180 char *start_time = NULL; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1181 |
98
3fd15032fd3a
tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
97
diff
changeset
|
1182 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
|
1183 long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1184 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1185 case 'b': |
13 | 1186 use_b25 = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1187 fprintf(stderr, "using B25...\n"); |
8 | 1188 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1189 case 's': |
13 | 1190 dopt.strip = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1191 fprintf(stderr, "enable B25 strip\n"); |
8 | 1192 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1193 case 'm': |
13 | 1194 dopt.emm = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1195 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 1196 break; |
13 | 1197 case 'u': |
1198 use_udp = TRUE; | |
1199 host_to = "localhost"; | |
1200 fprintf(stderr, "enable UDP broadcasting\n"); | |
1201 break; | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1202 case 'h': |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1203 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1204 show_usage(argv[0]); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1205 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1206 show_options(); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1207 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1208 show_channels(); |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1209 fprintf(stderr, "\n"); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1210 exit(0); |
13 | 1211 break; |
43
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
1212 case 'v': |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
1213 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
|
1214 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
|
1215 exit(0); |
9b36fdf7d5d0
show version option has been added
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
42
diff
changeset
|
1216 break; |
57
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1217 case 'l': |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1218 show_channels(); |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1219 exit(0); |
d3929562b8e7
- added --list option to show channel list.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
49
diff
changeset
|
1220 break; |
13 | 1221 /* following options require argument */ |
81
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1222 case 'n': |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1223 val = atoi(optarg); |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1224 switch(val) { |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1225 case 11: |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1226 tdata.lnb = 1; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1227 break; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1228 case 15: |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1229 tdata.lnb = 2; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1230 break; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1231 default: |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1232 tdata.lnb = 0; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1233 break; |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1234 } |
6e3bb2c0c5b6
add an option to specify LNB voltage
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
1235 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
|
1236 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1237 case 'r': |
8 | 1238 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1239 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1240 break; |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1241 case 'a': |
13 | 1242 use_udp = TRUE; |
8 | 1243 host_to = optarg; |
1244 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
1245 break; | |
1246 case 'p': | |
1247 port_to = atoi(optarg); | |
1248 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1249 break; |
32
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
1250 case 'd': |
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
1251 device = optarg; |
6004fe4f37f9
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
28
diff
changeset
|
1252 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
|
1253 break; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1254 case 'i': |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1255 use_splitter = TRUE; |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1256 sid_list = optarg; |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1257 break; |
121 | 1258 case 'e': |
1259 es_name_prefix = optarg; | |
1260 break; | |
122 | 1261 case 'y': |
1262 start_time = optarg; | |
1263 break; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1264 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1265 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1266 |
8 | 1267 if(argc - optind < 3) { |
13 | 1268 if(argc - optind == 2 && use_udp) { |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1269 fprintf(stderr, "Fileless UDP broadcasting\n"); |
13 | 1270 fileless = TRUE; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1271 tdata.wfd = -1; |
13 | 1272 } |
1273 else { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1274 fprintf(stderr, "Arguments are necessary!\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
1275 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
13 | 1276 return 1; |
1277 } | |
4 | 1278 } |
13 | 1279 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1280 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
|
1281 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1282 /* tune */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1283 if(tune(argv[optind], &tdata, device) != 0) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1284 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
|
1285 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1286 /* set recsec */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1287 if(parse_time(argv[optind + 1], &tdata) != 0) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1288 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
|
1289 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1290 /* open output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1291 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
|
1292 if(destfile && !strcmp("-", destfile)) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1293 use_stdout = TRUE; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1294 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
|
1295 } |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1296 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1297 if(!fileless) { |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
1298 int status; |
63
ca419e61f7f2
fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
62
diff
changeset
|
1299 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
|
1300 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
|
1301 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
|
1302 if(status == -1) |
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
1303 perror("mkpath"); |
63
ca419e61f7f2
fix for a bug that recpt1 crashes if dirname(3) returns '.'
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
62
diff
changeset
|
1304 free(path); |
61
f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
59
diff
changeset
|
1305 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1306 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
|
1307 if(tdata.wfd < 0) { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
1308 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
|
1309 argv[optind + 2]); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1310 return 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1311 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1312 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1313 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1314 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1315 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1316 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1317 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1318 if(!dec) { |
34
3f2487de156e
should not loop if tuner device is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
33
diff
changeset
|
1319 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
|
1320 fprintf(stderr, "Fall back to encrypted recording\n"); |
122 | 1321 use_b25 = FALSE; |
4 | 1322 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1323 } |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1324 /* initialize splitter */ |
122 | 1325 if(use_splitter) { |
1326 splitter = split_startup(sid_list, es_name_prefix, start_time); | |
1327 if(splitter->sid_list == NULL) { | |
104
afd25d9ebef6
output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
103
diff
changeset
|
1328 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
|
1329 return 1; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1330 } |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1331 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1332 |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1333 boolean use_dlna = TRUE; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1334 /* initialize DLNA */ |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1335 if(use_dlna) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1336 do { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1337 tdata.stream_queue = stream_queue; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1338 tdata.streamer = malloc(sizeof(streamer)); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1339 if ( tdata.streamer == NULL ) { |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1340 use_dlna = FALSE; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1341 break; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1342 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1343 tdata.streamer->stream_nr = 0; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1344 tdata.streamer->stream_session[0] = NULL; |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1345 pthread_mutex_init(&tdata.streamer->mutex, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1346 } while(0); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1347 } |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1348 |
8 | 1349 /* initialize udp connection */ |
1350 if(use_udp) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1351 sockdata = calloc(1, sizeof(sock_data)); |
8 | 1352 struct in_addr ia; |
1353 ia.s_addr = inet_addr(host_to); | |
1354 if(ia.s_addr == INADDR_NONE) { | |
1355 struct hostent *hoste = gethostbyname(host_to); | |
1356 if(!hoste) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1357 perror("gethostbyname"); |
8 | 1358 return 1; |
1359 } | |
1360 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
1361 } | |
28
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
1362 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
|
1363 perror("socket"); |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
1364 return 1; |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
1365 } |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
1366 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1367 sockdata->addr.sin_family = AF_INET; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1368 sockdata->addr.sin_port = htons (port_to); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1369 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
|
1370 |
97c820e30737
limit write length at once so that udp/stdout works well.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
27
diff
changeset
|
1371 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
|
1372 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
|
1373 perror("connect"); |
8 | 1374 return 1; |
1375 } | |
1376 } | |
1377 | |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1378 /* prepare thread data */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1379 tdata.queue = p_queue; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1380 tdata.decoder = dec; |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1381 tdata.splitter = splitter; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1382 tdata.sock_data = sockdata; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1383 |
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
|
1384 /* spawn signal handler thread */ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1385 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
|
1386 |
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
|
1387 /* spawn reader thread */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1388 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
|
1389 pthread_create(&reader_thread, NULL, reader_func, &tdata); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1390 pthread_create(&stream_thread, NULL, stream_func, &tdata); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1391 pthread_create(&dlna_thread, NULL, dlna_startup, NULL); |
3 | 1392 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1393 /* spawn ipc thread */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1394 key_t key; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1395 key = (key_t)getpid(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1396 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1397 if ((tdata.msqid = msgget(key, IPC_CREAT | 0666)) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1398 perror("msgget"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1399 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1400 pthread_create(&ipc_thread, NULL, mq_recv, &tdata); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1401 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1402 /* start recording */ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1403 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
|
1404 fprintf(stderr, "Tuner cannot start recording\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1405 return 1; |
4 | 1406 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1407 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1408 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
|
1409 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1410 time(&tdata.start_time); |
0 | 1411 |
4 | 1412 /* read from tuner */ |
1413 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
|
1414 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
|
1415 break; |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1416 //fprintf (stderr, "main() while loop start.\n"); |
26 | 1417 |
4 | 1418 time(&cur_time); |
1419 bufptr = malloc(sizeof(BUFSZ)); | |
88
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1420 if(!bufptr) { |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1421 f_exit = TRUE; |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1422 break; |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1423 } |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1424 //fprintf (stderr, "main() loop#1.\n"); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1425 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1426 //fprintf (stderr, "main() loop#2.\n"); |
4 | 1427 if(bufptr->size <= 0) { |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1428 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1429 //fprintf (stderr, "main() loop#3.\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1430 f_exit = TRUE; |
4 | 1431 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1432 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1433 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1434 else { |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1435 //fprintf (stderr, "main() loop#4.\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1436 continue; |
4 | 1437 } |
1438 } | |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1439 //fprintf (stderr, "main() loop#5.\n"); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1440 //fprintf (stderr, "PT1 enqueue start.\n"); |
4 | 1441 enqueue(p_queue, bufptr); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1442 //fprintf (stderr, "PT1 enqueue finish.\n"); |
0 | 1443 |
4 | 1444 /* stop recording */ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1445 time(&cur_time); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1446 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
|
1447 ioctl(tdata.tfd, STOP_REC, 0); |
4 | 1448 /* read remaining data */ |
1449 while(1) { | |
1450 bufptr = malloc(sizeof(BUFSZ)); | |
88
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1451 if(!bufptr) { |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1452 f_exit = TRUE; |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1453 break; |
59065b569eec
improve stability on changing channel
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
87
diff
changeset
|
1454 } |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1455 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 1456 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1457 f_exit = TRUE; |
4 | 1458 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1459 break; |
4 | 1460 } |
1461 enqueue(p_queue, bufptr); | |
1462 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1463 break; |
4 | 1464 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1465 } |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1466 //fprintf (stderr, "main() break?.\n"); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1467 |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1468 /* delete message queue*/ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1469 msgctl(tdata.msqid, IPC_RMID, NULL); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1470 |
24
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
1471 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
|
1472 |
f2cce7becf52
fixed a bug that recpt1 could not exit when recsec is specified.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
21
diff
changeset
|
1473 /* 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
|
1474 pthread_join(reader_thread, NULL); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1475 pthread_join(stream_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
|
1476 pthread_join(signal_thread, NULL); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1477 pthread_join(ipc_thread, NULL); |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1478 // pthread_join(dlna_startup, NULL); |
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1479 pthread_join(dlna_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
|
1480 |
4 | 1481 /* close tuner */ |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1482 if(close_tuner(&tdata) != 0) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1483 return 1; |
0 | 1484 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1485 /* release queue */ |
4 | 1486 destroy_queue(p_queue); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1487 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1488 /* close output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1489 if(!use_stdout) |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
74
diff
changeset
|
1490 close(tdata.wfd); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1491 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
1492 /* free socket data */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1493 if(use_udp) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1494 close(sockdata->sfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1495 free(sockdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
1496 } |
8 | 1497 |
4 | 1498 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1499 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1500 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1501 } |
96
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1502 if(use_splitter) { |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1503 split_shutdown(splitter); |
52f8e081763d
add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
91
diff
changeset
|
1504 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
1505 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1506 return 0; |
0 | 1507 } |
124
9c7bc6c0327e
Add DLNA server function test. (from uShare project)
naoyan@johnstown.minaminoshima.org
parents:
122
diff
changeset
|
1508 |