extratorSRT.cpp
2.18 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "extratorSRT.h"
using namespace std;
ExtratorSRT::ExtratorSRT(){
listeners = new list<ListenerSRT*>();
pcr_base = 0;
finish = false;
hasPCRBase = false;
DPRINTF("Done!\n");
}
ExtratorSRT::~ExtratorSRT(){
listeners->clear();
delete listeners;
//delete reader;
DDDPRINTF("Extractor STR finalized!\n");
}
void ExtratorSRT::initialize(){
try{
reader = new ReaderSRT(filepath, FileIO::MODE_READ);
}catch(ReaderException ex){
finish = true;
Util::Logger::Instance()->writeLog((char*) ex.getMessage().c_str());
throw ExtratorSrtException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.");
}
this->Start();
}
void ExtratorSRT::addListener(ListenerSRT* listener){
listeners->push_back(listener);
}
void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) {
for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
(*it)->notifySubtitle(subtitle, pts);
}
}
void ExtratorSRT::notifyEndExtraction(int sub_size) {
DDPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", sub_size);
for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
(*it)->notifyEnd(sub_size);
}
}
void ExtratorSRT::setFilePath(char* path){
filepath = (char*) path;
}
bool ExtratorSRT::isFinished(){
return finish;
}
void ExtratorSRT::Run(){
printf("\n");
DDPRINTF("[AGUARDE] Extraindo SRT...\n")
int sub_index = 0;
string sub_text = "";
while(reader->hasNextSubtitle()){
subtitle = reader->next();
sub_text = subtitle->getSubtitleText();
notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn()));
cout << " . ";
sub_index++;
free(subtitle);
}
printf("\n");
finish = true;
notifyEndExtraction(sub_index);
}
void ExtratorSRT::notifyPCRBase(uint64_t 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));
}