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