update shuttlerc, fix vwdw lock update_position
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / audiooss.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef AUDIOOSS_H
23 #define AUDIOOSS_H
24
25 #include "audiodevice.h"
26 #include "condition.inc"
27 #include "playbackconfig.inc"
28
29 #ifdef HAVE_OSS
30 #include <sys/soundcard.h>
31
32 class OSSThread : public Thread
33 {
34 public:
35         OSSThread(AudioOSS *device);
36         ~OSSThread();
37
38         void run();
39         void write_data(int fd, unsigned char *data, int bytes);
40         void read_data(int fd, unsigned char *data, int bytes);
41 // Must synchronize reads and writes
42         void wait_read();
43         void wait_write();
44         int64_t device_position();
45
46         Condition *input_lock;
47         Condition *output_lock;
48         Condition *read_lock;
49         Condition *write_lock;
50         int rd, wr, fd;
51         unsigned char *data;
52         int bytes;
53         int done;
54         AudioOSS *device;
55
56         int64_t bytes_written;
57         Timer *timer;
58         int delay;
59         Mutex *timer_lock;
60
61 };
62
63 class AudioOSS : public AudioLowLevel
64 {
65 public:
66         AudioOSS(AudioDevice *device);
67         ~AudioOSS();
68
69         int open_input();
70         int open_output();
71         int write_buffer(char *buffer, int bytes);
72         int read_buffer(char *buffer, int bytes);
73         int close_all();
74         int64_t device_position();
75         int flush_device();
76         int interrupt_playback();
77         int stop_output() { return interrupt_playback(); }
78         int64_t samples_output();
79
80 private:
81         int get_fmt(int bits);
82         int sizetofrag(int samples, int channels, int bits);
83         int set_cloexec_flag(int desc, int value);
84         int get_output(int number);
85         int get_input(int number);
86         int dsp_in[MAXDEVICES], dsp_out[MAXDEVICES];
87         OSSThread *thread[MAXDEVICES];
88 // Temp for each device, Bytes allocated
89         unsigned char *data[MAXDEVICES];
90         int data_allocated[MAXDEVICES];
91 };
92
93 #endif
94
95 #endif