0afe01431f0213d62f56915f69d7ea08d3b38b93
[senf.git] / senf / Packets / MPEGDVBBundle / MPESection.hh
1 // $Id:MPESection.hh 560 2007-12-13 14:39:37Z tho $
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief MPESection public header */
25
26 #ifndef HH_SENF_Packets_MPEGDVBBundle_MPESection_
27 #define HH_SENF_Packets_MPEGDVBBundle_MPESection_ 1
28
29 // Custom includes
30 #include <boost/crc.hpp>
31 #include <senf/Packets/Packets.hh>
32
33 //#include "MPESection.mpp"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 namespace senf {
37
38     struct MPERealTimeParametersParser : public PacketParserBase
39     {
40 #       include SENF_FIXED_PARSER()
41
42         SENF_PARSER_BITFIELD ( delta_t,                  12, unsigned );
43         SENF_PARSER_BITFIELD ( table_boundary,           1,  bool     );
44         SENF_PARSER_BITFIELD ( frame_boundary,           1,  bool     );
45         SENF_PARSER_BITFIELD ( address,                  18, unsigned );
46
47         SENF_PARSER_FINALIZE( MPERealTimeParametersParser );
48     };
49
50
51     /** \brief Parse a MPE Section
52
53         Parser implementing the header of a MPE Section
54
55         \see MPESectionType
56      */
57     class MPESectionParser : public PacketParserBase
58     {
59     public:
60 #       include SENF_FIXED_PARSER()
61
62         SENF_PARSER_FIELD( table_id, UInt8Parser );
63
64         SENF_PARSER_BITFIELD        ( section_syntax_indicator, 1,  bool     );
65         SENF_PARSER_BITFIELD        ( private_indicator,        1,  bool     );
66         SENF_PARSER_PRIVATE_BITFIELD( reserved_1,               2,  unsigned );
67         SENF_PARSER_BITFIELD        ( section_length,           12, unsigned );
68
69         SENF_PARSER_FIELD( mac_addr_6, UInt8Parser );
70         SENF_PARSER_FIELD( mac_addr_5, UInt8Parser );
71
72         SENF_PARSER_PRIVATE_BITFIELD( reserved_2,          2, unsigned );
73         SENF_PARSER_BITFIELD        ( payload_scrmbl_ctrl, 2, unsigned );
74         SENF_PARSER_BITFIELD        ( addr_scrmbl_ctrl,    2, unsigned );
75         SENF_PARSER_BITFIELD        ( llc_snap_flag,       1, bool     );
76         SENF_PARSER_BITFIELD        ( curr_next_indicator, 1, bool     );
77
78         SENF_PARSER_FIELD( section_num,      UInt8Parser );
79         SENF_PARSER_FIELD( last_section_num, UInt8Parser );
80
81         SENF_PARSER_FIELD( real_time_parameters, MPERealTimeParametersParser );
82
83         SENF_PARSER_FINALIZE( MPESectionParser );
84
85         SENF_PARSER_PRIVATE_BITFIELD( ip_datagram_version, 4, unsigned );
86
87         SENF_PARSER_INIT() {
88             table_id() = 0x3e;
89             section_syntax_indicator() = 1;
90             private_indicator() = 0;
91             reserved_1() = 3;
92             reserved_2() = 3;
93             payload_scrmbl_ctrl() = 0;
94             addr_scrmbl_ctrl() = 0;
95             curr_next_indicator() = 1;
96         }
97
98         UInt32Parser crc() const { return parse<UInt32Parser>( data().size()-4 ); }
99         boost::uint32_t calcCrc() const;
100
101         friend class MPESectionType;
102
103     private:
104         typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> crc32_t;
105     };
106
107
108     /** \brief MPE Section
109
110         \par Packet type (typedef):
111             \ref MPESection
112
113         \par Fields:
114             \ref MPESectionParser
115             \image html MPESection.png
116
117         \ingroup protocolbundle_mpegdvb
118      */
119     struct MPESectionType
120         : public PacketTypeBase,
121           public PacketTypeMixin<MPESectionType>
122     {
123 #ifndef DOXYGEN
124         typedef PacketTypeMixin<MPESectionType> mixin;
125 #endif
126         typedef ConcretePacket<MPESectionType> packet; ///< MPESection packet typedef
127         typedef MPESectionParser parser;               ///< typedef to the parser of MPESection
128
129         using mixin::nextPacketRange;
130         using mixin::init;
131
132         /** \brief Dump given MPESection in readable form to given output stream */
133         static void dump(packet p, std::ostream & os);
134
135         static void finalize(packet p);
136
137         static factory_t nextPacketType(packet p);
138
139         static PacketParserBase::size_type initSize();
140         static PacketParserBase::size_type initHeadSize();
141     };
142
143     /** \brief MPESection packet typedef
144          \ingroup protocolbundle_mpegdvb
145      */
146     typedef ConcretePacket<MPESectionType> MPESection;
147 }
148
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 //#include "MPESection.cci"
151 //#include "MPESection.ct"
152 //#include "MPESection.cti"
153 #endif
154
155 \f
156 // Local Variables:
157 // mode: c++
158 // fill-column: 100
159 // c-file-style: "senf"
160 // indent-tabs-mode: nil
161 // ispell-local-dictionary: "american"
162 // compile-command: "scons -u test"
163 // comment-column: 40
164 // End: