diff options
Diffstat (limited to 'src/pulse')
32 files changed, 1158 insertions, 700 deletions
diff --git a/src/pulse/channelmap.c b/src/pulse/channelmap.c index db0c4b3f..fd313bd3 100644 --- a/src/pulse/channelmap.c +++ b/src/pulse/channelmap.c @@ -198,10 +198,11 @@ pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, p pa_assert(m); pa_assert(channels > 0); pa_assert(channels <= PA_CHANNELS_MAX); + pa_assert(def < PA_CHANNEL_MAP_DEF_MAX); pa_channel_map_init(m); - m->channels = channels; + m->channels = (uint8_t) channels; switch (def) { case PA_CHANNEL_MAP_AIFF: @@ -287,9 +288,6 @@ pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, p case PA_CHANNEL_MAP_AUX: { unsigned i; - if (channels >= PA_CHANNELS_MAX) - return NULL; - for (i = 0; i < channels; i++) m->map[i] = PA_CHANNEL_POSITION_AUX0 + i; @@ -391,7 +389,7 @@ pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, p default: - return NULL; + pa_assert_not_reached(); } } @@ -401,6 +399,7 @@ pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels, pa_assert(m); pa_assert(channels > 0); pa_assert(channels <= PA_CHANNELS_MAX); + pa_assert(def < PA_CHANNEL_MAP_DEF_MAX); pa_channel_map_init(m); @@ -415,7 +414,7 @@ pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels, i++; } - m->channels = channels; + m->channels = (uint8_t) channels; return m; } @@ -460,13 +459,20 @@ int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) { char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map) { unsigned channel; - int first = 1; + pa_bool_t first = TRUE; char *e; pa_assert(s); pa_assert(l > 0); pa_assert(map); + pa_init_i18n(); + + if (!pa_channel_map_valid(map)) { + pa_snprintf(s, l, _("(invalid)")); + return s; + } + *(e = s) = 0; for (channel = 0; channel < map->channels && l > 1; channel++) { @@ -475,7 +481,7 @@ char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map) { pa_channel_position_to_string(map->map[channel])); e = strchr(e, 0); - first = 0; + first = FALSE; } return s; @@ -489,7 +495,7 @@ pa_channel_map *pa_channel_map_parse(pa_channel_map *rmap, const char *s) { pa_assert(rmap); pa_assert(s); - memset(&map, 0, sizeof(map)); + pa_channel_map_init(&map); if (strcmp(s, "stereo") == 0) { map.channels = 2; @@ -552,11 +558,22 @@ int pa_channel_map_valid(const pa_channel_map *map) { if (map->channels <= 0 || map->channels > PA_CHANNELS_MAX) return 0; - for (c = 0; c < map->channels; c++) { - - if (map->map[c] < 0 ||map->map[c] >= PA_CHANNEL_POSITION_MAX) + for (c = 0; c < map->channels; c++) + if (map->map[c] < 0 || map->map[c] >= PA_CHANNEL_POSITION_MAX) return 0; - } return 1; } + +int pa_channel_map_compatible(const pa_channel_map *map, const pa_sample_spec *ss) { + pa_assert(map); + pa_assert(ss); + + if (!pa_channel_map_valid(map)) + return 0; + + if (!pa_sample_spec_valid(ss)) + return 0; + + return map->channels == ss->channels; +} diff --git a/src/pulse/channelmap.h b/src/pulse/channelmap.h index 7c32b868..d7d19d79 100644 --- a/src/pulse/channelmap.h +++ b/src/pulse/channelmap.h @@ -142,24 +142,42 @@ typedef enum pa_channel_position { /** A list of channel mapping definitions for pa_channel_map_init_auto() */ typedef enum pa_channel_map_def { - PA_CHANNEL_MAP_AIFF, /**< The mapping from RFC3551, which is based on AIFF-C */ - PA_CHANNEL_MAP_ALSA, /**< The default mapping used by ALSA */ - PA_CHANNEL_MAP_AUX, /**< Only aux channels */ - PA_CHANNEL_MAP_WAVEEX, /**< Microsoft's WAVEFORMATEXTENSIBLE mapping */ - PA_CHANNEL_MAP_OSS, /**< The default channel mapping used by OSS as defined in the OSS 4.0 API specs */ + PA_CHANNEL_MAP_AIFF, + /**< The mapping from RFC3551, which is based on AIFF-C */ - PA_CHANNEL_MAP_DEFAULT = PA_CHANNEL_MAP_AIFF /**< The default channel map */ + PA_CHANNEL_MAP_ALSA, + /**< The default mapping used by ALSA */ + + PA_CHANNEL_MAP_AUX, + /**< Only aux channels */ + + PA_CHANNEL_MAP_WAVEEX, + /**< Microsoft's WAVEFORMATEXTENSIBLE mapping */ + + PA_CHANNEL_MAP_OSS, + /**< The default channel mapping used by OSS as defined in the OSS 4.0 API specs */ + + /**< Upper limit of valid channel mapping definitions */ + PA_CHANNEL_MAP_DEF_MAX, + + PA_CHANNEL_MAP_DEFAULT = PA_CHANNEL_MAP_AIFF + /**< The default channel map */ } pa_channel_map_def_t; /** A channel map which can be used to attach labels to specific * channels of a stream. These values are relevant for conversion and * mixing of streams */ typedef struct pa_channel_map { - uint8_t channels; /**< Number of channels */ - pa_channel_position_t map[PA_CHANNELS_MAX]; /**< Channel labels */ + uint8_t channels; + /**< Number of channels */ + + pa_channel_position_t map[PA_CHANNELS_MAX]; + /**< Channel labels */ } pa_channel_map; -/** Initialize the specified channel map and return a pointer to it */ +/** Initialize the specified channel map and return a pointer to + * it. The channel map will have a defined state but + * pa_channel_map_valid() will fail for it. */ pa_channel_map* pa_channel_map_init(pa_channel_map *m); /** Initialize the specified channel map for monoaural audio and return a pointer to it */ @@ -186,7 +204,11 @@ const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_PURE /** Return a human readable text label for the specified channel position. \since 0.9.7 */ const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos); -/** The maximum length of strings returned by pa_channel_map_snprint() */ +/** The maximum length of strings returned by + * pa_channel_map_snprint(). Please note that this value can change + * with any release without warning and without being considered API + * or ABI breakage. You should not use this definition anywhere where + * it might become part of an ABI. */ #define PA_CHANNEL_MAP_SNPRINT_MAX 336 /** Make a humand readable string from the specified channel map */ @@ -198,9 +220,13 @@ pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s); /** Compare two channel maps. Return 1 if both match. */ int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) PA_GCC_PURE; -/** Return non-zero of the specified channel map is considered valid */ +/** Return non-zero if the specified channel map is considered valid */ int pa_channel_map_valid(const pa_channel_map *map) PA_GCC_PURE; +/** Return non-zero if the specified channel map is compatible with + * the specified sample spec. \since 0.9.12 */ +int pa_channel_map_compatible(const pa_channel_map *map, const pa_sample_spec *ss) PA_GCC_PURE; + PA_C_DECL_END #endif diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c index 739ef161..58d64642 100644 --- a/src/pulse/client-conf.c +++ b/src/pulse/client-conf.c @@ -61,6 +61,7 @@ static const pa_client_conf default_conf = { .disable_shm = FALSE, .cookie_file = NULL, .cookie_valid = FALSE, + .shm_size = 0 }; pa_client_conf *pa_client_conf_new(void) { @@ -99,6 +100,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) { { "autospawn", pa_config_parse_bool, NULL }, { "cookie-file", pa_config_parse_string, NULL }, { "disable-shm", pa_config_parse_bool, NULL }, + { "shm-size-bytes", pa_config_parse_size, NULL }, { NULL, NULL, NULL }, }; @@ -110,6 +112,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) { table[5].data = &c->autospawn; table[6].data = &c->cookie_file; table[7].data = &c->disable_shm; + table[8].data = &c->shm_size; if (filename) { diff --git a/src/pulse/client-conf.h b/src/pulse/client-conf.h index 699279aa..4eac467e 100644 --- a/src/pulse/client-conf.h +++ b/src/pulse/client-conf.h @@ -31,6 +31,7 @@ typedef struct pa_client_conf { pa_bool_t autospawn, disable_shm; uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; pa_bool_t cookie_valid; /* non-zero, when cookie is valid */ + size_t shm_size; } pa_client_conf; /* Create a new configuration data object and reset it to defaults */ diff --git a/src/pulse/client.conf.in b/src/pulse/client.conf.in index 8339d651..579bcc20 100644 --- a/src/pulse/client.conf.in +++ b/src/pulse/client.conf.in @@ -30,3 +30,4 @@ ; cookie-file = ; disable-shm = no +; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB diff --git a/src/pulse/context.c b/src/pulse/context.c index 5be4078b..3145d9c8 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -81,8 +81,6 @@ #include "context.h" -#define AUTOSPAWN_LOCK "autospawn.lock" - void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { @@ -99,23 +97,6 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event, [PA_COMMAND_EXTENSION] = pa_command_extension }; - -static void unlock_autospawn_lock_file(pa_context *c) { - pa_assert(c); - - if (c->autospawn_lock_fd >= 0) { - char *lf; - - if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) - pa_log_warn(_("Cannot unlock autospawn because runtime path is no more.")); - - pa_unlock_lockfile(lf, c->autospawn_lock_fd); - pa_xfree(lf); - - c->autospawn_lock_fd = -1; - } -} - static void context_free(pa_context *c); pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) { @@ -174,11 +155,12 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * c->is_local = FALSE; c->server_list = NULL; c->server = NULL; - c->autospawn_lock_fd = -1; - memset(&c->spawn_api, 0, sizeof(c->spawn_api)); - c->do_autospawn = FALSE; + c->do_shm = FALSE; + c->do_autospawn = FALSE; + memset(&c->spawn_api, 0, sizeof(c->spawn_api)); + #ifndef MSG_NOSIGNAL #ifdef SIGPIPE pa_check_signal_is_blocked(SIGPIPE); @@ -192,10 +174,10 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * pa_client_conf_load(c->conf, NULL); pa_client_conf_env(c->conf); - if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm))) { + if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) { if (!c->conf->disable_shm) - c->mempool = pa_mempool_new(0); + c->mempool = pa_mempool_new(FALSE, c->conf->shm_size); if (!c->mempool) { context_free(c); @@ -246,8 +228,6 @@ static void context_free(pa_context *c) { context_unlink(c); - unlock_autospawn_lock_file(c); - if (c->record_streams) pa_dynarray_free(c->record_streams, NULL, NULL); if (c->playback_streams) @@ -407,11 +387,11 @@ int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa err = PA_ERR_UNKNOWN; if (fail) { - pa_context_fail(c, err); + pa_context_fail(c, (int) err); return -1; } - pa_context_set_error(c, err); + pa_context_set_error(c, (int) err); return 0; } @@ -433,7 +413,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t switch(c->state) { case PA_CONTEXT_AUTHORIZING: { pa_tagstruct *reply; - pa_bool_t shm_on_remote; + pa_bool_t shm_on_remote = FALSE; if (pa_tagstruct_getu32(t, &c->version) < 0 || !pa_tagstruct_eof(t)) { @@ -571,31 +551,89 @@ static void setup_context(pa_context *c, pa_iochannel *io) { pa_context_unref(c); } -static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata); +static char *get_old_legacy_runtime_dir(void) { + char *p, u[128]; + struct stat st; -#ifndef OS_IS_WIN32 + if (!pa_get_user_name(u, sizeof(u))) + return NULL; -static int context_connect_spawn(pa_context *c) { - pid_t pid; - int status, r; - int fds[2] = { -1, -1} ; - pa_iochannel *io; + p = pa_sprintf_malloc("/tmp/pulse-%s", u); - if (getuid() == 0) - return -1; + if (stat(p, &st) < 0) { + pa_xfree(p); + return NULL; + } - pa_context_ref(c); + if (st.st_uid != getuid()) { + pa_xfree(p); + return NULL; + } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { - pa_log_error(_("socketpair(): %s"), pa_cstrerror(errno)); - pa_context_fail(c, PA_ERR_INTERNAL); - goto fail; + return p; +} + +static char *get_very_old_legacy_runtime_dir(void) { + char *p, h[128]; + struct stat st; + + if (!pa_get_home_dir(h, sizeof(h))) + return NULL; + + p = pa_sprintf_malloc("%s/.pulse", h); + + if (stat(p, &st) < 0) { + pa_xfree(p); + return NULL; + } + + if (st.st_uid != getuid()) { + pa_xfree(p); + return NULL; } - pa_make_fd_cloexec(fds[0]); + return p; +} - pa_make_socket_low_delay(fds[0]); - pa_make_socket_low_delay(fds[1]); + +static pa_strlist *prepend_per_user(pa_strlist *l) { + char *ufn; + static char *legacy_dir; + + /* The very old per-user instance path (< 0.9.11). This is supported only to ease upgrades */ + if ((legacy_dir = get_very_old_legacy_runtime_dir())) { + char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir); + l = pa_strlist_prepend(l, p); + pa_xfree(p); + pa_xfree(legacy_dir); + } + + /* The old per-user instance path (< 0.9.12). This is supported only to ease upgrades */ + if ((legacy_dir = get_old_legacy_runtime_dir())) { + char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir); + l = pa_strlist_prepend(l, p); + pa_xfree(p); + pa_xfree(legacy_dir); + } + + /* The per-user instance */ + if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) { + l = pa_strlist_prepend(l, ufn); + pa_xfree(ufn); + } + + return l; +} + +#ifndef OS_IS_WIN32 + +static int context_autospawn(pa_context *c) { + pid_t pid; + int status, r; + + pa_log_debug("Trying to autospawn..."); + + pa_context_ref(c); if (c->spawn_api.prefork) c->spawn_api.prefork(); @@ -611,31 +649,22 @@ static int context_connect_spawn(pa_context *c) { } else if (!pid) { /* Child */ - char t[128]; const char *state = NULL; #define MAX_ARGS 64 const char * argv[MAX_ARGS+1]; int n; - char *f; - - pa_close_all(fds[1], -1); - - f = pa_sprintf_malloc("%i", fds[1]); - pa_set_env("PULSE_PASSED_FD", f); - pa_xfree(f); if (c->spawn_api.atfork) c->spawn_api.atfork(); + pa_close_all(-1); + /* Setup argv */ n = 0; argv[n++] = c->conf->daemon_binary; - argv[n++] = "--daemonize=yes"; - - pa_snprintf(t, sizeof(t), "-Lmodule-native-protocol-fd fd=%i", fds[1]); - argv[n++] = strdup(t); + argv[n++] = "--start"; while (n < MAX_ARGS) { char *a; @@ -655,14 +684,13 @@ static int context_connect_spawn(pa_context *c) { /* Parent */ - pa_assert_se(pa_close(fds[1]) == 0); - fds[1] = -1; - - r = waitpid(pid, &status, 0); - if (c->spawn_api.postfork) c->spawn_api.postfork(); + do { + r = waitpid(pid, &status, 0); + } while (r < 0 && errno == EINTR); + if (r < 0) { pa_log(_("waitpid(): %s"), pa_cstrerror(errno)); pa_context_fail(c, PA_ERR_INTERNAL); @@ -672,21 +700,11 @@ static int context_connect_spawn(pa_context *c) { goto fail; } - c->is_local = TRUE; - - unlock_autospawn_lock_file(c); - - io = pa_iochannel_new(c->mainloop, fds[0], fds[0]); - setup_context(c, io); - pa_context_unref(c); return 0; fail: - pa_close_pipe(fds); - - unlock_autospawn_lock_file(c); pa_context_unref(c); @@ -695,6 +713,8 @@ fail: #endif /* OS_IS_WIN32 */ +static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata); + static int try_next_connection(pa_context *c) { char *u = NULL; int r = -1; @@ -712,8 +732,18 @@ static int try_next_connection(pa_context *c) { #ifndef OS_IS_WIN32 if (c->do_autospawn) { - r = context_connect_spawn(c); - goto finish; + + if ((r = context_autospawn(c)) < 0) + goto finish; + + /* Autospawn only once */ + c->do_autospawn = FALSE; + + /* Connect only to per-user sockets this time */ + c->server_list = prepend_per_user(c->server_list); + + /* Retry connection */ + continue; } #endif @@ -768,36 +798,12 @@ static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userd goto finish; } - unlock_autospawn_lock_file(c); setup_context(c, io); finish: pa_context_unref(c); } - -static char *get_legacy_runtime_dir(void) { - char *p, u[128]; - struct stat st; - - if (!pa_get_user_name(u, sizeof(u))) - return NULL; - - p = pa_sprintf_malloc("/tmp/pulse-%s", u); - - if (stat(p, &st) < 0) { - pa_xfree(p); - return NULL; - } - - if (st.st_uid != getuid()) { - pa_xfree(p); - return NULL; - } - - return p; -} - int pa_context_connect( pa_context *c, const char *server, @@ -825,12 +831,13 @@ int pa_context_connect( pa_context_fail(c, PA_ERR_INVALIDSERVER); goto finish; } + } else { - char *d, *ufn; - static char *legacy_dir; + char *d; /* Prepend in reverse order */ + /* Follow the X display */ if ((d = getenv("DISPLAY"))) { char *e; d = pa_xstrdup(d); @@ -843,43 +850,27 @@ int pa_context_connect( pa_xfree(d); } - c->server_list = pa_strlist_prepend(c->server_list, "tcp6:localhost"); - c->server_list = pa_strlist_prepend(c->server_list, "tcp4:localhost"); + /* Add TCP/IP on the localhost */ + c->server_list = pa_strlist_prepend(c->server_list, "tcp6:[::1]"); + c->server_list = pa_strlist_prepend(c->server_list, "tcp4:127.0.0.1"); - /* The system wide instance */ + /* The system wide instance via PF_LOCAL */ c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET); - /* The old per-user instance path. This is supported only to ease upgrades */ - if ((legacy_dir = get_legacy_runtime_dir())) { - char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir); - c->server_list = pa_strlist_prepend(c->server_list, p); - pa_xfree(p); - pa_xfree(legacy_dir); - } + /* The user instance via PF_LOCAL */ + c->server_list = prepend_per_user(c->server_list); - /* The per-user instance */ - if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) { - c->server_list = pa_strlist_prepend(c->server_list, ufn); - pa_xfree(ufn); - } - - /* Wrap the connection attempts in a single transaction for sane autospawn locking */ + /* Set up autospawning */ if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) { - char *lf; - if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) { - pa_context_fail(c, PA_ERR_ACCESS); - goto finish; - } + if (getuid() == 0) + pa_log_debug("Not doing autospawn since we are root."); + else { + c->do_autospawn = TRUE; - pa_assert(c->autospawn_lock_fd <= 0); - c->autospawn_lock_fd = pa_lock_lockfile(lf); - pa_xfree(lf); - - if (api) - c->spawn_api = *api; - - c->do_autospawn = TRUE; + if (api) + c->spawn_api = *api; + } } } @@ -938,11 +929,11 @@ int pa_context_is_pending(pa_context *c) { static void set_dispatch_callbacks(pa_operation *o); -static void pdispatch_drain_callback(PA_GCC_UNUSED pa_pdispatch*pd, void *userdata) { +static void pdispatch_drain_callback(pa_pdispatch*pd, void *userdata) { set_dispatch_callbacks(userdata); } -static void pstream_drain_callback(PA_GCC_UNUSED pa_pstream *s, void *userdata) { +static void pstream_drain_callback(pa_pstream *s, void *userdata) { set_dispatch_callbacks(userdata); } @@ -994,7 +985,7 @@ pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *u return o; } -void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int success = 1; @@ -1146,7 +1137,7 @@ const char* pa_context_get_server(pa_context *c) { return c->server; } -uint32_t pa_context_get_protocol_version(PA_GCC_UNUSED pa_context *c) { +uint32_t pa_context_get_protocol_version(pa_context *c) { return PA_PROTOCOL_VERSION; } diff --git a/src/pulse/def.h b/src/pulse/def.h index aa07d1c9..ace56574 100644 --- a/src/pulse/def.h +++ b/src/pulse/def.h @@ -57,7 +57,7 @@ static inline int PA_CONTEXT_IS_GOOD(pa_context_state_t x) { /** The state of a stream */ typedef enum pa_stream_state { - PA_STREAM_UNCONNECTED, /**< The stream is not yet connected to any sink or source */ + PA_STREAM_UNCONNECTED, /**< The stream is not yet connected to any sink or source */ PA_STREAM_CREATING, /**< The stream is being created */ PA_STREAM_READY, /**< The stream is established, you may pass audio data to it now */ PA_STREAM_FAILED, /**< An error occured that made the stream invalid */ @@ -83,9 +83,15 @@ typedef enum pa_operation_state { /** Some special flags for contexts. */ typedef enum pa_context_flags { - PA_CONTEXT_NOAUTOSPAWN = 1 /**< Disabled autospawning of the PulseAudio daemon if required */ + PA_CONTEXT_NOAUTOSPAWN = 1 + /**< Disabled autospawning of the PulseAudio daemon if required */ } pa_context_flags_t; +/** \cond fulldocs */ +/* Allow clients to check with #ifdef for those flags */ +#define PA_CONTEXT_NOAUTOSPAWN PA_CONTEXT_NOAUTOSPAWN +/** \endcond */ + /** The direction of a pa_stream object */ typedef enum pa_stream_direction { PA_STREAM_NODIRECTION, /**< Invalid direction */ @@ -96,237 +102,226 @@ typedef enum pa_stream_direction { /** Some special flags for stream connections. */ typedef enum pa_stream_flags { - PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */ - PA_STREAM_INTERPOLATE_TIMING = 2, /**< Interpolate the latency for - * this stream. When enabled, - * pa_stream_get_latency() and - * pa_stream_get_time() will try - * to estimate the current - * record/playback time based on - * the local time that passed - * since the last timing info - * update. Using this option - * has the advantage of not - * requiring a whole roundtrip - * when the current - * playback/recording time is - * needed. Consider using this - * option when requesting - * latency information - * frequently. This is - * especially useful on long - * latency network - * connections. It makes a lot - * of sense to combine this - * option with - * PA_STREAM_AUTO_TIMING_UPDATE. */ - PA_STREAM_NOT_MONOTONIC = 4, /**< Don't force the time to - * increase monotonically. If - * this option is enabled, - * pa_stream_get_time() will not - * necessarily return always - * monotonically increasing time - * values on each call. This may - * confuse applications which - * cannot deal with time going - * 'backwards', but has the - * advantage that bad transport - * latency estimations that - * caused the time to to jump - * ahead can be corrected - * quickly, without the need to - * wait. (Please note that this - * flag was named - * PA_STREAM_NOT_MONOTONOUS in - * releases prior to 0.9.11. The - * old name is still defined too, - * for compatibility reasons. */ - PA_STREAM_AUTO_TIMING_UPDATE = 8, /**< If set timing update requests - * are issued periodically - * automatically. Combined with - * PA_STREAM_INTERPOLATE_TIMING - * you will be able to query the - * current time and latency with - * pa_stream_get_time() and - * pa_stream_get_latency() at - * all times without a packet - * round trip.*/ - PA_STREAM_NO_REMAP_CHANNELS = 16, /**< Don't remap channels by - * their name, instead map them - * simply by their - * index. Implies - * PA_STREAM_NO_REMIX_CHANNELS. Only - * supported when the server is - * at least PA 0.9.8. It is - * ignored on older - * servers.\since 0.9.8 */ - PA_STREAM_NO_REMIX_CHANNELS = 32, /**< When remapping channels by - * name, don't upmix or downmix - * them to related - * channels. Copy them into - * matching channels of the - * device 1:1. Only supported - * when the server is at least - * PA 0.9.8. It is ignored on - * older servers. \since - * 0.9.8 */ - PA_STREAM_FIX_FORMAT = 64, /**< Use the sample format of the - * sink/device this stream is being - * connected to, and possibly ignore - * the format the sample spec contains - * -- but you still have to pass a - * valid value in it as a hint to - * PulseAudio what would suit your - * stream best. If this is used you - * should query the used sample format - * after creating the stream by using - * pa_stream_get_sample_spec(). Also, - * if you specified manual buffer - * metrics it is recommended to update - * them with - * pa_stream_set_buffer_attr() to - * compensate for the changed frame - * sizes. Only supported when the - * server is at least PA 0.9.8. It is - * ignored on older servers. \since - * 0.9.8 */ - - PA_STREAM_FIX_RATE = 128, /**< Use the sample rate of the sink, - * and possibly ignore the rate the - * sample spec contains. Usage similar - * to PA_STREAM_FIX_FORMAT.Only - * supported when the server is at least - * PA 0.9.8. It is ignored on older - * servers. \since 0.9.8 */ - - PA_STREAM_FIX_CHANNELS = 256, /**< Use the number of channels and - * the channel map of the sink, and - * possibly ignore the number of - * channels and the map the sample spec - * and the passed channel map - * contains. Usage similar to - * PA_STREAM_FIX_FORMAT. Only supported - * when the server is at least PA - * 0.9.8. It is ignored on older - * servers. \since 0.9.8 */ - PA_STREAM_DONT_MOVE = 512, /**< Don't allow moving of this stream to - * another sink/device. Useful if you use - * any of the PA_STREAM_FIX_ flags and - * want to make sure that resampling - * never takes place -- which might - * happen if the stream is moved to - * another sink/source whith a different - * sample spec/channel map. Only - * supported when the server is at least - * PA 0.9.8. It is ignored on older - * servers. \since 0.9.8 */ - PA_STREAM_VARIABLE_RATE = 1024, /**< Allow dynamic changing of the - * sampling rate during playback - * with - * pa_stream_update_sample_rate(). Only - * supported when the server is at - * least PA 0.9.8. It is ignored - * on older servers. \since - * 0.9.8 */ - PA_STREAM_PEAK_DETECT = 2048, /**< Find peaks instead of - * resampling. \since 0.9.11 */ - - PA_STREAM_START_MUTED = 4096, /**< Create in muted state. \since 0.9.11 */ - - PA_STREAM_ADJUST_LATENCY = 8192, /**< Try to adjust the latency of - * the sink/source based on the - * requested buffer metrics and - * adjust buffer metrics - * accordingly. See pa_buffer_attr \since 0.9.11 */ + + PA_STREAM_START_CORKED = 0x0001U, + /**< Create the stream corked, requiring an explicit + * pa_stream_cork() call to uncork it. */ + + PA_STREAM_INTERPOLATE_TIMING = 0x0002U, + /**< Interpolate the latency for this stream. When enabled, + * pa_stream_get_latency() and pa_stream_get_time() will try to + * estimate the current record/playback time based on the local + * time that passed since the last timing info update. Using this + * option has the advantage of not requiring a whole roundtrip + * when the current playback/recording time is needed. Consider + * using this option when requesting latency information + * frequently. This is especially useful on long latency network + * connections. It makes a lot of sense to combine this option + * with PA_STREAM_AUTO_TIMING_UPDATE. */ + + PA_STREAM_NOT_MONOTONIC = 0x0004U, + /**< Don't force the time to increase monotonically. If this + * option is enabled, pa_stream_get_time() will not necessarily + * return always monotonically increasing time values on each + * call. This may confuse applications which cannot deal with time + * going 'backwards', but has the advantage that bad transport + * latency estimations that caused the time to to jump ahead can + * be corrected quickly, without the need to wait. (Please note + * that this flag was named PA_STREAM_NOT_MONOTONOUS in releases + * prior to 0.9.11. The old name is still defined too, for + * compatibility reasons. */ + + PA_STREAM_AUTO_TIMING_UPDATE = 0x0008U, + /**< If set timing update requests are issued periodically + * automatically. Combined with PA_STREAM_INTERPOLATE_TIMING you + * will be able to query the current time and latency with + * pa_stream_get_time() and pa_stream_get_latency() at all times + * without a packet round trip.*/ + + PA_STREAM_NO_REMAP_CHANNELS = 0x0010U, + /**< Don't remap channels by their name, instead map them simply + * by their index. Implies PA_STREAM_NO_REMIX_CHANNELS. Only + * supported when the server is at least PA 0.9.8. It is ignored + * on older servers.\since 0.9.8 */ + + PA_STREAM_NO_REMIX_CHANNELS = 0x0020U, + /**< When remapping channels by name, don't upmix or downmix them + * to related channels. Copy them into matching channels of the + * device 1:1. Only supported when the server is at least PA + * 0.9.8. It is ignored on older servers. \since 0.9.8 */ + + PA_STREAM_FIX_FORMAT = 0x0040U, + /**< Use the sample format of the sink/device this stream is being + * connected to, and possibly ignore the format the sample spec + * contains -- but you still have to pass a valid value in it as a + * hint to PulseAudio what would suit your stream best. If this is + * used you should query the used sample format after creating the + * stream by using pa_stream_get_sample_spec(). Also, if you + * specified manual buffer metrics it is recommended to update + * them with pa_stream_set_buffer_attr() to compensate for the + * changed frame sizes. Only supported when the server is at least + * PA 0.9.8. It is ignored on older servers. \since 0.9.8 */ + + PA_STREAM_FIX_RATE = 0x0080U, + /**< Use the sample rate of the sink, and possibly ignore the rate + * the sample spec contains. Usage similar to + * PA_STREAM_FIX_FORMAT.Only supported when the server is at least + * PA 0.9.8. It is ignored on older servers. \since 0.9.8 */ + + PA_STREAM_FIX_CHANNELS = 0x0100, + /**< Use the number of channels and the channel map of the sink, + * and possibly ignore the number of channels and the map the + * sample spec and the passed channel map contains. Usage similar + * to PA_STREAM_FIX_FORMAT. Only supported when the server is at + * least PA 0.9.8. It is ignored on older servers. \since 0.9.8 */ + + PA_STREAM_DONT_MOVE = 0x0200U, + /**< Don't allow moving of this stream to another + * sink/device. Useful if you use any of the PA_STREAM_FIX_ flags + * and want to make sure that resampling never takes place -- + * which might happen if the stream is moved to another + * sink/source whith a different sample spec/channel map. Only + * supported when the server is at least PA 0.9.8. It is ignored + * on older servers. \since 0.9.8 */ + + PA_STREAM_VARIABLE_RATE = 0x0400U, + /**< Allow dynamic changing of the sampling rate during playback + * with pa_stream_update_sample_rate(). Only supported when the + * server is at least PA 0.9.8. It is ignored on older + * servers. \since 0.9.8 */ + + PA_STREAM_PEAK_DETECT = 0x0800U, + /**< Find peaks instead of resampling. \since 0.9.11 */ + + PA_STREAM_START_MUTED = 0x1000U, + /**< Create in muted state. If neither PA_STREAM_START_UNMUTED nor + * PA_STREAM_START_MUTED it is left to the server to decide + * whether to create the stream in muted or in unmuted + * state. \since 0.9.11 */ + + PA_STREAM_ADJUST_LATENCY = 0x2000U, + /**< Try to adjust the latency of the sink/source based on the + * requested buffer metrics and adjust buffer metrics + * accordingly. Also see pa_buffer_attr. This option may not be + * specified at the same time as PA_STREAM_EARLY_REQUESTS. \since + * 0.9.11 */ + + PA_STREAM_EARLY_REQUESTS = 0x4000U, + /**< Enable compatibility mode for legacy clients that rely on a + * "classic" hardware device fragment-style playback model. If + * this option is set, the minreq value of the buffer metrics gets + * a new meaning: instead of just specifying that no requests + * asking for less new data than this value will be made to the + * client it will also guarantee that requests are generated as + * early as this limit is reached. This flag should only be set in + * very few situations where compatiblity with a fragment-based + * playback model needs to be kept and the client applications + * cannot deal with data requests that are delayed to the latest + * moment possible. (Usually these are programs that use usleep() + * or a similar call in their playback loops instead of sleeping + * on the device itself.) Also see pa_buffer_attr. This option may + * not be specified at the same time as + * PA_STREAM_ADJUST_LATENCY. \since 0.9.12 */ + + PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND = 0x8000U, + /**< If set this stream won't be taken into account when we it is + * checked whether the device this stream is connected to should + * auto-suspend. \ since 0.9.14 */ + + PA_STREAM_START_UNMUTED = 0x10000U + /**< Create in unmuted state. If neither PA_STREAM_START_UNMUTED + * nor PA_STREAM_START_MUTED it is left to the server to decide + * whether to create the stream in muted or in unmuted + * state. \since 0.9.14 */ + } pa_stream_flags_t; +/** \cond fulldocs */ -/** English is an evil language */ +/* English is an evil language */ #define PA_STREAM_NOT_MONOTONOUS PA_STREAM_NOT_MONOTONIC +/* Allow clients to check with #ifdef for those flags */ +#define PA_STREAM_START_CORKED PA_STREAM_START_CORKED +#define PA_STREAM_INTERPOLATE_TIMING PA_STREAM_INTERPOLATE_TIMING +#define PA_STREAM_NOT_MONOTONIC PA_STREAM_NOT_MONOTONIC +#define PA_STREAM_AUTO_TIMING_UPDATE PA_STREAM_AUTO_TIMING_UPDATE +#define PA_STREAM_NO_REMAP_CHANNELS PA_STREAM_NO_REMAP_CHANNELS +#define PA_STREAM_NO_REMIX_CHANNELS PA_STREAM_NO_REMIX_CHANNELS +#define PA_STREAM_FIX_FORMAT PA_STREAM_FIX_FORMAT +#define PA_STREAM_FIX_RATE PA_STREAM_FIX_RATE +#define PA_STREAM_FIX_CHANNELS PA_STREAM_FIX_CHANNELS +#define PA_STREAM_DONT_MOVE PA_STREAM_DONT_MOVE +#define PA_STREAM_VARIABLE_RATE PA_STREAM_VARIABLE_RATE +#define PA_STREAM_PEAK_DETECT PA_STREAM_PEAK_DETECT +#define PA_STREAM_START_MUTED PA_STREAM_START_MUTED +#define PA_STREAM_ADJUST_LATENCY PA_STREAM_ADJUST_LATENCY +#define PA_STREAM_EARLY_REQUESTS PA_STREAM_EARLY_REQUESTS +#define PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND +#define PA_STREAM_START_UNMUTED PA_STREAM_START_UNMUTED + +/** \endcond */ + /** Playback and record buffer metrics */ typedef struct pa_buffer_attr { - uint32_t maxlength; /**< Maximum length of the - * buffer. Setting this to (uint32_t) -1 will - * initialize this to the maximum value - * supported by server, which is - * recommended. */ - uint32_t tlength; /**< Playback only: target length of the - * buffer. The server tries to assure - * that at least tlength bytes are always - * available in the per-stream - * server-side playback buffer. It is - * recommended to set this to (uint32_t) - * -1, which will initialize this to a - * value that is deemed sensible by the - * server. However, this value will - * default to something like 2s, i.e. for - * applications that have specific - * latency requirements this value should - * be set to the maximum latency that the - * application can deal with. When - * PA_STREAM_ADJUST_LATENCY is not set - * this value will influence only the - * per-stream playback buffer size. When - * PA_STREAM_ADJUST_LATENCY is set the - * overall latency of the sink plus the - * playback buffer size is configured to - * this value. Set - * PA_STREAM_ADJUST_LATENCY if you are - * interested in adjusting the overall - * latency. Don't set it if you are - * interested in configuring the - * server-sider per-stream playback - * buffer size. */ - uint32_t prebuf; /**< Playback only: pre-buffering. The - * server does not start with playback - * before at least prebug bytes are - * available in the buffer. It is - * recommended to set this to (uint32_t) - * -1, which will initialize this to the - * same value as tlength, whatever that - * may be. Initialize to 0 to enable - * manual start/stop control of the - * stream. This means that playback will - * not stop on underrun and playback will - * not start automatically. Instead - * pa_stream_corked() needs to be called - * explicitly. If you set this value to 0 - * you should also set - * PA_STREAM_START_CORKED. */ - uint32_t minreq; /**< Playback only: minimum request. The - * server does not request less than - * minreq bytes from the client, instead - * waits until the buffer is free enough - * to request more bytes at once. It is - * recommended to set this to (uint32_t) - * -1, which will initialize this to a - * value that is deemed sensible by the - * server. This should be set to a value - * that gives PulseAudio enough time to - * move the data from the per-stream - * playback buffer into the hardware - * playback buffer. */ - uint32_t fragsize; /**< Recording only: fragment size. The - * server sends data in blocks of - * fragsize bytes size. Large values - * deminish interactivity with other - * operations on the connection context - * but decrease control overhead. It is - * recommended to set this to (uint32_t) - * -1, which will initialize this to a - * value that is deemed sensible by the - * server. However, this value will - * default to something like 2s, i.e. for - * applications that have specific - * latency requirements this value should - * be set to the maximum latency that the - * application can deal with. If - * PA_STREAM_ADJUST_LATENCY is set the - * overall source latency will be - * adjusted according to this value. If - * it is not set the source latency is - * left unmodified. */ + uint32_t maxlength; + /**< Maximum length of the buffer. Setting this to (uint32_t) -1 + * will initialize this to the maximum value supported by server, + * which is recommended. */ + + uint32_t tlength; + /**< Playback only: target length of the buffer. The server tries + * to assure that at least tlength bytes are always available in + * the per-stream server-side playback buffer. It is recommended + * to set this to (uint32_t) -1, which will initialize this to a + * value that is deemed sensible by the server. However, this + * value will default to something like 2s, i.e. for applications + * that have specific latency requirements this value should be + * set to the maximum latency that the application can deal + * with. When PA_STREAM_ADJUST_LATENCY is not set this value will + * influence only the per-stream playback buffer size. When + * PA_STREAM_ADJUST_LATENCY is set the overall latency of the sink + * plus the playback buffer size is configured to this value. Set + * PA_STREAM_ADJUST_LATENCY if you are interested in adjusting the + * overall latency. Don't set it if you are interested in + * configuring the server-sider per-stream playback buffer + * size. */ + + uint32_t prebuf; + /**< Playback only: pre-buffering. The server does not start with + * playback before at least prebug bytes are available in the + * buffer. It is recommended to set this to (uint32_t) -1, which + * will initialize this to the same value as tlength, whatever + * that may be. Initialize to 0 to enable manual start/stop + * control of the stream. This means that playback will not stop + * on underrun and playback will not start automatically. Instead + * pa_stream_corked() needs to be called explicitly. If you set + * this value to 0 you should also set PA_STREAM_START_CORKED. */ + + uint32_t minreq; + /**< Playback only: minimum request. The server does not request + * less than minreq bytes from the client, instead waits until the + * buffer is free enough to request more bytes at once. It is + * recommended to set this to (uint32_t) -1, which will initialize + * this to a value that is deemed sensible by the server. This + * should be set to a value that gives PulseAudio enough time to + * move the data from the per-stream playback buffer into the + * hardware playback buffer. */ + + uint32_t fragsize; + /**< Recording only: fragment size. The server sends data in + * blocks of fragsize bytes size. Large values deminish + * interactivity with other operations on the connection context + * but decrease control overhead. It is recommended to set this to + * (uint32_t) -1, which will initialize this to a value that is + * deemed sensible by the server. However, this value will default + * to something like 2s, i.e. for applications that have specific + * latency requirements this value should be set to the maximum + * latency that the application can deal with. If + * PA_STREAM_ADJUST_LATENCY is set the overall source latency will + * be adjusted according to this value. If it is not set the + * source latency is left unmodified. */ + } pa_buffer_attr; /** Error values as used by pa_context_errno(). Use pa_strerror() to convert these values to human readable strings */ @@ -358,36 +353,84 @@ enum { /** Subscription event mask, as used by pa_context_subscribe() */ typedef enum pa_subscription_mask { - PA_SUBSCRIPTION_MASK_NULL = 0, /**< No events */ - PA_SUBSCRIPTION_MASK_SINK = 1, /**< Sink events */ - PA_SUBSCRIPTION_MASK_SOURCE = 2, /**< Source events */ - PA_SUBSCRIPTION_MASK_SINK_INPUT = 4, /**< Sink input events */ - PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT = 8, /**< Source output events */ - PA_SUBSCRIPTION_MASK_MODULE = 16, /**< Module events */ - PA_SUBSCRIPTION_MASK_CLIENT = 32, /**< Client events */ - PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 64, /**< Sample cache events */ - PA_SUBSCRIPTION_MASK_SERVER = 128, /**< Other global server changes. */ - PA_SUBSCRIPTION_MASK_AUTOLOAD = 256, /**< Autoload table events. */ - PA_SUBSCRIPTION_MASK_ALL = 511 /**< Catch all events */ + PA_SUBSCRIPTION_MASK_NULL = 0x0000U, + /**< No events */ + + PA_SUBSCRIPTION_MASK_SINK = 0x0001U, + /**< Sink events */ + + PA_SUBSCRIPTION_MASK_SOURCE = 0x0002U, + /**< Source events */ + + PA_SUBSCRIPTION_MASK_SINK_INPUT = 0x0004U, + /**< Sink input events */ + + PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT = 0x0008U, + /**< Source output events */ + + PA_SUBSCRIPTION_MASK_MODULE = 0x0010U, + /**< Module events */ + + PA_SUBSCRIPTION_MASK_CLIENT = 0x0020U, + /**< Client events */ + + PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 0x0040U, + /**< Sample cache events */ + + PA_SUBSCRIPTION_MASK_SERVER = 0x0080U, + /**< Other global server changes. */ + + PA_SUBSCRIPTION_MASK_AUTOLOAD = 0x0100U, + /**< Autoload table events. */ + + PA_SUBSCRIPTION_MASK_ALL = 0x01ffU + /**< Catch all events */ } pa_subscription_mask_t; /** Subscription event types, as used by pa_context_subscribe() */ typedef enum pa_subscription_event_type { - PA_SUBSCRIPTION_EVENT_SINK = 0, /**< Event type: Sink */ - PA_SUBSCRIPTION_EVENT_SOURCE = 1, /**< Event type: Source */ - PA_SUBSCRIPTION_EVENT_SINK_INPUT = 2, /**< Event type: Sink input */ - PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT = 3, /**< Event type: Source output */ - PA_SUBSCRIPTION_EVENT_MODULE = 4, /**< Event type: Module */ - PA_SUBSCRIPTION_EVENT_CLIENT = 5, /**< Event type: Client */ - PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE = 6, /**< Event type: Sample cache item */ - PA_SUBSCRIPTION_EVENT_SERVER = 7, /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. */ - PA_SUBSCRIPTION_EVENT_AUTOLOAD = 8, /**< Event type: Autoload table changes. */ - PA_SUBSCRIPTION_EVENT_FACILITY_MASK = 15, /**< A mask to extract the event type from an event value */ - - PA_SUBSCRIPTION_EVENT_NEW = 0, /**< A new object was created */ - PA_SUBSCRIPTION_EVENT_CHANGE = 16, /**< A property of the object was modified */ - PA_SUBSCRIPTION_EVENT_REMOVE = 32, /**< An object was removed */ - PA_SUBSCRIPTION_EVENT_TYPE_MASK = 16+32 /**< A mask to extract the event operation from an event value */ + PA_SUBSCRIPTION_EVENT_SINK = 0x0000U, + /**< Event type: Sink */ + + PA_SUBSCRIPTION_EVENT_SOURCE = 0x0001U, + /**< Event type: Source */ + + PA_SUBSCRIPTION_EVENT_SINK_INPUT = 0x0002U, + /**< Event type: Sink input */ + + PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT = 0x0003U, + /**< Event type: Source output */ + + PA_SUBSCRIPTION_EVENT_MODULE = 0x0004U, + /**< Event type: Module */ + + PA_SUBSCRIPTION_EVENT_CLIENT = 0x0005U, + /**< Event type: Client */ + + PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE = 0x0006U, + /**< Event type: Sample cache item */ + + PA_SUBSCRIPTION_EVENT_SERVER = 0x0007U, + /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. */ + + PA_SUBSCRIPTION_EVENT_AUTOLOAD = 0x0008U, + /**< Event type: Autoload table changes. */ + + PA_SUBSCRIPTION_EVENT_FACILITY_MASK = 0x000FU, + /**< A mask to extract the event type from an event value */ + + PA_SUBSCRIPTION_EVENT_NEW = 0x0000U, + /**< A new object was created */ + + PA_SUBSCRIPTION_EVENT_CHANGE = 0x0010U, + /**< A property of the object was modified */ + + PA_SUBSCRIPTION_EVENT_REMOVE = 0x0020U, + /**< An object was removed */ + + PA_SUBSCRIPTION_EVENT_TYPE_MASK = 0x0030U, + /**< A mask to extract the event operation from an event value */ + } pa_subscription_event_type_t; /** Return one if an event type t matches an event mask bitfield */ @@ -412,69 +455,71 @@ typedef enum pa_subscription_event_type { * note that this structure can be extended as part of evolutionary * API updates at any time in any new release.*/ typedef struct pa_timing_info { - struct timeval timestamp; /**< The time when this timing info structure was current */ - int synchronized_clocks; /**< Non-zero if the local and the - * remote machine have synchronized - * clocks. If synchronized clocks are - * detected transport_usec becomes much - * more reliable. However, the code that - * detects synchronized clocks is very - * limited und unreliable itself. */ - - pa_usec_t sink_usec; /**< Time in usecs a sample takes to be played on the sink. For playback streams and record streams connected to a monitor source. */ - pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. */ - pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. */ - - int playing; /**< Non-zero when the stream is - * currently not underrun and data is - * being passed on to the device. Only - * for playback streams. This field does - * not say whether the data is actually - * already being played. To determine - * this check whether since_underrun - * (converted to usec) is larger than - * sink_usec.*/ - - int write_index_corrupt; /**< Non-zero if write_index is not - * up-to-date because a local write - * command that corrupted it has been - * issued in the time since this latency - * info was current . Only write - * commands with SEEK_RELATIVE_ON_READ - * and SEEK_RELATIVE_END can corrupt - * write_index. */ - int64_t write_index; /**< Current write index into the - * playback buffer in bytes. Think twice before - * using this for seeking purposes: it - * might be out of date a the time you - * want to use it. Consider using - * PA_SEEK_RELATIVE instead. */ - - int read_index_corrupt; /**< Non-zero if read_index is not - * up-to-date because a local pause or - * flush request that corrupted it has - * been issued in the time since this - * latency info was current. */ - - int64_t read_index; /**< Current read index into the - * playback buffer in bytes. Think twice before - * using this for seeking purposes: it - * might be out of date a the time you - * want to use it. Consider using - * PA_SEEK_RELATIVE_ON_READ - * instead. */ - - pa_usec_t configured_sink_usec; /**< The configured latency for - * the sink. \since 0.9.11 */ - pa_usec_t configured_source_usec; /**< The configured latency for - * the source. \since 0.9.11 */ - - int64_t since_underrun; /**< Bytes that were handed to the sink - since the last underrun happened, or - since playback started again after - the last underrun. playing will tell - you which case it is. \since - 0.9.11 */ + struct timeval timestamp; + /**< The time when this timing info structure was current */ + + int synchronized_clocks; + /**< Non-zero if the local and the remote machine have + * synchronized clocks. If synchronized clocks are detected + * transport_usec becomes much more reliable. However, the code + * that detects synchronized clocks is very limited und unreliable + * itself. */ + + pa_usec_t sink_usec; + /**< Time in usecs a sample takes to be played on the sink. For + * playback streams and record streams connected to a monitor + * source. */ + + pa_usec_t source_usec; + /**< Time in usecs a sample takes from being recorded to being + * delivered to the application. Only for record streams. */ + + pa_usec_t transport_usec; + /**< Estimated time in usecs a sample takes to be transferred + * to/from the daemon. For both playback and record streams. */ + + int playing; + /**< Non-zero when the stream is currently not underrun and data + * is being passed on to the device. Only for playback + * streams. This field does not say whether the data is actually + * already being played. To determine this check whether + * since_underrun (converted to usec) is larger than sink_usec.*/ + + int write_index_corrupt; + /**< Non-zero if write_index is not up-to-date because a local + * write command that corrupted it has been issued in the time + * since this latency info was current . Only write commands with + * SEEK_RELATIVE_ON_READ and SEEK_RELATIVE_END can corrupt + * write_index. */ + + int64_t write_index; + /**< Current write index into the playback buffer in bytes. Think + * twice before using this for seeking purposes: it might be out + * of date a the time you want to use it. Consider using + * PA_SEEK_RELATIVE instead. */ + + int read_index_corrupt; + /**< Non-zero if read_index is not up-to-date because a local + * pause or flush request that corrupted it has been issued in the + * time since this latency info was current. */ + + int64_t read_index; + /**< Current read index into the playback buffer in bytes. Think + * twice before using this for seeking purposes: it might be out + * of date a the time you want to use it. Consider using + * PA_SEEK_RELATIVE_ON_READ instead. */ + + pa_usec_t configured_sink_usec; + /**< The configured latency for the sink. \since 0.9.11 */ + + pa_usec_t configured_source_usec; + /**< The configured latency for * the source. \since 0.9.11 */ + + int64_t since_underrun; + /**< Bytes that were handed to the sink since the last underrun + * happened, or since playback started again after the last + * underrun. playing will tell you which case it is. \since + * 0.9.11 */ } pa_timing_info; @@ -486,45 +531,101 @@ typedef struct pa_timing_info { * thread compatible way. You might have to do this in * prefork/postfork. */ typedef struct pa_spawn_api { - void (*prefork)(void); /**< Is called just before the fork in the parent process. May be NULL. */ - void (*postfork)(void); /**< Is called immediately after the fork in the parent process. May be NULL.*/ - void (*atfork)(void); /**< Is called immediately after the - * fork in the child process. May be - * NULL. It is not safe to close all - * file descriptors in this function - * unconditionally, since a UNIX socket - * (created using socketpair()) is - * passed to the new process. */ + void (*prefork)(void); + /**< Is called just before the fork in the parent process. May be + * NULL. */ + + void (*postfork)(void); + /**< Is called immediately after the fork in the parent + * process. May be NULL.*/ + + void (*atfork)(void); + /**< Is called immediately after the fork in the child + * process. May be NULL. It is not safe to close all file + * descriptors in this function unconditionally, since a UNIX + * socket (created using socketpair()) is passed to the new + * process. */ } pa_spawn_api; /** Seek type for pa_stream_write(). */ typedef enum pa_seek_mode { - PA_SEEK_RELATIVE = 0, /**< Seek relatively to the write index */ - PA_SEEK_ABSOLUTE = 1, /**< Seek relatively to the start of the buffer queue */ - PA_SEEK_RELATIVE_ON_READ = 2, /**< Seek relatively to the read index. */ - PA_SEEK_RELATIVE_END = 3 /**< Seek relatively to the current end of the buffer queue. */ + PA_SEEK_RELATIVE = 0, + /**< Seek relatively to the write index */ + + PA_SEEK_ABSOLUTE = 1, + /**< Seek relatively to the start of the buffer queue */ + + PA_SEEK_RELATIVE_ON_READ = 2, + /**< Seek relatively to the read index. */ + + PA_SEEK_RELATIVE_END = 3 + /**< Seek relatively to the current end of the buffer queue. */ } pa_seek_mode_t; /** Special sink flags. */ typedef enum pa_sink_flags { - PA_SINK_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */ - PA_SINK_LATENCY = 2, /**< Supports latency querying */ - PA_SINK_HARDWARE = 4, /**< Is a hardware sink of some kind, in contrast to "virtual"/software sinks \since 0.9.3 */ - PA_SINK_NETWORK = 8, /**< Is a networked sink of some kind. \since 0.9.7 */ - PA_SINK_HW_MUTE_CTRL = 16, /**< Supports hardware mute control \since 0.9.11 */ - PA_SINK_DECIBEL_VOLUME = 32 /**< Volume can be translated to dB with pa_sw_volume_to_dB() \since 0.9.11 */ + PA_SINK_HW_VOLUME_CTRL = 0x0001U, + /**< Supports hardware volume control */ + + PA_SINK_LATENCY = 0x0002U, + /**< Supports latency querying */ + + PA_SINK_HARDWARE = 0x0004U, + /**< Is a hardware sink of some kind, in contrast to + * "virtual"/software sinks \since 0.9.3 */ + + PA_SINK_NETWORK = 0x0008U, + /**< Is a networked sink of some kind. \since 0.9.7 */ + + PA_SINK_HW_MUTE_CTRL = 0x0010U, + /**< Supports hardware mute control \since 0.9.11 */ + + PA_SINK_DECIBEL_VOLUME = 0x0020U + /**< Volume can be translated to dB with pa_sw_volume_to_dB() + * \since 0.9.11 */ } pa_sink_flags_t; +/** \cond fulldocs */ +#define PA_SINK_HW_VOLUME_CTRL PA_SINK_HW_VOLUME_CTRL +#define PA_SINK_LATENCY PA_SINK_LATENCY +#define PA_SINK_HARDWARE PA_SINK_HARDWARE +#define PA_SINK_NETWORK PA_SINK_NETWORK +#define PA_SINK_HW_VOLUME_CTRL PA_SINK_HW_VOLUME_CTRL +#define PA_SINK_DECIBEL_VOLUME PA_SINK_DECIBEL_VOLUME +/** \endcond */ + /** Special source flags. */ typedef enum pa_source_flags { - PA_SOURCE_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */ - PA_SOURCE_LATENCY = 2, /**< Supports latency querying */ - PA_SOURCE_HARDWARE = 4, /**< Is a hardware source of some kind, in contrast to "virtual"/software source \since 0.9.3 */ - PA_SOURCE_NETWORK = 8, /**< Is a networked sink of some kind. \since 0.9.7 */ - PA_SOURCE_HW_MUTE_CTRL = 16, /**< Supports hardware mute control \since 0.9.11 */ - PA_SOURCE_DECIBEL_VOLUME = 32 /**< Volume can be translated to dB with pa_sw_volume_to_dB() \since 0.9.11 */ + PA_SOURCE_HW_VOLUME_CTRL = 0x0001U, + /**< Supports hardware volume control */ + + PA_SOURCE_LATENCY = 0x0002U, + /**< Supports latency querying */ + + PA_SOURCE_HARDWARE = 0x0004U, + /**< Is a hardware source of some kind, in contrast to + * "virtual"/software source \since 0.9.3 */ + + PA_SOURCE_NETWORK = 0x0008U, + /**< Is a networked sink of some kind. \since 0.9.7 */ + + PA_SOURCE_HW_MUTE_CTRL = 0x0010U, + /**< Supports hardware mute control \since 0.9.11 */ + + PA_SOURCE_DECIBEL_VOLUME = 0x0020U + /**< Volume can be translated to dB with pa_sw_volume_to_dB() + * \since 0.9.11 */ } pa_source_flags_t; +/** \cond fulldocs */ +#define PA_SOURCE_HW_VOLUME_CTRL PA_SOURCE_HW_VOLUME_CTRL +#define PA_SOURCE_LATENCY PA_SOURCE_LATENCY +#define PA_SOURCE_HARDWARE PA_SOURCE_HARDWARE +#define PA_SOURCE_NETWORK PA_SOURCE_NETWORK +#define PA_SOURCE_HW_VOLUME_CTRL PA_SOURCE_HW_VOLUME_CTRL +#define PA_SOURCE_DECIBEL_VOLUME PA_SOURCE_DECIBEL_VOLUME +/** \endcond */ + /** A generic free() like callback prototype */ typedef void (*pa_free_cb_t)(void *p); diff --git a/src/pulse/ext-stream-restore.h b/src/pulse/ext-stream-restore.h index a8eceaf1..2038eb4a 100644 --- a/src/pulse/ext-stream-restore.h +++ b/src/pulse/ext-stream-restore.h @@ -24,37 +24,49 @@ #include <pulse/context.h> +/** \file + * + * Routines for controlling module-stream-restore + */ + PA_C_DECL_BEGIN +/** Stores information about one entry in the stream database that is + * maintained by module-stream-restore. \since 0.9.12 */ typedef struct pa_ext_stream_restore_info { - const char *name; - pa_channel_map channel_map; - pa_cvolume volume; - const char *device; - int mute; + const char *name; /**< Identifier string of the stream. A string like "sink-input-by-role:" or similar followed by some arbitrary property value. */ + pa_channel_map channel_map; /**< The channel map for the volume field */ + pa_cvolume volume; /**< The volume of the stream when it was seen last, if applicable */ + const char *device; /**< The sink/source of the stream when it was last seen */ + int mute; /**< The boolean mute state of the stream when it was last seen, if applicable */ } pa_ext_stream_restore_info; +/** Callback prototype for pa_ext_stream_restore_test(). \since 0.9.12 */ typedef void (*pa_ext_stream_restore_test_cb_t)( pa_context *c, uint32_t version, void *userdata); +/** Test if this extension module is available in the server. \since 0.9.12 */ pa_operation *pa_ext_stream_restore_test( pa_context *c, pa_ext_stream_restore_test_cb_t cb, void *userdata); +/** Callback prototype for pa_ext_stream_restore_read(). \since 0.9.12 */ typedef void (*pa_ext_stream_restore_read_cb_t)( pa_context *c, const pa_ext_stream_restore_info *info, int eol, void *userdata); +/** Read all entries from the stream database. \since 0.9.12 */ pa_operation *pa_ext_stream_restore_read( pa_context *c, pa_ext_stream_restore_read_cb_t cb, void *userdata); +/** Store entries in the stream database. \since 0.9.12 */ pa_operation *pa_ext_stream_restore_write( pa_context *c, pa_update_mode_t mode, @@ -64,22 +76,27 @@ pa_operation *pa_ext_stream_restore_write( pa_context_success_cb_t cb, void *userdata); +/** Delete entries from the stream database. \since 0.9.12 */ pa_operation *pa_ext_stream_restore_delete( pa_context *c, const char *const s[], pa_context_success_cb_t cb, void *userdata); +/** Subscribe to changes in the stream database. \since 0.9.12 */ pa_operation *pa_ext_stream_restore_subscribe( pa_context *c, int enable, pa_context_success_cb_t cb, void *userdata); +/** Callback prototype for pa_ext_stream_restore_set_subscribe_cb(). \since 0.9.12 */ typedef void (*pa_ext_stream_restore_subscribe_cb_t)( pa_context *c, void *userdata); +/** Set the subscription callback that is called when + * pa_ext_stream_restore_subscribe() was called. \since 0.9.12 */ void pa_ext_stream_restore_set_subscribe_cb( pa_context *c, pa_ext_stream_restore_subscribe_cb_t cb, diff --git a/src/pulse/gccmacro.h b/src/pulse/gccmacro.h index e4062033..0533b109 100644 --- a/src/pulse/gccmacro.h +++ b/src/pulse/gccmacro.h @@ -93,4 +93,24 @@ #endif #endif +#ifndef PA_GCC_ALLOC_SIZE +#if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) +#define PA_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x))) +#define PA_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y))) +#else +/** Macro for usage of GCC's alloc_size attribute */ +#define PA_GCC_ALLOC_SIZE(x) +#define PA_GCC_ALLOC_SIZE2(x,y) +#endif +#endif + +#ifndef PA_GCC_MALLOC +#ifdef __GNUCC__ +#define PA_GCC_MALLOC __attribute__ ((malloc)) +#else +/** Macro for usage of GCC's malloc attribute */ +#define PA_GCC_MALLOC +#endif +#endif + #endif diff --git a/src/pulse/glib-mainloop.c b/src/pulse/glib-mainloop.c index 6ddb0faa..5f5dc494 100644 --- a/src/pulse/glib-mainloop.c +++ b/src/pulse/glib-mainloop.c @@ -195,11 +195,11 @@ static void cleanup_defer_events(pa_glib_mainloop *g, int force) { } static gushort map_flags_to_glib(pa_io_event_flags_t flags) { - return - (flags & PA_IO_EVENT_INPUT ? G_IO_IN : 0) | - (flags & PA_IO_EVENT_OUTPUT ? G_IO_OUT : 0) | - (flags & PA_IO_EVENT_ERROR ? G_IO_ERR : 0) | - (flags & PA_IO_EVENT_HANGUP ? G_IO_HUP : 0); + return (gushort) + ((flags & PA_IO_EVENT_INPUT ? G_IO_IN : 0) | + (flags & PA_IO_EVENT_OUTPUT ? G_IO_OUT : 0) | + (flags & PA_IO_EVENT_ERROR ? G_IO_ERR : 0) | + (flags & PA_IO_EVENT_HANGUP ? G_IO_HUP : 0)); } static pa_io_event_flags_t map_flags_from_glib(gushort flags) { @@ -425,7 +425,7 @@ static void glib_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy_cb_ /* quit() */ -static void glib_quit(pa_mainloop_api*a, PA_GCC_UNUSED int retval) { +static void glib_quit(pa_mainloop_api*a, int retval) { g_warning("quit() ignored"); @@ -536,7 +536,7 @@ static gboolean check_func(GSource *source) { return FALSE; } -static gboolean dispatch_func(GSource *source, PA_GCC_UNUSED GSourceFunc callback, PA_GCC_UNUSED gpointer userdata) { +static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer userdata) { pa_glib_mainloop *g = (pa_glib_mainloop*) source; pa_io_event *e; diff --git a/src/pulse/internal.h b/src/pulse/internal.h index bfe888ee..5fe4210e 100644 --- a/src/pulse/internal.h +++ b/src/pulse/internal.h @@ -64,7 +64,7 @@ struct pa_context { uint32_t version; uint32_t ctag; uint32_t csyncid; - uint32_t error; + int error; pa_context_state_t state; pa_context_notify_cb_t state_callback; @@ -75,9 +75,9 @@ struct pa_context { pa_mempool *mempool; pa_bool_t is_local:1; - pa_bool_t do_autospawn:1; pa_bool_t do_shm:1; - int autospawn_lock_fd; + + pa_bool_t do_autospawn:1; pa_spawn_api spawn_api; pa_strlist *server_list; diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c index 4be2c62a..38091581 100644 --- a/src/pulse/introspect.c +++ b/src/pulse/introspect.c @@ -24,6 +24,8 @@ #include <config.h> #endif +#include <string.h> + #include <pulse/context.h> #include <pulse/gccmacro.h> @@ -36,7 +38,7 @@ /*** Statistics ***/ -static void context_stat_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_stat_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; pa_stat_info i, *p = &i; @@ -79,7 +81,7 @@ pa_operation* pa_context_stat(pa_context *c, pa_stat_info_cb_t cb, void *userdat /*** Server Info ***/ -static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; pa_server_info i, *p = &i; @@ -127,7 +129,7 @@ pa_operation* pa_context_get_server_info(pa_context *c, pa_server_info_cb_t cb, /*** Sink Info ***/ -static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -248,7 +250,7 @@ pa_operation* pa_context_get_sink_info_by_name(pa_context *c, const char *name, /*** Source info ***/ -static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -369,7 +371,7 @@ pa_operation* pa_context_get_source_info_by_name(pa_context *c, const char *name /*** Client info ***/ -static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -451,7 +453,7 @@ pa_operation* pa_context_get_client_info_list(pa_context *c, pa_client_info_cb_t /*** Module info ***/ -static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -530,7 +532,7 @@ pa_operation* pa_context_get_module_info_list(pa_context *c, pa_module_info_cb_t /*** Sink input info ***/ -static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -624,7 +626,7 @@ pa_operation* pa_context_get_sink_input_info_list(pa_context *c, void (*cb)(pa_c /*** Source output info ***/ -static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -954,7 +956,7 @@ pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name /** Sample Cache **/ -static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; @@ -1098,7 +1100,7 @@ pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_cont return command_kill(c, PA_COMMAND_KILL_SOURCE_OUTPUT, idx, cb, userdata); } -static void context_index_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_index_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; uint32_t idx; @@ -1159,7 +1161,7 @@ pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_s /*** Autoload stuff ***/ -static void context_get_autoload_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void context_get_autoload_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int eol = 1; diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index ca79f5b7..087bd9f9 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -561,7 +561,7 @@ typedef enum pa_autoload_type { typedef struct pa_autoload_info { uint32_t index; /**< Index of this autoload entry */ const char *name; /**< Name of the sink or source */ - pa_autoload_type_t type; /**< Type of the autoload entry */ + pa_autoload_type_t type; /**< Type of the autoload entry */ const char *module; /**< Module name to load */ const char *argument; /**< Argument string for module */ } pa_autoload_info; diff --git a/src/pulse/mainloop-api.c b/src/pulse/mainloop-api.c index 4e3b135a..4b862f9a 100644 --- a/src/pulse/mainloop-api.c +++ b/src/pulse/mainloop-api.c @@ -51,7 +51,7 @@ static void once_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata) m->defer_free(e); } -static void free_callback(pa_mainloop_api *m, PA_GCC_UNUSED pa_defer_event *e, void *userdata) { +static void free_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata) { struct once_info *i = userdata; pa_assert(m); diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c index e95968ae..d09f4b0a 100644 --- a/src/pulse/mainloop-signal.c +++ b/src/pulse/mainloop-signal.c @@ -90,7 +90,7 @@ static void dispatch(pa_mainloop_api*a, int sig) { } } -static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, PA_GCC_UNUSED void *userdata) { +static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) { ssize_t r; int sig; diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c index 5823e280..60e5d1ff 100644 --- a/src/pulse/mainloop.c +++ b/src/pulse/mainloop.c @@ -57,7 +57,7 @@ struct pa_io_event { pa_mainloop *mainloop; - int dead; + pa_bool_t dead:1; int fd; pa_io_event_flags_t events; @@ -72,9 +72,9 @@ struct pa_io_event { struct pa_time_event { pa_mainloop *mainloop; - int dead; + pa_bool_t dead:1; - int enabled; + pa_bool_t enabled:1; struct timeval timeval; pa_time_event_cb_t callback; @@ -86,9 +86,9 @@ struct pa_time_event { struct pa_defer_event { pa_mainloop *mainloop; - int dead; + pa_bool_t dead:1; - int enabled; + pa_bool_t enabled:1; pa_defer_event_cb_t callback; void *userdata; @@ -102,22 +102,24 @@ struct pa_mainloop { PA_LLIST_HEAD(pa_time_event, time_events); PA_LLIST_HEAD(pa_defer_event, defer_events); - int n_enabled_defer_events, n_enabled_time_events, n_io_events; - int io_events_please_scan, time_events_please_scan, defer_events_please_scan; + unsigned n_enabled_defer_events, n_enabled_time_events, n_io_events; + unsigned io_events_please_scan, time_events_please_scan, defer_events_please_scan; + pa_bool_t rebuild_pollfds:1; struct pollfd *pollfds; unsigned max_pollfds, n_pollfds; - int rebuild_pollfds; int prepared_timeout; pa_time_event *cached_next_time_event; - int quit, retval; pa_mainloop_api api; + int retval; + pa_bool_t quit:1; + + pa_bool_t wakeup_requested:1; int wakeup_pipe[2]; int wakeup_pipe_type; - int wakeup_requested; enum { STATE_PASSIVE, @@ -133,11 +135,11 @@ struct pa_mainloop { }; static short map_flags_to_libc(pa_io_event_flags_t flags) { - return - (flags & PA_IO_EVENT_INPUT ? POLLIN : 0) | - (flags & PA_IO_EVENT_OUTPUT ? POLLOUT : 0) | - (flags & PA_IO_EVENT_ERROR ? POLLERR : 0) | - (flags & PA_IO_EVENT_HANGUP ? POLLHUP : 0); + return (short) + ((flags & PA_IO_EVENT_INPUT ? POLLIN : 0) | + (flags & PA_IO_EVENT_OUTPUT ? POLLOUT : 0) | + (flags & PA_IO_EVENT_ERROR ? POLLERR : 0) | + (flags & PA_IO_EVENT_HANGUP ? POLLHUP : 0)); } static pa_io_event_flags_t map_flags_from_libc(short flags) { @@ -169,7 +171,7 @@ static pa_io_event* mainloop_io_new( e = pa_xnew(pa_io_event, 1); e->mainloop = m; - e->dead = 0; + e->dead = FALSE; e->fd = fd; e->events = events; @@ -194,13 +196,13 @@ static pa_io_event* mainloop_io_new( SELECT_TYPE_ARG5 &tv) == -1) && (WSAGetLastError() == WSAENOTSOCK)) { pa_log_warn("Cannot monitor non-socket file descriptors."); - e->dead = 1; + e->dead = TRUE; } } #endif PA_LLIST_PREPEND(pa_io_event, m->io_events, e); - m->rebuild_pollfds = 1; + m->rebuild_pollfds = TRUE; m->n_io_events ++; pa_mainloop_wakeup(m); @@ -220,7 +222,7 @@ static void mainloop_io_enable(pa_io_event *e, pa_io_event_flags_t events) { if (e->pollfd) e->pollfd->events = map_flags_to_libc(events); else - e->mainloop->rebuild_pollfds = 1; + e->mainloop->rebuild_pollfds = TRUE; pa_mainloop_wakeup(e->mainloop); } @@ -229,11 +231,11 @@ static void mainloop_io_free(pa_io_event *e) { pa_assert(e); pa_assert(!e->dead); - e->dead = 1; + e->dead = TRUE; e->mainloop->io_events_please_scan ++; e->mainloop->n_io_events --; - e->mainloop->rebuild_pollfds = 1; + e->mainloop->rebuild_pollfds = TRUE; pa_mainloop_wakeup(e->mainloop); } @@ -262,9 +264,9 @@ static pa_defer_event* mainloop_defer_new( e = pa_xnew(pa_defer_event, 1); e->mainloop = m; - e->dead = 0; + e->dead = FALSE; - e->enabled = 1; + e->enabled = TRUE; m->n_enabled_defer_events++; e->callback = callback; @@ -297,13 +299,13 @@ static void mainloop_defer_free(pa_defer_event *e) { pa_assert(e); pa_assert(!e->dead); - e->dead = 1; + e->dead = TRUE; e->mainloop->defer_events_please_scan ++; if (e->enabled) { pa_assert(e->mainloop->n_enabled_defer_events > 0); e->mainloop->n_enabled_defer_events--; - e->enabled = 0; + e->enabled = FALSE; } } @@ -333,7 +335,7 @@ static pa_time_event* mainloop_time_new( e = pa_xnew(pa_time_event, 1); e->mainloop = m; - e->dead = 0; + e->dead = FALSE; if ((e->enabled = !!tv)) { e->timeval = *tv; @@ -388,13 +390,13 @@ static void mainloop_time_free(pa_time_event *e) { pa_assert(e); pa_assert(!e->dead); - e->dead = 1; + e->dead = TRUE; e->mainloop->time_events_please_scan ++; if (e->enabled) { pa_assert(e->mainloop->n_enabled_time_events > 0); e->mainloop->n_enabled_time_events--; - e->enabled = 0; + e->enabled = FALSE; } if (e->mainloop->cached_next_time_event == e) @@ -462,7 +464,7 @@ pa_mainloop *pa_mainloop_new(void) { pa_make_fd_nonblock(m->wakeup_pipe[1]); pa_make_fd_cloexec(m->wakeup_pipe[0]); pa_make_fd_cloexec(m->wakeup_pipe[1]); - m->wakeup_requested = 0; + m->wakeup_requested = FALSE; PA_LLIST_HEAD_INIT(pa_io_event, m->io_events); PA_LLIST_HEAD_INIT(pa_time_event, m->time_events); @@ -476,9 +478,10 @@ pa_mainloop *pa_mainloop_new(void) { m->pollfds = NULL; m->max_pollfds = m->n_pollfds = 0; - m->rebuild_pollfds = 1; + m->rebuild_pollfds = TRUE; - m->quit = m->retval = 0; + m->quit = FALSE; + m->retval = 0; m->api = vtable; m->api.userdata = m; @@ -492,7 +495,7 @@ pa_mainloop *pa_mainloop_new(void) { return m; } -static void cleanup_io_events(pa_mainloop *m, int force) { +static void cleanup_io_events(pa_mainloop *m, pa_bool_t force) { pa_io_event *e; e = m->io_events; @@ -515,7 +518,7 @@ static void cleanup_io_events(pa_mainloop *m, int force) { pa_xfree(e); - m->rebuild_pollfds = 1; + m->rebuild_pollfds = TRUE; } e = n; @@ -524,7 +527,7 @@ static void cleanup_io_events(pa_mainloop *m, int force) { pa_assert(m->io_events_please_scan == 0); } -static void cleanup_time_events(pa_mainloop *m, int force) { +static void cleanup_time_events(pa_mainloop *m, pa_bool_t force) { pa_time_event *e; e = m->time_events; @@ -545,7 +548,7 @@ static void cleanup_time_events(pa_mainloop *m, int force) { if (!e->dead && e->enabled) { pa_assert(m->n_enabled_time_events > 0); m->n_enabled_time_events--; - e->enabled = 0; + e->enabled = FALSE; } if (e->destroy_callback) @@ -560,7 +563,7 @@ static void cleanup_time_events(pa_mainloop *m, int force) { pa_assert(m->time_events_please_scan == 0); } -static void cleanup_defer_events(pa_mainloop *m, int force) { +static void cleanup_defer_events(pa_mainloop *m, pa_bool_t force) { pa_defer_event *e; e = m->defer_events; @@ -581,7 +584,7 @@ static void cleanup_defer_events(pa_mainloop *m, int force) { if (!e->dead && e->enabled) { pa_assert(m->n_enabled_defer_events > 0); m->n_enabled_defer_events--; - e->enabled = 0; + e->enabled = FALSE; } if (e->destroy_callback) @@ -600,9 +603,9 @@ static void cleanup_defer_events(pa_mainloop *m, int force) { void pa_mainloop_free(pa_mainloop* m) { pa_assert(m); - cleanup_io_events(m, 1); - cleanup_defer_events(m, 1); - cleanup_time_events(m, 1); + cleanup_io_events(m, TRUE); + cleanup_defer_events(m, TRUE); + cleanup_time_events(m, TRUE); pa_xfree(m->pollfds); @@ -615,13 +618,13 @@ static void scan_dead(pa_mainloop *m) { pa_assert(m); if (m->io_events_please_scan) - cleanup_io_events(m, 0); + cleanup_io_events(m, FALSE); if (m->time_events_please_scan) - cleanup_time_events(m, 0); + cleanup_time_events(m, FALSE); if (m->defer_events_please_scan) - cleanup_defer_events(m, 0); + cleanup_defer_events(m, FALSE); } static void rebuild_pollfds(pa_mainloop *m) { @@ -662,7 +665,7 @@ static void rebuild_pollfds(pa_mainloop *m) { m->n_pollfds++; } - m->rebuild_pollfds = 0; + m->rebuild_pollfds = FALSE; } static int dispatch_pollfds(pa_mainloop *m) { @@ -948,7 +951,7 @@ int pa_mainloop_run(pa_mainloop *m, int *retval) { void pa_mainloop_quit(pa_mainloop *m, int retval) { pa_assert(m); - m->quit = 1; + m->quit = TRUE; m->retval = retval; pa_mainloop_wakeup(m); } diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c index 9e0549ea..93bc0034 100644 --- a/src/pulse/proplist.c +++ b/src/pulse/proplist.c @@ -280,7 +280,7 @@ char *pa_proplist_to_string(pa_proplist *p) { char *c; pa_assert_se(pa_proplist_get(p, key, &value, &nbytes) == 0); - c = pa_xnew(char, nbytes*2+1); + c = pa_xmalloc(nbytes*2+1); pa_hexstr((const uint8_t*) value, nbytes, c, nbytes*2+1); pa_strbuf_printf(buf, "%s = hex:%s\n", key, c); diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h index 39d53303..c23ef238 100644 --- a/src/pulse/proplist.h +++ b/src/pulse/proplist.h @@ -168,9 +168,19 @@ int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t * /** Update mode enum for pa_proplist_update(). \since 0.9.11 */ typedef enum pa_update_mode { - PA_UPDATE_SET, /*< Replace the entirey property list with the new one. Don't keep any of the old data around */ - PA_UPDATE_MERGE, /*< Merge new property list into the existing one, not replacing any old entries if they share a common key with the new property list. */ - PA_UPDATE_REPLACE /*< Merge new property list into the existing one, replacing all old entries that share a common key with the new property list. */ + PA_UPDATE_SET, + /*< Replace the entirey property list with the new one. Don't keep + * any of the old data around */ + + PA_UPDATE_MERGE, + /*< Merge new property list into the existing one, not replacing + * any old entries if they share a common key with the new + * property list. */ + + PA_UPDATE_REPLACE + /*< Merge new property list into the existing one, replacing all + * old entries that share a common key with the new property + * list. */ } pa_update_mode_t; /** Merge property list "other" into "p", adhering the merge mode as diff --git a/src/pulse/sample.c b/src/pulse/sample.c index 93da2465..29501595 100644 --- a/src/pulse/sample.c +++ b/src/pulse/sample.c @@ -80,6 +80,16 @@ size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) { return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * pa_frame_size(spec); } +pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec) { + pa_assert(spec); + + spec->format = PA_SAMPLE_INVALID; + spec->rate = 0; + spec->channels = 0; + + return spec; +} + int pa_sample_spec_valid(const pa_sample_spec *spec) { pa_assert(spec); @@ -131,7 +141,7 @@ char *pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) { pa_init_i18n(); if (!pa_sample_spec_valid(spec)) - pa_snprintf(s, l, _("Invalid")); + pa_snprintf(s, l, _("(invalid)")); else pa_snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels, spec->rate); diff --git a/src/pulse/sample.h b/src/pulse/sample.h index 2680cf7e..3c7dd0e7 100644 --- a/src/pulse/sample.h +++ b/src/pulse/sample.h @@ -120,17 +120,38 @@ PA_C_DECL_BEGIN /** Sample format */ typedef enum pa_sample_format { - PA_SAMPLE_U8, /**< Unsigned 8 Bit PCM */ - PA_SAMPLE_ALAW, /**< 8 Bit a-Law */ - PA_SAMPLE_ULAW, /**< 8 Bit mu-Law */ - PA_SAMPLE_S16LE, /**< Signed 16 Bit PCM, little endian (PC) */ - PA_SAMPLE_S16BE, /**< Signed 16 Bit PCM, big endian */ - PA_SAMPLE_FLOAT32LE, /**< 32 Bit IEEE floating point, little endian, range -1 to 1 */ - PA_SAMPLE_FLOAT32BE, /**< 32 Bit IEEE floating point, big endian, range -1 to 1 */ - PA_SAMPLE_S32LE, /**< Signed 32 Bit PCM, little endian (PC) */ - PA_SAMPLE_S32BE, /**< Signed 32 Bit PCM, big endian (PC) */ - PA_SAMPLE_MAX, /**< Upper limit of valid sample types */ - PA_SAMPLE_INVALID = -1 /**< An invalid value */ + PA_SAMPLE_U8, + /**< Unsigned 8 Bit PCM */ + + PA_SAMPLE_ALAW, + /**< 8 Bit a-Law */ + + PA_SAMPLE_ULAW, + /**< 8 Bit mu-Law */ + + PA_SAMPLE_S16LE, + /**< Signed 16 Bit PCM, little endian (PC) */ + + PA_SAMPLE_S16BE, + /**< Signed 16 Bit PCM, big endian */ + + PA_SAMPLE_FLOAT32LE, + /**< 32 Bit IEEE floating point, little endian, range -1 to 1 */ + + PA_SAMPLE_FLOAT32BE, + /**< 32 Bit IEEE floating point, big endian, range -1 to 1 */ + + PA_SAMPLE_S32LE, + /**< Signed 32 Bit PCM, little endian (PC) */ + + PA_SAMPLE_S32BE, + /**< Signed 32 Bit PCM, big endian (PC) */ + + PA_SAMPLE_MAX, + /**< Upper limit of valid sample types */ + + PA_SAMPLE_INVALID = -1 + /**< An invalid value */ } pa_sample_format_t; #ifdef WORDS_BIGENDIAN @@ -164,11 +185,29 @@ typedef enum pa_sample_format { /** A Shortcut for PA_SAMPLE_FLOAT32NE */ #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE +/** \cond fulldocs */ +/* Allow clients to check with #ifdef for thse sample formats */ +#define PA_SAMPLE_U8 PA_SAMPLE_U8 +#define PA_SAMPLE_ALAW PA_SAMPLE_ALAW +#define PA_SAMPLE_ULAW PA_SAMPLE_ULAW +#define PA_SAMPLE_S16LE PA_SAMPLE_S16LE +#define PA_SAMPLE_S16BE PA_SAMPLE_S16BE +#define PA_SAMPLE_FLOAT32LE PA_SAMPLE_FLOAT32LE +#define PA_SAMPLE_FLOAT32BE PA_SAMPLE_FLOAT32BE +#define PA_SAMPLE_S32LE PA_SAMPLE_S32LE +#define PA_SAMPLE_S32BE PA_SAMPLE_S32BE +/** \endcond */ + /** A sample format and attribute specification */ typedef struct pa_sample_spec { - pa_sample_format_t format; /**< The sample format */ - uint32_t rate; /**< The sample rate. (e.g. 44100) */ - uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */ + pa_sample_format_t format; + /**< The sample format */ + + uint32_t rate; + /**< The sample rate. (e.g. 44100) */ + + uint8_t channels; + /**< Audio channels. (1 for mono, 2 for stereo, ...) */ } pa_sample_spec; /** Type for usec specifications (unsigned). Always 64 bit. */ @@ -183,12 +222,21 @@ size_t pa_frame_size(const pa_sample_spec *spec) PA_GCC_PURE; /** Return the size of a sample with the specific sample type */ size_t pa_sample_size(const pa_sample_spec *spec) PA_GCC_PURE; -/** Calculate the time the specified bytes take to play with the specified sample type */ +/** Calculate the time the specified bytes take to play with the + * specified sample type. The return value will always be rounded + * down for non-integral return values. */ pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) PA_GCC_PURE; -/** Calculates the number of bytes that are required for the specified time. \since 0.9 */ +/** Calculates the number of bytes that are required for the specified + * time. The return value will always be rounded down for non-integral + * return values. \since 0.9 */ size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) PA_GCC_PURE; +/** Initialize the specified sample spec and return a pointer to + * it. The sample spec will have a defined state but + * pa_sample_spec_valid() will fail for it. \since 0.9.13 */ +pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec); + /** Return non-zero when the sample type specification is valid */ int pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE; @@ -201,7 +249,11 @@ const char *pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_PURE; /** Parse a sample format text. Inverse of pa_sample_format_to_string() */ pa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE; -/** Maximum required string length for pa_sample_spec_snprint() */ +/** Maximum required string length for + * pa_sample_spec_snprint(). Please note that this value can change + * with any release without warning and without being considered API + * or ABI breakage. You should not use this definition anywhere where + * it might become part of an ABI. */ #define PA_SAMPLE_SPEC_SNPRINT_MAX 32 /** Pretty print a sample type specification to a string */ diff --git a/src/pulse/scache.c b/src/pulse/scache.c index 5e31e7af..fd3b9876 100644 --- a/src/pulse/scache.c +++ b/src/pulse/scache.c @@ -47,6 +47,7 @@ int pa_stream_connect_upload(pa_stream *s, size_t length) { PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_UNCONNECTED, PA_ERR_BADSTATE); PA_CHECK_VALIDITY(s->context, length > 0, PA_ERR_INVALID); + PA_CHECK_VALIDITY(s->context, length == (size_t) (uint32_t) length, PA_ERR_INVALID); if (!(name = pa_proplist_gets(s->proplist, PA_PROP_EVENT_ID))) name = pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME); @@ -63,7 +64,7 @@ int pa_stream_connect_upload(pa_stream *s, size_t length) { pa_tagstruct_puts(t, name); pa_tagstruct_put_sample_spec(t, &s->sample_spec); pa_tagstruct_put_channel_map(t, &s->channel_map); - pa_tagstruct_putu32(t, length); + pa_tagstruct_putu32(t, (uint32_t) length); if (s->context->version >= 13) { pa_init_proplist(s->proplist); diff --git a/src/pulse/simple.c b/src/pulse/simple.c index 51160ad7..79e39ebb 100644 --- a/src/pulse/simple.c +++ b/src/pulse/simple.c @@ -272,7 +272,7 @@ int pa_simple_write(pa_simple *p, const void*data, size_t length, int *rerror) { if (l > length) l = length; - r = pa_stream_write(p->stream, data, l, NULL, 0, PA_SEEK_RELATIVE); + r = pa_stream_write(p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE); CHECK_SUCCESS_GOTO(p, rerror, r >= 0, unlock_and_fail); data = (const uint8_t*) data + l; diff --git a/src/pulse/stream.c b/src/pulse/stream.c index 585518f0..c0ae4ac2 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -86,7 +86,7 @@ pa_stream *pa_stream_new_with_proplist( pa_assert(PA_REFCNT_VALUE(c) >= 1); PA_CHECK_VALIDITY_RETURN_NULL(c, ss && pa_sample_spec_valid(ss), PA_ERR_INVALID); - PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 12 || (ss->format != PA_SAMPLE_S32LE || ss->format != PA_SAMPLE_S32NE), PA_ERR_NOTSUPPORTED); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 12 || (ss->format != PA_SAMPLE_S32LE && ss->format != PA_SAMPLE_S32BE), PA_ERR_NOTSUPPORTED); PA_CHECK_VALIDITY_RETURN_NULL(c, !map || (pa_channel_map_valid(map) && map->channels == ss->channels), PA_ERR_INVALID); PA_CHECK_VALIDITY_RETURN_NULL(c, name || (p && pa_proplist_contains(p, PA_PROP_MEDIA_NAME)), PA_ERR_INVALID); @@ -124,7 +124,7 @@ pa_stream *pa_stream_new_with_proplist( * what older PA versions provided. */ s->buffer_attr.maxlength = (uint32_t) -1; - s->buffer_attr.tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */ + s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */ s->buffer_attr.minreq = (uint32_t) -1; s->buffer_attr.prebuf = (uint32_t) -1; s->buffer_attr.fragsize = (uint32_t) -1; @@ -315,7 +315,7 @@ static void request_auto_timing_update(pa_stream *s, pa_bool_t force) { } } -void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_context *c = userdata; pa_stream *s; uint32_t channel; @@ -382,7 +382,7 @@ static void check_smoother_status(pa_stream *s, pa_bool_t aposteriori, pa_bool_t * if prebuf is non-zero! */ } -void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_context *c = userdata; pa_stream *s; uint32_t channel; @@ -479,7 +479,7 @@ finish: pa_context_unref(c); } -void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_context *c = userdata; pa_stream *s; uint32_t channel; @@ -557,13 +557,13 @@ void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, request_auto_timing_update(s, TRUE); if (s->started_callback) - s->started_callback(s, s->suspended_userdata); + s->started_callback(s, s->started_userdata); finish: pa_context_unref(c); } -void pa_command_request(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_stream *s; pa_context *c = userdata; uint32_t bytes, channel; @@ -598,7 +598,7 @@ finish: pa_context_unref(c); } -void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_stream *s; pa_context *c = userdata; uint32_t channel; @@ -670,7 +670,7 @@ static void invalidate_indexes(pa_stream *s, pa_bool_t r, pa_bool_t w) { request_auto_timing_update(s, TRUE); } -static void auto_timing_update_callback(PA_GCC_UNUSED pa_mainloop_api *m, PA_GCC_UNUSED pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { +static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) { pa_stream *s = userdata; pa_assert(s); @@ -694,7 +694,7 @@ static void create_stream_complete(pa_stream *s) { if (s->flags & PA_STREAM_AUTO_TIMING_UPDATE) { struct timeval tv; pa_gettimeofday(&tv); - tv.tv_usec += LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */ + tv.tv_usec += (suseconds_t) LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */ pa_assert(!s->auto_timing_update_event); s->auto_timing_update_event = s->mainloop->time_new(s->mainloop, &tv, &auto_timing_update_callback, s); @@ -722,7 +722,7 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s attr->maxlength = 4*1024*1024; /* 4MB is the maximum queue length PulseAudio <= 0.9.9 supported. */ if (attr->tlength == (uint32_t) -1) - attr->tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */ + attr->tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */ if (attr->minreq == (uint32_t) -1) attr->minreq = (attr->tlength)/5; /* Ask for more data when there are only 200ms left in the playback buffer */ @@ -734,7 +734,7 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s attr->fragsize = attr->tlength; /* Pass data to the app only when the buffer is filled up once */ } -void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_stream *s = userdata; pa_assert(pd); @@ -865,6 +865,7 @@ static int create_stream( pa_tagstruct *t; uint32_t tag; + pa_bool_t volume_set = FALSE; pa_assert(s); pa_assert(PA_REFCNT_VALUE(s) >= 1); @@ -885,7 +886,10 @@ static int create_stream( PA_STREAM_VARIABLE_RATE| PA_STREAM_PEAK_DETECT| PA_STREAM_START_MUTED| - PA_STREAM_ADJUST_LATENCY)), PA_ERR_INVALID); + PA_STREAM_ADJUST_LATENCY| + PA_STREAM_EARLY_REQUESTS| + PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND| + PA_STREAM_START_UNMUTED)), PA_ERR_INVALID); PA_CHECK_VALIDITY(s->context, s->context->version >= 12 || !(flags & PA_STREAM_VARIABLE_RATE), PA_ERR_NOTSUPPORTED); PA_CHECK_VALIDITY(s->context, s->context->version >= 13 || !(flags & PA_STREAM_PEAK_DETECT), PA_ERR_NOTSUPPORTED); @@ -898,6 +902,7 @@ static int create_stream( PA_CHECK_VALIDITY(s->context, direction == PA_STREAM_RECORD || !(flags & (PA_STREAM_PEAK_DETECT)), PA_ERR_INVALID); PA_CHECK_VALIDITY(s->context, !volume || volume->channels == s->sample_spec.channels, PA_ERR_INVALID); PA_CHECK_VALIDITY(s->context, !sync_stream || (direction == PA_STREAM_PLAYBACK && sync_stream->direction == PA_STREAM_PLAYBACK), PA_ERR_INVALID); + PA_CHECK_VALIDITY(s->context, (flags & (PA_STREAM_ADJUST_LATENCY|PA_STREAM_EARLY_REQUESTS)) != (PA_STREAM_ADJUST_LATENCY|PA_STREAM_EARLY_REQUESTS), PA_ERR_INVALID); pa_stream_ref(s); @@ -930,7 +935,7 @@ static int create_stream( t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM, + (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM), &tag); if (s->context->version < 13) @@ -957,6 +962,8 @@ static int create_stream( PA_TAG_U32, s->syncid, PA_TAG_INVALID); + volume_set = !!volume; + if (!volume) volume = pa_cvolume_reset(&cv, s->sample_spec.channels); @@ -994,6 +1001,22 @@ static int create_stream( pa_tagstruct_putu32(t, s->direct_on_input); } + if (s->context->version >= 14) { + + if (s->direction == PA_STREAM_PLAYBACK) + pa_tagstruct_put_boolean(t, volume_set); + + pa_tagstruct_put_boolean(t, flags & PA_STREAM_EARLY_REQUESTS); + } + + if (s->context->version >= 15) { + + if (s->direction == PA_STREAM_PLAYBACK) + pa_tagstruct_put_boolean(t, flags & (PA_STREAM_START_MUTED|PA_STREAM_START_UNMUTED)); + + pa_tagstruct_put_boolean(t, flags & PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND); + } + pa_pstream_send_tagstruct(s->context->pstream, t); pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL); @@ -1093,7 +1116,7 @@ int pa_stream_write( free_cb((void*) data); if (length < s->requested_bytes) - s->requested_bytes -= length; + s->requested_bytes -= (uint32_t) length; else s->requested_bytes = 0; @@ -1107,10 +1130,10 @@ int pa_stream_write( if (seek == PA_SEEK_ABSOLUTE) { s->write_index_corrections[s->current_write_index_correction].corrupt = FALSE; s->write_index_corrections[s->current_write_index_correction].absolute = TRUE; - s->write_index_corrections[s->current_write_index_correction].value = offset + length; + s->write_index_corrections[s->current_write_index_correction].value = offset + (int64_t) length; } else if (seek == PA_SEEK_RELATIVE) { if (!s->write_index_corrections[s->current_write_index_correction].corrupt) - s->write_index_corrections[s->current_write_index_correction].value += offset + length; + s->write_index_corrections[s->current_write_index_correction].value += offset + (int64_t) length; } else s->write_index_corrections[s->current_write_index_correction].corrupt = TRUE; } @@ -1120,10 +1143,10 @@ int pa_stream_write( if (seek == PA_SEEK_ABSOLUTE) { s->timing_info.write_index_corrupt = FALSE; - s->timing_info.write_index = offset + length; + s->timing_info.write_index = offset + (int64_t) length; } else if (seek == PA_SEEK_RELATIVE) { if (!s->timing_info.write_index_corrupt) - s->timing_info.write_index += offset + length; + s->timing_info.write_index += offset + (int64_t) length; } else s->timing_info.write_index_corrupt = TRUE; } @@ -1173,7 +1196,7 @@ int pa_stream_drop(pa_stream *s) { /* Fix the simulated local read index */ if (s->timing_info_valid && !s->timing_info.read_index_corrupt) - s->timing_info.read_index += s->peek_memchunk.length; + s->timing_info.read_index += (int64_t) s->peek_memchunk.length; pa_assert(s->peek_data); pa_memblock_release(s->peek_memchunk.memblock); @@ -1257,7 +1280,9 @@ static pa_usec_t calc_time(pa_stream *s, pa_bool_t ignore_transport) { usec -= s->timing_info.sink_usec; } - } else if (s->direction == PA_STREAM_RECORD) { + } else { + pa_assert(s->direction == PA_STREAM_RECORD); + /* The last byte written into the server side queue had * this time value associated */ usec = pa_bytes_to_usec(s->timing_info.write_index < 0 ? 0 : (uint64_t) s->timing_info.write_index, &s->sample_spec); @@ -1340,7 +1365,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command, i->read_index_corrupt = FALSE; i->playing = (int) playing; - i->since_underrun = playing ? playing_for : underrun_for; + i->since_underrun = (int64_t) (playing ? playing_for : underrun_for); pa_gettimeofday(&now); @@ -1418,7 +1443,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command, /* Read index correction */ if (!i->read_index_corrupt) - i->read_index -= pa_memblockq_get_length(o->stream->record_memblockq); + i->read_index -= (int64_t) pa_memblockq_get_length(o->stream->record_memblockq); } /* Update smoother */ @@ -1435,7 +1460,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command, * speakers. Since we follow that timing here, we need * to try to fix this up */ - su = pa_bytes_to_usec(i->since_underrun, &o->stream->sample_spec); + su = pa_bytes_to_usec((uint64_t) i->since_underrun, &o->stream->sample_spec); if (su < i->sink_usec) x += i->sink_usec - su; @@ -1494,7 +1519,7 @@ pa_operation* pa_stream_update_timing_info(pa_stream *s, pa_stream_success_cb_t t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_GET_PLAYBACK_LATENCY : PA_COMMAND_GET_RECORD_LATENCY, + (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_GET_PLAYBACK_LATENCY : PA_COMMAND_GET_RECORD_LATENCY), &tag); pa_tagstruct_putu32(t, s->channel); pa_tagstruct_put_timeval(t, pa_gettimeofday(&now)); @@ -1517,7 +1542,7 @@ pa_operation* pa_stream_update_timing_info(pa_stream *s, pa_stream_success_cb_t return o; } -void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_stream *s = userdata; pa_assert(pd); @@ -1557,8 +1582,8 @@ int pa_stream_disconnect(pa_stream *s) { t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_DELETE_PLAYBACK_STREAM : - (s->direction == PA_STREAM_RECORD ? PA_COMMAND_DELETE_RECORD_STREAM : PA_COMMAND_DELETE_UPLOAD_STREAM), + (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_DELETE_PLAYBACK_STREAM : + (s->direction == PA_STREAM_RECORD ? PA_COMMAND_DELETE_RECORD_STREAM : PA_COMMAND_DELETE_UPLOAD_STREAM)), &tag); pa_tagstruct_putu32(t, s->channel); pa_pstream_send_tagstruct(s->context->pstream, t); @@ -1667,7 +1692,7 @@ void pa_stream_set_started_callback(pa_stream *s, pa_stream_notify_cb_t cb, void s->started_userdata = userdata; } -void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int success = 1; @@ -1715,7 +1740,7 @@ pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, voi t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CORK_PLAYBACK_STREAM : PA_COMMAND_CORK_RECORD_STREAM, + (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CORK_PLAYBACK_STREAM : PA_COMMAND_CORK_RECORD_STREAM), &tag); pa_tagstruct_putu32(t, s->channel); pa_tagstruct_put_boolean(t, !!b); @@ -1760,7 +1785,7 @@ pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *use PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE); - if (!(o = stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata))) + if (!(o = stream_send_simple_command(s, (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM), cb, userdata))) return NULL; if (s->direction == PA_STREAM_PLAYBACK) { @@ -1836,7 +1861,7 @@ pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_succe if (s->context->version >= 13) { pa_proplist *p = pa_proplist_new(); - pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, name); + pa_proplist_sets(p, PA_PROP_MEDIA_NAME, name); o = pa_stream_proplist_update(s, PA_UPDATE_REPLACE, p, cb, userdata); pa_proplist_free(p); } else { @@ -1846,7 +1871,7 @@ pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_succe o = pa_operation_new(s->context, s, (pa_operation_cb_t) cb, userdata); t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_NAME : PA_COMMAND_SET_PLAYBACK_STREAM_NAME, + (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_NAME : PA_COMMAND_SET_PLAYBACK_STREAM_NAME), &tag); pa_tagstruct_putu32(t, s->channel); pa_tagstruct_puts(t, name); @@ -1932,7 +1957,7 @@ int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative) { if (cindex < 0) cindex = 0; - c = pa_bytes_to_usec(cindex, &s->sample_spec); + c = pa_bytes_to_usec((uint64_t) cindex, &s->sample_spec); if (s->direction == PA_STREAM_PLAYBACK) *r_usec = time_counter_diff(s, c, t, negative); @@ -1948,7 +1973,7 @@ const pa_timing_info* pa_stream_get_timing_info(pa_stream *s) { PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE); - PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->timing_info_valid, PA_ERR_BADSTATE); + PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->timing_info_valid, PA_ERR_NODATA); return &s->timing_info; } @@ -1978,7 +2003,7 @@ const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s) { return &s->buffer_attr; } -static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int success = 1; @@ -1995,7 +2020,6 @@ static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, success = 0; } else { - if (o->stream->direction == PA_STREAM_PLAYBACK) { if (pa_tagstruct_getu32(t, &o->stream->buffer_attr.maxlength) < 0 || pa_tagstruct_getu32(t, &o->stream->buffer_attr.tlength) < 0 || @@ -2012,6 +2036,20 @@ static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, } } + if (o->stream->context->version >= 13) { + pa_usec_t usec; + + if (pa_tagstruct_get_usec(t, &usec) < 0) { + pa_context_fail(o->context, PA_ERR_PROTOCOL); + goto finish; + } + + if (o->stream->direction == PA_STREAM_RECORD) + o->stream->timing_info.configured_source_usec = usec; + else + o->stream->timing_info.configured_sink_usec = usec; + } + if (!pa_tagstruct_eof(t)) { pa_context_fail(o->context, PA_ERR_PROTOCOL); goto finish; @@ -2046,7 +2084,7 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR : PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR, + (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR : PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR), &tag); pa_tagstruct_putu32(t, s->channel); @@ -2065,6 +2103,9 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr if (s->context->version >= 13) pa_tagstruct_put_boolean(t, !!(s->flags & PA_STREAM_ADJUST_LATENCY)); + if (s->context->version >= 14) + pa_tagstruct_put_boolean(t, !!(s->flags & PA_STREAM_EARLY_REQUESTS)); + pa_pstream_send_tagstruct(s->context->pstream, t); pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_set_buffer_attr_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref); @@ -2120,7 +2161,7 @@ int pa_stream_is_corked(pa_stream *s) { return s->corked; } -static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_operation *o = userdata; int success = 1; @@ -2177,7 +2218,7 @@ pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_strea t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE : PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE, + (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE : PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE), &tag); pa_tagstruct_putu32(t, s->channel); pa_tagstruct_putu32(t, rate); @@ -2205,7 +2246,7 @@ pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_ t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST : PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST, + (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST : PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST), &tag); pa_tagstruct_putu32(t, s->channel); pa_tagstruct_putu32(t, (uint32_t) mode); @@ -2238,7 +2279,7 @@ pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], t = pa_tagstruct_command( s->context, - s->direction == PA_STREAM_RECORD ? PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST : PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST, + (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST : PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST), &tag); pa_tagstruct_putu32(t, s->channel); diff --git a/src/pulse/stream.h b/src/pulse/stream.h index 2a8f7a8b..6cb363c8 100644 --- a/src/pulse/stream.h +++ b/src/pulse/stream.h @@ -473,7 +473,7 @@ void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, vo /** Set the callback function that is called when a the server starts * playback after an underrun or on initial startup. This only informs - * that audio is flowing again, it is no indication that audio startet + * that audio is flowing again, it is no indication that audio started * to reach the speakers already. (Only for playback streams). \since * 0.9.11 */ void pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); diff --git a/src/pulse/subscribe.c b/src/pulse/subscribe.c index b8d3be89..e12d1446 100644 --- a/src/pulse/subscribe.c +++ b/src/pulse/subscribe.c @@ -34,7 +34,7 @@ #include "subscribe.h" -void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { +void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_context *c = userdata; pa_subscription_event_type_t e; uint32_t idx; diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c index 9708a735..376cf13c 100644 --- a/src/pulse/timeval.c +++ b/src/pulse/timeval.c @@ -90,13 +90,13 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) { } /* Calculate the second difference*/ - r = ((pa_usec_t) a->tv_sec - b->tv_sec) * PA_USEC_PER_SEC; + r = ((pa_usec_t) a->tv_sec - (pa_usec_t) b->tv_sec) * PA_USEC_PER_SEC; /* Calculate the microsecond difference */ if (a->tv_usec > b->tv_usec) - r += ((pa_usec_t) a->tv_usec - b->tv_usec); + r += ((pa_usec_t) a->tv_usec - (pa_usec_t) b->tv_usec); else if (a->tv_usec < b->tv_usec) - r -= ((pa_usec_t) b->tv_usec - a->tv_usec); + r -= ((pa_usec_t) b->tv_usec - (pa_usec_t) a->tv_usec); return r; } @@ -132,7 +132,7 @@ struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) { pa_assert(tv); secs = (unsigned long) (v/PA_USEC_PER_SEC); - tv->tv_sec += secs; + tv->tv_sec += (time_t) secs; v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC; tv->tv_usec += (suseconds_t) v; @@ -140,7 +140,7 @@ struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) { /* Normalize */ while ((unsigned) tv->tv_usec >= PA_USEC_PER_SEC) { tv->tv_sec++; - tv->tv_usec -= PA_USEC_PER_SEC; + tv->tv_usec -= (suseconds_t) PA_USEC_PER_SEC; } return tv; @@ -151,14 +151,14 @@ struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) { pa_assert(tv); secs = (unsigned long) (v/PA_USEC_PER_SEC); - tv->tv_sec -= secs; + tv->tv_sec -= (time_t) secs; v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC; if (tv->tv_usec >= (suseconds_t) v) tv->tv_usec -= (suseconds_t) v; else { tv->tv_sec --; - tv->tv_usec = tv->tv_usec + PA_USEC_PER_SEC - v; + tv->tv_usec += (suseconds_t) (PA_USEC_PER_SEC - v); } return tv; @@ -167,8 +167,8 @@ struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) { struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) { pa_assert(tv); - tv->tv_sec = v / PA_USEC_PER_SEC; - tv->tv_usec = v % PA_USEC_PER_SEC; + tv->tv_sec = (time_t) (v / PA_USEC_PER_SEC); + tv->tv_usec = (suseconds_t) (v % PA_USEC_PER_SEC); return tv; } diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c index 119be542..7671be46 100644 --- a/src/pulse/utf8.c +++ b/src/pulse/utf8.c @@ -64,24 +64,24 @@ #define FILTER_CHAR '_' -static inline int is_unicode_valid(uint32_t ch) { +static inline pa_bool_t is_unicode_valid(uint32_t ch) { if (ch >= 0x110000) /* End of unicode space */ - return 0; + return FALSE; if ((ch & 0xFFFFF800) == 0xD800) /* Reserved area for UTF-16 */ - return 0; + return FALSE; if ((ch >= 0xFDD0) && (ch <= 0xFDEF)) /* Reserved */ - return 0; + return FALSE; if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */ - return 0; + return FALSE; - return 1; + return TRUE; } -static inline int is_continuation_char(uint8_t ch) { +static inline pa_bool_t is_continuation_char(uint8_t ch) { if ((ch & 0xc0) != 0x80) /* 10xxxxxx */ - return 0; - return 1; + return FALSE; + return TRUE; } static inline void merge_continuation_char(uint32_t *u_ch, uint8_t ch) { @@ -109,17 +109,17 @@ static char* utf8_validate(const char *str, char *output) { if ((*p & 0xe0) == 0xc0) { /* 110xxxxx two-char seq. */ size = 2; min = 128; - val = *p & 0x1e; + val = (uint32_t) (*p & 0x1e); goto ONE_REMAINING; } else if ((*p & 0xf0) == 0xe0) { /* 1110xxxx three-char seq.*/ size = 3; min = (1 << 11); - val = *p & 0x0f; + val = (uint32_t) (*p & 0x0f); goto TWO_REMAINING; } else if ((*p & 0xf8) == 0xf0) { /* 11110xxx four-char seq */ size = 4; min = (1 << 16); - val = *p & 0x07; + val = (uint32_t) (*p & 0x07); } else { size = 1; goto error; @@ -149,7 +149,7 @@ ONE_REMAINING: goto error; if (o) { - memcpy(o, last, size); + memcpy(o, last, (size_t) size); o += size - 1; } @@ -189,7 +189,7 @@ char* pa_utf8_filter (const char *str) { char *new_str; pa_assert(str); - new_str = pa_xnew(char, strlen(str) + 1); + new_str = pa_xmalloc(strlen(str) + 1); return utf8_validate(str, new_str); } @@ -212,7 +212,7 @@ static char* iconv_simple(const char *str, const char *to, const char *from) { return NULL; inlen = len = strlen(str) + 1; - new_str = pa_xnew(char, len); + new_str = pa_xmalloc(len); for (;;) { inbuf = (ICONV_CONST char*) str; /* Brain dead prototype for iconv() */ diff --git a/src/pulse/util.c b/src/pulse/util.c index f785a2e9..b20ea46a 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -95,12 +95,15 @@ char *pa_get_user_name(char *s, size_t l) { #elif defined(OS_IS_WIN32) /* HAVE_PWD_H */ DWORD size = sizeof(buf); - if (!GetUserName(buf, &size)) + if (!GetUserName(buf, &size)) { + errno = ENOENT; return NULL; + } p = buf; #else /* HAVE_PWD_H */ + return NULL; #endif /* HAVE_PWD_H */ } @@ -138,6 +141,8 @@ char *pa_get_home_dir(char *s, size_t l) { return pa_strlcpy(s, e, l); #ifdef HAVE_PWD_H + + errno = 0; #ifdef HAVE_GETPWUID_R if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) { #else @@ -145,11 +150,16 @@ char *pa_get_home_dir(char *s, size_t l) { * that do not support getpwuid_r. */ if ((r = getpwuid(getuid())) == NULL) { #endif + if (!errno) + errno = ENOENT; + return NULL; } return pa_strlcpy(s, r->pw_dir, l); #else /* HAVE_PWD_H */ + + errno = ENOENT; return NULL; #endif } @@ -200,6 +210,7 @@ char *pa_get_binary_name(char *s, size_t l) { } #endif + errno = ENOENT; return NULL; } @@ -249,8 +260,8 @@ int pa_msleep(unsigned long t) { #elif defined(HAVE_NANOSLEEP) struct timespec ts; - ts.tv_sec = t/1000; - ts.tv_nsec = (t % 1000) * 1000000; + ts.tv_sec = (time_t) (t/1000UL); + ts.tv_nsec = (long) ((t % 1000UL) * 1000000UL); return nanosleep(&ts, NULL); #else diff --git a/src/pulse/volume.c b/src/pulse/volume.c index 625eb19a..99a85f44 100644 --- a/src/pulse/volume.c +++ b/src/pulse/volume.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <string.h> +#include <pulse/i18n.h> #include <pulsecore/core-util.h> #include <pulsecore/macro.h> @@ -46,6 +47,19 @@ int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) { return 1; } +pa_cvolume* pa_cvolume_init(pa_cvolume *a) { + unsigned c; + + pa_assert(a); + + a->channels = 0; + + for (c = 0; c < PA_CHANNELS_MAX; c++) + a->values[c] = (pa_volume_t) -1; + + return a; +} + pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) { int i; @@ -53,7 +67,7 @@ pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) { pa_assert(channels > 0); pa_assert(channels <= PA_CHANNELS_MAX); - a->channels = channels; + a->channels = (uint8_t) channels; for (i = 0; i < a->channels; i++) a->values[i] = v; @@ -74,8 +88,29 @@ pa_volume_t pa_cvolume_avg(const pa_cvolume *a) { return (pa_volume_t) sum; } +pa_volume_t pa_cvolume_max(const pa_cvolume *a) { + pa_volume_t m = 0; + int i; + pa_assert(a); + + for (i = 0; i < a->channels; i++) + if (a->values[i] > m) + m = a->values[i]; + + return m; +} + pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) { - return pa_sw_volume_from_linear(pa_sw_volume_to_linear(a)* pa_sw_volume_to_linear(b)); + return pa_sw_volume_from_linear(pa_sw_volume_to_linear(a) * pa_sw_volume_to_linear(b)); +} + +pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) { + double v = pa_sw_volume_to_linear(b); + + if (v <= 0) + return 0; + + return pa_sw_volume_from_linear(pa_sw_volume_to_linear(a) / v); } #define USER_DECIBEL_RANGE 60 @@ -84,7 +119,7 @@ pa_volume_t pa_sw_volume_from_dB(double dB) { if (isinf(dB) < 0 || dB <= -USER_DECIBEL_RANGE) return PA_VOLUME_MUTED; - return (pa_volume_t) ((dB/USER_DECIBEL_RANGE+1)*PA_VOLUME_NORM); + return (pa_volume_t) lrint((dB/USER_DECIBEL_RANGE+1)*PA_VOLUME_NORM); } double pa_sw_volume_to_dB(pa_volume_t v) { @@ -110,18 +145,25 @@ double pa_sw_volume_to_linear(pa_volume_t v) { if (v == PA_VOLUME_MUTED) return 0; - return pow(10, pa_sw_volume_to_dB(v)/20); + return pow(10.0, pa_sw_volume_to_dB(v)/20.0); } char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c) { unsigned channel; - int first = 1; + pa_bool_t first = TRUE; char *e; pa_assert(s); pa_assert(l > 0); pa_assert(c); + pa_init_i18n(); + + if (!pa_cvolume_valid(c)) { + pa_snprintf(s, l, _("(invalid)")); + return s; + } + *(e = s) = 0; for (channel = 0; channel < c->channels && l > 1; channel++) { @@ -131,7 +173,38 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c) { (c->values[channel]*100)/PA_VOLUME_NORM); e = strchr(e, 0); - first = 0; + first = FALSE; + } + + return s; +} + +char *pa_sw_cvolume_snprint_dB(char *s, size_t l, const pa_cvolume *c) { + unsigned channel; + pa_bool_t first = TRUE; + char *e; + + pa_assert(s); + pa_assert(l > 0); + pa_assert(c); + + pa_init_i18n(); + + if (!pa_cvolume_valid(c)) { + pa_snprintf(s, l, _("(invalid)")); + return s; + } + + *(e = s) = 0; + + for (channel = 0; channel < c->channels && l > 1; channel++) { + l -= pa_snprintf(e, l, "%s%u: %0.2f dB", + first ? "" : " ", + channel, + pa_sw_volume_to_dB(c->values[channel])); + + e = strchr(e, 0); + first = FALSE; } return s; @@ -156,24 +229,41 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_assert(a); pa_assert(b); - for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) { + for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) + dest->values[i] = pa_sw_volume_multiply(a->values[i], b->values[i]); - dest->values[i] = pa_sw_volume_multiply( - i < a->channels ? a->values[i] : PA_VOLUME_NORM, - i < b->channels ? b->values[i] : PA_VOLUME_NORM); - } + dest->channels = (uint8_t) i; - dest->channels = i; + return dest; +} + +pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) { + unsigned i; + + pa_assert(dest); + pa_assert(a); + pa_assert(b); + + for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) + dest->values[i] = pa_sw_volume_divide(a->values[i], b->values[i]); + + dest->channels = (uint8_t) i; return dest; } int pa_cvolume_valid(const pa_cvolume *v) { + unsigned c; + pa_assert(v); if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX) return 0; + for (c = 0; c < v->channels; c++) + if (v->values[c] == (pa_volume_t) -1) + return 0; + return 1; } @@ -261,3 +351,17 @@ pa_cvolume *pa_cvolume_remap(pa_cvolume *v, pa_channel_map *from, pa_channel_map *v = result; return v; } + +int pa_cvolume_compatible(const pa_cvolume *v, const pa_sample_spec *ss) { + + pa_assert(v); + pa_assert(ss); + + if (!pa_cvolume_valid(v)) + return 0; + + if (!pa_sample_spec_valid(ss)) + return 0; + + return v->channels == ss->channels; +} diff --git a/src/pulse/volume.h b/src/pulse/volume.h index 4fdbf658..75051af5 100644 --- a/src/pulse/volume.h +++ b/src/pulse/volume.h @@ -62,7 +62,7 @@ * * The functions described above are only valid when used with * software volumes. Hence it is usually a better idea to treat all - * volume values as opaque with a range from PA_VOLUME_MUTE (0%) to + * volume values as opaque with a range from PA_VOLUME_MUTED (0%) to * PA_VOLUME_NORM (100%) and to refrain from any calculations with * them. * @@ -116,6 +116,11 @@ typedef struct pa_cvolume { /** Return non-zero when *a == *b */ int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) PA_GCC_PURE; +/** Initialize the specified volume and return a pointer to + * it. The sample spec will have a defined state but + * pa_cvolume_valid() will fail for it. \since 0.9.13 */ +pa_cvolume* pa_cvolume_init(pa_cvolume *a); + /** Set the volume of all channels to PA_VOLUME_NORM */ #define pa_cvolume_reset(a, n) pa_cvolume_set((a), (n), PA_VOLUME_NORM) @@ -125,15 +130,32 @@ int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) PA_GCC_PURE; /** Set the volume of all channels to the specified parameter */ pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v); -/** Maximum length of the strings returned by pa_cvolume_snprint() */ -#define PA_CVOLUME_SNPRINT_MAX 64 +/** Maximum length of the strings returned by + * pa_cvolume_snprint(). Please note that this value can change with + * any release without warning and without being considered API or ABI + * breakage. You should not use this definition anywhere where it + * might become part of an ABI.*/ +#define PA_CVOLUME_SNPRINT_MAX 320 /** Pretty print a volume structure */ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c); +/** Maximum length of the strings returned by + * pa_cvolume_snprint_dB(). Please note that this value can change with + * any release without warning and without being considered API or ABI + * breakage. You should not use this definition anywhere where it + * might become part of an ABI. \since 0.9.13 */ +#define PA_SW_CVOLUME_SNPRINT_DB_MAX 448 + +/** Pretty print a volume structure but show dB values. \since 0.9.13 */ +char *pa_sw_cvolume_snprint_dB(char *s, size_t l, const pa_cvolume *c); + /** Return the average volume of all channels */ pa_volume_t pa_cvolume_avg(const pa_cvolume *a) PA_GCC_PURE; +/** Return the maximum volume of all channels. \since 0.9.12 */ +pa_volume_t pa_cvolume_max(const pa_cvolume *a) PA_GCC_PURE; + /** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */ int pa_cvolume_valid(const pa_cvolume *v) PA_GCC_PURE; @@ -146,12 +168,25 @@ int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) PA_GCC_PURE /** Return 1 if the specified volume has all channels on normal level */ #define pa_cvolume_is_norm(a) pa_cvolume_channels_equal_to((a), PA_VOLUME_NORM) -/** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. This is only valid for software volumes! */ +/** Multiply two volume specifications, return the result. This uses + * PA_VOLUME_NORM as neutral element of multiplication. This is only + * valid for software volumes! */ pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) PA_GCC_CONST; -/** Multiply to per-channel volumes and return the result in *dest. This is only valid for software volumes! */ +/** Multiply two per-channel volumes and return the result in + * *dest. This is only valid for software volumes! */ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b); +/** Divide two volume specifications, return the result. This uses + * PA_VOLUME_NORM as neutral element of division. This is only valid + * for software volumes! If a division by zero is tried the result + * will be 0. \since 0.9.13 */ +pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) PA_GCC_CONST; + +/** Multiply to per-channel volumes and return the result in + * *dest. This is only valid for software volumes! \since 0.9.13 */ +pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b); + /** Convert a decibel value to a volume. This is only valid for software volumes! */ pa_volume_t pa_sw_volume_from_dB(double f) PA_GCC_CONST; @@ -174,6 +209,10 @@ double pa_sw_volume_to_linear(pa_volume_t v) PA_GCC_CONST; /** Remap a volume from one channel mapping to a different channel mapping. \since 0.9.12 */ pa_cvolume *pa_cvolume_remap(pa_cvolume *v, pa_channel_map *from, pa_channel_map *to); +/** Return non-zero if the specified volume is compatible with + * the specified sample spec. \since 0.9.13 */ +int pa_cvolume_compatible(const pa_cvolume *v, const pa_sample_spec *ss) PA_GCC_PURE; + PA_C_DECL_END #endif diff --git a/src/pulse/xmalloc.c b/src/pulse/xmalloc.c index 90237013..c570e40f 100644 --- a/src/pulse/xmalloc.c +++ b/src/pulse/xmalloc.c @@ -36,7 +36,7 @@ #include "xmalloc.h" /* Make sure not to allocate more than this much memory. */ -#define MAX_ALLOC_SIZE (1024*1024*20) /* 20MB */ +#define MAX_ALLOC_SIZE (1024*1024*96) /* 96MB */ /* #undef malloc */ /* #undef free */ @@ -46,7 +46,7 @@ static void oom(void) PA_GCC_NORETURN; -/** called in case of an OOM situation. Prints an error message and +/* called in case of an OOM situation. Prints an error message and * exits */ static void oom(void) { static const char e[] = "Not enough memory\n"; @@ -113,7 +113,7 @@ char *pa_xstrndup(const char *s, size_t l) { return NULL; if ((e = memchr(s, 0, l))) - return pa_xmemdup(s, e-s+1); + return pa_xmemdup(s, (size_t) (e-s+1)); r = pa_xmalloc(l+1); memcpy(r, s, l); diff --git a/src/pulse/xmalloc.h b/src/pulse/xmalloc.h index c453138b..b2643588 100644 --- a/src/pulse/xmalloc.h +++ b/src/pulse/xmalloc.h @@ -26,7 +26,9 @@ #include <stdlib.h> #include <limits.h> #include <assert.h> + #include <pulse/cdecl.h> +#include <pulse/gccmacro.h> /** \file * Memory allocation functions. @@ -35,52 +37,58 @@ PA_C_DECL_BEGIN /** Allocate the specified number of bytes, just like malloc() does. However, in case of OOM, terminate */ -void* pa_xmalloc(size_t l); +void* pa_xmalloc(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1); /** Same as pa_xmalloc(), but initialize allocated memory to 0 */ -void *pa_xmalloc0(size_t l); +void *pa_xmalloc0(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1); /** The combination of pa_xmalloc() and realloc() */ -void *pa_xrealloc(void *ptr, size_t size); +void *pa_xrealloc(void *ptr, size_t size) PA_GCC_ALLOC_SIZE(2); /** Free allocated memory */ void pa_xfree(void *p); /** Duplicate the specified string, allocating memory with pa_xmalloc() */ -char *pa_xstrdup(const char *s); +char *pa_xstrdup(const char *s) PA_GCC_MALLOC; /** Duplicate the specified string, but truncate after l characters */ -char *pa_xstrndup(const char *s, size_t l); +char *pa_xstrndup(const char *s, size_t l) PA_GCC_MALLOC; /** Duplicate the specified memory block */ -void* pa_xmemdup(const void *p, size_t l); +void* pa_xmemdup(const void *p, size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(2); /** Internal helper for pa_xnew() */ -static inline void* pa_xnew_internal(unsigned n, size_t k) { +static void* _pa_xnew_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2); + +static inline void* _pa_xnew_internal(size_t n, size_t k) { assert(n < INT_MAX/k); return pa_xmalloc(n*k); } /** Allocate n new structures of the specified type. */ -#define pa_xnew(type, n) ((type*) pa_xnew_internal((n), sizeof(type))) +#define pa_xnew(type, n) ((type*) _pa_xnew_internal((n), sizeof(type))) /** Internal helper for pa_xnew0() */ -static inline void* pa_xnew0_internal(unsigned n, size_t k) { +static void* _pa_xnew0_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2); + +static inline void* _pa_xnew0_internal(size_t n, size_t k) { assert(n < INT_MAX/k); return pa_xmalloc0(n*k); } /** Same as pa_xnew() but set the memory to zero */ -#define pa_xnew0(type, n) ((type*) pa_xnew0_internal((n), sizeof(type))) +#define pa_xnew0(type, n) ((type*) _pa_xnew0_internal((n), sizeof(type))) /** Internal helper for pa_xnew0() */ -static inline void* pa_xnewdup_internal(const void *p, unsigned n, size_t k) { +static void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(2,3); + +static inline void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) { assert(n < INT_MAX/k); return pa_xmemdup(p, n*k); } /** Same as pa_xnew() but set the memory to zero */ -#define pa_xnewdup(type, p, n) ((type*) pa_xnewdup_internal((p), (n), sizeof(type))) +#define pa_xnewdup(type, p, n) ((type*) _pa_xnewdup_internal((p), (n), sizeof(type))) PA_C_DECL_END |