-
Notifications
You must be signed in to change notification settings - Fork 3
/
context_impl.hpp
119 lines (101 loc) · 2.44 KB
/
context_impl.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef _TSD_CONTEXT_IMPL_HPP_
#define _TSD_CONTEXT_IMPL_HPP_
#include "filter.hpp"
namespace tsd {
context::context(std::unique_ptr<view> view) :
view_(std::move(view)),
packet_counter_(0)
{
set_initial_filters();
}
inline
void context::set_initial_filters() {
open_section_filter(
0x0000, std::unique_ptr<section_filter>(
new pat_section_filter()));
open_section_filter(
0x0011, std::unique_ptr<section_filter>(
new sdt_section_filter()));
open_section_filter(
0x0012, std::unique_ptr<section_filter>(
new eit_section_filter()));
open_section_filter(
0x0026, std::unique_ptr<section_filter>(
new eit_section_filter()));
open_section_filter(
0x0027, std::unique_ptr<section_filter>(
new eit_section_filter()));
open_section_filter(
0x0014, std::unique_ptr<section_filter>(
new tot_section_filter()));
open_section_filter(
0x0029, std::unique_ptr<section_filter>(
new cdt_section_filter()));
}
inline
void context::clear() {
pids_.clear();
ts_trimmer_.reset();
packet_counter_ = 0;
transport_stream_id = boost::none;
pat = boost::none;
program_pcr.clear();
first_pcr = boost::none;
latest_pcr = boost::none;
baseline_pcr = boost::none;
baseline_time = boost::none;
service_descriptors.clear();
set_initial_filters();
}
inline
void context::handle_packet(const transport_packet& packet) {
if(ts_trimmer_)
ts_trimmer_->add_packet(packet);
auto i_filter = pids_.find(packet.pid);
if(i_filter != pids_.end()) {
// find a correspondent filter
auto& f = i_filter->second;
f->handle_packet(*this, packet);
}
packet_counter_ += 1;
}
inline
void context::open_filter(
uint16_t pid,
std::unique_ptr<filter> f) {
auto i = pids_.lower_bound(pid);
if(i != pids_.end() && !(pid < i->first)) {
return;
}
else {
pids_.emplace_hint(i, pid, std::move(f));
}
}
inline
void context::open_section_filter(
uint16_t pid,
std::unique_ptr<section_filter> f) {
open_filter(pid, std::move(f));
}
inline
void context::open_pes_filter(
uint16_t pid,
std::unique_ptr<pes_filter> f) {
open_filter(pid, std::move(f));
}
inline
void context::open_pcr_filter(uint16_t pid) {
open_filter(
pid,
std::unique_ptr<pcr_filter>(new pcr_filter()));
}
inline
bool context::is_opened(uint16_t pid) const {
return pids_.count(pid);
}
inline
view& context::get_view() {
return *view_;
}
}
#endif