source: titan/titan/audiodev.h @ 15345

Last change on this file since 15345 was 14321, checked in by nit, 12 years ago

[titan] fix volume auto increase

File size: 5.1 KB
Line 
1#ifndef AUDIODEV_H
2#define AUDIODEV_H
3
4struct dvbdev* audioopen(int adapter)
5{
6        debug(1000, "in");
7        int fd = -1;
8        struct dvbdev* node = dvbdev;
9
10        while(node != NULL)
11        {
12                if(node->fd == -1 && node->type == AUDIODEV && node->adapter == adapter)
13                        break;
14                node = node->next;
15        }
16
17        if(node != NULL)
18        {
19                if((fd = open(node->dev, O_RDWR)) < 0)
20                {
21                        debug(200, "open audio failed %s", node->dev);
22                        node = NULL;
23                }
24                else
25                {
26                        node->fd = fd;
27                        closeonexec(fd);
28                }
29        }
30
31        debug(1000, "out");
32        return node;
33}
34
35int audioopendirect(char *audiodev)
36{
37        debug(1000, "in");
38        int fd = -1;
39
40        if((fd = open(audiodev, O_RDWR)) < 0)
41        {
42                debug(200, "open audio failed %s", audiodev);
43        }
44
45        closeonexec(fd);
46        debug(1000, "out");
47        return fd;
48}
49
50void audioclose(struct dvbdev* node, int fd)
51{
52        if(node != NULL)
53        {
54                close(node->fd);
55                node->fd = -1;
56        }
57        else
58                close(fd);
59}
60
61int audiostop(struct dvbdev* node)
62{
63        if(node == NULL)
64        {
65                debug(1000, "out-> NULL detect");
66                return 1;
67        }
68
69        debug(200, "AUDIO_STOP");
70        if(ioctl(node->fd, AUDIO_STOP) < 0)
71        {
72                perr("AUDIO_STOP");
73                return 1;
74        }
75       
76        return 0;
77}
78
79int audioplay(struct dvbdev* node)
80{
81        if(node == NULL)
82        {
83                debug(1000, "out-> NULL detect");
84                return 1;
85        }
86
87        debug(200, "AUDIO_PLAY");
88        if(ioctl(node->fd, AUDIO_PLAY) < 0)
89        {
90                perr("AUDIO_PLAY");
91                return 1;
92        }
93       
94        return 0;
95}
96
97int audiopause(struct dvbdev* node)
98{
99        if(node == NULL)
100        {
101                debug(1000, "out-> NULL detect");
102                return 1;
103        }
104
105        debug(200, "AUDIO_PAUSE");
106        if(ioctl(node->fd, AUDIO_PAUSE) < 0)
107        {
108                perr("AUDIO_PAUSE");
109                return 1;
110        }
111       
112        return 0;
113}
114
115int audiogetpts(struct dvbdev* node, uint64_t* pts)
116{
117        if(node == NULL)
118        {
119                debug(1000, "out-> NULL detect");
120                return 1;
121        }
122
123        debug(200, "AUDIO_GET_PTS");
124        if(ioctl(node->fd, AUDIO_GET_PTS, pts) < 0)
125        {
126                perr("AUDIO_GET_PTS");
127                return 1;
128        }
129       
130        return 0;
131}
132
133int audioselectsource(struct dvbdev* node, audio_stream_source_t source)
134{
135        if(node == NULL)
136        {
137                debug(1000, "out-> NULL detect");
138                return 1;
139        }
140
141        debug(200, "AUDIO_SELECT_SOURCE=%d", source);
142        if(ioctl(node->fd, AUDIO_SELECT_SOURCE, source) < 0)
143        {
144                perr("AUDIO_SELECT_SOURCE");
145                return 1;
146        }
147       
148        return 0;
149}
150
151int audiosetmute(struct dvbdev* node, int state)
152{
153        if(node == NULL)
154        {
155                debug(1000, "out-> NULL detect");
156                return 1;
157        }
158
159        debug(200, "AUDIO_SET_MUTE=%d", state);
160        if(ioctl(node->fd, AUDIO_SET_MUTE, state) < 0)
161        {
162                perr("AUDIO_SET_MUTE");
163                return 1;
164        }
165       
166        return 0;
167}
168int audiosetavsync(struct dvbdev* node, int state)
169{
170        if(node == NULL)
171        {
172                debug(1000, "out-> NULL detect");
173                return 1;
174        }
175
176        debug(200, "AUDIO_SET_AV_SYNC=%d", state);
177        if(ioctl(node->fd, AUDIO_SET_AV_SYNC, state) < 0)
178        {
179                perr("AUDIO_SET_AV_SYNC");
180                return 1;
181        }
182       
183        return 0;
184}
185
186int audiosetbypassmode(struct dvbdev* node, int mode)
187{
188        if(node == NULL)
189        {
190                debug(1000, "out-> NULL detect");
191                return 1;
192        }
193
194        debug(200, "AUDIO_SET_BYPASS_MODE=%d", mode);
195        if(ioctl(node->fd, AUDIO_SET_BYPASS_MODE, mode) < 0)
196        {
197                perr("AUDIO_SET_BYPASS_MODE");
198                return 1;
199        }
200
201        //auto increase volume for ac3
202        if(status.volautochangevalue != 0)
203        {
204                if(mode == AC3)
205                {
206                        if(status.volautochange == 0)
207                        {
208                                int aktvol = getvol();
209                                if(aktvol + status.volautochangevalue > 100)
210                                        status.volautochange = 100 - aktvol;
211                                else
212                                        status.volautochange = status.volautochangevalue;
213                                setvol(aktvol + status.volautochange);
214                        }
215                }
216                else if(status.volautochange > 0)
217                {
218                        setvol(getvol() - status.volautochange);
219                        status.volautochange = 0;
220                }
221        }
222       
223        return 0;
224}
225
226int audiochannelselect(struct dvbdev* node, audio_channel_select_t channel)
227{
228        if(node == NULL)
229        {
230                debug(1000, "out-> NULL detect");
231                return 1;
232        }
233
234        debug(200, "AUDIO_CHANNEL_SELECT=%d", channel);
235        if(ioctl(node->fd, AUDIO_CHANNEL_SELECT, channel) < 0)
236        {
237                perr("AUDIO_CHANNEL_SELECT");
238                return 1;
239        }
240       
241        return 0;
242}
243
244int audioclearbuffer(struct dvbdev* node)
245{
246        if(node == NULL)
247        {
248                debug(1000, "out-> NULL detect");
249                return 1;
250        }
251
252        if(ioctl(node->fd, AUDIO_CLEAR_BUFFER) < 0)
253        {
254                perr("AUDIO_CLEAR_BUFFER");
255                return 1;
256        }
257       
258        return 0;
259}
260
261int audiosetid(struct dvbdev* node, int id)
262{
263        if(node == NULL)
264        {
265                debug(1000, "out-> NULL detect");
266                return 1;
267        }
268
269        debug(200, "AUDIO_SET_ID=%d", id);
270        if(ioctl(node->fd, AUDIO_SET_ID, id) < 0)
271        {
272                perr("AUDIO_SET_ID");
273                return 1;
274        }
275       
276        return 0;
277}
278
279int audiosetstreamtype(struct dvbdev* node, int type)
280{
281        if(node == NULL)
282        {
283                debug(1000, "out-> NULL detect");
284                return 1;
285        }
286
287        debug(200, "AUDIO_SET_STREAMTYPE=%d", type);
288        if(ioctl(node->fd, AUDIO_SET_STREAMTYPE, type) < 0)
289        {
290                perr("AUDIO_SET_STREAMTYPE");
291                return 1;
292        }
293       
294        return 0;
295}
296
297int audiogetdev()
298{
299        debug(1000, "in");
300        int i, y, fd = -1, count = 0;
301        char *buf = NULL, *audiodev = NULL;
302
303        audiodev = getconfig("audiodev", NULL);
304        if(audiodev == NULL)
305        {
306                debug(1000, "out -> NULL detect");
307                return count;
308        }
309
310        buf = malloc(MINMALLOC);
311        if(buf == NULL)
312        {
313                err("no memory");
314                return count;
315        }
316
317        for(i = 0; i < MAXDVBADAPTER; i++)
318        {
319                for(y = 0; y < MAXAUDIODEV; y++)
320                {
321                        sprintf(buf, audiodev, i, y);
322                        fd = audioopendirect(buf);
323                        if(fd >= 0)
324                        {
325                                audioclose(NULL, fd);
326                                count++;
327                                adddvbdev(buf, i, y, -1, AUDIODEV, NULL, NULL);
328                        }
329                }
330        }
331
332        free(buf);
333        debug(1000, "out");
334        return count;
335}
336
337#endif
Note: See TracBrowser for help on using the repository browser.