-
Notifications
You must be signed in to change notification settings - Fork 3
/
splitter_context.hpp
88 lines (77 loc) · 1.44 KB
/
splitter_context.hpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef _TSD_SPLITTER_CONTEXT_HPP_
#define _TSD_SPLITTER_CONTEXT_HPP_
#include "wrap_around_time_stamp.hpp"
namespace tsd
{
class splitter_context
{
public:
enum class state
{
init,
buffering,
writing
};
public:
splitter_context() :
state_(state::init),
trim_threshold_sec_(0) {}
explicit splitter_context(int64_t trim_threshold_sec) :
state_(state::init),
trim_threshold_sec_(trim_threshold_sec) {}
const state get_state() const {
return state_;
}
void signal_pcr(uint64_t pcr) {
switch(state_) {
case state::init:
{
start_pcr_ = wrap_around_time_stamp(pcr);
state_ = state::buffering;
}
break;
case state::buffering:
{
wrap_around_time_stamp wpcr(pcr);
if(wpcr < start_pcr_)
return;
if(pcr_to_sec(wpcr - start_pcr_) >= trim_threshold_sec_) {
state_ = state::writing;
}
}
break;
case state::writing:
{
}
break;
}
}
void signal_split() {
switch(state_) {
case state::init:
{
}
break;
case state::buffering:
{
state_ = state::init;
}
break;
case state::writing:
{
state_ = state::init;
}
break;
}
}
private:
int64_t pcr_to_sec(int64_t pcr) const {
return pcr / 90000;
}
private:
state state_;
int64_t trim_threshold_sec_;
wrap_around_time_stamp start_pcr_;
};
}
#endif