serviceWindowGenerationFromREC.cpp 2.54 KB
#include "serviceWindowGenerationFromREC.h"

using namespace std;

ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
			char* path_video, int sublanguage, int position, int size, int transparency,  char* id, int serviceType, char* rate) {
    
	setPathInput(path_video);
	setSubLanguage(sublanguage);
	setPosition(position);
    setSize(size);
    setTransparency(transparency);
	setServiceType(serviceType);
	setUserId(id);
    rec = new Recognize(path_video, id, rate);
    DPRINTF("Done!\n");
}

ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
            char* path_video, int sublanguage, int position, int size, int transparency,  char* id, int serviceType) {
    
    setPathInput(path_video);
    setSubLanguage(sublanguage);
    setPosition(position);
    setSize(size);
    setTransparency(transparency);
    setServiceType(serviceType);
   	setUserId(id);
    rec = new Recognize(path_video, id);
    DPRINTF("Done!\n");
}

ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() {
	delete rec;
	DDDPRINTF("Service REC finished!\n");
}

void ServiceWindowGenerationFromREC::initialize() {

    rec->addListener(this);

    inputfile = new InputFile(this->path_input);        
    monitor_pcr_base = new MonitorPCR();

    monitor_pcr_base->addListenerPCRBase(rec);
    inputfile->registraOuvinte(monitor_pcr_base);
		
	ServiceWindowGeneration::initialize();

    try{
        rec->initialize();
        inputfile->initialize();                                
    }catch(RecognizeException ex){
        throw ServiceException(ex.getMessage());
    }
	this->Start();
}

void ServiceWindowGenerationFromREC::notifyTextRecognized(unsigned char* text, int64_t pts) {
    if (getRunningOption() == '3') {
        notifySynchWithoutTranslator(text, pts);
    } else {
        adicionaPTS(pts);
        notifyTranslator(text);
    }
}

void ServiceWindowGenerationFromREC::notifyTranslator(unsigned char *text) {
	tradutor->traduz(text);
}

void ServiceWindowGenerationFromREC::notifyEnd(int sentences_size) {
    DDPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size);
    setSizeOfSubtitles(sentences_size);
}

void ServiceWindowGenerationFromREC::notifySynchWithoutTranslator(unsigned char *text, int64_t pts) {
	char* pch = strtok((char*) text, " ");
    while (pch != NULL) {
        string pch_string = (string) pch;
        sincronizador->recebeglosa(pch_string, pts);
        pch = strtok(NULL, " ");
    }
    free(pch);
}

void ServiceWindowGenerationFromREC::Run() {

    while (!rec->isFinished()) {
        sleep(200000);
    }
}