diff --git a/main.cpp b/main.cpp index f9102fd..a479d90 100644 --- a/main.cpp +++ b/main.cpp @@ -177,7 +177,7 @@ void serviceREC(char* path_video, char* sublanguage, hasFailed(); return; } - while(service_rec->isRunning()){ + while(!service_rec->isFinished()){ sleep(2); } delete service_rec; @@ -202,7 +202,7 @@ void serviceREC(char* path_video, char* sublanguage, hasFailed(); return; } - while(service_rec->isRunning()){ + while(!service_rec->isFinished()){ sleep(2); } delete service_rec; @@ -225,7 +225,7 @@ void serviceSRT(char* path_in, char* path_srt, char* sublanguage, hasFailed(); return; } - while(service_srt->isRunning()){ + while(!service_srt->isFinished()){ sleep(5); } @@ -246,7 +246,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ return; } - while (service_text->isAlive()) { + while (!service_text->isFinished()) { usleep(100000); //100ms } delete service_text; @@ -263,7 +263,7 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ return; } - while (service_text->isAlive()) { + while (!service_text->isFinished()) { usleep(100000); //100ms } delete service_text; @@ -273,7 +273,6 @@ void serviceText(char* path_text, char* transparency, char* id, char* client_typ void serviceOnlySRT(char* path_file, char* transparency, char* id){ - ServiceWindowGenerationFromSRT * service_srt; service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, 5); try{ @@ -284,7 +283,7 @@ void serviceOnlySRT(char* path_file, char* transparency, char* id){ return; } - while (!service_srt->finished()) { + while (!service_srt->isFinished()) { usleep(100000); //100ms } delete service_srt; @@ -309,7 +308,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate hasFailed(); return; } - while(service_rec->isRunning()){ + while(!service_rec->isFinished()){ sleep(2); } delete service_rec; @@ -333,7 +332,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ hasFailed(); return; } - while(service_rec->isRunning()){ + while(!service_rec->isFinished()){ sleep(2); } delete service_rec; @@ -357,12 +356,12 @@ void hasInvalid(){ //Help do programa, explicando todos os parâmetros existentes... void help() { cout <<"\n##################################################################################\n" - <<"# SERVICE_TYPE: 1 - means Closed Caption - doesn't use INPUT_SRT #\n" - <<"# 2 - means With Subtitles (SRT) - requires INPUT_SRT #\n" - <<"# 3 - means Recognize - requires INPUT_VIDEO #\n" + <<"# SERVICE_TYPE: 1 - means Closed Caption - doesn't use INPUT_SRT #\n" + <<"# 2 - means With Subtitles (SRT) - requires INPUT_SRT #\n" + <<"# 3 - means Recognize - requires INPUT_VIDEO #\n" <<"# 4 - means Text - requires INPUT_FILE_TEXT #\n" - <<"# 5 - means Subtitles ONLY (SRT) - requires INPUT_SRT #\n" - <<"# 6 - means Audio - requires INPUT_AUDIO #\n" + <<"# 5 - means Subtitles ONLY (SRT) - requires INPUT_SRT #\n" + <<"# 6 - means Audio - requires INPUT_AUDIO #\n" <<"####################################################################################\n\n" /*<<"# INPUT_VIDEO: Path of the video file #\n" <<"#----------------------------------------------------------------------------------#\n" diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index ad8e6ca..4b7c6bb 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -57,12 +57,10 @@ protected: char* path_audio; char* path_libras; char* client_type; - - bool running; - - bool finish; char* user_id; + bool running; + int size, position, transparency, sublanguage, serviceType, numero_legendas, legendas_enviadas; void setSize(int); @@ -82,12 +80,12 @@ public: ServiceWindowGeneration(); ~ServiceWindowGeneration(); + virtual void notifyTranslation(vector* glosas); virtual void notifyEndOfSynchronization(); //virtual void notifyPCRBase(uint64_t pcr_base); + void initialize(); - TradutorPortGlosa * getTradutor(); - void adicionaPTS(int64_t pts); bool isRunning(); char* getPathLibras(); @@ -95,8 +93,11 @@ public: char* getClientType(); char* getPathInput(); string getPathAPI(); + TradutorPortGlosa * getTradutor(); + void setPathLibras(); void setSizeOfSubtitles(int sub_size); + void adicionaPTS(int64_t pts); }; #endif /* SERVICEWINDOWGENERATION_H */ diff --git a/servico/src/include/serviceWindowGenerationFromREC.h b/servico/src/include/serviceWindowGenerationFromREC.h index 07367cb..8fa1555 100644 --- a/servico/src/include/serviceWindowGenerationFromREC.h +++ b/servico/src/include/serviceWindowGenerationFromREC.h @@ -16,25 +16,21 @@ class ServiceWindowGenerationFromREC : public ServiceWindowGeneration, public Re private: Recognize *rec; + bool finish; public: ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate); - ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); - ~ServiceWindowGenerationFromREC(); - void initialize(); - + virtual void notifyTextRecognized(unsigned char* text, int64_t pts); virtual void notifyEnd(int sentences_size); - - void notifyTranslator(unsigned char *text); - void notifySynchWithoutTranslator(unsigned char *text, int64_t pts); - + + void initialize(); + bool isFinished(); void Run(); - }; #endif /* SERVICEWINDOWGENERATIONFROMREC_H */ diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index a45b1fe..7168566 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -21,33 +21,27 @@ private: pthread_mutex_t *mutex_serviceSRT; ExtratorSRT * extratorSRT; char* path_srt; - bool finish_srt; + bool finish; public: /* Construtor 1 - legenda e vídeo */ - ServiceWindowGenerationFromSRT( - char* path_video, char* path_srt, int sublanguage, + ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); - /* Construtor 2 - só legenda */ ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, int _serviceType); - - /* Destrutor */ ~ServiceWindowGenerationFromSRT(); virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); virtual void notifyEnd(int sub_size); - - void notificaTradutor(unsigned char *legenda); - - bool finished(); + void notifyTranslator(unsigned char* subtitle); - void notificaSincronizadorSemTradutor(unsigned char *legenda, int64_t pts); void initialize(); - void setPathSRT(char* path_srt); + bool isFinished(); void Run(); + void setPathSRT(char* path_srt); + }; #endif /* SERVICEWINDOWGENERATIONFROMSRT_H */ diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index 38735b8..c12b67d 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -12,17 +12,19 @@ class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { private: - ExtratorTXT * extratorTXT; - bool alive; + ExtratorTXT * extratorTXT; + bool finish; public: ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file, int _transp, int _serviceType, char* _client_type); ~ServiceWindowGenerationFromText (); + void notifyLine(unsigned char* line); void notifyEnd(int line_size); + void initialize(); - bool isAlive(); + bool isFinished(); void Run(); }; diff --git a/servico/src/serviceWindowGeneration.cpp b/servico/src/serviceWindowGeneration.cpp index 2c2dac9..806d3e2 100644 --- a/servico/src/serviceWindowGeneration.cpp +++ b/servico/src/serviceWindowGeneration.cpp @@ -20,57 +20,13 @@ ServiceWindowGeneration::~ServiceWindowGeneration() { if (mixer) delete mixer; if (tradutor) delete tradutor; if (sincronizador) delete sincronizador; - DDDPRINTF("Service finalized!\n"); - -} - -void ServiceWindowGeneration::adicionaPTS(int64_t pts) { - vetor_pts->push_back(pts); -} - -/* Checado pela subclasse para saber quando o sincronizador terminar. */ -bool ServiceWindowGeneration::isRunning() { - return this->running; -} - -/* Quando o sincronizador termina, ele invoca esse método para avisar! */ -void ServiceWindowGeneration::notifyEndOfSynchronization() { - if (serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) { - mixer = new Mixer(); - mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id); - createThumbnail(); - }else - transcodeVideoToMp4(); - this->running = false; - -} - -void ServiceWindowGeneration::setSizeOfSubtitles(int sub_size) { - numero_legendas = sub_size; - if (legendas_enviadas >= numero_legendas) { - sincronizador->stop(); - } -} - -void ServiceWindowGeneration::setPathLibras() { - char* final_path = new char[MAX_SIZE_PATH]; - strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); - strcat(final_path, this->user_id); - strcat(final_path, "/libras.ts"); - - this->path_libras = final_path; - //DDPRINTF("Path TS File: %s\n", this->path_libras); } char* ServiceWindowGeneration::getPathLibras() { return path_libras; } -void ServiceWindowGeneration::setPathInput(char* _path_input) { - this->path_input = _path_input; -} - char* ServiceWindowGeneration::getPathInput() { return path_input; } @@ -79,10 +35,6 @@ string ServiceWindowGeneration::getPathAPI() { return PATH_API; } -void ServiceWindowGeneration::setUserId(char* _userId) { - this->user_id = _userId; -} - char* ServiceWindowGeneration::getClientType(){ return client_type; } @@ -91,14 +43,26 @@ char* ServiceWindowGeneration::getUserId() { return user_id; } -void ServiceWindowGeneration::setServiceType(int type) { - serviceType = type; +void ServiceWindowGeneration::setPathInput(char* _path_input) { + this->path_input = _path_input; } void ServiceWindowGeneration::setClientType(char* client_type) { this->client_type = client_type; } +void ServiceWindowGeneration::setUserId(char* _userId) { + this->user_id = _userId; +} + +void ServiceWindowGeneration::setServiceType(int type) { + serviceType = type; +} + +void ServiceWindowGeneration::setSubLanguage(int sublang){ + this->sublanguage = sublang; +} + void ServiceWindowGeneration::setSize(int size){ this->size = size; } @@ -111,15 +75,47 @@ void ServiceWindowGeneration::setTransparency(int transparency){ this->transparency = transparency; } -void ServiceWindowGeneration::setSubLanguage(int sublang){ - this->sublanguage = sublang; +void ServiceWindowGeneration::setPathLibras() { + char* final_path = new char[MAX_SIZE_PATH]; + strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); + strcat(final_path, this->user_id); + strcat(final_path, "/libras.ts"); + + this->path_libras = final_path; + //DDPRINTF("Path TS File: %s\n", this->path_libras); +} + +void ServiceWindowGeneration::setSizeOfSubtitles(int sub_size) { + numero_legendas = sub_size; + if (legendas_enviadas >= numero_legendas) + sincronizador->stop(); +} + +void ServiceWindowGeneration::adicionaPTS(int64_t pts) { + vetor_pts->push_back(pts); +} + +/* Checado pela subclasse para saber quando o sincronizador terminar. */ +bool ServiceWindowGeneration::isRunning() { + return this->running; +} + +/* Quando o sincronizador termina, ele invoca esse método para avisar! */ +void ServiceWindowGeneration::notifyEndOfSynchronization() { + if (serviceType == SERVICE_TYPE_REC || serviceType == SERVICE_TYPE_SRT) { + mixer = new Mixer(); + mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id); + createThumbnail(); + }else{ + transcodeVideoToMp4(); + } + this->running = false; } void ServiceWindowGeneration::initialize() { setPathLibras(); - this->finish = false; if (this->sublanguage == 1) { tradutor->addListener(this); } diff --git a/servico/src/serviceWindowGenerationFromREC.cpp b/servico/src/serviceWindowGenerationFromREC.cpp index 4323579..2533855 100644 --- a/servico/src/serviceWindowGenerationFromREC.cpp +++ b/servico/src/serviceWindowGenerationFromREC.cpp @@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( setServiceType(serviceType); setUserId(id); rec = new Recognize(path_video, id, rate); + finish = false; DPRINTF("Done!\n"); } @@ -25,6 +26,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( setServiceType(serviceType); setUserId(id); rec = new Recognize(path_video, id); + finish = false; DPRINTF("Done!\n"); } @@ -33,6 +35,24 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { DDDPRINTF("Service REC finished!\n"); } +void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { + tradutor->traduz(text); +} + +void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) { + adicionaPTS(pts); + notifyTranslator(text); +} + +bool ServiceWindowGenerationFromREC::isFinished(){ + return finish; +} + +void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { + DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); + setSizeOfSubtitles(sentences_size); +} + void ServiceWindowGenerationFromREC::initialize() { rec->addListener(this); @@ -67,23 +87,10 @@ void ServiceWindowGenerationFromREC::initialize() { this->Start(); } -void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) { - adicionaPTS(pts); - notifyTranslator(text); -} - -void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) { - tradutor->traduz(text); -} - -void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) { - DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); - setSizeOfSubtitles(sentences_size); -} - void ServiceWindowGenerationFromREC::Run() { - while (!rec->isFinished()) { - sleep(200000); + while (isRunning()) { + usleep(200000); } + finish = true; } diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index fe93c1e..2bc6e7a 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -12,7 +12,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( setSubLanguage(sublanguage); setServiceType(serviceType); setUserId(id); - this->finish = false; + finish = false; DPRINTF("Done!\n"); } @@ -22,7 +22,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, i setTransparency(transparency); setServiceType(serviceType); setUserId(id); - finish_srt = false; + finish = false; DPRINTF("Done!\n"); } @@ -32,29 +32,31 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { DDDPRINTF("Service SRT finalized!\n"); } -void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { - this->path_srt = path_srt; -} +void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { -void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { - DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); - setSizeOfSubtitles(sub_size); + const char* constchar = (const char*) subtitle; + char* legenda_copy = new char[strlen(constchar)+1]; + strcpy(legenda_copy, constchar); + tradutor->traduz((unsigned char*) legenda_copy); + free(legenda_copy); } - -void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *legenda, int64_t pts){ +void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ adicionaPTS(pts); - notificaTradutor(legenda); - + notifyTranslator(subtitle); } -void ServiceWindowGenerationFromSRT::notificaTradutor(unsigned char* legenda) { +bool ServiceWindowGenerationFromSRT::isFinished(){ + return finish; +} - const char* constchar = (const char*) legenda; - char* legenda_copy = new char[strlen(constchar)+1]; - strcpy(legenda_copy, constchar); - tradutor->traduz((unsigned char*) legenda_copy); - free(legenda_copy); +void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { + DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); + setSizeOfSubtitles(sub_size); +} + +void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { + this->path_srt = path_srt; } void ServiceWindowGenerationFromSRT::initialize() { @@ -62,29 +64,23 @@ void ServiceWindowGenerationFromSRT::initialize() { DDPRINTF("Service SRT Initialize.\n"); if(serviceType == 2){ - - /* - Este serviço utiliza o arquivo de vídeo (em formato TS) do usuário para - capturar as informações referente ao relógio (PCR) para calcular as - etiquetas de apresentação (PTS) dos sinais em Libras. - */ + /*Este serviço utiliza o arquivo de vídeo (em formato TS) do usuário para + capturar as informações referente ao relógio (PCR) para calcular as + etiquetas de apresentação (PTS) dos sinais em Libras.*/ inputfile = new InputFile(this->path_input); extratorSRT = new ExtratorSRT(); + monitor_pcr_base = new MonitorPCR(); - monitor_pcr_base = new MonitorPCR(); - - /* [Temporário]: como o monitor do PCR não estava encontrando a extensão do - vídeo, este está sendo analisado e infomado no trecho de código a seguir. - */ - if (strstr(path_input, "ts") != NULL) { - char* format_video = new char[3]; - strcpy(format_video, "ts"); - monitor_pcr_base->setFormatVideo(format_video); - } + /* [Temporário]: como o monitor do PCR não estava encontrando a extensão do + vídeo, este está sendo analisado e infomado no trecho de código a seguir.*/ + if (strstr(path_input, "ts") != NULL) { + char* format_video = new char[3]; + strcpy(format_video, "ts"); + monitor_pcr_base->setFormatVideo(format_video); + } monitor_pcr_base->addListenerPCRBase(extratorSRT); - inputfile->addListener(monitor_pcr_base); extratorSRT->addListener(this); extratorSRT->setFilePath((char*) path_srt); @@ -102,13 +98,9 @@ void ServiceWindowGenerationFromSRT::initialize() { this->Start(); } else{ - - /** - Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, - portanto, não é preciso monitorar as informações do PCR a partir do - objeto InputFile(). - */ - + /*Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, + portanto, não é preciso monitorar as informações do PCR a partir do + objeto InputFile().*/ extratorSRT = new ExtratorSRT(); monitor_pcr_base = new MonitorPCR(); monitor_pcr_base->addListenerPCRBase(extratorSRT); @@ -128,13 +120,9 @@ void ServiceWindowGenerationFromSRT::initialize() { } -bool ServiceWindowGenerationFromSRT::finished() { - return finish_srt; -} - void ServiceWindowGenerationFromSRT::Run() { while (isRunning()) { usleep(200000); //200ms } - finish_srt = true; + finish = true; } diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index 07e957f..24bf9bd 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -8,7 +8,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( setUserId(username); setTransparency(transp); setServiceType(serviceType); - alive = true; + finish = false; DPRINTF("Done!\n"); } @@ -17,6 +17,19 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { DDDPRINTF("Service Text finished!\n"); } +void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { + tradutor->traduz(line); +} + +void ServiceWindowGenerationFromText::notifyEnd(int line_size) { + DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); + setSizeOfSubtitles(line_size); +} + +bool ServiceWindowGenerationFromText::isFinished() { + return finish; +} + void ServiceWindowGenerationFromText::initialize() { DDPRINTF("Service Text Initialize.\n"); @@ -34,22 +47,9 @@ void ServiceWindowGenerationFromText::initialize() { this->Start(); } -void ServiceWindowGenerationFromText::notifyEnd(int line_size) { - DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); - setSizeOfSubtitles(line_size); -} - -void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { - tradutor->traduz(line); -} - -bool ServiceWindowGenerationFromText::isAlive() { - return alive; -} - void ServiceWindowGenerationFromText::Run() { while (isRunning()) { usleep(200000); //200ms } - alive = false; + finish = true; } -- libgit2 0.21.2