codificadormanager.cpp
4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <iostream>
#include "codificadormanager.h"
#include "librasdatamessage.h"
#include "librascontrolmessage.h"
#include "librassection.h"
#include "tspacket.h"
#include "jdatagramsocket.h"
using namespace std;
using namespace jsocket;
namespace Codificador {
CodificadorManager* CodificadorManager::ccmanager = 0;
CodificadorManager::CodificadorManager() {
cc = 0;
packets = new unsigned char[70000];
//pid = 0x63;
version_number = 1;
}
CodificadorManager* CodificadorManager::getInstance() {
if (ccmanager == NULL)
ccmanager = new CodificadorManager();
return ccmanager;
}
CodificadorManager::~CodificadorManager() {
printf("Deletando ccManager1... \n");
if (packets) {
delete []packets;
packets = NULL;
}
printf("Deletando ccManager2... \n");
ccmanager == NULL;
}
int CodificadorManager::getPid() {
return this->pid;
}
void CodificadorManager::setPid(int pid) {
this->pid = pid;
}
void CodificadorManager::setResolution(string resolution) {
this->resolution = resolution;
}
void CodificadorManager::setDictionaryVersion(int dictionaryversion) {
this->dictionaryversion = dictionaryversion;
}
void CodificadorManager::setDPH(int dph) {
this->dph = dph;
}
void CodificadorManager::setDPV(int dpv) {
this->dpv = dpv;
}
void CodificadorManager::setDFW(int dfw) {
this->dfw = dfw;
}
void CodificadorManager::setDFH(int dfh) {
this->dfh = dfh;
}
void CodificadorManager::setPortaOut(int porta) {
this->portaOut = porta;
}
void CodificadorManager::setIp(string ip) {
this->ip = ip;
}
unsigned char *CodificadorManager::generateSection(unsigned int type, unsigned char *msg, int n, int *numPackets) {
unsigned short len;
unsigned char *pesBytes;
LibrasSection *librSection = NULL;
if (type == LibrasDataMessage::LIBRAS_DATA_TYPE) {
if(version_number == 32)
version_number = 1;
LibrasDataMessage *librData = new LibrasDataMessage((unsigned char *) msg, (unsigned short) n);
librSection = new LibrasSection(librData, type, version_number);
pesBytes = librSection->generateBytes(&len);
*numPackets = generateTsPacket(packets, pid, pesBytes);
delete librData;
} else if (type == LibrasControlMessage::LIBRAS_MGM_TYPE) {
if(version_number == 32)
version_number = 1;
LibrasControlMessage *librctrMess = new LibrasControlMessage();
librctrMess->setResolution(resolution);
librctrMess->setDictionaryVersion((unsigned char)dictionaryversion);
librctrMess->setDPH((unsigned short)dph);
librctrMess->setDPV((unsigned short)dpv);
librctrMess->setDFH((unsigned short)dfh);
librctrMess->setDFW((unsigned short)dfw);
librSection = new LibrasSection(librctrMess, type, version_number);
pesBytes = librSection->generateBytes(&len);
/*printf("PES Packet... \n");
for (int j = 0; j < len; j++){
printf("%x ", pesBytes[j]);
}
printf("\n");*/
*numPackets = generateTsPacket(packets, pid, pesBytes);
delete librctrMess;
} else {
return NULL;
}
version_number++;
delete []pesBytes;
delete librSection;
return packets;
}
int CodificadorManager::sendToOutput(unsigned char *pes, int numPackets) {
//ip do MUX
unsigned char *pack;
pack = (unsigned char*) malloc (188);
create_ts_null_packet(pack);
for (int i = 1; i < 7; i++) {
memcpy(pes + (i * 188), pack, 188);
}
DatagramSocket * w_socket = NULL;
try {
w_socket = new DatagramSocket(ip, portaOut);
} catch (...) {
printf("\nERRO ao abrir o socket.\n");
return 1;
}
//for (int i = 0; i < numPackets; i++)
//w_socket->Send((char *) pes + (i * 188), 188);
w_socket->Send((char *) pes, 1316);
w_socket->Close();
delete w_socket;
return 0;
}
}