From: Jaroslav Kysela Date: Tue, 4 Mar 2003 20:01:06 +0000 (+0000) Subject: Updated to new timer API X-Git-Tag: v1.0.3~221 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=9c084c4ba6a4cda677cfe1213b51cc1e4afeb3ed;p=alsa-lib.git Updated to new timer API --- diff --git a/include/local.h b/include/local.h index fc7bee69..57eb0c1c 100644 --- a/include/local.h +++ b/include/local.h @@ -80,6 +80,9 @@ typedef struct sndrv_seq_event snd_seq_event_t; #endif #define _snd_timer_id sndrv_timer_id +#define _snd_timer_ginfo sndrv_timer_ginfo +#define _snd_timer_gparams sndrv_timer_gparams +#define _snd_timer_gstatus sndrv_timer_gstatus #define _snd_timer_select sndrv_timer_select #define _snd_timer_info sndrv_timer_info #define _snd_timer_params sndrv_timer_params diff --git a/include/timer.h b/include/timer.h index 2e68aede..c63e6d2d 100644 --- a/include/timer.h +++ b/include/timer.h @@ -45,18 +45,18 @@ extern "C" { /** timer identification structure */ typedef struct _snd_timer_id snd_timer_id_t; +/** timer global info structure */ +typedef struct _snd_timer_ginfo snd_timer_ginfo_t; +/** timer global params structure */ +typedef struct _snd_timer_gparams snd_timer_gparams_t; +/** timer global status structure */ +typedef struct _snd_timer_gstatus snd_timer_gstatus_t; /** timer info structure */ typedef struct _snd_timer_info snd_timer_info_t; /** timer params structure */ typedef struct _snd_timer_params snd_timer_params_t; /** timer status structure */ typedef struct _snd_timer_status snd_timer_status_t; -/** timer read structure */ -typedef struct _snd_timer_read { - unsigned int resolution; /**< tick resolution in nanoseconds */ - unsigned int ticks; /**< count of happened ticks */ -} snd_timer_read_t; - /** timer master class */ typedef enum _snd_timer_class { SND_TIMER_CLASS_NONE = -1, /**< invalid */ @@ -76,13 +76,43 @@ typedef enum _snd_timer_slave_class { SND_TIMER_SCLASS_LAST = SND_TIMER_SCLASS_OSS_SEQUENCER /**< last slave timer */ } snd_timer_slave_class_t; +/** timer read event identification */ +typedef enum _snd_timer_event { + SND_TIMER_EVENT_RESOLUTION = 0, /* val = resolution in ns */ + SND_TIMER_EVENT_TICK, /* val = ticks */ + SND_TIMER_EVENT_START, /* val = resolution in ns */ + SND_TIMER_EVENT_STOP, /* val = 0 */ + SND_TIMER_EVENT_CONTINUE, /* val = resolution in ns */ + SND_TIMER_EVENT_PAUSE, /* val = 0 */ + /* master timer events for slave timer instances */ + SND_TIMER_EVENT_MSTART = SND_TIMER_EVENT_START + 10, + SND_TIMER_EVENT_MSTOP = SND_TIMER_EVENT_STOP + 10, + SND_TIMER_EVENT_MCONTINUE = SND_TIMER_EVENT_CONTINUE + 10, + SND_TIMER_EVENT_MPAUSE = SND_TIMER_EVENT_PAUSE + 10, +} snd_timer_event_t; + +/** timer read structure */ +typedef struct _snd_timer_read { + unsigned int resolution; /**< tick resolution in nanoseconds */ + unsigned int ticks; /**< count of happened ticks */ +} snd_timer_read_t; + +/** timer tstamp + event read structure */ +typedef struct _snd_timer_tread { + snd_timer_event_t event; + snd_htimestamp_t tstamp; + unsigned int val; +} snd_timer_tread_t; + /** global timer - system */ #define SND_TIMER_GLOBAL_SYSTEM 0 /** global timer - RTC */ #define SND_TIMER_GLOBAL_RTC 1 /** timer open mode flag - non-blocking behaviour */ -#define SND_TIMER_OPEN_NONBLOCK 0x0001 +#define SND_TIMER_OPEN_NONBLOCK (1<<0) +/** use timestamps and event notification - enhanced read */ +#define SND_TIMER_OPEN_TREAD (1<<1) /** timer handle type */ typedef enum _snd_timer_type { @@ -104,6 +134,9 @@ int snd_timer_query_open(snd_timer_query_t **handle, const char *name, int mode) int snd_timer_query_open_lconf(snd_timer_query_t **handle, const char *name, int mode, snd_config_t *lconf); int snd_timer_query_close(snd_timer_query_t *handle); int snd_timer_query_next_device(snd_timer_query_t *handle, snd_timer_id_t *tid); +int snd_timer_query_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info); +int snd_timer_query_params(snd_timer_query_t *handle, snd_timer_gparams_t *params); +int snd_timer_query_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status); int snd_timer_open(snd_timer_t **handle, const char *name, int mode); int snd_timer_open_lconf(snd_timer_t **handle, const char *name, int mode, snd_config_t *lconf); @@ -148,7 +181,6 @@ int snd_timer_info_is_slave(snd_timer_info_t * info); int snd_timer_info_get_card(snd_timer_info_t * info); const char *snd_timer_info_get_id(snd_timer_info_t * info); const char *snd_timer_info_get_name(snd_timer_info_t * info); -long snd_timer_info_get_ticks(snd_timer_info_t * info); long snd_timer_info_get_resolution(snd_timer_info_t * info); size_t snd_timer_params_sizeof(void); @@ -159,10 +191,15 @@ void snd_timer_params_free(snd_timer_params_t *obj); void snd_timer_params_copy(snd_timer_params_t *dst, const snd_timer_params_t *src); void snd_timer_params_set_auto_start(snd_timer_params_t * params, int auto_start); +int snd_timer_params_get_auto_start(snd_timer_params_t * params); +void snd_timer_params_set_exclusive(snd_timer_params_t * params, int exclusive); +int snd_timer_params_get_exclusive(snd_timer_params_t * params); void snd_timer_params_set_ticks(snd_timer_params_t * params, long ticks); long snd_timer_params_get_ticks(snd_timer_params_t * params); void snd_timer_params_set_queue_size(snd_timer_params_t * params, long queue_size); long snd_timer_params_get_queue_size(snd_timer_params_t * params); +void snd_timer_params_set_filter(snd_timer_params_t * params, unsigned int filter); +unsigned int snd_timer_params_get_filter(snd_timer_params_t * params); size_t snd_timer_status_sizeof(void); /** allocate #snd_timer_status_t container on stack */ @@ -177,6 +214,9 @@ long snd_timer_status_get_lost(snd_timer_status_t * status); long snd_timer_status_get_overrun(snd_timer_status_t * status); long snd_timer_status_get_queue(snd_timer_status_t * status); +/* deprecated functions, for compatibility */ +long snd_timer_info_get_ticks(snd_timer_info_t * info); + /** \} */ #ifdef __cplusplus diff --git a/src/Versions b/src/Versions index 58de00f2..dab89280 100644 --- a/src/Versions +++ b/src/Versions @@ -88,3 +88,15 @@ ALSA_0.9.0rc8 { snd_pcm_status_get_htstamp; } ALSA_0.9.0rc4; + +ALSA_0.9.0 { + global: + + snd_timer_query_info; + snd_timer_query_params; + snd_timer_query_status; + snd_timer_params_set_exclusive; + snd_timer_params_get_exclusive; + snd_timer_params_set_filter; + snd_timer_params_get_filter; +} ALSA_0.9.0rc8; diff --git a/src/timer/timer.c b/src/timer/timer.c index 10e5ec67..8b366e66 100644 --- a/src/timer/timer.c +++ b/src/timer/timer.c @@ -466,16 +466,6 @@ const char *snd_timer_info_get_name(snd_timer_info_t * info) return info->name; } -/** - * \brief get maximum timer ticks - * \param info pointer to #snd_timer_info_t structure - * \return maximum timer ticks - */ -long snd_timer_info_get_ticks(snd_timer_info_t * info) -{ - assert(info); - return info->ticks; -} /** * \brief get timer resolution in us @@ -575,6 +565,40 @@ int snd_timer_params_get_auto_start(snd_timer_params_t * params) return params->flags & SNDRV_TIMER_PSFLG_AUTO ? 1 : 0; } +/** + * \brief set timer exclusive use + * \param params pointer to #snd_timer_params_t structure + */ +#ifndef DOXYGEN +void INTERNAL(snd_timer_params_set_exclusive)(snd_timer_params_t * params, int exclusive) +#else +void snd_timer_params_set_exclusive(snd_timer_params_t * params, int exclusive) +#endif +{ + assert(params); + if (exclusive) + params->flags |= SNDRV_TIMER_PSFLG_EXCLUSIVE; + else + params->flags &= ~SNDRV_TIMER_PSFLG_EXCLUSIVE; +} +default_symbol_version(__snd_timer_params_set_exclusive, snd_timer_params_set_exclusive, ALSA_0.9.0); + +/** + * \brief determine if timer has exclusive flag + * \param params pointer to #snd_timer_params_t structure + * \return nonzero if timer has exclusive flag + */ +#ifndef DOXYGEN +int INTERNAL(snd_timer_params_get_exclusive)(snd_timer_params_t * params) +#else +int snd_timer_params_get_exclusive(snd_timer_params_t * params) +#endif +{ + assert(params); + return params->flags & SNDRV_TIMER_PSFLG_EXCLUSIVE ? 1 : 0; +} +default_symbol_version(__snd_timer_params_get_exclusive, snd_timer_params_get_exclusive, ALSA_0.9.0); + /** * \brief set timer ticks * \param params pointer to #snd_timer_params_t structure @@ -617,6 +641,37 @@ long snd_timer_params_get_queue_size(snd_timer_params_t * params) return params->queue_size; } +/** + * \brief set timer event filter + * \param params pointer to #snd_timer_params_t structure + */ +#ifndef DOXYGEN +void INTERNAL(snd_timer_params_set_filter)(snd_timer_params_t * params, unsigned int filter) +#else +void snd_timer_params_set_filter(snd_timer_params_t * params, unsigned int filter) +#endif +{ + assert(params); + params->filter = filter; +} +default_symbol_version(__snd_timer_params_set_filter, snd_timer_params_set_filter, ALSA_0.9.0); + +/** + * \brief get timer event filter + * \param params pointer to #snd_timer_params_t structure + * \return timer event filter + */ +#ifndef DOXYGEN +unsigned int INTERNAL(snd_timer_params_get_filter)(snd_timer_params_t * params) +#else +unsigned int snd_timer_params_get_filter(snd_timer_params_t * params) +#endif +{ + assert(params); + return params->filter; +} +default_symbol_version(__snd_timer_params_get_filter, snd_timer_params_get_filter, ALSA_0.9.0); + /** * \brief set parameters for timer handle * \param timer timer handle @@ -796,3 +851,17 @@ ssize_t snd_timer_read(snd_timer_t *timer, void *buffer, size_t size) assert(buffer || size == 0); return timer->ops->read(timer, buffer, size); } + +/** + * \brief (DEPRECATED) get maximum timer ticks + * \param info pointer to #snd_timer_info_t structure + * \return maximum timer ticks + */ +long snd_timer_info_get_ticks(snd_timer_info_t * info) +{ + assert(info); + return 1; +} +#ifndef DOC_HIDDEN +link_warning(snd_timer_info_get_ticks, "Warning: snd_timer_info_get_ticks is deprecated"); +#endif diff --git a/src/timer/timer_hw.c b/src/timer/timer_hw.c index b20c0aa2..2ea2aa98 100644 --- a/src/timer/timer_hw.c +++ b/src/timer/timer_hw.c @@ -233,6 +233,15 @@ int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int close(fd); return -SND_ERROR_INCOMPATIBLE_VERSION; } + if (mode & SND_TIMER_OPEN_TREAD) { + int arg = 1; + if (ioctl(fd, SNDRV_TIMER_IOCTL_TREAD, &arg) < 0) { + ret = -errno; + close(fd); + SNDERR("extended read is not supported (SNDRV_TIMER_IOCTL_TREAD)"); + return ret; + } + } memset(&sel, 0, sizeof(sel)); sel.id.dev_class = dev_class; sel.id.dev_sclass = dev_sclass; diff --git a/src/timer/timer_local.h b/src/timer/timer_local.h index bbe8f0c7..f11bce34 100644 --- a/src/timer/timer_local.h +++ b/src/timer/timer_local.h @@ -52,6 +52,9 @@ int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int typedef struct { int (*close)(snd_timer_query_t *timer); int (*next_device)(snd_timer_query_t *timer, snd_timer_id_t *tid); + int (*info)(snd_timer_query_t *timer, snd_timer_ginfo_t *info); + int (*params)(snd_timer_query_t *timer, snd_timer_gparams_t *info); + int (*status)(snd_timer_query_t *timer, snd_timer_gstatus_t *info); } snd_timer_query_ops_t; struct _snd_timer_query { diff --git a/src/timer/timer_query.c b/src/timer/timer_query.c index 497460f7..d381d2ac 100644 --- a/src/timer/timer_query.c +++ b/src/timer/timer_query.c @@ -220,6 +220,56 @@ int snd_timer_query_next_device(snd_timer_query_t *timer, snd_timer_id_t *tid) return timer->ops->next_device(timer, tid); } +/** + * \brief obtain the timer global information + * \param timer timer handle + * \param info timer information + * \return 0 on success otherwise a negative error code + */ +#ifndef DOXYGEN +int INTERNAL(snd_timer_query_info)(snd_timer_query_t *timer, snd_timer_ginfo_t *info) +#else +int snd_timer_query_info(snd_timer_query_t *timer, snd_timer_ginfo_t *info) +#endif +{ + assert(timer); + assert(info); + return timer->ops->info(timer, info); +} +default_symbol_version(__snd_timer_query_info, snd_timer_query_info, ALSA_0.9.0); + +/** + * \brief set the timer global parameters + * \param timer timer handle + * \param params timer parameters + * \return 0 on success otherwise a negative error code + */ +#ifndef DOXYGEN +int INTERNAL(snd_timer_query_params)(snd_timer_query_t *timer, snd_timer_gparams_t *params) +#else +int snd_timer_query_params(snd_timer_query_t *timer, snd_timer_gparams_t *params) +#endif +{ + assert(timer); + assert(params); + return timer->ops->params(timer, params); +} +default_symbol_version(__snd_timer_query_params, snd_timer_query_params, ALSA_0.9.0); + +/** + * \brief get the timer global status + * \param timer timer handle + * \param status timer status + * \return 0 on success otherwise a negative error code + */ +int snd_timer_query_status(snd_timer_query_t *timer, snd_timer_gstatus_t *status) +{ + assert(timer); + assert(status); + return timer->ops->status(timer, status); +} +default_symbol_version(__snd_timer_query_status, snd_timer_query_status, ALSA_0.9.0); + /** * \brief get size of the snd_timer_id_t structure in bytes * \return size of the snd_timer_id_t structure in bytes diff --git a/src/timer/timer_query_hw.c b/src/timer/timer_query_hw.c index feded1f8..18178d6d 100644 --- a/src/timer/timer_query_hw.c +++ b/src/timer/timer_query_hw.c @@ -54,9 +54,39 @@ static int snd_timer_query_hw_next_device(snd_timer_query_t *handle, snd_timer_i return 0; } +static int snd_timer_query_hw_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info) +{ + if (!handle || !info) + return -EINVAL; + if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GINFO, info) < 0) + return -errno; + return 0; +} + +static int snd_timer_query_hw_params(snd_timer_query_t *handle, snd_timer_gparams_t *params) +{ + if (!handle || !params) + return -EINVAL; + if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0) + return -errno; + return 0; +} + +static int snd_timer_query_hw_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status) +{ + if (!handle || !status) + return -EINVAL; + if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GSTATUS, status) < 0) + return -errno; + return 0; +} + static snd_timer_query_ops_t snd_timer_query_hw_ops = { close: snd_timer_query_hw_close, next_device: snd_timer_query_hw_next_device, + info: snd_timer_query_hw_info, + params: snd_timer_query_hw_params, + status: snd_timer_query_hw_status }; int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mode)