From b886dc375aa8a6924a2f257bcfdfa896d9704d99 Mon Sep 17 00:00:00 2001 From: Erickson Silva Date: Sat, 18 Jul 2015 14:43:57 -0300 Subject: [PATCH] Adiciona serviço 6 (rec without mixing), corrige alguns serviços e simplifica o TradutorPortGlosa. --- main.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- recognize/src/recognize.cpp | 4 +++- servico/src/include/serviceWindowGenerationFromRec.h | 9 +++++---- servico/src/include/serviceWindowGenerationFromSRT.h | 5 +++-- servico/src/include/serviceWindowGenerationFromText.h | 5 +++-- servico/src/serviceWindowGenerationFromRec.cpp | 26 +++++++------------------- servico/src/serviceWindowGenerationFromSRT.cpp | 52 ++++++++++++++++++++++++++-------------------------- servico/src/serviceWindowGenerationFromText.cpp | 38 ++++++++++++++++++++------------------ tradutor/src/include/listenerTradutor.h | 2 +- tradutor/src/include/tradutorPortGlosa.h | 5 ++--- tradutor/src/tradutorPortGlosa.cpp | 48 +++++++----------------------------------------- 11 files changed, 128 insertions(+), 155 deletions(-) diff --git a/main.cpp b/main.cpp index 524b013..65481cf 100644 --- a/main.cpp +++ b/main.cpp @@ -25,12 +25,15 @@ using namespace std; void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); -void serviceOnlySRT(char* service, char* path_file, char* transparency, char* username, char* client_type); +void serviceREC(char* service, char* path_video, char* position, char* size, char* transparency, char* id, char* client_type); + +void serviceOnlySRT(char* service, char* path_file, char* sublanguage, char* transparency, char* id, char* client_type); +void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type); +void serviceRECWithoutMixing(char* service, char* path_video, char* transparency, char* id, char* client_type); +void serviceText(char* service, char* path_text, char* sublanguage, char* transparency, char* id, char* client_type); + //void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username, char* rate); -void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); //void serviceOnlyAudio(char* path_audio, char* transparency, char* username, char* rate); -void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type); -void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type); void help(); void serviceHelp(int service); @@ -63,19 +66,19 @@ int main(int argc, char* argv[]) { } break; case 2: - if(argc <= 8){ + if(argc <= 7){ serviceHelp(2); hasInvalid(); }else{ - serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); + serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); } break; case 3: - if(argc <= 5){ + if(argc <= 6){ serviceHelp(3); hasInvalid(); }else{ - serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); + serviceText(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); } break; case 4: @@ -83,7 +86,7 @@ int main(int argc, char* argv[]) { serviceHelp(4); hasInvalid(); }else{ - serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); + serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); } break; case 5: @@ -94,6 +97,14 @@ int main(int argc, char* argv[]) { serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); } break; + case 6: + if(argc <= 5){ + serviceHelp(6); + hasInvalid(); + }else{ + serviceRECWithoutMixing(argv[1], argv[2], argv[3], argv[4], argv[5]); + } + break; default: cout << "\nFAIL VLibras: Serviço inválido! Tente --help" << endl; hasInvalid(); @@ -142,14 +153,14 @@ void serviceSRT(char* service, char* path_video, char* path_srt, char* sublangua delete service_srt; } -void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, +void serviceREC(char* service, char* path_video, char* position, char* size, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromRec * service_rec; - service_rec = new ServiceWindowGenerationFromRec(path_video, (int) atoi(sublanguage), - (int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); + service_rec = new ServiceWindowGenerationFromRec(path_video, (int) atoi(position), + (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_rec->initialize(); @@ -164,12 +175,21 @@ void serviceREC(char* service, char* path_video, char* sublanguage, char* positi delete service_rec; } -void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ +void serviceRECWithoutMixing(char* service, char* path_video, char* transparency, char* id, char* client_type){ + + char* position = new char[1]; + char* size = new char[1]; + strcpy(position, "0"); + strcpy(size, "0"); + serviceREC(service, path_video, position, size, transparency, id, client_type); +} + +void serviceText(char* service, char* path_text, char* sublanguage, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromText *service_text; - service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(transparency), id, client_type); + service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(sublanguage), (int) atoi(transparency), id, client_type); try{ service_text->initialize(); @@ -185,12 +205,12 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c delete service_text; } -void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id, char* client_type){ +void serviceOnlySRT(char* service, char* path_file, char* sublanguage, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromSRT * service_srt; - service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, client_type, (int) atoi(service)); + service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(sublanguage), (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_srt->initialize(); }catch(ServiceException ex){ @@ -203,27 +223,15 @@ void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id usleep(100000); //100ms } delete service_srt; - } void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){ - setPathContents(client_type); - - ServiceWindowGenerationFromRec * service_rec; - service_rec = new ServiceWindowGenerationFromRec(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service)); - - try{ - service_rec->initialize(); - }catch(ServiceException ex){ - fail(ex.getMessage()); - hasFailed(); - return; - } - while(!service_rec->isFinished()){ - sleep(2); - } - delete service_rec; + char* position = new char[1]; + char* size = new char[1]; + strcpy(position, "0"); + strcpy(size, "0"); + serviceREC(service, path_audio, position, size, transparency, id, client_type); } /*void serviceREC(char* path_video, char* sublanguage, @@ -307,25 +315,29 @@ void serviceHelp(int service){ switch(service){ case 1: cout << "\nService Type: Video with Subtitles\n" - << "./vlibras INPUT_VIDEO INPUT_SRT LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " + << "./vlibras 1 INPUT_VIDEO INPUT_SRT LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " << "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; break; case 2: cout << "\nService Type: Video Recognize\n" - << "./vlibras INPUT_VIDEO LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " + << "./vlibras 2 INPUT_VIDEO POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " << "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; break; case 3: cout << "\nService Type: Text\n" - << "./vlibras INPUT_TEXT_FILE TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + << "./vlibras 3 INPUT_TEXT_FILE LANGUAGE(1: Portuguese, 2:Glosa) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; break; case 4: cout << "\nService Type: Subtitles only\n" - << "./vlibras INPUT_SRT TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + << "./vlibras 4 INPUT_SRT LANGUAGE(1: Portuguese, 2:Glosa) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; break; case 5: cout << "\nService Type: Audio Recognize\n" - << "./vlibras INPUT_AUDIO TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + << "./vlibras 5 INPUT_AUDIO TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + case 6: + cout << "\nService Type: Video Recognize Without Mixing\n" + << "./vlibras 6 INPUT_VIDEO TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; break; } } @@ -341,6 +353,7 @@ void help() { << "3 Text - requires INPUT_TEXT_FILE\n" << "4 Subtitles only (SRT) - requires INPUT_SRT\n" << "5 Audio Recognize - requires INPUT_AUDIO\n" + << "6 Video Recognize without mixing - requires INPUT_VIDEO\n" << "\nSERVICES PARAMETERS:\n" << "Video with subtitles:\n" << " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" diff --git a/recognize/src/recognize.cpp b/recognize/src/recognize.cpp index 8d55fda..4448583 100644 --- a/recognize/src/recognize.cpp +++ b/recognize/src/recognize.cpp @@ -369,7 +369,9 @@ void Recognize::notifyListeners(char* text, int64_t pts) { //cout << "NOTIFY: " << text << endl; for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ - (*it)->notifyTextRecognized((unsigned char*) text, calcula_pts(pts)); + //(*it)->notifyTextRecognized((unsigned char*) text, calcula_pts(pts)); + (*it)->notifyTextRecognized((unsigned char*) text, pts); + } } diff --git a/servico/src/include/serviceWindowGenerationFromRec.h b/servico/src/include/serviceWindowGenerationFromRec.h index a59c38a..bde76a3 100644 --- a/servico/src/include/serviceWindowGenerationFromRec.h +++ b/servico/src/include/serviceWindowGenerationFromRec.h @@ -7,6 +7,7 @@ #define SERVICE_TYPE_REC 2 #define SERVICE_TYPE_REC_ONLY_AUDIO 5 +#define SERVICE_TYPE_REC_UNMIXED 6 class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerRenderer, public Thread { @@ -19,15 +20,15 @@ private: void setPathContents(); bool isRunning(); public: - ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, - int transparency, char* id, int serviceType, char* rate); - ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int pos, int size, + ServiceWindowGenerationFromRec(char* pathVideo, int position, int size, + int transparency, char* id, char* client, int serviceType, char* rate); + ServiceWindowGenerationFromRec(char* pathVideo, int pos, int size, int transp, char* id, char* client, int serviceType); ~ServiceWindowGenerationFromRec(); void notifyTextRecognized(unsigned char* text, int64_t pts); void notifyEndOfRenderization(); - void notifyTranslation(vector* glosas); + void notifyTranslation(char* glosa); void notifyTranslator(unsigned char* text); void notifyEnd(int sentences_size); diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index 30df73a..87e1e3e 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -26,13 +26,14 @@ public: ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, int pos, int size, int transp, char* id, char* client, int serviceType); //construtor de serviço de somente legenda - ServiceWindowGenerationFromSRT(char* pathSRT, int transparency, char* id, char* client, int serviceType); + ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transparency, char* id, char* client, int serviceType); ~ServiceWindowGenerationFromSRT(); void notifySubtitle(unsigned char* subtitle, int64_t pts); void notifyEndOfRenderization(); - void notifyTranslation(vector* glosas); + void notifyTranslation(char* glosas); void notifyTranslator(unsigned char* text); + void notifyRenderer(string glosa); void notifyEnd(int sub_size); void initialize(); diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index 00ed357..a2e7d5a 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -18,13 +18,14 @@ private: void setPathContents(); bool isRunning(); public: - ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); + ServiceWindowGenerationFromText(char* pathFile, int sublanguage, int transparency, char* id, char* client); ~ServiceWindowGenerationFromText(); void notifyLine(unsigned char* line); void notifyEndOfRenderization(); - void notifyTranslation(vector* glosas); + void notifyTranslation(char* glosa); void notifyTranslator(unsigned char* text); + void notifyRenderer(string glosa); void notifyEnd(int line_size); void initialize(); diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp index f442a43..f0e87b5 100644 --- a/servico/src/serviceWindowGenerationFromRec.cpp +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -1,14 +1,14 @@ #include "serviceWindowGenerationFromRec.h" ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( - char* pathVideo, int sublanguage, int pos, int size, int transp, char* id, int serviceType, char* rate){ + char* pathVideo, int pos, int size, int transp, char* id, char* client, int serviceType, char* rate){ this->path_input = pathVideo; - this->sub_language = sublanguage; this->position = pos; this->size = size; this->transparency = transp; this->user_id = id; + this->client_type = client; this->service_type = serviceType; numero_legendas = INT_MAX; legendas_enviadas = 0; @@ -21,10 +21,9 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( } ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( - char* pathVideo, int sublanguage, int pos, int size, int transp, char* id, char* client, int serviceType){ + char* pathVideo, int pos, int size, int transp, char* id, char* client, int serviceType){ this->path_input = pathVideo; - this->sub_language = sublanguage; this->position = pos; this->size = size; this->transparency = transp; @@ -117,23 +116,12 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i notifyTranslator(text); } -void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) { - string glosa = ""; - int64_t pts_notificado; - for (int i = 0; i < glosas->size(); i++) { - locale loc; - string glosa_lower = ""; - for (int k = 0; k < glosas->at(i).length(); k++){ - glosa_lower += std::tolower(glosas->at(i).at(k), loc); - } - glosa += glosa_lower; - glosa += " "; - pts_notificado = vetor_pts->front(); - } +void ServiceWindowGenerationFromRec::notifyTranslation(char* glosa) { + string sGlosa(reinterpret_cast(glosa)); while(renderer->isSending()) usleep(10000); try{ - renderer->receiveGlosa(glosa, pts_notificado); + renderer->receiveGlosa(sGlosa, vetor_pts->front()); legendas_enviadas++; }catch(lavidlib::RuntimeException &ex){ throw ServiceException(ex.getMessage().c_str()); @@ -142,8 +130,8 @@ void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) } void ServiceWindowGenerationFromRec::notifyEndOfRenderization() { + mixer = new Mixer(); 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); } diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 091c344..6fd82a9 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -5,7 +5,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, this->path_input = pathVideo; this->path_srt = pathSRT; - this-> sub_language = sublanguage; + this->sub_language = sublanguage; this->position = pos; this->size = size; this->transparency = transp; @@ -15,7 +15,6 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, numero_legendas = INT_MAX; legendas_enviadas = 0; vetor_pts = new vector(); - tradutor = new TradutorPortGlosa(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -27,8 +26,9 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, DPRINTF("Done!\n"); } -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int transp, char* id, char* client, int serviceType) { +ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transp, char* id, char* client, int serviceType) { this->path_srt = pathSRT; + this->sub_language = sublanguage; this->transparency = transp; this->user_id = id; this->client_type = client; @@ -36,7 +36,6 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in numero_legendas = INT_MAX; legendas_enviadas = 0; vetor_pts = new vector(); - tradutor = new TradutorPortGlosa(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -50,7 +49,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { free(vetor_pts); - if (mixer) delete mixer; + if (this->mixer) delete mixer; if (tradutor) delete tradutor; if (renderer) delete renderer; if (extratorSRT)delete extratorSRT; @@ -119,36 +118,34 @@ void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ addPTS(pts); - notifyTranslator(subtitle); -} - -void ServiceWindowGenerationFromSRT::notifyTranslation(vector * glosas) { - string glosa = ""; - int64_t pts_notificado; - for (int i = 0; i < glosas->size(); i++) { - locale loc; - string glosa_lower = ""; - for (int k = 0; k < glosas->at(i).length(); k++){ - glosa_lower += std::tolower(glosas->at(i).at(k), loc); - } - glosa += glosa_lower; - glosa += " "; - pts_notificado = vetor_pts->front(); - } + if (sub_language == 1) + notifyTranslator(subtitle); + else{ + string glosa(reinterpret_cast(subtitle)); + notifyRenderer(glosa); + } +} + +void ServiceWindowGenerationFromSRT::notifyTranslation(char* glosa) { + string sGlosa(glosa); + notifyRenderer(sGlosa); +} + +void ServiceWindowGenerationFromSRT::notifyRenderer(string glosa) { while(renderer->isSending()) usleep(10000); try{ - renderer->receiveGlosa(glosa, pts_notificado); + renderer->receiveGlosa(glosa, vetor_pts->front()); legendas_enviadas++; }catch(lavidlib::RuntimeException &ex){ throw ServiceException(ex.getMessage().c_str()); } - vetor_pts->erase(vetor_pts->begin()); + vetor_pts->erase(vetor_pts->begin()); } void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() { + mixer = new Mixer(); 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); } @@ -175,11 +172,14 @@ void ServiceWindowGenerationFromSRT::initialize() { extratorSRT->addListener(this); extratorSRT->setFilePath(path_srt); - tradutor->addListener(this); + tradutor = new TradutorPortGlosa(); + if (this->sub_language == 1) { + tradutor->addListener(this); + } renderer = new Renderer(this->path_libras ,this->user_id); renderer->addListener(this); - + try{ renderer->Start(); extratorSRT->initialize(); diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index 1f33764..6ffebc9 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -1,15 +1,15 @@ #include "serviceWindowGenerationFromText.h" -ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, int transp, char* id, char* client) { +ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, int sublanguage, int transp, char* id, char* client) { this->path_input = pathFile; this->transparency = transp; + this->sub_language = sublanguage; this->user_id = id; client_type = client; running = true; finish = false; numero_legendas = INT_MAX; legendas_enviadas = 0; - tradutor = new TradutorPortGlosa(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -72,24 +72,23 @@ void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { tradutor->traduz(text); } -void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { - notifyTranslator(line); +void ServiceWindowGenerationFromText::notifyLine(unsigned char* line){ + if (sub_language == 1) + notifyTranslator(line); + else{ + string glosa(reinterpret_cast(line)); + notifyRenderer(glosa); + } } -void ServiceWindowGenerationFromText::notifyTranslation(vector * glosas) { - string glosa = ""; - for (int i = 0; i < glosas->size(); i++) { - locale loc; - string glosa_lower = ""; - for (int k = 0; k < glosas->at(i).length(); k++){ - glosa_lower += std::tolower(glosas->at(i).at(k), loc); - } - glosa += glosa_lower; - glosa += " "; - } - while(renderer->isSending()){ // aguarda o renderizador processar a glosa anterior +void ServiceWindowGenerationFromText::notifyTranslation(char* glosa) { + string sGlosa(glosa); + notifyRenderer(sGlosa); +} + +void ServiceWindowGenerationFromText::notifyRenderer(string glosa) { + while(renderer->isSending()) usleep(10000); - } try{ renderer->receiveGlosa(glosa, (int64_t) -1); legendas_enviadas++; @@ -122,7 +121,10 @@ void ServiceWindowGenerationFromText::initialize() { extratorTXT->addListener(this); extratorTXT->setFilePath(path_input); - tradutor->addListener(this); + tradutor = new TradutorPortGlosa(); + if (this->sub_language == 1) { + tradutor->addListener(this); + } renderer = new Renderer(this->path_libras, this->user_id); renderer->addListener(this); diff --git a/tradutor/src/include/listenerTradutor.h b/tradutor/src/include/listenerTradutor.h index d834106..63af315 100644 --- a/tradutor/src/include/listenerTradutor.h +++ b/tradutor/src/include/listenerTradutor.h @@ -18,7 +18,7 @@ namespace Tradutor { //virtual ~OuvinteTradutor(); // Metodo que vai ser chamado quando chegar a traducao - virtual void notifyTranslation(std::vector * glosas) = 0; + virtual void notifyTranslation(char* glosa) = 0; }; } diff --git a/tradutor/src/include/tradutorPortGlosa.h b/tradutor/src/include/tradutorPortGlosa.h index 379ed66..f5ba0bc 100644 --- a/tradutor/src/include/tradutorPortGlosa.h +++ b/tradutor/src/include/tradutorPortGlosa.h @@ -31,8 +31,7 @@ namespace Tradutor { public: TradutorPortGlosa(); virtual ~TradutorPortGlosa(); - std::vector * portuguesToGlosaVector(const char * input); - std::vector * portuguesToGlosaVectorSplit(char * pGlosa); + char* portuguesToGlosaVector(const char * input); // Adiciona void addListener(ListenerTradutor * listener); @@ -45,7 +44,7 @@ namespace Tradutor { private: - void notifyListeners(std::vector * traducao); + void notifyListeners(char* traducao); std::list * listeners; PyTradutor * pyTradutor; diff --git a/tradutor/src/tradutorPortGlosa.cpp b/tradutor/src/tradutorPortGlosa.cpp index 1d3699e..8f1e20f 100644 --- a/tradutor/src/tradutorPortGlosa.cpp +++ b/tradutor/src/tradutorPortGlosa.cpp @@ -48,7 +48,7 @@ namespace Tradutor { } - void TradutorPortGlosa::notifyListeners(vector * traducao) { + void TradutorPortGlosa::notifyListeners(char* traducao) { for (list::iterator i = listeners->begin() ; i != listeners->end() ; i++){ (*i)->notifyTranslation(traducao); } @@ -73,10 +73,8 @@ namespace Tradutor { void TradutorPortGlosa::traduz(unsigned char * texto) { - vector * vGlosa = portuguesToGlosaVector((const char *)texto); - if (vGlosa->size() > 0) - notifyListeners(vGlosa); - free(vGlosa); + char* glosa = portuguesToGlosaVector((const char *)texto); + notifyListeners(glosa); } @@ -87,42 +85,10 @@ namespace Tradutor { * @param input texto de entrada * @return vetor de string contendo os tokens em glosa traduzidos. **/ - vector * TradutorPortGlosa::portuguesToGlosaVector(const char * input) { - char * sGlosa; - vector * vGlosa; + char* TradutorPortGlosa::portuguesToGlosaVector(const char * input) { + char * glosa; // Faz a tradução de portugues para glosa - sGlosa = pyTradutor->convertStringToGlosa(input); - // Cria vetor de string contendo os tokens da glosa já traduzidos - vGlosa = portuguesToGlosaVectorSplit(sGlosa); - return vGlosa; - } - - /** - * Faz split de uma string (char * sGlosa) para um vector contendo os - * tokens da glosa - * - * @param sGlosa string de glosa - * @return vetor de string contendo os tokens em glosa. - **/ - vector * TradutorPortGlosa::portuguesToGlosaVectorSplit(char * sGlosa) { - - //printf("[INFO] Glosa: %s\n", sGlosa); - - vector * vGlosa = new vector(); - string str(reinterpret_cast(sGlosa)); - - int cutAt; - while((cutAt = str.find_first_of(" ")) != str.npos){ - if(cutAt > 0){ - vGlosa->push_back(str.substr(0,cutAt)); - } - str = str.substr(cutAt+1); - } - - if(str.length() > 0) { - vGlosa->push_back(str); - } - - return vGlosa; + glosa = pyTradutor->convertStringToGlosa(input); + return glosa; } } -- libgit2 0.21.2