Commit 094f6d33cfa8d545da1657f8073185724b89e5ca

Authored by wesnydy
1 parent abe25056
Exists in master and in 1 other branch devel

Implementada Conexão via socket(TCP) com o Unity

servico/src/include/serviceWindowGeneration.h
@@ -2,18 +2,23 @@ @@ -2,18 +2,23 @@
2 #define SERVICEWINDOWGENERATION_H 2 #define SERVICEWINDOWGENERATION_H
3 3
4 #include <vector> 4 #include <vector>
  5 +#include <iostream>
5 #include <stdint.h> 6 #include <stdint.h>
6 #include <string> 7 #include <string>
7 #include <locale> 8 #include <locale>
8 #include "jthread.h" 9 #include "jthread.h"
9 #include "dprintf.h" 10 #include "dprintf.h"
10 #include "Mixer.h" 11 #include "Mixer.h"
11 -#include "synchronizer.h"  
12 -#include "listenerSynchronizer.h" 12 +//#include "synchronizer.h"
  13 +//#include "listenerSynchronizer.h"
13 #include "listenerTradutor.h" 14 #include "listenerTradutor.h"
14 #include "tradutorPortGlosa.h" 15 #include "tradutorPortGlosa.h"
15 #include "serviceException.h" 16 #include "serviceException.h"
16 #include <json/json.h> 17 #include <json/json.h>
  18 +#include <lavidlib/net/StreamSocket.h>
  19 +#include <lavidlib/net/InetAddress.h>
  20 +#include <lavidlib/net/UnknownHostException.h>
  21 +#include <lavidlib/net/SocketException.h>
17 #include <lavidlib/base/RuntimeException.h> 22 #include <lavidlib/base/RuntimeException.h>
18 23
19 #define DEVELOPER "devel" 24 #define DEVELOPER "devel"
@@ -27,18 +32,23 @@ @@ -27,18 +32,23 @@
27 #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" 32 #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/"
28 #define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" 33 #define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json"
29 #define MAX_SIZE_PATH 256 34 #define MAX_SIZE_PATH 256
  35 +#define END_NOTIFICATION "FINALIZE"
  36 +#define HOST "127.0.0.1"
  37 +#define PORTNO 12345
30 38
31 using namespace Json; 39 using namespace Json;
32 using namespace Tradutor; 40 using namespace Tradutor;
33 using namespace jthread; 41 using namespace jthread;
34 using namespace std; 42 using namespace std;
  43 +using namespace lavidlib;
35 44
36 class ServiceWindowGeneration { 45 class ServiceWindowGeneration {
37 46
38 protected: 47 protected:
39 TradutorPortGlosa* tradutor; 48 TradutorPortGlosa* tradutor;
40 - Synchronizer* sincronizador; 49 + //Synchronizer* sincronizador;
41 Mixer* mixer; 50 Mixer* mixer;
  51 + StreamSocket* core_socket;
42 52
43 Value root; 53 Value root;
44 Reader reader; 54 Reader reader;
@@ -66,7 +76,11 @@ protected: @@ -66,7 +76,11 @@ protected:
66 virtual void setSizeOfSubtitles(int sub_size) = 0; 76 virtual void setSizeOfSubtitles(int sub_size) = 0;
67 virtual void setPathContents() = 0; 77 virtual void setPathContents() = 0;
68 virtual void setPathLibras() = 0; 78 virtual void setPathLibras() = 0;
69 - virtual void setBackground() = 0; 79 + //virtual void setBackground() = 0;
  80 +
  81 + virtual void connectToUnity() = 0;
  82 + virtual void sendGlosa(string glosa) = 0;
  83 + virtual void waitVideoGeneration() = 0;
70 84
71 //virtual void transcodeVideoToWebm(); 85 //virtual void transcodeVideoToWebm();
72 virtual void transcodeVideoToMp4() = 0; 86 virtual void transcodeVideoToMp4() = 0;
servico/src/include/serviceWindowGenerationFromRec.h
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 #define SERVICE_TYPE_REC 2 8 #define SERVICE_TYPE_REC 2
9 #define SERVICE_TYPE_REC_ONLY_AUDIO 5 9 #define SERVICE_TYPE_REC_ONLY_AUDIO 5
10 10
11 -class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerSynchronizer, public Thread { 11 +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public Thread {
12 12
13 private: 13 private:
14 Recognize* rec; 14 Recognize* rec;
@@ -17,7 +17,11 @@ private: @@ -17,7 +17,11 @@ private:
17 void setSizeOfSubtitles(int sub_size); 17 void setSizeOfSubtitles(int sub_size);
18 void setPathContents(); 18 void setPathContents();
19 void setPathLibras(); 19 void setPathLibras();
20 - void setBackground(); 20 + //void setBackground();
  21 +
  22 + void connectToUnity();
  23 + void sendGlosa(string glosa);
  24 + void waitVideoGeneration();
21 25
22 void transcodeVideoToMp4(); 26 void transcodeVideoToMp4();
23 void createThumbnail(); 27 void createThumbnail();
@@ -32,7 +36,7 @@ public: @@ -32,7 +36,7 @@ public:
32 void notifyTextRecognized(unsigned char* text, int64_t pts); 36 void notifyTextRecognized(unsigned char* text, int64_t pts);
33 void notifyTranslation(vector<string>* glosas); 37 void notifyTranslation(vector<string>* glosas);
34 void notifyTranslator(unsigned char* text); 38 void notifyTranslator(unsigned char* text);
35 - void notifyEndOfSynchronization(); 39 + //void notifyEndOfSynchronization();
36 void notifyEnd(int sentences_size); 40 void notifyEnd(int sentences_size);
37 41
38 void initialize(); 42 void initialize();
servico/src/include/serviceWindowGenerationFromSRT.h
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 #define SERVICE_TYPE_SRT 1 8 #define SERVICE_TYPE_SRT 1
9 #define SERVICE_TYPE_SRT_ONLY 4 9 #define SERVICE_TYPE_SRT_ONLY 4
10 10
11 -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerSynchronizer, public Thread { 11 +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public Thread {
12 12
13 private: 13 private:
14 ExtratorFactory* extrator_factory; 14 ExtratorFactory* extrator_factory;
@@ -20,7 +20,11 @@ private: @@ -20,7 +20,11 @@ private:
20 void setSizeOfSubtitles(int sub_size); 20 void setSizeOfSubtitles(int sub_size);
21 void setPathContents(); 21 void setPathContents();
22 void setPathLibras(); 22 void setPathLibras();
23 - void setBackground(); 23 + //void setBackground();
  24 +
  25 + void connectToUnity();
  26 + void sendGlosa(string glosa);
  27 + void waitVideoGeneration();
24 28
25 void transcodeVideoToMp4(); 29 void transcodeVideoToMp4();
26 void createThumbnail(); 30 void createThumbnail();
@@ -36,7 +40,7 @@ public: @@ -36,7 +40,7 @@ public:
36 void notifySubtitle(unsigned char* subtitle, int64_t pts); 40 void notifySubtitle(unsigned char* subtitle, int64_t pts);
37 void notifyTranslation(vector<string>* glosas); 41 void notifyTranslation(vector<string>* glosas);
38 void notifyTranslator(unsigned char* text); 42 void notifyTranslator(unsigned char* text);
39 - void notifyEndOfSynchronization(); 43 + //void notifyEndOfSynchronization();
40 void notifyEnd(int sub_size); 44 void notifyEnd(int sub_size);
41 45
42 void initialize(); 46 void initialize();
servico/src/include/serviceWindowGenerationFromText.h
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 7
8 #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto 8 #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto
9 9
10 -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerSynchronizer, public Thread { 10 +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public Thread {
11 11
12 private: 12 private:
13 ExtratorFactory* extrator_factory; 13 ExtratorFactory* extrator_factory;
@@ -16,7 +16,11 @@ private: @@ -16,7 +16,11 @@ private:
16 void setSizeOfSubtitles(int sub_size); 16 void setSizeOfSubtitles(int sub_size);
17 void setPathContents(); 17 void setPathContents();
18 void setPathLibras(); 18 void setPathLibras();
19 - void setBackground(); 19 + //void setBackground();
  20 +
  21 + void connectToUnity();
  22 + void sendGlosa(string glosa);
  23 + void waitVideoGeneration();
20 24
21 void transcodeVideoToMp4(); 25 void transcodeVideoToMp4();
22 bool isRunning(); 26 bool isRunning();
@@ -27,7 +31,7 @@ public: @@ -27,7 +31,7 @@ public:
27 void notifyLine(unsigned char* line); 31 void notifyLine(unsigned char* line);
28 void notifyTranslation(vector<string>* glosas); 32 void notifyTranslation(vector<string>* glosas);
29 void notifyTranslator(unsigned char* text); 33 void notifyTranslator(unsigned char* text);
30 - void notifyEndOfSynchronization(); 34 + //void notifyEndOfSynchronization();
31 void notifyEnd(int line_size); 35 void notifyEnd(int line_size);
32 36
33 void initialize(); 37 void initialize();
servico/src/serviceWindowGenerationFromRec.cpp
@@ -50,7 +50,7 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ @@ -50,7 +50,7 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){
50 free(vetor_pts); 50 free(vetor_pts);
51 if (tradutor) delete tradutor; 51 if (tradutor) delete tradutor;
52 if (rec) delete rec; 52 if (rec) delete rec;
53 - if (sincronizador) delete sincronizador; 53 + //if (sincronizador) delete sincronizador;
54 if (mixer) delete mixer; 54 if (mixer) delete mixer;
55 DDDPRINTF("Service Rec finished!\n"); 55 DDDPRINTF("Service Rec finished!\n");
56 } 56 }
@@ -87,29 +87,32 @@ void ServiceWindowGenerationFromRec::setPathLibras(){ @@ -87,29 +87,32 @@ void ServiceWindowGenerationFromRec::setPathLibras(){
87 this->path_libras = final_path; 87 this->path_libras = final_path;
88 } 88 }
89 89
90 -void ServiceWindowGenerationFromRec::setBackground(){  
91 - if(this->transparency == 0) { //pega dicionario com BackGround opaco  
92 - char* dicPath;  
93 - dicPath = getenv("DIC_LIBRAS");  
94 - if(dicPath != NULL)  
95 - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
96 - else  
97 - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
98 -  
99 - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente  
100 - char* dicTPath;  
101 - dicTPath = getenv("DICTRANSP_LIBRAS");  
102 - if(dicTPath != NULL)  
103 - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
104 - else  
105 - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
106 - }  
107 -} 90 +// void ServiceWindowGenerationFromRec::setBackground(){
  91 +// if(this->transparency == 0) { //pega dicionario com BackGround opaco
  92 +// char* dicPath;
  93 +// dicPath = getenv("DIC_LIBRAS");
  94 +// if(dicPath != NULL)
  95 +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  96 +// else
  97 +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  98 +
  99 +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente
  100 +// char* dicTPath;
  101 +// dicTPath = getenv("DICTRANSP_LIBRAS");
  102 +// if(dicTPath != NULL)
  103 +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  104 +// else
  105 +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  106 +// }
  107 +// }
108 108
109 void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ 109 void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){
110 numero_legendas = sub_size; 110 numero_legendas = sub_size;
111 - if (legendas_enviadas >= numero_legendas)  
112 - sincronizador->stop(); 111 + if (legendas_enviadas >= numero_legendas){
  112 + sendGlosa(END_NOTIFICATION);
  113 + waitVideoGeneration();
  114 + //sincronizador->stop();
  115 + }
113 } 116 }
114 117
115 void ServiceWindowGenerationFromRec::addPTS(int64_t pts){ 118 void ServiceWindowGenerationFromRec::addPTS(int64_t pts){
@@ -126,18 +129,18 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i @@ -126,18 +129,18 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i
126 notifyTranslator(text); 129 notifyTranslator(text);
127 } 130 }
128 131
129 -//Quando o sincronizador termina, ele invoca esse método para avisar  
130 -void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() {  
131 - if (this->service_type == SERVICE_TYPE_REC) {  
132 - mixer = new Mixer();  
133 - mixer->initialize(this->path_input, this->path_libras,this->position,this->size,  
134 - this->transparency, this->user_id, this->path_uploads, this->path_contents);  
135 - createThumbnail();  
136 - }else{  
137 - transcodeVideoToMp4();  
138 - }  
139 - this->running = false;  
140 -} 132 +// //Quando o sincronizador termina, ele invoca esse método para avisar
  133 +// void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() {
  134 +// if (this->service_type == SERVICE_TYPE_REC) {
  135 +// mixer = new Mixer();
  136 +// mixer->initialize(this->path_input, this->path_libras,this->position,this->size,
  137 +// this->transparency, this->user_id, this->path_uploads, this->path_contents);
  138 +// createThumbnail();
  139 +// }else{
  140 +// transcodeVideoToMp4();
  141 +// }
  142 +// this->running = false;
  143 +// }
141 144
142 void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) { 145 void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) {
143 for (int i = 0; i < glosas->size(); i++) { 146 for (int i = 0; i < glosas->size(); i++) {
@@ -146,15 +149,18 @@ void ServiceWindowGenerationFromRec::notifyTranslation(vector&lt;string&gt; * glosas) @@ -146,15 +149,18 @@ void ServiceWindowGenerationFromRec::notifyTranslation(vector&lt;string&gt; * glosas)
146 for (int k = 0; k < glosas->at(i).length(); k++){ 149 for (int k = 0; k < glosas->at(i).length(); k++){
147 glosa_lower += std::tolower(glosas->at(i).at(k), loc); 150 glosa_lower += std::tolower(glosas->at(i).at(k), loc);
148 } 151 }
149 - int64_t pts_notificado = vetor_pts->front();  
150 - sincronizador->recebeglosa(glosa_lower, pts_notificado); 152 + //int64_t pts_notificado = vetor_pts->front();
  153 + //sincronizador->recebeglosa(glosa_lower, pts_notificado);
  154 + sendGlosa(glosa_lower);
151 } 155 }
  156 +
152 vetor_pts->erase(vetor_pts->begin()); 157 vetor_pts->erase(vetor_pts->begin());
153 - legendas_enviadas++; 158 + legendas_enviadas++;
154 } 159 }
155 160
156 void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ 161 void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){
157 DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); 162 DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size);
  163 + cout << "chamou: " << sentences_size << endl;
158 setSizeOfSubtitles(sentences_size); 164 setSizeOfSubtitles(sentences_size);
159 } 165 }
160 166
@@ -196,12 +202,14 @@ void ServiceWindowGenerationFromRec::initialize(){ @@ -196,12 +202,14 @@ void ServiceWindowGenerationFromRec::initialize(){
196 tradutor->addListener(this); 202 tradutor->addListener(this);
197 } 203 }
198 204
199 - setBackground(); 205 + connectToUnity();
200 206
201 - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro  
202 - sincronizador->setPCRBase(pcr_base);  
203 - sincronizador->addListener(this);  
204 - sincronizador->Start(); 207 + // setBackground();
  208 +
  209 + // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro
  210 + // sincronizador->setPCRBase(pcr_base);
  211 + // sincronizador->addListener(this);
  212 + // sincronizador->Start();
205 213
206 try{ 214 try{
207 rec->initialize(); 215 rec->initialize();
@@ -211,6 +219,46 @@ void ServiceWindowGenerationFromRec::initialize(){ @@ -211,6 +219,46 @@ void ServiceWindowGenerationFromRec::initialize(){
211 this->Start(); 219 this->Start();
212 } 220 }
213 221
  222 +void ServiceWindowGenerationFromRec::sendGlosa(string glosa) {
  223 + char* glosa_buffer = new char[strlen(glosa.c_str())+1];
  224 + strcpy(glosa_buffer, glosa.c_str());
  225 + int tamanho = strlen(glosa_buffer)+1;
  226 + //cout << "Enviando glosa: " << glosa_buffer << endl;
  227 + core_socket->write(glosa_buffer, tamanho);
  228 + delete [] glosa_buffer;
  229 +
  230 + char* ok_core = new char[4];
  231 + core_socket->read(ok_core, 4); //aguarda o unity confirmar o recebimento da glosa
  232 + //cout << "Recebi: " << ok_core << endl;
  233 + delete [] ok_core;
  234 +}
  235 +
  236 +void ServiceWindowGenerationFromRec::connectToUnity() {
  237 + core_socket = new StreamSocket();
  238 + try{
  239 + static InetAddress* addr = InetAddress::createByName(HOST);
  240 + core_socket->connect(addr, PORTNO);
  241 + }catch(UnknownHostException ex){
  242 + throw ServiceException(ex.getMessage());
  243 + }catch(SocketException ex){
  244 + throw ServiceException(ex.getMessage());
  245 + }
  246 +}
  247 +
  248 +void ServiceWindowGenerationFromRec::waitVideoGeneration() {
  249 + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1];
  250 + try{
  251 + do{
  252 + core_socket->read(endgeneration, sizeof(endgeneration));
  253 + //usleep(500000);
  254 + }while(strcmp(endgeneration, END_NOTIFICATION) != 0);
  255 + core_socket->close();
  256 + this->running = false;
  257 + }catch(IOException ex){
  258 + throw ServiceException(ex.getMessage());
  259 + }
  260 +}
  261 +
214 void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){ 262 void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){
215 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); 263 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n");
216 string command = "ffmpeg -i "; 264 string command = "ffmpeg -i ";
servico/src/serviceWindowGenerationFromSRT.cpp
@@ -53,7 +53,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { @@ -53,7 +53,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {
53 free(vetor_pts); 53 free(vetor_pts);
54 if (mixer) delete mixer; 54 if (mixer) delete mixer;
55 if (tradutor) delete tradutor; 55 if (tradutor) delete tradutor;
56 - if (sincronizador) delete sincronizador; 56 + //if (sincronizador) delete sincronizador;
57 if (extratorSRT)delete extratorSRT; 57 if (extratorSRT)delete extratorSRT;
58 if (extrator_factory) delete extrator_factory; 58 if (extrator_factory) delete extrator_factory;
59 DDDPRINTF("Service SRT finalized!\n"); 59 DDDPRINTF("Service SRT finalized!\n");
@@ -89,29 +89,32 @@ void ServiceWindowGenerationFromSRT::setPathLibras() { @@ -89,29 +89,32 @@ void ServiceWindowGenerationFromSRT::setPathLibras() {
89 this->path_libras = final_path; 89 this->path_libras = final_path;
90 } 90 }
91 91
92 -void ServiceWindowGenerationFromSRT::setBackground() {  
93 - if(this->transparency == 0) { //pega dicionario com BackGround opaco  
94 - char* dicPath;  
95 - dicPath = getenv("DIC_LIBRAS");  
96 - if(dicPath != NULL)  
97 - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
98 - else  
99 - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
100 -  
101 - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente  
102 - char* dicTPath;  
103 - dicTPath = getenv("DICTRANSP_LIBRAS");  
104 - if(dicTPath != NULL)  
105 - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
106 - else  
107 - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
108 - }  
109 -} 92 +// void ServiceWindowGenerationFromSRT::setBackground() {
  93 +// if(this->transparency == 0) { //pega dicionario com BackGround opaco
  94 +// char* dicPath;
  95 +// dicPath = getenv("DIC_LIBRAS");
  96 +// if(dicPath != NULL)
  97 +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  98 +// else
  99 +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  100 +
  101 +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente
  102 +// char* dicTPath;
  103 +// dicTPath = getenv("DICTRANSP_LIBRAS");
  104 +// if(dicTPath != NULL)
  105 +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  106 +// else
  107 +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  108 +// }
  109 +// }
110 110
111 void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { 111 void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) {
112 numero_legendas = sub_size; 112 numero_legendas = sub_size;
113 - if (legendas_enviadas >= numero_legendas)  
114 - sincronizador->stop(); 113 + if (legendas_enviadas >= numero_legendas){
  114 + sendGlosa(END_NOTIFICATION);
  115 + waitVideoGeneration();
  116 + //sincronizador->stop();
  117 + }
115 } 118 }
116 119
117 void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){ 120 void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){
@@ -131,17 +134,17 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int @@ -131,17 +134,17 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int
131 notifyTranslator(subtitle); 134 notifyTranslator(subtitle);
132 } 135 }
133 136
134 -void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() {  
135 - if (this->service_type == SERVICE_TYPE_SRT) {  
136 - mixer = new Mixer();  
137 - mixer->initialize(this->path_input, this->path_libras,this->position,this->size,  
138 - this->transparency, this->user_id, this->path_uploads, this->path_contents);  
139 - createThumbnail();  
140 - }else{  
141 - transcodeVideoToMp4();  
142 - }  
143 - this->running = false;  
144 -} 137 +// void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() {
  138 +// if (this->service_type == SERVICE_TYPE_SRT) {
  139 +// mixer = new Mixer();
  140 +// mixer->initialize(this->path_input, this->path_libras,this->position,this->size,
  141 +// this->transparency, this->user_id, this->path_uploads, this->path_contents);
  142 +// createThumbnail();
  143 +// }else{
  144 +// transcodeVideoToMp4();
  145 +// }
  146 +// this->running = false;
  147 +// }
145 148
146 void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) { 149 void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) {
147 for (int i = 0; i < glosas->size(); i++) { 150 for (int i = 0; i < glosas->size(); i++) {
@@ -150,11 +153,13 @@ void ServiceWindowGenerationFromSRT::notifyTranslation(vector&lt;string&gt; * glosas) @@ -150,11 +153,13 @@ void ServiceWindowGenerationFromSRT::notifyTranslation(vector&lt;string&gt; * glosas)
150 for (int k = 0; k < glosas->at(i).length(); k++){ 153 for (int k = 0; k < glosas->at(i).length(); k++){
151 glosa_lower += std::tolower(glosas->at(i).at(k), loc); 154 glosa_lower += std::tolower(glosas->at(i).at(k), loc);
152 } 155 }
153 - int64_t pts_notificado = vetor_pts->front();  
154 - sincronizador->recebeglosa(glosa_lower, pts_notificado); 156 + sendGlosa(glosa_lower);
  157 + //int64_t pts_notificado = vetor_pts->front();
  158 + //sincronizador->recebeglosa(glosa_lower, pts_notificado);
155 } 159 }
  160 +
156 vetor_pts->erase(vetor_pts->begin()); 161 vetor_pts->erase(vetor_pts->begin());
157 - legendas_enviadas++; 162 + legendas_enviadas++;
158 } 163 }
159 164
160 void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { 165 void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) {
@@ -203,15 +208,17 @@ void ServiceWindowGenerationFromSRT::initialize() { @@ -203,15 +208,17 @@ void ServiceWindowGenerationFromSRT::initialize() {
203 tradutor->addListener(this); 208 tradutor->addListener(this);
204 } 209 }
205 210
206 - setBackground(); 211 + //setBackground();
207 212
208 if (service_type != SERVICE_TYPE_SRT) { 213 if (service_type != SERVICE_TYPE_SRT) {
209 uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro 214 uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro
210 - sincronizador->setPCRBase(pcr_base); 215 + //sincronizador->setPCRBase(pcr_base);
211 } 216 }
212 217
213 - sincronizador->addListener(this);  
214 - sincronizador->Start(); 218 + connectToUnity();
  219 +
  220 + // sincronizador->addListener(this);
  221 + // sincronizador->Start();
215 222
216 try{ 223 try{
217 extratorSRT->initialize(); 224 extratorSRT->initialize();
@@ -221,6 +228,46 @@ void ServiceWindowGenerationFromSRT::initialize() { @@ -221,6 +228,46 @@ void ServiceWindowGenerationFromSRT::initialize() {
221 this->Start(); 228 this->Start();
222 } 229 }
223 230
  231 +void ServiceWindowGenerationFromSRT::sendGlosa(string glosa) {
  232 + char* glosa_buffer = new char[strlen(glosa.c_str())+1];
  233 + strcpy(glosa_buffer, glosa.c_str());
  234 + int tamanho = strlen(glosa_buffer)+1;
  235 + //cout << "Enviando glosa: " << glosa_buffer << endl;
  236 + core_socket->write(glosa_buffer, tamanho);
  237 + delete [] glosa_buffer;
  238 +
  239 + char* ok_core = new char[3];
  240 + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa
  241 + //cout << "Recebi: " << ok_core << endl;
  242 + delete [] ok_core;
  243 +}
  244 +
  245 +void ServiceWindowGenerationFromSRT::connectToUnity() {
  246 + core_socket = new StreamSocket();
  247 + try{
  248 + static InetAddress* addr = InetAddress::createByName(HOST);
  249 + core_socket->connect(addr, PORTNO);
  250 + }catch(UnknownHostException ex){
  251 + throw ServiceException(ex.getMessage());
  252 + }catch(SocketException ex){
  253 + throw ServiceException(ex.getMessage());
  254 + }
  255 +}
  256 +
  257 +void ServiceWindowGenerationFromSRT::waitVideoGeneration() {
  258 + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1];
  259 + try{
  260 + do{
  261 + core_socket->read(endgeneration, sizeof(endgeneration));
  262 + //usleep(500000);
  263 + }while(strcmp(endgeneration, END_NOTIFICATION) != 0);
  264 + core_socket->close();
  265 + this->running = false;
  266 + }catch(IOException ex){
  267 + throw ServiceException(ex.getMessage());
  268 + }
  269 +}
  270 +
224 void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){ 271 void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){
225 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); 272 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n");
226 string command = "ffmpeg -i "; 273 string command = "ffmpeg -i ";
servico/src/serviceWindowGenerationFromText.cpp
@@ -25,7 +25,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, @@ -25,7 +25,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile,
25 ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { 25 ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
26 free(vetor_pts); 26 free(vetor_pts);
27 if (tradutor) delete tradutor; 27 if (tradutor) delete tradutor;
28 - if (sincronizador) delete sincronizador; 28 + //if (sincronizador) delete sincronizador;
29 if (extratorTXT)delete extratorTXT; 29 if (extratorTXT)delete extratorTXT;
30 if (extrator_factory) delete extrator_factory; 30 if (extrator_factory) delete extrator_factory;
31 DDDPRINTF("Service Text finalized!\n"); 31 DDDPRINTF("Service Text finalized!\n");
@@ -59,30 +59,33 @@ void ServiceWindowGenerationFromText::setPathLibras() { @@ -59,30 +59,33 @@ void ServiceWindowGenerationFromText::setPathLibras() {
59 this->path_libras = final_path; 59 this->path_libras = final_path;
60 } 60 }
61 61
62 -void ServiceWindowGenerationFromText::setBackground() {  
63 - if(this->transparency == 0) { //pega dicionario com BackGround opaco  
64 - char* dicPath;  
65 - dicPath = getenv("DIC_LIBRAS");  
66 - if(dicPath != NULL)  
67 - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
68 - else  
69 - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
70 -  
71 - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente  
72 - char* dicTPath;  
73 - dicTPath = getenv("DICTRANSP_LIBRAS");  
74 - if(dicTPath != NULL)  
75 - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
76 - else{  
77 - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);  
78 - }  
79 - }  
80 -} 62 +// void ServiceWindowGenerationFromText::setBackground() {
  63 +// if(this->transparency == 0) { //pega dicionario com BackGround opaco
  64 +// char* dicPath;
  65 +// dicPath = getenv("DIC_LIBRAS");
  66 +// if(dicPath != NULL)
  67 +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  68 +// else
  69 +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  70 +
  71 +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente
  72 +// char* dicTPath;
  73 +// dicTPath = getenv("DICTRANSP_LIBRAS");
  74 +// if(dicTPath != NULL)
  75 +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  76 +// else{
  77 +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency);
  78 +// }
  79 +// }
  80 +// }
81 81
82 void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { 82 void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) {
83 numero_legendas = sub_size; 83 numero_legendas = sub_size;
84 - if (legendas_enviadas >= numero_legendas)  
85 - sincronizador->stop(); 84 + if (legendas_enviadas >= numero_legendas){
  85 + sendGlosa(END_NOTIFICATION);
  86 + waitVideoGeneration();
  87 + //sincronizador->stop();
  88 + }
86 } 89 }
87 90
88 void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { 91 void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) {
@@ -93,10 +96,10 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { @@ -93,10 +96,10 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) {
93 notifyTranslator(line); 96 notifyTranslator(line);
94 } 97 }
95 98
96 -void ServiceWindowGenerationFromText::notifyEndOfSynchronization() {  
97 - transcodeVideoToMp4();  
98 - this->running = false;  
99 -} 99 +// void ServiceWindowGenerationFromText::notifyEndOfSynchronization() {
  100 +// transcodeVideoToMp4();
  101 +// this->running = false;
  102 +// }
100 103
101 void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) { 104 void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) {
102 for (int i = 0; i < glosas->size(); i++) { 105 for (int i = 0; i < glosas->size(); i++) {
@@ -105,13 +108,12 @@ void ServiceWindowGenerationFromText::notifyTranslation(vector&lt;string&gt; * glosas) @@ -105,13 +108,12 @@ void ServiceWindowGenerationFromText::notifyTranslation(vector&lt;string&gt; * glosas)
105 for (int k = 0; k < glosas->at(i).length(); k++){ 108 for (int k = 0; k < glosas->at(i).length(); k++){
106 glosa_lower += std::tolower(glosas->at(i).at(k), loc); 109 glosa_lower += std::tolower(glosas->at(i).at(k), loc);
107 } 110 }
108 - sincronizador->recebeglosa(glosa_lower, 1000); 111 + sendGlosa(glosa_lower);
  112 + //sincronizador->recebeglosa(glosa_lower, 1000);
109 } 113 }
110 - sincronizador->stop();  
111 - legendas_enviadas++; 114 + legendas_enviadas++;
112 } 115 }
113 116
114 -  
115 void ServiceWindowGenerationFromText::notifyEnd(int line_size) { 117 void ServiceWindowGenerationFromText::notifyEnd(int line_size) {
116 DPRINTF("Service Text recebeu: %d linhas.\n", line_size); 118 DPRINTF("Service Text recebeu: %d linhas.\n", line_size);
117 setSizeOfSubtitles(line_size); 119 setSizeOfSubtitles(line_size);
@@ -135,12 +137,14 @@ void ServiceWindowGenerationFromText::initialize() { @@ -135,12 +137,14 @@ void ServiceWindowGenerationFromText::initialize() {
135 137
136 tradutor->addListener(this); 138 tradutor->addListener(this);
137 139
138 - setBackground(); 140 + connectToUnity();
  141 +
  142 + //setBackground();
139 143
140 - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro  
141 - sincronizador->setPCRBase(pcr_base);  
142 - sincronizador->addListener(this);  
143 - sincronizador->Start(); 144 + // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro
  145 + // sincronizador->setPCRBase(pcr_base);
  146 + // sincronizador->addListener(this);
  147 + // sincronizador->Start();
144 148
145 try{ 149 try{
146 extratorTXT->initialize(); 150 extratorTXT->initialize();
@@ -150,6 +154,46 @@ void ServiceWindowGenerationFromText::initialize() { @@ -150,6 +154,46 @@ void ServiceWindowGenerationFromText::initialize() {
150 this->Start(); 154 this->Start();
151 } 155 }
152 156
  157 +void ServiceWindowGenerationFromText::sendGlosa(string glosa) {
  158 + char* glosa_buffer = new char[strlen(glosa.c_str())+1];
  159 + strcpy(glosa_buffer, glosa.c_str());
  160 + int tamanho = strlen(glosa_buffer)+1;
  161 + //cout << "Enviando glosa: " << glosa_buffer << endl;
  162 + core_socket->write(glosa_buffer, tamanho);
  163 + delete [] glosa_buffer;
  164 +
  165 + char* ok_core = new char[3];
  166 + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa
  167 + //cout << "Recebi: " << ok_core << endl;
  168 + delete [] ok_core;
  169 +}
  170 +
  171 +void ServiceWindowGenerationFromText::connectToUnity() {
  172 + core_socket = new StreamSocket();
  173 + try{
  174 + static InetAddress* addr = InetAddress::createByName(HOST);
  175 + core_socket->connect(addr, PORTNO);
  176 + }catch(UnknownHostException ex){
  177 + throw ServiceException(ex.getMessage());
  178 + }catch(SocketException ex){
  179 + throw ServiceException(ex.getMessage());
  180 + }
  181 +}
  182 +
  183 +void ServiceWindowGenerationFromText::waitVideoGeneration() {
  184 + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1];
  185 + try{
  186 + do{
  187 + core_socket->read(endgeneration, sizeof(endgeneration));
  188 + //usleep(500000);
  189 + }while(strcmp(endgeneration, END_NOTIFICATION) != 0);
  190 + core_socket->close();
  191 + this->running = false;
  192 + }catch(IOException ex){
  193 + throw ServiceException(ex.getMessage());
  194 + }
  195 +}
  196 +
153 void ServiceWindowGenerationFromText::transcodeVideoToMp4(){ 197 void ServiceWindowGenerationFromText::transcodeVideoToMp4(){
154 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); 198 DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n");
155 string command = "ffmpeg -i "; 199 string command = "ffmpeg -i ";