serviceWindowGenerationFromSRT.cpp 2.9 KB
#include "serviceWindowGenerationFromSRT.h"

using namespace std;

ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(
			char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, int _serviceType) {
    
	setPathInput(path_video, path_srt);
    setPosition(position);
    setSize(size);
    setTransparency(transparency);
    setSubLanguage(sublanguage);
	setServiceType(_serviceType);
    //numero_legendas = 0;
    this->finish = false;
    //initialize();

}

ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {

}

void ServiceWindowGenerationFromSRT::setPathInput(char* path_video, char* path_srt) {
    this->path_input = path_video;
    this->path_srt = path_srt;
}

void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *legenda, int64_t pts){
    cout << "1-Chegou LEGENDA no ServiceFromSRT\n" << endl;
    printf("Glosa: %s PTS: %lld\n", legenda, pts);

    if (!strcmp((const char*) legenda, "Homem supermercado falar nao vender.")) {
        //printf("\nIGUAL\n");
        return;
    } else {
        //printf("\nDIFERENTE\n");
    }

    this->numero_legendas++;
    
    char op = this->getRunningOption();

    if (op == '3') {
        notificaSincronizadorSemTradutor(legenda, pts);
    } else {
        adicionaPTS(pts);
        notificaTradutor(legenda);
    }
    
}

void ServiceWindowGenerationFromSRT::notificaSincronizadorSemTradutor(unsigned char * legenda, int64_t pts) {
    
	char* pch = strtok((char*) legenda, " ");

    while (pch != NULL) {
        string pch_string = (string) pch;
        sincronizador->recebeglosa(pch_string, pts);
        printf("%s\n", pch);
        pch = strtok(NULL, " ");
    }

}

void ServiceWindowGenerationFromSRT::notificaTradutor(unsigned char* legenda) {

    const char* constchar = (const char*) legenda;
    char* legenda_copy = new char[strlen(constchar)];
    strcpy(legenda_copy, constchar);
    tradutor->traduz((unsigned char*) legenda_copy);

}

void ServiceWindowGenerationFromSRT::initialize() {

    printf("###ServiceWindowGenerationFromSRT::initialize() \n");
    this->inputfile = new InputFile(this->path_input);
    
    extratorSRT = new ExtratorSRT();
    
    monitor_pcr_base = new MonitorPCR();
    monitor_pcr_base->addListenerPCRBase(extratorSRT);
        
    inputfile->registraOuvinte(monitor_pcr_base);
    extratorSRT->addListener(this);
    extratorSRT->setFilePath((char*)this->path_srt);
    
    ServiceWindowGeneration::initialize();
    
    extratorSRT->initialize();
    
    this->inputfile->initialize();
    this->Start();

}

void ServiceWindowGenerationFromSRT::Run() {

    while (true) {

        if (extratorSRT->isFinished()) {
          
            this->finish = true;
            
            if (getRunningOption() == '3') {
                //printf("\n\n\nEncerrei\n\n\n");
                sincronizador->encerrouLegendas();

            }
        }
        sleep(5);
    }

}