Ginga  0.13.6
 All Classes Namespaces Functions Variables
TSPacket.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef TSPACKET_
51 #define TSPACKET_
52 
53 #include "Pat.h"
54 using namespace ::br::pucrio::telemidia::ginga::core::tsparser::si;
55 
56 #include "ITSPacket.h"
57 #include "tsparser/TSAdaptationField.h"
58 
59 #include <iostream>
60 using namespace std;
61 
62 namespace br {
63 namespace pucrio {
64 namespace telemidia {
65 namespace ginga {
66 namespace core {
67 namespace tsparser {
68  class TSPacket : public ITSPacket {
69  protected:
70  //
71  // ISO/IEC 13818-1 TS PACKET HEADER
72  //
73 
74  // Value must be 0x47. (1 byte)
75  char syncByte;
76 
77  // Error indicator flag. (1 bit)
78  // 1 Error
79  // 0 OK
80  bool transportErrorIndication;
81 
82  // Indicator that carries PES packets or PSI data.
83  // (1 bit)
84  // 1 Indicates that the payload of this TS packet
85  // will start with the first byte of a PES
86  // packet.
87  // 0 Indicates no PES packet shall start in this
88  // TS packet.
89  bool payloadUnitStartIndicator;
90 
91  // Indicates that the associated packet is of greater
92  // priority than other packets having the same PID.
93  bool transportPriority;
94 
95  // Indicates the type of the data stored in
96  // the payload. (13 bits)
97  // 0x00 PAT
98  // 0x01 CAT
99  // 0x02 TS description table
100  // 0x03 IPMP control
101  unsigned short pid;
102 
103  // Indicates the scrambling mode of the TS packet.
104  // (2 bits)
105  // 00 Not scrambled
106  // 01 User Defined
107  // 10 User Defined
108  // 11 User Defined
109  unsigned char transportScramblingControl;
110 
111  // Indicates whether this TS packet header is followed
112  // by an adaptation field and/or payload. (2 bits)
113  // 00 ISO future use; packet must be discarded
114  // 01 no adaptation field (payload only)
115  // 10 adaptation field only (no payload)
116  // 11 adaptation field followed by payload
117  static const unsigned int FUTURE_USE = 0;
118  static const unsigned int PAYLOAD_ONLY = 1;
119  static const unsigned int NO_PAYLOAD = 2;
120  static const unsigned int ADAPT_PAYLOAD = 3;
121  unsigned int adaptationFieldControl;
122 
123  // Incrementing with each TS packet with the same PID.
124  // This field shall not be incremented when the
125  // adaptationFieldControl is set to 00 or 10. (4 bits)
126  unsigned char continuityCounter;
127 
128  // TODO: AdaptationField?
129 
130  // Number of bytes immediately following this
131  // pointerField until the first byte of the first
132  // section that is present in the payload. The
133  // maximum value is 182. If the
134  // payloadUnitStartIndicator is set to 1, then the
135  // first byte of the payload is the pointerField
136  // itself.
137  unsigned char pointerField;
138 
139  bool streamUpdated;
140  unsigned int packetCount;
141 
142  // Packet payload data. (184 bytes) If pointerField
143  // is present, then the payload size is 183 bytes.
144  char* stream;
145  char payload[TS_PAYLOAD_SIZE];
146  char payload2[TS_PAYLOAD_SIZE];
147  TSAdaptationField* tsaf;
148  unsigned char payloadSize;
149  unsigned char payloadSize2;
150  bool isSectionType;
151  bool constructionFailed;
152 
153  public:
154  //Constructor to read a TS packet
155  TSPacket(char* packetData);
156 
157  //Constructor to encode a TS packet
158  TSPacket(
159  bool sectionType,
160  char* payload,
161  unsigned char payloadSize);
162 
163  virtual ~TSPacket();
164 
165  private:
166  void releaseTSAF();
167  void releaseStream();
168 
169  protected:
170  bool create(char data[TS_PACKET_SIZE]);
171  char updateStream();
172 
173  public:
174  bool isConstructionFailed();
175  unsigned short getPid();
176  char getPacketData(char** dataStream);
177  void getPayload(char streamData[TS_PAYLOAD_SIZE]);
178  void getPayload2(char streamData[TS_PAYLOAD_SIZE]);
179  unsigned char getPayloadSize();
180  unsigned char getPayloadSize2();
181  bool getStartIndicator();
182  unsigned char getPointerField();
183  unsigned char getAdaptationFieldControl();
184  unsigned char getContinuityCounter();
185  void setPid(unsigned short pid);
186  void setContinuityCounter(unsigned int counter);
187  void print();
188  void setPacketCount(unsigned int count);
189  unsigned int getPacketCount();
190  };
191 }
192 }
193 }
194 }
195 }
196 }
197 
198 #endif /*TSPACKET_*/