-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmot_manager.h
126 lines (100 loc) · 3.29 KB
/
mot_manager.h
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
120
121
122
123
124
125
126
/*
DABlin - capital DAB experience
Copyright (C) 2016-2018 Stefan Pöschel
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/>.
*/
#ifndef MOT_MANAGER_H_
#define MOT_MANAGER_H_
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <vector>
#include <QDebug>
#include "charsets.h"
#include "tools.h"
// --- MOT_FILE -----------------------------------------------------------------
struct MOT_FILE {
std::vector<uint8_t> data;
// from header core
size_t body_size;
int content_type;
int content_sub_type;
// from header extension
std::string content_name;
std::string content_name_charset;
std::string category_title;
std::string click_through_url;
bool trigger_time_now;
static const int CONTENT_TYPE_IMAGE = 0x02;
static const int CONTENT_TYPE_MOT_TRANSPORT = 0x05;
static const int CONTENT_SUB_TYPE_JFIF = 0x001;
static const int CONTENT_SUB_TYPE_PNG = 0x003;
static const int CONTENT_SUB_TYPE_HEADER_UPDATE = 0x000;
MOT_FILE() :
body_size(-1),
content_type(-1),
content_sub_type(-1),
trigger_time_now(false)
{}
};
typedef std::vector<uint8_t> seg_t;
typedef std::map<int,seg_t> segs_t;
// --- MOTEntity -----------------------------------------------------------------
class MOTEntity {
private:
segs_t segs;
int last_seg_number;
size_t size;
public:
MOTEntity() {Reset();}
void Reset() {
segs.clear();
last_seg_number = -1;
size = 0;
}
void AddSeg(int seg_number, bool last_seg, const uint8_t* data, size_t len);
bool IsFinished();
size_t GetSize() {return size;}
std::vector<uint8_t> GetData();
};
// --- MOTObject -----------------------------------------------------------------
class MOTObject {
private:
MOTEntity header;
MOTEntity body;
bool header_received;
bool shown;
MOT_FILE result_file;
bool ParseCheckHeader(MOT_FILE& target_file);
public:
MOTObject(): header_received(false), shown(false) {}
void AddSeg(bool dg_type_header, int seg_number, bool last_seg, const uint8_t* data, size_t len);
bool IsToBeShown();
MOT_FILE GetFile() {return result_file;}
};
// --- MOTManager -----------------------------------------------------------------
class MOTManager {
private:
MOTObject object;
int current_transport_id;
bool ParseCheckDataGroupHeader(const std::vector<uint8_t>& dg, size_t& offset, int& dg_type);
bool ParseCheckSessionHeader(const std::vector<uint8_t>& dg, size_t& offset, bool& last_seg, int& seg_number, int& transport_id);
bool ParseCheckSegmentationHeader(const std::vector<uint8_t>& dg, size_t& offset, size_t& seg_size);
public:
MOTManager();
void Reset();
bool HandleMOTDataGroup(const std::vector<uint8_t>& dg);
MOT_FILE GetFile() {return object.GetFile();}
};
#endif /* MOT_MANAGER_H_ */