a384c2e68b7a2145587a9a2f139adaeb0fcae5d9
[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 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief MPESection public header */
30
31 #ifndef HH_SENF_Packets_MPEGDVBBundle_MPESection_
32 #define HH_SENF_Packets_MPEGDVBBundle_MPESection_ 1
33
34 // Custom includes
35 #include <boost/crc.hpp>
36 #include <senf/Packets/Packets.hh>
37
38 //#include "MPESection.mpp"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace senf {
42
43     struct MPERealTimeParametersParser : public PacketParserBase
44     {
45 #       include SENF_FIXED_PARSER()
46
47         SENF_PARSER_BITFIELD ( delta_t,                  12, unsigned );
48         SENF_PARSER_BITFIELD ( table_boundary,           1,  bool     );
49         SENF_PARSER_BITFIELD ( frame_boundary,           1,  bool     );
50         SENF_PARSER_BITFIELD ( address,                  18, unsigned );
51
52         SENF_PARSER_FINALIZE( MPERealTimeParametersParser );
53     };
54
55
56     /** \brief Parse a MPE Section
57
58         Parser implementing the header of a MPE Section
59
60         \see MPESectionType
61      */
62     class MPESectionParser : public PacketParserBase
63     {
64     public:
65 #       include SENF_FIXED_PARSER()
66
67         SENF_PARSER_FIELD( table_id, UInt8Parser );
68
69         SENF_PARSER_BITFIELD        ( section_syntax_indicator, 1,  bool     );
70         SENF_PARSER_BITFIELD        ( private_indicator,        1,  bool     );
71         SENF_PARSER_PRIVATE_BITFIELD( reserved_1,               2,  unsigned );
72         SENF_PARSER_BITFIELD        ( section_length,           12, unsigned );
73
74         SENF_PARSER_FIELD( mac_addr_6, UInt8Parser );
75         SENF_PARSER_FIELD( mac_addr_5, UInt8Parser );
76
77         SENF_PARSER_PRIVATE_BITFIELD( reserved_2,          2, unsigned );
78         SENF_PARSER_BITFIELD        ( payload_scrmbl_ctrl, 2, unsigned );
79         SENF_PARSER_BITFIELD        ( addr_scrmbl_ctrl,    2, unsigned );
80         SENF_PARSER_BITFIELD        ( llc_snap_flag,       1, bool     );
81         SENF_PARSER_BITFIELD        ( curr_next_indicator, 1, bool     );
82
83         SENF_PARSER_FIELD( section_num,      UInt8Parser );
84         SENF_PARSER_FIELD( last_section_num, UInt8Parser );
85
86         SENF_PARSER_FIELD( real_time_parameters, MPERealTimeParametersParser );
87
88         SENF_PARSER_FINALIZE( MPESectionParser );
89
90         SENF_PARSER_PRIVATE_BITFIELD( ip_datagram_version, 4, unsigned );
91
92         SENF_PARSER_INIT() {
93             table_id() = 0x3e;
94             section_syntax_indicator() = 1;
95             private_indicator() = 0;
96             reserved_1() = 3;
97             reserved_2() = 3;
98             payload_scrmbl_ctrl() = 0;
99             addr_scrmbl_ctrl() = 0;
100             curr_next_indicator() = 1;
101         }
102
103         UInt32Parser crc() const { return parse<UInt32Parser>( data().size()-4 ); }
104         boost::uint32_t calcCrc() const;
105
106         friend class MPESectionType;
107
108     private:
109         typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> crc32_t;
110     };
111
112
113     /** \brief MPE Section
114
115         \par Packet type (typedef):
116             \ref MPESection
117
118         \par Fields:
119             \ref MPESectionParser
120             \image html MPESection.png
121
122         \ingroup protocolbundle_mpegdvb
123      */
124     struct MPESectionType
125         : public PacketTypeBase,
126           public PacketTypeMixin<MPESectionType>
127     {
128 #ifndef DOXYGEN
129         typedef PacketTypeMixin<MPESectionType> mixin;
130 #endif
131         typedef ConcretePacket<MPESectionType> packet; ///< MPESection packet typedef
132         typedef MPESectionParser parser;               ///< typedef to the parser of MPESection
133
134         using mixin::nextPacketRange;
135         using mixin::init;
136
137         /** \brief Dump given MPESection in readable form to given output stream */
138         static void dump(packet p, std::ostream & os);
139
140         static void finalize(packet p);
141
142         static factory_t nextPacketType(packet p);
143
144         static PacketParserBase::size_type initSize();
145         static PacketParserBase::size_type initHeadSize();
146     };
147
148     /** \brief MPESection packet typedef
149          \ingroup protocolbundle_mpegdvb
150      */
151     typedef ConcretePacket<MPESectionType> MPESection;
152 }
153
154 //-/////////////////////////////////////////////////////////////////////////////////////////////////
155 //#include "MPESection.cci"
156 //#include "MPESection.ct"
157 //#include "MPESection.cti"
158 #endif
159
160 \f
161 // Local Variables:
162 // mode: c++
163 // fill-column: 100
164 // c-file-style: "senf"
165 // indent-tabs-mode: nil
166 // ispell-local-dictionary: "american"
167 // compile-command: "scons -u test"
168 // comment-column: 40
169 // End: