diff --git a/Makefile b/Makefile index 85e58d8..4177880 100644 --- a/Makefile +++ b/Makefile @@ -171,4 +171,4 @@ svn: @find -iname "*.swp" -exec rm {} \; @find -iname "*.tmp" -exec rm {} \; @find -iname "*.svn-base" -exec rm -r {} \; - @find -iname "*.svn" -exec rm -r {} \; \ No newline at end of file + @find -iname "*.svn" -exec rm -r {} ;\ \ No newline at end of file diff --git a/extratorSRT/src/extratorSRT.cpp b/extratorSRT/src/extratorSRT.cpp index a92f21d..0e6edfe 100644 --- a/extratorSRT/src/extratorSRT.cpp +++ b/extratorSRT/src/extratorSRT.cpp @@ -76,11 +76,11 @@ void ExtratorSRT::Run(){ void ExtratorSRT::notifyPCRBase(uint64_t pcrbase){ - DDPRINTF("PCRBase = %ld\n", pcrbase); + //DDPRINTF("PCRBase = %ld\n", pcrbase); this->pcr_base = pcrbase; this->hasPCRBase = true; } uint64_t ExtratorSRT::calcula_pts(double msec) { return (uint64_t)(pcr_base + ((msec/1000) * 100000.0)); -} \ No newline at end of file +} diff --git a/input/src/include/inputFile.h b/input/src/include/inputFile.h index 8769be1..9d0c8bb 100644 --- a/input/src/include/inputFile.h +++ b/input/src/include/inputFile.h @@ -9,6 +9,7 @@ #define INPUTFILE_H #include +#include #include "logger.h" #include "ouvinteInput.h" #include "inputException.h" diff --git a/input/src/inputFile.cpp b/input/src/inputFile.cpp index 5c64c39..02c8de1 100644 --- a/input/src/inputFile.cpp +++ b/input/src/inputFile.cpp @@ -20,26 +20,26 @@ InputFile::~InputFile(){ void InputFile::initialize(){ ifstream filein(path, ifstream::binary); - - if (filein.is_open()) { - - char buffer [MAX_SIZE_PACKET]; - DPRINTF("[AGUARDE] Lendo arquivo...\n") - while (!filein.eof()) { - filein.read(buffer, MAX_SIZE_PACKET); - unsigned char* packet = (unsigned char*) buffer; - notificaOuvintes(packet); + + if (strstr(path, ".ts") != NULL) { + if (filein.is_open()) { + char buffer [MAX_SIZE_PACKET]; + DPRINTF("[AGUARDE] Lendo arquivo...\n") + while (!filein.eof()) { + filein.read(buffer, MAX_SIZE_PACKET); + unsigned char* packet = (unsigned char*) buffer; + notificaOuvintes(packet); + } + printf("\n"); + filein.close(); + //finished = true; + } else { + finished = true; + Util::Logger::Instance()->writeLog((char*) "[ERRO: inputFile.cpp] Arquivo de vídeo não encontrado."); + throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe."); } - - printf("\n"); - filein.close(); - finished = true; - - } else { - finished = true; - Util::Logger::Instance()->writeLog((char*) "[ERRO: inputFile.cpp] Arquivo de vídeo não encontrado."); - throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe."); } + finished = true; } diff --git a/monitorPCR/src/include/monitor_pcr.h b/monitorPCR/src/include/monitor_pcr.h index 23b4e08..c08ed83 100644 --- a/monitorPCR/src/include/monitor_pcr.h +++ b/monitorPCR/src/include/monitor_pcr.h @@ -30,6 +30,13 @@ class MonitorPCR: public OuvinteInput { void notifyListenersWithPCRBase(uint64_t pcrbase); uint64_t getPCRBase(); void chegouInput(unsigned char* packet); + + /** + * Informa para o monitor o formato do vídeo que está sendo manipulado. + * Caso seja qualquer outro diferente de Transport Stream (TS), os componentes + * observadores devem receber a notificação de um valor de PCR padrão. + */ + void setFormatVideo(char* format); private: diff --git a/monitorPCR/src/monitor_pcr.cpp b/monitorPCR/src/monitor_pcr.cpp index fb4a863..fe7c2ec 100644 --- a/monitorPCR/src/monitor_pcr.cpp +++ b/monitorPCR/src/monitor_pcr.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "monitor_pcr.h" #define PCRBASE_PADRAO 1000000 using namespace std; @@ -17,52 +18,45 @@ MonitorPCR::~MonitorPCR(){ DDDPRINTF("Monitor PCR finalized!\n"); } + uint64_t MonitorPCR::getPCRBase(){ return pcr_base; } -void MonitorPCR::chegouInput(unsigned char* packet) { - - //printf("\n\n\n\n\n\nEXTENSAOOO---2: %s\n\n\n\n\n\n", extvideo); - if (!find) { // verifica se o PCRBase já foi encontrado - //printf("\n>>> 2\n"); +void MonitorPCR::setFormatVideo(char* format) { + extvideo = format; +} - if (strcmp(extvideo, (char*) "ts") == 0) { // se for TS procura nos pacotes - readPCRBase(packet); - //printf("\n>>> 3\n"); +void MonitorPCR::chegouInput(unsigned char* packet) { - } - else // outros formatos de vídeo, define o PCR padrão = 1000000 + if (!find) { // verifica se o PCRBase já foi encontrado + *extvideo = tolower(*extvideo); + if (strcmp(extvideo, (char*) "ts") == 0) { // se for TS procura nos pacotes + readPCRBase(packet); + } else { // outros formatos de vídeo, define o PCR padrão = 1000000 notifyListenersWithPCRBase((uint64_t) PCRBASE_PADRAO); - } + find = true; + } + } + } + void MonitorPCR::readPCRBase(unsigned char* packet){ - // printf("\n>>> 0\n"); - if (packet[0] == 0x47 && !find){ - //printf("\n>>> 1\n"); - if((((packet[1] & 0x1F) << 8) | packet[2]) != 0xFF){ - - int adaptation_field_control = ((packet[3] & 0x30) >> 4); - - if (adaptation_field_control == 2 || adaptation_field_control == 3) { - - int adaptation_field_length = packet[4]; - - if (adaptation_field_length > 0) { - - if (((packet[5] & 0x10) >> 4) == 1) { - + if((((packet[1] & 0x1F) << 8) | packet[2]) != 0xFF) { + int adaptation_field_control = ((packet[3] & 0x30) >> 4); + if (adaptation_field_control == 2 || adaptation_field_control == 3) { + int adaptation_field_length = packet[4]; + if (adaptation_field_length > 0) { + if (((packet[5] & 0x10) >> 4) == 1) { uint64_t program_clock_reference_base = (uint64_t) packet[6] << 25 | packet[7] << 17 | packet[8] << 9 - | packet[9] << 1 | (packet[10] & 0x80) >> 7; - + | packet[9] << 1 | (packet[10] & 0x80) >> 7; notifyListenersWithPCRBase(program_clock_reference_base); - find = true; - + find = true; } } } @@ -79,4 +73,4 @@ void MonitorPCR::notifyListenersWithPCRBase(uint64_t pcrbase){ for(list::iterator it = this->listeners->begin(); it != this->listeners->end(); it++){ (*it)->notifyPCRBase(pcrbase); } -} \ No newline at end of file +} diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 15f75aa..963f638 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -100,8 +100,18 @@ void ServiceWindowGenerationFromSRT::initialize() { */ inputfile = new InputFile(this->path_input); - extratorSRT = new ExtratorSRT(); - monitor_pcr_base = new MonitorPCR(); + extratorSRT = new ExtratorSRT(); + + monitor_pcr_base = new MonitorPCR(); + + /* [Temporário]: como o monitor do PCR não estava encontrando a extensão do + vídeo, este está sendo analisado e infomado no trecho de código a seguir. + */ + if (strstr(path_input, "ts") != NULL) { + char* format_video = new char[3]; + strcpy(format_video, "ts"); + monitor_pcr_base->setFormatVideo(format_video); + } monitor_pcr_base->addListenerPCRBase(extratorSRT); -- libgit2 0.21.2