Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Control interface to front ends. |
||
3 | * written/copyrights 1997 by Michael Hipp |
||
4 | */ |
||
5 | |||
6 | #include <stdio.h> |
||
7 | |||
8 | #include <sys/time.h> |
||
9 | #include <sys/types.h> |
||
10 | #include <unistd.h> |
||
11 | |||
12 | #include <linux/socket.h> |
||
13 | /* <sys/socket.h> */ |
||
14 | |||
15 | #include "jukebox/controldata.h" |
||
16 | #include "mpg123.h" |
||
17 | |||
18 | #define MODE_STOPPED 0 |
||
19 | #define MODE_PLAYING 1 |
||
20 | #define MODE_PAUSED 2 |
||
21 | |||
22 | extern FILE *filept; |
||
23 | extern int tabsel_123[2][3][16]; |
||
24 | |||
25 | int sajber_sendmsg(int type,int data) |
||
26 | { |
||
27 | TControlMsg msg; |
||
28 | msg.type = type; |
||
29 | msg.data = data; |
||
30 | return write(1,&msg,sizeof(TControlMsg)); |
||
31 | } |
||
32 | |||
33 | void control_sajber(struct frame *fr) |
||
34 | { |
||
35 | struct timeval timeout; |
||
36 | fd_set readfds; |
||
37 | int n; |
||
38 | int mode = MODE_STOPPED; |
||
39 | TControlMsg smsg,rmsg; |
||
40 | struct msghdr msghdr; |
||
41 | struct m_cmsghdr cmsghdr; |
||
42 | struct iovec iovec[1]; |
||
43 | char buf[2]; |
||
44 | int init = 0; |
||
45 | int framecnt = 0; |
||
46 | |||
47 | while(1) { |
||
48 | timeout.tv_sec = 0; |
||
49 | timeout.tv_usec = 0; |
||
50 | FD_ZERO(&readfds); |
||
51 | FD_SET(0,&readfds); |
||
52 | |||
53 | if(mode == MODE_PLAYING) { |
||
54 | n = select(32,&readfds,NULL,NULL,&timeout); |
||
55 | if(n == 0) { |
||
56 | if(!read_frame(fr)) { |
||
57 | mode = MODE_STOPPED; |
||
58 | close_stream(); |
||
59 | sajber_sendmsg(MSG_NEXT,0); |
||
60 | continue; |
||
61 | } |
||
62 | play_frame(init,fr); |
||
63 | if(init) { |
||
64 | AudioInfo sai; |
||
65 | sai.bitrate = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] * 1000; |
||
66 | sai.frequency = freqs[fr->sampling_frequency]; |
||
67 | sai.stereo = fr->stereo; |
||
68 | sai.type = fr->lay; |
||
69 | sai.sample = 16; |
||
70 | sajber_sendmsg(MSG_INFO,TRUE); |
||
71 | write(1,&sai,sizeof(AudioInfo)); |
||
72 | init = 0; |
||
73 | |||
74 | } |
||
75 | framecnt++; |
||
76 | if(!(framecnt & 0xf)) { |
||
77 | sajber_sendmsg(MSG_FRAMES,framecnt); |
||
78 | sajber_sendmsg(MSG_POSITION,tell_stream()); |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | else { |
||
83 | while(1) { |
||
84 | n = select(32,&readfds,NULL,NULL,NULL); |
||
85 | if(n > 0) |
||
86 | break; |
||
87 | } |
||
88 | } |
||
89 | if(n < 0) { |
||
90 | exit(1); |
||
91 | } |
||
92 | if(n > 0) { |
||
93 | int len; |
||
94 | len = read(0,&rmsg,sizeof(TControlMsg)); |
||
95 | if(len != sizeof(TControlMsg)) { |
||
96 | fprintf(stderr,"Error reading control message!\n"); |
||
97 | exit(1); |
||
98 | } |
||
99 | #if 0 |
||
100 | fprintf(stderr,"%d.%d\n",rmsg.type,rmsg.data); |
||
101 | #endif |
||
102 | switch(rmsg.type) { |
||
103 | case MSG_CTRL: |
||
104 | switch(rmsg.data) { |
||
105 | case FORWARD_STEP: |
||
106 | if(mode != MODE_STOPPED) { |
||
107 | int i; |
||
108 | for(i=0;i<16;i++) { |
||
109 | read_frame(fr); |
||
110 | if(framecnt && fr->lay == 3) |
||
111 | set_pointer(512); |
||
112 | framecnt++; |
||
113 | } |
||
114 | } |
||
115 | sajber_sendmsg(MSG_RESPONSE,FORWARD_STEP); |
||
116 | break; |
||
117 | case FORWARD_BEGIN: |
||
118 | sajber_sendmsg(MSG_RESPONSE,FORWARD_BEGIN); |
||
119 | break; |
||
120 | case FORWARD_END: |
||
121 | sajber_sendmsg(MSG_RESPONSE,FORWARD_END); |
||
122 | break; |
||
123 | case REWIND_BEGIN: |
||
124 | sajber_sendmsg(MSG_RESPONSE,REWIND_BEGIN); |
||
125 | break; |
||
126 | case REWIND_STEP: |
||
127 | if(back_frame(fr,16) == 0) |
||
128 | framecnt -= 16; |
||
129 | else |
||
130 | framecnt = 0; |
||
131 | sajber_sendmsg(MSG_RESPONSE,REWIND_STEP); |
||
132 | break; |
||
133 | case REWIND_END: |
||
134 | sajber_sendmsg(MSG_RESPONSE,REWIND_END); |
||
135 | break; |
||
136 | case PLAY_STOP: |
||
137 | mode = MODE_STOPPED; |
||
138 | close_stream(); |
||
139 | break; |
||
140 | case PLAY_PAUSE: |
||
141 | mode = MODE_PAUSED; |
||
142 | break; |
||
143 | } |
||
144 | break; |
||
145 | case MSG_BUFFER: |
||
146 | break; |
||
147 | case MSG_SONG: |
||
148 | if(mode == MODE_PLAYING) { |
||
149 | close_stream(); |
||
150 | mode = MODE_STOPPED; |
||
151 | } |
||
152 | |||
153 | iovec[0].iov_base = buf; |
||
154 | iovec[0].iov_len = 2; |
||
155 | /* |
||
156 | * this control message 'delivers' a given file |
||
157 | * descriptor to another process .. |
||
158 | * the sent descriptor can then be accesed by the |
||
159 | * child process. |
||
160 | */ |
||
161 | cmsghdr.cmsg_len = sizeof(cmsghdr); |
||
162 | cmsghdr.cmsg_level = SOL_SOCKET; |
||
163 | cmsghdr.cmsg_type = SCM_RIGHTS; |
||
164 | |||
165 | msghdr.msg_name = NULL; |
||
166 | msghdr.msg_namelen = 0; |
||
167 | msghdr.msg_iov = iovec; |
||
168 | msghdr.msg_iovlen = 1; |
||
169 | msghdr.msg_control = &cmsghdr; |
||
170 | msghdr.msg_controllen = sizeof(cmsghdr); |
||
171 | |||
172 | if(recvmsg(0,&msghdr,0) < 0) { |
||
173 | perror("recvmsg"); |
||
174 | exit(1); |
||
175 | } |
||
176 | |||
177 | open_stream(NULL,cmsghdr.fd); |
||
178 | mode = MODE_PLAYING; |
||
179 | init = 1; |
||
180 | framecnt = 0; |
||
181 | read_frame_init(); |
||
182 | break; |
||
183 | case MSG_QUIT: |
||
184 | exit(0); |
||
185 | break; |
||
186 | case MSG_QUERY: |
||
187 | smsg.type = MSG_RESPONSE; |
||
188 | smsg.data = FALSE; |
||
189 | switch(rmsg.data) { |
||
190 | case QUERY_PLAYING: |
||
191 | if(mode == MODE_PLAYING) |
||
192 | smsg.data = TRUE; |
||
193 | break; |
||
194 | case QUERY_PAUSED: |
||
195 | if(mode == MODE_PAUSED) |
||
196 | smsg.data = TRUE; |
||
197 | break; |
||
198 | } |
||
199 | write(1,&smsg,sizeof(TControlMsg)); |
||
200 | break; |
||
201 | case MSG_BUFAHEAD: |
||
202 | break; |
||
203 | case MSG_SEEK: |
||
204 | break; |
||
205 | case MSG_PRIORITY: |
||
206 | break; |
||
207 | case MSG_RELEASE: |
||
208 | break; |
||
209 | } |
||
210 | |||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | void control_tk3play(struct frame *fr) |
||
216 | { |
||
217 | |||
218 | } |
||
219 | |||
220 |