#include "serviceWindowGeneration.h" #define VIDEO_POSE_NEUTRA "poseneutra" #define BASEDIR "../dicionario_libras/" #define BASEDIRTRANSP "../dicionarioTransp_libras/" #define EXTENSAO_DICIONARIO ".ts" #define PTS_DEFAULT = 1000 int contt = 0; ServiceWindowGeneration::ServiceWindowGeneration() { char op2 = this->getRunningOption(); if (op2 != '3') { puts("\n\nIniciei tradutor\n\n"); tradutor = new TradutorPortGlosa(); } vetor_pts = new vector(); mixer = new Mixer(); numero_legendas = 0; legendas_enviadas = 0; this->running = true; serviceType = 0; } ServiceWindowGeneration::~ServiceWindowGeneration() { if (tradutor) delete tradutor; } void ServiceWindowGeneration::adicionaPTS(int64_t pts) { vetor_pts->push_back(pts); } bool ServiceWindowGeneration::isRunning() { return this->running; } void ServiceWindowGeneration::finalizouSincronizacao() { printf("\nServiceWindowGeneration::finalizouSincronizacao()\n"); char op = this->getRunningOption(); if (op != '2' && serviceType != SERVICE_TYPE_TEXT) { printf("path_input: %s\npath_libras: %s\n", path_input, path_libras); mixer->initialize(this->path_input, this->path_libras,this->position,this->size,this->transparency); } this->running = false; //printf("\nFinalizando a mixagem...\n\n"); } char ServiceWindowGeneration::getRunningOption() { //TODO CORRIGIR problema abaixo /*Quando é executado direto da interface do GTAAAS_WEB, ela perde o caminho relativo e não encontra o arquivo runningoption.xml*/ int file_d = open("../gtaaas/runningoption.xml", O_RDONLY); char option; int cont = read(file_d, &option, 1); close(file_d); return option; //return '3'; } void ServiceWindowGeneration::setPathLibras(char* _path_libras) { this->path_libras = _path_libras; printf("path_libras: %s\n", path_libras); } void ServiceWindowGeneration::initialize() { if (serviceType == 0) { printf("serviceType não encontrado. Este precisa ser especificado ao instanciar um novo Serviço!"); return; } this->finish = false; char opt = getRunningOption(); if (opt != '3' && this->sublanguage == 1) { tradutor->registraOuvinte(this); } // o path do arquivo só poderá conter um "."(ponto), esse identifica a extensão. vector tokens; /* Se for texto não é necessário vídeo de entrada (path_input) */ if (serviceType != SERVICE_TYPE_TEXT) { char * pathtmp = this->path_input; int size = strlen(pathtmp); char vtemp [size]; strcpy(vtemp, pathtmp); pathtmp = strtok(vtemp, "."); while (pathtmp != NULL) { tokens.push_back(string(pathtmp)); pathtmp = strtok(NULL, "."); } string buildstrpath = tokens[0] + "_libras" + EXTENSAO_DICIONARIO; this->path_libras = new char[buildstrpath.size()]; strcpy(this->path_libras, buildstrpath.c_str()); } else { tradutor->registraOuvinte(this); } if(this->transparency == 0) { //pega dicionario com BackGround opaco cout << "********* Backgroud OPACO" << endl; sincronizador = new Synchronizer(BASEDIR, EXTENSAO_DICIONARIO, this->path_libras, this->transparency); } else { if(this->transparency == 1) { //pega dicionario com BackGround transparente cout << "********* Backgroud TRANSPARENTE" << endl; sincronizador = new Synchronizer(BASEDIRTRANSP, EXTENSAO_DICIONARIO, this->path_libras,this->transparency); } } /* Se for SERVICE_TYPE_REC (Recognized) não é necessário usar o monitor_pcr_base */ if (serviceType == SERVICE_TYPE_CC || serviceType == SERVICE_TYPE_SRT) { char* extensao = (char*) tokens[1].c_str(); this->monitor_pcr_base->extvideo = new char[strlen(extensao)]; strcpy(this->monitor_pcr_base->extvideo, extensao); monitor_pcr_base->addListenerPCRBase(sincronizador); } else { uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro sincronizador->setPCRBase(pcr_base); } sincronizador->registraOuvinte(this); sincronizador->Start(); printf("\nServiceWindowGeneration::initialize()\n"); } void ServiceWindowGeneration::codifica(vector * glosas) { this->legendas_enviadas++; cout << "ServiceWindowGeneration recebeu " << glosas->size() << endl; if (serviceType != SERVICE_TYPE_TEXT) { for (int i = 0; i < glosas->size(); i++) { cout << "__Glosa [" << i << "] = " << glosas->at(i) << endl; int64_t pts_notificado = vetor_pts->front(); string glosa_bytes = glosas->at(i); sincronizador->recebeglosa(glosa_bytes, pts_notificado); } if (this->legendas_enviadas == this->numero_legendas) { int64_t pts_notificado = vetor_pts->front(); sincronizador->recebeglosa(VIDEO_POSE_NEUTRA, pts_notificado); printf("Tradutor ja enviou todas as legendas\n\n"); sincronizador->encerrouLegendas(); } vetor_pts->erase(vetor_pts->begin()); } else { //FIXME: esppecificar um PTS default int pts_notificado = 100; for (int i = 0; i < glosas->size(); i++) { cout << "__Glosa [" << i << "] = " << glosas->at(i) << endl; string glosa_bytes = glosas->at(i); sincronizador->recebeglosa(glosa_bytes, pts_notificado); } sincronizador->recebeglosa(VIDEO_POSE_NEUTRA, pts_notificado); //sincronizador->encerrouLegendas(); } } void ServiceWindowGeneration::stopServiceText() { sincronizador->hasText(false); } void ServiceWindowGeneration::setServiceType(int type) { serviceType = type; } bool ServiceWindowGeneration::mustFinish(){ return this->finish; } TradutorPortGlosa* ServiceWindowGeneration::getTradutor() { return this->tradutor; } void ServiceWindowGeneration::setSize(int size){ this->size = size; } void ServiceWindowGeneration::setPosition(int position){ this->position = position; } void ServiceWindowGeneration::setTransparency(int transparency){ this->transparency = transparency; } void ServiceWindowGeneration::setSubLanguage(int sublang){ this->sublanguage = sublang; }