/* * 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 "serviceWindowGenerationFromCC.h" #include "serviceWindowGenerationFromSRT.h" #include "serviceWindowGenerationFromREC.h" #include "serviceWindowGenerationFromText.h" #include 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); void serviceText(char* path_text, char* transparency, char* username, char* client_type); void serviceREC2(); void help(); void header(); string createFileToResponse(char* id); void updateRequestStatus(const char* filename, char* id, char* status); string createFileToRespWeb(char* id); void updateRequestStatusWeb(const char* filename, char* id, char* status); string filename; 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; printf(" \n################## GTAAAAS : LAVID ##################\n\n"); DDPRINTF("Service Type: %s\n", argv[1]); /*switch(argc){ case 4: path_file = (char*) argv[2]; username = (char*) argv[3]; DDPRINTF("Path File: %s\n\n", path_file); break; case 6: path_file = (char*) argv[2]; transp = (int) atoi(argv[3]); username = (char*) argv[4]; client_type = (char*) argv[5]; // {WEB, DESKTOP} DDPRINTF("Path File: %s\n", path_file); DDPRINTF("ID: %s\n", username); DDPRINTF("Client Type: %s\n", client_type); if (transp == 0){ DDPRINTF("Background: Opaco\n\n"); } else{ DDPRINTF("Background: Transparente.\n\n"); } break; default: cout << "\nParametros inválidos. Tente novamente." << endl; help(); return 1; }*/ switch((int) atoi(argv[1])){ case 1: serviceCC(); return 1; case 2: serviceSRT(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); break; case 3: serviceREC(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); break; case 4: serviceText(argv[2], argv[3], argv[4], argv[5]); break; case 5: serviceOnlySRT(argv[2], argv[3], argv[4]); break; case 6: serviceREC2(); return 1; default: cout << "\nServiço inválido. Tente novamente." << endl; help(); return 1; } gettimeofday(&tv2, NULL); t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; cout << endl; DPRINTF("Time: %lf\n", (t2-t1)); DPRINTF("GTaaaS concluído!\n\n"); return 1; } 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]); 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* username){ filename = createFileToResponse(username); ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC( path_video, (int) atoi(sublanguage), (int) atoi(position), (int) atoi(size), (int) atoi(transparency), 3); service_rec->initialize(); while(service_rec->isRunning()){ sleep(2); } char* id = (char*) username; updateRequestStatus(filename.c_str(), username, "true"); delete service_rec; } void serviceSRT(char* path_in, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* username){ filename = createFileToResponse(username); ServiceWindowGenerationFromSRT * service_srt; service_srt = new ServiceWindowGenerationFromSRT( path_in, path_srt, (int) atoi(sublanguage), (int) atoi(position), (int) atoi(size), (int) atoi(transparency), 2); service_srt->initialize(); while(service_srt->isRunning()){ sleep(5); } updateRequestStatus(filename.c_str(), username, "true"); delete service_srt; } void serviceText(char* path_text, char* transparency, char* username, char* client_type){ //filename = createFileToRespWeb(username); ServiceWindowGenerationFromText *service_text; service_text = new ServiceWindowGenerationFromText(path_text, username, (int) atoi(transparency), 4, client_type); service_text->initialize(); service_text->Start(); while (service_text->isAlive()) { usleep(100000); //100ms } //updateRequestStatusWeb(filename.c_str(), username, "true"); delete service_text; } void serviceOnlySRT(char* path_file, char* transparency, char* username){ // LEONARDO: comentado para os testes de Eduardo! //filename = createFileToRespWeb(username); //cout << "SRT FILE: " << path_file << endl; ServiceWindowGenerationFromSRT * service_srt; service_srt = new ServiceWindowGenerationFromSRT(path_file, username, (int) atoi(transparency), 5); service_srt->initialize(); service_srt->Start(); //while(service_srt->isRunning()){ while (!service_srt->finished()) { //sleep(1); usleep(100000); //100ms } delete service_srt; } void serviceREC2(){ cout << "\n--> Serviço não disponível.\n" << endl; // ./gtaaas 6 /** cout << "\nSERVICE RECOGNIZER FROM AUDIO - Delivers only LIBRAS Translation\n" << endl; char* path_in = (char*) argv[2]; int transparency = (int) atoi(argv[3]); char* username = (char*) argv[4]; filename = createFileToRespWeb(username); printf("Main 1\n"); ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC(path_in, username, transparency, 6); service_rec->initialize(); while(service_rec->isRunning()){ sleep(5); printf("\nservice_rec->isRunning()...\n"); } printf("\nService REC_FROM_AUDIO finished!\n"); updateRequestStatus(filename.c_str(), username, "true"); **/ } //Help do programa, explicando todos os parâmetros existentes... void help() { //cout << "\nCommand line: ./gtaaas SERVICE_TYPE INPUT_VIDEO INPUT_SRT INPUT_TEXT_FILE LANGUAGE POSITION SIZE TRANSPARENCY ID\n\n" cout << "\nService Type Text: ./gtaaas 4 INPUT_TEXT_FILE TRANSPARENCY ID CLIENT_TYPE" << "\nService Type SRT Only: ./gtaaas 5 INPUT_SRT TRANSPARENCY ID CLIENT_TYPE\n\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" <<"#----------------------------------------------------------------------------------#\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" <<"# 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"; } /* Response file to Web */ string createFileToRespWeb(char* id) { FILE* file; string filename = "web-content/"; filename += id; filename += ".xml"; file = fopen(filename.c_str(), "w+"); string content_file = "\n\n\t"; content_file += id; content_file += "\n\tfalse\n"; const char *textchar = content_file.c_str(); fwrite(textchar, 1, content_file.size(), file); fclose(file); //DDPRINTF("Criando o arquivo: %s\n", filename.c_str()); return filename; } void updateRequestStatusWeb(const char* filename, char* id, char* status){ //printf("\nupdateRequestStatusWeb: id = %s\n", id); FILE *file = fopen(filename, "w+"); string content = "\n\n\t"; content += id; content += "\n\t"; content += status; content += "\n"; const char *textchar = content.c_str(); fwrite(textchar, 1, content.size(), file); fclose(file); } /* End */ string createFileToResponse(char *id){ /**FILE *arquivofinish; string namearq = "/home/erickson/gtaaas_web/public/uploads/videos"; namearq += id; namearq += "/"; namearq += id; namearq += ".xml"; arquivofinish = fopen(namearq.c_str(), "w+"); string arqtext = "\n\n\t"; arqtext += id; arqtext += "\n\tfalse\n"; const char *textchar = arqtext.c_str(); fwrite(textchar, 1, arqtext.size(), arquivofinish); fclose(arquivofinish); //printf("\ncreating file: %s\n", namearq.c_str()); return namearq;**/ FILE *arquivofinish; string namearq = "/home/gtaaas/gtaaas_web/public/uploads/videos/"; namearq += id; namearq += "/"; namearq += id; namearq += ".xml"; //printf("file name: %s\n", namearq.c_str()); arquivofinish = fopen(namearq.c_str(), "w+"); string arqtext = "\n\n\t"; arqtext += id; arqtext += "\n\tfalse\n"; const char *textchar = arqtext.c_str(); fwrite(textchar, 1, arqtext.size(), arquivofinish); fclose(arquivofinish); //printf("\ncreating file: %s\n", namearq.c_str()); return namearq; } void updateRequestStatus(const char* filename, char* id, char* status){ //printf("\nupdateRequestStatus: id = %s\n", id); //printf("\nupdating file: %s\n", filename); /**FILE *arquivofinish = fopen(filename, "w+"); string arqtext = "\n\n\t"; arqtext += id; arqtext += "\n\t"; arqtext += status; arqtext += "\n"; const char *textchar = arqtext.c_str(); fwrite(textchar, 1, arqtext.size(), arquivofinish); fclose(arquivofinish);**/ //printf("\nupdateRequestStatus: id = %s\n", id); //printf("\nupdating file: %s\n", filename); FILE *arquivofinish = fopen(filename, "w+"); string arqtext = "\n\n\t"; arqtext += id; arqtext += "\n\t"; arqtext += status; arqtext += "\n"; const char *textchar = arqtext.c_str(); fwrite(textchar, 1, arqtext.size(), arquivofinish); fclose(arquivofinish); }