diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index 53b4d63..3565d24 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -2,18 +2,23 @@ #define SERVICEWINDOWGENERATION_H #include +#include #include #include #include #include "jthread.h" #include "dprintf.h" #include "Mixer.h" -#include "synchronizer.h" -#include "listenerSynchronizer.h" +//#include "synchronizer.h" +//#include "listenerSynchronizer.h" #include "listenerTradutor.h" #include "tradutorPortGlosa.h" #include "serviceException.h" #include +#include +#include +#include +#include #include #define DEVELOPER "devel" @@ -27,18 +32,23 @@ #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" #define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" #define MAX_SIZE_PATH 256 +#define END_NOTIFICATION "FINALIZE" +#define HOST "127.0.0.1" +#define PORTNO 12345 using namespace Json; using namespace Tradutor; using namespace jthread; using namespace std; +using namespace lavidlib; class ServiceWindowGeneration { protected: TradutorPortGlosa* tradutor; - Synchronizer* sincronizador; + //Synchronizer* sincronizador; Mixer* mixer; + StreamSocket* core_socket; Value root; Reader reader; @@ -66,7 +76,11 @@ protected: virtual void setSizeOfSubtitles(int sub_size) = 0; virtual void setPathContents() = 0; virtual void setPathLibras() = 0; - virtual void setBackground() = 0; + //virtual void setBackground() = 0; + + virtual void connectToUnity() = 0; + virtual void sendGlosa(string glosa) = 0; + virtual void waitVideoGeneration() = 0; //virtual void transcodeVideoToWebm(); virtual void transcodeVideoToMp4() = 0; diff --git a/servico/src/include/serviceWindowGenerationFromRec.h b/servico/src/include/serviceWindowGenerationFromRec.h index 25fbbe3..2d132da 100644 --- a/servico/src/include/serviceWindowGenerationFromRec.h +++ b/servico/src/include/serviceWindowGenerationFromRec.h @@ -8,7 +8,7 @@ #define SERVICE_TYPE_REC 2 #define SERVICE_TYPE_REC_ONLY_AUDIO 5 -class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerSynchronizer, public Thread { +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public Thread { private: Recognize* rec; @@ -17,7 +17,11 @@ private: void setSizeOfSubtitles(int sub_size); void setPathContents(); void setPathLibras(); - void setBackground(); + //void setBackground(); + + void connectToUnity(); + void sendGlosa(string glosa); + void waitVideoGeneration(); void transcodeVideoToMp4(); void createThumbnail(); @@ -32,7 +36,7 @@ public: void notifyTextRecognized(unsigned char* text, int64_t pts); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); - void notifyEndOfSynchronization(); + //void notifyEndOfSynchronization(); void notifyEnd(int sentences_size); void initialize(); diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index 7e76f63..d602125 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -8,7 +8,7 @@ #define SERVICE_TYPE_SRT 1 #define SERVICE_TYPE_SRT_ONLY 4 -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerSynchronizer, public Thread { +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public Thread { private: ExtratorFactory* extrator_factory; @@ -20,7 +20,11 @@ private: void setSizeOfSubtitles(int sub_size); void setPathContents(); void setPathLibras(); - void setBackground(); + //void setBackground(); + + void connectToUnity(); + void sendGlosa(string glosa); + void waitVideoGeneration(); void transcodeVideoToMp4(); void createThumbnail(); @@ -36,7 +40,7 @@ public: void notifySubtitle(unsigned char* subtitle, int64_t pts); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); - void notifyEndOfSynchronization(); + //void notifyEndOfSynchronization(); void notifyEnd(int sub_size); void initialize(); diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index 2fec3f9..9b40b56 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -7,7 +7,7 @@ #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerSynchronizer, public Thread { +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public Thread { private: ExtratorFactory* extrator_factory; @@ -16,7 +16,11 @@ private: void setSizeOfSubtitles(int sub_size); void setPathContents(); void setPathLibras(); - void setBackground(); + //void setBackground(); + + void connectToUnity(); + void sendGlosa(string glosa); + void waitVideoGeneration(); void transcodeVideoToMp4(); bool isRunning(); @@ -27,7 +31,7 @@ public: void notifyLine(unsigned char* line); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); - void notifyEndOfSynchronization(); + //void notifyEndOfSynchronization(); void notifyEnd(int line_size); void initialize(); diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp index 8dada47..95d4d85 100644 --- a/servico/src/serviceWindowGenerationFromRec.cpp +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -50,7 +50,7 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ free(vetor_pts); if (tradutor) delete tradutor; if (rec) delete rec; - if (sincronizador) delete sincronizador; + //if (sincronizador) delete sincronizador; if (mixer) delete mixer; DDDPRINTF("Service Rec finished!\n"); } @@ -87,29 +87,32 @@ void ServiceWindowGenerationFromRec::setPathLibras(){ this->path_libras = final_path; } -void ServiceWindowGenerationFromRec::setBackground(){ - if(this->transparency == 0) { //pega dicionario com BackGround opaco - char* dicPath; - dicPath = getenv("DIC_LIBRAS"); - if(dicPath != NULL) - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente - char* dicTPath; - dicTPath = getenv("DICTRANSP_LIBRAS"); - if(dicTPath != NULL) - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - } -} +// void ServiceWindowGenerationFromRec::setBackground(){ +// if(this->transparency == 0) { //pega dicionario com BackGround opaco +// char* dicPath; +// dicPath = getenv("DIC_LIBRAS"); +// if(dicPath != NULL) +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); + +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente +// char* dicTPath; +// dicTPath = getenv("DICTRANSP_LIBRAS"); +// if(dicTPath != NULL) +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// } +// } void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ numero_legendas = sub_size; - if (legendas_enviadas >= numero_legendas) - sincronizador->stop(); + if (legendas_enviadas >= numero_legendas){ + sendGlosa(END_NOTIFICATION); + waitVideoGeneration(); + //sincronizador->stop(); + } } void ServiceWindowGenerationFromRec::addPTS(int64_t pts){ @@ -126,18 +129,18 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i notifyTranslator(text); } -//Quando o sincronizador termina, ele invoca esse método para avisar -void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() { - if (this->service_type == SERVICE_TYPE_REC) { - mixer = new Mixer(); - mixer->initialize(this->path_input, this->path_libras,this->position,this->size, - this->transparency, this->user_id, this->path_uploads, this->path_contents); - createThumbnail(); - }else{ - transcodeVideoToMp4(); - } - this->running = false; -} +// //Quando o sincronizador termina, ele invoca esse método para avisar +// void ServiceWindowGenerationFromRec::notifyEndOfSynchronization() { +// if (this->service_type == SERVICE_TYPE_REC) { +// mixer = new Mixer(); +// mixer->initialize(this->path_input, this->path_libras,this->position,this->size, +// this->transparency, this->user_id, this->path_uploads, this->path_contents); +// createThumbnail(); +// }else{ +// transcodeVideoToMp4(); +// } +// this->running = false; +// } void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) { for (int i = 0; i < glosas->size(); i++) { @@ -146,15 +149,18 @@ void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - int64_t pts_notificado = vetor_pts->front(); - sincronizador->recebeglosa(glosa_lower, pts_notificado); + //int64_t pts_notificado = vetor_pts->front(); + //sincronizador->recebeglosa(glosa_lower, pts_notificado); + sendGlosa(glosa_lower); } + vetor_pts->erase(vetor_pts->begin()); - legendas_enviadas++; + legendas_enviadas++; } void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); + cout << "chamou: " << sentences_size << endl; setSizeOfSubtitles(sentences_size); } @@ -196,12 +202,14 @@ void ServiceWindowGenerationFromRec::initialize(){ tradutor->addListener(this); } - setBackground(); + connectToUnity(); - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro - sincronizador->setPCRBase(pcr_base); - sincronizador->addListener(this); - sincronizador->Start(); + // setBackground(); + + // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro + // sincronizador->setPCRBase(pcr_base); + // sincronizador->addListener(this); + // sincronizador->Start(); try{ rec->initialize(); @@ -211,6 +219,46 @@ void ServiceWindowGenerationFromRec::initialize(){ this->Start(); } +void ServiceWindowGenerationFromRec::sendGlosa(string glosa) { + char* glosa_buffer = new char[strlen(glosa.c_str())+1]; + strcpy(glosa_buffer, glosa.c_str()); + int tamanho = strlen(glosa_buffer)+1; + //cout << "Enviando glosa: " << glosa_buffer << endl; + core_socket->write(glosa_buffer, tamanho); + delete [] glosa_buffer; + + char* ok_core = new char[4]; + core_socket->read(ok_core, 4); //aguarda o unity confirmar o recebimento da glosa + //cout << "Recebi: " << ok_core << endl; + delete [] ok_core; +} + +void ServiceWindowGenerationFromRec::connectToUnity() { + core_socket = new StreamSocket(); + try{ + static InetAddress* addr = InetAddress::createByName(HOST); + core_socket->connect(addr, PORTNO); + }catch(UnknownHostException ex){ + throw ServiceException(ex.getMessage()); + }catch(SocketException ex){ + throw ServiceException(ex.getMessage()); + } +} + +void ServiceWindowGenerationFromRec::waitVideoGeneration() { + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; + try{ + do{ + core_socket->read(endgeneration, sizeof(endgeneration)); + //usleep(500000); + }while(strcmp(endgeneration, END_NOTIFICATION) != 0); + core_socket->close(); + this->running = false; + }catch(IOException ex){ + throw ServiceException(ex.getMessage()); + } +} + void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){ DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); string command = "ffmpeg -i "; diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 6e940e0..7a11d2b 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -53,7 +53,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { free(vetor_pts); if (mixer) delete mixer; if (tradutor) delete tradutor; - if (sincronizador) delete sincronizador; + //if (sincronizador) delete sincronizador; if (extratorSRT)delete extratorSRT; if (extrator_factory) delete extrator_factory; DDDPRINTF("Service SRT finalized!\n"); @@ -89,29 +89,32 @@ void ServiceWindowGenerationFromSRT::setPathLibras() { this->path_libras = final_path; } -void ServiceWindowGenerationFromSRT::setBackground() { - if(this->transparency == 0) { //pega dicionario com BackGround opaco - char* dicPath; - dicPath = getenv("DIC_LIBRAS"); - if(dicPath != NULL) - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente - char* dicTPath; - dicTPath = getenv("DICTRANSP_LIBRAS"); - if(dicTPath != NULL) - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - } -} +// void ServiceWindowGenerationFromSRT::setBackground() { +// if(this->transparency == 0) { //pega dicionario com BackGround opaco +// char* dicPath; +// dicPath = getenv("DIC_LIBRAS"); +// if(dicPath != NULL) +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); + +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente +// char* dicTPath; +// dicTPath = getenv("DICTRANSP_LIBRAS"); +// if(dicTPath != NULL) +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// } +// } void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { numero_legendas = sub_size; - if (legendas_enviadas >= numero_legendas) - sincronizador->stop(); + if (legendas_enviadas >= numero_legendas){ + sendGlosa(END_NOTIFICATION); + waitVideoGeneration(); + //sincronizador->stop(); + } } void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){ @@ -131,17 +134,17 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int notifyTranslator(subtitle); } -void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() { - if (this->service_type == SERVICE_TYPE_SRT) { - mixer = new Mixer(); - mixer->initialize(this->path_input, this->path_libras,this->position,this->size, - this->transparency, this->user_id, this->path_uploads, this->path_contents); - createThumbnail(); - }else{ - transcodeVideoToMp4(); - } - this->running = false; -} +// void ServiceWindowGenerationFromSRT::notifyEndOfSynchronization() { +// if (this->service_type == SERVICE_TYPE_SRT) { +// mixer = new Mixer(); +// mixer->initialize(this->path_input, this->path_libras,this->position,this->size, +// this->transparency, this->user_id, this->path_uploads, this->path_contents); +// createThumbnail(); +// }else{ +// transcodeVideoToMp4(); +// } +// this->running = false; +// } void ServiceWindowGenerationFromSRT::notifyTranslation(vector * glosas) { for (int i = 0; i < glosas->size(); i++) { @@ -150,11 +153,13 @@ void ServiceWindowGenerationFromSRT::notifyTranslation(vector * glosas) for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - int64_t pts_notificado = vetor_pts->front(); - sincronizador->recebeglosa(glosa_lower, pts_notificado); + sendGlosa(glosa_lower); + //int64_t pts_notificado = vetor_pts->front(); + //sincronizador->recebeglosa(glosa_lower, pts_notificado); } + vetor_pts->erase(vetor_pts->begin()); - legendas_enviadas++; + legendas_enviadas++; } void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { @@ -203,15 +208,17 @@ void ServiceWindowGenerationFromSRT::initialize() { tradutor->addListener(this); } - setBackground(); + //setBackground(); if (service_type != SERVICE_TYPE_SRT) { uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro - sincronizador->setPCRBase(pcr_base); + //sincronizador->setPCRBase(pcr_base); } - sincronizador->addListener(this); - sincronizador->Start(); + connectToUnity(); + + // sincronizador->addListener(this); + // sincronizador->Start(); try{ extratorSRT->initialize(); @@ -221,6 +228,46 @@ void ServiceWindowGenerationFromSRT::initialize() { this->Start(); } +void ServiceWindowGenerationFromSRT::sendGlosa(string glosa) { + char* glosa_buffer = new char[strlen(glosa.c_str())+1]; + strcpy(glosa_buffer, glosa.c_str()); + int tamanho = strlen(glosa_buffer)+1; + //cout << "Enviando glosa: " << glosa_buffer << endl; + core_socket->write(glosa_buffer, tamanho); + delete [] glosa_buffer; + + char* ok_core = new char[3]; + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa + //cout << "Recebi: " << ok_core << endl; + delete [] ok_core; +} + +void ServiceWindowGenerationFromSRT::connectToUnity() { + core_socket = new StreamSocket(); + try{ + static InetAddress* addr = InetAddress::createByName(HOST); + core_socket->connect(addr, PORTNO); + }catch(UnknownHostException ex){ + throw ServiceException(ex.getMessage()); + }catch(SocketException ex){ + throw ServiceException(ex.getMessage()); + } +} + +void ServiceWindowGenerationFromSRT::waitVideoGeneration() { + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; + try{ + do{ + core_socket->read(endgeneration, sizeof(endgeneration)); + //usleep(500000); + }while(strcmp(endgeneration, END_NOTIFICATION) != 0); + core_socket->close(); + this->running = false; + }catch(IOException ex){ + throw ServiceException(ex.getMessage()); + } +} + void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){ DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); string command = "ffmpeg -i "; diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index c636a68..6dff586 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -25,7 +25,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { free(vetor_pts); if (tradutor) delete tradutor; - if (sincronizador) delete sincronizador; + //if (sincronizador) delete sincronizador; if (extratorTXT)delete extratorTXT; if (extrator_factory) delete extrator_factory; DDDPRINTF("Service Text finalized!\n"); @@ -59,30 +59,33 @@ void ServiceWindowGenerationFromText::setPathLibras() { this->path_libras = final_path; } -void ServiceWindowGenerationFromText::setBackground() { - if(this->transparency == 0) { //pega dicionario com BackGround opaco - char* dicPath; - dicPath = getenv("DIC_LIBRAS"); - if(dicPath != NULL) - sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - - } else if(this->transparency == 1) { //pega dicionario com BackGround transparente - char* dicTPath; - dicTPath = getenv("DICTRANSP_LIBRAS"); - if(dicTPath != NULL) - sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - else{ - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); - } - } -} +// void ServiceWindowGenerationFromText::setBackground() { +// if(this->transparency == 0) { //pega dicionario com BackGround opaco +// char* dicPath; +// dicPath = getenv("DIC_LIBRAS"); +// if(dicPath != NULL) +// sincronizador = new Synchronizer(dicPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else +// sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); + +// } else if(this->transparency == 1) { //pega dicionario com BackGround transparente +// char* dicTPath; +// dicTPath = getenv("DICTRANSP_LIBRAS"); +// if(dicTPath != NULL) +// sincronizador = new Synchronizer(dicTPath, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// else{ +// sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); +// } +// } +// } void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { numero_legendas = sub_size; - if (legendas_enviadas >= numero_legendas) - sincronizador->stop(); + if (legendas_enviadas >= numero_legendas){ + sendGlosa(END_NOTIFICATION); + waitVideoGeneration(); + //sincronizador->stop(); + } } void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { @@ -93,10 +96,10 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { notifyTranslator(line); } -void ServiceWindowGenerationFromText::notifyEndOfSynchronization() { - transcodeVideoToMp4(); - this->running = false; -} +// void ServiceWindowGenerationFromText::notifyEndOfSynchronization() { +// transcodeVideoToMp4(); +// this->running = false; +// } void ServiceWindowGenerationFromText::notifyTranslation(vector * glosas) { for (int i = 0; i < glosas->size(); i++) { @@ -105,13 +108,12 @@ void ServiceWindowGenerationFromText::notifyTranslation(vector * glosas) for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - sincronizador->recebeglosa(glosa_lower, 1000); + sendGlosa(glosa_lower); + //sincronizador->recebeglosa(glosa_lower, 1000); } - sincronizador->stop(); - legendas_enviadas++; + legendas_enviadas++; } - void ServiceWindowGenerationFromText::notifyEnd(int line_size) { DPRINTF("Service Text recebeu: %d linhas.\n", line_size); setSizeOfSubtitles(line_size); @@ -135,12 +137,14 @@ void ServiceWindowGenerationFromText::initialize() { tradutor->addListener(this); - setBackground(); + connectToUnity(); + + //setBackground(); - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro - sincronizador->setPCRBase(pcr_base); - sincronizador->addListener(this); - sincronizador->Start(); + // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro + // sincronizador->setPCRBase(pcr_base); + // sincronizador->addListener(this); + // sincronizador->Start(); try{ extratorTXT->initialize(); @@ -150,6 +154,46 @@ void ServiceWindowGenerationFromText::initialize() { this->Start(); } +void ServiceWindowGenerationFromText::sendGlosa(string glosa) { + char* glosa_buffer = new char[strlen(glosa.c_str())+1]; + strcpy(glosa_buffer, glosa.c_str()); + int tamanho = strlen(glosa_buffer)+1; + //cout << "Enviando glosa: " << glosa_buffer << endl; + core_socket->write(glosa_buffer, tamanho); + delete [] glosa_buffer; + + char* ok_core = new char[3]; + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa + //cout << "Recebi: " << ok_core << endl; + delete [] ok_core; +} + +void ServiceWindowGenerationFromText::connectToUnity() { + core_socket = new StreamSocket(); + try{ + static InetAddress* addr = InetAddress::createByName(HOST); + core_socket->connect(addr, PORTNO); + }catch(UnknownHostException ex){ + throw ServiceException(ex.getMessage()); + }catch(SocketException ex){ + throw ServiceException(ex.getMessage()); + } +} + +void ServiceWindowGenerationFromText::waitVideoGeneration() { + char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; + try{ + do{ + core_socket->read(endgeneration, sizeof(endgeneration)); + //usleep(500000); + }while(strcmp(endgeneration, END_NOTIFICATION) != 0); + core_socket->close(); + this->running = false; + }catch(IOException ex){ + throw ServiceException(ex.getMessage()); + } +} + void ServiceWindowGenerationFromText::transcodeVideoToMp4(){ DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); string command = "ffmpeg -i "; -- libgit2 0.21.2