LiVES  2.4.1-svn
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 #include "audio.h"
17 
18 
19 #define PULSE_MAX_OUTPUT_CHANS PA_CHANNEL_POSITION_MAX
20 
21 #define LIVES_PA_BUFF_MAXLEN 16384
22 #define LIVES_PA_BUFF_TARGET 1024
23 
24 typedef struct {
25  size_t size;
26  size_t max_size;
27  void *data;
28 } audio_buffer_t;
29 
30 
31 typedef struct {
32  pa_threaded_mainloop *mloop;
33  pa_context *con;
34  pa_stream *pstream;
35  pa_proplist *pa_props;
36 
37  pa_usec_t usec_start;
38 
39  int str_idx;
40 
41  pa_context_state_t state;
42 
43  // app side
44  int64_t in_arate;
45  uint64_t in_achans;
46  uint64_t in_asamps;
47 
48  // server side
49  int64_t 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  float volume[PULSE_MAX_OUTPUT_CHANS];
69 
70  boolean in_use;
71  boolean mute;
72 
74  volatile aserver_message_t *msgq;
75 
76  volatile uint64_t frames_written;
77 
78  boolean is_paused;
79 
80  volatile int64_t audio_ticks;
81 
82  int fd;
83  boolean is_opening;
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  /* variables used for trying to restart the connection to pulse */
93  boolean pulsed_died;
94  struct timeval last_reconnect_attempt;
95 
96  boolean is_output;
97 
98  int playing_file;
99 
100  lives_audio_buf_t **abufs;
101  volatile int read_abuf;
102 
103  uint64_t chunk_size;
104 
105  volatile int astream_fd;
106 
107 } pulse_driver_t;
108 
109 
110 
111 // TODO - rationalise names
112 
113 boolean lives_pulse_init(short startup_phase);
114 
115 int pulse_audio_init(void);
116 int pulse_audio_read_init(void); // ditto
117 
118 pulse_driver_t *pulse_get_driver(boolean is_output);
119 
120 int pulse_driver_activate(pulse_driver_t *);
121 void pulse_close_client(pulse_driver_t *);
122 
123 void pulse_shutdown(void);
124 
125 void pulse_aud_pb_ready(int fileno);
126 
127 size_t pulse_flush_read_data(pulse_driver_t *, int fileno, size_t rbytes, boolean rev_endian, void *data);
128 
129 void pulse_driver_uncork(pulse_driver_t *);
130 
131 boolean pulse_try_reconnect(void);
132 
133 // utils
134 volatile aserver_message_t *pulse_get_msgq(pulse_driver_t *);
135 
136 int64_t pulse_audio_seek_bytes(pulse_driver_t *, int64_t bytes);
137 
138 int64_t lives_pulse_get_time(pulse_driver_t *, boolean absolute);
139 
140 double lives_pulse_get_pos(pulse_driver_t *);
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:143
Definition: audio.h:77
lives_whentostop_t
which stream end should cause playback to finish ?
Definition: main.h:359
Definition: audio.h:59
lives_cancel_t
cancel reason
Definition: main.h:367