#include "serviceWindowGenerationFromText.h" #define PATH_LIBRAS "libras/video/" #define OUTPUT_VIDEO_WEB "gtaaas_user/gtaaas-plugin-server/videos/libras.webm" #define MAX_SIZE_PATH 256 ServiceWindowGenerationFromText::ServiceWindowGenerationFromText (char* _path_file, char* _username, int _transp, int _serviceType, char* _client_type) { path_file = _path_file; client_type = _client_type; setTransparency(_transp); setServiceType(_serviceType); char* final_path = new char[MAX_SIZE_PATH]; strcpy(final_path, PATH_LIBRAS); strcat(final_path, _username); strcat(final_path, ".ts"); setPathLibras(final_path); alive = true; DPRINTF("Done!\n"); } ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { delete extratorTXT; DDDPRINTF("Service Text finished!\n"); } void ServiceWindowGenerationFromText::initialize() { DDPRINTF("Service Text Initialize.\n"); extratorTXT = new ExtratorTXT(); extratorTXT->addListener(this); extratorTXT->setFilePath((char*) path_file); ServiceWindowGeneration::initialize(); try{ extratorTXT->initialize(); }catch(ExtratorTxtException ex){ throw ServiceException(ex.getMessage()); } this->Start(); } void ServiceWindowGenerationFromText::notifyEnd(int line_size) { DDPRINTF("Service SRT recebeu: %d linhas.\n", line_size); setSizeOfSubtitles(line_size); } void ServiceWindowGenerationFromText::notificaTradutor(unsigned char* line) { tradutor->traduz(line); } bool ServiceWindowGenerationFromText::isAlive() { return alive; } void ServiceWindowGenerationFromText::Run() { while (isRunning()) { usleep(200000); //200ms } if (strcmp(client_type, (char*)"WEB") == 0) { printf("[INFO]: A transcodificação para .webm está ativada!\n"); transcodeVideoToWebm(); } alive = false; } void ServiceWindowGenerationFromText::transcodeVideoToWebm() { FILE *video_webm; video_webm = fopen(OUTPUT_VIDEO_WEB, "r"); if (video_webm != NULL) { string cmd = "rm "; cmd.append(OUTPUT_VIDEO_WEB); printf("[INFO]: Remove video libras.webm: %s\n", cmd.c_str()); system(cmd.c_str()); fclose(video_webm); } char* command = (char*) malloc (INT_MAX); strcpy(command, "ffmpeg -i "); strcat(command, PATH_LIBRAS); strcat(command, " -vcodec libvpx -acodec libvorbis "); strcat(command, OUTPUT_VIDEO_WEB); printf("[INFO]: Transcodification command -> %s\n", command); system(command); free(video_webm); free(command); }