summaryrefslogtreecommitdiff
path: root/src/buffer/common_internal.h
blob: 6685a3ee458015f72eea53a3eee26d3f84bb9356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <al/types.h>

#include "clock.h"

enum {
    // Flowing.
    FLOWING,
    // Got request to flush.
    FLUSHED,
    // Flushed because of an error.
    FLUSHED_ERROR,
    // Realized flush.
    SIGNALED,
    // Errored.
    ERRORED
};

//#define CAMU_BUFFER_SPORADIC_ERRORS
#ifdef CAMU_BUFFER_SPORADIC_ERRORS
#include <al/random.h>
#define ROLL_FOR_BUFFER_ERROR(buf) do { \
    if (al_random_int(0, 254) == 72) { \
        log_warn("Random buffer error proc."); \
        atomic_store(u32)(&(buf)->flow, FLUSHED_ERROR, AL_ATOMIC_RELAXED); \
    } \
} while (0)
#endif

static inline bool frame_is_late(struct camu_clock *clock, f64 base, f64 pts, f64 duration)
{
    return pts + duration < ((base == -1.0) ? camu_clock_get_base_pts(clock) : base);
}