diff --git a/Makefile b/Makefile index d83ac4e..11d3f77 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,8 @@ inputObjs= \ inputException.o servicoObjs= \ - serviceWindowGeneration.o \ serviceWindowGenerationFromSRT.o \ - serviceWindowGenerationFromREC.o \ + serviceWindowGenerationFromRec.o \ serviceWindowGenerationFromText.o \ serviceException.o diff --git a/extrator/src/extratorFactory.cpp b/extrator/src/extratorFactory.cpp index 9db97c9..b78f068 100644 --- a/extrator/src/extratorFactory.cpp +++ b/extrator/src/extratorFactory.cpp @@ -8,9 +8,12 @@ ExtratorFactory::~ExtratorFactory(){ //TODO } -Extrator* ExtratorFactory::getExtrator(int extrator_type){ - if(extrator_type == SRT) - return new ExtratorSRT(); - if(extrator_type == TXT) - return new ExtratorTXT(); +Extrator* ExtratorFactory::getExtrator(Extrator::ExtratorType extrator_type) { + extrator = extrator_type; + switch(extrator){ + case Extrator::SRT: + return new ExtratorSRT(); + case Extrator::TXT: + return new ExtratorTXT(); + } } \ No newline at end of file diff --git a/extrator/src/extratorSRT.cpp b/extrator/src/extratorSRT.cpp index f03b34a..b7b77dc 100644 --- a/extrator/src/extratorSRT.cpp +++ b/extrator/src/extratorSRT.cpp @@ -43,7 +43,7 @@ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { } void ExtratorSRT::notifyEndExtraction(int size) { - DDPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); + DPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(size); } @@ -72,8 +72,7 @@ bool ExtratorSRT::hasNextSubtitle() { } void ExtratorSRT::Run(){ - printf("\n"); - DDPRINTF("[AGUARDE] Extraindo Legendas...\n"); + DPRINTF("[AGUARDE] Extraindo Legendas...\n"); int sub_index = 0; string sub_text = ""; @@ -89,7 +88,6 @@ void ExtratorSRT::Run(){ } if(sub_index == 0) notifyListeners((unsigned char*)"ARQUIVO_VAZIO", 0); - printf("\n"); finish = true; notifyEndExtraction(sub_index); } diff --git a/extrator/src/extratorTXT.cpp b/extrator/src/extratorTXT.cpp index b8d1e6d..a8e57b9 100644 --- a/extrator/src/extratorTXT.cpp +++ b/extrator/src/extratorTXT.cpp @@ -50,7 +50,7 @@ void ExtratorTXT::notifyListeners(unsigned char* line) { } void ExtratorTXT::notifyEndExtraction(int size) { - DDPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); + DPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(size); } @@ -76,7 +76,7 @@ bool ExtratorTXT::isFinished(){ void ExtratorTXT::Run(){ - DDPRINTF("[AGUARDE] Extraindo Texto...\n") + DPRINTF("[AGUARDE] Extraindo Texto...\n") int line_index = 0; bool hasNext = true; @@ -99,7 +99,6 @@ void ExtratorTXT::Run(){ throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); } } - printf("\n"); finish = true; notifyEndExtraction(line_index); } diff --git a/extrator/src/include/extrator.h b/extrator/src/include/extrator.h index 2c5271e..b9502f6 100644 --- a/extrator/src/include/extrator.h +++ b/extrator/src/include/extrator.h @@ -20,6 +20,10 @@ protected: BufferedReader* bff_reader; public: + enum ExtratorType { + SRT, + TXT + }; virtual void notifyEndExtraction(int size) = 0; virtual void setFilePath(char* path) = 0; virtual void initialize() = 0; diff --git a/extrator/src/include/extratorFactory.h b/extrator/src/include/extratorFactory.h index 9196958..a3faa79 100644 --- a/extrator/src/include/extratorFactory.h +++ b/extrator/src/include/extratorFactory.h @@ -5,16 +5,16 @@ #include "extratorSRT.h" #include "extratorTXT.h" -#define SRT 1 -#define TXT 2 - class ExtratorFactory{ public: ExtratorFactory(); ~ExtratorFactory(); - Extrator* getExtrator(int extrator_type); + Extrator* getExtrator(Extrator::ExtratorType extrator_type); + +private: + Extrator::ExtratorType extrator; }; diff --git a/log/log b/log/log index 7a3bb44..e69de29 100644 --- a/log/log +++ b/log/log @@ -1,4 +0,0 @@ -Wed May 6 14:05:56 2015 -[ERRO: recognize.cpp] Arquivo não encontrado. - - \ No newline at end of file diff --git a/main.cpp b/main.cpp index fdf4290..46e41b4 100644 --- a/main.cpp +++ b/main.cpp @@ -12,11 +12,9 @@ * Edit on 03 de Fevereiro de 2014 */ #include "serviceWindowGenerationFromSRT.h" -#include "serviceWindowGenerationFromREC.h" +#include "serviceWindowGenerationFromRec.h" #include "serviceWindowGenerationFromText.h" #include "serviceException.h" -#include "property.h" - #include #include @@ -32,7 +30,6 @@ void serviceText(char* service, char* path_text, char* transparency, char* id, c void help(); void serviceHelp(int service); -void setStatusOfReady(char* ready); void fail(string msg); void hasFailed(); void hasInvalid(); @@ -47,91 +44,61 @@ int main(int argc, char* argv[]) { gettimeofday(&tv1, NULL); t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; - - printf("\n################## VLIBRAS : LAVID ##################\n\n"); - - if(argc >= 2) { - + + if(argc > 2) { + printf("\n################## VLIBRAS : LAVID ##################\n\n"); DDPRINTF("Service Type: %s\n", argv[1]); - switch((int) atoi(argv[1])){ - case 1: - if(argc < 9){ + if(argc <= 9){ serviceHelp(1); hasInvalid(); - break; - } - if(argc == 9){ - setStatusOfReady("0"); - serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], "user"); - setStatusOfReady("1"); - }else + }else{ serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); - + } break; case 2: - if(argc < 8){ + if(argc <= 8){ serviceHelp(2); hasInvalid(); - break; - } - if(argc == 8){ - setStatusOfReady("0"); - serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], "user"); - setStatusOfReady("1"); - }else + }else{ serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); + } break; case 3: - if(argc < 5){ + if(argc <= 5){ serviceHelp(3); hasInvalid(); - break; - } - if(argc == 5){ - setStatusOfReady("0"); - serviceText(argv[1], argv[2], argv[3], argv[4], "user"); - setStatusOfReady("1"); - }else + }else{ serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); + } break; case 4: - if(argc < 5){ + if(argc <= 5){ serviceHelp(4); hasInvalid(); - break; - } - if(argc == 5 ){ - setStatusOfReady("0"); - serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user"); - setStatusOfReady("1"); - }else + }else{ serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); + } break; case 5: - printf("[INFO] Serviço em manutenção!!!\n"); - exit(0); - if(argc < 5){ + if(argc <= 5){ serviceHelp(5); hasInvalid(); - break; - } - if (argc == 5){ - setStatusOfReady("0"); - serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user"); - setStatusOfReady("1"); - }else + }else{ serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); + } break; default: - cout << "\nServiço inválido. Tente novamente." << endl; - help(); + cout << "\nFAIL VLibras: Serviço inválido! Tente --help" << endl; hasInvalid(); break; } + }else if(argc == 2 && (strcmp(argv[1], "--help")) == 0){ + help(); + exit(0); }else{ - help(); + cout << "\nFAIL VLibras: Tente --help para obter informações.\n" << endl; hasInvalid(); } @@ -142,18 +109,9 @@ int main(int argc, char* argv[]) { gettimeofday(&tv2, NULL); t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; - cout << endl; DDPRINTF("Time: %lf\n", (t2-t1)); - DDPRINTF("VLibras concluído!\n\n"); + DDPRINTF("VLibras finalized!\n\n"); exit(0); - -} - -void setStatusOfReady(char* ready){ - char* status = new char[256]; - strcpy(status, "READY="); - strcat(status,ready); - Util::Logger::Instance()->writeInfoLog("/home/wesnydy/.vlibras-conf/service/log-vbox", status); } void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, @@ -180,8 +138,8 @@ void serviceSRT(char* service, char* path_video, char* path_srt, char* sublangua void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type){ - ServiceWindowGenerationFromREC * service_rec; - service_rec = new ServiceWindowGenerationFromREC(path_video, (int) atoi(sublanguage), + 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)); try{ @@ -200,7 +158,7 @@ void serviceREC(char* service, char* path_video, char* sublanguage, char* positi void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ ServiceWindowGenerationFromText *service_text; - service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), (int) atoi(service), client_type); + service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(transparency), id, client_type); try{ service_text->initialize(); @@ -236,8 +194,8 @@ void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){ - ServiceWindowGenerationFromREC * service_rec; - service_rec = new ServiceWindowGenerationFromREC(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service)); + 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(); @@ -349,21 +307,21 @@ void help() { cout << endl << "Usage Summary: vlibras [SERVICE] [INPUT] ... [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" << "\nSERVICE:\n" - << "1 Video with Subtitles (SRT) - requires INPUT_VIDEO and INPUT_SRT\n" - << "2 Video Recognize - requires INPUT_VIDEO\n" - << "3 Text - requires INPUT_TEXT_FILE\n" - << "4 Subtitles only (SRT) - requires INPUT_SRT\n" - << "5 Audio Recognize - requires INPUT_AUDIO\n" + << "1 Video with Subtitles (SRT) - requires INPUT_VIDEO and INPUT_SRT\n" + << "2 Video Recognize - requires INPUT_VIDEO\n" + << "3 Text - requires INPUT_TEXT_FILE\n" + << "4 Subtitles only (SRT) - requires INPUT_SRT\n" + << "5 Audio Recognize - requires INPUT_AUDIO\n" << "\nSERVICES PARAMETERS:\n" << "Video with subtitles:\n" << " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" - << "Video Recognize:\n" + << "\nVideo Recognize:\n" << " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" - << "Text:\n" + << "\nText:\n" << " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" - << "Subtitles only:\n" + << "\nSubtitles only:\n" << " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" - << "Audio Recognize\n" + << "\nAudio Recognize\n" << " [INPUT_AUDIO] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" << "\nPARAMETERS:\n" << "INPUT_VIDEO Path of the video file\n" @@ -375,5 +333,6 @@ void help() { << "SIZE 1 - means Small, 2 - means Medium, 3 - means Large\n" << "TRANSPARENCY 0 - means that the background is opaque , 1 - means that the background is transparent\n" << "ID Relative to the unique ID on the Database\n" - << "CLIENT_TYPE web - necessary only for web clients, others clients can ignore this parameter\n"; + << "CLIENT_TYPE prod - means that the client is web/cloud, devel - means that the client is developer\n" + << endl; } \ No newline at end of file diff --git a/mixer/src/Mixer.cpp b/mixer/src/Mixer.cpp index 2230df3..79a7109 100644 --- a/mixer/src/Mixer.cpp +++ b/mixer/src/Mixer.cpp @@ -24,11 +24,12 @@ Mixer::~Mixer() { /*Faz a chamada ffmpeg no terminal.*/ -void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, int transparency, char* _id, char* client_type){ +void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, + int transparency, char* _id, char* path_uploads, char* path_contents){ - DDPRINTF("[AGUARDE] Mixando...\n") - - client = client_type; + DPRINTF("[AGUARDE] Mixando...\n") + uploads = path_uploads; + contents = path_contents; stringstream ss; ss << _id; ss >> user_id; @@ -146,24 +147,10 @@ void Mixer::mixVideos () { } void Mixer::setPathFinal(){ - - char* final_path = new char[256]; - - if(strcmp(client, (char*)WEB_USER) == 0){ - pathFinal = PATH_API; - pathFinal.append(user_id).append(".mp4"); - }else{ - try{ - PropertyHandler* reader = new PropertyHandler("vlibras_user/.vlibras-conf/configuration/params-vbox.conf"); - strcpy(final_path, reader->getAttributeValue("STORAGE")); - stringstream ss; - ss << final_path; - ss >> pathFinal; - pathFinal.append("/").append(user_id).append(".mp4"); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); - } - } + stringstream ss; + ss << contents; + ss >> pathFinal; + pathFinal.append(user_id).append(".mp4"); } /*Ajusta o FPS do vídeo principal para 45 se preciso...*/ @@ -330,15 +317,11 @@ void Mixer::setMainVideo(string mainVideo){ } //ajeitar isso depois string nameOfMainVideo = mainVideo.substr(0, dotPosition); - char* final_path = new char[256]; - - if(strcmp(client, (char*)WEB_USER) == 0){ - this->temporaryTextFile = "vlibras_user/vlibras-api/uploads/"; - temporaryTextFile.append(this->user_id).append("/tamanho.txt"); - }else{ - this->temporaryTextFile = "vlibras_user/.vlibras-conf/contents/"; - temporaryTextFile.append("tamanho.txt"); - } + + stringstream ss; + ss << uploads; + ss >> temporaryTextFile; + temporaryTextFile.append(this->user_id).append("/tamanho.txt"); //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); } string Mixer::getMainVideo(){ diff --git a/mixer/src/include/Mixer.h b/mixer/src/include/Mixer.h index a299ee8..2a495bb 100644 --- a/mixer/src/include/Mixer.h +++ b/mixer/src/include/Mixer.h @@ -18,9 +18,6 @@ #include #include "dprintf.h" #include "property.h" - -using namespace std; -using namespace sndesc; //SL Video Position #define TOP_LEFT 1 @@ -37,11 +34,8 @@ using namespace sndesc; #define LARGE_HEIGHT 540 //0.5*1080 #define MAX_SIZE_PATH 256 -#define WEB_USER "web" -#define PATH_API "vlibras_user/vlibras-api/videos/" using namespace std; -using namespace sndesc; class Mixer { public: @@ -66,7 +60,7 @@ public: int getTransparency(); void setNumThreads(string); string getNumThreads(); - void initialize(string mainVideo, string slVideo, int, int, int, char*, char*); + void initialize(string mainVideo, string slVideo, int, int, int, char*, char*, char*); void setPathFinal(); private: @@ -82,7 +76,8 @@ private: void convertSecondaryVideoFPS(double); string mainVideo, secondaryVideo, temporaryTextFile, numThreads, pathFinal, user_id; - char* client; + char* contents; + char* uploads; int positionSecondaryVideo; double widthSecondaryVideo, heightSecondaryVideo; int transparency; diff --git a/recognize/src/include/recognize.h b/recognize/src/include/recognize.h index 7ff03ff..7727725 100644 --- a/recognize/src/include/recognize.h +++ b/recognize/src/include/recognize.h @@ -23,9 +23,6 @@ #define SIZE_BUFFER 256 #define CONFIDENCE_RATE 0.10 -#define WEB_USER 1 -#define PATH_API_UPLOADS "vlibras_user/vlibras-api/uploads/" -#define PATH_VBOX_CONTENTS "vlibras_user/.vlibras-conf/contents/" #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" #define PATH_AUDIO_PARTS "/audio/parts/" #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" @@ -49,7 +46,7 @@ class Recognize: public Thread { public: - Recognize(char* _pathVideo, char* id, int client_type); + Recognize(char* _pathVideo, char* id); Recognize(char* _pathVideo, char* id, char* rate); Recognize(char* _pathVideo, int _inputType, char* id); ~Recognize(); @@ -68,6 +65,7 @@ public: * Define o tamanho em segundos de cada parte retirada do audio original. */ void setSizeAudioBlocs(int sec); + void setPathAudioContents(char* path); void addListener(RecognizeListener* listener); diff --git a/recognize/src/recognize.cpp b/recognize/src/recognize.cpp index 857724c..c910ac6 100644 --- a/recognize/src/recognize.cpp +++ b/recognize/src/recognize.cpp @@ -1,6 +1,6 @@ #include -Recognize::Recognize(char* _pathVideo, char* _id, int client_type) { +Recognize::Recognize(char* _pathVideo, char* _id) { listeners = new list(); pathVideo = _pathVideo; @@ -11,12 +11,6 @@ Recognize::Recognize(char* _pathVideo, char* _id, int client_type) { ss << _id; ss >> id; confidenceRate=CONFIDENCE_RATE; - if(client_type == WEB_USER){ - path_contents = (char*) PATH_API_UPLOADS; - }else{ - path_contents = (char*) PATH_VBOX_CONTENTS; - } - DPRINTF("Done!\n"); } @@ -56,7 +50,7 @@ Recognize::~Recognize() { void Recognize::initialize() { - DDPRINTF("Recognizing...\n"); + DPRINTF("Recognizing...\n"); /**printf("*** Initialized Recognition ***\n\nVideo: %s\nType [1-File; 2-Mic]: %d\nFrequency: %d\n\n", this->pathVideo, this->inputType, this->frequency);**/ @@ -93,6 +87,10 @@ void Recognize::setSizeAudioBlocs(int sec) { sizeBlocs = sec; } +void Recognize::setPathAudioContents(char* path){ + path_contents = path; +} + char* Recognize::extractAudioFromVideo() { @@ -208,7 +206,6 @@ void Recognize::breakVideoParts(int timeTotal) { } - void Recognize::executeJuliusEngine() { string command, type, freqStr; @@ -225,7 +222,7 @@ void Recognize::executeJuliusEngine() { sprintf(cfreq, "%i", frequency); command.append(" -smpFreq "). append(cfreq). - append(" -nolog >> "); + append(" >> "); command.append(path_contents).append(id).append(FILENAME_RECOGNIZED_OUT); //Command of execute Julius //printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); @@ -286,7 +283,6 @@ void Recognize::generateConfidence() { scores.push_back(avgScores/sizeAvgScores); }else if(pass==0){ - notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", 0); notifyEndExtraction(count_lines); return; @@ -341,7 +337,6 @@ void Recognize::filterOutputJulius() { if(getConfidence()) notifyListeners(sentence_ptr, pts.front()); else{ - notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", pts.front()); } scores.erase(scores.begin()); @@ -371,7 +366,7 @@ void Recognize::notifyListeners(char* text, int64_t pts) { } void Recognize::notifyEndExtraction(int sentences_size) { - DDPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); + DPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(sentences_size); } @@ -409,8 +404,7 @@ void Recognize::cleanFiles() { void Recognize::createDir(){ string command = "mkdir "; - command.append(path_contents).append(id) - .append(" && mkdir ").append(path_contents).append(id).append("/audio") + command.append(path_contents).append(id).append("/audio") .append(" && mkdir ").append(path_contents).append(id).append("/audio/parts") .append(" && mkdir ").append(path_contents).append(id).append("/audio/origin"); system(command.c_str()); diff --git a/servico/src/include/serviceException.h b/servico/src/include/serviceException.h index 4943e7e..8698d7b 100644 --- a/servico/src/include/serviceException.h +++ b/servico/src/include/serviceException.h @@ -9,17 +9,20 @@ * * **************************************************************************/ - #ifndef SERVICEEXCEPTION_H - #define SERVICEEXCEPTION_H +#ifndef SERVICEEXCEPTION_H +#define SERVICEEXCEPTION_H - #include +#include - using namespace lavidlib; +using namespace std; +using namespace lavidlib; - class ServiceException : public RuntimeException { - public: - ServiceException(const std::string message); - ServiceException(const char* message); - }; +class ServiceException : public RuntimeException { + +public: + ServiceException(const string message); + ServiceException(const char* message); + +}; - #endif /* SERVICEEXCEPTION_H */ \ No newline at end of file +#endif /* SERVICEEXCEPTION_H */ \ No newline at end of file diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index f6be548..0a97533 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -1,103 +1,77 @@ #ifndef SERVICEWINDOWGENERATION_H -#define SERVICEWINDOWGENERATION_H +#define SERVICEWINDOWGENERATION_H -#include -#include -#include -#include #include -#include -#include -#include +#include +#include +#include +#include "jthread.h" #include "dprintf.h" -#include "Mixer.h" -//#include "inputFile.h" #include "property.h" -#include "listenerTradutor.h" -#include "tradutorPortGlosa.h" -//#include "httpstreamer.h" +#include "Mixer.h" #include "synchronizer.h" #include "listenerSynchronizer.h" +#include "listenerTradutor.h" +#include "tradutorPortGlosa.h" #include "serviceException.h" #include -#define WEB_USER "web" -#define VIDEO_POSE_NEUTRA "poseneutra" +#define DEVELOPER "devel" +#define PRODUCTION "prod" #define BASEDIR "vlibras_user/dicionario_libras/" #define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/" +#define VIDEO_POSE_NEUTRA "poseneutra" #define EXTENSAO_DICIONARIO ".ts" -#define PATH_CONTENTS "vlibras_user/.vlibras-conf/contents/" -#define PATH_API "vlibras_user/vlibras-api/videos/" +#define PATH_DEVEL "vlibras_user/vlibras-contents/videos/" +#define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" +#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" +#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/configuration/params-vbox.conf" #define MAX_SIZE_PATH 256 -#define SERVICE_TYPE_SRT 1 /* Subtitle SRT */ -#define SERVICE_TYPE_REC 2 /* Reconhecimento de Voz */ -#define SERVICE_TYPE_TEXT 3 /* Texto */ -#define SERVICE_TYPE_SRT_ONLY 4 /* Subtitle SRT ONLY */ -#define SERVICE_TYPE_REC_ONLY_AUDIO 5 /* Subtitle AUDIO ONLY */ - using namespace Tradutor; -//using namespace Util; +using namespace jthread; using namespace std; -using namespace sndesc; -class ServiceWindowGeneration : public ListenerTradutor, public ListenerSynchronizer{ +class ServiceWindowGeneration { protected: + TradutorPortGlosa* tradutor; + Synchronizer* sincronizador; + PropertyHandler* ppty_h; + Mixer* mixer; + + vector* vetor_pts; - TradutorPortGlosa * tradutor; - //HttpStreamer *sincronizador; - Synchronizer * sincronizador; - //InputFile * inputfile; - Mixer * mixer; - PropertyHandler* reader; + bool finish; + bool running; - vector * vetor_pts; - - char* path_input; - char* path_audio; + char* path_input; char* path_libras; + char* path_contents; + char* path_uploads; char* client_type; char* user_id; - bool running; + int size; + int position; + int transparency; + int sub_language; + int service_type; + int numero_legendas; + int legendas_enviadas; + + virtual void setSizeOfSubtitles(int sub_size) = 0; + virtual void setPathContents() = 0; + virtual void setPathLibras() = 0; + virtual void setBackground() = 0; + + //virtual void transcodeVideoToWebm(); + virtual void transcodeVideoToMp4() = 0; - int size, position, transparency, sublanguage, serviceType, numero_legendas, legendas_enviadas; - - void setSize(int); - void setPosition(int); - void setTransparency(int); - void setSubLanguage(int sublang); - void setServiceType(int type); - void setUserId(char* _userId); - void setClientType(char* client_type); - void setPathInput(char* _path_input); - - void transcodeVideoToWebm(); - void transcodeVideoToMp4(); - void createThumbnail(); - public: - - ServiceWindowGeneration(); - ~ServiceWindowGeneration(); - - virtual void notifyTranslation(vector* glosas); - virtual void notifyEndOfSynchronization(); - - void initialize(); - bool isRunning(); - - char* getPathLibras(); - char* getUserId(); - char* getClientType(); - char* getPathInput(); - string getPathAPI(); - TradutorPortGlosa * getTradutor(); - - void setPathLibras(); - void setSizeOfSubtitles(int sub_size); - void adicionaPTS(int64_t pts); + virtual void initialize() = 0; + virtual bool isFinished() = 0; + virtual void notifyTranslator(unsigned char* text) = 0; }; -#endif /* SERVICEWINDOWGENERATION_H */ +#endif /* SERVICEWINDOWGENERATION_H */ \ No newline at end of file diff --git a/servico/src/include/serviceWindowGenerationFromREC.h b/servico/src/include/serviceWindowGenerationFromREC.h deleted file mode 100644 index dfe40e7..0000000 --- a/servico/src/include/serviceWindowGenerationFromREC.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef SERVICEWINDOWGENERATIONFROMREC_H -#define SERVICEWINDOWGENERATIONFROMREC_H - -#include -#include -#include "jthread.h" -#include "serviceWindowGeneration.h" -#include "recognize.h" -#include "inputFile.h" - -using namespace std; -using namespace jthread; - -class ServiceWindowGenerationFromREC : public ServiceWindowGeneration, public RecognizeListener, public Thread { - -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, char* client_type, int _serviceType); - ~ServiceWindowGenerationFromREC(); - - virtual void notifyTextRecognized(unsigned char* text, int64_t pts); - virtual void notifyEnd(int sentences_size); - void notifyTranslator(unsigned char *text); - - void initialize(); - bool isFinished(); - void Run(); -}; - -#endif /* SERVICEWINDOWGENERATIONFROMREC_H */ diff --git a/servico/src/include/serviceWindowGenerationFromRec.h b/servico/src/include/serviceWindowGenerationFromRec.h new file mode 100644 index 0000000..25fbbe3 --- /dev/null +++ b/servico/src/include/serviceWindowGenerationFromRec.h @@ -0,0 +1,43 @@ +#ifndef SERVICEWINDOWGENERATIONFROMREC_H +#define SERVICEWINDOWGENERATIONFROMREC_H + +#include "recognize.h" +#include "recognizeListener.h" +#include "serviceWindowGeneration.h" + +#define SERVICE_TYPE_REC 2 +#define SERVICE_TYPE_REC_ONLY_AUDIO 5 + +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerSynchronizer, public Thread { + +private: + Recognize* rec; + + void addPTS(int64_t pts); + void setSizeOfSubtitles(int sub_size); + void setPathContents(); + void setPathLibras(); + void setBackground(); + + void transcodeVideoToMp4(); + void createThumbnail(); + 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, + int transp, char* id, char* client, int serviceType); + ~ServiceWindowGenerationFromRec(); + + void notifyTextRecognized(unsigned char* text, int64_t pts); + void notifyTranslation(vector* glosas); + void notifyTranslator(unsigned char* text); + void notifyEndOfSynchronization(); + void notifyEnd(int sentences_size); + + void initialize(); + bool isFinished(); + void Run(); +}; + +#endif /* SERVICEWINDOWGENERATIONFROMREC_H */ \ No newline at end of file diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index 81168b6..7e76f63 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -1,49 +1,47 @@ #ifndef SERVICEWINDOWGENERATIONFROMSRT_H -#define SERVICEWINDOWGENERATIONFROMSRT_H +#define SERVICEWINDOWGENERATIONFROMSRT_H -#include "serviceWindowGeneration.h" -#include -#include "inputFile.h" -#include "extratorFactory.h" #include "listenerSRT.h" -#include "stdint.h" -#include -#include "jthread.h" - -#define SRT 1 +#include "extratorFactory.h" +#include "serviceWindowGeneration.h" -using namespace std; -using namespace jthread; -using namespace Util; +#define SERVICE_TYPE_SRT 1 +#define SERVICE_TYPE_SRT_ONLY 4 -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public Thread { +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerSynchronizer, public Thread { private: - pthread_mutex_t *mutex_serviceSRT; - ExtratorFactory *extrator_factory; - ExtratorSRT * extratorSRT; - char* path_srt; - bool finish; - -public: + ExtratorFactory* extrator_factory; + ExtratorSRT* extratorSRT; - /* Construtor 1 - legenda e vídeo */ - ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, - int position, int size, int transparency, char* id, char* client_type, int _serviceType); - /* Construtor 2 - só legenda */ - ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, char* client_type, int _serviceType); + char* path_srt; + + void addPTS(int64_t pts); + void setSizeOfSubtitles(int sub_size); + void setPathContents(); + void setPathLibras(); + void setBackground(); + + void transcodeVideoToMp4(); + void createThumbnail(); + bool isRunning(); +public: + //construtor de serviço de video e legenda + 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(); - - virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); - virtual void notifyEnd(int sub_size); - void notifyTranslator(unsigned char* subtitle); + + void notifySubtitle(unsigned char* subtitle, int64_t pts); + void notifyTranslation(vector* glosas); + void notifyTranslator(unsigned char* text); + void notifyEndOfSynchronization(); + void notifyEnd(int sub_size); void initialize(); bool isFinished(); void Run(); - - void setPathSRT(char* path_srt); - }; -#endif /* SERVICEWINDOWGENERATIONFROMSRT_H */ +#endif /* SERVICEWINDOWGENERATIONFROMSRT_H_ */ \ No newline at end of file diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index cda8985..2fec3f9 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -1,31 +1,38 @@ -#ifndef _SERVICEWINDOWGENERATIONFROMTEXT_H -#define _SERVICEWINDOWGENERATIONFROMTEXT_H +#ifndef SERVICEWINDOWGENERATIONFROMTEXT_H +#define SERVICEWINDOWGENERATIONFROMTEXT_H -#include "serviceWindowGeneration.h" -#include "extratorFactory.h" #include "listenerTXT.h" +#include "extratorFactory.h" +#include "serviceWindowGeneration.h" -#define TXT 2 -/*FIXME: está restrito a 2K bytes de texto */ -#define MAX_TEXT_SIZE 2048 +#define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerSynchronizer, public Thread { private: - ExtratorFactory *extrator_factory; - ExtratorTXT * extratorTXT; - bool finish; - + ExtratorFactory* extrator_factory; + ExtratorTXT* extratorTXT; + + void setSizeOfSubtitles(int sub_size); + void setPathContents(); + void setPathLibras(); + void setBackground(); + + void transcodeVideoToMp4(); + bool isRunning(); public: - ServiceWindowGenerationFromText (char* _path_file, char* user_id, int _transp, int _serviceType, char* _client_type); - ~ServiceWindowGenerationFromText (); + ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); + ~ServiceWindowGenerationFromText(); void notifyLine(unsigned char* line); + void notifyTranslation(vector* glosas); + void notifyTranslator(unsigned char* text); + void notifyEndOfSynchronization(); void notifyEnd(int line_size); void initialize(); bool isFinished(); - void Run(); + void Run(); }; -#endif /* _SERVICEWINDOWGENERATIONFROMTEXT_H */ +#endif /* SERVICEWINDOWGENERATIONFROMTEXT_H */ \ No newline at end of file diff --git a/servico/src/serviceException.cpp b/servico/src/serviceException.cpp index e58a6a4..2b9fce8 100644 --- a/servico/src/serviceException.cpp +++ b/servico/src/serviceException.cpp @@ -11,10 +11,10 @@ - #include "serviceException.h" +#include "serviceException.h" - ServiceException::ServiceException(const std::string message) - : RuntimeException(message) + ServiceException::ServiceException(const std::string message) + : RuntimeException(message) { /* TODO */ } ServiceException::ServiceException(const char* message) : RuntimeException(message) diff --git a/servico/src/serviceWindowGeneration.cpp b/servico/src/serviceWindowGeneration.cpp deleted file mode 100644 index ca81211..0000000 --- a/servico/src/serviceWindowGeneration.cpp +++ /dev/null @@ -1,283 +0,0 @@ - -#include "serviceWindowGeneration.h" - -ServiceWindowGeneration::ServiceWindowGeneration() { - tradutor = new TradutorPortGlosa(); - vetor_pts = new vector(); - try{ - reader = new PropertyHandler("vlibras_user/.vlibras-conf/configuration/params-vbox.conf"); - }catch(RuntimeException &ex){printf("%s\n", ex.getMessage().c_str());} - numero_legendas = INT_MAX; - legendas_enviadas = 0; - this->running = true; - serviceType = 0; - DPRINTF("Done!\n"); -} - -ServiceWindowGeneration::~ServiceWindowGeneration() { - free(vetor_pts); - free(path_libras); - if (mixer) delete mixer; - if (tradutor) delete tradutor; - if (sincronizador) delete sincronizador; - DDDPRINTF("Service finalized!\n"); -} - -char* ServiceWindowGeneration::getPathLibras() { - return path_libras; -} - -char* ServiceWindowGeneration::getPathInput() { - return path_input; -} - -string ServiceWindowGeneration::getPathAPI() { - return PATH_API; -} - -char* ServiceWindowGeneration::getClientType(){ - return client_type; -} - -char* ServiceWindowGeneration::getUserId() { - return user_id; -} - -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; -} - -void ServiceWindowGeneration::setPosition(int position){ - this->position = position; -} - -void ServiceWindowGeneration::setTransparency(int transparency){ - this->transparency = transparency; -} - -void ServiceWindowGeneration::setPathLibras() { - - char* final_path = new char[MAX_SIZE_PATH]; - - if(strcmp(client_type, (char*)WEB_USER) == 0){ - strcpy(final_path, "vlibras_user/vlibras-api/uploads/"); - strcat(final_path, this->user_id); - strcat(final_path, "/libras.ts"); - }else{ - strcpy(final_path, PATH_CONTENTS); - 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, this->client_type); - createThumbnail(); - }else{ - transcodeVideoToMp4(); - } - this->running = false; -} - -void ServiceWindowGeneration::initialize() { - - setPathLibras(); - - if (this->sublanguage == 1) { - tradutor->addListener(this); - } - - // o path do arquivo só poderá conter um "."(ponto), esse identifica a extensão. - - vector tokens; - /* Se for texto não é necessário vídeo de entrada (path_input) */ - if (serviceType != SERVICE_TYPE_TEXT && serviceType != SERVICE_TYPE_SRT_ONLY && - serviceType != SERVICE_TYPE_REC_ONLY_AUDIO) { - char * pathtmp = this->path_input; - int size = strlen(pathtmp); - char vtemp [size]; - strcpy(vtemp, pathtmp); - pathtmp = strtok(vtemp, "."); - while (pathtmp != NULL) { - tokens.push_back(string(pathtmp)); - pathtmp = strtok(NULL, "."); - } - string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; - this->path_libras = new char[buildstrpath.size()]; - strcpy(this->path_libras, buildstrpath.c_str()); - //printf("O ServiceWGeneration montou o seguinte path para o vídeo de Libras: %s\n", path_libras); - - } else { - tradutor->addListener(this); - } - - if(this->transparency == 0) { //pega dicionario com BackGround opaco - sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, - this->path_libras, this->transparency); - } else { - if(this->transparency == 1) { //pega dicionario com BackGround transparente - sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, - this->path_libras,this->transparency); - } - } - - if (serviceType != SERVICE_TYPE_SRT) { - uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro - sincronizador->setPCRBase(pcr_base); - } - sincronizador->addListener(this); - sincronizador->Start(); -} - -/* Método utilizado pelo Tradutor para notificar o texto traduzido. */ -void ServiceWindowGeneration::notifyTranslation(vector * glosas) { - - if (serviceType != SERVICE_TYPE_TEXT) { - for (int i = 0; i < glosas->size(); i++) { - std::locale loc; - std::string glosa_lower = ""; - for (int k = 0; k < glosas->at(i).length(); k++) - glosa_lower += std::tolower(glosas->at(i).at(k), loc); - - //cout << "__Glosa [" << i << "] = " << glosa_lower << endl; - int64_t pts_notificado = vetor_pts->front(); - sincronizador->recebeglosa(glosa_lower, pts_notificado); - } - /* O 'numero_legendas' é informado pela subclasse através do método setSizeOfSubtitles. - Então, inicialmente, seu valor corresponde a um número inteiro máximo. - */ - /*printf("numero_legendas = %d\nlegendas_enviadas = %d\n", numero_legendas, legendas_enviadas); - if (legendas_enviadas >= numero_legendas) { - sincronizador->stop(); - }*/ - vetor_pts->erase(vetor_pts->begin()); - } else { - //Nova versão! - for (int i = 0; i < glosas->size(); i++) { - std::locale loc; - std::string glosa_lower = ""; - for (int k = 0; k < glosas->at(i).length(); k++) - glosa_lower += std::tolower(glosas->at(i).at(k), loc); - - //cout << "__Glosa [" << i << "] = " << glosa_lower << endl; - sincronizador->recebeglosa(glosa_lower, 1000); - } - sincronizador->stop(); - } - legendas_enviadas++; -} - -void ServiceWindowGeneration::transcodeVideoToWebm() { - //printf("[INFO]: A transcodificação para .webm está ativada!\n"); - DDDPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); - string command = "ffmpeg -i "; - command.append(path_libras) - .append(" -vcodec libvpx -acodec libvorbis ") - //.append(" -v quiet ") - .append(PATH_API) - .append(getUserId()) - .append(".webm"); - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); - system(command.c_str()); -} - -void ServiceWindowGeneration::transcodeVideoToMp4() { - //if (serviceType == SERVICE_TYPE_TEXT && strcmp(client_type, (char*)"WEB") == 0) - // transcodeVideoToWebm(); - //else{ - //printf("[INFO]: A transcodificação para .mp4 está ativada!\n"); - DDDPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); - string command = "ffmpeg -i "; - command.append(path_libras) - .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 "); - //.append(" -v quiet "); - - if(strcmp(client_type, (char*)WEB_USER) == 0){ - command.append(PATH_API).append(getUserId()); - - }else{ - try{ - char* vPath = new char[256]; - vPath = reader->getAttributeValue("STORAGE"); - command.append(vPath).append("/").append(getUserId()); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); - } - } - - command.append(".mp4"); - //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); - system(command.c_str()); - - //.append(" -strict experimental -vcodec mjpeg -r 30 -pix_fmt yuvj422p ") - //.append(" -strict experimental -vcodec mpeg2video -r 30 ") - //} -} - -void ServiceWindowGeneration::createThumbnail(){ - string command = "ffmpeg -ss 10 -i "; - //command.append(PATH_API).append(user_id).append(".mp4") - //.append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 "); - //.append(" -v quiet "); - - if(strcmp(client_type, (char*)WEB_USER) == 0){ - command.append(PATH_API).append(user_id).append(".mp4") - .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ") - .append(PATH_API).append(getUserId()); - }else{ - try{ - char* pPath = new char[256]; - pPath = reader->getAttributeValue("STORAGE"); - command.append(pPath).append("/").append(getUserId()).append(".mp4"); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); - } - command.append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ") - .append(" -v quiet ") - .append(PATH_CONTENTS).append(getUserId()); - } - command.append(".png"); - system(command.c_str()); -} \ No newline at end of file diff --git a/servico/src/serviceWindowGenerationFromREC.cpp b/servico/src/serviceWindowGenerationFromREC.cpp deleted file mode 100644 index 52412f7..0000000 --- a/servico/src/serviceWindowGenerationFromREC.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "serviceWindowGenerationFromREC.h" - -ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( - char* path_video, int sublanguage, int position, int size, int transparency, char* id, int serviceType, char* rate) { - - setPathInput(path_video); - setSubLanguage(sublanguage); - setPosition(position); - setSize(size); - setTransparency(transparency); - setServiceType(serviceType); - setUserId(id); - rec = new Recognize(path_video, id, rate); - finish = false; - DPRINTF("Done!\n"); -} - -ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( - char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int serviceType) { - - setPathInput(path_video); - setSubLanguage(sublanguage); - setPosition(position); - setSize(size); - setTransparency(transparency); - setServiceType(serviceType); - setClientType(client_type); - setUserId(id); - if(strcmp(client_type, "web") == 0) - rec = new Recognize(path_video, id, 1);// parametro 1 indica que é um cliente web - else - rec = new Recognize(path_video, id, 0);// parametro 0 indica que é um cliente diferente, ex: cloud - - finish = false; - DPRINTF("Done!\n"); -} - -ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { - delete rec; - 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); - - ServiceWindowGeneration::initialize(); - - try{ - rec->initialize(); - } catch(RecognizeException ex){ - throw ServiceException(ex.getMessage()); - } - this->Start(); -} - -void ServiceWindowGenerationFromREC::Run() { - - while (isRunning()) { - usleep(200000); - } - finish = true; -} diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp new file mode 100644 index 0000000..887eff8 --- /dev/null +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -0,0 +1,224 @@ +#include "serviceWindowGenerationFromRec.h" + +ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( + char* pathVideo, int sublanguage, int pos, int size, int transp, char* id, 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->service_type = serviceType; + numero_legendas = INT_MAX; + legendas_enviadas = 0; + vetor_pts = new vector(); + rec = new Recognize(pathVideo, id, rate); + tradutor = new TradutorPortGlosa(); + running = true; + finish = false; + DPRINTF("Done!\n"); +} + +ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( + char* pathVideo, int sublanguage, 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; + this->user_id = id; + this->client_type = client; + this->service_type = serviceType; + numero_legendas = INT_MAX; + legendas_enviadas = 0; + vetor_pts = new vector(); + rec = new Recognize(path_input, id);// parametro 1 indica que é um cliente web + tradutor = new TradutorPortGlosa(); + setPathContents(); + running = true; + finish = false; + DPRINTF("Done!\n"); +} + +ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ + free(vetor_pts); + delete(ppty_h); + if (tradutor) delete tradutor; + if (rec) delete rec; + if (sincronizador) delete sincronizador; + if (mixer) delete mixer; + DDDPRINTF("Service Rec finished!\n"); +} + +void ServiceWindowGenerationFromRec::setPathContents(){ + if(strcmp(client_type,DEVELOPER) == 0){ + this->path_contents = PATH_DEVEL; + this->path_uploads = PATH_DEVEL_UPLOADS; + rec->setPathAudioContents(path_uploads); + }else if(strcmp(client_type, PRODUCTION) == 0){ + try{ + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); + }catch(RuntimeException &ex){ + printf("%s\n", ex.getMessage().c_str()); + } + this->path_uploads = PATH_VBOX_UPLOADS; + rec->setPathAudioContents(path_uploads); + }else{ + throw new ServiceException("Invalid client!"); + } +} + +void ServiceWindowGenerationFromRec::setPathLibras(){ + char* final_path = new char[MAX_SIZE_PATH]; + strcpy(final_path, this->path_uploads); + strcat(final_path, this->user_id); + strcat(final_path, "/video_libras.ts"); + + this->path_libras = final_path; +} + +void ServiceWindowGenerationFromRec::setBackground(){ + if(this->transparency == 0) { //pega dicionario com BackGround opaco + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, + this->path_libras, this->transparency); + } else { + if(this->transparency == 1) { //pega dicionario com BackGround transparente + 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(); +} + +void ServiceWindowGenerationFromRec::addPTS(int64_t pts){ + vetor_pts->push_back(pts); +} + +void ServiceWindowGenerationFromRec::notifyTranslator(unsigned char* text){ + tradutor->traduz(text); +} + +//Metodo utilizado pelo reconhecedor para avisar sobre novas sentenças reconhecidas +void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, int64_t pts){ + addPTS(pts); + 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; +} + +void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) { + 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); + } + int64_t pts_notificado = vetor_pts->front(); + sincronizador->recebeglosa(glosa_lower, pts_notificado); + } + vetor_pts->erase(vetor_pts->begin()); + legendas_enviadas++; +} + +void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ + DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); + setSizeOfSubtitles(sentences_size); +} + +bool ServiceWindowGenerationFromRec::isRunning(){ + return this->running; +} + +bool ServiceWindowGenerationFromRec::isFinished(){ + return this->finish; +} + +void ServiceWindowGenerationFromRec::initialize(){ + DPRINTF("Service REC Initialize.\n"); + rec->addListener(this); + setPathLibras(); + + if(this->sub_language == 1) + tradutor->addListener(this); + + if(this->service_type != SERVICE_TYPE_REC_ONLY_AUDIO){ + vector tokens; + char* pathtmp = this->path_input; + int size = strlen(pathtmp); + char vtemp [size]; + + strcpy(vtemp, pathtmp); + pathtmp = strtok(vtemp, "."); + while (pathtmp != NULL) { + tokens.push_back(string(pathtmp)); + pathtmp = strtok(NULL, "."); + } + + string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; + this->path_libras = new char[buildstrpath.size()]; + strcpy(this->path_libras, buildstrpath.c_str()); + //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); + + }else{ + tradutor->addListener(this); + } + + setBackground(); + + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro + sincronizador->setPCRBase(pcr_base); + sincronizador->addListener(this); + sincronizador->Start(); + + try{ + rec->initialize(); + } catch(RecognizeException ex){ + throw ServiceException(ex.getMessage()); + } + this->Start(); +} + +void ServiceWindowGenerationFromRec::transcodeVideoToMp4(){ + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); + string command = "ffmpeg -i "; + command.append(path_libras) + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") + .append(path_contents).append(user_id).append(".mp4"); + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); + system(command.c_str()); +} + +void ServiceWindowGenerationFromRec::createThumbnail(){ + string command = "ffmpeg -ss 10 -i "; + command.append(path_contents).append(user_id).append(".mp4") + .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") + .append(path_contents).append(user_id).append(".png"); + //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); + system(command.c_str()); +} + +void ServiceWindowGenerationFromRec::Run(){ + while(isRunning()){ + usleep(200000); + } + finish = true; +} \ No newline at end of file diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index b934928..dc8b8ce 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -1,45 +1,106 @@ #include "serviceWindowGenerationFromSRT.h" +ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, char* pathSRT, int sublanguage, + int pos, int size, int transp, char* id, char* client, int serviceType) { + + this->path_input = pathVideo; + this->path_srt = pathSRT; + 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; + vetor_pts = new vector(); + tradutor = new TradutorPortGlosa(); + extrator_factory = new ExtratorFactory(); + setPathContents(); + running = true; + finish = false; + DPRINTF("Done!\n"); +} -//Construtor Service 1 -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, - int position, int size, int transparency, char* id, char* client_type, int serviceType) { - +ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int transp, char* id, char* client, int serviceType) { + + this->path_srt = pathSRT; + this->transparency = transp; + this->user_id = id; + this->client_type = client; + this->service_type = serviceType; + numero_legendas = INT_MAX; + legendas_enviadas = 0; + vetor_pts = new vector(); + tradutor = new TradutorPortGlosa(); extrator_factory = new ExtratorFactory(); - setPathInput(path_video); - setPathSRT(path_srt); - setClientType(client_type); - setPosition(position); - setSize(size); - setTransparency(transparency); - setSubLanguage(sublanguage); - setServiceType(serviceType); - setUserId(id); - finish = false; - DPRINTF("Done!\n"); -} - -//Construtor Service 4 -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, char* client_type, int serviceType) { - - extrator_factory = new ExtratorFactory(); - setPathInput(path_srt); - setClientType(client_type); - setTransparency(transparency); - setServiceType(serviceType); - setUserId(id); - finish = false; - DPRINTF("Done!\n"); + setPathContents(); + running = true; + finish = false; + DPRINTF("Done!\n"); } ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { - if (mutex_serviceSRT) delete mutex_serviceSRT; - delete extratorSRT; + free(vetor_pts); + delete(ppty_h); + if (mixer) delete mixer; + if (tradutor) delete tradutor; + if (sincronizador) delete sincronizador; + if (extratorSRT)delete extratorSRT; + if (extrator_factory) delete extrator_factory; DDDPRINTF("Service SRT finalized!\n"); } -void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { +void ServiceWindowGenerationFromSRT::setPathContents() { + if(strcmp(client_type,DEVELOPER) == 0){ + this->path_contents = PATH_DEVEL; + this->path_uploads = PATH_DEVEL_UPLOADS; + }else if(strcmp(client_type, PRODUCTION) == 0){ + try{ + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); + }catch(RuntimeException &ex){ + printf("%s\n", ex.getMessage().c_str()); + } + this->path_uploads = PATH_VBOX_UPLOADS; + }else{ + throw new ServiceException("Invalid client!"); + } +} + +void ServiceWindowGenerationFromSRT::setPathLibras() { + char* final_path = new char[MAX_SIZE_PATH]; + strcpy(final_path, this->path_uploads); + strcat(final_path, this->user_id); + strcat(final_path, "/video_libras.ts"); + + this->path_libras = final_path; +} + +void ServiceWindowGenerationFromSRT::setBackground() { + if(this->transparency == 0) { //pega dicionario com BackGround opaco + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, + this->path_libras, this->transparency); + } else { + if(this->transparency == 1) { //pega dicionario com BackGround transparente + 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(); +} + +void ServiceWindowGenerationFromSRT::addPTS(int64_t pts){ + vetor_pts->push_back(pts); +} + +void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { const char* constchar = (const char*) subtitle; char* legenda_copy = new char[strlen(constchar)+1]; strcpy(legenda_copy, constchar); @@ -48,67 +109,122 @@ void ServiceWindowGenerationFromSRT::notifyTranslator(unsigned char* subtitle) { } void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int64_t pts){ - adicionaPTS(pts); - notifyTranslator(subtitle); + addPTS(pts); + notifyTranslator(subtitle); } -bool ServiceWindowGenerationFromSRT::isFinished(){ - return finish; +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++) { + 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); + } + int64_t pts_notificado = vetor_pts->front(); + sincronizador->recebeglosa(glosa_lower, pts_notificado); + } + vetor_pts->erase(vetor_pts->begin()); + legendas_enviadas++; } void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { - DDPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); + DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); setSizeOfSubtitles(sub_size); } -void ServiceWindowGenerationFromSRT::setPathSRT(char* path_srt) { - this->path_srt = path_srt; +bool ServiceWindowGenerationFromSRT::isRunning() { + return this->running; +} + +bool ServiceWindowGenerationFromSRT::isFinished() { + return this->finish; } void ServiceWindowGenerationFromSRT::initialize() { + DPRINTF("Service SRT Initialize.\n"); + extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT); + extratorSRT->addListener(this); + extratorSRT->setFilePath(path_srt); - DDPRINTF("Service SRT Initialize.\n"); + setPathLibras(); + + if (this->sub_language == 1) + tradutor->addListener(this); - //codigo abaixo sera arrumado apos a aplicação do factory pattern - - if(serviceType == 1){ - - extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); - extratorSRT->addListener(this); - extratorSRT->setFilePath(path_srt); - - ServiceWindowGeneration::initialize(); - - try{ - extratorSRT->initialize(); - }catch(ExtratorException ex){ - throw ServiceException(ex.getMessage()); - } - 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().*/ - extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); - extratorSRT->addListener(this); - extratorSRT->setFilePath(path_input); - - ServiceWindowGeneration::initialize(); - - try{ - extratorSRT->initialize(); - }catch(ExtratorException ex){ - throw ServiceException(ex.getMessage()); - } - this->Start(); + if(this->service_type != SERVICE_TYPE_SRT_ONLY){ + vector tokens; + char* pathtmp = this->path_input; + int size = strlen(pathtmp); + char vtemp [size]; + + strcpy(vtemp, pathtmp); + pathtmp = strtok(vtemp, "."); + while (pathtmp != NULL) { + tokens.push_back(string(pathtmp)); + pathtmp = strtok(NULL, "."); + } + + string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; + this->path_libras = new char[buildstrpath.size()]; + strcpy(this->path_libras, buildstrpath.c_str()); + //printf("O Serviço montou o seguinte path para o vídeo de Libras: %s\n", path_libras); + + }else{ + tradutor->addListener(this); + } + + setBackground(); + + if (service_type != SERVICE_TYPE_SRT) { + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro + sincronizador->setPCRBase(pcr_base); + } + + sincronizador->addListener(this); + sincronizador->Start(); + + try{ + extratorSRT->initialize(); + }catch(ExtratorException ex){ + throw ServiceException(ex.getMessage()); } + this->Start(); +} +void ServiceWindowGenerationFromSRT::transcodeVideoToMp4(){ + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); + string command = "ffmpeg -i "; + command.append(path_libras) + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") + .append(path_contents).append(user_id).append(".mp4"); + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); + system(command.c_str()); } -void ServiceWindowGenerationFromSRT::Run() { - while (isRunning()) { - usleep(200000); //200ms - } - finish = true; +void ServiceWindowGenerationFromSRT::createThumbnail(){ + string command = "ffmpeg -ss 10 -i "; + command.append(path_contents).append(user_id).append(".mp4") + .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 ").append(" -v quiet ") + .append(path_contents).append(user_id).append(".png"); + //printf("[INFO]: Thumbnail command -> %s\n", command.c_str()); + system(command.c_str()); } + +void ServiceWindowGenerationFromSRT::Run() { + while(isRunning()){ + usleep(200000); + } + finish = true; +} \ No newline at end of file diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index b81d08f..91a78c3 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -1,43 +1,133 @@ #include "serviceWindowGenerationFromText.h" -ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( - char* path_file, char* username, int transp, int serviceType, char* client_type) { - - extrator_factory = new ExtratorFactory(); - setPathInput(path_file); - setClientType(client_type); - setUserId(username); - setTransparency(transp); - setServiceType(serviceType); +ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, int transp, char* id, char* client) { + this->path_input = pathFile; + this->transparency = transp; + this->user_id = id; + client_type = client; + running = true; finish = false; + numero_legendas = INT_MAX; + legendas_enviadas = 0; + vetor_pts = new vector(); + tradutor = new TradutorPortGlosa(); + extrator_factory = new ExtratorFactory(); + setPathContents(); + running = true; + finish = false; + DPRINTF("Done!\n"); } ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { - delete extratorTXT; - DDDPRINTF("Service Text finished!\n"); + free(vetor_pts); + delete(ppty_h); + if (tradutor) delete tradutor; + if (sincronizador) delete sincronizador; + if (extratorTXT)delete extratorTXT; + if (extrator_factory) delete extrator_factory; + DDDPRINTF("Service Text finalized!\n"); +} + +void ServiceWindowGenerationFromText::setPathContents() { + if(strcmp(client_type,DEVELOPER) == 0){ + this->path_contents = PATH_DEVEL; + this->path_uploads = PATH_DEVEL_UPLOADS; + }else if(strcmp(client_type, PRODUCTION) == 0){ + try{ + ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); + this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); + }catch(RuntimeException &ex){ + printf("%s\n", ex.getMessage().c_str()); + } + this->path_uploads = PATH_VBOX_UPLOADS; + }else{ + throw new ServiceException("Invalid client!"); + } +} + +void ServiceWindowGenerationFromText::setPathLibras() { + char* final_path = new char[MAX_SIZE_PATH]; + strcpy(final_path, this->path_uploads); + strcat(final_path, this->user_id); + strcat(final_path, "/video_libras.ts"); + + this->path_libras = final_path; +} + +void ServiceWindowGenerationFromText::setBackground() { + if(this->transparency == 0) { //pega dicionario com BackGround opaco + sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, + this->path_libras, this->transparency); + } else { + if(this->transparency == 1) { //pega dicionario com BackGround transparente + 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(); +} + +void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { + tradutor->traduz(text); } void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { - tradutor->traduz(line); + notifyTranslator(line); +} + +void ServiceWindowGenerationFromText::notifyEndOfSynchronization() { + transcodeVideoToMp4(); + this->running = false; } +void ServiceWindowGenerationFromText::notifyTranslation(vector * glosas) { + 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); + } + sincronizador->recebeglosa(glosa_lower, 1000); + } + sincronizador->stop(); + legendas_enviadas++; +} + + void ServiceWindowGenerationFromText::notifyEnd(int line_size) { - DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size); + DPRINTF("Service Text recebeu: %d linhas.\n", line_size); setSizeOfSubtitles(line_size); } +bool ServiceWindowGenerationFromText::isRunning() { + return this->running; +} + bool ServiceWindowGenerationFromText::isFinished() { - return finish; + return this->finish; } void ServiceWindowGenerationFromText::initialize() { - DDPRINTF("Service Text Initialize.\n"); - - extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(TXT); + DPRINTF("Service Text Initialize.\n"); + extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT); extratorTXT->addListener(this); - extratorTXT->setFilePath(getPathInput()); - - ServiceWindowGeneration::initialize(); + extratorTXT->setFilePath(path_input); + + setPathLibras(); + + tradutor->addListener(this); + + setBackground(); + + uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro + sincronizador->setPCRBase(pcr_base); + sincronizador->addListener(this); + sincronizador->Start(); try{ extratorTXT->initialize(); @@ -47,9 +137,19 @@ void ServiceWindowGenerationFromText::initialize() { this->Start(); } -void ServiceWindowGenerationFromText::Run() { - while (isRunning()) { - usleep(200000); //200ms - } - finish = true; +void ServiceWindowGenerationFromText::transcodeVideoToMp4(){ + DPRINTF("[AGUARDE] Transcodificando o vídeo de Libras...\n"); + string command = "ffmpeg -i "; + command.append(path_libras) + .append(" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 ").append(" -v quiet ") + .append(path_contents).append(user_id).append(".mp4"); + //printf("[INFO]: Transcodification command -> %s\n", command.c_str()); + system(command.c_str()); } + +void ServiceWindowGenerationFromText::Run(){ + while(isRunning()){ + usleep(200000); + } + finish = true; +} \ No newline at end of file diff --git a/synchronizer/src/synchronizer.cpp b/synchronizer/src/synchronizer.cpp index 1978f28..19852e9 100644 --- a/synchronizer/src/synchronizer.cpp +++ b/synchronizer/src/synchronizer.cpp @@ -175,27 +175,28 @@ char * Synchronizer::getproximoarquivo() { //proximo = NULL; if (videos->size() == 0) { - if(this->transparency == 0) - return VIDEO_PADRAO; - else - return VIDEOTRANSP_PADRAO; + if(this->transparency == 0){ + return VIDEO_PADRAO; + }else{ + return VIDEOTRANSP_PADRAO; + } } mutexi->Lock(); video = videos->front(); + videos->erase(videos->begin()); mutexi->Unlock(); if (video == NULL) { - if(this->transparency == 0) - return VIDEO_PADRAO; - else - return VIDEOTRANSP_PADRAO; - - } else { + if(this->transparency == 0){ + return VIDEO_PADRAO; + }else{ + return VIDEOTRANSP_PADRAO; + } + }else{ return video; } - } void Synchronizer::analisaPCR(unsigned char *pacote) { @@ -420,7 +421,6 @@ void Synchronizer::soletraGlosa(string glosa, int64_t pts) { return; char c = glosa[i]; if (c >= 97 && c <= 122) { - //cout << "soletrando a letra: " << glosa[i] << endl; string path2 = (string) baseDir + glosa[i] + (string) extensao; char* path2_char = converteString(path2); recebeglosa(converteString(path2), strlen(path2_char), pts); @@ -505,6 +505,7 @@ void Synchronizer::Run() { int desc_out = -1; while (videos_processed <= count_tasks || service_running) { + cnt = read(filefd, buff, bufferSize); // atualiza os valores de PCR e PTS/DTS para cada video @@ -551,8 +552,6 @@ void Synchronizer::Run() { contagemPCR = 0; ultimoPCRBaseMod = 0; } - - } else if (finalcnt == -1) { printf("Erro: Finalizando Sincronizador!\n"); this->stop(); diff --git a/util/src/include/property.h b/util/src/include/property.h index d1ae46d..f518d40 100644 --- a/util/src/include/property.h +++ b/util/src/include/property.h @@ -6,43 +6,60 @@ * João Pessoa - PB - Brasil * * * * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * - * Date: Qui Nov 28 14:05:39 BRT 2013 * + * Date: Mon Jun 1 19:29:50 BRT 2015 * * * **************************************************************************/ - #ifndef PROPERTY_H - #define PROPERTY_H + #ifndef PROPERTYHANDLER_H + #define PROPERTYHANDLER_H - #include "logger.h" #include #include + #include #include #include - #include + #include #include + #include #include #include #include - #define EXTENSION ".conf" - - using namespace std; using namespace lavidlib; - namespace sndesc { - - class PropertyHandler { + class PropertyHandler { public: - PropertyHandler(string filename); + enum HandlerMode { + READ, + WRITE + }; + PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode); virtual ~PropertyHandler(); - char* getAttributeValue(string attr); + + int attr_exists(char* _attr); + const char* get_attibute_value(char* _attr); + void set_attribute_value(char* _attr_p, char* _value_p); + void update_properties(); + int remove_attribute(char* _attr_p); private: - BufferedReader* rbuffer; - FileIO* file_property; - int checkFileExtension(string &filename); - }; - } + std::string filename; + File* file_p; + FileIO* file_io_p; + BufferedReader* buff_reader_p; + HandlerMode handler_mode; + + std::map * map_ppty_p; + + int check_file_extension(char* _filename); + void format_line_str(std::string* _line_str); + int load_properties(); + void init_write_mode(); + std::string get_key(std::string _ppty_line); + std::string get_value(std::string _ppty_line); + int write_properties_on_file(std::string _key, std::string _value, FILE* _file_output); + }; + - #endif /* PROPERTY_H */ \ No newline at end of file + #endif /* PROPERTYHANDLER_H */ \ No newline at end of file diff --git a/util/src/logger.cpp b/util/src/logger.cpp index 54573df..2d2b218 100644 --- a/util/src/logger.cpp +++ b/util/src/logger.cpp @@ -53,7 +53,7 @@ namespace Util { void Logger::writeInfoLog(char* filepath ,char* infoLog){ this->openInfoLogFile(filepath); - file << getTime(); + file << "READY="; file << infoLog << "\n\r"; this->closeLogFile(); } diff --git a/util/src/property.cpp b/util/src/property.cpp index a4ed104..612cc1e 100644 --- a/util/src/property.cpp +++ b/util/src/property.cpp @@ -6,74 +6,231 @@ * João Pessoa - PB - Brasil * * * * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * - * Date: Qui Nov 28 14:06:10 BRT 2013 * + * Date: Mon Jun 1 19:29:50 BRT 2015 * * * **************************************************************************/ - #include "property.h" +#include "property.h" + + +PropertyHandler::PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode) +{ + if ( check_file_extension(_filename) == -1 ) + throw new RuntimeException("Format file not is supported"); + + filename = (std::string) _filename; + handler_mode = _handler_mode; + + switch (handler_mode) + { + case READ: + if ( load_properties() <= 0 ) + throw new RuntimeException("Cannot to load properties of the file"); + break; + case WRITE: + init_write_mode(); + break; + default: + printf("Handler mode not supported"); + exit(1); + } + +} + + +PropertyHandler::~PropertyHandler() +{ + if (handler_mode == WRITE) + update_properties(); + + if (buff_reader_p) delete buff_reader_p; + if (file_io_p) delete file_io_p; + if (file_p) delete file_p; + if (map_ppty_p) delete map_ppty_p; + +} + + +int PropertyHandler::load_properties() +{ + std::string buff_str; + int buff_index = 0; + + file_p = new File(filename); + try { + file_io_p = new FileIO(file_p->getPath(), FileIO::MODE_READ); + } + catch(IOException &ex) { + printf("[ERROR] %s\n", ex.getMessage().c_str()); + exit(1); + } + + buff_reader_p = new BufferedReader(file_io_p); + map_ppty_p = new std::map(); + + try { + buff_str = buff_reader_p->readLine(); + + while (buff_str.size() > 0) + { + buff_index++; + format_line_str(&buff_str); + + map_ppty_p->insert(map_ppty_p->begin(), + (std::pair(get_key(buff_str), get_value(buff_str)))); + + /* get next line (key, value) */ + buff_str = buff_reader_p->readLine(); + } + + } catch (EOFException &ex) { + printf("[ERROR] %s\n", ex.getMessage().c_str()); + } + + return buff_index; + +} + + +void PropertyHandler::init_write_mode() +{ + /* init map structure to manipulate the properties in WRITE mode */ + map_ppty_p = new std::map(); +} + + +int PropertyHandler::attr_exists(char* _attr) +{ + std::map::iterator it; + if ( (it = map_ppty_p->find((const char*) _attr)) != map_ppty_p->end() ) + return 1; + return 0; +} + +const char* PropertyHandler::get_attibute_value(char* _attr) +{ + if (attr_exists(_attr)) + { + return (map_ppty_p->find((const char*) _attr)->second).c_str(); + } + return _attr; +} - using namespace std; - namespace sndesc { +void PropertyHandler::set_attribute_value(char* _attr_p, char* _value_p) +{ + if (handler_mode == PropertyHandler::READ) + throw new RuntimeException("Cannot set properties in the READ mode"); + + if (attr_exists(_attr_p)) + throw new RuntimeException("This attribute already exists"); + + map_ppty_p->insert(map_ppty_p->begin(), + (std::pair((std::string) _attr_p, (std::string) _value_p))); +} + + +void PropertyHandler::update_properties() +{ + FILE* file_output_p; + file_output_p = fopen (filename.c_str(), "w"); + if (file_output_p == NULL) + throw new IOException("Cannot open file to write properties"); + fseek(file_output_p, 0, SEEK_SET); + + std::string str_properties; + + std::map::iterator it; + for (it = map_ppty_p->begin(); it != map_ppty_p->end(); it++) + if ( write_properties_on_file(it->first, it->second, file_output_p) == 0 ) + throw new IOException("Error to write properties in the file"); + + fclose (file_output_p); +} + + +int PropertyHandler::write_properties_on_file(std::string _key, std::string _value, FILE* _file_output) +{ + std::string str_properties = _key; + str_properties.append("="); + str_properties.append(_value); + + int count_bytes = 0; + + count_bytes += fputs((char*) str_properties.c_str(), _file_output); + count_bytes += fputs("\n", _file_output); + + return count_bytes; +} + +//TODO +int PropertyHandler::remove_attribute(char* _attr_p) +{ + + if (attr_exists(_attr_p)) { + + if ( map_ppty_p->erase((const char*) _attr_p) != 1 ) + throw new RuntimeException("Cannot remove attribute of the map structure"); + + /* if delete the attribute corretly, update the map of the properties */ + update_properties(); + return 1; + } + return 0; +} + + +#define CONF_FILE_EXTENSION ".conf" +/** + Verify if the file extension is valid. +*/ +int PropertyHandler::check_file_extension(char* _filename) +{ + return ((std::string) _filename).find(CONF_FILE_EXTENSION); +} + +#undef CONF_FILE_EXTENSION /* .conf */ + + +#define CHAR_TO_REMOVE " \t" +/** + Remove all whitespaces in the text line. +*/ +void PropertyHandler::format_line_str(std::string* _line_str) +{ + int index = -1; + std::string chars_rm_str = (std::string) CHAR_TO_REMOVE; + for (int i = 0; i < chars_rm_str.size(); i++) + { + while ( (index = (int) _line_str->find(chars_rm_str[i]) ) != std::string::npos) + { + _line_str->replace(index, 1, ""); // remove whitespaces (" ") replacing your position by "" + } + } +} +#undef CHAR_TO_REMOVE + +#define TOKEN_ATTR "=" +std::string PropertyHandler::get_key(std::string _ppty_line) +{ + int target_pos = -1; + target_pos = _ppty_line.find(TOKEN_ATTR); + + if (target_pos < 1) /* minimum lenght of a key (k=value) */ + throw new RuntimeException("Bad format sentence"); + + return (std::string) _ppty_line.substr(0, target_pos); +} - PropertyHandler::PropertyHandler(string filename) { - - try { - if (checkFileExtension(filename) != 1) - throw new RuntimeException("Format file not is recognized!"); - file_property = new FileIO(filename, FileIO::MODE_READ); - } catch (IOException &ex) { - printf("[FAILED] Can't open file %s\n%s\n", filename.c_str(), - ex.getMessage().c_str()); - } - } - - PropertyHandler::~PropertyHandler() { - if (rbuffer) - delete rbuffer; - if (file_property) - delete file_property; - } - - char* PropertyHandler::getAttributeValue(string attr) { - - char* value1; - char* value2; - - rbuffer = new BufferedReader(file_property); - string fline; - try { - int target_pos = -1, begin = 0; - string attr_t, value_t; - while((fline = rbuffer->readLine()).size() > 0) { - target_pos = fline.find("="); - if (target_pos < 2) - throw new RuntimeException("The assignment symbol was not found."); - - attr_t = fline.substr(begin, target_pos); - begin = target_pos+1; - value_t = fline.substr(begin, fline.size()); - - if (attr.compare(attr_t) == 0) { - file_property->seek(0); - value1 = new char[value_t.length() + 1]; - strcpy(value1, value_t.c_str()); - return value1; - } - target_pos = -1; - begin = 0; - } - } catch (lavidlib::EOFException &ex) { - printf("[INFO] File is completed.\n%s\n", ex.getMessage().c_str()); - } - file_property->seek(0); - strcpy(value2, fline.c_str()); - return value2; - } - - int PropertyHandler::checkFileExtension(string &filename) { - - return (filename.find(EXTENSION) > 0 && - (filename.size() == (filename.find(EXTENSION) + strlen(EXTENSION)))) ? 1 : -1; - } - } \ No newline at end of file + +std::string PropertyHandler::get_value(std::string _ppty_line) +{ + int target_pos = -1; + target_pos = _ppty_line.find(TOKEN_ATTR); + + if (target_pos < 1) /* minimum lenght of a key (k=value) */ + throw new RuntimeException("Bad format sentence"); + + return (std::string) _ppty_line.substr(target_pos+1, _ppty_line.size()); +} +#undef TOKEN_ATTR \ No newline at end of file -- libgit2 0.21.2