/* * File: main.cpp * Author: felipe * * Created on 15 de Outubro de 2009, 10:56 */ /* * File: main.cpp * Author: Erickson * * Edit on 03 de Fevereiro de 2014 */ #include "serviceWindowGenerationFromSRT.h" #include "serviceWindowGenerationFromRec.h" #include "serviceWindowGenerationFromText.h" #include "serviceException.h" #include #include #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos" #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads" #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads" using namespace std; void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type); void serviceOnlySRT(char* service, char* path_file, char* transparency, char* username, char* client_type); //void serviceREC(char* 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 setPathContents(char* client); void fail(string msg); void hasFailed(); void hasInvalid(); bool isFailed; bool isInvalid; int main(int argc, char* argv[]) { struct timeval tv1, tv2; double t1, t2; gettimeofday(&tv1, NULL); t1 = (double)(tv1.tv_sec) + (double)(tv1.tv_usec)/ 1000000.00; 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){ serviceHelp(1); hasInvalid(); }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){ serviceHelp(2); hasInvalid(); }else{ serviceREC(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); } break; case 3: if(argc <= 5){ serviceHelp(3); hasInvalid(); }else{ serviceText(argv[1], argv[2], argv[3], argv[4], argv[5]); } break; case 4: if(argc <= 5){ serviceHelp(4); hasInvalid(); }else{ serviceOnlySRT(argv[1], argv[2], argv[3], argv[4], argv[5]); } break; case 5: if(argc <= 5){ serviceHelp(5); hasInvalid(); }else{ serviceOnlyAudio(argv[1], argv[2], argv[3], argv[4], argv[5]); } break; default: 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{ cout << "\nFAIL VLibras: Tente --help para obter informações.\n" << endl; hasInvalid(); } if(isFailed) exit(1); else if(isInvalid) exit(127); gettimeofday(&tv2, NULL); t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; DDPRINTF("Time: %lf\n", (t2-t1)); DDPRINTF("VLibras finalized!\n\n"); exit(0); } void serviceSRT(char* service, char* path_video, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type){ setPathContents(client_type); 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_srt->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while(!service_srt->isFinished()){ sleep(5); } delete service_srt; } void serviceREC(char* service, char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromRec * service_rec; service_rec = new ServiceWindowGenerationFromRec(path_video, (int) atoi(sublanguage), (int) atoi(position), (int) atoi(size), (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_rec->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while(!service_rec->isFinished()){ sleep(2); } delete service_rec; } void serviceText(char* service, char* path_text, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromText *service_text; service_text = new ServiceWindowGenerationFromText(path_text, (int) atoi(transparency), id, client_type); try{ service_text->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while (!service_text->isFinished()) { usleep(100000); //100ms } delete service_text; } void serviceOnlySRT(char* service, char* path_file, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromSRT * service_srt; service_srt = new ServiceWindowGenerationFromSRT(path_file, (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_srt->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while (!service_srt->isFinished()) { usleep(100000); //100ms } delete service_srt; } void serviceOnlyAudio(char* service, char* path_audio, char* transparency, char* id, char* client_type){ setPathContents(client_type); ServiceWindowGenerationFromRec * service_rec; service_rec = new ServiceWindowGenerationFromRec(path_audio, 0, 0, 0, (int) atoi(transparency), id, client_type, (int) atoi(service)); try{ service_rec->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while(!service_rec->isFinished()){ sleep(2); } delete service_rec; } /*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, 2, rate); try{ service_rec->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while(!service_rec->isFinished()){ sleep(2); } delete service_rec; }*/ /*void serviceOnlyAudio(char* path_audio, char* transparency, char* id, char* rate){ ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC( path_audio, 0, 0, 0, (int) atoi(transparency), id, 5, rate); try{ service_rec->initialize(); }catch(ServiceException ex){ fail(ex.getMessage()); hasFailed(); return; } while(!service_rec->isFinished()){ sleep(2); } delete service_rec; }*/ void fail(string msg){ printf("\n"); DDDDPRINTF("Ops... Tivemos um problema! :(\n"); DDDDPRINTF("Possível causa do erro: %s\n\n", msg.c_str()); } void hasFailed(){ isFailed = true; } void hasInvalid(){ isInvalid = true; } void setPathContents(char* client){ string command = "mkdir -p "; if(strcmp(client, "devel") == 0) command.append(PATH_DEVEL_CONTENTS).append(" && mkdir -p ").append(PATH_DEVEL_UPLOADS); else if (strcmp(client, "prod") == 0) command.append(PATH_VBOX_UPLOADS); else { fail("Cliente Inválido!"); exit(127); } system(command.c_str()); } 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 << 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" << "\nVideo Recognize:\n" << " [INPUT_VIDEO] [LANGUAGE] [POSITION] [SIZE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" << "\nText:\n" << " [INPUT_TEXT_FILE] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" << "\nSubtitles only:\n" << " [INPUT_SRT] [TRANSPARENCY] [ID] [CLIENT_TYPE]\n" << "\nAudio 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 prod - means that the client is web/cloud, devel - means that the client is developer\n" << endl; }