LiVES  2.8.9
pulse.h
Go to the documentation of this file.
1 // pulse.h
2 // LiVES (lives-exe)
3 // (c) G. Finch 2005 - 2012
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 
32 typedef struct {
33  pa_threaded_mainloop *mloop;
34  pa_context *con;
35  pa_stream *pstream;
36  pa_proplist *pa_props;
37 
38  pa_usec_t usec_start;
39 
40  int str_idx;
41 
42  pa_context_state_t state;
43 
44  // app side
45  int64_t in_arate;
46  uint64_t in_achans;
47  uint64_t in_asamps;
48 
49  // server side
50  int64_t out_arate;
51  uint64_t out_achans;
52  uint64_t out_asamps;
53 
54  uint64_t out_chans_available;
55 
56  int in_signed;
57  int in_endian;
58 
59  int out_signed;
60  int out_endian;
61 
62  uint64_t num_calls;
64  audio_buffer_t *aPlayPtr;
65  lives_audio_loop_t loop;
66 
67  uint8_t *sound_buffer;
68 
69  float volume[PULSE_MAX_OUTPUT_CHANS];
70 
71  boolean in_use;
72  boolean mute;
73 
75  volatile aserver_message_t *msgq;
76 
77  volatile uint64_t frames_written;
78 
79  boolean is_paused;
80 
81  volatile int64_t audio_ticks;
82 
83  int fd;
84  volatile off_t 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  volatile int astream_fd;
104 
105  volatile float abs_maxvol_heard;
106 
107  volatile boolean waitforop;
108 } pulse_driver_t;
109 
110 
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 
132 boolean pulse_try_reconnect(void);
133 
134 // utils
135 volatile aserver_message_t *pulse_get_msgq(pulse_driver_t *);
136 
137 int64_t pulse_audio_seek_bytes(pulse_driver_t *, int64_t bytes);
138 
139 int64_t lives_pulse_get_time(pulse_driver_t *, boolean absolute);
140 
141 double lives_pulse_get_pos(pulse_driver_t *);
142 
143 void pa_mloop_lock(void);
144 void pa_mloop_unlock(void);
145 
146 
148 
149 boolean pulse_audio_seek_frame(pulse_driver_t *, int frame);
150 
151 void pulse_get_rec_avals(pulse_driver_t *);
152 
153 
154 
155 #endif
lives_audio_loop_t
Definition: audio.h:140
Definition: audio.h:73
lives_whentostop_t
which stream end should cause playback to finish ?
Definition: main.h:418
Definition: audio.h:60
lives_cancel_t
cancel reason
Definition: main.h:425