From 23dddcacb96326a92a256dd0181bbd08d3040941 Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Wed, 27 May 2015 10:14:30 -0300 Subject: [PATCH] Atualização (VLibras-Box) --- Makefile | 3 ++- main.cpp | 446 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mixer/src/Mixer.cpp | 37 +++++++++++++++++++++++++++++-------- mixer/src/include/Mixer.h | 11 ++++++++--- servico/src/include/serviceWindowGeneration.h | 22 +++++++++++++--------- servico/src/include/serviceWindowGenerationFromREC.h | 2 +- servico/src/include/serviceWindowGenerationFromSRT.h | 4 ++-- servico/src/include/serviceWindowGenerationFromText.h | 3 +-- servico/src/serviceWindowGeneration.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- servico/src/serviceWindowGenerationFromREC.cpp | 3 ++- servico/src/serviceWindowGenerationFromSRT.cpp | 29 +++++++++++++++++++++-------- servico/src/serviceWindowGenerationFromText.cpp | 1 - util/src/include/logger.h | 5 ++++- util/src/include/property.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ util/src/logger.cpp | 13 +++++++++++-- util/src/property.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 500 insertions(+), 289 deletions(-) create mode 100644 util/src/include/property.h create mode 100644 util/src/property.cpp diff --git a/Makefile b/Makefile index 049dcc9..d83ac4e 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ INCLUDES= \ #-I libs/jthread/include -I libs/jcommon/include -I libs/jsocket/include -Wall utilObjs= \ - logger.o + logger.o \ + property.o tradutorObjs = \ pyTradutor.o \ diff --git a/main.cpp b/main.cpp index a479d90..e17f245 100644 --- a/main.cpp +++ b/main.cpp @@ -16,22 +16,27 @@ #include "serviceWindowGenerationFromREC.h" #include "serviceWindowGenerationFromText.h" #include "serviceException.h" +#include "property.h" #include #include +#define BLOQUEANTE 1 +#define NAO_BLOQUEANTE 2 +#define BOTH 3 + using namespace std; -void serviceCC(); -void serviceSRT(char* path_in, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* username); -void serviceOnlySRT(char* path_file, char* transparency, char* username); -void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username, char* rate); -void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username); -void serviceOnlyAudio(char* path_audio, char* transparency, char* username, char* rate); -void serviceOnlyAudio(char* path_audio, char* transparency, char* username); -void serviceText(char* path_text, char* transparency, char* username, char* client_type); +void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); +void serviceOnlySRT(char* service, char* path_file, char* transparency, char* username, char* client_type); +//void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username, char* rate); +void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); +//void serviceOnlyAudio(char* path_audio, char* transparency, char* username, char* rate); +void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type); +void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type); void help(); +void serviceHelp(int service); void fail(string msg); void hasFailed(); void hasInvalid(); @@ -47,74 +52,98 @@ int main(int argc, char* argv[]) { gettimeofday(&tv1, NULL); t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; + /*try{ + PropertyHandler* reader = new PropertyHandler(); + service-type = reader->getAttributeValue("SERVICE-TYPE"); + }catch(RuntimeException &ex){ + return; // escrever log aki + }*/ - printf("\n################## VLIBRAS : LAVID ##################\n\n"); - DDPRINTF("Service Type: %s\n", argv[1]); + //Util::Logger::Instance()->writeInfoLog("/home/wesnydy/.vlibras-conf/service/log-vbox", "VBox OK!"); - switch((int) atoi(argv[1])){ - case 1: - serviceCC(); - hasInvalid(); - break; - case 2: - if(argc <= 8){ - cout << "\nParametros inválidos. Tente novamente.\nService Type SRT: ./vlibras 2 INPUT_VIDEO INPUT_SRT LANGUAGE{1=Portuguese, 2=Glosa} POSITION{1=Top Left, 2=Top Right, 3=Bottom Right, 4=Bottom Left} SIZE{1=Small, 2=Medium, 3=Large} TRANSPARENCY{0=Opaque, 1=Transparent} ID" << endl; - help(); - hasInvalid(); + printf("\n################## VLIBRAS : LAVID ##################\n\n"); + + if(argc >= 2) { + + DDPRINTF("Service Type: %s\n", argv[1]); + + switch((int) atoi(argv[1])){ + + case 1: + //printf("[INFO] Serviço em manutenção!!!\n"); + //exit(0); + if(argc < 9){ + serviceHelp(1); + hasInvalid(); + break; + } + if(argc == 9) + serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], "user"); + else + serviceSRT(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); + break; - } - serviceSRT(argv[2], argv[3], argv[4], argv[5], - argv[6], argv[7], argv[8]); - break; - case 3: - if(argc <= 7){ - cout << "\nParametros inválidos. Tente novamente.\nService Type REC: ./vlibras 3 INPUT_VIDEO LANGUAGE{1=Portuguese, 2=Glosa} POSITION{1=Top Left, 2=Top Right, 3=Bottom Right, 4=Bottom Left} SIZE{1=Small, 2=Medium, 3=Large} TRANSPARENCY{0=Opaque, 1=Transparent} ID" << endl; - help(); - hasInvalid(); + case 2: + printf("[INFO] Serviço em manutenção!!!\n"); + exit(0); + if(argc < 7){ + serviceHelp(2); + hasInvalid(); + break; + } + if(argc == 7) + serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], "user"); + else + serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); break; - } - if (argc == 8) - serviceREC(argv[2], argv[3], argv[4], argv[5], - argv[6], argv[7]); - else - serviceREC(argv[2], argv[3], argv[4], argv[5], - argv[6], argv[7], argv[8]); - break; - case 4: - if(argc <= 5){ - cout << "\nParametros inválidos. Tente novamente.\nService Type Text: ./vlibras 4 INPUT_TEXT_FILE TRANSPARENCY{0=Opaque, 1=Transparent} ID CLIENT_TYPE{Desktop, Web}" << endl; - help(); - hasInvalid(); - break; - } - serviceText(argv[2], argv[3], argv[4], argv[5]); - break; - case 5: - if(argc <= 4){ - cout << "\nParametros inválidos. Tente novamente.\nService Type SRT Only: ./vlibras 5 INPUT_SRT TRANSPARENCY{0=Opaque, 1=Transparent} ID" << endl; - help(); - hasInvalid(); + case 3: + //printf("[INFO] Serviço em manutenção!!!\n"); + //exit(0); + if(argc < 5){ + serviceHelp(3); + hasInvalid(); + break; + } + if(argc == 5){ + serviceText(argv[1], argv[2], argv[3], argv[4], "user"); + } + serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); + break; + case 4: + printf("[INFO] Serviço em manutenção!!!\n"); + exit(0); + if(argc < 5){ + serviceHelp(4); + hasInvalid(); + break; + } + if(argc == 5 ) + serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], "user"); + 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){ + serviceHelp(5); + hasInvalid(); + break; + } + if (argc == 5) + serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], "user"); + else + serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); break; - } - serviceOnlySRT(argv[2], argv[3], argv[4]); - break; - case 6: - if(argc <= 4){ - cout << "\nParametros inválidos. Tente novamente.\nService Type REC: ./vlibras 6 INPUT_AUDIO TRANSPARENCY{0=Opaque, 1=Transparent} ID" << endl; - help(); - hasInvalid(); + default: + cout << "\nServiço inválido. Tente novamente." << endl; + help(); + hasInvalid(); break; - } - if (argc == 6) - serviceOnlyAudio(argv[2], argv[3], argv[4], argv[5]); - else - serviceOnlyAudio(argv[2], argv[3], argv[4]); - break; - default: - cout << "\nServiço inválido. Tente novamente." << endl; - help(); - hasInvalid(); - break; + } + }else{ + help(); + hasInvalid(); } if(isFailed) @@ -131,69 +160,33 @@ int main(int argc, char* argv[]) { } -void serviceCC(){ - - cout << "\n--> Serviço não disponível.\n" << endl; - /** - cout << "\nSERVICE CLOSED CAPTION\n" << endl; - filename = createFileToResponse((char*)argv[6]); // FIXME: [6] é transparency - - char* input_file = argv[2]; - int position = (int) atoi(argv[4]); - int size = (int) atoi(argv[5]); - int transparency = (int) atoi(argv[6]); +void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, + char* size, char* transparency, char* id, char* client_type){ - ServiceWindowGenerationFromCC *service; - service = new ServiceWindowGenerationFromCC( - input_file,position,size, transparency, 1); - - service->initialize(); - - while(service->isRunning()){ - sleep(5); - } - - char* id = (char*) argv[7]; - updateRequestStatus(filename.c_str(), id, "true"); - **/ -} - -void serviceREC(char* path_video, char* sublanguage, - char* position, char* size, char* transparency, char* id, char* rate){ - - ServiceWindowGenerationFromREC * service_rec; - service_rec = new ServiceWindowGenerationFromREC( - path_video, - (int) atoi(sublanguage), - (int) atoi(position), - (int) atoi(size), - (int) atoi(transparency), - id, 3, rate); + ServiceWindowGenerationFromSRT * service_srt; + service_srt = new ServiceWindowGenerationFromSRT(path_video, path_srt, (int) atoi(sublanguage), + (int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ - service_rec->initialize(); + service_srt->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; - } - while(!service_rec->isFinished()){ - sleep(2); + } + while(!service_srt->isFinished()){ + sleep(5); } - delete service_rec; + + delete service_srt; } -void serviceREC(char* path_video, char* sublanguage, - char* position, char* size, char* transparency, char* id){ +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), - (int) atoi(position), - (int) atoi(size), - (int) atoi(transparency), - id, 3); + 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{ service_rec->initialize(); @@ -208,73 +201,29 @@ void serviceREC(char* path_video, char* sublanguage, delete service_rec; } -void serviceSRT(char* path_in, char* path_srt, char* sublanguage, - char* position, char* size, char* transparency, char* id){ +void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ - - ServiceWindowGenerationFromSRT * service_srt; - service_srt = new ServiceWindowGenerationFromSRT( - path_in, path_srt, (int) atoi(sublanguage), - (int) atoi(position), (int) atoi(size), - (int) atoi(transparency), id, 2); - - try{ - service_srt->initialize(); - }catch(ServiceException ex){ - fail(ex.getMessage()); - hasFailed(); - return; - } - while(!service_srt->isFinished()){ - sleep(5); - } - - delete service_srt; - -} + ServiceWindowGenerationFromText *service_text; + service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), (int) atoi(service), client_type); -void serviceText(char* path_text, char* transparency, char* id, char* client_type){ - - if (strcmp(client_type, (char*)"WEB") == 0) { - ServiceWindowGenerationFromText *service_text; - service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, client_type); - try{ - service_text->initialize(); - }catch(ServiceException ex){ - fail(ex.getMessage()); - hasFailed(); - return; - } - - while (!service_text->isFinished()) { - usleep(100000); //100ms - } - delete service_text; - - } else { - - ServiceWindowGenerationFromText *service_text; - service_text = new ServiceWindowGenerationFromText(path_text, id, (int) atoi(transparency), 4, (char*)"IOS"); - try{ - service_text->initialize(); - }catch(ServiceException ex){ - fail(ex.getMessage()); - hasFailed(); - return; - } + try{ + service_text->initialize(); + }catch(ServiceException ex){ + fail(ex.getMessage()); + hasFailed(); + return; + } - while (!service_text->isFinished()) { - usleep(100000); //100ms - } - delete service_text; - } - + while (!service_text->isFinished()) { + usleep(100000); //100ms + } + delete service_text; } -void serviceOnlySRT(char* path_file, char* transparency, char* id){ +void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id, char* client_type){ ServiceWindowGenerationFromSRT * service_srt; - service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, 5); + service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_srt->initialize(); }catch(ServiceException ex){ @@ -290,16 +239,35 @@ void serviceOnlySRT(char* path_file, char* transparency, char* id){ } -void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate){ +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)); + + try{ + service_rec->initialize(); + }catch(ServiceException ex){ + fail(ex.getMessage()); + hasFailed(); + return; + } + while(!service_rec->isFinished()){ + sleep(2); + } + delete service_rec; +} + +/*void serviceREC(char* path_video, char* sublanguage, + char* position, char* size, char* transparency, char* id, char* rate){ ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC( - path_audio, - 0, - 0, - 0, + path_video, + (int) atoi(sublanguage), + (int) atoi(position), + (int) atoi(size), (int) atoi(transparency), - id, 6, rate); + id, 2, rate); try{ service_rec->initialize(); @@ -312,9 +280,9 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate sleep(2); } delete service_rec; -} +}*/ -void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ +/*void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate){ ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC( @@ -323,7 +291,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ 0, 0, (int) atoi(transparency), - id, 6); + id, 5, rate); try{ service_rec->initialize(); @@ -336,7 +304,7 @@ void serviceOnlyAudio(char* path_audio, char* transparency, char* id){ sleep(2); } delete service_rec; -} +}*/ void fail(string msg){ printf("\n"); @@ -352,45 +320,65 @@ void hasInvalid(){ isInvalid = true; } +void serviceHelp(int service){ + cout << "\nParâmetros inválidos! Tente novamente.\n"; + switch(service){ + case 1: + cout << "\nService Type: Video with Subtitles\n" + << "./vlibras INPUT_VIDEO INPUT_SRT LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " + << "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + case 2: + cout << "\nService Type: Video Recognize\n" + << "./vlibras INPUT_VIDEO LANGUAGE(1: Portuguese, 2:Glosa) POSITION(1: Top_Left, 2: Top_Right, 3: Bottom_Right, 4: Bottom_Left) " + << "SIZE(1: Small, 2: Medium, 3: Large) TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + case 3: + cout << "\nService Type: Text\n" + << "./vlibras INPUT_TEXT_FILE TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + case 4: + cout << "\nService Type: Subtitles only\n" + << "./vlibras INPUT_SRT TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + case 5: + cout << "\nService Type: Audio Recognize\n" + << "./vlibras INPUT_AUDIO TRANSPARENCY(0: Opaque, 1: Transparent) ID CLIENT_TYPE\n"; + break; + } +} //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" - <<"# 4 - means Text - requires INPUT_FILE_TEXT #\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" - <<"# INPUT_SRT: Path of the SRT file (only for SERVICE_TYPE = 2) #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# INPUT_FILE_TEXT: Path of the text file (doesn't use INPUT_VIDEO and INPUT_SRT) #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# INPUT_AUDIO: Path of the audio file" #\n - <<"#----------------------------------------------------------------------------------#\n" - <<"# LANGUAGE: 1 - means Portuguese #\n" - <<"# 2 - means Glosa #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# POSITION: 1 - means TOP_LEFT #\n" - <<"# 2 - means TOP_RIGHT #\n" - <<"# 3 - means BOTTOM_RIGHT #\n" - <<"# 4 - means BOTTOM_LEFT #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# SIZE: 1 - means SMALL #\n" - <<"# 2 - means MEDIUM #\n" - <<"# 3 - means LARGE #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# TRANSPARENCY: 0 - means that the Background is Opaque #\n" - <<"# 1 - means that the Background is Transparent #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# CLIENT TYPE: DESKTOP #\n" - <<"# WEB #\n" - <<"#----------------------------------------------------------------------------------#\n" - <<"# ID: relative to the unique ID on the Database #\n" - <<"####################################################################################\n"*/; - -} + 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" + << "\nSERVICES PARAMETERS:\n" + << "Video with subtitles:\n" + << " [INPUT_VIDEO] [INPUT_SRT] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" + << "Video Recognize:\n" + << " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" + << "Text:\n" + << " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" + << "Subtitles only:\n" + << " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" + << "Audio Recognize\n" + << " [INPUT_AUDIO] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" + << "\nPARAMETERS:\n" + << "INPUT_VIDEO Path of the video file\n" + << "INPUT_SRT Path of the subtitle file\n" + << "INPUT_TEXT_FILE Path of the text file\n" + << "INPUT_AUDIO Path of the audio file\n" + << "LANGUAGE 1 - means Portuguese, 2 - means Glosa\n" + << "POSITION 1 - means Top_Left, 2 - means Top_Right, 3 - means Bottom_Right, 4 - means Bottom_Left\n" + << "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"; +} \ No newline at end of file diff --git a/mixer/src/Mixer.cpp b/mixer/src/Mixer.cpp index a04d49f..2230df3 100644 --- a/mixer/src/Mixer.cpp +++ b/mixer/src/Mixer.cpp @@ -24,10 +24,11 @@ Mixer::~Mixer() { /*Faz a chamada ffmpeg no terminal.*/ -void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, int transparency, char* _id){ +void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, int transparency, char* _id, char* client_type){ DDPRINTF("[AGUARDE] Mixando...\n") + client = client_type; stringstream ss; ss << _id; ss >> user_id; @@ -42,7 +43,6 @@ void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVi this->setTransparency(transparency); this->setPathFinal(); this->mixVideos(); - } void Mixer::mixVideos () { @@ -146,8 +146,24 @@ void Mixer::mixVideos () { } void Mixer::setPathFinal(){ - pathFinal = PATH_API; - pathFinal.append(user_id).append(".mp4"); + + 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()); + } + } } /*Ajusta o FPS do vídeo principal para 45 se preciso...*/ @@ -314,11 +330,16 @@ void Mixer::setMainVideo(string mainVideo){ } //ajeitar isso depois string nameOfMainVideo = mainVideo.substr(0, dotPosition); - this->temporaryTextFile = "vlibras_user/vlibras-api/uploads/"; - temporaryTextFile.append(this->user_id).append("/tamanho.txt"); - + 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"); + } //printf("##########temporaryTextFile: %s\n", temporaryTextFile.c_str()); - } string Mixer::getMainVideo(){ return this->mainVideo; diff --git a/mixer/src/include/Mixer.h b/mixer/src/include/Mixer.h index 930892b..a299ee8 100644 --- a/mixer/src/include/Mixer.h +++ b/mixer/src/include/Mixer.h @@ -17,9 +17,10 @@ #include #include #include "dprintf.h" +#include "property.h" using namespace std; - +using namespace sndesc; //SL Video Position #define TOP_LEFT 1 @@ -35,9 +36,12 @@ using namespace std; #define MEDIUM_HEIGHT 432 //0,4*1080 #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: @@ -62,7 +66,7 @@ public: int getTransparency(); void setNumThreads(string); string getNumThreads(); - void initialize(string mainVideo, string slVideo, int, int, int, char*); + void initialize(string mainVideo, string slVideo, int, int, int, char*, char*); void setPathFinal(); private: @@ -78,11 +82,12 @@ private: void convertSecondaryVideoFPS(double); string mainVideo, secondaryVideo, temporaryTextFile, numThreads, pathFinal, user_id; + char* client; int positionSecondaryVideo; double widthSecondaryVideo, heightSecondaryVideo; int transparency; - + PropertyHandler* reader; }; diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index e6da100..f6be548 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -11,7 +11,8 @@ #include #include "dprintf.h" #include "Mixer.h" -#include "inputFile.h" +//#include "inputFile.h" +#include "property.h" #include "listenerTradutor.h" #include "tradutorPortGlosa.h" //#include "httpstreamer.h" @@ -20,23 +21,25 @@ #include "serviceException.h" #include +#define WEB_USER "web" #define VIDEO_POSE_NEUTRA "poseneutra" #define BASEDIR "vlibras_user/dicionario_libras/" #define BASEDIRTRANSP "vlibras_user/dicionarioTransp_libras/" #define EXTENSAO_DICIONARIO ".ts" +#define PATH_CONTENTS "vlibras_user/.vlibras-conf/contents/" #define PATH_API "vlibras_user/vlibras-api/videos/" #define MAX_SIZE_PATH 256 -/*#define SERVICE_TYPE_CC 1 /* Closed Caption */ -#define SERVICE_TYPE_SRT 2 /* Subtitle SRT */ -#define SERVICE_TYPE_REC 3 /* Reconhecimento de Voz */ -#define SERVICE_TYPE_TEXT 4 /* Texto */ -#define SERVICE_TYPE_SRT_ONLY 5 /* Subtitle SRT ONLY */ -#define SERVICE_TYPE_REC_ONLY_AUDIO 6 /* Subtitle AUDIO ONLY */ +#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 Util; using namespace std; +using namespace sndesc; class ServiceWindowGeneration : public ListenerTradutor, public ListenerSynchronizer{ @@ -45,8 +48,9 @@ protected: TradutorPortGlosa * tradutor; //HttpStreamer *sincronizador; Synchronizer * sincronizador; - InputFile * inputfile; + //InputFile * inputfile; Mixer * mixer; + PropertyHandler* reader; vector * vetor_pts; diff --git a/servico/src/include/serviceWindowGenerationFromREC.h b/servico/src/include/serviceWindowGenerationFromREC.h index 88b0b07..dfe40e7 100644 --- a/servico/src/include/serviceWindowGenerationFromREC.h +++ b/servico/src/include/serviceWindowGenerationFromREC.h @@ -20,7 +20,7 @@ private: 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(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); diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index ebb1a41..81168b6 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -29,9 +29,9 @@ public: /* Construtor 1 - legenda e vídeo */ ServiceWindowGenerationFromSRT(char* path_video, char* path_srt, int sublanguage, - int position, int size, int transparency, char* id, int _serviceType); + 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, int _serviceType); + ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, char* client_type, int _serviceType); ~ServiceWindowGenerationFromSRT(); virtual void notifySubtitle(unsigned char* subtitle, int64_t pts); diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index ab468c5..cda8985 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -17,8 +17,7 @@ private: bool finish; public: - ServiceWindowGenerationFromText (char* _path_file, char* _video_path_file, - int _transp, int _serviceType, char* _client_type); + ServiceWindowGenerationFromText (char* _path_file, char* user_id, int _transp, int _serviceType, char* _client_type); ~ServiceWindowGenerationFromText (); void notifyLine(unsigned char* line); diff --git a/servico/src/serviceWindowGeneration.cpp b/servico/src/serviceWindowGeneration.cpp index 03896fd..2ef65ac 100644 --- a/servico/src/serviceWindowGeneration.cpp +++ b/servico/src/serviceWindowGeneration.cpp @@ -4,6 +4,9 @@ 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; @@ -14,7 +17,6 @@ ServiceWindowGeneration::ServiceWindowGeneration() { ServiceWindowGeneration::~ServiceWindowGeneration() { free(vetor_pts); free(path_libras); - if (inputfile) delete inputfile; if (mixer) delete mixer; if (tradutor) delete tradutor; if (sincronizador) delete sincronizador; @@ -74,11 +76,18 @@ void ServiceWindowGeneration::setTransparency(int transparency){ } 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"); + 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); } @@ -102,7 +111,7 @@ bool ServiceWindowGeneration::isRunning() { 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); + mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency, this->user_id, this->client_type); createThumbnail(); }else{ transcodeVideoToMp4(); @@ -112,8 +121,12 @@ void ServiceWindowGeneration::notifyEndOfSynchronization() { void ServiceWindowGeneration::initialize() { + cout << "entrei" << endl; + setPathLibras(); + cout << "passei" << endl; + if (this->sublanguage == 1) { tradutor->addListener(this); } @@ -204,7 +217,7 @@ void ServiceWindowGeneration::transcodeVideoToWebm() { string command = "ffmpeg -i "; command.append(path_libras) .append(" -vcodec libvpx -acodec libvorbis ") - .append(" -v quiet ") + //.append(" -v quiet ") .append(PATH_API) .append(getUserId()) .append(".webm"); @@ -213,32 +226,60 @@ void ServiceWindowGeneration::transcodeVideoToWebm() { } void ServiceWindowGeneration::transcodeVideoToMp4() { - if (serviceType == SERVICE_TYPE_TEXT && strcmp(client_type, (char*)"WEB") == 0) - transcodeVideoToWebm(); - else{ + //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 ") - .append(PATH_API) - .append(getUserId()) - .append(".mp4"); + .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 ") - .append(PATH_API).append(user_id).append(".png"); + //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()); + }catch(RuntimeException &ex){ + printf("%s\n", ex.getMessage().c_str()); + } + + command.append(PATH_CONTENTS).append(user_id).append(".mp4") + .append(" -vcodec png -vframes 1 -an -f rawvideo -y -vf scale=200:200 "); + } + 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 index 89bdaad..6299569 100644 --- a/servico/src/serviceWindowGenerationFromREC.cpp +++ b/servico/src/serviceWindowGenerationFromREC.cpp @@ -16,7 +16,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( } ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( - char* path_video, int sublanguage, int position, int size, int transparency, char* id, int serviceType) { + char* path_video, int sublanguage, int position, int size, int transparency, char* id, char* client_type, int _serviceType) { setPathInput(path_video); setSubLanguage(sublanguage); @@ -24,6 +24,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( setSize(size); setTransparency(transparency); setServiceType(serviceType); + setClientType(client_type); setUserId(id); rec = new Recognize(path_video, id); finish = false; diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 2695584..7acb9f9 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -1,12 +1,24 @@ #include "serviceWindowGenerationFromSRT.h" -//Construtor Service 2 -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( - char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, char* id, int serviceType) { +//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) { + + // cout << "video: " << path_video << endl; + // cout << "srt: " << path_srt << endl; + // cout << "language: " << sublanguage << endl; + // cout << "position: " << position << endl; + // cout << "size: " << size << endl; + // cout << "transparency: " << transparency << endl; + // cout << "id: " << id << endl; + // cout << "serviceType: " << serviceType << endl; + //cout << "client_type: " << client_type << endl; + extrator_factory = new ExtratorFactory(); setPathInput(path_video); setPathSRT(path_srt); + setClientType(client_type); setPosition(position); setSize(size); setTransparency(transparency); @@ -17,10 +29,11 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( DPRINTF("Done!\n"); } -//Construtor Service 5 -ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, int serviceType){ +//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); @@ -67,11 +80,11 @@ void ServiceWindowGenerationFromSRT::initialize() { //codigo abaixo sera arrumado apos a aplicação do factory pattern - if(serviceType == 2){ + if(serviceType == 1){ extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); extratorSRT->addListener(this); - extratorSRT->setFilePath((char*) path_srt); + extratorSRT->setFilePath(path_srt); ServiceWindowGeneration::initialize(); @@ -88,7 +101,7 @@ void ServiceWindowGenerationFromSRT::initialize() { objeto InputFile().*/ extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); extratorSRT->addListener(this); - extratorSRT->setFilePath((char*) path_input); + extratorSRT->setFilePath(path_input); ServiceWindowGeneration::initialize(); diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index 18101bf..b81d08f 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -10,7 +10,6 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( setTransparency(transp); setServiceType(serviceType); finish = false; - DPRINTF("Done!\n"); } ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { diff --git a/util/src/include/logger.h b/util/src/include/logger.h index 78a8483..ed7d3f3 100644 --- a/util/src/include/logger.h +++ b/util/src/include/logger.h @@ -17,6 +17,7 @@ #include #include #include +#include "property.h" //#include @@ -31,7 +32,9 @@ namespace Util { public: static Logger* Instance(); void openLogFile(); - void writeLog(char* exception); + void openInfoLogFile(char* filepath); + void writeLog(char* log); + void writeInfoLog(char* filepath ,char* infoLog); void closeLogFile(); char* getTime(); diff --git a/util/src/include/property.h b/util/src/include/property.h new file mode 100644 index 0000000..d1ae46d --- /dev/null +++ b/util/src/include/property.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Universidade Federal da Paraíba * + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * + * * + * Centro de Informática - UFPB - Campus I * + * 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 * + * * + **************************************************************************/ + + #ifndef PROPERTY_H + #define PROPERTY_H + + #include "logger.h" + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #define EXTENSION ".conf" + + using namespace std; + using namespace lavidlib; + + namespace sndesc { + + class PropertyHandler { + public: + PropertyHandler(string filename); + virtual ~PropertyHandler(); + char* getAttributeValue(string attr); + + private: + BufferedReader* rbuffer; + FileIO* file_property; + int checkFileExtension(string &filename); + + }; + } + + #endif /* PROPERTY_H */ \ No newline at end of file diff --git a/util/src/logger.cpp b/util/src/logger.cpp index f934f73..54573df 100644 --- a/util/src/logger.cpp +++ b/util/src/logger.cpp @@ -30,6 +30,9 @@ namespace Util { file.open("vlibras_user/vlibras-core/log/log", ios_base::app); } + void Logger::openInfoLogFile(char* filepath){ + file.open(filepath , ios_base::trunc); + } void Logger::closeLogFile(){ file.close(); @@ -46,6 +49,12 @@ namespace Util { file << getTime(); file << exception << "\n\n\r"; this->closeLogFile(); - } - + } + + void Logger::writeInfoLog(char* filepath ,char* infoLog){ + this->openInfoLogFile(filepath); + file << getTime(); + file << infoLog << "\n\r"; + this->closeLogFile(); + } } diff --git a/util/src/property.cpp b/util/src/property.cpp new file mode 100644 index 0000000..a4ed104 --- /dev/null +++ b/util/src/property.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** + * Universidade Federal da Paraíba * + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * + * * + * Centro de Informática - UFPB - Campus I * + * 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 * + * * + **************************************************************************/ + + #include "property.h" + + using namespace std; + + namespace sndesc { + + 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 -- libgit2 0.21.2