recebeglosa.cpp
3.23 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
/*
* File: RecebeGlosa.cpp
* Author: felipe
*
* Created on 2 de Fevereiro de 2010, 09:43
*/
#include "recebeglosa.h"
#include "librasdatamessage.h"
#include "dprintf.h"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <tspacket.h>
namespace Codificador {
RecebeGlosa::RecebeGlosa(int pd, string rl, int vs, int dh, int dv, int dw, int df, int portOut, string ip) {
codificadorManager = CodificadorManager::getInstance();
codificadorManager->setPid(pd);
codificadorManager->setResolution(rl);
codificadorManager->setDictionaryVersion(vs);
codificadorManager->setDPH(dh);
codificadorManager->setDPV(dv);
codificadorManager->setDFW(dw);
codificadorManager->setDFH(df);
codificadorManager->setPortaOut(portOut);
codificadorManager->setIp(ip);
// Inicia o mutex
mutex = (pthread_mutex_t *) malloc( sizeof(pthread_mutex_t) );
pthread_mutex_init(mutex, NULL);
}
RecebeGlosa::~RecebeGlosa() {
if (mutex) {
int ret = pthread_mutex_destroy(mutex);
if (ret)
DDDPRINTF("erro destruindo mutex\n");
free(mutex);
}
}
void RecebeGlosa::codifica(vector<string> * glosas) {
// Mutex para evitar bug multiplas chamadas dos notificadores
pthread_mutex_lock(mutex);
unsigned char *nullpackets = new unsigned char [188];
vector<string>::iterator it;
unsigned char *data;
string valor;
int tamanho, numPackets, contNullPackets = 0;
//FILE *arq;
unsigned char *pes;
//arq = fopen ("../libras.ts" , "a");
printf("\nGlosa recebida para codificacao: ");
printf("\033[31m");
for (it = glosas->begin(); it < glosas->end(); it++) {
cout << *it << " ";
}
printf("\033[0m");
printf("\n");
for (it = glosas->begin(); it < glosas->end(); it++) {
valor = *it;
//Gambiarra
//if(gambis == 0) {
//valor.insert(0, "dl");
//gambis++;
//}
tamanho = valor.size();
data = (unsigned char*) valor.c_str();
//cout << "Glosa: " << data << endl;
if ((tamanho>2) && data[0] == 'd' && data[1] == 'l') {
for(int i = 2; i < tamanho; i++) {
pes = codificadorManager->generateSection(LibrasDataMessage::LIBRAS_DATA_TYPE,(unsigned char*) &data[i], 1, &numPackets);
codificadorManager->sendToOutput(pes, numPackets);
//fwrite(pes , 1 , 188 , arq );
}
} else {
pes = codificadorManager->generateSection(LibrasDataMessage::LIBRAS_DATA_TYPE, data, tamanho, &numPackets);
codificadorManager->sendToOutput(pes, numPackets);
//fwrite(pes , 1 , 188 , arq );
}
}
//printf("\nGerando Libras Data Message\n");
//create_ts_null_packet(nullpackets);
//while(contNullPackets < 30000) {
//contNullPackets++;
//fwrite(nullpackets , 1 , 188 , arq );
//}
//fclose(arq);
pthread_mutex_unlock(mutex);
}
}