Headers.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef __HEADERS_H_FCE771847176E1__
00043 #define __HEADERS_H_FCE771847176E1__
00044
00045
00046 #include "debug.h"
00047
00048
00049 namespace famouso {
00050 namespace mw {
00051 namespace afp {
00052 namespace defrag {
00053
00054
00058 template <class DCP>
00059 class Headers {
00060
00061 typedef typename DCP::SizeProp::elen_t elen_t;
00062 typedef typename DCP::SizeProp::flen_t flen_t;
00063 typedef typename DCP::SizeProp::fcount_t fcount_t;
00064
00065 typedef class DCP::DemuxPolicy::EventSeqHeaderPolicy EventSeqHeader;
00066 typedef class DCP::EventDataReconstructionPolicy::FECHeaderPolicy FECHeader;
00067
00068 protected:
00069
00071 flen_t all_header_length;
00072
00074 flen_t ext_header_length;
00075
00076 public:
00077
00079 bool first_fragment;
00080
00082 fcount_t fseq;
00083
00085 EventSeqHeader eseq;
00086
00088 FECHeader fec;
00089
00090
00096 Headers(const uint8_t * data) {
00097
00098 all_header_length = 0;
00099 ext_header_length = 0;
00100
00101
00102 uint8_t h = data[0];
00103
00104 flen_t b_header_length = 1;
00105 while (h & 0x80) {
00106 b_header_length++;
00107 h <<= 1;
00108 }
00109
00110 bool one_more_header = h & 0x40;
00111 first_fragment = h & 0x20;
00112
00113 if (b_header_length > sizeof(fseq) || b_header_length > 6) {
00114 ::logging::log::emit< ::logging::Warning>()
00115 << PROGMEMSTRING("AFP: Receiving to large event! Dropping fragment!")
00116 << ::logging::log::endl;
00117 fseq = 0;
00118 return;
00119 }
00120
00121
00122 fseq = data[0] & (0x3f >> b_header_length);
00123 for (uint8_t i = 1; i < b_header_length; i++) {
00124 fseq <<= 8;
00125 fseq |= data[i];
00126 }
00127
00128 data += b_header_length;
00129
00130
00131 flen_t e_header_length;
00132 while (one_more_header) {
00133 if (eseq.check(data))
00134 e_header_length = eseq.read_header(data);
00135 else if (fec.check(data))
00136 e_header_length = fec.read_header(data);
00137 else {
00138
00139 ::logging::log::emit< ::logging::Error>()
00140 << PROGMEMSTRING("AFP: Unknown or unsupported extension header ")
00141 << (*data & 0x1f)
00142 << PROGMEMSTRING("! Dropping fragment!")
00143 << ::logging::log::endl;
00144 return;
00145 }
00146 if (!e_header_length) {
00147
00148 return;
00149 }
00150 one_more_header = *data & 0x40;
00151 ext_header_length += e_header_length;
00152 data += e_header_length;
00153 }
00154
00155
00156 all_header_length = b_header_length + ext_header_length;
00157 }
00158
00160 bool error() const {
00161 return all_header_length == 0;
00162 }
00163
00165 flen_t length() const {
00166 return all_header_length;
00167 }
00168
00170 flen_t ext_length() const {
00171 return ext_header_length;
00172 }
00173 };
00174
00175
00176 }
00177 }
00178 }
00179 }
00180
00181
00182 #endif // __HEADERS_H_FCE771847176E1__
00183