switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / MPEGDVBBundle / TransportPacket.hh
1 // $Id:TransportPacket.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 TransportPacket public header */
30
31 #ifndef HH_SENF_Packets_MPEGDVBBundle_TransportPacket_
32 #define HH_SENF_Packets_MPEGDVBBundle_TransportPacket_ 1
33
34 // Custom includes
35 #include <senf/Packets/Packets.hh>
36
37 //#include "TransportPacket.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41
42     /** \brief Parse a Transport Stream packet
43
44         Parser implementing the header of a MPEG Transport Stream packet.
45         \image html TransportPacket.png
46
47         \see TransportPacketType
48      */
49     struct TransportPacketParser : public PacketParserBase
50     {
51 #       include SENF_PARSER()
52
53         SENF_PARSER_FIELD       ( sync_byte,                  UInt8Parser );
54
55         SENF_PARSER_BITFIELD    ( transport_error_indicator,  1, bool     );
56         SENF_PARSER_BITFIELD_RO ( pusi,                       1, bool     );
57         SENF_PARSER_BITFIELD    ( transport_priority,         1, bool     );
58         SENF_PARSER_BITFIELD    ( pid,                       13, unsigned );
59         SENF_PARSER_BITFIELD    ( transport_scrmbl_ctrl,      2, unsigned );
60         SENF_PARSER_BITFIELD    ( adaptation_field_ctrl,      2, unsigned );
61         SENF_PARSER_BITFIELD    ( continuity_counter,         4, unsigned );
62
63         SENF_PARSER_PRIVATE_VARIANT ( pointer_field_, pusi,
64                 (senf::VoidPacketParser) (UInt8Parser) );
65
66         SENF_PARSER_FINALIZE( TransportPacketParser );
67
68         UInt8Parser pointer_field() const;
69         void init_fields() const;
70         void setPUSI(bool pusi) const;
71
72         SENF_PARSER_INIT() {
73             defaultInit();
74             init_fields();
75         }
76     };
77
78     /** \brief Transport Stream packet
79
80         <table class="senf">
81           <tr style="text-align:center">
82             <th>Syntax</th><th>No. of bits</th></tr>
83           <tr>
84             <td>transport_packet() {</td> <td></td>
85           </tr>
86           <tr>
87             <td style="padding-left:2em">\ref TransportPacketParser::sync_byte() "sync_byte"</td>
88             <td>8</td></tr>
89           <tr>
90             <td style="padding-left:2em">\ref TransportPacketParser::transport_error_indicator() "transport_error_indicator"</td>
91             <td>1</td></tr>
92           <tr>
93             <td style="padding-left:2em">\ref TransportPacketParser::pusi() "payload_uni_start_indicator"</td>
94             <td>1</td></tr>
95           <tr>
96             <td style="padding-left:2em">\ref TransportPacketParser::transport_priority() "transport_priority"</td>
97             <td>1</td></tr>
98           <tr>
99             <td style="padding-left:2em">\ref TransportPacketParser::pid() "PID"</td>
100             <td>13</td></tr>
101           <tr>
102             <td style="padding-left:2em">\ref TransportPacketParser::transport_scrmbl_ctrl() "transport_scrambling_control"</td>
103             <td>2</td></tr>
104           <tr>
105             <td style="padding-left:2em">\ref TransportPacketParser::adaptation_field_ctrl() "adaptation_field_control"</td>
106             <td>2</td></tr>
107           <tr>
108             <td style="padding-left:2em">\ref TransportPacketParser::continuity_counter() "continuity_counter"</td>
109             <td>4</td></tr>
110           <tr>
111             <td>}</td> <td></td></tr>
112         </table>
113
114         \par Packet type (typedef):
115             \ref TransportPacket
116
117         \par Fields:
118             \ref TransportPacketParser
119
120         \ingroup protocolbundle_mpegdvb
121      */
122     struct TransportPacketType
123         : public PacketTypeBase,
124           public PacketTypeMixin<TransportPacketType>
125     {
126 #ifndef DOXYGEN
127         typedef PacketTypeMixin<TransportPacketType> mixin;
128 #endif
129         typedef ConcretePacket<TransportPacketType> packet; ///< Transport packet typedef
130         typedef TransportPacketParser parser; ///< typedef to the parser of Transport packet
131
132         using mixin::nextPacketRange;
133         using mixin::init;
134         using mixin::initSize;
135
136         /** \brief Dump given Transport packet in readable form to given output stream */
137         static void dump(packet p, std::ostream & os);
138         static const byte SYNC_BYTE = 0x47;
139     };
140
141     /** \brief Transport packet typedef */
142     typedef ConcretePacket<TransportPacketType> TransportPacket;
143 }
144
145
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 //#include "TransportPacket.cci"
148 //#include "TransportPacket.ct"
149 //#include "TransportPacket.cti"
150 #endif
151
152 \f
153 // Local Variables:
154 // mode: c++
155 // fill-column: 100
156 // c-file-style: "senf"
157 // indent-tabs-mode: nil
158 // ispell-local-dictionary: "american"
159 // compile-command: "scons -u test"
160 // comment-column: 40
161 // End: