LiVES  3.2.0
pulse.h
Go to the documentation of this file.
1 // pulse.h
2 // LiVES (lives-exe)
3 // (c) G. Finch 2005 - 2020
4 // Released under the GPL 3 or later
5 // see file ../COPYING for licensing details
6 
7 #ifdef HAVE_PULSE_AUDIO
8 
9 #include <pulse/context.h>
10 #include <pulse/thread-mainloop.h>
11 #include <pulse/introspect.h>
12 #include <pulse/stream.h>
13 #include <pulse/proplist.h>
14 #include <pulse/error.h>
15 
16 #define PULSE_MAX_OUTPUT_CHANS PA_CHANNEL_POSITION_MAX
17 
18 #define LIVES_PA_BUFF_MAXLEN 32768
19 #define LIVES_PA_BUFF_TARGET 4096
20 #define LIVES_PA_BUFF_MINREQ 2048
21 #define LIVES_PA_BUFF_FRAGSIZE 4096
22 
23 #define PA_SAMPSIZE 16
24 #define PA_ACHANS 2
25 
26 typedef struct {
27  ssize_t size;
28  size_t max_size;
29  volatile void *data;
30 } audio_buffer_t;
31 
32 typedef struct {
33  pa_threaded_mainloop *mloop;
34  pa_context *con;
35  pa_stream *pstream;
36  pa_proplist *pa_props;
37 
38  volatile int64_t usec_start;
39  volatile int64_t extrausec;
40 
41  int str_idx;
42 
43  pa_stream_state_t state;
44 
45  // app side
46  volatile int in_arate;
47  uint64_t in_achans;
48  uint64_t in_asamps;
49 
50  // server side
51  int out_arate;
52  uint64_t out_achans;
53  uint64_t out_asamps;
54 
55  uint64_t out_chans_available;
56 
57  int in_signed;
58  int in_endian;
59 
60  int out_signed;
61  int out_endian;
62 
63  uint64_t num_calls;
65  audio_buffer_t *aPlayPtr;
66  lives_audio_loop_t loop;
67 
68  uint8_t *sound_buffer;
69 
70  pa_cvolume volume;
71 
72  //float volume[PULSE_MAX_OUTPUT_CHANS]; ///< amount volume, 1.0 is full volume (currently unused, see volume_linear)
73 
74  boolean in_use;
75  boolean mute;
76 
78  volatile aserver_message_t *msgq;
79 
80  volatile uint64_t frames_written;
81 
82  boolean is_paused;
83 
84  int fd;
85  off_t seek_pos;
86  volatile off_t real_seek_pos;
87  off_t seek_end;
88  boolean usigned;
89  boolean reverse_endian;
90 
91  volatile lives_whentostop_t *whentostop;
92  volatile lives_cancel_t *cancelled;
93 
94  boolean pulsed_died;
95 
96  boolean is_output;
97 
98  volatile int playing_file;
99 
100  lives_audio_buf_t **abufs;
101  volatile int read_abuf;
102 
103  size_t chunk_size;
104 
105  double volume_linear;
106 
107  volatile int astream_fd;
108 
109  volatile float abs_maxvol_heard;
110 
111  volatile boolean is_corked;
112 } pulse_driver_t;
113 
114 // TODO - rationalise names
115 
116 boolean lives_pulse_init(short startup_phase);
117 
118 int pulse_audio_init(void);
119 int pulse_audio_read_init(void); // ditto
120 
121 pulse_driver_t *pulse_get_driver(boolean is_output);
122 
123 int pulse_driver_activate(pulse_driver_t *);
124 void pulse_close_client(pulse_driver_t *);
125 
126 void pulse_shutdown(void);
127 
128 void pulse_aud_pb_ready(int fileno);
129 
130 size_t pulse_flush_read_data(pulse_driver_t *, int fileno, size_t rbytes, boolean rev_endian, void *data);
131 
132 void pulse_driver_uncork(pulse_driver_t *);
133 void pulse_driver_cork(pulse_driver_t *);
134 
135 boolean pulse_try_reconnect(void);
136 
137 // utils
138 volatile aserver_message_t *pulse_get_msgq(pulse_driver_t *);
139 
140 int64_t pulse_audio_seek_bytes(pulse_driver_t *, int64_t bytes, lives_clip_t *);
141 
142 boolean pa_time_reset(pulse_driver_t *, int64_t offset);
143 void pulse_tscale_reset(pulse_driver_t *);
144 
145 ticks_t lives_pulse_get_time(pulse_driver_t *);
146 
147 double lives_pulse_get_pos(pulse_driver_t *);
148 
149 size_t pulse_get_buffsize(pulse_driver_t *);
150 
151 
152 void pa_mloop_lock(void);
153 void pa_mloop_unlock(void);
154 
156 
157 boolean pulse_audio_seek_frame(pulse_driver_t *, double frame);
158 
159 void pulse_get_rec_avals(pulse_driver_t *);
160 
161 #endif
lives_audio_buf_t
Definition: audio.h:76
ticks_t
int64_t ticks_t
Definition: main.h:97
lives_whentostop_t
lives_whentostop_t
which stream end should cause playback to finish ?
Definition: main.h:692
lives_cancel_t
lives_cancel_t
cancel reason
Definition: main.h:699
lives_audio_loop_t
lives_audio_loop_t
Definition: audio.h:145
aserver_message_t
Definition: audio.h:62
lives_clip_t
corresponds to one clip in the GUI
Definition: main.h:877