extratorSRT.h
2.7 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* \file extratorSRT.h
*
* \author Leonardo de Araújo Domingues <leonardo.araujo@lavid.ufpb.br>
* \date 17/02/2012
*/
#ifndef EXTRATORSRT_H
#define EXTRATORSRT_H
#include <list>
#include <string.h>
#include <stdlib.h>
#include <fstream>
#include <stdio.h>
#include "jthread.h"
#include "extrator.h"
#include "subtitle.h"
#include "listenerSub.h"
#include "extratorException.h"
#define SIZE_CSCAPE 1
#define TARGET_TIME "-->"
#define LESS_THAN "<"
#define MORE_THAN ">"
#define TEMP_SRT "/tmp/tempsrt.srt"
//#define MAX_LINE 1024
using namespace jthread;
using namespace std;
using namespace sndesc;
/** \brief Classe que implementa o extrator de legenda.
*
* Instâncias desta classe extraem o conteúdo de
* arquivos SubRipText(SRT).
*
* \headerfile extrator/src/include/extratorSRT.h
*/
class ExtratorSRT: public Extrator, public Thread {
public:
/** Construtor */
ExtratorSRT();
/** Destrutor */
~ExtratorSRT();
/** Adiciona ouvintes do extratorSRT.
*
* \param listener O ouvinte a ser registrado.
*/
void addListener(ListenerSub* listener);
/** Notifica os ouvintes sobre novas extrações realizadas.
*
* \param subtitle A legenda extraída.
* \param pts Etiqueta de tempo (Presentation timestamp) da legenda.
*/
void notifyListeners(unsigned char* subtitle, int64_t pts);
/** Notifica o fim da extração das legendas.
*
* \param size Quantidade de legendas extraídas.
*/
void notifyEndExtraction(int size);
/** Define o path do arquivo de entrada.
*
* \param path O path do arquivo.
*/
void setFilePath(char* path);
/** Inicializa o processo de extração da legendas.
*
* \exception ExtratorException caso o arquivo de legenda não seja encontrado.
*/
void initialize();
/** Indica o fim do processo de extração das legendas.
*
* \return O status do do processo.
*/
bool isFinished();
/** Retorna o conteúdo da legenda extraída.
*
* \return Referência para um objeto Subtitle.
* \exception ExtratorException se ocorrer algum erro no processo de extração.
*/
Subtitle* next();
/** Indica se há legendas para serem extraídas do arquivo.
*
* \return True se houver legendas, caso contrário, retorna False.
*/
bool hasNextSubtitle();
/** Este método é chamado quando a Thread for iniciada. */
void Run();
private:
list<ListenerSub*> *listeners;
Subtitle *subtitle;
int64_t seek_pos;
bool hasNextSub;
void encodingfiletoUTF8();
string formatText(string line);
uint64_t calcula_pts(double msec);
int64_t str_to_time(std::string str_time);
};
#endif /* EXTRATORSRT_H */