LiVES  2.8.7
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 1024
21 
22 typedef struct {
23  size_t size;
24  size_t max_size;
25  void *data;
26 } audio_buffer_t;
27 
28 
29 typedef struct {
30  pa_threaded_mainloop *mloop;
31  pa_context *con;
32  pa_stream *pstream;
33  pa_proplist *pa_props;
34 
35  pa_usec_t usec_start;
36 
37  int str_idx;
38 
39  pa_context_state_t state;
40 
41  // app side
42  int64_t in_arate;
43  uint64_t in_achans;
44  uint64_t in_asamps;
45 
46  // server side
47  int64_t out_arate;
48  uint64_t out_achans;
49  uint64_t out_asamps;
50 
51  uint64_t out_chans_available;
52 
53  int in_signed;
54  int in_endian;
55 
56  int out_signed;
57  int out_endian;
58 
59  uint64_t num_calls;
61  audio_buffer_t *aPlayPtr;
62  lives_audio_loop_t loop;
63 
64  uint8_t *sound_buffer;
65 
66  float volume[PULSE_MAX_OUTPUT_CHANS];
67 
68  boolean in_use;
69  boolean mute;
70 
72  volatile aserver_message_t *msgq;
73 
74  volatile uint64_t frames_written;
75 
76  boolean is_paused;
77 
78  volatile int64_t audio_ticks;
79 
80  int fd;
81  boolean is_opening;
82  volatile off_t seek_pos;
83  off_t seek_end;
84  boolean usigned;
85  boolean reverse_endian;
86 
87  lives_whentostop_t *whentostop;
88  volatile lives_cancel_t *cancelled;
89 
90  /* variables used for trying to restart the connection to pulse */
91  boolean pulsed_died;
92  struct timeval last_reconnect_attempt;
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 } pulse_driver_t;
105 
106 
107 
108 // TODO - rationalise names
109 
110 boolean lives_pulse_init(short startup_phase);
111 
112 int pulse_audio_init(void);
113 int pulse_audio_read_init(void); // ditto
114 
115 pulse_driver_t *pulse_get_driver(boolean is_output);
116 
117 int pulse_driver_activate(pulse_driver_t *);
118 void pulse_close_client(pulse_driver_t *);
119 
120 void pulse_shutdown(void);
121 
122 void pulse_aud_pb_ready(int fileno);
123 
124 size_t pulse_flush_read_data(pulse_driver_t *, int fileno, size_t rbytes, boolean rev_endian, void *data);
125 
126 void pulse_driver_uncork(pulse_driver_t *);
127 
128 boolean pulse_try_reconnect(void);
129 
130 // utils
131 volatile aserver_message_t *pulse_get_msgq(pulse_driver_t *);
132 
133 int64_t pulse_audio_seek_bytes(pulse_driver_t *, int64_t bytes);
134 
135 int64_t lives_pulse_get_time(pulse_driver_t *, boolean absolute);
136 
137 double lives_pulse_get_pos(pulse_driver_t *);
138 
139 void pa_mloop_lock(void);
140 void pa_mloop_unlock(void);
141 
142 
144 
145 boolean pulse_audio_seek_frame(pulse_driver_t *, int frame);
146 
147 void pulse_get_rec_avals(pulse_driver_t *);
148 
149 
150 
151 #endif
lives_audio_loop_t
Definition: audio.h:146
Definition: audio.h:78
lives_whentostop_t
which stream end should cause playback to finish ?
Definition: main.h:410
Definition: audio.h:60
lives_cancel_t
cancel reason
Definition: main.h:417