Return the total stream latency. This function is based on pa_stream_get_time(). In case the stream is a monitoring stream the result can be negative, i.e. the captured samples are not yet played. In this case *negative is set to 1. If no timing information has been recieved yet this call will return PA_ERR_NODATA. For more details see pa_stream_get_timing_info() and pa_stream_get_time(). Definition at line 2218 of file stream.c. References PA_ERR_BADSTATE, PA_ERR_FORKED, PA_ERR_NODATA, PA_STREAM_PLAYBACK, PA_STREAM_READY, PA_STREAM_RECORD, and PA_STREAM_UPLOAD. { pa_usec_t t, c; int r; int64_t cindex; pa_assert(s); pa_assert(PA_REFCNT_VALUE(s) >= 1); pa_assert(r_usec); PA_CHECK_VALIDITY(s->context, !pa_detect_fork(), PA_ERR_FORKED); 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->timing_info_valid, PA_ERR_NODATA); PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_PLAYBACK || !s->timing_info.write_index_corrupt, PA_ERR_NODATA); PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.read_index_corrupt, PA_ERR_NODATA); if ((r = pa_stream_get_time(s, &t)) < 0) return r; if (s->direction == PA_STREAM_PLAYBACK) cindex = s->timing_info.write_index; else cindex = s->timing_info.read_index; if (cindex < 0) cindex = 0; 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); else *r_usec = time_counter_diff(s, t, c, negative); return 0; }
|