Commit d8416ef00da001ad651a5c192708bc2b9880e8da
1 parent
a17be48c
Exists in
master
and in
1 other branch
Remove /util/src/tspacket.cpp, pois é obsoleto
Showing
3 changed files
with
0 additions
and
875 deletions
Show diff stats
Makefile-libras.mk
... | ... | @@ -1,128 +0,0 @@ |
1 | -# | |
2 | -# There exist several targets which are by default empty and which can be | |
3 | -# used for execution of your targets. These targets are usually executed | |
4 | -# before and after some main targets. They are: | |
5 | -# | |
6 | -# .build-pre: called before 'build' target | |
7 | -# .build-post: called after 'build' target | |
8 | -# .clean-pre: called before 'clean' target | |
9 | -# .clean-post: called after 'clean' target | |
10 | -# .clobber-pre: called before 'clobber' target | |
11 | -# .clobber-post: called after 'clobber' target | |
12 | -# .all-pre: called before 'all' target | |
13 | -# .all-post: called after 'all' target | |
14 | -# .help-pre: called before 'help' target | |
15 | -# .help-post: called after 'help' target | |
16 | -# | |
17 | -# Targets beginning with '.' are not intended to be called on their own. | |
18 | -# | |
19 | -# Main targets can be executed directly, and they are: | |
20 | -# | |
21 | -# build build a specific configuration | |
22 | -# clean remove built files from a configuration | |
23 | -# clobber remove all built files | |
24 | -# all build all configurations | |
25 | -# help print help mesage | |
26 | -# | |
27 | -# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and | |
28 | -# .help-impl are implemented in nbproject/makefile-impl.mk. | |
29 | -# | |
30 | -# Available make variables: | |
31 | -# | |
32 | -# CND_BASEDIR base directory for relative paths | |
33 | -# CND_DISTDIR default top distribution directory (build artifacts) | |
34 | -# CND_BUILDDIR default top build directory (object files, ...) | |
35 | -# CONF name of current configuration | |
36 | -# CND_PLATFORM_${CONF} platform name (current configuration) | |
37 | -# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) | |
38 | -# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) | |
39 | -# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) | |
40 | -# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) | |
41 | -# CND_PACKAGE_NAME_${CONF} name of package (current configuration) | |
42 | -# CND_PACKAGE_PATH_${CONF} path to package (current configuration) | |
43 | -# | |
44 | -# NOCDDL | |
45 | - | |
46 | - | |
47 | -# Environment | |
48 | -MKDIR=mkdir | |
49 | -CP=cp | |
50 | -CCADMIN=CCadmin | |
51 | - | |
52 | - | |
53 | -# build | |
54 | -build: .build-post | |
55 | - | |
56 | -.build-pre: | |
57 | -# Add your pre 'build' code here... | |
58 | - | |
59 | -.build-post: .build-impl | |
60 | -# Add your post 'build' code here... | |
61 | - | |
62 | - | |
63 | -# clean | |
64 | -clean: .clean-post | |
65 | - | |
66 | -.clean-pre: | |
67 | -# Add your pre 'clean' code here... | |
68 | - | |
69 | -.clean-post: .clean-impl | |
70 | -# Add your post 'clean' code here... | |
71 | - | |
72 | - | |
73 | -# clobber | |
74 | -clobber: .clobber-post | |
75 | - | |
76 | -.clobber-pre: | |
77 | -# Add your pre 'clobber' code here... | |
78 | - | |
79 | -.clobber-post: .clobber-impl | |
80 | -# Add your post 'clobber' code here... | |
81 | - | |
82 | - | |
83 | -# all | |
84 | -all: .all-post | |
85 | - | |
86 | -.all-pre: | |
87 | -# Add your pre 'all' code here... | |
88 | - | |
89 | -.all-post: .all-impl | |
90 | -# Add your post 'all' code here... | |
91 | - | |
92 | - | |
93 | -# build tests | |
94 | -build-tests: .build-tests-post | |
95 | - | |
96 | -.build-tests-pre: | |
97 | -# Add your pre 'build-tests' code here... | |
98 | - | |
99 | -.build-tests-post: .build-tests-impl | |
100 | -# Add your post 'build-tests' code here... | |
101 | - | |
102 | - | |
103 | -# run tests | |
104 | -test: .test-post | |
105 | - | |
106 | -.test-pre: | |
107 | -# Add your pre 'test' code here... | |
108 | - | |
109 | -.test-post: .test-impl | |
110 | -# Add your post 'test' code here... | |
111 | - | |
112 | - | |
113 | -# help | |
114 | -help: .help-post | |
115 | - | |
116 | -.help-pre: | |
117 | -# Add your pre 'help' code here... | |
118 | - | |
119 | -.help-post: .help-impl | |
120 | -# Add your post 'help' code here... | |
121 | - | |
122 | - | |
123 | - | |
124 | -# include project implementation makefile | |
125 | -include nbproject/Makefile-impl.mk | |
126 | - | |
127 | -# include project make variables | |
128 | -include nbproject/Makefile-variables.mk |
util/src/include/tspacket.h
... | ... | @@ -1,122 +0,0 @@ |
1 | -#ifndef _TSPACKET_H_ | |
2 | -#define _TSPACKET_H_ | |
3 | - | |
4 | -/** | |
5 | - * Esse arquivo possui fun??????es que retornam os campos de um pacote TS | |
6 | - * As informa??????es necess???rias para a constru??????o deste arquivo estao na | |
7 | -especifica??????o | |
8 | - * ISO/IEC 13818-1, Table 2-2, pag 18. | |
9 | - * | |
10 | - **/ | |
11 | - | |
12 | -#include <stdio.h> | |
13 | -#include <string.h> | |
14 | -#include <stdint.h> | |
15 | -#include <stdlib.h> | |
16 | -//#include "section.h" | |
17 | - | |
18 | -#define PID_PACOTE_NULO 0x1FFF | |
19 | - | |
20 | -/* 71 == 0x47*/ | |
21 | -#define SYNC_BYTE 71 | |
22 | - | |
23 | -#define PACKET_SIZE 188 | |
24 | -#define MAX_PAYLOAD_SIZE 184 | |
25 | -#define STUFFING_BYTE 0xFF | |
26 | - | |
27 | -#define AFC_RESERVED 0 | |
28 | -#define AFC_ONLY_PAYLOAD 1 | |
29 | -#define AFC_ONLY_ADAPT_FIELD 2 | |
30 | -#define AFC_BOTH_PAYLOAD_AND_ADAPT_FIELD 3 | |
31 | - | |
32 | -#define SC_NOT_SCRAMBLED 0 | |
33 | -#define SC_USER_DEFINED_1 1 | |
34 | -#define SC_USER_DEFINED_2 2 | |
35 | -#define SC_USER_DEFINED_3 3 | |
36 | - | |
37 | -#ifndef NULL | |
38 | -#define NULL 0 | |
39 | -#endif | |
40 | - | |
41 | -/// Assinatura das funcoes: | |
42 | - | |
43 | -/// Genericas | |
44 | -unsigned char * getPayload (unsigned char * pacote, unsigned int * | |
45 | -length); | |
46 | -unsigned int getPayloadLength (unsigned char * pacote); | |
47 | -unsigned int getAdaptationFieldLength (unsigned char * pacote); | |
48 | -char hasAdaptationField (unsigned char * pacote); | |
49 | -//char assert (int value); | |
50 | -unsigned int generateGenericTsPackets(unsigned char * tsPacketInitial, int pid, | |
51 | -unsigned char * section, unsigned int tableSize); | |
52 | -unsigned int generateTsPacket(unsigned char * tsPacketInitial, int pid, unsigned | |
53 | -char * section); | |
54 | -void create_ts_null_packet(unsigned char *buffer); | |
55 | - | |
56 | -/// Gets tamanho | |
57 | -unsigned getSectionLength(unsigned char * section); | |
58 | -unsigned getSectionDataLength(unsigned char * section); | |
59 | - | |
60 | - | |
61 | -/// Gets do cabecalho ts ... | |
62 | -int getSyncByte (unsigned char * pacote); | |
63 | -char getTransportErrorIndicator (unsigned char * pacote); | |
64 | -unsigned char getPayloadUnitStartIndicator (unsigned char * pacote); | |
65 | -char getTransportPriority (unsigned char * pacote); | |
66 | -int getPid (unsigned char * pacote); | |
67 | -char getTransportScramblingControl(unsigned char * pacote); | |
68 | -unsigned int getAdaptationFieldControl (unsigned char * pacote); | |
69 | -unsigned int getAdaptationFieldLength (unsigned char * pacote); | |
70 | -unsigned getContinuityCounter (unsigned char * pacote); | |
71 | - | |
72 | - | |
73 | - | |
74 | -/// Sets do cabecalho ts ... | |
75 | -void setSyncByte (unsigned char * pacote, int value); | |
76 | -void setTransportErrorIndicator (unsigned char * pacote, unsigned char | |
77 | -transportError); | |
78 | -void setPayloadUnitStartIndicator (unsigned char * pacote, unsigned char | |
79 | -payloadUnitStart); | |
80 | -void setTransportPriority (unsigned char * pacote, unsigned char | |
81 | -transportPriority); | |
82 | -void setPid (unsigned char * pacote, int pid); | |
83 | -void setTransportScramblingControl(unsigned char * pacote, unsigned char | |
84 | -scramblingControl); | |
85 | -void setAdaptationFieldControl (unsigned char * pacote, unsigned char | |
86 | -adaptationFieldControl); | |
87 | -void setContinuityCounter (unsigned char * pacote, unsigned char | |
88 | -continuityCounter); | |
89 | -void setPayload (unsigned char * pacote, unsigned char *data, | |
90 | -unsigned length); | |
91 | -void setAdaptationFieldLength (unsigned char * pacote, int length); | |
92 | - | |
93 | -/// Adaptation Field | |
94 | -char hasPcr (unsigned char * pacote); | |
95 | -int64_t getPcrBase (unsigned char * pacote); | |
96 | -int64_t getPcrExtension (unsigned char * pacote); | |
97 | - | |
98 | -char getDiscontinuityIndicator (unsigned char * pacote); | |
99 | -char getRandomAccessIndicator (unsigned char * pacote); | |
100 | -char getElementaryStreamPriorityIndicator(unsigned char * pacote); | |
101 | -char getPcrFlag (unsigned char * pacote); | |
102 | -char getOpcrFlag (unsigned char * pacote); | |
103 | -char getSplicingPointFlag (unsigned char * pacote); | |
104 | -char getTransportPrivateDataFlag (unsigned char * pacote); | |
105 | -char getAdaptationFieldExtensionFlag(unsigned char * pacote); | |
106 | - | |
107 | -void setPcrBase (unsigned char * pacote, int64_t pcrBase); | |
108 | -void setPcrExtension (unsigned char * pacote, int64_t pcrExtension); | |
109 | - | |
110 | -void setDiscontinuityIndicator (unsigned char * pacote, int value); | |
111 | -void setRandomAccessIndicator (unsigned char * pacote, int value); | |
112 | -void setElementaryStreamPriorityIndicator(unsigned char * pacote, int value); | |
113 | -void setPcrFlag (unsigned char * pacote, char flag); | |
114 | -void setOpcrFlag (unsigned char * pacote, char flag); | |
115 | -void setSplicingPointFlag (unsigned char * pacote, char flag); | |
116 | -void setTransportPrivateDataFlag (unsigned char * pacote, char flag); | |
117 | -void setFlagsZero (unsigned char * pacote); | |
118 | -void setAdaptationFieldExtensionFlag(unsigned char * pacote, char flag); | |
119 | - | |
120 | -#endif // _TSPACKET_H_ | |
121 | - | |
122 | - |
util/src/tspacket.cpp
... | ... | @@ -1,625 +0,0 @@ |
1 | -#include "tspacket.h" | |
2 | -//#include "debug.h" | |
3 | - | |
4 | -//#include "dprintf.h" | |
5 | - | |
6 | -// Cria pacote nulo de 188 bytes | |
7 | - void create_ts_null_packet(unsigned char *buffer){ | |
8 | - | |
9 | - unsigned char nullPacket [188]= { | |
10 | - 0x47, 0x1F, 0xFF, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
11 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
12 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
13 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
14 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
15 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
16 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
17 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
18 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
19 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
20 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
21 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
22 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
23 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
24 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
25 | - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | |
26 | - | |
27 | - memcpy(buffer, nullPacket, 188); | |
28 | - return; | |
29 | -} | |
30 | - | |
31 | - | |
32 | -/** | |
33 | - * Retorna error se value <= 0 | |
34 | - * | |
35 | - * @param value -> valor a ser avaliado | |
36 | - **/ | |
37 | -char assert(int value) | |
38 | -{ | |
39 | - if (value <= 0) | |
40 | - { | |
41 | - printf("Error no assert %d\n", value); | |
42 | - return 0; | |
43 | - } | |
44 | - else | |
45 | - return 1; | |
46 | -} | |
47 | - | |
48 | - | |
49 | -/** | |
50 | - * retorna zero se n???o h??? adaptation field, ou diferente de zero se h??? | |
51 | - * | |
52 | - * @param pacote -> pacote TS de 188 bytes | |
53 | - **/ | |
54 | -char hasAdaptationField(unsigned char * pacote) | |
55 | -{ | |
56 | - return getAdaptationFieldControl(pacote) == AFC_ONLY_ADAPT_FIELD | |
57 | - || getAdaptationFieldControl(pacote) == AFC_BOTH_PAYLOAD_AND_ADAPT_FIELD; | |
58 | -} | |
59 | - | |
60 | - | |
61 | -/** | |
62 | - * retorna o adaptation field len | |
63 | - * | |
64 | - * @param pacote -> pacote TS de 188 bytes | |
65 | - **/ | |
66 | -unsigned int getAdaptationFieldLength(unsigned char * pacote) | |
67 | -{ | |
68 | - if ( hasAdaptationField(pacote) ) | |
69 | - { | |
70 | - unsigned aFieldLength = pacote[4]; // 5 byte | |
71 | - | |
72 | - switch (getAdaptationFieldControl(pacote)) { | |
73 | - case AFC_ONLY_ADAPT_FIELD: | |
74 | - //assert(aFieldLength == 183); | |
75 | - //break; | |
76 | - if (aFieldLength == 183) | |
77 | - break; | |
78 | - else | |
79 | - return 0; | |
80 | - | |
81 | - case AFC_BOTH_PAYLOAD_AND_ADAPT_FIELD: | |
82 | - //assert(0 <= aFieldLength && aFieldLength <= 182); | |
83 | - //break; | |
84 | - if(0 <= aFieldLength && aFieldLength <= 182) | |
85 | - break; | |
86 | - else | |
87 | - return 0; | |
88 | - default: | |
89 | - break; | |
90 | - } | |
91 | - | |
92 | - return aFieldLength; | |
93 | - } | |
94 | - else | |
95 | - return 0; | |
96 | -} | |
97 | - | |
98 | -void setAdaptationFieldLength(unsigned char * pacote, int length) | |
99 | -{ | |
100 | - if ( hasAdaptationField(pacote) ) | |
101 | - { | |
102 | - pacote[4] = length; | |
103 | - } | |
104 | -} | |
105 | - | |
106 | - | |
107 | - | |
108 | - | |
109 | -/** | |
110 | - * Retorna o tamanho do payload | |
111 | - * | |
112 | - * @param pacote -> pacote TS de 188 bytes | |
113 | - **/ | |
114 | -unsigned int getPayloadLength(unsigned char * pacote) | |
115 | -{ | |
116 | - int aFieldControl = getAdaptationFieldControl(pacote); | |
117 | - | |
118 | - if (aFieldControl & 0x1) { /* aFieldControl is either 0x1 or 0x3: payload is | |
119 | -present */ | |
120 | - unsigned aFieldLength = 0; | |
121 | - | |
122 | - if (aFieldControl == 0x3) /* adaption field is present */ | |
123 | - aFieldLength = getAdaptationFieldLength(pacote) + 1; /* the '1' is to include the | |
124 | -aFieldLength itself */ | |
125 | - | |
126 | - if (aFieldLength <= 183) | |
127 | - return MAX_PAYLOAD_SIZE - aFieldLength; | |
128 | - } | |
129 | - | |
130 | - return 0; /* nao h??? payload */ | |
131 | -} | |
132 | -// proveitoso, recompesador, valer a pena, prof???cuo | |
133 | - | |
134 | -/** | |
135 | - * Retorna um ponteiro para o in???cio do payload no pacote. | |
136 | - * | |
137 | - * @param pacote -> pacote TS de 188 bytes | |
138 | - * @param length -> vari???vel que receber??? o tamanho do payload | |
139 | - */ | |
140 | -unsigned char * getPayload(unsigned char * pacote, unsigned int * length) { | |
141 | - (*length) = getPayloadLength(pacote); | |
142 | - | |
143 | - if ( (*length) == 0 ) | |
144 | - return NULL; | |
145 | - | |
146 | - return &pacote[PACKET_SIZE - (*length)]; | |
147 | -} | |
148 | - | |
149 | - | |
150 | -/// Gets... | |
151 | - | |
152 | -int getSyncByte(unsigned char * pacote) | |
153 | -{ | |
154 | - return pacote[0]; | |
155 | -} | |
156 | - | |
157 | -// retorna 1 ou zero | |
158 | -char getTransportErrorIndicator(unsigned char * pacote) { | |
159 | - return (pacote[1] & 0x80) >> 7; | |
160 | -} | |
161 | - | |
162 | -/** | |
163 | - * retorna 0x40 se existir o payload unit start indication, e zero se nao existir | |
164 | - * @param pacote -> pacote TS de 188 bytes | |
165 | - **/ | |
166 | -unsigned char getPayloadUnitStartIndicator(unsigned char * pacote) | |
167 | -{ | |
168 | - return (pacote[1] & 0x40) >> 6; | |
169 | -} | |
170 | - | |
171 | -// retorna 1 ou zero | |
172 | -char getTransportPriority(unsigned char * pacote) { | |
173 | - return (pacote[1] & 0x20) >> 5; | |
174 | -} | |
175 | - | |
176 | -/** | |
177 | - * retorna o pid do pacote TS | |
178 | - * @param pacote -> pacote TS de 188 bytes | |
179 | - **/ | |
180 | -int getPid(unsigned char * pacote) | |
181 | -{ | |
182 | - return ((pacote[1] & 0x1F) << 8) | pacote[2]; | |
183 | -} | |
184 | - | |
185 | - | |
186 | -char getTransportScramblingControl(unsigned char * pacote) { | |
187 | - unsigned sControl = (pacote[3] & 0xC0) >> 6; | |
188 | - | |
189 | - switch (sControl) { | |
190 | - case 0x1: return SC_USER_DEFINED_1; | |
191 | - case 0x2: return SC_USER_DEFINED_2; | |
192 | - case 0x3: return SC_USER_DEFINED_3; | |
193 | - } | |
194 | - return SC_NOT_SCRAMBLED; | |
195 | -} | |
196 | - | |
197 | - | |
198 | - | |
199 | -/** | |
200 | - * retorna o adaptation field control | |
201 | - * @param pacote -> pacote TS de 188 bytes | |
202 | - **/ | |
203 | -unsigned int getAdaptationFieldControl(unsigned char * pacote) | |
204 | -{ | |
205 | - unsigned int aFieldControl = (pacote[3] & 0x30) >> 4; | |
206 | - switch (aFieldControl) { | |
207 | - case 0x1: return AFC_ONLY_PAYLOAD; | |
208 | - case 0x2: return AFC_ONLY_ADAPT_FIELD; | |
209 | - case 0x3: return AFC_BOTH_PAYLOAD_AND_ADAPT_FIELD; | |
210 | - } | |
211 | - return AFC_RESERVED; | |
212 | -} | |
213 | - | |
214 | -unsigned getContinuityCounter(unsigned char * pacote) { | |
215 | - return pacote[3] & 0x0F; | |
216 | -} | |
217 | - | |
218 | - | |
219 | - | |
220 | -/// Sets... | |
221 | - | |
222 | -// Value deve ser setado para 71 decimal, ou 47 hexa | |
223 | -void setSyncByte(unsigned char * pacote, int value) { | |
224 | - pacote[0] = value; | |
225 | -} | |
226 | - | |
227 | -// transportError deve ser 0 ou 1 | |
228 | -void setTransportErrorIndicator(unsigned char * pacote, unsigned char transportError) { | |
229 | - pacote[1] = (pacote[1] & 0x7F) | (transportError << 7); | |
230 | -} | |
231 | - | |
232 | -// payloadUnitStart deve ser 0 ou 1 | |
233 | -void setPayloadUnitStartIndicator(unsigned char * pacote, unsigned char | |
234 | -payloadUnitStart) { | |
235 | - pacote[1] = (pacote[1] & 0xBF) | (payloadUnitStart << 6); | |
236 | -} | |
237 | - | |
238 | -// transportError deve ser 0 ou 1 | |
239 | -void setTransportPriority(unsigned char * pacote, unsigned char transportPriority) { | |
240 | - pacote[1] = (pacote[1] & 0xDF) | (transportPriority << 5); | |
241 | -} | |
242 | - | |
243 | -// pid contem 13 bits | |
244 | -void setPid(unsigned char * pacote, int pid) { | |
245 | - pacote[1] = (pacote[1] & 0xE0) | ((pid & 0x1F00) >> 8); | |
246 | - pacote[2] = pid & 0x00FF; | |
247 | -} | |
248 | - | |
249 | -// scramblingControl contem 2 bits | |
250 | -void setTransportScramblingControl(unsigned char * pacote, unsigned char | |
251 | -scramblingControl) { | |
252 | - pacote[3] = (pacote[3] & 0x3F) | ((scramblingControl << 6) & 0xC0); | |
253 | -} | |
254 | - | |
255 | -// adaptationFieldControl contem 2 bits | |
256 | -void setAdaptationFieldControl(unsigned char * pacote, unsigned char | |
257 | -adaptationFieldControl) { | |
258 | - pacote[3] = (pacote[3] & 0xCF) | ((adaptationFieldControl & 0x3) << 4); | |
259 | -} | |
260 | - | |
261 | -//continuityConter deve ser sempre incrementado externamente a essa funcao, mas seele ultrapassar 15, | |
262 | -// recebe zero | |
263 | -void setContinuityCounter(unsigned char * pacote, unsigned char continuityCounter) { | |
264 | - continuityCounter = continuityCounter % 16; | |
265 | - pacote[3] = (pacote[3] & 0xF0) | (continuityCounter & 0x0F); | |
266 | -} | |
267 | - | |
268 | -void setPayload(unsigned char * pacote, unsigned char *data, unsigned length) { | |
269 | - unsigned available; | |
270 | - unsigned char *payload = getPayload(pacote, &available); | |
271 | - | |
272 | - /* be sure that the available data is enough */ | |
273 | - if (length <= available) | |
274 | - { | |
275 | - /* copy data */ | |
276 | - memcpy(payload, data, length); | |
277 | - | |
278 | - /* fill the remaining data with stuffing bytes */ | |
279 | - memset(payload + length, STUFFING_BYTE, available - length); | |
280 | - } | |
281 | - else | |
282 | - printf("Error, tentando setar o payload (%d) maior que o espa???o disponivel(%d)\n", length, available); | |
283 | -} | |
284 | - | |
285 | -char getDiscontinuityIndicator(unsigned char * pacote) { | |
286 | - if (getAdaptationFieldLength(pacote)) | |
287 | - { | |
288 | - return pacote[5] & 0x80; /* 1000 0000 */ | |
289 | - } | |
290 | - else | |
291 | - return 0; | |
292 | -} | |
293 | - | |
294 | -char getRandomAccessIndicator(unsigned char * pacote) { | |
295 | - if (getAdaptationFieldLength(pacote)) | |
296 | - { | |
297 | - return pacote[5] & 0x40; /* 0100 0000 */ | |
298 | - } | |
299 | - else | |
300 | - return 0; | |
301 | -} | |
302 | - | |
303 | -char getElementaryStreamPriorityIndicator(unsigned char * pacote) { | |
304 | - if (getAdaptationFieldLength(pacote)) | |
305 | - { | |
306 | - return pacote[5] & 0x20; /* 0010 0000 */ | |
307 | - } | |
308 | - else | |
309 | - return 0; | |
310 | -} | |
311 | - | |
312 | -void setDiscontinuityIndicator(unsigned char * pacote, int value) { | |
313 | - if (getAdaptationFieldLength(pacote)) | |
314 | - { | |
315 | - pacote[5] = (pacote[5] & 0x7F) | ((value<<7) & 0x80); /* 1000 0000 */ | |
316 | - } | |
317 | -} | |
318 | - | |
319 | -void setRandomAccessIndicator(unsigned char * pacote, int value) { | |
320 | - if (getAdaptationFieldLength(pacote)) | |
321 | - { | |
322 | - pacote[5] = (pacote[5] & 0xBF) | ((value<<6) & 0x40); /* 0100 0000 */ | |
323 | - } | |
324 | -} | |
325 | - | |
326 | -void setElementaryStreamPriorityIndicator(unsigned char * pacote, int value) { | |
327 | - if (getAdaptationFieldLength(pacote)) | |
328 | - { | |
329 | - pacote[5] = (pacote[5] & 0xDF) | ((value << 5)& 0x20); /* 0010 0000 */ | |
330 | - } | |
331 | -} | |
332 | - | |
333 | -char getOpcrFlag(unsigned char * pacote) { | |
334 | - if (getAdaptationFieldLength(pacote)) | |
335 | - { | |
336 | - return pacote[5] & 0x08; /* 0000 1000 */ | |
337 | - } | |
338 | - else | |
339 | - return NULL; | |
340 | -} | |
341 | -void setOpcrFlag(unsigned char * pacote, char flag) { | |
342 | - if (getAdaptationFieldLength(pacote)) | |
343 | - { | |
344 | - pacote[5] = (pacote[5] & 0xF7) | ((flag<<3) & 0x08); | |
345 | - } | |
346 | -} | |
347 | - | |
348 | - | |
349 | -char getPcrFlag(unsigned char * pacote) { | |
350 | - if (getAdaptationFieldLength(pacote)) | |
351 | - { | |
352 | - return pacote[5] & 0x10; /* 0001 0000 */ | |
353 | - } | |
354 | - else | |
355 | - return 0; | |
356 | -} | |
357 | -void setPcrFlag(unsigned char * pacote, char flag) { | |
358 | - if (getAdaptationFieldLength(pacote)) | |
359 | - { | |
360 | - pacote[5] = (pacote[5] & 0xEF) | ((flag<<4) & 0x10); | |
361 | - } | |
362 | -} | |
363 | - | |
364 | - | |
365 | -char getSplicingPointFlag(unsigned char * pacote) { | |
366 | - if (getAdaptationFieldLength(pacote)) | |
367 | - { | |
368 | - return pacote[5] & 0x04; /* 0000 0100 */ | |
369 | - } | |
370 | - else | |
371 | - return 0; | |
372 | -} | |
373 | -void setSplicingPointFlag(unsigned char * pacote, char flag) { | |
374 | - if (getAdaptationFieldLength(pacote)) | |
375 | - { | |
376 | - pacote[5] = (pacote[5] & 0xFB) | ((flag<<2) & 0x04); /* 0000 0100 */ | |
377 | - } | |
378 | -} | |
379 | - | |
380 | -char getTransportPrivateDataFlag(unsigned char * pacote) { | |
381 | - if (getAdaptationFieldLength(pacote)) | |
382 | - { | |
383 | - return pacote[5] & 0x02; /* 0000 0010 */ | |
384 | - } | |
385 | - else | |
386 | - return 0; | |
387 | -} | |
388 | -void setTransportPrivateDataFlag(unsigned char * pacote, char flag) { | |
389 | - if (getAdaptationFieldLength(pacote)) | |
390 | - { | |
391 | - pacote[5] = (pacote[5] & 0xFD) | ((flag<<1) & 0x02); /* 0000 0010 */ | |
392 | - } | |
393 | -} | |
394 | - | |
395 | -char getAdaptationFieldExtensionFlag(unsigned char * pacote) { | |
396 | - if (getAdaptationFieldLength(pacote)) | |
397 | - { | |
398 | - return pacote[5] & 0x01; /* 0000 0001 */ | |
399 | - } | |
400 | - else | |
401 | - return 0; | |
402 | -} | |
403 | -void setAdaptationFieldExtensionFlag(unsigned char * pacote, char flag) { | |
404 | - if (getAdaptationFieldLength(pacote)) | |
405 | - { | |
406 | - pacote[5] = (pacote[5] & 0xFE) | (flag & 0x01); /* 0000 0001 */ | |
407 | - } | |
408 | -} | |
409 | - | |
410 | - | |
411 | -void setFlagsZero(unsigned char * pacote) | |
412 | -{ | |
413 | - if (getAdaptationFieldLength(pacote)) | |
414 | - { | |
415 | - pacote[5] = pacote[5] & 0xE0; | |
416 | - } | |
417 | -} | |
418 | - | |
419 | - | |
420 | - | |
421 | -char hasPcr(unsigned char * pacote) { | |
422 | - return hasAdaptationField(pacote) && (getAdaptationFieldLength(pacote) != 0) && getPcrFlag(pacote); | |
423 | -} | |
424 | - | |
425 | - | |
426 | -int64_t getPcrBase(unsigned char * pacote) { /* 33 */ | |
427 | -// if (hasPcr(pacote)) // comentei para otimizar o codigo | |
428 | - { | |
429 | - return ( | |
430 | - ( ((uint64_t) pacote[ 6])<< 25 ) | | |
431 | - ( pacote[ 7] << 17 ) | | |
432 | - ( pacote[ 8] << 9 ) | | |
433 | - ( pacote[ 9] << 1 ) | | |
434 | - ( pacote[10] >> 7 ) ); | |
435 | - //+ (((uint64_t)1000000000)*7) + (((uint64_t)100000000)*4) +(((uint64_t)10000000)*6);//testes | |
436 | - } | |
437 | -// else | |
438 | -// return 0; | |
439 | -/* | |
440 | - (( (((uint64_t) pacote[6]) << 25)) & (((uint64_t) 0x1FE00000)<<4 ) ) | | |
441 | - (( (uint64_t) (pacote[ 7] << 17)) & ( 0x001FE0000) ) | | |
442 | - (( (uint64_t) (pacote[ 8] << 9)) & ( 0x00001FE00) ) | | |
443 | - (( (uint64_t) (pacote[ 9] << 1)) & ( 0x0000001FE) ) | | |
444 | - (( (uint64_t) (pacote[10] >> 7)) & ( 0x000000001) ) ); | |
445 | -*/ | |
446 | -} | |
447 | - | |
448 | - | |
449 | -void setPcrBase(unsigned char * pacote, int64_t pcrBase) { /* 33 */ | |
450 | -// if (hasPcr(pacote)) // comentei para ficar mais rapido | |
451 | - { | |
452 | - pacote[ 6] = pcrBase>>25; | |
453 | - pacote[ 7] = pcrBase>>17; | |
454 | - pacote[ 8] = pcrBase>>9; | |
455 | - pacote[ 9] = pcrBase>>1; | |
456 | - pacote[10] = ((pcrBase<<7) & 0x80) | (pacote[10] & 0x7F); | |
457 | - } | |
458 | -} | |
459 | - | |
460 | - | |
461 | -int64_t getPcrExtension(unsigned char * pacote) { | |
462 | - return ((pacote[10] & 0x1) << 8) | pacote[11]; | |
463 | -} | |
464 | - | |
465 | - | |
466 | -void setPcrExtension(unsigned char * pacote, int64_t pcrExtension) { | |
467 | - pacote[10] = ((pcrExtension>>8) & 0x01) | (pacote[10] & 0xFE); | |
468 | - pacote[11] = pcrExtension; | |
469 | -} | |
470 | - | |
471 | -unsigned getSectionLength(unsigned char * section) | |
472 | -{ | |
473 | - unsigned sectionLength = ((section[1] & 0x0F) << 8) | section[2]; | |
474 | - /* ITU-T H.222.0 2.4.4.11 page 48 (private section length) */ | |
475 | - if (sectionLength >= 4094) | |
476 | - { | |
477 | - printf("tamanho de pat section invalido (%d), maximo 4093\n", | |
478 | -sectionLength); | |
479 | - return 0; | |
480 | - } | |
481 | - | |
482 | - return sectionLength; | |
483 | -} | |
484 | - | |
485 | -unsigned getSectionDataLength(unsigned char * section) { | |
486 | - // +3, pq tem 3 bytes antes do campo sectionLength | |
487 | - return getSectionLength(section) + 3; | |
488 | -} | |
489 | - | |
490 | - | |
491 | -unsigned int generateGenericTsPackets(unsigned char * tsPacketInitial, int pid, unsigned char * section, unsigned int tableSize) | |
492 | -{ | |
493 | - int sectionSize = tableSize; | |
494 | - unsigned char * temp = (unsigned char *) malloc(184); | |
495 | - unsigned char * tsPacket; | |
496 | - int remainBytes = 0; | |
497 | - int payloadSize = 0; | |
498 | - unsigned int quantPacotes =1; | |
499 | - int cc = 0; | |
500 | - | |
501 | - memset(temp, 0xFF, 184); | |
502 | - tsPacket = tsPacketInitial; | |
503 | - | |
504 | - if (sectionSize > 183) | |
505 | - payloadSize = 183; | |
506 | - else | |
507 | - payloadSize = sectionSize; | |
508 | - | |
509 | - temp[0] = 0; | |
510 | - memcpy(&temp[1], section, payloadSize); | |
511 | - remainBytes = sectionSize; | |
512 | - | |
513 | - setSyncByte (tsPacket, SYNC_BYTE); | |
514 | - setTransportErrorIndicator (tsPacket, 0); | |
515 | - setPayloadUnitStartIndicator (tsPacket, 1); // 1 == first packet | |
516 | - setTransportPriority (tsPacket, 0); | |
517 | - setPid (tsPacket, pid); | |
518 | - setTransportScramblingControl(tsPacket, SC_NOT_SCRAMBLED); | |
519 | - setAdaptationFieldControl (tsPacket, AFC_ONLY_PAYLOAD); | |
520 | - setContinuityCounter (tsPacket, cc++); | |
521 | - setPayload (tsPacket, temp, payloadSize+1); | |
522 | - free(temp); | |
523 | - | |
524 | -/*printf("Pat: "); | |
525 | -for (i = 0; i < 188; i++){ | |
526 | - printf("%x ", tsPacket[i]); | |
527 | -}*/ | |
528 | - | |
529 | - remainBytes -= payloadSize; | |
530 | - | |
531 | - while (remainBytes>0) | |
532 | - { | |
533 | -// printf("entrei no while, remainBytes == %d, payloadSize == %d \n", remainBytes,payloadSize); | |
534 | - quantPacotes++; | |
535 | - tsPacket = tsPacket + PACKET_SIZE; | |
536 | - section = section + payloadSize; | |
537 | - | |
538 | - if (remainBytes > 184) | |
539 | - payloadSize = 184; | |
540 | - else | |
541 | - payloadSize = remainBytes; | |
542 | - | |
543 | - setSyncByte (tsPacket, SYNC_BYTE); | |
544 | - setTransportErrorIndicator (tsPacket, 0); | |
545 | - setPayloadUnitStartIndicator (tsPacket, 0); // 0 == not the first packet | |
546 | - setTransportPriority (tsPacket, 0); | |
547 | - setPid (tsPacket, pid); | |
548 | - setTransportScramblingControl(tsPacket, SC_NOT_SCRAMBLED); | |
549 | - setAdaptationFieldControl (tsPacket, AFC_ONLY_PAYLOAD); | |
550 | - setContinuityCounter (tsPacket, cc++); | |
551 | - setPayload (tsPacket, section, payloadSize); | |
552 | - | |
553 | - remainBytes -= payloadSize; | |
554 | - } | |
555 | - return quantPacotes; | |
556 | -} | |
557 | - | |
558 | - | |
559 | - | |
560 | -unsigned int generateTsPacket(unsigned char * tsPacketInitial, int pid, unsigned char * section) | |
561 | -{ | |
562 | - int sectionSize = getSectionDataLength(section); | |
563 | - unsigned char * temp = (unsigned char *) malloc(184); | |
564 | - unsigned char * tsPacket; | |
565 | - int remainBytes = 0; | |
566 | - int payloadSize = 0; | |
567 | - unsigned int quantPacotes =1; | |
568 | - int cc = 0; | |
569 | - | |
570 | - memset(temp, 0xFF, 184); | |
571 | - tsPacket = tsPacketInitial; | |
572 | - | |
573 | - if (sectionSize > 183) | |
574 | - payloadSize = 183; | |
575 | - else | |
576 | - payloadSize = sectionSize; | |
577 | - | |
578 | - temp[0] = 0; | |
579 | - memcpy(&temp[1], section, payloadSize); | |
580 | - remainBytes = sectionSize; | |
581 | - | |
582 | - setSyncByte (tsPacket, SYNC_BYTE); | |
583 | - setTransportErrorIndicator (tsPacket, 0); | |
584 | - setPayloadUnitStartIndicator (tsPacket, 1); // 1 == first packet | |
585 | - setTransportPriority (tsPacket, 0); | |
586 | - setPid (tsPacket, pid); | |
587 | - setTransportScramblingControl(tsPacket, SC_NOT_SCRAMBLED); | |
588 | - setAdaptationFieldControl (tsPacket, AFC_ONLY_PAYLOAD); | |
589 | - setContinuityCounter (tsPacket, cc++); | |
590 | - setPayload (tsPacket, temp, payloadSize+1); | |
591 | - free(temp); | |
592 | - | |
593 | -/*printf("Pat: "); | |
594 | -for (i = 0; i < 188; i++){ | |
595 | - printf("%x ", tsPacket[i]); | |
596 | -}*/ | |
597 | - | |
598 | - remainBytes -= payloadSize; | |
599 | - | |
600 | - while (remainBytes>0) | |
601 | - { | |
602 | -// printf("entrei no while, remainBytes == %d, payloadSize == %d \n", remainBytes,payloadSize); | |
603 | - quantPacotes++; | |
604 | - tsPacket = tsPacket + PACKET_SIZE; | |
605 | - section = section + payloadSize; | |
606 | - | |
607 | - if (remainBytes > 184) | |
608 | - payloadSize = 184; | |
609 | - else | |
610 | - payloadSize = remainBytes; | |
611 | - | |
612 | - setSyncByte (tsPacket, SYNC_BYTE); | |
613 | - setTransportErrorIndicator (tsPacket, 0); | |
614 | - setPayloadUnitStartIndicator (tsPacket, 0); // 0 == not the first packet | |
615 | - setTransportPriority (tsPacket, 0); | |
616 | - setPid (tsPacket, pid); | |
617 | - setTransportScramblingControl(tsPacket, SC_NOT_SCRAMBLED); | |
618 | - setAdaptationFieldControl (tsPacket, AFC_ONLY_PAYLOAD); | |
619 | - setContinuityCounter (tsPacket, cc++); | |
620 | - setPayload (tsPacket, section, payloadSize); | |
621 | - | |
622 | - remainBytes -= payloadSize; | |
623 | - } | |
624 | - return quantPacotes; | |
625 | -} |