summaryrefslogtreecommitdiff
path: root/src/pulse
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-11-21 01:30:40 +0000
committerLennart Poettering <lennart@poettering.net>2007-11-21 01:30:40 +0000
commit14a9b80afbb0bddc216462b72156f14e032e1b5e (patch)
tree4b76ca3fe8eb313a3d6e1eb866fdc1589383cfc6 /src/pulse
parent4ac6b53478be63ae5d0163a330e67e4134f17f89 (diff)
- Check process name when dealing with PID files
- Add new PA_STREAM_FIX_CHANNELS, FIX_RATE, FIX_FORMAT, DONT_MOVE, VARIABLE_RATES to pa_sream_flags_t adn implement it - Expose those flags in pacat - Add notifications about device suspend/resume to the protocol and expose them in libpulse - Allow changing of buffer_attr during playback - allow disabling for remixing globally - hookup polkit support git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2067 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/context.c9
-rw-r--r--src/pulse/def.h79
-rw-r--r--src/pulse/internal.h16
-rw-r--r--src/pulse/operation.c2
-rw-r--r--src/pulse/stream.c436
-rw-r--r--src/pulse/stream.h71
6 files changed, 593 insertions, 20 deletions
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 805cd44ee..bc960e21d 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -86,6 +86,10 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_UNDERFLOW] = pa_command_overflow_or_underflow,
[PA_COMMAND_PLAYBACK_STREAM_KILLED] = pa_command_stream_killed,
[PA_COMMAND_RECORD_STREAM_KILLED] = pa_command_stream_killed,
+ [PA_COMMAND_PLAYBACK_STREAM_MOVED] = pa_command_stream_moved,
+ [PA_COMMAND_RECORD_STREAM_MOVED] = pa_command_stream_moved,
+ [PA_COMMAND_PLAYBACK_STREAM_SUSPENDED] = pa_command_stream_suspended,
+ [PA_COMMAND_RECORD_STREAM_SUSPENDED] = pa_command_stream_suspended,
[PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event
};
@@ -396,7 +400,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
/* Enable shared memory support if possible */
if (c->version >= 10 &&
pa_mempool_is_shared(c->mempool) &&
- c->is_local) {
+ c->is_local > 0) {
/* Only enable SHM if both sides are owned by the same
* user. This is a security measure because otherwise
@@ -965,6 +969,9 @@ pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_
int pa_context_is_local(pa_context *c) {
pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY(c, c->is_local >= 0, PA_ERR_BADSTATE);
return c->is_local;
}
diff --git a/src/pulse/def.h b/src/pulse/def.h
index a7c475db8..dabbc5eb0 100644
--- a/src/pulse/def.h
+++ b/src/pulse/def.h
@@ -122,7 +122,7 @@ typedef enum pa_stream_flags {
* ahead can be corrected
* quickly, without the need to
* wait. */
- PA_STREAM_AUTO_TIMING_UPDATE = 8 /**< If set timing update requests
+ PA_STREAM_AUTO_TIMING_UPDATE = 8, /**< If set timing update requests
* are issued periodically
* automatically. Combined with
* PA_STREAM_INTERPOLATE_TIMING
@@ -132,6 +132,83 @@ typedef enum pa_stream_flags {
* 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_flags_t;
/** Playback and record buffer metrics */
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index 95593adb0..873f1363b 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -103,6 +103,7 @@ struct pa_stream {
PA_LLIST_FIELDS(pa_stream);
char *name;
+ pa_bool_t manual_buffer_attr;
pa_buffer_attr buffer_attr;
pa_sample_spec sample_spec;
pa_channel_map channel_map;
@@ -110,12 +111,17 @@ struct pa_stream {
uint32_t channel;
uint32_t syncid;
int channel_valid;
- uint32_t device_index;
+ uint32_t stream_index;
pa_stream_direction_t direction;
pa_stream_state_t state;
+ pa_bool_t buffer_attr_not_ready, timing_info_not_ready;
uint32_t requested_bytes;
+ uint32_t device_index;
+ char *device_name;
+ pa_bool_t suspended;
+
pa_memchunk peek_memchunk;
void *peek_data;
pa_memblockq *record_memblockq;
@@ -157,6 +163,10 @@ struct pa_stream {
void *underflow_userdata;
pa_stream_notify_cb_t latency_update_callback;
void *latency_update_userdata;
+ pa_stream_notify_cb_t moved_callback;
+ void *moved_userdata;
+ pa_stream_notify_cb_t suspended_callback;
+ void *suspended_userdata;
};
typedef void (*pa_operation_cb_t)(void);
@@ -172,12 +182,16 @@ struct pa_operation {
pa_operation_state_t state;
void *userdata;
pa_operation_cb_t callback;
+
+ void *private; /* some operations might need this */
};
void pa_command_request(pa_pdispatch *pd, uint32_t command, 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);
void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, 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);
+void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, 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_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
void pa_operation_done(pa_operation *o);
diff --git a/src/pulse/operation.c b/src/pulse/operation.c
index 8a782fd17..5d2da5b8f 100644
--- a/src/pulse/operation.c
+++ b/src/pulse/operation.c
@@ -44,6 +44,7 @@ pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb
PA_REFCNT_INIT(o);
o->context = c;
o->stream = s;
+ o->private = NULL;
o->state = PA_OPERATION_RUNNING;
o->callback = cb;
@@ -63,7 +64,6 @@ pa_operation *pa_operation_ref(pa_operation *o) {
PA_REFCNT_INC(o);
return o;
}
-
void pa_operation_unref(pa_operation *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 47906a5cf..92420825b 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -51,6 +51,7 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
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, !map || (pa_channel_map_valid(map) && map->channels == ss->channels), PA_ERR_INVALID);
s = pa_xnew(pa_stream, 1);
@@ -58,6 +59,8 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
s->context = c;
s->mainloop = c->mainloop;
+ s->buffer_attr_not_ready = s->timing_info_not_ready = FALSE;
+
s->read_callback = NULL;
s->read_userdata = NULL;
s->write_callback = NULL;
@@ -70,6 +73,10 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
s->underflow_userdata = NULL;
s->latency_update_callback = NULL;
s->latency_update_userdata = NULL;
+ s->moved_callback = NULL;
+ s->moved_userdata = NULL;
+ s->suspended_callback = NULL;
+ s->suspended_userdata = NULL;
s->direction = PA_STREAM_NODIRECTION;
s->name = pa_xstrdup(name);
@@ -84,11 +91,17 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
s->channel = 0;
s->channel_valid = 0;
s->syncid = c->csyncid++;
- s->device_index = PA_INVALID_INDEX;
+ s->stream_index = PA_INVALID_INDEX;
s->requested_bytes = 0;
s->state = PA_STREAM_UNCONNECTED;
+
+ s->manual_buffer_attr = FALSE;
memset(&s->buffer_attr, 0, sizeof(s->buffer_attr));
+ s->device_index = PA_INVALID_INDEX;
+ s->device_name = NULL;
+ s->suspended = FALSE;
+
s->peek_memchunk.index = 0;
s->peek_memchunk.length = 0;
s->peek_memchunk.memblock = NULL;
@@ -139,6 +152,7 @@ static void stream_free(pa_stream *s) {
pa_memblockq_free(s->record_memblockq);
pa_xfree(s->name);
+ pa_xfree(s->device_name);
pa_xfree(s);
}
@@ -178,7 +192,7 @@ uint32_t pa_stream_get_index(pa_stream *s) {
PA_CHECK_VALIDITY_RETURN_ANY(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE, PA_INVALID_INDEX);
- return s->device_index;
+ return s->stream_index;
}
void pa_stream_set_state(pa_stream *s, pa_stream_state_t st) {
@@ -262,6 +276,95 @@ finish:
pa_context_unref(c);
}
+void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_context *c = userdata;
+ pa_stream *s;
+ uint32_t channel;
+ const char *dn;
+ int suspended;
+ uint32_t di;
+
+ pa_assert(pd);
+ pa_assert(command == PA_COMMAND_PLAYBACK_STREAM_MOVED || command == PA_COMMAND_RECORD_STREAM_MOVED);
+ pa_assert(t);
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ pa_context_ref(c);
+
+ if (c->version < 12) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (pa_tagstruct_getu32(t, &channel) < 0 ||
+ pa_tagstruct_getu32(t, &di) < 0 ||
+ pa_tagstruct_gets(t, &dn) < 0 ||
+ pa_tagstruct_get_boolean(t, &suspended) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!dn || di == PA_INVALID_INDEX) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_MOVED ? c->playback_streams : c->record_streams, channel)))
+ goto finish;
+
+ pa_xfree(s->device_name);
+ s->device_name = pa_xstrdup(dn);
+ s->device_index = di;
+
+ s->suspended = suspended;
+
+ if (s->moved_callback)
+ s->moved_callback(s, s->moved_userdata);
+
+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) {
+ pa_context *c = userdata;
+ pa_stream *s;
+ uint32_t channel;
+ int suspended;
+
+ pa_assert(pd);
+ pa_assert(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED || command == PA_COMMAND_RECORD_STREAM_SUSPENDED);
+ pa_assert(t);
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ pa_context_ref(c);
+
+ if (c->version < 12) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (pa_tagstruct_getu32(t, &channel) < 0 ||
+ pa_tagstruct_get_boolean(t, &suspended) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED ? c->playback_streams : c->record_streams, channel)))
+ goto finish;
+
+ s->suspended = suspended;
+
+ if (s->suspended_callback)
+ s->suspended_callback(s, s->suspended_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) {
pa_stream *s;
pa_context *c = userdata;
@@ -412,6 +515,9 @@ static void create_stream_complete(pa_stream *s) {
pa_assert(PA_REFCNT_VALUE(s) >= 1);
pa_assert(s->state == PA_STREAM_CREATING);
+ if (s->buffer_attr_not_ready || s->timing_info_not_ready)
+ return;
+
pa_stream_set_state(s, PA_STREAM_READY);
if (s->requested_bytes > 0 && s->write_callback)
@@ -426,6 +532,17 @@ static void create_stream_complete(pa_stream *s) {
}
}
+static void automatic_buffer_attr(pa_buffer_attr *attr, pa_sample_spec *ss) {
+ pa_assert(attr);
+ pa_assert(ss);
+
+ attr->tlength = pa_bytes_per_second(ss)/2;
+ attr->maxlength = (attr->tlength*3)/2;
+ attr->minreq = attr->tlength/50;
+ attr->prebuf = attr->tlength - attr->minreq;
+ attr->fragsize = attr->tlength/50;
+}
+
void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_stream *s = userdata;
@@ -445,13 +562,13 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
}
if (pa_tagstruct_getu32(t, &s->channel) < 0 ||
- ((s->direction != PA_STREAM_UPLOAD) && pa_tagstruct_getu32(t, &s->device_index) < 0) ||
+ ((s->direction != PA_STREAM_UPLOAD) && pa_tagstruct_getu32(t, &s->stream_index) < 0) ||
((s->direction != PA_STREAM_RECORD) && pa_tagstruct_getu32(t, &s->requested_bytes) < 0)) {
pa_context_fail(s->context, PA_ERR_PROTOCOL);
goto finish;
}
- if (pa_context_get_server_protocol_version(s->context) >= 9) {
+ if (s->context->version >= 9) {
if (s->direction == PA_STREAM_PLAYBACK) {
if (pa_tagstruct_getu32(t, &s->buffer_attr.maxlength) < 0 ||
pa_tagstruct_getu32(t, &s->buffer_attr.tlength) < 0 ||
@@ -469,6 +586,58 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
}
}
+ if (s->context->version >= 12) {
+ pa_sample_spec ss;
+ pa_channel_map cm;
+ const char *dn = NULL;
+ int suspended;
+
+ if (pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
+ pa_tagstruct_get_channel_map(t, &cm) < 0 ||
+ pa_tagstruct_getu32(t, &s->device_index) < 0 ||
+ pa_tagstruct_gets(t, &dn) < 0 ||
+ pa_tagstruct_get_boolean(t, &suspended) < 0) {
+ pa_context_fail(s->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!dn || s->device_index == PA_INVALID_INDEX ||
+ ss.channels != cm.channels ||
+ !pa_channel_map_valid(&cm) ||
+ !pa_sample_spec_valid(&ss) ||
+ (!(s->flags & PA_STREAM_FIX_FORMAT) && ss.format != s->sample_spec.format) ||
+ (!(s->flags & PA_STREAM_FIX_RATE) && ss.rate != s->sample_spec.rate) ||
+ (!(s->flags & PA_STREAM_FIX_CHANNELS) && !pa_channel_map_equal(&cm, &s->channel_map))) {
+ pa_context_fail(s->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ pa_xfree(s->device_name);
+ s->device_name = pa_xstrdup(dn);
+ s->suspended = suspended;
+
+ if (!s->manual_buffer_attr && pa_bytes_per_second(&ss) != pa_bytes_per_second(&s->sample_spec)) {
+ pa_buffer_attr attr;
+ pa_operation *o;
+
+ automatic_buffer_attr(&attr, &ss);
+
+ /* If we need to update the buffer metrics, we wait for
+ * the the OK for that call before we go to
+ * PA_STREAM_READY */
+
+ s->state = PA_STREAM_READY;
+ pa_assert_se(o = pa_stream_set_buffer_attr(s, &attr, NULL, NULL));
+ pa_operation_unref(o);
+ s->state = PA_STREAM_CREATING;
+
+ s->buffer_attr_not_ready = TRUE;
+ }
+
+ s->channel_map = cm;
+ s->sample_spec = ss;
+ }
+
if (!pa_tagstruct_eof(t)) {
pa_context_fail(s->context, PA_ERR_PROTOCOL);
goto finish;
@@ -491,15 +660,19 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
if (s->direction != PA_STREAM_UPLOAD && s->flags & PA_STREAM_AUTO_TIMING_UPDATE) {
+
/* If automatic timing updates are active, we wait for the
* first timing update before going to PA_STREAM_READY
* state */
+
s->state = PA_STREAM_READY;
request_auto_timing_update(s, 1);
s->state = PA_STREAM_CREATING;
- } else
- create_stream_complete(s);
+ s->timing_info_not_ready = TRUE;
+ }
+
+ create_stream_complete(s);
finish:
pa_stream_unref(s);
@@ -525,7 +698,13 @@ static int create_stream(
PA_STREAM_START_CORKED|
PA_STREAM_INTERPOLATE_TIMING|
PA_STREAM_NOT_MONOTONOUS|
- PA_STREAM_AUTO_TIMING_UPDATE : 0))), PA_ERR_INVALID);
+ PA_STREAM_AUTO_TIMING_UPDATE|
+ PA_STREAM_NO_REMAP_CHANNELS|
+ PA_STREAM_NO_REMIX_CHANNELS|
+ PA_STREAM_FIX_FORMAT|
+ PA_STREAM_FIX_RATE|
+ PA_STREAM_FIX_CHANNELS|
+ PA_STREAM_DONT_MOVE : 0))), 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);
@@ -537,15 +716,17 @@ static int create_stream(
if (sync_stream)
s->syncid = sync_stream->syncid;
- if (attr)
+ if (attr) {
s->buffer_attr = *attr;
- else {
+ s->manual_buffer_attr = TRUE;
+ } else {
/* half a second, with minimum request of 10 ms */
s->buffer_attr.tlength = pa_bytes_per_second(&s->sample_spec)/2;
s->buffer_attr.maxlength = (s->buffer_attr.tlength*3)/2;
s->buffer_attr.minreq = s->buffer_attr.tlength/50;
s->buffer_attr.prebuf = s->buffer_attr.tlength - s->buffer_attr.minreq;
s->buffer_attr.fragsize = s->buffer_attr.tlength/50;
+ s->manual_buffer_attr = FALSE;
}
if (!dev)
@@ -585,6 +766,19 @@ static int create_stream(
} else
pa_tagstruct_putu32(t, s->buffer_attr.fragsize);
+ if (s->context->version >= 12 && s->direction != PA_STREAM_UPLOAD) {
+ pa_tagstruct_put(
+ t,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_NO_REMAP_CHANNELS,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_NO_REMIX_CHANNELS,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_FIX_FORMAT,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_FIX_RATE,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_FIX_CHANNELS,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_DONT_MOVE,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_VARIABLE_RATE,
+ PA_TAG_INVALID);
+ }
+
pa_pstream_send_tagstruct(s->context->pstream, t);
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL);
@@ -921,8 +1115,10 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
}
/* First, let's complete the initialization, if necessary. */
- if (o->stream->state == PA_STREAM_CREATING)
+ if (o->stream->state == PA_STREAM_CREATING) {
+ o->stream->timing_info_not_ready = FALSE;
create_stream_complete(o->stream);
+ }
if (o->stream->latency_update_callback)
o->stream->latency_update_callback(o->stream, o->stream->latency_update_userdata);
@@ -1084,6 +1280,22 @@ void pa_stream_set_latency_update_callback(pa_stream *s, pa_stream_notify_cb_t c
s->latency_update_userdata = userdata;
}
+void pa_stream_set_moved_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ s->moved_callback = cb;
+ s->moved_userdata = userdata;
+}
+
+void pa_stream_set_suspended_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ s->suspended_callback = cb;
+ s->suspended_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) {
pa_operation *o = userdata;
int success = 1;
@@ -1420,8 +1632,208 @@ const pa_buffer_attr* pa_stream_get_buffer_attr(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,
- pa_context_get_server_protocol_version(s->context) >= 9, PA_ERR_NODATA);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 9, PA_ERR_NODATA);
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) {
+ pa_operation *o = userdata;
+ int success = 1;
+
+ pa_assert(pd);
+ pa_assert(o);
+ pa_assert(PA_REFCNT_VALUE(o) >= 1);
+
+ if (!o->context)
+ goto finish;
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t) < 0)
+ goto finish;
+
+ 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 ||
+ pa_tagstruct_getu32(t, &o->stream->buffer_attr.prebuf) < 0 ||
+ pa_tagstruct_getu32(t, &o->stream->buffer_attr.minreq) < 0) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+ } else if (o->stream->direction == PA_STREAM_RECORD) {
+ if (pa_tagstruct_getu32(t, &o->stream->buffer_attr.maxlength) < 0 ||
+ pa_tagstruct_getu32(t, &o->stream->buffer_attr.fragsize) < 0) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+ }
+
+ if (!pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ o->stream->manual_buffer_attr = TRUE;
+ }
+
+ if (o->stream->state == PA_STREAM_CREATING) {
+ o->stream->buffer_attr_not_ready = FALSE;
+ create_stream_complete(o->stream);
+ }
+
+ if (o->callback) {
+ pa_stream_success_cb_t cb = (pa_stream_success_cb_t) o->callback;
+ cb(o->stream, success, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+
+pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ pa_assert(attr);
+
+ 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->context->version >= 12, PA_ERR_NOTSUPPORTED);
+
+ 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_BUFFER_ATTR : PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR,
+ &tag);
+ pa_tagstruct_putu32(t, s->channel);
+
+ pa_tagstruct_putu32(t, attr->maxlength);
+
+ if (s->direction == PA_STREAM_PLAYBACK)
+ pa_tagstruct_put(
+ t,
+ PA_TAG_U32, attr->tlength,
+ PA_TAG_U32, attr->prebuf,
+ PA_TAG_U32, attr->minreq,
+ PA_TAG_INVALID);
+ else
+ pa_tagstruct_putu32(t, attr->fragsize);
+
+ 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);
+
+ return o;
+}
+
+uint32_t pa_stream_get_device_index(pa_stream *s) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_ANY(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE, PA_INVALID_INDEX);
+ PA_CHECK_VALIDITY_RETURN_ANY(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE, PA_INVALID_INDEX);
+ PA_CHECK_VALIDITY_RETURN_ANY(s->context, s->context->version >= 12, PA_ERR_NOTSUPPORTED, PA_INVALID_INDEX);
+ PA_CHECK_VALIDITY_RETURN_ANY(s->context, s->device_index != PA_INVALID_INDEX, PA_ERR_BADSTATE, PA_INVALID_INDEX);
+
+ return s->device_index;
+}
+
+const char *pa_stream_get_device_name(pa_stream *s) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ 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->context->version >= 12, PA_ERR_NOTSUPPORTED);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->device_name, PA_ERR_BADSTATE);
+
+ return s->device_name;
+}
+
+int pa_stream_is_suspended(pa_stream *s) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY(s->context, s->context->version >= 12, PA_ERR_NOTSUPPORTED);
+
+ return s->suspended;
+}
+
+static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_operation *o = userdata;
+ int success = 1;
+
+ pa_assert(pd);
+ pa_assert(o);
+ pa_assert(PA_REFCNT_VALUE(o) >= 1);
+
+ if (!o->context)
+ goto finish;
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t) < 0)
+ goto finish;
+
+ success = 0;
+ } else {
+
+ if (!pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+ }
+
+ o->stream->sample_spec.rate = PA_PTR_TO_UINT(o->private);
+ pa_assert(pa_sample_spec_valid(&o->stream->sample_spec));
+
+ if (o->callback) {
+ pa_stream_success_cb_t cb = (pa_stream_success_cb_t) o->callback;
+ cb(o->stream, success, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+
+pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, rate > 0 && rate <= PA_RATE_MAX, PA_ERR_INVALID);
+ 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->flags & PA_STREAM_VARIABLE_RATE, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 12, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(s->context, s, (pa_operation_cb_t) cb, userdata);
+ o->private = PA_UINT_TO_PTR(rate);
+
+ 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,
+ &tag);
+ pa_tagstruct_putu32(t, s->channel);
+ pa_tagstruct_putu32(t, rate);
+
+ pa_pstream_send_tagstruct(s->context->pstream, t);
+ pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_update_sample_rate_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+
+}
diff --git a/src/pulse/stream.h b/src/pulse/stream.h
index 8c6a90c16..854732272 100644
--- a/src/pulse/stream.h
+++ b/src/pulse/stream.h
@@ -295,9 +295,38 @@ pa_stream_state_t pa_stream_get_state(pa_stream *p);
/** Return the context this stream is attached to */
pa_context* pa_stream_get_context(pa_stream *p);
-/** Return the device (sink input or source output) index this stream is connected to */
+/** Return the sink input resp. source output index this stream is
+ * identified in the server with. This is useful for usage with the
+ * introspection functions, such as pa_context_get_sink_input_info()
+ * resp. pa_context_get_source_output_info(). */
uint32_t pa_stream_get_index(pa_stream *s);
+/** Return the index of the sink or source this stream is connected to
+ * in the server. This is useful for usage with the introspection
+ * functions, such as pa_context_get_sink_info_by_index()
+ * resp. pa_context_get_source_info_by_index(). Please note that
+ * streams may be moved between sinks/sources and thus it is
+ * recommended to use pa_stream_set_moved_callback() to be notified
+ * about this. This function will return with PA_ERR_NOTSUPPORTED when the
+ * server is older than 0.9.8. \since 0.9.8 */
+uint32_t pa_stream_get_device_index(pa_stream *s);
+
+/** Return the name of the sink or source this stream is connected to
+ * in the server. This is useful for usage with the introspection
+ * functions, such as pa_context_get_sink_info_by_name()
+ * resp. pa_context_get_source_info_by_name(). Please note that
+ * streams may be moved between sinks/sources and thus it is
+ * recommended to use pa_stream_set_moved_callback() to be notified
+ * about this. This function will return with PA_ERR_NOTSUPPORTED when the
+ * server is older than 0.9.8. \since 0.9.8 */
+const char *pa_stream_get_device_name(pa_stream *s);
+
+/** Return 1 if the sink or source this stream is connected to has
+ * been suspended. This will return 0 if not, and negative on
+ * error. This function will return with PA_ERR_NOTSUPPORTED when the
+ * server is older than 0.9.8. \since 0.9.8 */
+int pa_stream_is_suspended(pa_stream *s);
+
/** Connect the stream to a sink */
int pa_stream_connect_playback(
pa_stream *s /**< The stream to connect to a sink */,
@@ -346,10 +375,10 @@ int pa_stream_peek(
* calling pa_stream_peek(). \since 0.8 */
int pa_stream_drop(pa_stream *p);
-/** Return the nember of bytes that may be written using pa_stream_write(), in bytes */
+/** Return the number of bytes that may be written using pa_stream_write() */
size_t pa_stream_writable_size(pa_stream *p);
-/** Return the number of bytes that may be read using pa_stream_read(), in bytes \since 0.8 */
+/** Return the number of bytes that may be read using pa_stream_read() \since 0.8 */
size_t pa_stream_readable_size(pa_stream *p);
/** Drain a playback stream. Use this for notification when the buffer is empty */
@@ -378,9 +407,28 @@ void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, voi
/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) \since 0.8 */
void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
-/** Set the callback function that is called whenever a latency information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE streams only. (Only for playback streams) \since 0.8.2 */
+/** Set the callback function that is called whenever a latency
+ * information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE
+ * streams only. (Only for playback streams) \since 0.8.2 */
void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
+/** Set the callback function that is called whenever the stream is
+ * moved to a different sink/source. Use pa_stream_get_device_name()or
+ * pa_stream_get_device_index() to query the new sink/source. This
+ * notification is only generated when the server is at least
+ * 0.9.8. \since 0.9.8 */
+void pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
+
+/** Set the callback function that is called whenever the sink/source
+ * this stream is connected to is suspended or resumed. Use
+ * pa_stream_is_suspended() to query the new suspend status. Please
+ * note that the suspend status might also change when the stream is
+ * moved between devices. Thus if you call this function you very
+ * likely want to call pa_stream_set_moved_callback, too. This
+ * notification is only generated when the server is at least
+ * 0.9.8. \since 0.9.8 */
+void pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
+
/** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. \since 0.3 */
pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);
@@ -447,6 +495,21 @@ const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
* PulseAudio 0.9. \since 0.9.0 */
const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s);
+/** Change the buffer metrics of the stream during playback. The
+ * server might have chosen different buffer metrics then
+ * requested. The selected metrics may be queried with
+ * pa_stream_get_buffer_attr() as soon as the callback is called. Only
+ * valid after the stream has been connected successfully and if the
+ * server is at least PulseAudio 0.9.8. \since 0.9.8 */
+pa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata);
+
+/* Change the stream sampling rate during playback. You need to pass
+ * PA_STREAM_VARIABLE_RATE in the flags parameter of
+ * pa_stream_connect() if you plan to use this function. Only valid
+ * after the stream has been connected successfully and if the server
+ * is at least PulseAudio 0.9.8. \since 0.9.8 */
+pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata);
+
PA_C_DECL_END
#endif