*** 0.5 ***
- more complete pactl
-- input latency
- fix tcp/native
- paman: add support for killing sink inputs, source outputs, clients
- add client config file
- udp based protocol
- make mcalign merge chunks
- option to use default fragment size on alsa drivers
+- improve module-oss-mmap latency measurement
** later ***
- xmlrpc/http
backends for:
- portaudio
+- alsa-lib
- sdl
- gstreamer (semi-done)
-- alsa-lib
- OSS (esddsp style)
for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec);
- pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n",
+ pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tlatency: <%0.0f usec>\n\tsample_spec: <%s>\n",
c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
source->index,
source->name,
+ (float) pa_source_get_latency(source),
ss);
if (source->monitor_of)
assert(io);
return pa_socket_set_sndbuf(io->ofd, l);
}
+
+void pa_iochannel_force_unreadable(struct pa_iochannel *io) {
+ assert(io);
+ io->readable = 0;
+ enable_mainloop_sources(io);
+}
+
+void pa_iochannel_force_unwritable(struct pa_iochannel *io) {
+ io->writable = 0;
+ enable_mainloop_sources(io);
+}
int pa_iochannel_is_writable(struct pa_iochannel*io);
int pa_iochannel_is_hungup(struct pa_iochannel*io);
+void pa_iochannel_force_unreadable(struct pa_iochannel *io);
+void pa_iochannel_force_unwritable(struct pa_iochannel *io);
+
void pa_iochannel_set_noclose(struct pa_iochannel*io, int b);
void pa_iochannel_set_callback(struct pa_iochannel*io, void (*callback)(struct pa_iochannel*io, void *userdata), void *userdata);
do_read(u);
}
+static pa_usec_t source_get_latency_cb(struct pa_source *s) {
+ struct userdata *u = s->userdata;
+ snd_pcm_sframes_t frames;
+ assert(s && u && u->source);
+
+ if (snd_pcm_delay(u->pcm_handle, &frames) < 0) {
+ pa_log(__FILE__": failed to get delay\n");
+ s->get_latency = NULL;
+ return 0;
+ }
+
+ return pa_bytes_to_usec(frames * u->frame_size, &s->sample_spec);
+}
+
int pa__init(struct pa_core *c, struct pa_module*m) {
struct pa_modargs *ma = NULL;
int ret = -1;
assert(u->source);
u->source->userdata = u;
+ u->source->get_latency = source_get_latency_cb;
pa_source_set_owner(u->source, m);
u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
struct pa_memchunk memchunk, silence;
uint32_t in_fragment_size, out_fragment_size, sample_size;
+ int use_getospace, use_getispace;
int fd;
struct pa_module *module;
static void do_write(struct userdata *u) {
struct pa_memchunk *memchunk;
ssize_t r;
+ size_t l;
+ int loop = 0;
+
assert(u);
if (!u->sink || !pa_iochannel_is_writable(u->io))
update_usage(u);
- memchunk = &u->memchunk;
-
- if (!memchunk->length)
- if (pa_sink_render(u->sink, u->out_fragment_size, memchunk) < 0)
- memchunk = &u->silence;
-
- assert(memchunk->memblock);
- assert(memchunk->memblock->data);
- assert(memchunk->length);
+ l = u->out_fragment_size;
- if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
- pa_log(__FILE__": write() failed: %s\n", strerror(errno));
- return;
+ if (u->use_getospace) {
+ audio_buf_info info;
+
+ if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0)
+ u->use_getospace = 0;
+ else {
+ if (info.bytes/l > 0) {
+ l = (info.bytes/l)*l;
+ loop = 1;
+ }
+ }
}
+
+ do {
+ memchunk = &u->memchunk;
+
+ if (!memchunk->length)
+ if (pa_sink_render(u->sink, l, memchunk) < 0)
+ memchunk = &u->silence;
- if (memchunk == &u->silence)
- assert(r % u->sample_size == 0);
- else {
- u->memchunk.index += r;
- u->memchunk.length -= r;
+ assert(memchunk->memblock);
+ assert(memchunk->memblock->data);
+ assert(memchunk->length);
- if (u->memchunk.length <= 0) {
- pa_memblock_unref(u->memchunk.memblock);
- u->memchunk.memblock = NULL;
+ if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
+ pa_log(__FILE__": write() failed: %s\n", strerror(errno));
+ break;
}
- }
+
+ if (memchunk == &u->silence)
+ assert(r % u->sample_size == 0);
+ else {
+ u->memchunk.index += r;
+ u->memchunk.length -= r;
+
+ if (u->memchunk.length <= 0) {
+ pa_memblock_unref(u->memchunk.memblock);
+ u->memchunk.memblock = NULL;
+ }
+ }
+
+ l = l > (size_t) r ? l - r : 0;
+ } while (loop && l > 0);
}
static void do_read(struct userdata *u) {
struct pa_memchunk memchunk;
ssize_t r;
+ size_t l;
+ int loop = 0;
assert(u);
if (!u->source || !pa_iochannel_is_readable(u->io))
update_usage(u);
- memchunk.memblock = pa_memblock_new(u->in_fragment_size, u->core->memblock_stat);
- assert(memchunk.memblock);
- if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
- pa_memblock_unref(memchunk.memblock);
- if (errno != EAGAIN)
- pa_log(__FILE__": read() failed: %s\n", strerror(errno));
- return;
- }
+ l = u->in_fragment_size;
- assert(r <= (ssize_t) memchunk.memblock->length);
- memchunk.length = memchunk.memblock->length = r;
- memchunk.index = 0;
+ if (u->use_getispace) {
+ audio_buf_info info;
+
+ if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0)
+ u->use_getispace = 0;
+ else {
+ if (info.bytes/l > 0) {
+ l = (info.bytes/l)*l;
+ loop = 1;
+ }
+ }
+ }
+
+ do {
+ memchunk.memblock = pa_memblock_new(l, u->core->memblock_stat);
+ assert(memchunk.memblock);
+ if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
+ pa_memblock_unref(memchunk.memblock);
+ if (errno != EAGAIN)
+ pa_log(__FILE__": read() failed: %s\n", strerror(errno));
+ break;
+ }
+
+ assert(r <= (ssize_t) memchunk.memblock->length);
+ memchunk.length = memchunk.memblock->length = r;
+ memchunk.index = 0;
+
+ pa_source_post(u->source, &memchunk);
+ pa_memblock_unref(memchunk.memblock);
- pa_source_post(u->source, &memchunk);
- pa_memblock_unref(memchunk.memblock);
+ l = l > (size_t) r ? l - r : 0;
+ } while (loop && l > 0);
}
static void io_callback(struct pa_iochannel *io, void*userdata) {
return r;
}
+static pa_usec_t source_get_latency_cb(struct pa_source *s) {
+ struct userdata *u = s->userdata;
+ audio_buf_info info;
+ assert(s && u && u->sink);
+
+ if (!u->use_getispace)
+ return 0;
+
+ if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
+ u->use_getispace = 0;
+ return 0;
+ }
+
+ if (info.bytes <= 0)
+ return 0;
+
+ return pa_bytes_to_usec(info.bytes, &s->sample_spec);
+}
+
int pa__init(struct pa_core *c, struct pa_module*m) {
struct audio_buf_info info;
struct userdata *u = NULL;
assert(frag_size);
in_frag_size = out_frag_size = frag_size;
+ u = pa_xmalloc(sizeof(struct userdata));
+ u->core = c;
+ u->use_getospace = u->use_getispace = 0;
+
if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
pa_log(__FILE__": input -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
in_frag_size = info.fragsize;
+ u->use_getispace = 1;
}
if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
pa_log(__FILE__": output -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
out_frag_size = info.fragsize;
+ u->use_getospace = 1;
}
- u = pa_xmalloc(sizeof(struct userdata));
- u->core = c;
-
if (mode != O_WRONLY) {
u->source = pa_source_new(c, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss);
assert(u->source);
u->source->userdata = u;
+ u->source->get_latency = source_get_latency_cb;
pa_source_set_owner(u->source, m);
u->source->description = pa_sprintf_malloc("Open Sound System PCM on '%s'", p);
} else
PA_COMMAND_REMOVE_AUTOLOAD,
PA_COMMAND_GET_AUTOLOAD_INFO,
PA_COMMAND_GET_AUTOLOAD_INFO_LIST,
+ PA_COMMAND_GET_RECORD_LATENCY,
PA_COMMAND_MAX
};
}
-/* Show the current playback latency */
+/* Show the current latency */
static void stream_get_latency_callback(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) {
+ double total;
assert(s);
if (!i) {
- fprintf(stderr, "Failed to get latency: %s\n", strerror(errno));
+ fprintf(stderr, "Failed to get latency: %s\n", pa_strerror(pa_context_errno(context)));
quit(1);
return;
}
- fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
- (float) i->buffer_usec, (float) i->sink_usec, (float) i->transport_usec,
- (float) (i->buffer_usec+i->sink_usec+i->transport_usec),
+ if (mode == PLAYBACK)
+ total = (double) i->sink_usec + i->buffer_usec + i->transport_usec;
+ else
+ total = (double) i->source_usec + i->buffer_usec + i->transport_usec - i->sink_usec;
+
+ fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
+ (float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, total,
i->synchronized_clocks ? "yes" : "no");
}
/* Someone requested that the latency is shown */
static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
- if (mode != PLAYBACK)
- return;
-
fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
pa_operation_unref(pa_stream_get_latency(stream, stream_get_latency_callback, NULL));
}
/** Return one if an event type t matches an event mask bitfield */
#define pa_subscription_match_flags(m, t) (!!((m) & (1 << ((t) & PA_SUBSCRIPTION_EVENT_FACILITY_MASK))))
-/** A structure for latency info. See pa_stream_get_latency(). The
- * total latency a sample that is written with pa_stream_write() takes
- * to be played may be estimated by
- * buffer_usec+sink_usec+transport_usec. The buffer to which
+/** A structure for latency info. See pa_stream_get_latency(). The
+ * total output latency a sample that is written with
+ * pa_stream_write() takes to be played may be estimated by
+ * sink_usec+buffer_usec+transport_usec. The output buffer to which
* buffer_usec relates may be manipulated freely (with
* pa_stream_write()'s delta argument, pa_stream_flush() and friends),
- * the playback buffer sink_usec relates to is a FIFO which cannot be
- * flushed or manipulated in any way. */
+ * the buffers sink_usec/source_usec relates to is a first-in
+ * first-out buffer which cannot be flushed or manipulated in any
+ * way. The total input latency a sample that is recorded takes to be
+ * delivered to the application is:
+ * source_usec+buffer_usec+transport_usec-sink_usec. (Take care of
+ * sign issues!) When connected to a monitor source sink_usec contains
+ * the latency of the owning sink.*/
struct pa_latency_info {
- pa_usec_t buffer_usec; /**< Time in usecs the current buffer takes to play */
- pa_usec_t sink_usec; /**< Time in usecs a sample takes to be played on the sink. */
- pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to the daemon. \since 0.5 */
- int playing; /**< Non-zero when the stream is currently playing */
- uint32_t queue_length; /**< Queue size in bytes. */
+ pa_usec_t buffer_usec; /**< Time in usecs the current buffer takes to play. For both playback and record streams. */
+ 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. \since 0.5*/
+ 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. \since 0.5 */
+ int playing; /**< Non-zero when the stream is currently playing. Only for playback streams. */
+ uint32_t queue_length; /**< Queue size in bytes. For both playback and recrd streams. */
int synchronized_clocks; /**< Non-zero if the local and the
* remote machine have synchronized
* clocks. If synchronized clocks are
pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
pa_tagstruct_getu32(t, &i.monitor_of_sink) < 0 ||
- pa_tagstruct_gets(t, &i.monitor_of_sink_name) < 0) {
+ pa_tagstruct_gets(t, &i.monitor_of_sink_name) < 0 ||
+ pa_tagstruct_get_usec(t, &i.latency) < 0) {
+
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
goto finish;
}
pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
pa_tagstruct_getu32(t, &i.client) < 0 ||
pa_tagstruct_getu32(t, &i.source) < 0 ||
- pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0) {
+ pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
+ pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
+ pa_tagstruct_get_usec(t, &i.source_usec) < 0) {
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
goto finish;
}
pa_volume_t volume; /**< Volume of the sink */
uint32_t monitor_source; /**< Index of the monitor source connected to this sink */
const char *monitor_source_name; /**< The name of the monitor source */
- pa_usec_t latency; /**< Length of the playback buffer of this sink */
+ pa_usec_t latency; /**< Length of filled playback buffer of this sink */
};
/** Get information about a sink by its name */
uint32_t owner_module; /**< Owning module index, or PA_INVALID_INDEX */
uint32_t monitor_of_sink; /**< If this is a monitor source the index of the owning sink, otherwise PA_INVALID_INDEX */
const char *monitor_of_sink_name; /**< Name of the owning sink, or PA_INVALID_INDEX */
+ pa_usec_t latency; /**< Length of filled record buffer of this source. \since 0.5 */
};
/** Get information about a source by its name */
uint32_t client; /**< Index of the client this sink input belongs to, or PA_INVALID_INDEX when it does not belong to any client */
uint32_t source; /**< Index of the connected source */
struct pa_sample_spec sample_spec; /**< The sample specification of the source output */
+ pa_usec_t buffer_usec; /**< Latency due to buffering in the source output, see pa_latency_info for details. \since 0.5 */
+ pa_usec_t source_usec; /**< Latency of the source device, see pa_latency_info for details. \since 0.5 */
};
/** Get information about a source output by its index */
} else if (pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
pa_tagstruct_get_usec(t, &i.sink_usec) < 0 ||
+ pa_tagstruct_get_usec(t, &i.source_usec) < 0 ||
pa_tagstruct_get_boolean(t, &i.playing) < 0 ||
pa_tagstruct_getu32(t, &i.queue_length) < 0 ||
pa_tagstruct_get_timeval(t, &local) < 0 ||
if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
/* local and remote seem to have synchronized clocks */
- i.transport_usec = pa_timeval_diff(&remote, &local);
+
+ if (o->stream->direction == PA_STREAM_PLAYBACK)
+ i.transport_usec = pa_timeval_diff(&remote, &local);
+ else
+ i.transport_usec = pa_timeval_diff(&now, &remote);
+
i.synchronized_clocks = 1;
i.timestamp = remote;
} else {
struct pa_operation *o;
struct pa_tagstruct *t;
struct timeval now;
+ assert(s && s->direction != PA_STREAM_UPLOAD);
o = pa_operation_new(s->context, s);
assert(o);
t = pa_tagstruct_new(NULL, 0);
assert(t);
- pa_tagstruct_putu32(t, PA_COMMAND_GET_PLAYBACK_LATENCY);
+ pa_tagstruct_putu32(t, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_GET_PLAYBACK_LATENCY : PA_COMMAND_GET_RECORD_LATENCY);
pa_tagstruct_putu32(t, tag = s->context->ctag++);
pa_tagstruct_putu32(t, s->channel);
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
static void sink_input_kill_cb(struct pa_sink_input *i);
static pa_usec_t sink_input_get_latency_cb(struct pa_sink_input *i);
+static pa_usec_t source_output_get_latency_cb(struct pa_source_output *o);
static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk);
static void source_output_kill_cb(struct pa_source_output *o);
c->source_output->client = c->client;
c->source_output->push = source_output_push_cb;
c->source_output->kill = source_output_kill_cb;
+ c->source_output->get_latency = source_output_get_latency_cb;
c->source_output->userdata = c;
c->state = ESD_STREAMING_DATA;
connection_free((struct connection *) i->userdata);
}
-
static pa_usec_t sink_input_get_latency_cb(struct pa_sink_input *i) {
struct connection*c = i->userdata;
assert(i && c);
connection_free((struct connection *) o->userdata);
}
+static pa_usec_t source_output_get_latency_cb(struct pa_source_output *o) {
+ struct connection*c = o->userdata;
+ assert(o && c);
+ return pa_bytes_to_usec(pa_memblockq_get_length(c->output_memblockq), &c->source_output->sample_spec);
+}
+
/*** socket server callback ***/
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
static void source_output_kill_cb(struct pa_source_output *o);
static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk);
+static pa_usec_t source_output_get_latency_cb(struct pa_source_output *o);
static void command_exit(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_lookup(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_stat(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_create_upload_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_finish_upload_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_play_sample(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
[PA_COMMAND_LOOKUP_SOURCE] = { command_lookup },
[PA_COMMAND_STAT] = { command_stat },
[PA_COMMAND_GET_PLAYBACK_LATENCY] = { command_get_playback_latency },
+ [PA_COMMAND_GET_RECORD_LATENCY] = { command_get_record_latency },
[PA_COMMAND_CREATE_UPLOAD_STREAM] = { command_create_upload_stream },
[PA_COMMAND_DELETE_UPLOAD_STREAM] = { command_delete_stream },
[PA_COMMAND_FINISH_UPLOAD_STREAM] = { command_finish_upload_stream },
s->source_output = source_output;
s->source_output->push = source_output_push_cb;
s->source_output->kill = source_output_kill_cb;
+ s->source_output->get_latency = source_output_get_latency_cb;
s->source_output->userdata = s;
s->source_output->owner = c->protocol->module;
s->source_output->client = c->client;
pa_pstream_send_tagstruct(r->connection->pstream, t);
}
-
/*** sinkinput callbacks ***/
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
record_stream_free((struct record_stream *) o->userdata);
}
+static pa_usec_t source_output_get_latency_cb(struct pa_source_output *o) {
+ struct record_stream *s;
+ assert(o && o->userdata);
+ s = o->userdata;
+
+ /*pa_log(__FILE__": get_latency: %u\n", pa_memblockq_get_length(s->memblockq));*/
+
+ return pa_bytes_to_usec(pa_memblockq_get_length(s->memblockq), &o->sample_spec);
+}
+
/*** pdispatch callbacks ***/
static void protocol_error(struct connection *c) {
struct timeval tv, now;
uint32_t index;
assert(c && t);
-
+
if (pa_tagstruct_getu32(t, &index) < 0 ||
pa_tagstruct_get_timeval(t, &tv) < 0 ||
!pa_tagstruct_eof(t)) {
pa_tagstruct_putu32(reply, tag);
pa_tagstruct_put_usec(reply, pa_sink_input_get_latency(s->sink_input));
pa_tagstruct_put_usec(reply, pa_sink_get_latency(s->sink_input->sink));
+ pa_tagstruct_put_usec(reply, 0);
pa_tagstruct_put_boolean(reply, pa_memblockq_is_readable(s->memblockq));
pa_tagstruct_putu32(reply, pa_memblockq_get_length(s->memblockq));
pa_tagstruct_put_timeval(reply, &tv);
pa_pstream_send_tagstruct(c->pstream, reply);
}
+static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ struct pa_tagstruct *reply;
+ struct record_stream *s;
+ struct timeval tv, now;
+ uint32_t index;
+ assert(c && t);
+
+ if (pa_tagstruct_getu32(t, &index) < 0 ||
+ pa_tagstruct_get_timeval(t, &tv) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (!(s = pa_idxset_get_by_index(c->record_streams, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ reply = pa_tagstruct_new(NULL, 0);
+ assert(reply);
+ pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+ pa_tagstruct_putu32(reply, tag);
+ pa_tagstruct_put_usec(reply, pa_source_output_get_latency(s->source_output));
+ pa_tagstruct_put_usec(reply, s->source_output->source->monitor_of ? pa_sink_get_latency(s->source_output->source->monitor_of) : 0);
+ pa_tagstruct_put_usec(reply, pa_source_get_latency(s->source_output->source));
+ pa_tagstruct_put_boolean(reply, 0);
+ pa_tagstruct_putu32(reply, pa_memblockq_get_length(s->memblockq));
+ pa_tagstruct_put_timeval(reply, &tv);
+ gettimeofday(&now, NULL);
+ pa_tagstruct_put_timeval(reply, &now);
+ pa_pstream_send_tagstruct(c->pstream, reply);
+}
+
+
static void command_create_upload_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
struct upload_stream *s;
pa_tagstruct_putu32(t, source->owner ? source->owner->index : (uint32_t) -1);
pa_tagstruct_putu32(t, source->monitor_of ? source->monitor_of->index : (uint32_t) -1);
pa_tagstruct_puts(t, source->monitor_of ? source->monitor_of->name : "");
+ pa_tagstruct_put_usec(t, pa_source_get_latency(source));
}
static void client_fill_tagstruct(struct pa_tagstruct *t, struct pa_client *client) {
pa_tagstruct_putu32(t, s->client ? s->client->index : (uint32_t) -1);
pa_tagstruct_putu32(t, s->source->index);
pa_tagstruct_put_sample_spec(t, &s->sample_spec);
+ pa_tagstruct_put_usec(t, pa_source_output_get_latency(s));
+ pa_tagstruct_put_usec(t, pa_source_get_latency(s->source));
}
static void scache_fill_tagstruct(struct pa_tagstruct *t, struct pa_scache_entry *e) {
connection_free((struct connection *) o->userdata);
}
+static pa_usec_t source_output_get_latency_cb(struct pa_source_output *o) {
+ struct connection*c = o->userdata;
+ assert(o && c);
+ return pa_bytes_to_usec(pa_memblockq_get_length(c->output_memblockq), &c->source_output->sample_spec);
+}
+
/*** client callbacks ***/
static void client_kill_cb(struct pa_client *c) {
c->source_output->push = source_output_push_cb;
c->source_output->kill = source_output_kill_cb;
+ c->source_output->get_latency = source_output_get_latency_cb;
c->source_output->userdata = c;
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*RECORD_BUFFER_SECONDS);
unsigned n;
size_t l;
int r = -1;
- assert(s && s->ref >= 1 && length && result);
+ assert(s);
+ assert(s->ref >= 1);
+ assert(length);
+ assert(result);
pa_sink_ref(s);
o->push = NULL;
o->kill = NULL;
o->userdata = NULL;
+ o->get_latency = NULL;
+
o->resampler = resampler;
assert(s->core);
pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
}
+
+pa_usec_t pa_source_output_get_latency(struct pa_source_output *o) {
+ assert(o && o->ref >= 1);
+
+ if (o->get_latency)
+ return o->get_latency(o);
+
+ return 0;
+}
void (*push)(struct pa_source_output *o, const struct pa_memchunk *chunk);
void (*kill)(struct pa_source_output* o);
+ pa_usec_t (*get_latency) (struct pa_source_output *i);
struct pa_resampler* resampler;
void pa_source_output_set_name(struct pa_source_output *i, const char *name);
+pa_usec_t pa_source_output_get_latency(struct pa_source_output *i);
+
+
#endif
s->outputs = pa_idxset_new(NULL, NULL);
s->monitor_of = NULL;
+ s->get_latency = NULL;
s->notify = NULL;
s->userdata = NULL;
assert(s);
s->owner = m;
}
+
+pa_usec_t pa_source_get_latency(struct pa_source *s) {
+ assert(s && s->ref >= 1);
+
+ if (!s->get_latency)
+ return 0;
+
+ return s->get_latency(s);
+}
+
struct pa_sink *monitor_of;
void (*notify)(struct pa_source*source);
+ pa_usec_t (*get_latency)(struct pa_source *s);
void *userdata;
};
void pa_source_set_owner(struct pa_source *s, struct pa_module *m);
+pa_usec_t pa_source_get_latency(struct pa_source *s);
+
#endif