inputFile.cpp
1.59 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
#include "inputFile.h"
InputFile::InputFile(char* path) {
this->path = path;
this->listeners = new list<ListenerInput*>();
finish = false;
PRINTL(util::_DEBUG, "Done!\n");
}
InputFile::~InputFile(){
listeners->clear();
delete listeners;
PRINTL(util::_DEBUG, "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];
PRINTL(util::_INFO, "Lendo arquivo...\n");
while (!filein.eof()) {
filein.read(buffer, MAX_SIZE_PACKET);
unsigned char* packet = (unsigned char*) buffer;
notifyListeners(packet);
}
printf("\n");
filein.close();
//finished = true;
} else {
finish = true;
Logging::instance()->writeLog("inputFile.cpp <Error>: Arquivo de vídeo não encontrado.");
throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe.");
}
}
finish = true;
}
bool InputFile::isFinished(){
return this->finish;
}
void InputFile::addListener(ListenerInput* listener){
this->listeners->push_back(listener);
}
void InputFile::removeListener(ListenerInput* listener) {
this->listeners->remove(listener);
}
void InputFile::notifyListeners(unsigned char* pack){
for(list<ListenerInput*>::iterator it = this->listeners->begin(); it != this->listeners->end(); it++){
(*it)->notifyInput(pack);
}
}