-
Notifications
You must be signed in to change notification settings - Fork 6
/
minimal.cpp
86 lines (58 loc) · 2.11 KB
/
minimal.cpp
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
/*++
* tssi - A library for parsing MPEG-2 and DVB Transport Streams
*
* Copyright (C) 2017 Martin Hoernig (goforcode.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
--*/
#include <fstream>
#include <iostream>
#include <vector>
#include "tsparser.hpp"
using namespace std;
using namespace tssi;
int main() {
// load ts data into buffer (without error checking, ouch!)
auto f = ifstream{ "examples/data/ard.ts", ifstream::binary };
auto b = vector<char>( 4'000'000 );
f.read(b.data(), b.size());
// create tssi parser and a common processing and storage object for psi data
auto ts = TSParser<>();
auto heap = make_shared<PSIHeap<>>();
// we try to find the transmission data of the transport stream (pid 0x14)
// this is a service information, utilize psiheap
ts.pid_parser({ 0x14 }, heap);
// process data
ts(b);
// get the retrieved data
auto& psi_data = heap->psi_heap();
// what have we got?
// parse time and date section and
// time offset section on pid 0x14
// iterate over all sections parsed
for (auto& v : psi_data)
// v.first is the section_identifier tuple
// v.second is the actual PSISection
// check the section id
if ((get<0>(v.first) == 0x70) || (get<0>(v.first) == 0x73)) {
// load tssi functions into this scope
using namespace etsi300468::time_date_section;
// return timecode in this section (already converted to time_t)
auto time = UTC_time(v.second.psi_data());
// print and good bye
cout << ctime(&time) << endl;
break;
}
}