Logo Search packages:      
Sourcecode: pulseaudio version File versions  Download package

int pa_stream_get_latency ( pa_stream s,
pa_usec_t r_usec,
int *  negative 
)

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.

Since:
0.6

Definition at line 1568 of file stream.c.

References PA_ERR_BADSTATE, 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, 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(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;
}


Generated by  Doxygen 1.6.0   Back to index