libpulse_sys/
timeval.rs

1// Copyright 2017 Lyndon Brown
2//
3// This file is part of the PulseAudio Rust language linking library.
4//
5// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
6// copy, modify, or distribute this file except in compliance with said license. You can find copies
7// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
8// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
9// respectively.
10//
11// Portions of documentation are copied from the LGPL 2.1+ licensed PulseAudio C headers on a
12// fair-use basis, as discussed in the overall project readme (available in the git repository).
13
14//! Utility functions for handling timeval calculations.
15
16pub(crate) use libc::timeval;
17use crate::sample::pa_usec_t;
18
19pub const PA_MSEC_PER_SEC: pa_usec_t = 1000;
20pub const PA_USEC_PER_SEC: pa_usec_t = 1_000_000;
21pub const PA_NSEC_PER_SEC: u64 = 1_000_000_000;
22pub const PA_USEC_PER_MSEC: pa_usec_t = 1000;
23pub const PA_NSEC_PER_MSEC: u64 = 1_000_000;
24pub const PA_NSEC_PER_USEC: u64 = 1000;
25
26pub const PA_USEC_INVALID: pa_usec_t = std::u64::MAX;
27
28pub const PA_USEC_MAX: pa_usec_t = std::u64::MAX - 1;
29
30#[link(name = "pulse")]
31extern "C" {
32    pub fn pa_gettimeofday(tv: *mut timeval) -> *mut timeval;
33    pub fn pa_timeval_diff(a: *const timeval, b: *const timeval) -> pa_usec_t;
34    pub fn pa_timeval_cmp(a: *const timeval, b: *const timeval) -> i32;
35    pub fn pa_timeval_age(tv: *const timeval) -> pa_usec_t;
36    pub fn pa_timeval_add(tv: *mut timeval, v: pa_usec_t) -> *mut timeval;
37    pub fn pa_timeval_sub(tv: *mut timeval, v: pa_usec_t) -> *mut timeval;
38    pub fn pa_timeval_store(tv: *mut timeval, v: pa_usec_t) -> *mut timeval;
39    pub fn pa_timeval_load(tv: *const timeval) -> pa_usec_t;
40}