Logo Search packages:      
Sourcecode: pulseaudio version File versions

int pa_stream_get_time ( pa_stream s,
pa_usec_t r_usec 
)

Return the current playback/recording time. This is based on the data in the timing info structure returned by pa_stream_get_timing_info().

This function will usually only return new data if a timing info update has been recieved. Only if timing interpolation has been requested (PA_STREAM_INTERPOLATE_TIMING) the data from the last timing update is used for an estimation of the current playback/recording time based on the local time that passed since the timing info structure has been acquired.

The time value returned by this function is guaranteed to increase monotonically. (that means: the returned value is always greater or equal to the value returned on the last call). This behaviour can be disabled by using PA_STREAM_NOT_MONOTONIC. This may be desirable to deal better with bad estimations of transport latencies, but may have strange effects if the application is not able to deal with time going 'backwards'.

The time interpolator activated by PA_STREAM_INTERPOLATE_TIMING favours 'smooth' time graphs over accurate ones to improve the smoothness of UI operations that are tied to the audio clock. If accuracy is more important to you you might need to estimate your timing based on the data from pa_stream_get_timing_info() yourself or not work with interpolated timing at all and instead always query on the server side for the most up to date timing with pa_stream_update_timing_info().

If no timing information has been recieved yet this call will return PA_ERR_NODATA. For more details see pa_stream_get_timing_info().

Definition at line 2168 of file stream.c.

References PA_ERR_BADSTATE, PA_ERR_FORKED, PA_ERR_NODATA, PA_STREAM_NOT_MONOTONIC, PA_STREAM_PLAYBACK, PA_STREAM_READY, PA_STREAM_RECORD, and PA_STREAM_UPLOAD.

                                                        {
    pa_usec_t usec;

    pa_assert(s);
    pa_assert(PA_REFCNT_VALUE(s) >= 1);

    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.read_index_corrupt, PA_ERR_NODATA);
    PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt, PA_ERR_NODATA);

    if (s->smoother)
        usec = pa_smoother_get(s->smoother, pa_rtclock_now());
    else
        usec = calc_time(s, FALSE);

    /* Make sure the time runs monotonically */
    if (!(s->flags & PA_STREAM_NOT_MONOTONIC)) {
        if (usec < s->previous_time)
            usec = s->previous_time;
        else
            s->previous_time = usec;
    }

    if (r_usec)
        *r_usec = usec;

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index