/* * File: main.cpp * Author: felipe * * Created on 15 de Outubro de 2009, 10:56 */ #include #include #include #include #include "dprintf.h" #include #include "extratorCC.h" #include "demux.h" #include "serviceWindowGenerationFromCC.h" #include "serviceWindowGenerationFromSRT.h" #include "serviceWindowGenerationFromREC.h" #include "serviceWindowGenerationFromText.h" #include "serviceWindowGeneration.h" #define BASEDIR_VIDEOSGERADOS "../videosgerados_gtaaas/" #include using namespace Tradutor; using namespace Util; using namespace Codificador; using namespace std; void help(); 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); /* * Manager */ int main(int argc, char* argv[]) { if (argc < 2) { help(); return 1; } char* service_type = argv[1]; /* FIXME: Os parâmetros devem ser especificados da seguinte forma: * $ ./gtaaas -st -video -srt -text -lg -pos -size -tp -id */ if (service_type[0] != '4') { printf("[WARNING]: Service temporarily unavailable!\n"); return 1; /* FIXME */ if(argc != 8 && argc != 9){ help(); return 1; } } string filename; int sublanguage; if(service_type[0] == '1') { 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"); } else if (service_type[0] == '2') { cout << "\nSERVICE SUBTITLE (SRT)\n" << endl; filename = createFileToResponse((char*)argv[8]); char* path_in = (char*) argv[2]; char* path_srt = (char*) argv[3]; sublanguage = (int) atoi(argv[4]); int position = (int) atoi(argv[5]); int size = (int) atoi(argv[6]); int transparency = (int) atoi(argv[7]); ServiceWindowGenerationFromSRT * service_srt; service_srt = new ServiceWindowGenerationFromSRT( path_in, path_srt, sublanguage, position, size, transparency, 2); service_srt->initialize(); while(service_srt->isRunning()){ sleep(5); } char* id = (char*) argv[8]; updateRequestStatus(filename.c_str(), id, "true"); } else if (service_type[0] == '3') { cout << "\nSERVICE RECOGNIZER\n" << endl; filename = createFileToResponse((char*)argv[7]); char* path_in = (char*) argv[2]; sublanguage = (int) atoi(argv[3]); int position = (int) atoi(argv[4]); int size = (int) atoi(argv[5]); int transparency = (int) atoi(argv[6]); ServiceWindowGenerationFromREC * service_rec; service_rec = new ServiceWindowGenerationFromREC( path_in, sublanguage, position, size, transparency, 3); service_rec->initialize(); while(service_rec->isRunning()){ sleep(5); printf("\nservice_rec->isRunning()...\n"); } printf("\nservice_rec->finished!\n"); char* id = (char*) argv[7]; updateRequestStatus(filename.c_str(), id, "true"); printf("\n\nAtualizei o status"); } else if (service_type[0] == '4') { // ./gtaaas 4 char* username = "user"; filename = createFileToRespWeb(username); char* path_file = (char*) argv[2]; int transp = (int) atoi(argv[3]); char* client_type = (char*) argv[4]; // {WEB, DESKTOP} printf("***client_type: %s\n", client_type); cout << "TEXT: " << path_file << endl; ServiceWindowGenerationFromText *service_text; service_text = new ServiceWindowGenerationFromText(path_file, transp, 4, client_type); service_text->initialize(); while (service_text->isAlive()) { sleep(3); } printf("\nService Text finished!\n"); updateRequestStatusWeb(filename.c_str(), username, "true"); } else { help(); return 1; } return 1; } //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" <<"######################################################################################\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" <<"#------------------------------------------------------------------------------------#\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" <<"# 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); printf("\ncreating file: %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 = "../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; } 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); }