Commit a17be48caed92e5b51bc58ae8a3ab390da242ac7

Authored by Wesnydy Ribeiro
1 parent 2a840a72
Exists in master and in 1 other branch devel

Remoção de componentesnão utilizados (correção)

codificador/src/codificadormanager.cpp
@@ -1,171 +0,0 @@ @@ -1,171 +0,0 @@
1 -#include <stdio.h>  
2 -#include <stdlib.h>  
3 -#include <stdint.h>  
4 -#include <iostream>  
5 -  
6 -#include "codificadormanager.h"  
7 -  
8 -#include "librasdatamessage.h"  
9 -#include "librascontrolmessage.h"  
10 -#include "librassection.h"  
11 -#include "tspacket.h"  
12 -#include "jdatagramsocket.h"  
13 -  
14 -using namespace std;  
15 -using namespace jsocket;  
16 -  
17 -namespace Codificador {  
18 -  
19 - CodificadorManager* CodificadorManager::ccmanager = 0;  
20 -  
21 - CodificadorManager::CodificadorManager() {  
22 - cc = 0;  
23 - packets = new unsigned char[70000];  
24 - //pid = 0x63;  
25 - version_number = 1;  
26 - }  
27 -  
28 - CodificadorManager* CodificadorManager::getInstance() {  
29 - if (ccmanager == NULL)  
30 - ccmanager = new CodificadorManager();  
31 - return ccmanager;  
32 - }  
33 -  
34 - CodificadorManager::~CodificadorManager() {  
35 - printf("Deletando ccManager1... \n");  
36 - if (packets) {  
37 - delete []packets;  
38 - packets = NULL;  
39 - }  
40 -  
41 - printf("Deletando ccManager2... \n");  
42 - ccmanager == NULL;  
43 - }  
44 -  
45 - int CodificadorManager::getPid() {  
46 - return this->pid;  
47 - }  
48 -  
49 - void CodificadorManager::setPid(int pid) {  
50 - this->pid = pid;  
51 - }  
52 -  
53 - void CodificadorManager::setResolution(string resolution) {  
54 - this->resolution = resolution;  
55 - }  
56 -  
57 - void CodificadorManager::setDictionaryVersion(int dictionaryversion) {  
58 - this->dictionaryversion = dictionaryversion;  
59 - }  
60 -  
61 - void CodificadorManager::setDPH(int dph) {  
62 - this->dph = dph;  
63 - }  
64 -  
65 - void CodificadorManager::setDPV(int dpv) {  
66 - this->dpv = dpv;  
67 - }  
68 -  
69 - void CodificadorManager::setDFW(int dfw) {  
70 - this->dfw = dfw;  
71 - }  
72 -  
73 - void CodificadorManager::setDFH(int dfh) {  
74 - this->dfh = dfh;  
75 - }  
76 -  
77 - void CodificadorManager::setPortaOut(int porta) {  
78 - this->portaOut = porta;  
79 - }  
80 -  
81 - void CodificadorManager::setIp(string ip) {  
82 - this->ip = ip;  
83 - }  
84 -  
85 - unsigned char *CodificadorManager::generateSection(unsigned int type, unsigned char *msg, int n, int *numPackets) {  
86 - unsigned short len;  
87 - unsigned char *pesBytes;  
88 - LibrasSection *librSection = NULL;  
89 -  
90 - if (type == LibrasDataMessage::LIBRAS_DATA_TYPE) {  
91 - if(version_number == 32)  
92 - version_number = 1;  
93 -  
94 - LibrasDataMessage *librData = new LibrasDataMessage((unsigned char *) msg, (unsigned short) n);  
95 -  
96 - librSection = new LibrasSection(librData, type, version_number);  
97 -  
98 - pesBytes = librSection->generateBytes(&len);  
99 -  
100 - *numPackets = generateTsPacket(packets, pid, pesBytes);  
101 -  
102 -  
103 - delete librData;  
104 - } else if (type == LibrasControlMessage::LIBRAS_MGM_TYPE) {  
105 - if(version_number == 32)  
106 - version_number = 1;  
107 -  
108 - LibrasControlMessage *librctrMess = new LibrasControlMessage();  
109 - librctrMess->setResolution(resolution);  
110 - librctrMess->setDictionaryVersion((unsigned char)dictionaryversion);  
111 - librctrMess->setDPH((unsigned short)dph);  
112 - librctrMess->setDPV((unsigned short)dpv);  
113 - librctrMess->setDFH((unsigned short)dfh);  
114 - librctrMess->setDFW((unsigned short)dfw);  
115 -  
116 - librSection = new LibrasSection(librctrMess, type, version_number);  
117 -  
118 - pesBytes = librSection->generateBytes(&len);  
119 -  
120 - /*printf("PES Packet... \n");  
121 - for (int j = 0; j < len; j++){  
122 - printf("%x ", pesBytes[j]);  
123 - }  
124 - printf("\n");*/  
125 -  
126 - *numPackets = generateTsPacket(packets, pid, pesBytes);  
127 -  
128 - delete librctrMess;  
129 - } else {  
130 - return NULL;  
131 - }  
132 - version_number++;  
133 -  
134 - delete []pesBytes;  
135 - delete librSection;  
136 - return packets;  
137 - }  
138 -  
139 - int CodificadorManager::sendToOutput(unsigned char *pes, int numPackets) {  
140 - //ip do MUX  
141 -  
142 - unsigned char *pack;  
143 - pack = (unsigned char*) malloc (188);  
144 - create_ts_null_packet(pack);  
145 -  
146 - for (int i = 1; i < 7; i++) {  
147 - memcpy(pes + (i * 188), pack, 188);  
148 - }  
149 -  
150 - DatagramSocket * w_socket = NULL;  
151 -  
152 - try {  
153 - w_socket = new DatagramSocket(ip, portaOut);  
154 -  
155 - } catch (...) {  
156 - printf("\nERRO ao abrir o socket.\n");  
157 - return 1;  
158 - }  
159 -  
160 - //for (int i = 0; i < numPackets; i++)  
161 - //w_socket->Send((char *) pes + (i * 188), 188);  
162 - w_socket->Send((char *) pes, 1316);  
163 -  
164 - w_socket->Close();  
165 - delete w_socket;  
166 -  
167 - return 0;  
168 -  
169 -  
170 - }  
171 -}  
codificador/src/crc32.cpp
@@ -1,80 +0,0 @@ @@ -1,80 +0,0 @@
1 -#include "crc32.h"  
2 -  
3 -static const unsigned int CRC32[256] = {  
4 - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,  
5 - 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,  
6 - 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,  
7 - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,  
8 - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,  
9 - 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,  
10 - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,  
11 - 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,  
12 - 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,  
13 - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,  
14 - 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,  
15 - 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,  
16 - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,  
17 - 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,  
18 - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,  
19 - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,  
20 - 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,  
21 - 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,  
22 - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,  
23 - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,  
24 - 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,  
25 - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,  
26 - 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,  
27 - 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,  
28 - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,  
29 - 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,  
30 - 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,  
31 - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,  
32 - 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,  
33 - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,  
34 - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,  
35 - 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,  
36 - 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,  
37 - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,  
38 - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,  
39 - 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,  
40 - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,  
41 - 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,  
42 - 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,  
43 - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,  
44 - 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,  
45 - 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,  
46 - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,  
47 - 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,  
48 - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,  
49 - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,  
50 - 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,  
51 - 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,  
52 - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,  
53 - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,  
54 - 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,  
55 - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,  
56 - 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,  
57 - 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,  
58 - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,  
59 - 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,  
60 - 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,  
61 - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,  
62 - 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,  
63 - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,  
64 - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,  
65 - 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,  
66 - 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,  
67 - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4,  
68 -};  
69 -  
70 -unsigned int calculate_CRC_32(unsigned char *begin, unsigned count) {  
71 - unsigned crc = 0xffffffff;  
72 -  
73 - while (count > 0) {  
74 - crc = (crc << 8) ^ CRC32[(crc >> 24) ^ ((unsigned) * begin)];  
75 - begin++;  
76 - count--;  
77 - }  
78 - return crc;  
79 -}  
80 -  
codificador/src/include/codificadormanager.h
@@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
1 -#ifndef _LIBRAS_MANAGER_H_  
2 -#define _LIBRAS_MANAGER_H_  
3 -  
4 -#include <string>  
5 -#include "tspacket.h"  
6 -  
7 -using namespace std;  
8 -  
9 -namespace Codificador {  
10 -  
11 - class CodificadorManager {  
12 - private:  
13 - static CodificadorManager *ccmanager;  
14 - CodificadorManager();  
15 -  
16 - int cc;  
17 - int pid;  
18 - unsigned char version_number;  
19 - unsigned char *packets;  
20 -  
21 - string resolution;  
22 - int dictionaryversion;  
23 - int dph;  
24 - int dpv;  
25 - int dfw;  
26 - int dfh;  
27 - int portaOut;  
28 - string ip;  
29 -  
30 -  
31 - public:  
32 - static CodificadorManager *getInstance();  
33 - virtual ~CodificadorManager();  
34 -  
35 - int getPid();  
36 - void setPid(int pid);  
37 - void setResolution(string resolution);  
38 - void setDictionaryVersion(int dictionaryversion);  
39 - void setDPH(int dph);  
40 - void setDPV(int dph);  
41 - void setDFW(int dph);  
42 - void setDFH(int dph);  
43 - void setPortaOut(int porta);  
44 - void setIp(string ip);  
45 -  
46 - unsigned char *generateSection(unsigned int type, unsigned char *msg, int n, int *numPackets);  
47 - int sendToOutput(unsigned char *pes, int numPackets);  
48 - };  
49 -}  
50 -  
51 -#endif  
codificador/src/include/crc32.h
@@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
1 -#ifndef _CRC32_H_  
2 -#define _CRC32_H_  
3 -  
4 -unsigned int calculate_CRC_32(unsigned char *, unsigned);  
5 -  
6 -#endif  
codificador/src/include/inmanagementdata.h
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -#ifndef _INPUT_MGM_DATA_H_  
2 -#define _INPUT_MGM_DATA_H_  
3 -  
4 -#include "jthread.h"  
5 -#include "codificadormanager.h"  
6 -  
7 - namespace Codificador {  
8 -  
9 - class InManagementData: public jthread::Thread{  
10 -  
11 - private:  
12 - CodificadorManager *codificadorManager;  
13 - bool stopped;  
14 -  
15 - public:  
16 - static const int MAX_CC_MSG = 65536;  
17 -  
18 - InManagementData();  
19 - virtual ~InManagementData();  
20 -  
21 - void Run();  
22 - void stop();  
23 - };  
24 -  
25 - }  
26 -  
27 -#endif  
codificador/src/include/librascontrolmessage.h
@@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
1 -#ifndef _LIBRAS_CONTROL_MESSAGE_H_  
2 -#define _LIBRAS_CONTROL_MESSAGE_H_  
3 -  
4 -#include "librascontrolsection.h"  
5 -#include <string>  
6 -  
7 -using namespace std;  
8 -  
9 -namespace Codificador {  
10 -  
11 - class LibrasControlMessage : public LibrasControlSection {  
12 -  
13 - private:  
14 - unsigned short messagelength;  
15 - unsigned char resolution;  
16 - unsigned char dictionaryversion;  
17 - unsigned short dph;  
18 - unsigned short dpv;  
19 - unsigned short dfw;  
20 - unsigned short dfh;  
21 - unsigned char privatedatalength;  
22 - unsigned char *privateDataBytes;  
23 -  
24 - public:  
25 - static const unsigned int LIBRAS_MGM_TYPE = 0x00;  
26 - static const unsigned int MESSAGE_ID_CONTROL = 0x01;  
27 -  
28 - unsigned short getMessageLength();  
29 - unsigned char getResolution();  
30 - unsigned char getDictionaryVersion();  
31 - unsigned short getDPH();  
32 - unsigned short getDPV();  
33 - unsigned short getDFW();  
34 - unsigned short getDFH();  
35 - unsigned char getPrivateDataLength();  
36 - unsigned char *getPrivateDataBytes();  
37 -  
38 - void setMessageLength(unsigned short messagelength);  
39 - void setResolution(string resolution);  
40 - void setDictionaryVersion(unsigned char dictionaryversion);  
41 - void setDPH(unsigned short dph);  
42 - void setDPV(unsigned short dph);  
43 - void setDFW(unsigned short dph);  
44 - void setDFH(unsigned short dph);  
45 - void setPrivateDataLength(unsigned char privatedatalength);  
46 - void setPrivateDataBytes(unsigned char *privateDataBytes, int len);  
47 -  
48 - LibrasControlMessage();  
49 - virtual ~LibrasControlMessage();  
50 -  
51 -  
52 - virtual unsigned char *generateBytes(unsigned short *librasLen);  
53 - };  
54 -  
55 -}  
56 -  
57 -#endif  
codificador/src/include/librascontrolsection.h
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -#ifndef _LIBRAS_CONTROL_SECTION_H_  
2 -#define _LIBRAS_CONTROL_SECTION_H_  
3 -  
4 -namespace Codificador {  
5 -  
6 - class LibrasControlSection {  
7 - protected:  
8 - unsigned int type;  
9 - unsigned char timecontrolflag;  
10 - unsigned char messageid;  
11 -  
12 - public:  
13 -  
14 - LibrasControlSection();  
15 - virtual ~LibrasControlSection();  
16 -  
17 - unsigned char getTimeControlFlag();  
18 -  
19 - void setTimeControlFlag(unsigned char timecontrolflag);  
20 -  
21 - virtual unsigned char *generateBytes(unsigned short *librasLen);  
22 - };  
23 -  
24 -}  
25 -  
26 -#endif  
codificador/src/include/librasdatamessage.h
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -#ifndef _LIBRAS_DATA_MESSAGE_H_  
2 -#define _LIBRAS_DATA_MESSAGE_H_  
3 -  
4 -#include "librascontrolsection.h"  
5 -  
6 -namespace Codificador {  
7 -  
8 - class LibrasDataMessage : public LibrasControlSection {  
9 -  
10 - private:  
11 - unsigned short messagelength;  
12 - unsigned int stm;  
13 - unsigned short sinaislooplength;  
14 - unsigned char glosadatalength;  
15 - unsigned char *glosaDataBytes;  
16 -  
17 - public:  
18 - static const unsigned int LIBRAS_DATA_TYPE = 0x01;  
19 - static const unsigned int MESSAGE_ID_DATA = 0x02;  
20 -  
21 - unsigned short getMessageLength();  
22 - unsigned int getStm();  
23 - unsigned short getSinaisLoopLength();  
24 - unsigned char getGlosaDataLength();  
25 - unsigned char *getGlosaDataBytes();  
26 -  
27 - void setMessageLength(unsigned short messagelength);  
28 - void setStm(unsigned int stm);  
29 - void setSinaisLoopLength(unsigned short sinaislooplength);  
30 - void setGlosaDataLength(unsigned char glosadatalength);  
31 - void setGlosaDataBytes(unsigned char *glosaDataBytes, int len);  
32 -  
33 - LibrasDataMessage(unsigned char *data, int size);  
34 - virtual ~LibrasDataMessage();  
35 -  
36 - virtual unsigned char *generateBytes(unsigned short *librasLen);  
37 -  
38 - };  
39 -  
40 -}  
41 -  
42 -#endif  
codificador/src/include/librassection.h
@@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
1 -#ifndef _SYNCRO_PES_DATA_H_  
2 -#define _SYNCRO_PES_DATA_H_  
3 -  
4 -#include "librascontrolsection.h"  
5 -  
6 - namespace Codificador {  
7 -  
8 - class LibrasSection{  
9 -  
10 - private:  
11 - unsigned char tableid;  
12 - unsigned char section_syntax_indicator;  
13 - unsigned short libras_section_length;  
14 - unsigned short table_id_extension;  
15 - unsigned char version_number;  
16 - unsigned char current_next_indicator;  
17 - unsigned char section_number;  
18 - unsigned char last_section_number;  
19 - unsigned int crc32;  
20 -  
21 - LibrasControlSection *libras;  
22 -  
23 - public:  
24 -  
25 - LibrasSection(LibrasControlSection *libr, unsigned int type, unsigned char version);  
26 - virtual ~LibrasSection();  
27 -  
28 - unsigned char getSectionSyntaxIndicator();  
29 - unsigned short getLibrasSectionLength();  
30 - unsigned char getTableIdExtension();  
31 - unsigned char getVersionNumber();  
32 - unsigned char getCurrentNextIndicator();  
33 - unsigned char getSectionNumber();  
34 - unsigned char getLastSectionNumber();  
35 - unsigned int getCrc32();  
36 - LibrasControlSection *getLibras();  
37 -  
38 - void setSectionSyntaxIndicator(unsigned char section_syntax_indicator);  
39 - void setLibrasSectionLength(unsigned short libras_section_length);  
40 - void setTableIdExtension(unsigned short table_id_extension);  
41 - void setVersionNumber(unsigned char version_number);  
42 - void setCurrentNextIndicator(unsigned char current_next_indicator);  
43 - void setSectionNumber(unsigned char section_number);  
44 - void setLastSectionNumber(unsigned char last_section_number);  
45 -  
46 - void setLibras(LibrasControlSection *libras);  
47 -  
48 - unsigned char *generateBytes(unsigned short *syncPesLen);  
49 - };  
50 -  
51 - }  
52 -  
53 -#endif  
codificador/src/include/recebeglosa.h
@@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
1 -/*  
2 - * File: RecebeGlosa.h  
3 - * Author: felipe  
4 - *  
5 - * Created on 2 de Fevereiro de 2010, 09:43  
6 - */  
7 -  
8 -#ifndef _RECEBEGLOSA_H  
9 -#define _RECEBEGLOSA_H  
10 -  
11 -#include <vector>  
12 -#include <string>  
13 -#include <pthread.h>  
14 -#include "codificadormanager.h"  
15 -#include "ouvinteTradutor.h"  
16 -  
17 -using namespace std;  
18 -  
19 -namespace Codificador {  
20 -  
21 - class RecebeGlosa : public Tradutor::OuvinteTradutor {  
22 - public:  
23 -  
24 - RecebeGlosa(int pd, string rl, int vs, int dh, int dv, int dw, int df, int portOut, string ip);  
25 - ~RecebeGlosa();  
26 -  
27 - void PreencheVector();  
28 - virtual void codifica(std::vector<std::string> * glosas);  
29 -  
30 - private:  
31 - CodificadorManager *codificadorManager;  
32 -  
33 - // Mutex para evitar mutiplas chamadas de notificadores  
34 - pthread_mutex_t *mutex;  
35 - };  
36 -}  
37 -  
38 -#endif /* _RECEBEGLOSA_H */  
39 -  
codificador/src/inmanagementdata.cpp
@@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
1 -#include <stdio.h>  
2 -  
3 -#include "inmanagementdata.h"  
4 -#include "codificadormanager.h"  
5 -#include "librascontrolmessage.h"  
6 -  
7 -namespace Codificador{  
8 -  
9 - InManagementData::InManagementData(){  
10 - stopped = false;  
11 - codificadorManager = CodificadorManager::getInstance();  
12 - }  
13 -  
14 - InManagementData::~InManagementData(){  
15 - }  
16 -  
17 - void InManagementData::stop(){  
18 - stopped = true;  
19 - }  
20 -  
21 - void InManagementData::Run(){  
22 - int numPackets;  
23 - unsigned char *pes;  
24 -  
25 - while(!stopped){  
26 - pes = codificadorManager->generateSection(LibrasControlMessage::LIBRAS_MGM_TYPE, NULL, 0, &numPackets);  
27 - codificadorManager->sendToOutput(pes, numPackets);  
28 - printf("\nGerando Libras Control Message\n");  
29 - sleep(2);  
30 -  
31 - }  
32 -  
33 - printf("Saiu do InputMgmData... \n");  
34 -  
35 - }  
36 -}  
codificador/src/librascontrolmessage.cpp
@@ -1,143 +0,0 @@ @@ -1,143 +0,0 @@
1 -#include <stdio.h>  
2 -#include <stdlib.h>  
3 -#include <string.h>  
4 -  
5 -#include "librascontrolmessage.h"  
6 -  
7 -namespace Codificador {  
8 -  
9 - LibrasControlMessage::LibrasControlMessage() : LibrasControlSection() {  
10 - type = LIBRAS_MGM_TYPE;  
11 -  
12 - messagelength = 11;  
13 - //resolution = 1;  
14 - timecontrolflag = 0;  
15 - //dictionaryversion = 1;  
16 - privatedatalength = 0;  
17 - privateDataBytes = NULL;  
18 - //dph = 0;  
19 - //dfh = 0;  
20 - //dfw = 0;  
21 - //dpv = 0;  
22 - }  
23 -  
24 - LibrasControlMessage::~LibrasControlMessage() {  
25 -  
26 - }  
27 -  
28 - unsigned short LibrasControlMessage::getMessageLength() {  
29 - return messagelength;  
30 - }  
31 -  
32 - unsigned char LibrasControlMessage::getResolution() {  
33 - return resolution;  
34 - }  
35 -  
36 - unsigned char LibrasControlMessage::getDictionaryVersion() {  
37 - return dictionaryversion;  
38 - }  
39 -  
40 - unsigned short LibrasControlMessage::getDPH() {  
41 - return dph;  
42 - }  
43 -  
44 - unsigned short LibrasControlMessage::getDPV() {  
45 - return dpv;  
46 - }  
47 -  
48 - unsigned short LibrasControlMessage::getDFW() {  
49 - return dfw;  
50 - }  
51 -  
52 - unsigned short LibrasControlMessage::getDFH() {  
53 - return dfh;  
54 - }  
55 -  
56 - unsigned char LibrasControlMessage::getPrivateDataLength() {  
57 - return privatedatalength;  
58 - }  
59 -  
60 - unsigned char *LibrasControlMessage::getPrivateDataBytes() {  
61 - return privateDataBytes;  
62 - }  
63 -  
64 - void LibrasControlMessage::setMessageLength(unsigned short messagelength) {  
65 - this->messagelength = messagelength;  
66 - }  
67 -  
68 - void LibrasControlMessage::setResolution(string resolution) {  
69 - if(resolution.compare("1920x1080") == 0)  
70 - this->resolution = 0;  
71 - if(resolution.compare("1280x720") == 0)  
72 - this->resolution = 1;  
73 - if(resolution.compare("640x480") == 0)  
74 - this->resolution = 2;  
75 - if(resolution.compare("960x540") == 0)  
76 - this->resolution = 3;  
77 - if(resolution.compare("720x480") == 0)  
78 - this->resolution = 4;  
79 - }  
80 -  
81 - void LibrasControlMessage::setDictionaryVersion(unsigned char dictionaryversion) {  
82 - this->dictionaryversion = dictionaryversion;  
83 - }  
84 -  
85 - void LibrasControlMessage::setDPH(unsigned short dph) {  
86 - this->dph = dph;  
87 - }  
88 -  
89 - void LibrasControlMessage::setDPV(unsigned short dpv) {  
90 - this->dpv = dpv;  
91 - }  
92 -  
93 - void LibrasControlMessage::setDFW(unsigned short dfw) {  
94 - this->dfw = dfw;  
95 - }  
96 -  
97 - void LibrasControlMessage::setDFH(unsigned short dfh) {  
98 - this->dfh = dfh;  
99 - }  
100 -  
101 - void LibrasControlMessage::setPrivateDataLength(unsigned char privatedatalength) {  
102 - this->privatedatalength = privatedatalength;  
103 - }  
104 -  
105 - void LibrasControlMessage::setPrivateDataBytes(unsigned char *privateDataBytes, int len) {  
106 - if (this->privateDataBytes) {  
107 - delete (this->privateDataBytes);  
108 - }  
109 -  
110 - this->privateDataBytes = new unsigned char[len];  
111 - memcpy(this->privateDataBytes, privateDataBytes, len);  
112 - }  
113 -  
114 - unsigned char *LibrasControlMessage::generateBytes(unsigned short *librasLen) {  
115 - unsigned char *librasDataBytes;  
116 -  
117 - *librasLen = privatedatalength + messagelength + 3;  
118 -  
119 - librasDataBytes = new unsigned char[*librasLen];  
120 -  
121 - messageid = MESSAGE_ID_CONTROL;  
122 - messagelength += privatedatalength;  
123 -  
124 - librasDataBytes[0] = messageid & 0xFF;  
125 - librasDataBytes[1] = (messagelength >> 8) & 0xFF;  
126 - librasDataBytes[2] = messagelength & 0xFF;  
127 - librasDataBytes[3] = ((resolution << 1) & 0x1E) | (timecontrolflag & 0x01);  
128 - librasDataBytes[4] = dictionaryversion & 0xFF;  
129 - librasDataBytes[5] = (dph >> 8) & 0xFF;  
130 - librasDataBytes[6] = dph & 0xFF;  
131 - librasDataBytes[7] = (dpv >> 8) & 0xFF;  
132 - librasDataBytes[8] = dpv & 0xFF;  
133 - librasDataBytes[9] = (dfw >> 8) & 0xFF;  
134 - librasDataBytes[10] = dfw & 0xFF;  
135 - librasDataBytes[11] = (dfh >> 8) & 0xFF;  
136 - librasDataBytes[12] = dfh & 0xFF;  
137 - librasDataBytes[13] = privatedatalength & 0xFF;  
138 -  
139 - memcpy(librasDataBytes + 11, privateDataBytes, privatedatalength);  
140 -  
141 - return librasDataBytes;  
142 - }  
143 -}  
codificador/src/librascontrolsection.cpp
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -#include "librascontrolsection.h"  
2 -  
3 -#define NULL 0  
4 -  
5 -namespace Codificador {  
6 -  
7 - LibrasControlSection::LibrasControlSection() {  
8 - timecontrolflag = 0;  
9 - }  
10 -  
11 - LibrasControlSection::~LibrasControlSection() {  
12 -  
13 - }  
14 -  
15 - unsigned char LibrasControlSection::getTimeControlFlag() {  
16 - return timecontrolflag;  
17 - }  
18 -  
19 - void LibrasControlSection::setTimeControlFlag(unsigned char timecontrolflag) {  
20 - this->timecontrolflag = timecontrolflag;  
21 - }  
22 -  
23 - unsigned char *LibrasControlSection::generateBytes(unsigned short *librasLen) {  
24 -  
25 - return NULL;  
26 - }  
27 -}  
codificador/src/librasdatamessage.cpp
@@ -1,98 +0,0 @@ @@ -1,98 +0,0 @@
1 -#include <stdio.h>  
2 -#include <stdlib.h>  
3 -#include <string.h>  
4 -  
5 -#include "librasdatamessage.h"  
6 -  
7 -namespace Codificador {  
8 -  
9 - LibrasDataMessage::LibrasDataMessage(unsigned char *data, int size) : LibrasControlSection() {  
10 - type = LIBRAS_DATA_TYPE;  
11 -  
12 - messagelength = 4;  
13 -  
14 - glosadatalength = size;  
15 - glosaDataBytes = NULL;  
16 - //Pode mudar  
17 - sinaislooplength = 1;  
18 -  
19 - if (size > 0) {  
20 - glosaDataBytes = new unsigned char[glosadatalength];  
21 - memcpy(glosaDataBytes, data, size);  
22 - }  
23 - }  
24 -  
25 - LibrasDataMessage::~LibrasDataMessage() {  
26 - if (glosaDataBytes) delete [] glosaDataBytes;  
27 - }  
28 -  
29 - unsigned short LibrasDataMessage::getMessageLength() {  
30 - return messagelength;  
31 - }  
32 -  
33 - unsigned int LibrasDataMessage::getStm() {  
34 - return stm;  
35 - }  
36 -  
37 - unsigned short LibrasDataMessage::getSinaisLoopLength() {  
38 - return sinaislooplength;  
39 - }  
40 -  
41 - unsigned char LibrasDataMessage::getGlosaDataLength() {  
42 - return glosadatalength;  
43 - }  
44 -  
45 - unsigned char *LibrasDataMessage::getGlosaDataBytes() {  
46 - return glosaDataBytes;  
47 - }  
48 -  
49 - void LibrasDataMessage::setMessageLength(unsigned short messagelength) {  
50 - this->messagelength = messagelength;  
51 - }  
52 -  
53 - void LibrasDataMessage::setStm(unsigned int stm) {  
54 - this->stm = stm;  
55 - }  
56 -  
57 - void LibrasDataMessage::setSinaisLoopLength(unsigned short sinaislooplength) {  
58 - this->sinaislooplength = sinaislooplength;  
59 - }  
60 -  
61 - void LibrasDataMessage::setGlosaDataLength(unsigned char glosadatalength) {  
62 - this->glosadatalength = glosadatalength;  
63 - }  
64 -  
65 - void LibrasDataMessage::setGlosaDataBytes(unsigned char *glosaDataBytes, int len) {  
66 - if (this->glosaDataBytes) {  
67 - delete [] (this->glosaDataBytes);  
68 - }  
69 -  
70 - this->glosaDataBytes = new unsigned char[len];  
71 - memcpy(this->glosaDataBytes, glosaDataBytes, len);  
72 - }  
73 -  
74 - unsigned char *LibrasDataMessage::generateBytes(unsigned short *librasLen) {  
75 - unsigned char *librasDataBytes;  
76 -  
77 - *librasLen = glosadatalength + messagelength + 3;  
78 - sinaislooplength += glosadatalength;  
79 -  
80 - librasDataBytes = new unsigned char[*librasLen];  
81 -  
82 - messageid = MESSAGE_ID_DATA;  
83 - messagelength += glosadatalength;  
84 -  
85 - librasDataBytes[0] = messageid & 0xFF;  
86 - librasDataBytes[1] = (messagelength >> 8) & 0xFF;  
87 - librasDataBytes[2] = messagelength & 0xFF;  
88 - librasDataBytes[3] = timecontrolflag & 0x01;  
89 - //Ajeitar pra quando tiver STM  
90 - librasDataBytes[4] = (sinaislooplength >> 8) & 0xFF;  
91 - librasDataBytes[5] = sinaislooplength & 0xFF;  
92 - librasDataBytes[6] = glosadatalength & 0xFF;  
93 -  
94 - memcpy(librasDataBytes + 7, glosaDataBytes, glosadatalength);  
95 -  
96 - return librasDataBytes;  
97 - }  
98 -}  
codificador/src/librassection.cpp
@@ -1,138 +0,0 @@ @@ -1,138 +0,0 @@
1 -#include <stdio.h>  
2 -#include <stdlib.h>  
3 -#include <string.h>  
4 -  
5 -#include "librassection.h"  
6 -#include "crc32.h"  
7 -  
8 -namespace Codificador{  
9 -  
10 - LibrasSection::LibrasSection(LibrasControlSection *libr, unsigned int type, unsigned char version){  
11 -  
12 - tableid = 145;  
13 - section_syntax_indicator = 1;  
14 -  
15 - if( type == 0 )  
16 - table_id_extension = 0x0001;  
17 - if( type == 1)  
18 - table_id_extension = 0x0002;  
19 -  
20 - version_number = version;  
21 - current_next_indicator = 1;  
22 - section_number = 0;  
23 - last_section_number = 0;  
24 -  
25 - libras_section_length = 9;  
26 -  
27 - libras = libr;  
28 - }  
29 -  
30 - LibrasSection::~LibrasSection(){  
31 -  
32 - }  
33 -  
34 - unsigned char LibrasSection::getSectionSyntaxIndicator(){  
35 - return section_syntax_indicator;  
36 - }  
37 -  
38 - unsigned short LibrasSection::getLibrasSectionLength(){  
39 - return libras_section_length;  
40 - }  
41 -  
42 - unsigned char LibrasSection::getTableIdExtension(){  
43 - return table_id_extension;  
44 - }  
45 -  
46 - unsigned char LibrasSection::getVersionNumber(){  
47 - return version_number;  
48 - }  
49 -  
50 - unsigned char LibrasSection::getCurrentNextIndicator(){  
51 - return current_next_indicator;  
52 - }  
53 -  
54 - unsigned char LibrasSection::getSectionNumber(){  
55 - return section_number;  
56 - }  
57 -  
58 - unsigned char LibrasSection::getLastSectionNumber(){  
59 - return last_section_number;  
60 - }  
61 -  
62 - unsigned int LibrasSection::getCrc32(){  
63 - return crc32;  
64 - }  
65 -  
66 - LibrasControlSection *LibrasSection::getLibras(){  
67 - return libras;  
68 - }  
69 -  
70 - void LibrasSection::setSectionSyntaxIndicator(unsigned char section_syntax_indicator){  
71 - this->section_syntax_indicator = section_syntax_indicator;  
72 - }  
73 -  
74 - void LibrasSection::setLibrasSectionLength(unsigned short libras_section_length){  
75 - this->libras_section_length = libras_section_length;  
76 - }  
77 -  
78 - void LibrasSection::setTableIdExtension(unsigned short table_id_extension){  
79 - this->table_id_extension = table_id_extension;  
80 - }  
81 -  
82 - void LibrasSection::setVersionNumber(unsigned char version_number){  
83 - this->version_number = version_number;  
84 - }  
85 -  
86 - void LibrasSection::setCurrentNextIndicator(unsigned char current_next_indicator){  
87 - this->current_next_indicator = current_next_indicator;  
88 - }  
89 -  
90 - void LibrasSection::setSectionNumber(unsigned char section_number){  
91 - this->section_number = section_number;  
92 - }  
93 -  
94 - void LibrasSection::setLastSectionNumber(unsigned char last_section_number){  
95 - this->last_section_number = last_section_number;  
96 - }  
97 -  
98 - void LibrasSection::setLibras(LibrasControlSection *libras){  
99 - this->libras = libras;  
100 - }  
101 -  
102 - unsigned char *LibrasSection::generateBytes(unsigned short *librLen){  
103 - int offset = 0;  
104 - unsigned short librasLen;  
105 - unsigned char *librSecBytes;  
106 - unsigned char *librasBytes = libras->generateBytes(&librasLen);  
107 -  
108 - *librLen = librasLen + libras_section_length + 3;  
109 - libras_section_length += librasLen;  
110 -  
111 - librSecBytes = new unsigned char[*librLen];  
112 -  
113 - librSecBytes[0] = tableid & 0xFF;  
114 - librSecBytes[1] = (section_syntax_indicator << 7) & 0x80;  
115 - librSecBytes[1] = (libras_section_length >> 8) & 0x0F;  
116 - librSecBytes[2] = libras_section_length & 0xFF;  
117 - librSecBytes[3] = (table_id_extension >> 8) & 0xFF;  
118 - librSecBytes[4] = table_id_extension & 0xFF;  
119 - librSecBytes[5] = (version_number << 5) & 0x3E;  
120 - librSecBytes[5] = current_next_indicator & 0x01;  
121 - librSecBytes[6] = section_number & 0xFF;  
122 - librSecBytes[7] = last_section_number & 0xFF;  
123 -  
124 - memcpy(librSecBytes + 8, librasBytes, librasLen);  
125 -  
126 - crc32 = calculate_CRC_32(librSecBytes, *librLen - 4);  
127 - offset = 8 + librasLen;  
128 -  
129 - librSecBytes[offset + 0]= (crc32 >> 24) & 0xFF;  
130 - librSecBytes[offset + 1]= (crc32 >> 16) & 0xFF;  
131 - librSecBytes[offset + 2]= (crc32 >> 8) & 0xFF;  
132 - librSecBytes[offset + 3]= crc32 & 0xFF;  
133 -  
134 - delete []librasBytes;  
135 - return librSecBytes;  
136 - }  
137 -}  
138 -  
codificador/src/recebeglosa.cpp
@@ -1,102 +0,0 @@ @@ -1,102 +0,0 @@
1 -/*  
2 - * File: RecebeGlosa.cpp  
3 - * Author: felipe  
4 - *  
5 - * Created on 2 de Fevereiro de 2010, 09:43  
6 - */  
7 -  
8 -#include "recebeglosa.h"  
9 -#include "librasdatamessage.h"  
10 -#include "dprintf.h"  
11 -#include <iostream>  
12 -  
13 -#include <stdlib.h>  
14 -#include <stdio.h>  
15 -#include <tspacket.h>  
16 -  
17 -namespace Codificador {  
18 -  
19 - RecebeGlosa::RecebeGlosa(int pd, string rl, int vs, int dh, int dv, int dw, int df, int portOut, string ip) {  
20 - codificadorManager = CodificadorManager::getInstance();  
21 - codificadorManager->setPid(pd);  
22 - codificadorManager->setResolution(rl);  
23 - codificadorManager->setDictionaryVersion(vs);  
24 - codificadorManager->setDPH(dh);  
25 - codificadorManager->setDPV(dv);  
26 - codificadorManager->setDFW(dw);  
27 - codificadorManager->setDFH(df);  
28 - codificadorManager->setPortaOut(portOut);  
29 - codificadorManager->setIp(ip);  
30 - // Inicia o mutex  
31 - mutex = (pthread_mutex_t *) malloc( sizeof(pthread_mutex_t) );  
32 - pthread_mutex_init(mutex, NULL);  
33 - }  
34 -  
35 - RecebeGlosa::~RecebeGlosa() {  
36 - if (mutex) {  
37 - int ret = pthread_mutex_destroy(mutex);  
38 - if (ret)  
39 - DDDPRINTF("erro destruindo mutex\n");  
40 - free(mutex);  
41 - }  
42 - }  
43 -  
44 - void RecebeGlosa::codifica(vector<string> * glosas) {  
45 - // Mutex para evitar bug multiplas chamadas dos notificadores  
46 - pthread_mutex_lock(mutex);  
47 - unsigned char *nullpackets = new unsigned char [188];  
48 -  
49 - vector<string>::iterator it;  
50 - unsigned char *data;  
51 - string valor;  
52 - int tamanho, numPackets, contNullPackets = 0;  
53 - //FILE *arq;  
54 -  
55 - unsigned char *pes;  
56 -  
57 - //arq = fopen ("../libras.ts" , "a");  
58 -  
59 - printf("\nGlosa recebida para codificacao: ");  
60 - printf("\033[31m");  
61 - for (it = glosas->begin(); it < glosas->end(); it++) {  
62 - cout << *it << " ";  
63 - }  
64 - printf("\033[0m");  
65 - printf("\n");  
66 -  
67 - for (it = glosas->begin(); it < glosas->end(); it++) {  
68 - valor = *it;  
69 - //Gambiarra  
70 - //if(gambis == 0) {  
71 - //valor.insert(0, "dl");  
72 - //gambis++;  
73 - //}  
74 - tamanho = valor.size();  
75 - data = (unsigned char*) valor.c_str();  
76 - //cout << "Glosa: " << data << endl;  
77 -  
78 - if ((tamanho>2) && data[0] == 'd' && data[1] == 'l') {  
79 - for(int i = 2; i < tamanho; i++) {  
80 - pes = codificadorManager->generateSection(LibrasDataMessage::LIBRAS_DATA_TYPE,(unsigned char*) &data[i], 1, &numPackets);  
81 - codificadorManager->sendToOutput(pes, numPackets);  
82 - //fwrite(pes , 1 , 188 , arq );  
83 - }  
84 -  
85 - } else {  
86 - pes = codificadorManager->generateSection(LibrasDataMessage::LIBRAS_DATA_TYPE, data, tamanho, &numPackets);  
87 - codificadorManager->sendToOutput(pes, numPackets);  
88 - //fwrite(pes , 1 , 188 , arq );  
89 - }  
90 - }  
91 - //printf("\nGerando Libras Data Message\n");  
92 - //create_ts_null_packet(nullpackets);  
93 -  
94 - //while(contNullPackets < 30000) {  
95 - //contNullPackets++;  
96 - //fwrite(nullpackets , 1 , 188 , arq );  
97 - //}  
98 -  
99 - //fclose(arq);  
100 - pthread_mutex_unlock(mutex);  
101 - }  
102 -}  
103 \ No newline at end of file 0 \ No newline at end of file
demux/src/bitutil_hal.cpp
@@ -1,71 +0,0 @@ @@ -1,71 +0,0 @@
1 -#include "bitutil_hal.h"  
2 -  
3 -  
4 - const U8 bitMask[8] = { 0x80, 0x40, 0x20, 0x10,  
5 - 0x08, 0x04, 0x02, 0x01 };  
6 -  
7 - U8 getByteAt(unsigned char * bitStream,  
8 - int byteIndex)  
9 - {  
10 - return bitStream[byteIndex];  
11 -  
12 - }  
13 -  
14 - BOOL getBitAt(unsigned char * bitStream, int bitIndex)  
15 - {  
16 - int byteIndex = bitIndex / 8;  
17 - int bitOffset = bitIndex % 8;  
18 -  
19 - if ((bitStream[byteIndex] & bitMask[bitOffset]) != 0)  
20 - return TRUE;  
21 - else  
22 - return FALSE;  
23 - }  
24 -  
25 - U32 getIntAt(unsigned char * bitStream,int intIndex)  
26 - {  
27 - U32 * bitStream2 = (U32 *) bitStream;  
28 - return bitStream2[intIndex];  
29 -  
30 - }  
31 -  
32 - U8 getByteAtBits(unsigned char * bitStream,int firstBitOffset, int length)  
33 - {  
34 - U8 byte = 0x00;  
35 - int lastBitOffset = firstBitOffset + length - 1;  
36 -  
37 - int i, bit;  
38 - for (bit = lastBitOffset, i = 7;  
39 - bit >= firstBitOffset;  
40 - bit--, i--){  
41 - int byteIndex = bit / 8;  
42 - int bitOffset = bit % 8;  
43 - if ((bitStream[byteIndex] & bitMask[bitOffset]) != 0){  
44 - byte = byte | bitMask[i];  
45 - }  
46 - }  
47 -  
48 - return byte;  
49 - }  
50 - U32 getIntAtBits(unsigned char * bitStream,int firstBitOffset, int length)  
51 - {  
52 - U32 integer = 0x00000000;  
53 - U8 * byte = (U8 *) &integer;  
54 - int lastBitOffset = firstBitOffset + length - 1;  
55 -  
56 - int i, bit;  
57 - for (bit = lastBitOffset, i = 31;  
58 - bit >= firstBitOffset;  
59 - bit--, i--){  
60 - int byteIndex = bit / 8;  
61 - int bitOffset = bit % 8;  
62 - if ((bitStream[byteIndex] & bitMask[bitOffset]) != 0){  
63 - int byteIndex2 = 3 - (i / 8);  
64 - int bitOffset2 = i % 8;  
65 - byte[byteIndex2] = byte[byteIndex2] | bitMask[bitOffset2];  
66 - }  
67 - }  
68 -  
69 - return integer;  
70 - }  
71 -  
demux/src/demux.cpp
@@ -1,256 +0,0 @@ @@ -1,256 +0,0 @@
1 -/*  
2 - * Demux.cpp  
3 - *  
4 - * Created on: 09/10/2008  
5 - * Author: lacet  
6 - */  
7 -  
8 -#include "filter.h"  
9 -#include "packet.h"  
10 -#include "section_hal.h"  
11 -  
12 -#include <stdio.h>  
13 -#include <string.h>  
14 -  
15 -#include "demux.h"  
16 -#include "demuxListener.h"  
17 -#include "jmutex.h"  
18 -#include "util.h"  
19 -#define OK (0)  
20 -  
21 -//debug  
22 -#define DEBUG 0  
23 -#define DEBUG_ARQ 0  
24 -  
25 -FILE *file = NULL;  
26 -  
27 -Packet* myPacket = NULL;  
28 -  
29 -Mutex* mutex = new Mutex();  
30 -  
31 -Demux::Demux(int pid) {  
32 - //mutex->Lock();  
33 - //filters = new vector<Filter*> ();  
34 - filter = new Filter(pid, 0, 0);  
35 - //printf("\nFiltro Setado\n");  
36 - mySectionBuffer = new SectionBuffer();  
37 - mySectionBuffer->initSectionsBuffer();  
38 - sectionSize = -1;  
39 - sectionRead = 0;  
40 - countPacotes = 0;  
41 - continuityCounter = 0;  
42 - lastContinuityCounter = 0;  
43 - flagShiftPointerField = 1;  
44 - //setDemuxListener();  
45 - //mutex->Unlock();  
46 -}  
47 -  
48 -Demux::Demux(int pid, DemuxListener* listener) {  
49 - //mutex->Lock();  
50 - //filters = new vector<Filter*> ();  
51 - filter = new Filter(pid, 0, 0);  
52 - //printf("\nFiltro Setado\n");  
53 - mySectionBuffer = new SectionBuffer();  
54 - mySectionBuffer->initSectionsBuffer();  
55 - sectionSize = -1;  
56 - sectionRead = 0;  
57 - countPacotes = 0;  
58 - continuityCounter = 0;  
59 - lastContinuityCounter = 0;  
60 - setDemuxListener(listener);  
61 - //mutex->Unlock();  
62 - ouvintes = new list<OuvinteDemux*>();  
63 -  
64 - // Inicia o mutex  
65 - mutex = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t));  
66 - pthread_mutex_init(mutex, NULL);  
67 -}  
68 -  
69 -void Demux::setDemuxListener(DemuxListener* listener) {  
70 - this->listener = listener;  
71 -}  
72 -  
73 -void Demux::chegouInput(unsigned char *pacote) {  
74 - // Mutex para evitar bug multiplas chamadas dos notificadores  
75 - pthread_mutex_lock(mutex);  
76 - Packet *mypack = new Packet(pacote);  
77 - getNextSection(pacote, mypack);  
78 -  
79 - pthread_mutex_unlock(mutex);  
80 -  
81 -}  
82 -  
83 -Demux::~Demux() {  
84 -  
85 - delete filter;  
86 - delete mySectionBuffer;  
87 -  
88 - if (ouvintes) {  
89 - // nao deleta os ouvintes mesmo, apenas a lista  
90 - ouvintes->clear();  
91 - delete ouvintes;  
92 - }  
93 -  
94 - if (mutex) {  
95 - int ret = pthread_mutex_destroy(mutex);  
96 - if (ret)  
97 - printf("erro destruindo mutex\n");  
98 - free(mutex);  
99 - }  
100 -  
101 -  
102 -}  
103 -  
104 -Filter* Demux::getFilter() {  
105 - return filter;  
106 -}  
107 -  
108 -int getPESSize(unsigned char* pacote) {  
109 - return getIntAtBits(pacote, 32, 16) + 6;  
110 -}  
111 -int start = 0;  
112 -//int countPacotes = 0;  
113 -  
114 -int Demux::getNextSection(unsigned char* packet, Packet *myPacket) {  
115 - //countPacotes++;  
116 - //unsigned char* packet = new unsigned char[PACKET_SIZE]; // TODO desalocar  
117 - unsigned char *payloadData;  
118 - static utils::Util util;  
119 - int packetControl = OK;  
120 - //Filter* filter;  
121 - //int packetControl;  
122 - int count1, count2;  
123 - count1 = count2 = 0;  
124 - //printf("\nPacket Notified - PID: %d\nSection Read: %d\n", myPacket->getPid(), sectionRead);  
125 - //this->flagShiftPointerField = 1;  
126 -  
127 - if (myPacket && filter) {  
128 -  
129 - if (packetControl == OK) {  
130 -  
131 - if (myPacket->getPid() != filter->getFilterPid()) {  
132 - //printf("\nRefused Packet - PID: %d\n", myPacket->getPid());  
133 - //invalid pid  
134 -  
135 - return 0;  
136 - } else if (myPacket->getPayloadLength() < 1) {  
137 - //printf("\nEmpty Payload\n");  
138 - return 0;  
139 - //empty payload  
140 - } else {  
141 - //cout << "Accepted Packet - PID: " << myPacket->getPid() << endl;  
142 - continuityCounter = myPacket->getContinuityCounter();  
143 - //printf("\nContinuity Counter: %d\n", continuityCounter);  
144 -  
145 - if (start == 0) {  
146 - start = 1;  
147 - } else {  
148 - if (lastContinuityCounter == 15) {  
149 - if (continuityCounter != 0) {  
150 - //cout << "ERRO DE CONTINUIDADE!!" << endl;  
151 - //cout << "PID: " << myPacket->getPid() << endl;  
152 - //cout << "CC: " << continuityCounter << endl;  
153 - //cout << "LCC: " << lastContinuityCounter << endl;  
154 - lastContinuityCounter = continuityCounter;  
155 - sectionRead = 0;  
156 - sectionSize = -1;  
157 - return OK;  
158 -  
159 - }  
160 - } else if (continuityCounter != (lastContinuityCounter + 1)) {  
161 - //cout << "ERRO DE CONTINUIDADE!" << endl;  
162 - //cout << "PID: " << myPacket->getPid() << endl;  
163 - //cout << "CC: " << continuityCounter << endl;  
164 - //cout << "LCC: " << lastContinuityCounter << endl;  
165 -  
166 - lastContinuityCounter = continuityCounter;  
167 - sectionRead = 0;  
168 - sectionSize = -1;  
169 - return OK;  
170 - }  
171 - }  
172 - }  
173 - lastContinuityCounter = continuityCounter;  
174 -  
175 - }  
176 - } else {  
177 - //printf("\nInvalid Packet\n");  
178 - return 0;  
179 - //invalid packet  
180 - }  
181 -  
182 - payloadData = myPacket->getPayloadCopy();  
183 - payloadSize = myPacket->getPayloadLength();  
184 - // TODO validate continuity_counter  
185 - if (myPacket->hasAdaptationField()) {  
186 - int tamanho = packet[4];  
187 - payloadData = (unsigned char *) myPacket->getPayloadBeginingAtUnitStarted();  
188 - payloadSize = myPacket->getPayloadBeginingAtUnitStartedLength();  
189 - if (payloadData[0] == 0x00 && payloadData[1] == 0x00 && payloadData[2] == 0x01) {  
190 - //cout << "Pegou Payload Correto" << endl;  
191 - } else {  
192 - cout << "Pegou Payload Errado" << endl;  
193 - }  
194 -  
195 - } else {  
196 -  
197 - }  
198 -  
199 - if (sectionRead == 0) {  
200 -  
201 - sectionSize = getPESSize(payloadData);  
202 -  
203 - if (sectionSize > payloadSize) {  
204 - memcpy(sectionData, payloadData, payloadSize);  
205 - sectionRead += payloadSize;  
206 - } else {  
207 - memcpy(sectionData, payloadData, sectionSize);  
208 - sectionRead += sectionSize;  
209 - }  
210 -  
211 - if (sectionData[0] == 0x00 && sectionData[1] == 0x00 && sectionData[2] == 0x01) {  
212 - //cout << "Pacote PES OK!" << endl;  
213 - } else {  
214 - sectionRead = 0;  
215 - sectionSize = -1;  
216 - cout << "Pacote PES ERRADO!" << endl;  
217 - }  
218 -  
219 - } else {  
220 -  
221 - if ((sectionSize - sectionRead) > payloadSize) {  
222 - memcpy(sectionData + sectionRead, payloadData, payloadSize);  
223 - sectionRead += payloadSize;  
224 - } else {  
225 - memcpy(sectionData + sectionRead, payloadData, (sectionSize - sectionRead));  
226 - sectionRead += (sectionSize - sectionRead);  
227 - }  
228 -  
229 - }  
230 -  
231 - if (sectionRead == sectionSize) {  
232 - sectionSize = getPESSize(sectionData);  
233 - //cout << "PES NOTIFIED - PES Size: " << sectionSize << endl;  
234 - listener->notifySection(myPacket->getPid(), sectionData, sectionSize);  
235 - sectionRead = 0;  
236 - sectionSize = -1;  
237 -  
238 - }  
239 -  
240 - delete myPacket;  
241 - return OK;  
242 -}  
243 -  
244 -void Demux::registraOuvinte(OuvinteDemux * ouvinte) {  
245 - ouvintes->push_back(ouvinte);  
246 -}  
247 -  
248 -void Demux::removeOuvinte(OuvinteDemux * ouvinte) {  
249 - ouvintes->remove(ouvinte);  
250 -}  
251 -  
252 -void Demux::notificaOuvintes(unsigned char * sec) {  
253 - for (list<OuvinteDemux*>::iterator i = ouvintes->begin(); i != ouvintes->end(); i++) {  
254 - (*i)->chegou(sec);  
255 - }  
256 -}  
demux/src/demuxListener.cpp
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -#include "demuxListener.h"  
2 -  
3 -DemuxListener::DemuxListener() {  
4 -}  
5 -  
6 -DemuxListener::~DemuxListener() {  
7 -}  
demux/src/filter.cpp
@@ -1,147 +0,0 @@ @@ -1,147 +0,0 @@
1 -/*  
2 - * Filter.cpp  
3 - *  
4 - * Created on: 08/10/2008  
5 - * Author: lacet  
6 - */  
7 -  
8 -#include "filter.h"  
9 -#include "packet.h"  
10 -#include "section_hal.h"  
11 -  
12 -#include <stdio.h>  
13 -#include <string.h>  
14 -#include "util.h"  
15 -  
16 -int sectionSizee;  
17 -  
18 -Filter::Filter(int FilterPID, int FilterTID, int FilterTIDx) {  
19 - // TODO Auto-generated constructor stub  
20 - this->setFilterPid(FilterPID);  
21 - this->setFilterTid(FilterTID);  
22 - this->setFilterTidx(FilterTIDx);  
23 - this->setLastSectionCRC(0);  
24 - this->setCrcErrorCount(0);  
25 -}  
26 -  
27 -Filter::Filter() {  
28 -  
29 -}  
30 -  
31 -Filter::~Filter() {  
32 - // TODO Auto-generated destructor stub  
33 -}  
34 -  
35 -int Filter::isValid(unsigned char *section, Packet* myPacket, DemuxListener* listener) {  
36 - static utils::Util util;  
37 -  
38 - if (getFilterTidx() == -1) {  
39 - //printf("->2\n");  
40 - if (section[0] == this->getFilterTid()) {  
41 - //printf("->3\n");  
42 - if (checkCRC32(section)) {  
43 - if (getSectionCRC(section) != this->getLastSectionCRC()) {  
44 - this->setLastSectionCRC(getSectionCRC(section));  
45 - return 1;  
46 - } else {  
47 - //Old Version Of Section  
48 - /*analisadorSI*/listener->notifyOldSection(myPacket->getPid(), getTid(  
49 - section), getTidX(section));  
50 - if (getTid(section) == 80) {  
51 - int a = util.getBits(section, 0, 48, 8);  
52 - if (a == 48) {  
53 - //printf("\nOld Section\n");  
54 - }  
55 - }  
56 - return 0;  
57 - }  
58 - } else {  
59 - //return 0;  
60 - this->setCrcErrorCount(this->getCrcErrorCount() + 1);  
61 - cout << "\nERRO DE CRC no PID " << myPacket->getPid() << endl;  
62 -  
63 - sectionSizee = getSectionSize(section);  
64 -  
65 - listener->notifyErroCRC(this->getCrcErrorCount(),  
66 - myPacket->getPid(), getTid(section), getTidX(section),  
67 - section, sectionSizee);  
68 -  
69 - //return 1;  
70 - return 0;  
71 - }  
72 -  
73 - } else {  
74 -  
75 - return 0;  
76 - }  
77 - } else {  
78 -  
79 - if ((section[0] == this->getFilterTid()) && (getIntAtBits(section, 24,  
80 - 16) == this->getFilterTidx())) {  
81 - if (checkCRC32(section)) {  
82 - if (getSectionCRC(section) != this->getLastSectionCRC()) {  
83 - this->setLastSectionCRC(getSectionCRC(section));  
84 - return 1;  
85 - } else {  
86 - //Old Version Of Section  
87 - /*analisadorSI*/listener->notifyOldSection(myPacket->getPid(), getTid(  
88 - section), getTidX(section));  
89 - return 0;  
90 - }  
91 - } else {  
92 - this->setCrcErrorCount(this->getCrcErrorCount() + 1);  
93 - sectionSizee = getSectionSize(section);  
94 - /*analisadorSI*/listener->notifyErroCRC(this->getCrcErrorCount(),  
95 - myPacket->getPid(), getTid(section), getTidX(section),  
96 - section, sectionSizee);  
97 - cout << "\nERRO DE CRC no PID " << myPacket->getPid() << endl;  
98 -  
99 - return 0;  
100 - }  
101 - } else {  
102 - //printf("->6");  
103 - return 0;  
104 - }  
105 - }  
106 -}  
107 -  
108 -void Filter::setLastSectionCRC(int lastSectionCRC) {  
109 - this->lastSectionCRC = lastSectionCRC;  
110 -}  
111 -  
112 -void Filter::setFilterPid(int FilterPID) {  
113 - this->FilterPID = FilterPID;  
114 -}  
115 -  
116 -void Filter::setFilterTid(int FilterTID) {  
117 - this->FilterTID = FilterTID;  
118 -}  
119 -  
120 -void Filter::setFilterTidx(int FilterTIDx) {  
121 - this->FilterTIDx = FilterTIDx;  
122 -}  
123 -  
124 -void Filter::setCrcErrorCount(int crcErrorCount) {  
125 - this->crcErrorCount = crcErrorCount;  
126 -}  
127 -  
128 -int Filter::getCrcErrorCount() {  
129 - return crcErrorCount;  
130 -}  
131 -  
132 -int Filter::getLastSectionCRC() {  
133 - return lastSectionCRC;  
134 -}  
135 -  
136 -int Filter::getFilterPid() {  
137 - return FilterPID;  
138 -}  
139 -  
140 -int Filter::getFilterTid() {  
141 - return FilterTID;  
142 -}  
143 -  
144 -int Filter::getFilterTidx() {  
145 - return FilterTIDx;  
146 -}  
147 -  
demux/src/include/bitutil_hal.h
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -#ifndef BITUTIL_H_  
2 -#define BITUTIL_H_  
3 -//#include "global_init.h"  
4 -  
5 -typedef unsigned char U8;  
6 -typedef unsigned short U16;  
7 -typedef unsigned int U32;  
8 -typedef unsigned char BOOL;  
9 -  
10 -#define TRUE (1)  
11 -#define FALSE (0)  
12 -  
13 -U8 getByteAt(unsigned char * bitStream,int byteIndex);  
14 -BOOL getBitAt(unsigned char * bitStream, int bitIndex);  
15 -U32 getIntAt(unsigned char * bitStream,int intIndex);  
16 -U8 getByteAtBits(unsigned char * bitStream,int firstBitOffset, int length);  
17 -U32 getIntAtBits(unsigned char * bitStream,int firstBitOffset, int length);  
18 -  
19 -  
20 -#endif /*BITUTIL_H_*/  
demux/src/include/demux.h
@@ -1,70 +0,0 @@ @@ -1,70 +0,0 @@
1 -/*  
2 - * demux.h  
3 - *  
4 - * Created on: 09/10/2008  
5 - * Author: lacet  
6 - */  
7 -  
8 -#ifndef DEMUX_H_  
9 -#define DEMUX_H_  
10 -  
11 -#include "filter.h"  
12 -#include <vector>  
13 -#include "jthread.h"  
14 -#include <pthread.h>  
15 -#include "demuxListener.h"  
16 -#include "ouvinteDemux.h"  
17 -#include "ouvinteInput.h"  
18 -  
19 -  
20 -using namespace std;  
21 -  
22 -using namespace jthread;  
23 -  
24 -class Demux : public OuvinteInput {  
25 -  
26 -private:  
27 -  
28 - vector<Filter*> *permanentFilters;  
29 - //vector<Filter*> *filters;  
30 - //Filter* *filters;  
31 - //Filter* filter;  
32 - vector<Filter*> *addedFilter;  
33 - vector<Filter*> *filtersAux;  
34 - SectionBuffer* mySectionBuffer;  
35 - DemuxListener* listener;  
36 - int sectionSize;  
37 -  
38 - int sectionRead;  
39 - unsigned char section[MAX_SECTION_SIZE];  
40 - int payloadSize;  
41 - int firstPart;  
42 - int quantity;  
43 - int remain;  
44 - int countPacotes;  
45 - unsigned char sectionData[MAX_SECTION_SIZE];  
46 - int continuityCounter;  
47 - int lastContinuityCounter;  
48 - int flagShiftPointerField;  
49 -  
50 - std::list<OuvinteDemux*> * ouvintes;  
51 - pthread_mutex_t *mutex;  
52 -  
53 -public:  
54 - //void setDemuxListener();  
55 - void setDemuxListener(DemuxListener* listener);  
56 - Filter* filter;  
57 - ~Demux();  
58 - Demux(int pid);  
59 - Demux(int pid, DemuxListener* listener);  
60 - Filter* getFilter();  
61 - int getNextSection(unsigned char* packet, Packet *myPacket);  
62 -  
63 - virtual void chegouInput(unsigned char *pacote);  
64 - void registraOuvinte(OuvinteDemux * ouvinte);  
65 - void removeOuvinte(OuvinteDemux * ouvinte);  
66 - void notificaOuvintes(unsigned char * CC);  
67 -  
68 -};  
69 -  
70 -#endif /* DEMUX_H_ */  
demux/src/include/demuxListener.h
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -/*  
2 - * demuxListener.h  
3 - *  
4 - * Created on: 03/10/2008  
5 - * Author: thales  
6 - */  
7 -  
8 -#ifndef DEMUXLISTENER_H_  
9 -#define DEMUXLISTENER_H_  
10 -  
11 -  
12 -#include <vector>  
13 -#include <list>  
14 -#include <iostream>  
15 -  
16 -using namespace std;  
17 -  
18 -class DemuxListener{  
19 -public:  
20 - DemuxListener();  
21 - ~DemuxListener();  
22 - virtual void notifySection(int PID, unsigned char* section, int sectionSize) = 0;  
23 -  
24 - virtual void notifyErroCRC(int numErroCRC, int PID, int tableID, int tableIDX, unsigned char* section,  
25 - int sectionSize) = 0;  
26 -  
27 - virtual void notifyOldSection(int PID, int tableID, int tableIDX) = 0;  
28 -  
29 - // virtual ~DemuxListener() = 0;  
30 -  
31 -};  
32 -  
33 -  
34 -#endif /* IANALISADORSI_H_ */  
demux/src/include/filter.h
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -/*  
2 - * filter.h  
3 - *  
4 - * Created on: 08/10/2008  
5 - * Author: lacet  
6 - */  
7 -  
8 -#ifndef FILTER_H_  
9 -#define FILTER_H_  
10 -  
11 -#include "sectionBuffer.h"  
12 -#include "bitutil_hal.h"  
13 -#include "demuxListener.h"  
14 -#include "packet.h"  
15 -  
16 -  
17 -  
18 -class Filter {  
19 -  
20 -private:  
21 - int FilterPID;  
22 - int FilterTID;  
23 - int FilterTIDx;  
24 - int lastSectionCRC;  
25 - int crcErrorCount;  
26 -  
27 -public:  
28 - Filter(int FilterPID, int FilterTID, int FilterTIDx);  
29 - Filter();  
30 - virtual ~Filter();  
31 - int isValid(unsigned char *section, Packet* myPacket, DemuxListener* listener);  
32 - //int getNextPacket(unsigned char *packet);  
33 - //int getNextSection(unsigned char *section, SectionBuffer *mySectionBuffer);  
34 - //int test();  
35 - void setLastSectionCRC(int lastSectionCRC);  
36 - void setFilterPid(int FilterPID);  
37 - void setFilterTid(int FilterTID);  
38 - void setFilterTidx(int FilterTIDx);  
39 - void setCrcErrorCount(int crcErrorCount);  
40 - int getLastSectionCRC();  
41 - int getFilterPid();  
42 - int getFilterTid();  
43 - int getFilterTidx();  
44 - int getCrcErrorCount();  
45 -  
46 -};  
47 -  
48 -#endif /* FILTER_H_ */  
demux/src/include/ouvinteDemux.h
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -/*  
2 - * File: ouvintedemux.h  
3 - * Author: felipel  
4 - *  
5 - * Created on 12 de Julho de 2010, 15:03  
6 - */  
7 -  
8 -#ifndef OUVINTEDEMUX_H  
9 -#define OUVINTEDEMUX_H  
10 -  
11 -#include <string>  
12 -  
13 -using namespace std;  
14 -  
15 -class OuvinteDemux {  
16 -public:  
17 - OuvinteDemux();  
18 - virtual ~OuvinteDemux();  
19 -  
20 - virtual void chegou(unsigned char * section) = 0;  
21 -private:  
22 -  
23 -};  
24 -  
25 -#endif /* OUVINTEDEMUX_H */  
26 -  
demux/src/include/packet.h
@@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
1 -/* Modificado por: @Felipe Lacet  
2 - * Ultima Atualização: 08/10/2008  
3 - *  
4 - * packet.h  
5 - *  
6 - */  
7 -  
8 -#ifndef PACKET_H_  
9 -#define PACKET_H_  
10 -//#include "global_init.h"  
11 -#include "bitutil_hal.h"  
12 -#define PACKET_SIZE (188)  
13 -  
14 -  
15 -  
16 -class Packet{  
17 -  
18 -public:  
19 -  
20 -Packet(unsigned char* packet);  
21 -~Packet();  
22 -unsigned char* getPayloadBeginingAtUnitStarted();  
23 -BOOL hasPointerField();  
24 -BOOL hasPayload();  
25 -U8 getPayloadLength();  
26 -unsigned char * getPayloadCopy();  
27 -U8 getPayloadBeginingAtUnitStartedLength();  
28 -U8 getPointerField();  
29 -U16 getPid();  
30 -U8 getAdaptationFieldLength();  
31 -U32 getContinuityCounter();  
32 -BOOL hasAdaptationField();  
33 -BOOL parser();  
34 -  
35 -private:  
36 -  
37 -unsigned char* packet;  
38 -  
39 -};  
40 -  
41 -#endif /*PACKET_H_*/  
demux/src/include/sectionBuffer.h
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -/* Modificado por: @Felipe Lacet  
2 - * Ultima Atualização: 08/10/2008  
3 - *  
4 - * sectionBuffer.h  
5 - *  
6 - */  
7 -#ifndef QUEUE_H_  
8 -#define QUEUE_H_  
9 -#include "section_hal.h"  
10 -  
11 -#define MAX_SECTIONS_COUNT (20)  
12 -  
13 -#define SECTIONS_BUFFER_SIZE (MAX_SECTIONS_COUNT*MAX_SECTION_SIZE)  
14 -  
15 -class SectionBuffer{  
16 -  
17 -private:  
18 - unsigned char sectionsBufferData[SECTIONS_BUFFER_SIZE];  
19 - int sectionsBufferBegin;  
20 - int sectionsBufferEnd;  
21 - int bufferSectionsCount;  
22 -  
23 -public:  
24 - SectionBuffer();  
25 - ~SectionBuffer();  
26 - void copyData(unsigned char *data, int *position, int size, int fromBuffer);  
27 - void initSectionsBuffer();  
28 - int getSectionsCount();  
29 - void addSection(unsigned char *section);  
30 - void removeSection(unsigned char *section);  
31 -  
32 -};  
33 -  
34 -#endif //QUEUE_H_  
demux/src/include/section_hal.h
@@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
1 -#ifndef SECTION_H_  
2 -#define SECTION_H_  
3 -#include "bitutil_hal.h"  
4 -#include <stdio.h>  
5 -  
6 -#define SECTION_HEADER_SIZE (6)  
7 -  
8 -#define MAX_SECTION_SIZE (4096)  
9 -  
10 -  
11 -U8 getTid(unsigned char* section);  
12 -U16 getTidX(unsigned char* section);  
13 -int getSectionSize(unsigned char* payload);  
14 -U8 getSectionNumber(unsigned char *bitStream);  
15 -U32 getSectionCRC(unsigned char* section);  
16 -BOOL checkCRC32(unsigned char* section);  
17 -U32 calculateCrc(unsigned char *begin, unsigned count);  
18 -  
19 -  
20 -  
21 -  
22 -#endif /*SECTION_H_*/  
demux/src/include/util.h
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -#ifndef UTIL_H_  
2 -#define UTIL_H_  
3 -  
4 -#include <string>  
5 -#include <sstream>  
6 -#include <stdlib.h>  
7 -#include <stdio.h>  
8 -#include <algorithm>  
9 -  
10 -using std::string;  
11 -  
12 -namespace utils  
13 -{  
14 -  
15 -class Util  
16 -{  
17 -public:  
18 -  
19 - /*  
20 - retorna os bits do buffer.  
21 - */  
22 - static unsigned long long getBits(unsigned char* buf, int byte_offset, int startbit, int bitlen);  
23 -  
24 - static void stringUpper(string& string);  
25 -  
26 - static string int2str(int n);  
27 -  
28 - static int stringtoint(const char* string);  
29 -  
30 - static long long getBits48(unsigned char *buf, int byte_offset, int startbit, int bitlen);  
31 -  
32 - static unsigned long long getBits64(unsigned char *buf, int byte_offset, int startbit, int bitlen);  
33 -};  
34 -  
35 -}  
36 -  
37 -#endif /*UTIL_H_*/  
demux/src/ouvinteDemux.cpp
@@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
1 -/*  
2 - * File: ouvinteDemux.cpp  
3 - * Author: felipel  
4 - *  
5 - * Created on 12 de Julho de 2010, 15:03  
6 - */  
7 -  
8 -#include "ouvinteDemux.h"  
9 -  
10 -OuvinteDemux::OuvinteDemux() {  
11 -}  
12 -  
13 -OuvinteDemux::~OuvinteDemux() {  
14 -}  
15 -  
demux/src/packet.cpp
@@ -1,129 +0,0 @@ @@ -1,129 +0,0 @@
1 -/* Modificado por: @Felipe Lacet  
2 - * Ultima Atualização: 08/10/2008  
3 - *  
4 - * Packet.cpp  
5 - *  
6 - */  
7 -#include "bitutil_hal.h"  
8 -#include "packet.h"  
9 -//#include "dprintf.h"  
10 -#include <iostream>  
11 -int TS_PACKET_SIZE = 188;  
12 -  
13 -//static int payloadIndex;  
14 -using namespace std;  
15 -  
16 -Packet::Packet(unsigned char* packet) {  
17 -  
18 - this->packet = packet;  
19 -  
20 -}  
21 -  
22 -Packet::~Packet() {  
23 -};  
24 -  
25 -unsigned char* Packet::getPayloadBeginingAtUnitStarted() {  
26 -  
27 - int payloadIndex = 4 + (hasAdaptationField() ? 1 : 0) + getAdaptationFieldLength();  
28 - return (&packet[payloadIndex]);  
29 -  
30 -}  
31 -  
32 -BOOL Packet::hasPointerField() {  
33 - return ( getBitAt(packet, 9));  
34 -}  
35 -  
36 -BOOL Packet::hasPayload() {  
37 - unsigned int adaptationFieldControl = getByteAtBits(packet, 26, 2);  
38 -  
39 - if ((adaptationFieldControl == 0x1) || (adaptationFieldControl == 0x3)) {  
40 - return (1);  
41 - } else {  
42 - return (0);  
43 - }  
44 -}  
45 -  
46 -U8 Packet::getPayloadLength() {  
47 - if (!hasPayload()) {  
48 - return (0);  
49 - } else {  
50 - return (TS_PACKET_SIZE - (hasAdaptationField() ? 1 : 0) - getAdaptationFieldLength() - 4);  
51 - }  
52 -}  
53 -  
54 -unsigned char* Packet::getPayloadCopy() {  
55 - int payloadIndex = 4 + (hasAdaptationField() ? 1 : 0) + getAdaptationFieldLength();  
56 -  
57 - if (hasPayload()) {  
58 - int size = getPayloadLength();  
59 -  
60 - /*unsigned char * payload =(unsigned char *) malloc(sizeof(unsigned char)*size);*/  
61 - return (&packet[payloadIndex]);  
62 -  
63 - /*memcpy(payload, &packet[payloadIndex], size);*/  
64 - /*return payload;*/  
65 - /*return &packet[payloadIndex];*/  
66 - } else {  
67 - return (NULL);  
68 - }  
69 -}  
70 -  
71 -U8 Packet::getPayloadBeginingAtUnitStartedLength() {  
72 - int payloadIndex = 4 + (hasAdaptationField() ? 1 : 0) + getAdaptationFieldLength();  
73 - return TS_PACKET_SIZE - payloadIndex - 1;  
74 -}  
75 -  
76 -U8 Packet::getPointerField() {  
77 - int payloadIndex = 4 + (hasAdaptationField() ? 1 : 0) + getAdaptationFieldLength();  
78 -  
79 - if (hasPointerField()) {  
80 - unsigned char pf = getByteAt(packet, payloadIndex);  
81 - //cout << "Poiter Field: " << pf << endl;  
82 - //printf("Poiter Field: %x\n", pf);  
83 - return ( getByteAt(packet, payloadIndex));  
84 - } else {  
85 - return (0);  
86 - }  
87 -}  
88 -  
89 -U16 Packet::getPid() {  
90 - return ( getIntAtBits(packet, 11, 13));  
91 -}  
92 -  
93 -U8 Packet::getAdaptationFieldLength() {  
94 - if (hasAdaptationField()) {  
95 - return ( getByteAt(packet, 4));  
96 - } else {  
97 - return (0);  
98 - }  
99 -}  
100 -  
101 -unsigned int Packet::getContinuityCounter() {  
102 - return ( getIntAtBits(packet, 28, 4));  
103 -}  
104 -  
105 -BOOL Packet::hasAdaptationField() {  
106 - unsigned int adaptationFieldControl = getByteAtBits(packet, 26, 2);  
107 -  
108 - if ((adaptationFieldControl == 0x2) || (adaptationFieldControl == 0x3)) {  
109 - return TRUE;  
110 - } else {  
111 - return FALSE;  
112 - }  
113 -}  
114 -  
115 -BOOL Packet::parser() {  
116 - // DPRINTF("PACOTE %X\n",packet[0]);  
117 - if (getByteAt(packet, 0) != 0x47) {  
118 - // DPRINTF("NAO PACOTE");  
119 - return FALSE;  
120 - }  
121 -  
122 - if (getBitAt(packet, 8)) {  
123 - // DPRINTF("NAO PACOTE 2");  
124 -  
125 - return FALSE;  
126 - }  
127 - // payloadIndex = 4 + (hasAdaptationField(packet) ? 1 : 0) + getAdaptationFieldLength(packet);  
128 - return TRUE;  
129 -}  
demux/src/sectionBuffer.cpp
@@ -1,123 +0,0 @@ @@ -1,123 +0,0 @@
1 -/* Modificado por: @Felipe Lacet  
2 - * Ultima Atualização: 08/10/2008  
3 - *  
4 - * SectionBuffer.cpp  
5 - *  
6 - */  
7 -  
8 -//#include "queue.h"  
9 -#include <string.h>  
10 -#include <stdio.h>  
11 -//#include "dprintf.h"  
12 -#include "section_hal.h"  
13 -#include "sectionBuffer.h"  
14 -  
15 -SectionBuffer::SectionBuffer() {  
16 - initSectionsBuffer();  
17 -}  
18 -  
19 -SectionBuffer::~SectionBuffer() {  
20 -}  
21 -  
22 -void SectionBuffer::copyData(unsigned char *data, int *position, int size, int fromBuffer) {  
23 - unsigned char *source, *target;  
24 - int rightSpace;  
25 -  
26 - rightSpace = SECTIONS_BUFFER_SIZE - *position;  
27 - if (fromBuffer) {  
28 - source = sectionsBufferData + *position;  
29 - target = data;  
30 - } else {  
31 - source = data;  
32 - target = sectionsBufferData + *position;  
33 - }  
34 -  
35 - if (size > rightSpace) {  
36 - memcpy(target, source, rightSpace);  
37 - if (fromBuffer) {  
38 - target = data + rightSpace;  
39 - source = sectionsBufferData;  
40 - } else {  
41 - target = sectionsBufferData;  
42 - source = data + rightSpace;  
43 - }  
44 - memcpy(target, source, size - rightSpace);  
45 - } else {  
46 - memcpy(target, source, size);  
47 - }  
48 -  
49 - *position = (*position + size) % SECTIONS_BUFFER_SIZE;  
50 -}  
51 -  
52 -void SectionBuffer::initSectionsBuffer() {  
53 - sectionsBufferBegin = 0;  
54 - sectionsBufferEnd = 0;  
55 - bufferSectionsCount = 0;  
56 - memset(sectionsBufferData, 0, SECTIONS_BUFFER_SIZE);  
57 -}  
58 -  
59 -//int getSectionsCount(demux_section_t *demux_section)  
60 -  
61 -int SectionBuffer::getSectionsCount() {  
62 - return bufferSectionsCount;  
63 -}  
64 -  
65 -void SectionBuffer::addSection(unsigned char *section) {  
66 - copyData(section, &sectionsBufferEnd, getSectionSize(section), 0);  
67 - bufferSectionsCount++;  
68 -}  
69 -  
70 -void SectionBuffer::removeSection(unsigned char *section) {  
71 - // copy section header  
72 - copyData(section, &sectionsBufferBegin, SECTION_HEADER_SIZE, 1);  
73 - // copy section body  
74 - copyData(section + SECTION_HEADER_SIZE, &sectionsBufferBegin, getSectionSize(section) - SECTION_HEADER_SIZE, 1);  
75 - // update sections counter  
76 - bufferSectionsCount--;  
77 -}  
78 -  
79 -/*  
80 -  
81 -// tests  
82 -  
83 -int main() {  
84 - int i, j, k;  
85 - unsigned char section[5][8] = {  
86 - { 99, 0, 2, 99, 99, 99, 99, 99 },  
87 - { 88, 0, 5, 88, 88, 88, 88, 88 },  
88 - { 77, 0, 1, 77, 77, 77, 77, 77 },  
89 - { 66, 0, 3, 66, 66, 66, 66, 66 },  
90 - { 55, 0, 1, 55, 55, 55, 55, 55 }  
91 - };  
92 -  
93 - initSectionsBuffer();  
94 - DPRINTF("---------------\n");  
95 -  
96 - for (i = 0, k = 0; i < 10; i++) {  
97 - DDPRINTF("i = %d\n", i);  
98 - if (i % 2 == 1) {  
99 - unsigned char removed[] = { 0, 0, 0, 0, 0, 0, 0, 0 };  
100 - DDPRINTF("will REMOVE section:");  
101 - removeSection(removed);  
102 - for (j = 0; j < getSectionSize(removed); j++) {  
103 - printf("%3d", removed[j]);  
104 - }  
105 - printf("\n");  
106 - } else {  
107 - DDPRINTF("will ADD section %d with %d bytes\n", k, getSectionSize(section[k]));  
108 - addSection(section[k++]);  
109 - }  
110 - DPRINTF("data:");  
111 - for (j = 0; j < SECTIONS_BUFFER_SIZE; j++) {  
112 - printf("%3d", demux_section->sectionsBufferData[j]);  
113 - }  
114 - printf("\n");  
115 - DPRINTF(" ");  
116 - for (j = 0; j < SECTIONS_BUFFER_SIZE; j++) {  
117 - printf(demux_section->sectionsBufferBegin == j ? (demux_section->sectionsBufferEnd == j ? " be" : " b") : (demux_section->sectionsBufferEnd == j ? " e" : " "));  
118 - }  
119 - printf("\n");  
120 - DPRINTF("sections count = %d\n", demux_section->bufferSectionsCount);  
121 - DPRINTF("---------------\n");  
122 - }  
123 -}*/  
demux/src/section_hal.cpp
@@ -1,132 +0,0 @@ @@ -1,132 +0,0 @@
1 -#include "section_hal.h"  
2 -  
3 -int crcError;  
4 -#include <iostream>  
5 -using namespace std;  
6 -  
7 -  
8 -U32 CRC32[256] = {  
9 - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,  
10 - 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,  
11 - 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,  
12 - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,  
13 - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,  
14 - 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,  
15 - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,  
16 - 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,  
17 - 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,  
18 - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,  
19 - 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,  
20 - 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,  
21 - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,  
22 - 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,  
23 - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,  
24 - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,  
25 - 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,  
26 - 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,  
27 - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,  
28 - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,  
29 - 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,  
30 - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,  
31 - 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,  
32 - 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,  
33 - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,  
34 - 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,  
35 - 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,  
36 - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,  
37 - 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,  
38 - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,  
39 - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,  
40 - 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,  
41 - 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,  
42 - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,  
43 - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,  
44 - 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,  
45 - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,  
46 - 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,  
47 - 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,  
48 - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,  
49 - 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,  
50 - 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,  
51 - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,  
52 - 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,  
53 - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,  
54 - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,  
55 - 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,  
56 - 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,  
57 - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,  
58 - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,  
59 - 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,  
60 - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,  
61 - 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,  
62 - 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,  
63 - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,  
64 - 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,  
65 - 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,  
66 - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,  
67 - 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,  
68 - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,  
69 - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,  
70 - 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,  
71 - 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,  
72 - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4,  
73 -};  
74 -  
75 -U8 getTid(unsigned char* section) {  
76 - return getByteAt(section, 0);  
77 -}  
78 -  
79 -U16 getTidX(unsigned char* section) {  
80 - return getIntAtBits(section, 24, 16);  
81 -}  
82 -  
83 -int getSectionSize(unsigned char* payload) {  
84 -  
85 - return getIntAtBits(payload, 12, 12) + 3;  
86 -  
87 -}  
88 -  
89 -U8 getSectionNumber(unsigned char *bitStream) {  
90 - return getIntAtBits(bitStream, 48, 8);  
91 -}  
92 -  
93 -U32 getSectionCRC(unsigned char* section) {  
94 - U32 sectionCRC = getIntAtBits(section, (getSectionSize(section)*8) - 32, 32);  
95 - return sectionCRC;  
96 -}  
97 -  
98 -BOOL checkCRC32(unsigned char* section) {  
99 - //if (!getBitAt(section, 8)) {  
100 - // printf("\nCRC ERROR - YES\n");  
101 - // return FALSE;  
102 - //}  
103 - U32 aux;  
104 - int i;  
105 -  
106 - U32 sectionCRC32 = getIntAtBits(section, (getSectionSize(section)*8) - 32, 32);  
107 -  
108 - aux = calculateCrc(section, (getSectionSize(section) - 4));  
109 -  
110 - if (aux == sectionCRC32) {  
111 - //printf("\nCRC Calculado: %x\nCRC Lido:%x\n", aux, sectionCRC32);  
112 -  
113 - return TRUE;  
114 -  
115 - }  
116 - printf("\nCRC Calculado: %x\nCRC Lido:%x\n", aux, sectionCRC32);  
117 - return FALSE;  
118 -}  
119 -  
120 -U32 calculateCrc(unsigned char *begin, unsigned count) {  
121 - unsigned crc = 0xffffffff;  
122 -  
123 - while (count > 0) {  
124 - crc = (crc << 8) ^ CRC32[(crc >> 24) ^ ((unsigned) * begin)];  
125 - begin++;  
126 - count--;  
127 - }  
128 -  
129 - return crc;  
130 -}  
131 -  
132 -  
demux/src/util.cpp
@@ -1,135 +0,0 @@ @@ -1,135 +0,0 @@
1 -#include "util.h"  
2 -  
3 -namespace utils {  
4 -  
5 - void Util::stringUpper(string& string) {  
6 - transform(string.begin(), string.end(), string.begin(), toupper);  
7 - }  
8 -  
9 - string Util::int2str(int n) {  
10 - std::stringstream ss;  
11 -  
12 - ss << n;  
13 - return ss.str();  
14 - }  
15 -  
16 - int Util::stringtoint(const char* string) {  
17 - return atoi(string);  
18 - }  
19 -  
20 - /*  
21 - -- get bits out of buffer (max 32 bit!!!)  
22 - -- return: value  
23 - */  
24 -  
25 - unsigned long long Util::getBits(unsigned char* buf, int byte_offset, int startbit, int bitlen) {  
26 - unsigned char *b;  
27 - unsigned long v;  
28 - unsigned long mask;  
29 - unsigned long tmp_long;  
30 - int bitHigh;  
31 -  
32 -  
33 - b = &buf[byte_offset + (startbit >> 3)];  
34 - startbit %= 8;  
35 -  
36 - switch ((bitlen - 1) >> 3) {  
37 - case -1 : // -- <=0 bits: always 0  
38 - return 0L;  
39 - break;  
40 -  
41 - case 0: // -- 1..8 bit  
42 - tmp_long = (unsigned long) (  
43 - (*(b) << 8) + *(b + 1));  
44 - bitHigh = 16;  
45 - break;  
46 -  
47 - case 1: // -- 9..16 bit  
48 - tmp_long = (unsigned long) (  
49 - (*(b) << 16) + (*(b + 1) << 8) + *(b + 2));  
50 - bitHigh = 24;  
51 - break;  
52 -  
53 - case 2: // -- 17..24 bit  
54 - tmp_long = (unsigned long) (  
55 - (*(b) << 24) + (*(b + 1) << 16) +  
56 - (*(b + 2) << 8) + *(b + 3));  
57 - bitHigh = 32;  
58 - break;  
59 -  
60 - case 3: // -- 25..32 bit  
61 - // -- to be safe, we need 32+8 bit as shift range  
62 - return (unsigned long) Util::getBits48(b, 0, startbit, bitlen);  
63 - break;  
64 -  
65 - default: // -- 33.. bits: fail, deliver constant fail value  
66 - //printf("\nGET BITS: OUT OF BOUNDS\n");  
67 - return getBits48(buf, byte_offset, startbit, bitlen);  
68 - break;  
69 - }  
70 -  
71 - startbit = bitHigh - startbit - bitlen;  
72 - tmp_long = tmp_long >> startbit;  
73 - mask = (1ULL << bitlen) - 1; // 1ULL !!!  
74 - v = tmp_long & mask;  
75 -  
76 - return v;  
77 - }  
78 -  
79 - /*  
80 - -- get bits out of buffer (max 48 bit)  
81 - -- extended bitrange, so it's slower  
82 - -- return: value  
83 - */  
84 -  
85 - long long Util::getBits48(unsigned char *buf, int byte_offset, int startbit, int bitlen) {  
86 - unsigned char *b;  
87 - unsigned long long v;  
88 - unsigned long long mask;  
89 - unsigned long long tmp;  
90 -  
91 - if (bitlen > 48) {  
92 - printf("\ngetBits48() OUT OF BOUNDS\n");  
93 - return getBits64(buf, byte_offset, startbit, bitlen);  
94 - }  
95 -  
96 -  
97 - b = &buf[byte_offset + (startbit / 8)];  
98 - startbit %= 8;  
99 -  
100 -  
101 - // -- safe is 48 bitlen  
102 - tmp = (unsigned long long) (  
103 - ((unsigned long long) *(b) << 48) + ((unsigned long long) *(b + 1) << 40) +  
104 - ((unsigned long long) *(b + 2) << 32) + ((unsigned long long) *(b + 3) << 24) +  
105 - (*(b + 4) << 16) + (*(b + 5) << 8) + *(b + 6));  
106 -  
107 - startbit = 56 - startbit - bitlen;  
108 - tmp = tmp >> startbit;  
109 - mask = (1ULL << bitlen) - 1; // 1ULL !!!  
110 - v = tmp & mask;  
111 -  
112 - return v;  
113 - }  
114 -  
115 - /*  
116 - -- get bits out of buffer (max 64 bit)  
117 - -- extended bitrange, so it's slower  
118 - -- return: value  
119 - */  
120 -  
121 - unsigned long long Util::getBits64(unsigned char *buf, int byte_offset, int startbit, int bitlen) {  
122 - unsigned long long x1, x2, x3;  
123 -  
124 - if (bitlen <= 32) {  
125 - x3 = Util::getBits(buf, byte_offset, startbit, bitlen);  
126 - } else {  
127 - x1 = Util::getBits(buf, byte_offset, startbit, 32);  
128 - x2 = Util::getBits(buf, byte_offset, startbit + 32, bitlen - 32);  
129 - x3 = (x1 << (bitlen - 32)) + x2;  
130 - }  
131 - return x3;  
132 - }  
133 -  
134 -}  
135 -  
extratorCC/src/extratorCC.cpp
@@ -1,487 +0,0 @@ @@ -1,487 +0,0 @@
1 -/*  
2 - * File: PacketPES.cpp  
3 - * Author: felipe  
4 - *  
5 - * Created on 19 de Outubro de 2009, 14:49  
6 - */  
7 -  
8 -#include "extratorCC.h"  
9 -#include <cstdlib>  
10 -#include <stdint.h>  
11 -#include <stdio.h>  
12 -#include <fstream>  
13 -#include <sstream>  
14 -  
15 -#include "dprintf.h"  
16 -  
17 -using namespace std;  
18 -  
19 -ExtratorCC::ExtratorCC() {  
20 - ouvintes = new list<OuvinteCC*>();  
21 -  
22 - PTS = 0;  
23 -  
24 - // Inicia o mutex  
25 - mutex = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t));  
26 - pthread_mutex_init(mutex, NULL);  
27 -}  
28 -  
29 -void ExtratorCC::notifySection(int PID, unsigned char* section, int sectionSize) {  
30 - //cout << "Recebi PES com a PID: " << PID << endl;  
31 - packetPES(section);  
32 -  
33 -}  
34 -  
35 -void ExtratorCC::notifyErroCRC(int numErroCRC, int PID, int tableID, int tableIDX, unsigned char* section, int sectionSize) {  
36 -  
37 -}  
38 -  
39 -void ExtratorCC::notifyOldSection(int PID, int tableID, int tableIDX) {  
40 -  
41 -}  
42 -  
43 -ExtratorCC::~ExtratorCC() {  
44 - if (ouvintes) {  
45 - // nao deleta os ouvintes mesmo, apenas a lista  
46 - ouvintes->clear();  
47 - delete ouvintes;  
48 - }  
49 -  
50 - if (mutex) {  
51 - int ret = pthread_mutex_destroy(mutex);  
52 - if (ret)  
53 - DDDPRINTF("erro destruindo mutex\n");  
54 - free(mutex);  
55 - }  
56 -}  
57 -  
58 -/*void ExtratorCC::chegouInput(unsigned char *pacote) {  
59 - // Mutex para evitar bug multiplas chamadas dos notificadores  
60 - pthread_mutex_lock(mutex);  
61 -  
62 - //packetPES(pacote);  
63 -  
64 - pthread_mutex_unlock(mutex);  
65 -}*/  
66 -  
67 -  
68 -int ExtratorCC::contemAF(unsigned char * pacote) {  
69 - return pacote[3] & 0x20;  
70 -}  
71 -  
72 -int ExtratorCC::contemDTS(unsigned char * ExtratorCC) {  
73 - return ((ExtratorCC[7] >> 6) & 0x03);  
74 -}  
75 -  
76 -int ExtratorCC::contemESCR(unsigned char * ExtratorCC) {  
77 - return ((ExtratorCC[7] >> 5) & 0x01);  
78 -}  
79 -  
80 -int ExtratorCC::contemDSM(unsigned char * ExtratorCC) {  
81 - return ((ExtratorCC[7] >> 3) & 0x01);  
82 -}  
83 -  
84 -int ExtratorCC::contemPES_extension(unsigned char * ExtratorCC) {  
85 - return ExtratorCC[7] & 0x01;  
86 -}  
87 -  
88 -int ExtratorCC::contemAdditional(unsigned char * ExtratorCC) {  
89 - return ((ExtratorCC[7] >> 2) & 0x01);  
90 -}  
91 -  
92 -int ExtratorCC::contemPES_CRC(unsigned char * ExtratorCC) {  
93 - return ((ExtratorCC[7] >> 1) & 0x01);  
94 -}  
95 -  
96 -int ExtratorCC::contemES_rate(unsigned char * ExtratorCC) {  
97 - return ((ExtratorCC[7] >> 4) & 0x01);  
98 -}  
99 -  
100 -int ExtratorCC::contemPayloadData(unsigned char *pacote) {  
101 - return pacote[3] & 0x10;  
102 -}  
103 -  
104 -int ExtratorCC::contemPayloadStartIndicator(unsigned char *pacote) {  
105 - return pacote[1] & 0x40;  
106 -}  
107 -  
108 -int ExtratorCC::contemPCR(unsigned char * pacote) {  
109 - return pacote[5] & 0x10;  
110 -}  
111 -  
112 -int ExtratorCC::contemPTS(unsigned char * ExtratorCC) {  
113 - return ((ExtratorCC[7] >> 6) & 0x02);  
114 -}  
115 -  
116 -short unsigned ExtratorCC::GetTamanhoAF(unsigned char *pacote) {  
117 - return pacote[4];  
118 -}  
119 -  
120 -int ExtratorCC::verificaPESStartCode(unsigned char * ExtratorCC) {  
121 - // cout << "Start Code: " << ((PESPacket[0] << 16) | (PESPacket[1] << 8) | (PESPacket[2])) << endl;  
122 - return (((ExtratorCC[0] << 16) | (ExtratorCC[1] << 8) | (ExtratorCC[2]))  
123 - == 0x000001) ? 1 : 0;  
124 -}  
125 -  
126 -int ExtratorCC::verificaPESStreamID(unsigned char * ExtratorCC) {  
127 - int stream_id = ExtratorCC[3];  
128 -  
129 - return ((stream_id != 0xBC) && (stream_id != 0xBE) && (stream_id != 0xBF)  
130 - && (stream_id != 0xF0) && (stream_id != 0xF1) && (stream_id != 0xFF)  
131 - && (stream_id != 0xF2) && (stream_id != 0xF8));  
132 -}  
133 -  
134 -int ExtratorCC::verificaPESStreamIDSynchronized(unsigned char * ExtratorCC) {  
135 - int stream_id = ExtratorCC[3];  
136 -  
137 - return ((stream_id == 0xBD));  
138 -}  
139 -  
140 -/* Extrai o PTS (Presentation Time Stamp) do pacote PES e retorna um  
141 - * int64_t contendo os 33-bits extraídos */  
142 -int64_t ExtratorCC::extractPTS(unsigned char* PESPacket) {  
143 -  
144 - int64_t pts, c1, c2, c3 = 0;  
145 -  
146 - // leitura do 1º campo do PTS[32..30]  
147 - c1 = ((PESPacket[9] & 0x0E) >> 1); // 0x0E = 00001110  
148 - pts = c1;  
149 -  
150 - // leitura do 2º campo do PTS[29..15]  
151 - c2 = (((PESPacket[10] << 8) | (PESPacket[11])) >> 1); // >> 1 tira o marker_bit  
152 - pts = (((pts << 16) | (c2 << 1)) >> 1);  
153 -  
154 - // leitura do 3º campo do PTS[14..0]  
155 - c3 = (((PESPacket[12] << 8) | (PESPacket[13])) >> 1);  
156 - pts = (((pts << 16) | (c3 << 1)) >> 1);  
157 -  
158 - return pts;  
159 -  
160 -}  
161 -  
162 -/* Extrai o DTS 33-bits (Decoding Time Stamp) do pacote PES */  
163 -int64_t ExtratorCC::extractDTS(unsigned char* PESPacket) {  
164 -  
165 - int64_t dts, c1, c2, c3 = 0;  
166 -  
167 - // leitura do 1º campo do DTS[32..30]  
168 - c1 = ((PESPacket[14] & 0x0E) >> 1); // 0x0E = 00001110  
169 - dts = c1;  
170 -  
171 - // leitura do 2º campo do DTS[29..15]  
172 - c2 = (((PESPacket[15] << 8) | (PESPacket[16])) >> 1); // >> 1 tira o marker_bit  
173 - dts = (((dts << 16) | (c2 << 1)) >> 1);  
174 -  
175 - // leitura do 3º campo do DTS[14..0]  
176 - c3 = (((PESPacket[17] << 8) | (PESPacket[18])) >> 1);  
177 - dts = (((dts << 16) | (c3 << 1)) >> 1);  
178 -  
179 - return dts;  
180 -  
181 -}  
182 -  
183 -int ExtratorCC::packetPES(unsigned char *pacote) {  
184 - int N1, N2, PES_header_data_length, PES_packet_length, cont_stuffing_byte = 0, cont_PES_packet_data_byte = 0;  
185 - int pack_stuffing_length, system_header_start_code, PES_packet_data_byte;  
186 -  
187 - this->PTS = 0;  
188 - this->DTS = 0;  
189 -  
190 -  
191 - int inicioPESData = 0;  
192 -  
193 - if ((!verificaPESStartCode(pacote + inicioPESData)) ||  
194 - (!verificaPESStreamIDSynchronized(pacote + inicioPESData))) {  
195 -  
196 - return -1;  
197 - }  
198 -  
199 - PES_packet_data_byte = inicioPESData + 9;  
200 - PES_packet_length = (((pacote[inicioPESData + 4] & 0xFF) << 8) | (pacote[inicioPESData + 5] & 0xFF));  
201 - PES_header_data_length = pacote[inicioPESData + 8];  
202 - cont_PES_packet_data_byte = 3;  
203 -  
204 - /* PTS_DTS_flags = '10' */  
205 - if (contemPTS(pacote + inicioPESData) == 2) {  
206 - PTS = extractPTS(pacote);  
207 - PES_packet_data_byte += 5;  
208 - cont_stuffing_byte += 5;  
209 - }  
210 -  
211 - /* PTS_DTS_flags = '11' */  
212 - if (contemDTS(pacote + inicioPESData) == 3) {  
213 - PTS = extractPTS(pacote);  
214 - DTS = extractDTS(pacote);  
215 - PES_packet_data_byte += 10;  
216 - cont_stuffing_byte += 10;  
217 - }  
218 -  
219 - if (contemESCR(pacote + inicioPESData) == 1) {  
220 - PES_packet_data_byte += 6;  
221 - cont_stuffing_byte += 6;  
222 - }  
223 -  
224 - if (contemES_rate(pacote + inicioPESData) == 1) {  
225 - PES_packet_data_byte += 3;  
226 - cont_stuffing_byte += 3;  
227 - }  
228 -  
229 - if (contemDSM(pacote + inicioPESData) == 1) {  
230 - PES_packet_data_byte += 1;  
231 - cont_stuffing_byte += 1;  
232 - }  
233 -  
234 - if (contemAdditional(pacote + inicioPESData) == 1) {  
235 - PES_packet_data_byte += 1;  
236 - cont_stuffing_byte += 1;  
237 - }  
238 -  
239 - if (contemPES_CRC(pacote + inicioPESData) == 1) {  
240 - PES_packet_data_byte += 2;  
241 - cont_stuffing_byte += 2;  
242 - }  
243 -  
244 - if (contemPES_extension(pacote + inicioPESData) == 1) {  
245 - int flag = PES_packet_data_byte;  
246 - int PES_extension_field_length, PES_private_data_flag, pack_header_field_flag;  
247 - int program_packet_sequence_counter_flag, PSTD_buffer_flag, PES_extension_flag_2;  
248 - PES_packet_data_byte += 1;  
249 - cont_stuffing_byte += 1;  
250 -  
251 - PES_private_data_flag = ((pacote[flag] >> 7) & 0x01);  
252 - if (PES_private_data_flag == 1) {  
253 - PES_packet_data_byte += 16;  
254 - cont_stuffing_byte += 16;  
255 - }  
256 -  
257 - pack_header_field_flag = ((pacote[flag] >> 6) & 0x01);  
258 - if (pack_header_field_flag == 1) {  
259 - PES_packet_data_byte += 14;  
260 - cont_stuffing_byte += 15;  
261 - pack_stuffing_length = pacote[PES_packet_data_byte] & 0x07;  
262 - PES_packet_data_byte += 1;  
263 - for (int i = 0; i < pack_stuffing_length; i++) {  
264 - PES_packet_data_byte++;  
265 - cont_stuffing_byte++;  
266 - }  
267 - system_header_start_code = (pacote[PES_packet_data_byte] << 24) | (pacote[PES_packet_data_byte + 1] << 16) | (pacote[PES_packet_data_byte + 2] << 8) | (pacote[PES_packet_data_byte + 3]);  
268 - if (system_header_start_code == 0x000001BB) {  
269 - PES_packet_data_byte += 12;  
270 - cont_stuffing_byte += 12;  
271 - while (pacote[PES_packet_data_byte] == 0x01) {  
272 - PES_packet_data_byte += 3;  
273 - cont_stuffing_byte += 3;  
274 - }  
275 - }  
276 - }  
277 -  
278 - program_packet_sequence_counter_flag = ((pacote[flag] >> 5) & 0x01);  
279 - if (program_packet_sequence_counter_flag == 1) {  
280 - PES_packet_data_byte += 2;  
281 - cont_stuffing_byte += 2;  
282 - }  
283 -  
284 - PSTD_buffer_flag = ((pacote[flag] >> 4) & 0x01);  
285 - if (PSTD_buffer_flag == 1) {  
286 - PES_packet_data_byte += 2;  
287 - cont_stuffing_byte += 2;  
288 - }  
289 -  
290 - PES_extension_flag_2 = pacote[flag] & 0x01;  
291 - if (PES_extension_flag_2 == 1) {  
292 - PES_extension_field_length = pacote[PES_packet_data_byte] & 0x7F;  
293 - PES_packet_data_byte += 1;  
294 - cont_stuffing_byte += 1;  
295 - for (int i = 0; i < PES_extension_field_length; i++) {  
296 - PES_packet_data_byte++;  
297 - cont_stuffing_byte++;  
298 - }  
299 - }  
300 - }  
301 -  
302 - N1 = PES_header_data_length - cont_stuffing_byte;  
303 - cont_PES_packet_data_byte += cont_stuffing_byte + N1;  
304 - N2 = PES_packet_length - cont_PES_packet_data_byte;  
305 -  
306 - for (int i = 0; i < N1; i++) {  
307 - PES_packet_data_byte++;  
308 - }  
309 -  
310 - synchronizedPesData(PES_packet_data_byte, pacote);  
311 -  
312 - return 0;  
313 -}  
314 -  
315 -void ExtratorCC::synchronizedPesData(int PES_packet_data_byte, unsigned char *pacote) {  
316 - int PES_data_private_data_byte;  
317 - PES_packet_data_byte += 2;  
318 - PES_data_private_data_byte = pacote[PES_packet_data_byte] & 0x0F;  
319 - PES_packet_data_byte += 1;  
320 -  
321 - for (int i = 0; i < PES_data_private_data_byte; i++) {  
322 - PES_packet_data_byte++;  
323 - }  
324 -  
325 - dataGroup(PES_packet_data_byte, pacote);  
326 -}  
327 -  
328 -void ExtratorCC::dataGroup(int PES_packet_data_byte, unsigned char *pacote) {  
329 - int data_group_id, data_group_size;  
330 -  
331 - data_group_id = (pacote[PES_packet_data_byte] >> 2) & 0x3F;  
332 - PES_packet_data_byte += 3;  
333 - data_group_size = (pacote[PES_packet_data_byte] << 8) | (pacote[PES_packet_data_byte + 1]);  
334 - PES_packet_data_byte += 2;  
335 -  
336 - captionData(PES_packet_data_byte, pacote, data_group_id);  
337 -}  
338 -  
339 -void ExtratorCC::captionData(int PES_packet_data_byte, unsigned char *pacote, int data_group_id) {  
340 - int TDM, data_unit_loop_length;  
341 -  
342 - TDM = (pacote[PES_packet_data_byte] >> 6) & 0x03;  
343 - PES_packet_data_byte += 1;  
344 - if (TDM == 1 || TDM == 2) {  
345 - PES_packet_data_byte += 5;  
346 - }  
347 - if (data_group_id > 0) {  
348 - data_unit_loop_length = (pacote[PES_packet_data_byte] << 16) | (pacote[PES_packet_data_byte + 1] << 8) | (pacote[PES_packet_data_byte + 2]);  
349 - PES_packet_data_byte += 4;  
350 -  
351 - dataUnit(PES_packet_data_byte, pacote);  
352 - }  
353 -}  
354 -  
355 -void ExtratorCC::dataUnit(int PES_packet_data_byte, unsigned char *pacote) {  
356 - int data_unit_parameter, data_unit_size, controle_CSI_count, controle_CSI, flag;  
357 - unsigned char msg[300]; // TODO ver qual eh o valor maximo que isso pode atingir  
358 - int k = 0; // contador que vai percorrer msg  
359 -  
360 - //FILE * pFile;  
361 - //stringstream st;  
362 - //string resultadoo, finall;  
363 -  
364 - //pFile = fopen ("tempo2.txt" , "a+");  
365 - //if (pFile == NULL) perror ("Error opening file");  
366 -  
367 - data_unit_parameter = pacote[PES_packet_data_byte];  
368 - PES_packet_data_byte += 1;  
369 - data_unit_size = (pacote[PES_packet_data_byte] << 16) | (pacote[PES_packet_data_byte + 1] << 8) | (pacote[PES_packet_data_byte + 2]);  
370 - PES_packet_data_byte += 3;  
371 -  
372 - // printf("\nPACOTE: ");  
373 - // for (int f = 0; f < data_unit_size + 10; f++) {  
374 - // printf(" %x", pacote[f + PES_packet_data_byte]);  
375 - //}  
376 -  
377 - for (int i = 0; i < data_unit_size; i++) {  
378 -  
379 - if (pacote[PES_packet_data_byte + i] < 0x1C) {  
380 - } else  
381 - if (pacote[PES_packet_data_byte + i] == 0x1C) {  
382 - i += 2;  
383 - } else  
384 - if (pacote[PES_packet_data_byte + i] > 0x1C && pacote[PES_packet_data_byte + i] < 0x20) {  
385 - } else  
386 - if (pacote[PES_packet_data_byte + i] >= 0x80 && pacote[PES_packet_data_byte + i] <= 0x8A) {  
387 - } else  
388 - if (pacote[PES_packet_data_byte + i] == 0x8B) {  
389 - i += 1;  
390 - if (pacote[PES_packet_data_byte + i] == 0x60 || pacote[PES_packet_data_byte + i] == 0x41 ||  
391 - pacote[PES_packet_data_byte + i] == 0x44 || pacote[PES_packet_data_byte + i] == 0x45 ||  
392 - pacote[PES_packet_data_byte + i] == 0x6B || pacote[PES_packet_data_byte + i] == 0x64) {  
393 - }  
394 - } else  
395 - if (pacote[PES_packet_data_byte + i] == 0x90) {  
396 - if (pacote[PES_packet_data_byte + i + 1] == 0x20)  
397 - i += 2;  
398 - else  
399 - i += 1;  
400 - } else  
401 - if (pacote[PES_packet_data_byte + i] == 0x91) {  
402 - i += 1;  
403 - if (pacote[PES_packet_data_byte + i] == 0x40 || pacote[PES_packet_data_byte + i] == 0x47 ||  
404 - pacote[PES_packet_data_byte + i] == 0x4F) {  
405 - }  
406 - } else  
407 - if (pacote[PES_packet_data_byte + i] == 0x92) {  
408 - if (pacote[PES_packet_data_byte + i + 1] == 0x20)  
409 - i += 2;  
410 - else  
411 - i += 1;  
412 - } else  
413 - if (pacote[PES_packet_data_byte + i] == 0x93) {  
414 - i += 1;  
415 - if (pacote[PES_packet_data_byte + i] == 0x40 || pacote[PES_packet_data_byte + i] == 0x41 ||  
416 - pacote[PES_packet_data_byte + i] == 0x42) {  
417 - }  
418 - } else  
419 - if (pacote[PES_packet_data_byte + i] == 0x94) {  
420 - i += 1;  
421 - if (pacote[PES_packet_data_byte + i] == 0x40 || pacote[PES_packet_data_byte + i] == 0x44 ||  
422 - pacote[PES_packet_data_byte + i] == 0x45) {  
423 - }  
424 - } else  
425 - if (pacote[PES_packet_data_byte + i] == 0x97 || pacote[PES_packet_data_byte + i] == 0x98) {  
426 - i += 1;  
427 - } else  
428 - if (pacote[PES_packet_data_byte + i] == 0x99 || pacote[PES_packet_data_byte + i] == 0x9A) {  
429 - } else  
430 - if (pacote[PES_packet_data_byte + i] == 0x9B) {  
431 - controle_CSI_count = 0;  
432 - flag = 0;  
433 -  
434 - controle_CSI = PES_packet_data_byte + i;  
435 -  
436 - while (flag == 0) {  
437 - if (pacote[controle_CSI] == 0x53 || pacote[controle_CSI] == 0x54 || pacote[controle_CSI] == 0x6E ||  
438 - pacote[controle_CSI] == 0x61 || pacote[controle_CSI] == 0x56 || pacote[controle_CSI] == 0x5F ||  
439 - pacote[controle_CSI] == 0x57 || pacote[controle_CSI] == 0x5B || pacote[controle_CSI] == 0x5C ||  
440 - pacote[controle_CSI] == 0x58 || pacote[controle_CSI] == 0x59 || pacote[controle_CSI] == 0x42 ||  
441 - pacote[controle_CSI] == 0x5D || pacote[controle_CSI] == 0x5E || pacote[controle_CSI] == 0x62 ||  
442 - pacote[controle_CSI] == 0x65 || pacote[controle_CSI] == 0x63 || pacote[controle_CSI] == 0x64 ||  
443 - pacote[controle_CSI] == 0x66 || pacote[controle_CSI] == 0x68 || pacote[controle_CSI] == 0x69 ||  
444 - pacote[controle_CSI] == 0x6F) {  
445 -  
446 - flag = 1;  
447 - i += controle_CSI_count;  
448 - }  
449 -  
450 - controle_CSI++;  
451 - controle_CSI_count++;  
452 - }  
453 - } else {  
454 - if (pacote[PES_packet_data_byte + i] < 0x20)  
455 - msg[k++] = ' ';  
456 - else  
457 - msg[k++] = pacote[PES_packet_data_byte + i];  
458 - }  
459 - }  
460 -  
461 - msg[k] = '\0';  
462 - printf("\n****************************************************************************************");  
463 - printf("\nMensagem extraida do CC: ");  
464 - printf("\033[31m");  
465 - printf("_%s_", msg);  
466 - printf("\033[0m");  
467 - printf("\n\n");  
468 -  
469 - //printf("\nTEMPO DE EXTRAÇÃO: %lld\n\n", calculoFinal);  
470 - printf("PTS = %lld\n", PTS);  
471 - //printf("DTS = %lld\n", DTS);  
472 - notificaOuvintes(msg);  
473 -}  
474 -  
475 -void ExtratorCC::registraOuvinte(OuvinteCC * ouvinte) {  
476 - ouvintes->push_back(ouvinte);  
477 -}  
478 -  
479 -void ExtratorCC::removeOuvinte(OuvinteCC * ouvinte) {  
480 - ouvintes->remove(ouvinte);  
481 -}  
482 -  
483 -void ExtratorCC::notificaOuvintes(unsigned char * CC) {  
484 - for (list<OuvinteCC*>::iterator i = ouvintes->begin(); i != ouvintes->end(); i++) {  
485 - (*i)->notificaCC(CC, PTS);  
486 - }  
487 -}  
extratorCC/src/include/extratorCC.h
@@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
1 -/*  
2 - * File: PacketPES.h  
3 - * Author: felipe  
4 - *  
5 - * Created on 19 de Outubro de 2009, 14:49  
6 - */  
7 -  
8 -#ifndef _EXTRATORCC_H  
9 -#define _EXTRATORCC_H  
10 -  
11 -#include <cstring>  
12 -#include <string>  
13 -#include <list>  
14 -#include <pthread.h>  
15 -#include <iostream>  
16 -#include "ouvinteCC.h"  
17 -#include "stdint.h"  
18 -#include "ouvinteInput.h"  
19 -#include "demuxListener.h"  
20 -  
21 -using namespace std;  
22 -  
23 -class ExtratorCC : /*public OuvinteInput,*/ public DemuxListener {  
24 -public:  
25 - ExtratorCC();  
26 - ~ExtratorCC();  
27 - int packetPES(unsigned char *pacote);  
28 -  
29 - void synchronizedPesData(int PES_packet_data_byte, unsigned char *pacote);  
30 - void dataGroup(int PES_packet_data_byte, unsigned char *pacote);  
31 - void captionData(int PES_packet_data_byte, unsigned char *pacote, int data_group_id);  
32 - void dataUnit(int PES_packet_data_byte, unsigned char *pacote);  
33 -  
34 - int verificaPESStreamIDSynchronized(unsigned char * PESPacket);  
35 - int verificaPESStreamID(unsigned char * PESPacket);  
36 - int verificaPESStartCode(unsigned char * PESPacket);  
37 - int contemAF(unsigned char * pacote);  
38 - int contemDTS(unsigned char * PESPacket);  
39 - int contemESCR(unsigned char * PESPacket);  
40 - int contemPayloadData(unsigned char *pacote);  
41 - int contemPayloadStartIndicator(unsigned char *pacote);  
42 - int contemPCR(unsigned char * pacote);  
43 - int contemPTS(unsigned char * PESPacket);  
44 - int contemDSM(unsigned char * PESPacket);  
45 - int contemAdditional(unsigned char * PESPacket);  
46 - int contemES_rate(unsigned char * PESPacket);  
47 - int contemPES_CRC(unsigned char * PESPacket);  
48 - int contemPES_extension(unsigned char * PESPacket);  
49 - short unsigned GetTamanhoAF(unsigned char *pacote);  
50 -  
51 - int64_t extractPTS(unsigned char * PESPacket);  
52 - int64_t extractDTS(unsigned char * PESPacket);  
53 -  
54 - virtual void registraOuvinte(OuvinteCC * ouvinte);  
55 - virtual void removeOuvinte(OuvinteCC * ouvinte);  
56 - virtual void notificaOuvintes(unsigned char * CC);  
57 -  
58 - //virtual void chegouInput(unsigned char *pacote);  
59 -  
60 - virtual void notifySection(int PID, unsigned char* section, int sectionSize);  
61 - virtual void notifyErroCRC(int numErroCRC, int PID, int tableID, int tableIDX, unsigned char* section, int sectionSize);  
62 - virtual void notifyOldSection(int PID, int tableID, int tableIDX);  
63 -  
64 -private:  
65 - string ClosedCaption;  
66 - int64_t PTS, DTS;  
67 -  
68 - std::list<OuvinteCC*> * ouvintes;  
69 -  
70 - // Mutex para evitar mutiplas chamadas de notificadores  
71 - pthread_mutex_t *mutex;  
72 -};  
73 -  
74 -  
75 -#endif  
76 -  
extratorCC/src/include/ouvinteCC.h
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -/*  
2 - * File: ouvinteCC.h  
3 - * Author: felipe  
4 - *  
5 - * Created on 3 de Fevereiro de 2010, 19:44  
6 - */  
7 -  
8 -#ifndef _OUVINTECC_H  
9 -#define _OUVINTECC_H  
10 -  
11 -#include <string>  
12 -#include <stdint.h>  
13 -  
14 -using namespace std;  
15 -  
16 -class OuvinteCC {  
17 -public:  
18 - OuvinteCC();  
19 - virtual ~OuvinteCC();  
20 -  
21 - // inclusão do parâmetro "long int pts"  
22 - virtual void notificaCC(unsigned char * cc, int64_t pts) = 0;  
23 -private:  
24 -  
25 -};  
26 -  
27 -  
28 -#endif /* _OUVINTECC_H */  
29 -  
extratorCC/src/ouvinteCC.cpp
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -/*  
2 - * File: ouvinteCC.cpp  
3 - * Author: felipe  
4 - *  
5 - * Created on 3 de Fevereiro de 2010, 19:44  
6 - */  
7 -  
8 -#include "ouvinteCC.h"  
9 -  
10 -OuvinteCC::OuvinteCC() {  
11 -}  
12 -  
13 -OuvinteCC::~OuvinteCC() {  
14 -}  
15 -  
16 -  
servico/src/include/serviceWindowGenerationFromCC.h
@@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
1 -#ifndef SERVICEWINDOWGENERATIONFROMCC_H  
2 -#define SERVICEWINDOWGENERATIONFROMCC_H  
3 -  
4 -#include "serviceWindowGeneration.h"  
5 -#include "ouvinteCC.h"  
6 -#include <pthread.h>  
7 -#include "inputFile.h"  
8 -#include "extratorCC.h"  
9 -#include "demux.h"  
10 -#include "stdint.h"  
11 -#include <vector>  
12 -#include "jthread.h"  
13 -  
14 -using namespace std;  
15 -using namespace jthread;  
16 -  
17 -class ServiceWindowGenerationFromCC : public ServiceWindowGeneration, public OuvinteCC, public Thread {  
18 -private:  
19 - pthread_mutex_t *mutex_serviceCC;  
20 - //LEONARDO: comentado. //InputFile *inputfile;  
21 - ExtratorCC *extratorCC;  
22 - Demux *demux;  
23 - //char* path_input;  
24 - //int numero_legendas;  
25 -  
26 -  
27 -  
28 -public:  
29 -  
30 - ServiceWindowGenerationFromCC(  
31 - char* path, int position, int size, int transparency, int _serviceType);  
32 -  
33 - ~ServiceWindowGenerationFromCC();  
34 - //virtual void chegouCC(unsigned char * cc);  
35 - virtual void notificaCC(unsigned char * cc, int64_t pts);  
36 - void notificaTradutor(unsigned char * cc);  
37 - void notificaSincronizadorSemTradutor(unsigned char * cc, int64_t pts);  
38 - void initialize();  
39 - void setPathInput(char* path);  
40 - void Run();  
41 -  
42 -};  
43 -  
44 -#endif  
servico/src/serviceWindowGenerationFromCC.cpp
@@ -1,102 +0,0 @@ @@ -1,102 +0,0 @@
1 -#include "include/serviceWindowGenerationFromCC.h"  
2 -  
3 -using namespace std;  
4 -  
5 -ServiceWindowGenerationFromCC::ServiceWindowGenerationFromCC(  
6 - char* path, int position, int size, int transparency, int _serviceType) {  
7 - setPathInput(path);  
8 - numero_legendas = 0;  
9 - setPosition(position);  
10 - setSize(size);  
11 - setTransparency(transparency);  
12 - setServiceType(_serviceType);  
13 - //this->fisish = false;  
14 - //initialize();  
15 -}  
16 -  
17 -ServiceWindowGenerationFromCC::~ServiceWindowGenerationFromCC() {  
18 -  
19 -}  
20 -  
21 -void ServiceWindowGenerationFromCC::setPathInput(char* path) {  
22 - this->path_input = path;  
23 -}  
24 -  
25 -void ServiceWindowGenerationFromCC::notificaCC(unsigned char* cc, int64_t pts) {  
26 - cout << "1-Chegou LEGENDA no ServiceFromCC\n" << endl;  
27 - printf("Glosa: %s PTS: %lld\n", cc, pts);  
28 -  
29 - if (!strcmp((const char*) cc, "Homem supermercado falar nao vender.")) {  
30 - printf("\nIGUAL\n");  
31 - return;  
32 - } else {  
33 - //printf("\nDIFERENTE\n");  
34 - }  
35 -  
36 - numero_legendas++;  
37 - char op = this->getRunningOption();  
38 -  
39 - if (op == '3') {  
40 - notificaSincronizadorSemTradutor(cc, pts);  
41 - } else {  
42 - adicionaPTS(pts);  
43 - notificaTradutor(cc);  
44 - }  
45 -  
46 -}  
47 -  
48 -void ServiceWindowGenerationFromCC::notificaSincronizadorSemTradutor(unsigned char * cc, int64_t pts) {  
49 - char* pch = strtok((char*) cc, " ");  
50 - while (pch != NULL) {  
51 - string pch_string = (string) pch;  
52 - sincronizador->recebeglosa(pch_string, pts);  
53 - printf("%s\n", pch);  
54 - pch = strtok(NULL, " ");  
55 - }  
56 -}  
57 -  
58 -void ServiceWindowGenerationFromCC::notificaTradutor(unsigned char* cc) {  
59 -  
60 - const char* constchar = (const char*) cc;  
61 - char* cc_copy = new char[strlen(constchar)];  
62 - strcpy(cc_copy, constchar);  
63 - tradutor->traduz((unsigned char*) cc_copy);  
64 -  
65 -}  
66 -  
67 -void ServiceWindowGenerationFromCC::initialize() {  
68 -  
69 - inputfile = new InputFile(this->path_input);  
70 - extratorCC = new ExtratorCC();  
71 - monitor_pcr_base = new MonitorPCR();  
72 - demux = new Demux(278, (DemuxListener*) extratorCC);  
73 - inputfile->registraOuvinte(demux);  
74 - extratorCC->registraOuvinte(this);  
75 -  
76 - inputfile->registraOuvinte(monitor_pcr_base);  
77 -  
78 - ServiceWindowGeneration::initialize();  
79 -  
80 - inputfile->initialize();  
81 - this->Start();  
82 -}  
83 -  
84 -void ServiceWindowGenerationFromCC::Run() {  
85 -  
86 - while (true) {  
87 -  
88 - if (inputfile->isFinished()) {  
89 -  
90 - this->finish = true;  
91 -  
92 - if (getRunningOption() == '3') {  
93 - //printf("\n\n\nEncerrei\n\n\n");  
94 - sincronizador->stop();  
95 -  
96 - }  
97 -  
98 - }  
99 - sleep(5);  
100 - }  
101 -  
102 -}