inputFile.cpp
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <list>
#include <stdlib.h>
#include "inputFile.h"
#include "ouvinteInput.h"
InputFile::InputFile(char* path) {
this->path = path;
this->ouvintes = new list<OuvinteInput*>();
finished = false;
DPRINTF("Done!\n");
}
InputFile::~InputFile(){
ouvintes->clear();
delete ouvintes;
DDDPRINTF("Input finalized!\n");
}
void InputFile::initialize(){
ifstream filein(path, ifstream::binary);
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.");
}
}
finished = true;
}
bool InputFile::isFinished(){
return this->finished;
}
void InputFile::registraOuvinte(OuvinteInput* ouvinte){
this->ouvintes->push_back(ouvinte);
}
void InputFile::removeOuvinte(OuvinteInput* ouvinte) {
this->ouvintes->remove(ouvinte);
}
void InputFile::notificaOuvintes(unsigned char* pacote){
for(list<OuvinteInput*>::iterator it = this->ouvintes->begin(); it != this->ouvintes->end(); it++){
(*it)->chegouInput(pacote);
}
}