22 #include "spdlog/spdlog.h"
26 : _instance_id( instance_id )
27 , _global_fec_oti( fec_oti )
32 : _instance_id( instance_id )
34 tinyxml2::XMLDocument
doc(
true, tinyxml2::COLLAPSE_WHITESPACE);
35 doc.Parse(buffer, len);
36 auto fdt_instance =
doc.FirstChildElement(
"FDT-Instance");
37 _expires = std::stoull(fdt_instance->Attribute(
"Expires"));
39 spdlog::debug(
"Received new FDT with instance ID {}",
instance_id);
41 uint8_t def_fec_encoding_id = 0;
42 auto val = fdt_instance->Attribute(
"FEC-OTI-FEC-Encoding-ID");
44 def_fec_encoding_id = strtoul(val,
nullptr, 0);
47 uint32_t def_fec_max_source_block_length = 0;
48 val = fdt_instance->Attribute(
"FEC-OTI-Maximum-Source-Block-Length");
50 def_fec_max_source_block_length = strtoul(val,
nullptr, 0);
53 uint32_t def_fec_encoding_symbol_length = 0;
54 val = fdt_instance->Attribute(
"FEC-OTI-Encoding-Symbol-Length");
56 def_fec_encoding_symbol_length = strtoul(val,
nullptr, 0);
59 for (
auto file = fdt_instance->FirstChildElement(
"File");
60 file !=
nullptr; file = file->NextSiblingElement(
"File")) {
63 auto toi_str = file->Attribute(
"TOI");
64 if (toi_str ==
nullptr) {
65 throw "Missing TOI attribute on File element";
67 uint32_t toi = strtoull(toi_str,
nullptr, 0);
69 auto content_location = file->Attribute(
"Content-Location");
70 if (content_location ==
nullptr) {
71 throw "Missing Content-Location attribute on File element";
74 uint32_t content_length = 0;
75 val = file->Attribute(
"Content-Length");
77 content_length = strtoull(val,
nullptr, 0);
80 uint32_t transfer_length = 0;
81 val = file->Attribute(
"Transfer-Length");
83 transfer_length = strtoull(val,
nullptr, 0);
86 auto content_md5 = file->Attribute(
"Content-MD5");
91 auto content_type = file->Attribute(
"Content-Type");
96 auto encoding_id = def_fec_encoding_id;
97 val = file->Attribute(
"FEC-OTI-FEC-Encoding-ID");
99 encoding_id = strtoul(val,
nullptr, 0);
102 auto max_source_block_length = def_fec_max_source_block_length;
103 val = file->Attribute(
"FEC-OTI-Maximum-Source-Block-Length");
104 if (val !=
nullptr) {
105 max_source_block_length = strtoul(val,
nullptr, 0);
108 auto encoding_symbol_length = def_fec_encoding_symbol_length;
109 val = file->Attribute(
"FEC-OTI-Encoding-Symbol-Length");
110 if (val !=
nullptr) {
111 encoding_symbol_length = strtoul(val,
nullptr, 0);
113 uint32_t expires = 0;
114 auto cc = file->FirstChildElement(
"mbms2007:Cache-Control");
116 auto expires_elem = cc->FirstChildElement(
"mbms2007:Expires");
118 expires = strtoul(expires_elem->GetText(),
nullptr, 0);
125 encoding_symbol_length,
126 max_source_block_length
131 std::string(content_location),
133 std::string(content_md5),
134 std::string(content_type),
138 _file_entries.push_back(fe);
145 _file_entries.push_back(fe);
150 for (
auto it = _file_entries.cbegin(); it != _file_entries.cend();) {
151 if (it->toi == toi) {
152 it = _file_entries.erase(it);
161 tinyxml2::XMLDocument
doc;
162 doc.InsertFirstChild(
doc.NewDeclaration() );
163 auto root =
doc.NewElement(
"FDT-Instance");
164 root->SetAttribute(
"Expires", std::to_string(_expires).c_str());
165 root->SetAttribute(
"FEC-OTI-FEC-Encoding-ID", (
unsigned)_global_fec_oti.encoding_id);
166 root->SetAttribute(
"FEC-OTI-Maximum-Source-Block-Length", (
unsigned)_global_fec_oti.max_source_block_length);
167 root->SetAttribute(
"FEC-OTI-Encoding-Symbol-Length", (
unsigned)_global_fec_oti.encoding_symbol_length);
168 root->SetAttribute(
"xmlns:mbms2007",
"urn:3GPP:metadata:2007:MBMS:FLUTE:FDT");
169 doc.InsertEndChild(root);
171 for (
const auto& file : _file_entries) {
172 auto f =
doc.NewElement(
"File");
173 f->SetAttribute(
"TOI", file.toi);
174 f->SetAttribute(
"Content-Location", file.content_location.c_str());
175 f->SetAttribute(
"Content-Length", file.content_length);
176 f->SetAttribute(
"Transfer-Length", (
unsigned)file.fec_oti.transfer_length);
177 f->SetAttribute(
"Content-MD5", file.content_md5.c_str());
178 f->SetAttribute(
"Content-Type", file.content_type.c_str());
179 auto cc =
doc.NewElement(
"mbms2007:Cache-Control");
180 auto exp =
doc.NewElement(
"mbms2007:Expires");
181 exp->SetText(std::to_string(file.expires).c_str());
182 cc->InsertEndChild(exp);
183 f->InsertEndChild(cc);
184 root->InsertEndChild(f);
188 tinyxml2::XMLPrinter printer;
190 return std::string(printer.CStr());
uint32_t instance_id()
Get the FDT instance ID.
void remove(uint32_t toi)
Remove a file entry.
std::string to_string() const
Serialize the FDT to an XML string.
FileDeliveryTable(uint32_t instance_id, FecOti fec_oti)
Create an empty FDT.
void add(const FileEntry &entry)
Add a file entry.
FecScheme
Error correction schemes.
An entry for a file in the FDT.