blob: cd0782b05394d9c02c9fd9dde5a9a35acee19b0e (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*
* Copyright 2024 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include <stdint.h>
#include <cstdint>
#include <deque>
#include <memory>
#include "audio/audio_events.hpp"
namespace audio {
/*
* Utility for tracking which track is currently being played (and how long it
* has been playing for) based on counting samples that are put into and taken
* out of the audio processor's output buffer.
*/
class StreamCues {
public:
StreamCues();
/* Updates the current track given the new most recently played sample. */
auto update(uint32_t sample) -> void;
/* Returns the current track, and how long it has been playing for. */
auto current() -> std::pair<std::shared_ptr<TrackInfo>, uint32_t>;
auto hasStream() -> bool;
auto addCue(std::shared_ptr<TrackInfo>, uint32_t start_at) -> void;
private:
uint32_t now_;
struct Cue {
std::shared_ptr<TrackInfo> track;
uint32_t start_at;
};
std::optional<Cue> current_;
std::deque<Cue> upcoming_;
};
} // namespace audio
|