ALSA project - the C library reference
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1
11/*
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as
14 * published by the Free Software Foundation; either version 2.1 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 */
27
28#if !defined(__ASOUNDLIB_H) && !defined(ALSA_LIBRARY_BUILD)
29/* don't use ALSA_LIBRARY_BUILD define in sources outside alsa-lib */
30#warning "use #include <alsa/asoundlib.h>, <alsa/timer.h> should not be used directly"
31#include <alsa/asoundlib.h>
32#endif
33
34#ifndef __ALSA_TIMER_H
35#define __ALSA_TIMER_H
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
48#define SND_TIMER_DLSYM_VERSION _dlsym_timer_001
50#define SND_TIMER_QUERY_DLSYM_VERSION _dlsym_timer_query_001
51
53typedef struct _snd_timer_id snd_timer_id_t;
55typedef struct _snd_timer_ginfo snd_timer_ginfo_t;
57typedef struct _snd_timer_gparams snd_timer_gparams_t;
59typedef struct _snd_timer_gstatus snd_timer_gstatus_t;
61typedef struct _snd_timer_info snd_timer_info_t;
63typedef struct _snd_timer_params snd_timer_params_t;
65typedef struct _snd_timer_status snd_timer_status_t;
67typedef enum _snd_timer_class {
68 SND_TIMER_CLASS_NONE = -1,
69 SND_TIMER_CLASS_SLAVE = 0,
70 SND_TIMER_CLASS_GLOBAL,
71 SND_TIMER_CLASS_CARD,
72 SND_TIMER_CLASS_PCM,
73 SND_TIMER_CLASS_LAST = SND_TIMER_CLASS_PCM
74} snd_timer_class_t;
75
77typedef enum _snd_timer_slave_class {
78 SND_TIMER_SCLASS_NONE = 0,
79 SND_TIMER_SCLASS_APPLICATION,
80 SND_TIMER_SCLASS_SEQUENCER,
81 SND_TIMER_SCLASS_OSS_SEQUENCER,
82 SND_TIMER_SCLASS_LAST = SND_TIMER_SCLASS_OSS_SEQUENCER
83} snd_timer_slave_class_t;
84
86typedef enum _snd_timer_event {
87 SND_TIMER_EVENT_RESOLUTION = 0, /* val = resolution in ns */
88 SND_TIMER_EVENT_TICK, /* val = ticks */
89 SND_TIMER_EVENT_START, /* val = resolution in ns */
90 SND_TIMER_EVENT_STOP, /* val = 0 */
91 SND_TIMER_EVENT_CONTINUE, /* val = resolution in ns */
92 SND_TIMER_EVENT_PAUSE, /* val = 0 */
93 SND_TIMER_EVENT_EARLY, /* val = 0 */
94 SND_TIMER_EVENT_SUSPEND, /* val = 0 */
95 SND_TIMER_EVENT_RESUME, /* val = resolution in ns */
96 /* master timer events for slave timer instances */
97 SND_TIMER_EVENT_MSTART = SND_TIMER_EVENT_START + 10,
98 SND_TIMER_EVENT_MSTOP = SND_TIMER_EVENT_STOP + 10,
99 SND_TIMER_EVENT_MCONTINUE = SND_TIMER_EVENT_CONTINUE + 10,
100 SND_TIMER_EVENT_MPAUSE = SND_TIMER_EVENT_PAUSE + 10,
101 SND_TIMER_EVENT_MSUSPEND = SND_TIMER_EVENT_SUSPEND + 10,
102 SND_TIMER_EVENT_MRESUME = SND_TIMER_EVENT_RESUME + 10
103} snd_timer_event_t;
104
106typedef struct _snd_timer_read {
107 unsigned int resolution;
108 unsigned int ticks;
109} snd_timer_read_t;
110
112typedef struct _snd_timer_tread {
113 snd_timer_event_t event;
114 snd_htimestamp_t tstamp;
115 unsigned int val;
116} snd_timer_tread_t;
117
119#define SND_TIMER_GLOBAL_SYSTEM 0
121#define SND_TIMER_GLOBAL_RTC 1 /* Obsoleted, due to enough legacy. */
123#define SND_TIMER_GLOBAL_HPET 2
125#define SND_TIMER_GLOBAL_HRTIMER 3
126
128#define SND_TIMER_OPEN_NONBLOCK (1<<0)
130#define SND_TIMER_OPEN_TREAD (1<<1)
131
133typedef enum _snd_timer_type {
135 SND_TIMER_TYPE_HW = 0,
137 SND_TIMER_TYPE_SHM,
139 SND_TIMER_TYPE_INET
140} snd_timer_type_t;
141
143typedef struct _snd_timer_query snd_timer_query_t;
145typedef struct _snd_timer snd_timer_t;
146
147
148int snd_timer_query_open(snd_timer_query_t **handle, const char *name, int mode);
149int snd_timer_query_open_lconf(snd_timer_query_t **handle, const char *name, int mode, snd_config_t *lconf);
150int snd_timer_query_close(snd_timer_query_t *handle);
151int snd_timer_query_next_device(snd_timer_query_t *handle, snd_timer_id_t *tid);
152int snd_timer_query_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info);
153int snd_timer_query_params(snd_timer_query_t *handle, snd_timer_gparams_t *params);
154int snd_timer_query_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status);
155
156int snd_timer_open(snd_timer_t **handle, const char *name, int mode);
157int snd_timer_open_lconf(snd_timer_t **handle, const char *name, int mode, snd_config_t *lconf);
158int snd_timer_close(snd_timer_t *handle);
159int snd_async_add_timer_handler(snd_async_handler_t **handler, snd_timer_t *timer,
160 snd_async_callback_t callback, void *private_data);
161snd_timer_t *snd_async_handler_get_timer(snd_async_handler_t *handler);
162int snd_timer_poll_descriptors_count(snd_timer_t *handle);
163int snd_timer_poll_descriptors(snd_timer_t *handle, struct pollfd *pfds, unsigned int space);
164int snd_timer_poll_descriptors_revents(snd_timer_t *timer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
165int snd_timer_info(snd_timer_t *handle, snd_timer_info_t *timer);
166int snd_timer_params(snd_timer_t *handle, snd_timer_params_t *params);
167int snd_timer_status(snd_timer_t *handle, snd_timer_status_t *status);
168int snd_timer_start(snd_timer_t *handle);
169int snd_timer_stop(snd_timer_t *handle);
170int snd_timer_continue(snd_timer_t *handle);
171ssize_t snd_timer_read(snd_timer_t *handle, void *buffer, size_t size);
172
173size_t snd_timer_id_sizeof(void);
175#define snd_timer_id_alloca(ptr) __snd_alloca(ptr, snd_timer_id)
176int snd_timer_id_malloc(snd_timer_id_t **ptr);
177void snd_timer_id_free(snd_timer_id_t *obj);
178void snd_timer_id_copy(snd_timer_id_t *dst, const snd_timer_id_t *src);
179
180void snd_timer_id_set_class(snd_timer_id_t *id, int dev_class);
181int snd_timer_id_get_class(snd_timer_id_t *id);
182void snd_timer_id_set_sclass(snd_timer_id_t *id, int dev_sclass);
183int snd_timer_id_get_sclass(snd_timer_id_t *id);
184void snd_timer_id_set_card(snd_timer_id_t *id, int card);
185int snd_timer_id_get_card(snd_timer_id_t *id);
186void snd_timer_id_set_device(snd_timer_id_t *id, int device);
187int snd_timer_id_get_device(snd_timer_id_t *id);
188void snd_timer_id_set_subdevice(snd_timer_id_t *id, int subdevice);
189int snd_timer_id_get_subdevice(snd_timer_id_t *id);
190
191size_t snd_timer_ginfo_sizeof(void);
193#define snd_timer_ginfo_alloca(ptr) __snd_alloca(ptr, snd_timer_ginfo)
194int snd_timer_ginfo_malloc(snd_timer_ginfo_t **ptr);
195void snd_timer_ginfo_free(snd_timer_ginfo_t *obj);
196void snd_timer_ginfo_copy(snd_timer_ginfo_t *dst, const snd_timer_ginfo_t *src);
197
198int snd_timer_ginfo_set_tid(snd_timer_ginfo_t *obj, snd_timer_id_t *tid);
199snd_timer_id_t *snd_timer_ginfo_get_tid(snd_timer_ginfo_t *obj);
200unsigned int snd_timer_ginfo_get_flags(snd_timer_ginfo_t *obj);
201int snd_timer_ginfo_get_card(snd_timer_ginfo_t *obj);
202char *snd_timer_ginfo_get_id(snd_timer_ginfo_t *obj);
203char *snd_timer_ginfo_get_name(snd_timer_ginfo_t *obj);
204unsigned long snd_timer_ginfo_get_resolution(snd_timer_ginfo_t *obj);
205unsigned long snd_timer_ginfo_get_resolution_min(snd_timer_ginfo_t *obj);
206unsigned long snd_timer_ginfo_get_resolution_max(snd_timer_ginfo_t *obj);
207unsigned int snd_timer_ginfo_get_clients(snd_timer_ginfo_t *obj);
208
209size_t snd_timer_info_sizeof(void);
211#define snd_timer_info_alloca(ptr) __snd_alloca(ptr, snd_timer_info)
212int snd_timer_info_malloc(snd_timer_info_t **ptr);
213void snd_timer_info_free(snd_timer_info_t *obj);
214void snd_timer_info_copy(snd_timer_info_t *dst, const snd_timer_info_t *src);
215
216int snd_timer_info_is_slave(snd_timer_info_t * info);
217int snd_timer_info_get_card(snd_timer_info_t * info);
218const char *snd_timer_info_get_id(snd_timer_info_t * info);
219const char *snd_timer_info_get_name(snd_timer_info_t * info);
220long snd_timer_info_get_resolution(snd_timer_info_t * info);
221
222size_t snd_timer_params_sizeof(void);
224#define snd_timer_params_alloca(ptr) __snd_alloca(ptr, snd_timer_params)
225int snd_timer_params_malloc(snd_timer_params_t **ptr);
226void snd_timer_params_free(snd_timer_params_t *obj);
227void snd_timer_params_copy(snd_timer_params_t *dst, const snd_timer_params_t *src);
228
229int snd_timer_params_set_auto_start(snd_timer_params_t * params, int auto_start);
230int snd_timer_params_get_auto_start(snd_timer_params_t * params);
231int snd_timer_params_set_exclusive(snd_timer_params_t * params, int exclusive);
232int snd_timer_params_get_exclusive(snd_timer_params_t * params);
233int snd_timer_params_set_early_event(snd_timer_params_t * params, int early_event);
234int snd_timer_params_get_early_event(snd_timer_params_t * params);
235void snd_timer_params_set_ticks(snd_timer_params_t * params, long ticks);
236long snd_timer_params_get_ticks(snd_timer_params_t * params);
237void snd_timer_params_set_queue_size(snd_timer_params_t * params, long queue_size);
238long snd_timer_params_get_queue_size(snd_timer_params_t * params);
239void snd_timer_params_set_filter(snd_timer_params_t * params, unsigned int filter);
240unsigned int snd_timer_params_get_filter(snd_timer_params_t * params);
241
242size_t snd_timer_status_sizeof(void);
244#define snd_timer_status_alloca(ptr) __snd_alloca(ptr, snd_timer_status)
245int snd_timer_status_malloc(snd_timer_status_t **ptr);
246void snd_timer_status_free(snd_timer_status_t *obj);
247void snd_timer_status_copy(snd_timer_status_t *dst, const snd_timer_status_t *src);
248
249snd_htimestamp_t snd_timer_status_get_timestamp(snd_timer_status_t * status);
250long snd_timer_status_get_resolution(snd_timer_status_t * status);
251long snd_timer_status_get_lost(snd_timer_status_t * status);
252long snd_timer_status_get_overrun(snd_timer_status_t * status);
253long snd_timer_status_get_queue(snd_timer_status_t * status);
254
255/* deprecated functions, for compatibility */
256long snd_timer_info_get_ticks(snd_timer_info_t * info);
257
260#ifdef __cplusplus
261}
262#endif
263
264#endif
int snd_async_add_timer_handler(snd_async_handler_t **handler, snd_timer_t *timer, snd_async_callback_t callback, void *private_data)
Add an async handler for a timer.
Definition timer.c:301
snd_htimestamp_t snd_timer_status_get_timestamp(snd_timer_status_t *status)
get timestamp
Definition timer.c:842
int snd_timer_params_get_auto_start(snd_timer_params_t *params)
determine if timer has auto start flag
Definition timer.c:628
int snd_timer_poll_descriptors(snd_timer_t *timer, struct pollfd *pfds, unsigned int space)
get poll descriptors
Definition timer.c:358
long snd_timer_params_get_ticks(snd_timer_params_t *params)
get timer ticks
Definition timer.c:712
int snd_timer_params_malloc(snd_timer_params_t **params)
allocate a new snd_timer_params_t structure
Definition timer.c:575
int snd_timer_params(snd_timer_t *timer, snd_timer_params_t *params)
set parameters for timer handle
Definition timer.c:778
void snd_timer_info_free(snd_timer_info_t *info)
frees the snd_timer_info_t structure
Definition timer.c:472
int snd_timer_poll_descriptors_revents(snd_timer_t *timer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
get returned events from poll descriptors
Definition timer.c:389
long snd_timer_info_get_resolution(snd_timer_info_t *info)
get timer resolution in us
Definition timer.c:539
void snd_timer_params_set_queue_size(snd_timer_params_t *params, long queue_size)
set timer queue size (32-1024)
Definition timer.c:723
int snd_timer_params_set_exclusive(snd_timer_params_t *params, int exclusive)
set timer exclusive use
Definition timer.c:642
int snd_timer_info(snd_timer_t *timer, snd_timer_info_t *info)
get information about timer handle
Definition timer.c:551
size_t snd_timer_params_sizeof()
get size of the snd_timer_params_t structure in bytes
Definition timer.c:562
int snd_timer_params_get_exclusive(snd_timer_params_t *params)
determine if timer has exclusive flag
Definition timer.c:662
int snd_timer_info_malloc(snd_timer_info_t **info)
allocate a new snd_timer_info_t structure
Definition timer.c:456
const char * snd_timer_info_get_name(snd_timer_info_t *info)
get timer name
Definition timer.c:527
void snd_timer_params_copy(snd_timer_params_t *dst, const snd_timer_params_t *src)
copy one snd_timer_params_t structure to another
Definition timer.c:602
int snd_timer_params_get_early_event(snd_timer_params_t *params)
determine if timer has early event flag
Definition timer.c:690
long snd_timer_status_get_queue(snd_timer_status_t *status)
get count of used queue elements
Definition timer.c:886
size_t snd_timer_status_sizeof()
get size of the snd_timer_status_t structure in bytes
Definition timer.c:789
ssize_t snd_timer_read(snd_timer_t *timer, void *buffer, size_t size)
read bytes using timer handle
Definition timer.c:944
void snd_timer_params_free(snd_timer_params_t *params)
frees the snd_timer_params_t structure
Definition timer.c:591
void snd_timer_info_copy(snd_timer_info_t *dst, const snd_timer_info_t *src)
copy one snd_timer_info_t structure to another
Definition timer.c:483
int snd_timer_stop(snd_timer_t *timer)
stop the timer
Definition timer.c:921
unsigned int snd_timer_params_get_filter(snd_timer_params_t *params)
get timer event filter
Definition timer.c:764
int snd_timer_start(snd_timer_t *timer)
start the timer
Definition timer.c:910
long snd_timer_params_get_queue_size(snd_timer_params_t *params)
get queue size
Definition timer.c:734
int snd_timer_poll_descriptors_count(snd_timer_t *timer)
get count of poll descriptors for timer handle
Definition timer.c:345
void snd_timer_params_set_ticks(snd_timer_params_t *params, long ticks)
set timer ticks
Definition timer.c:701
long snd_timer_status_get_lost(snd_timer_status_t *status)
get master tick lost count
Definition timer.c:864
long snd_timer_status_get_resolution(snd_timer_status_t *status)
get resolution in us
Definition timer.c:853
snd_timer_t * snd_async_handler_get_timer(snd_async_handler_t *handler)
Return timer handle related to an async handler.
Definition timer.c:331
void snd_timer_params_set_filter(snd_timer_params_t *params, unsigned int filter)
set timer event filter
Definition timer.c:748
int snd_timer_status_malloc(snd_timer_status_t **status)
allocate a new snd_timer_status_t structure
Definition timer.c:802
void snd_timer_status_copy(snd_timer_status_t *dst, const snd_timer_status_t *src)
copy one snd_timer_status_t structure to another
Definition timer.c:829
size_t snd_timer_info_sizeof()
get size of the snd_timer_info_t structure in bytes
Definition timer.c:443
int snd_timer_open(snd_timer_t **timer, const char *name, int mode)
Opens a new connection to the timer interface.
Definition timer.c:202
const char * snd_timer_info_get_id(snd_timer_info_t *info)
get timer id
Definition timer.c:516
int snd_timer_params_set_auto_start(snd_timer_params_t *params, int auto_start)
set timer auto start
Definition timer.c:613
int snd_timer_continue(snd_timer_t *timer)
continue the timer
Definition timer.c:932
int snd_timer_status(snd_timer_t *timer, snd_timer_status_t *status)
get status from timer handle
Definition timer.c:898
int snd_timer_info_is_slave(snd_timer_info_t *info)
determine, if timer is slave
Definition timer.c:494
long snd_timer_info_get_ticks(snd_timer_info_t *info)
(DEPRECATED) get maximum timer ticks
Definition timer.c:957
int snd_timer_close(snd_timer_t *timer)
close timer handle
Definition timer.c:248
int snd_timer_info_get_card(snd_timer_info_t *info)
get timer card
Definition timer.c:505
int snd_timer_params_set_early_event(snd_timer_params_t *params, int early_event)
set timer early event
Definition timer.c:675
int snd_timer_open_lconf(snd_timer_t **timer, const char *name, int mode, snd_config_t *lconf)
Opens a new connection to the timer interface using local configuration.
Definition timer.c:233
long snd_timer_status_get_overrun(snd_timer_status_t *status)
get overrun count
Definition timer.c:875
void snd_timer_status_free(snd_timer_status_t *status)
frees the snd_timer_status_t structure
Definition timer.c:818
int snd_timer_ginfo_get_card(snd_timer_ginfo_t *obj)
get associated card with timer
Definition timer_query.c:315
int snd_timer_id_malloc(snd_timer_id_t **info)
allocate a new snd_timer_id_t structure
Definition timer_query.c:451
int snd_timer_query_open(snd_timer_query_t **timer, const char *name, int mode)
Opens a new connection to the timer query interface.
Definition timer_query.c:160
void snd_timer_id_set_class(snd_timer_id_t *tid, int dev_class)
set timer class
Definition timer_query.c:489
char * snd_timer_ginfo_get_name(snd_timer_ginfo_t *obj)
get timer name
Definition timer_query.c:335
unsigned long snd_timer_ginfo_get_resolution_min(snd_timer_ginfo_t *obj)
get timer minimal resolution in ns
Definition timer_query.c:355
void snd_timer_id_set_device(snd_timer_id_t *tid, int device)
set timer device
Definition timer_query.c:555
unsigned int snd_timer_ginfo_get_flags(snd_timer_ginfo_t *obj)
get timer flags
Definition timer_query.c:305
int snd_timer_query_next_device(snd_timer_query_t *timer, snd_timer_id_t *tid)
obtain the next timer identification
Definition timer_query.c:221
size_t snd_timer_id_sizeof()
get size of the snd_timer_id_t structure in bytes
Definition timer_query.c:438
unsigned long snd_timer_ginfo_get_resolution(snd_timer_ginfo_t *obj)
get timer resolution in ns
Definition timer_query.c:345
void snd_timer_id_set_card(snd_timer_id_t *tid, int card)
set timer card
Definition timer_query.c:533
unsigned int snd_timer_ginfo_get_clients(snd_timer_ginfo_t *obj)
get current timer clients
Definition timer_query.c:375
size_t snd_timer_ginfo_sizeof(void)
get size of the snd_timer_ginfo_t structure in bytes
Definition timer_query.c:232
int snd_timer_query_open_lconf(snd_timer_query_t **timer, const char *name, int mode, snd_config_t *lconf)
Opens a new connection to the timer query interface using local configuration.
Definition timer_query.c:185
int snd_timer_query_close(snd_timer_query_t *timer)
close timer query handle
Definition timer_query.c:200
int snd_timer_id_get_device(snd_timer_id_t *tid)
get timer device
Definition timer_query.c:566
unsigned long snd_timer_ginfo_get_resolution_max(snd_timer_ginfo_t *obj)
get timer maximal resolution in ns
Definition timer_query.c:365
int snd_timer_ginfo_malloc(snd_timer_ginfo_t **info)
allocate a new snd_timer_ginfo_t structure
Definition timer_query.c:245
snd_timer_id_t * snd_timer_ginfo_get_tid(snd_timer_ginfo_t *obj)
get timer identification
Definition timer_query.c:295
void snd_timer_id_set_sclass(snd_timer_id_t *tid, int dev_sclass)
set timer sub-class
Definition timer_query.c:511
int snd_timer_id_get_sclass(snd_timer_id_t *tid)
get timer sub-class
Definition timer_query.c:522
void snd_timer_id_set_subdevice(snd_timer_id_t *tid, int subdevice)
set timer subdevice
Definition timer_query.c:577
void snd_timer_ginfo_free(snd_timer_ginfo_t *info)
frees the snd_timer_ginfo_t structure
Definition timer_query.c:261
int snd_timer_id_get_class(snd_timer_id_t *tid)
get timer class
Definition timer_query.c:500
void snd_timer_id_free(snd_timer_id_t *info)
frees the snd_timer_id_t structure
Definition timer_query.c:467
void snd_timer_id_copy(snd_timer_id_t *dst, const snd_timer_id_t *src)
copy one snd_timer_id_t structure to another
Definition timer_query.c:478
void snd_timer_ginfo_copy(snd_timer_ginfo_t *dst, const snd_timer_ginfo_t *src)
copy one snd_timer_info_t structure to another
Definition timer_query.c:272
int snd_timer_id_get_subdevice(snd_timer_id_t *tid)
get timer subdevice
Definition timer_query.c:588
int snd_timer_id_get_card(snd_timer_id_t *tid)
get timer card
Definition timer_query.c:544
int snd_timer_ginfo_set_tid(snd_timer_ginfo_t *obj, snd_timer_id_t *tid)
set timer identification
Definition timer_query.c:284
char * snd_timer_ginfo_get_id(snd_timer_ginfo_t *obj)
get timer identification
Definition timer_query.c:325