Commit 90ada98a68ec61b61dd5865e5d1bf9283df745de
1 parent
96c7c6e5
Exists in
master
and in
1 other branch
Criação do componente Extrator utilizando factory pattern
Showing
29 changed files
with
745 additions
and
697 deletions
Show diff stats
... | ... | @@ -0,0 +1,9 @@ |
1 | +#include "extratorException.h" | |
2 | + | |
3 | +ExtratorException::ExtratorException(const string message) | |
4 | + : RuntimeException(message) | |
5 | + { /* TODO */ } | |
6 | +ExtratorException::ExtratorException(const char* message) | |
7 | + : RuntimeException(message) | |
8 | + { /* TODO */ } | |
9 | + | |
0 | 10 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +#include "extratorFactory.h" | |
2 | + | |
3 | +ExtratorFactory::ExtratorFactory(){ | |
4 | + //TODO | |
5 | +} | |
6 | + | |
7 | +ExtratorFactory::~ExtratorFactory(){ | |
8 | + //TODO | |
9 | +} | |
10 | + | |
11 | +Extrator* ExtratorFactory::getExtrator(int extrator_type){ | |
12 | + if(extrator_type == SRT) | |
13 | + return new ExtratorSRT(); | |
14 | + if(extrator_type == TXT) | |
15 | + return new ExtratorTXT(); | |
16 | +} | |
0 | 17 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,168 @@ |
1 | +#include "extratorSRT.h" | |
2 | + | |
3 | +ExtratorSRT::ExtratorSRT(){ | |
4 | + listeners = new list<ListenerSRT*>(); | |
5 | + finish = false; | |
6 | + seek_pos = 0; | |
7 | + hasNextSub = true; | |
8 | + DPRINTF("Done!\n"); | |
9 | +} | |
10 | + | |
11 | +ExtratorSRT::~ExtratorSRT(){ | |
12 | + listeners->clear(); | |
13 | + delete listeners; | |
14 | + if (bff_reader) delete bff_reader; | |
15 | + if (file_io) delete file_io; | |
16 | + DDDPRINTF("ExtratorSTR finalized!\n"); | |
17 | +} | |
18 | + | |
19 | +void ExtratorSRT::initialize(){ | |
20 | + | |
21 | + file = new lavidlib::File(filePath); | |
22 | + | |
23 | + try{ | |
24 | + file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
25 | + }catch(Exception ex){ | |
26 | + finish = true; | |
27 | + Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de legenda não encontrado."); | |
28 | + throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
29 | + } | |
30 | + | |
31 | + this->Start(); | |
32 | +} | |
33 | + | |
34 | + | |
35 | +void ExtratorSRT::addListener(ListenerSRT* listener){ | |
36 | + listeners->push_back(listener); | |
37 | +} | |
38 | + | |
39 | +void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { | |
40 | + for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
41 | + (*it)->notifySubtitle(subtitle, pts); | |
42 | + } | |
43 | +} | |
44 | + | |
45 | +void ExtratorSRT::notifyEndExtraction(int size) { | |
46 | + DDPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); | |
47 | + for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
48 | + (*it)->notifyEnd(size); | |
49 | + } | |
50 | +} | |
51 | + | |
52 | +void ExtratorSRT::setFilePath(char* path){ | |
53 | + filePath = (char*) path; | |
54 | + string command = "perl -p -e \'s/\n/ /\' "; | |
55 | + command.append(filePath).append(" > /dev/null"); | |
56 | + system(command.c_str()); | |
57 | +} | |
58 | + | |
59 | +bool ExtratorSRT::isFinished(){ | |
60 | + return finish; | |
61 | +} | |
62 | + | |
63 | +bool ExtratorSRT::hasNextSubtitle() { | |
64 | + return hasNextSub; | |
65 | +} | |
66 | + | |
67 | +void ExtratorSRT::Run(){ | |
68 | + printf("\n"); | |
69 | + DDPRINTF("[AGUARDE] Extraindo Legendas...\n"); | |
70 | + | |
71 | + int sub_index = 0; | |
72 | + string sub_text = ""; | |
73 | + | |
74 | + while(hasNextSubtitle()){ | |
75 | + subtitle = next(); | |
76 | + sub_text = subtitle->getSubtitleText(); | |
77 | + notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn())); | |
78 | + cout << " . "; | |
79 | + sub_index++; | |
80 | + free(subtitle); | |
81 | + } | |
82 | + printf("\n"); | |
83 | + finish = true; | |
84 | + notifyEndExtraction(sub_index); | |
85 | +} | |
86 | + | |
87 | +Subtitle* ExtratorSRT::next() { | |
88 | + | |
89 | + if (seek_pos >= file_io->getSize()) | |
90 | + throw ExtratorException("[ERRO: extratorSRT.cpp] Esse arquivo já foi lido."); | |
91 | + | |
92 | + file_io->seek(seek_pos); | |
93 | + try{ | |
94 | + bff_reader = new BufferedReader(file_io); | |
95 | + }catch(Exception &ex){ | |
96 | + throw ExtratorException("[ERRO: extratorSRT.cpp] O BufferedReader não foi inicializado."); | |
97 | + } | |
98 | + | |
99 | + Subtitle* sub = new Subtitle(); | |
100 | + string line = ""; | |
101 | + string text_sub = ""; | |
102 | + | |
103 | + try { | |
104 | + /* ID */ | |
105 | + int id = 0; | |
106 | + line = bff_reader->readLine(); | |
107 | + seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
108 | + id = atoi(line.c_str()); | |
109 | + sub->setID(id); | |
110 | + | |
111 | + /* TimeIn and TimeOut */ | |
112 | + int64_t t_in = 0, t_out = 0; | |
113 | + line = bff_reader->readLine(); | |
114 | + seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
115 | + | |
116 | + int target_pos = line.find(TARGET_TIME); | |
117 | + t_in = str_to_time(line.substr(0, target_pos)); | |
118 | + sub->setTimeIn(t_in); | |
119 | + t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); | |
120 | + sub->setTimeOut(t_out); | |
121 | + | |
122 | + /* Text: read until line be empty */ | |
123 | + while ((line = bff_reader->readLine()).size() > 0) { | |
124 | + text_sub += line; | |
125 | + text_sub.append(" "); | |
126 | + } | |
127 | + seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | |
128 | + | |
129 | + } catch (lavidlib::EOFException &ex) { | |
130 | + sub->setSubtitleText(text_sub); | |
131 | + seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | |
132 | + hasNextSub = false; | |
133 | + return sub; | |
134 | + } | |
135 | + sub->setSubtitleText(text_sub); | |
136 | + delete(bff_reader); | |
137 | + return sub; | |
138 | + | |
139 | + } | |
140 | + | |
141 | + | |
142 | +int64_t ExtratorSRT::str_to_time(string str_time) { | |
143 | + | |
144 | + int64_t ttime = 0; | |
145 | + char* tokens = new char[4]; // hh, mm, ss, ms | |
146 | + strcpy(tokens, (char*)str_time.c_str()); | |
147 | + | |
148 | + int index = 0; | |
149 | + int values [4]; // hh, mm, ss, ms | |
150 | + char * str = strtok(tokens, ":,"); | |
151 | + while (str != NULL) { | |
152 | + values[index] = atoi(str); | |
153 | + str = strtok(NULL, ":,"); | |
154 | + index++; | |
155 | + } | |
156 | + delete(tokens); | |
157 | + | |
158 | + /* calculate time */ | |
159 | + ttime = /*hour to sec*/((((values[0] * 60) * 60) + | |
160 | + /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; | |
161 | + | |
162 | + return ttime; | |
163 | + | |
164 | + } | |
165 | + | |
166 | +uint64_t ExtratorSRT::calcula_pts(double msec) { | |
167 | + return (uint64_t)(1000 /*pcr_base*/ + ((msec/1000) * 90000.0)); | |
168 | +} | ... | ... |
... | ... | @@ -0,0 +1,93 @@ |
1 | +/*************************************************************************** | |
2 | + * Universidade Federal da Paraíba * | |
3 | + * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | + * * | |
5 | + * Centro de Informática - UFPB - Campus I * | |
6 | + * João Pessoa - PB - Brasil * | |
7 | + * * | |
8 | + * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | + * * | |
10 | + **************************************************************************/ | |
11 | + | |
12 | +#include "extratorTXT.h" | |
13 | + | |
14 | +ExtratorTXT::ExtratorTXT(){ | |
15 | + listeners = new list<ListenerTXT*>(); | |
16 | + finish = false; | |
17 | + DPRINTF("Done!\n"); | |
18 | +} | |
19 | + | |
20 | +ExtratorTXT::~ExtratorTXT(){ | |
21 | + listeners->clear(); | |
22 | + delete listeners; | |
23 | + delete file; | |
24 | + delete file_io; | |
25 | + delete bff_reader; | |
26 | + DDDPRINTF("ExtratorTXT finalized!\n"); | |
27 | +} | |
28 | + | |
29 | +void ExtratorTXT::initialize(){ | |
30 | + file = new lavidlib::File(filePath); | |
31 | + try{ | |
32 | + file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
33 | + bff_reader = new BufferedReader(file_io); | |
34 | + }catch(Exception &ex){ | |
35 | + finish = true; | |
36 | + Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Arquivo de texto não encontrado."); | |
37 | + throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); | |
38 | + } | |
39 | + this->Start(); | |
40 | +} | |
41 | + | |
42 | +void ExtratorTXT::addListener(ListenerTXT* listener){ | |
43 | + listeners->push_back(listener); | |
44 | +} | |
45 | + | |
46 | +void ExtratorTXT::notifyListeners(unsigned char* line) { | |
47 | + for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
48 | + (*it)->notifyLine(line); | |
49 | + } | |
50 | +} | |
51 | + | |
52 | +void ExtratorTXT::notifyEndExtraction(int size) { | |
53 | + DDPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); | |
54 | + for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
55 | + (*it)->notifyEnd(size); | |
56 | + } | |
57 | +} | |
58 | + | |
59 | +void ExtratorTXT::setFilePath(char* path){ | |
60 | + filePath = (char*) path; | |
61 | +} | |
62 | + | |
63 | +bool ExtratorTXT::isFinished(){ | |
64 | + return finish; | |
65 | +} | |
66 | + | |
67 | +void ExtratorTXT::Run(){ | |
68 | + | |
69 | + DDPRINTF("[AGUARDE] Extraindo Texto...\n") | |
70 | + | |
71 | + int line_index = 0; | |
72 | + bool hasNext = true; | |
73 | + string line; | |
74 | + | |
75 | + while (hasNext) { | |
76 | + try{ | |
77 | + line = bff_reader->readLine(); | |
78 | + if (line.length() > 0){ | |
79 | + notifyListeners((unsigned char*) line.c_str()); | |
80 | + cout << " . "; | |
81 | + line_index++; | |
82 | + } | |
83 | + }catch (EOFException &ex){ | |
84 | + hasNext = false; | |
85 | + }catch (...){ | |
86 | + Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Erro durante a leitura do arquivo de texto."); | |
87 | + throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); | |
88 | + } | |
89 | + } | |
90 | + printf("\n"); | |
91 | + finish = true; | |
92 | + notifyEndExtraction(line_index); | |
93 | +} | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +#ifndef EXTRATOR_H | |
2 | +#define EXTRATOR_H | |
3 | + | |
4 | +#include <lavidlib/io/File.h> | |
5 | +#include <lavidlib/io/FileIO.h> | |
6 | +#include <lavidlib/io/BufferedReader.h> | |
7 | +#include <lavidlib/io/IOException.h> | |
8 | +#include <lavidlib/io/EOFException.h> | |
9 | + | |
10 | +using namespace lavidlib; | |
11 | + | |
12 | +class Extrator { | |
13 | + | |
14 | +protected: | |
15 | + char* filePath; | |
16 | + bool finish; | |
17 | + | |
18 | + File* file; | |
19 | + FileIO* file_io; | |
20 | + BufferedReader* bff_reader; | |
21 | + | |
22 | +public: | |
23 | + virtual void notifyEndExtraction(int size) = 0; | |
24 | + virtual void setFilePath(char* path) = 0; | |
25 | + virtual void initialize() = 0; | |
26 | + virtual bool isFinished() = 0; | |
27 | +}; | |
28 | + | |
29 | +#endif /* EXTRATOR_H */ | |
0 | 30 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +#ifndef EXTRATOREXCEPTION_H | |
2 | +#define EXTRATOREXCEPTION_H | |
3 | + | |
4 | +#include <lavidlib/base/RuntimeException.h> | |
5 | + | |
6 | +using namespace lavidlib; | |
7 | +using namespace std; | |
8 | + | |
9 | +class ExtratorException : public RuntimeException { | |
10 | +public: | |
11 | + /** | |
12 | + * Construtor da classe. | |
13 | + * Cria uma nova exceção com uma mensagem detalhada. | |
14 | + * @param message A mensagem em forma de um objeto string. | |
15 | + */ | |
16 | + ExtratorException(const string message); | |
17 | + | |
18 | + /** | |
19 | + * Construtor da classe. | |
20 | + * Cria uma nova exceção com uma mensagem detalhada. | |
21 | + * @param message A mensagem em forma de um array de caracteres. | |
22 | + */ | |
23 | + ExtratorException(const char* message); | |
24 | +}; | |
25 | + | |
26 | +#endif /* EXTRATOREXCEPTION_H */ | |
0 | 27 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +#ifndef EXTRATORFACTORY_H | |
2 | +#define EXTRATORFACTORY_H | |
3 | + | |
4 | +#include "extrator.h" | |
5 | +#include "extratorSRT.h" | |
6 | +#include "extratorTXT.h" | |
7 | + | |
8 | +#define SRT 1 | |
9 | +#define TXT 2 | |
10 | + | |
11 | +class ExtratorFactory{ | |
12 | + | |
13 | +public: | |
14 | + ExtratorFactory(); | |
15 | + ~ExtratorFactory(); | |
16 | + | |
17 | + Extrator* getExtrator(int extrator_type); | |
18 | + | |
19 | +}; | |
20 | + | |
21 | +#endif /* EXTRATORFACTORY_H */ | |
0 | 22 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,66 @@ |
1 | +/* | |
2 | + * File: extratorSRT.h | |
3 | + * Author: leonardo | |
4 | + * | |
5 | + * Created on 17 de Fevereiro de 2012, 17:51 | |
6 | + */ | |
7 | +#ifndef EXTRATORSRT_H | |
8 | +#define EXTRATORSRT_H | |
9 | + | |
10 | +#include <list> | |
11 | +#include <string.h> | |
12 | +#include <stdlib.h> | |
13 | +#include <fstream> | |
14 | +#include <stdio.h> | |
15 | +#include "jthread.h" | |
16 | +#include "dprintf.h" | |
17 | +#include "logger.h" | |
18 | +#include "extrator.h" | |
19 | +#include "subtitle.h" | |
20 | +#include "listenerSRT.h" | |
21 | +#include "extratorException.h" | |
22 | + | |
23 | +#define SIZE_CSCAPE 1 | |
24 | +#define TARGET_TIME "-->" | |
25 | +//#define MAX_LINE 1024 | |
26 | + | |
27 | +using namespace jthread; | |
28 | +using namespace std; | |
29 | +using namespace sndesc; | |
30 | + | |
31 | +/** Classe que modela ExtratorSRT. | |
32 | +* Instâncias do tipo ExtratorSRT são modelados | |
33 | +* a partir desta classe, esses objetos são | |
34 | +* responsáveis por extrair o conteudo de arquivos | |
35 | +* com a extensão SubRipText(SRT). | |
36 | +*/ | |
37 | +class ExtratorSRT: public Extrator, public Thread { | |
38 | + | |
39 | +public: | |
40 | + ExtratorSRT(); | |
41 | + ~ExtratorSRT(); | |
42 | + | |
43 | + void addListener(ListenerSRT* listener); | |
44 | + void notifyListeners(unsigned char* subtitle, int64_t pts); | |
45 | + void notifyEndExtraction(int size); | |
46 | + | |
47 | + void setFilePath(char* path); | |
48 | + void initialize(); | |
49 | + bool isFinished(); | |
50 | + | |
51 | + Subtitle* next(); | |
52 | + bool hasNextSubtitle(); | |
53 | + void Run(); | |
54 | + | |
55 | +private: | |
56 | + list<ListenerSRT*> *listeners; | |
57 | + | |
58 | + Subtitle *subtitle; | |
59 | + int64_t seek_pos; | |
60 | + bool hasNextSub; | |
61 | + | |
62 | + uint64_t calcula_pts(double msec); | |
63 | + int64_t str_to_time(std::string str_time); | |
64 | +}; | |
65 | + | |
66 | +#endif /* EXTRATORSRT_H */ | |
0 | 67 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +/*************************************************************************** | |
2 | + * Universidade Federal da Paraíba * | |
3 | + * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | + * * | |
5 | + * Centro de Informática - UFPB - Campus I * | |
6 | + * João Pessoa - PB - Brasil * | |
7 | + * * | |
8 | + * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | + * * | |
10 | + **************************************************************************/ | |
11 | + | |
12 | +#ifndef EXTRATORTXT_H | |
13 | +#define EXTRATORTXT_H | |
14 | + | |
15 | +#include <list> | |
16 | +#include "jthread.h" | |
17 | +#include "dprintf.h" | |
18 | +#include "logger.h" | |
19 | +#include "extrator.h" | |
20 | +#include "listenerTXT.h" | |
21 | +#include "extratorException.h" | |
22 | + | |
23 | +using namespace jthread; | |
24 | +using namespace std; | |
25 | + | |
26 | +/** | |
27 | +* Classe que modela o ExtratorTXT. | |
28 | +* O ExtratorTXT extrai o conteúdo | |
29 | +* de um arquivo txt. | |
30 | +*/ | |
31 | +class ExtratorTXT: public Extrator, public Thread { | |
32 | + | |
33 | +public: | |
34 | + ExtratorTXT(); | |
35 | + ~ExtratorTXT(); | |
36 | + | |
37 | + void addListener(ListenerTXT* listener); | |
38 | + void notifyListeners(unsigned char* line); | |
39 | + void notifyEndExtraction(int size); | |
40 | + | |
41 | + void setFilePath(char* path); | |
42 | + void initialize(); | |
43 | + bool isFinished(); | |
44 | + | |
45 | + void Run(); | |
46 | + | |
47 | +private: | |
48 | + list<ListenerTXT*> *listeners; | |
49 | +}; | |
50 | + | |
51 | +#endif /* EXTRATORTXT_H */ | |
52 | + | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +#ifndef LISTENERSRT_H | |
2 | +#define LISTENERSRT_H | |
3 | + | |
4 | +#include <stdint.h> | |
5 | + | |
6 | +class ListenerSRT{ | |
7 | + | |
8 | +public: | |
9 | + virtual void notifySubtitle(unsigned char* subtitle, int64_t pts) = 0; | |
10 | + virtual void notifyEnd(int sub_size) = 0; | |
11 | +}; | |
12 | + | |
13 | +#endif /* LISTENEREXTRATOR_H */ | |
0 | 14 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +#ifndef LISTENERTXT_H | |
2 | +#define LISTENERTXT_H | |
3 | + | |
4 | +#include <stdint.h> | |
5 | + | |
6 | +class ListenerTXT { | |
7 | +public: | |
8 | + virtual void notifyLine(unsigned char* line) = 0; | |
9 | + virtual void notifyEnd(int line_size) = 0; | |
10 | +}; | |
11 | + | |
12 | + | |
13 | +#endif /* LISTENERTXT_H */ | |
0 | 14 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,138 @@ |
1 | +/*************************************************************************** | |
2 | + * Universidade Federal da Paraíba * | |
3 | + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | |
4 | + * * | |
5 | + * Centro de Informática - UFPB - Campus I * | |
6 | + * João Pessoa - PB - Brasil * | |
7 | + * * | |
8 | + * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | |
9 | + * Date: Qui Out 24 22:26:35 BRT 2013 * | |
10 | + * * | |
11 | + **************************************************************************/ | |
12 | + | |
13 | + #ifndef SUBTITLE_H | |
14 | + #define SUBTITLE_H | |
15 | + | |
16 | + #include <string> | |
17 | + #include <stdint.h> | |
18 | + #include <stdio.h> | |
19 | + | |
20 | + #define MAX_FIELD 64 | |
21 | + | |
22 | + using namespace std; | |
23 | + | |
24 | + namespace sndesc { | |
25 | + | |
26 | + /** | |
27 | + * Classe que modela legendas. | |
28 | + * Objetos com informações de legendas | |
29 | + * são implementados através desta classe. | |
30 | + */ | |
31 | + class Subtitle { | |
32 | + | |
33 | + public: | |
34 | + /** | |
35 | + * Construtor da classe. | |
36 | + * Cria uma nova instância da classe para | |
37 | + * representar uma legenda, as variáveis | |
38 | + * iniciam com valores default. | |
39 | + */ | |
40 | + Subtitle(); | |
41 | + | |
42 | + /** | |
43 | + * Construtor da clasee. | |
44 | + * Cria uma nova instância da classe para a representar uma legenda, | |
45 | + * as variáveis iniciam com valores passados por parametros. | |
46 | + * @param _id O numero da legenda. | |
47 | + * @param _sub_text O texto da legenda. | |
48 | + * @param _timein O tempo de inicio da legenda. | |
49 | + * @param _timeout O tempo de termino da legenda. | |
50 | + */ | |
51 | + Subtitle(int _id, string _sub_text, int64_t _timein, int64_t _timeout); | |
52 | + | |
53 | + /** | |
54 | + * Destrutor da classe. | |
55 | + * Desaloca todo espaço de armazenamento atribuído | |
56 | + * para a instância do Subtitle. | |
57 | + */ | |
58 | + ~Subtitle(); | |
59 | + | |
60 | + /** | |
61 | + * Seta o id da legenda. | |
62 | + * @param _id O numero da legenda. | |
63 | + */ | |
64 | + void setID(int _id); | |
65 | + | |
66 | + /** | |
67 | + * Seta o texto da legenda. | |
68 | + * @param _subtext O texto da legenda. | |
69 | + */ | |
70 | + void setSubtitleText(std::string _subtext); | |
71 | + | |
72 | + /** | |
73 | + * Seta o tempo de inicio da legenda. | |
74 | + * @param _timein O tempo de entrada da legenda. | |
75 | + */ | |
76 | + void setTimeIn(int64_t _timein); | |
77 | + | |
78 | + /** | |
79 | + * Seta o tempo de termino da legenda. | |
80 | + * @param _timeout O tempo de saida da legenda. | |
81 | + */ | |
82 | + void setTimeOut(int64_t _timeout); | |
83 | + | |
84 | + /** | |
85 | + * Obtém o texto da legenda. | |
86 | + * @return O texto da legenda. | |
87 | + */ | |
88 | + std::string getSubtitleText(); | |
89 | + | |
90 | + /** | |
91 | + * Obtém o tempo de inicio da legenda. | |
92 | + * @return O tempo de inicio. | |
93 | + */ | |
94 | + int64_t getTimeIn(); | |
95 | + | |
96 | + /** | |
97 | + * Obtém o tempo de termino da legenda. | |
98 | + * @return O tempo de saida. | |
99 | + */ | |
100 | + int64_t getTimeOut(); | |
101 | + | |
102 | + /** | |
103 | + * Obtém o id da legenda. | |
104 | + * @return O numero da legenda. | |
105 | + */ | |
106 | + int getID(); | |
107 | + | |
108 | + /** | |
109 | + * Converte os dados de uma legenda em uma string. | |
110 | + * @return Uma string com a representação da legenda. | |
111 | + */ | |
112 | + string toString(); | |
113 | + | |
114 | + private: | |
115 | + /** | |
116 | + * O numero da legenda. | |
117 | + */ | |
118 | + int id; | |
119 | + | |
120 | + /** | |
121 | + * O texto da legenda. | |
122 | + */ | |
123 | + string subtitle_text; | |
124 | + | |
125 | + /** | |
126 | + * O tempo de entrada da legenda. | |
127 | + */ | |
128 | + int64_t time_in; | |
129 | + | |
130 | + /** | |
131 | + * O tempo de saida da legenda. | |
132 | + */ | |
133 | + int64_t time_out; | |
134 | + | |
135 | + }; | |
136 | +} | |
137 | + | |
138 | +#endif /* SUBTITLE_H */ | ... | ... |
... | ... | @@ -0,0 +1,82 @@ |
1 | +/*************************************************************************** | |
2 | + * Universidade Federal da Paraíba * | |
3 | + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | |
4 | + * * | |
5 | + * Centro de Informática - UFPB - Campus I * | |
6 | + * João Pessoa - PB - Brasil * | |
7 | + * * | |
8 | + * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | |
9 | + * Date: Qui Out 24 22:31:50 BRT 2013 * | |
10 | + * * | |
11 | + **************************************************************************/ | |
12 | + | |
13 | + #include "subtitle.h" | |
14 | + | |
15 | + namespace sndesc { | |
16 | + | |
17 | + Subtitle::Subtitle() { | |
18 | + //TODO: default parameters! | |
19 | + } | |
20 | + | |
21 | + Subtitle::Subtitle (int _id, string _sub_text, | |
22 | + int64_t _timein, int64_t _timeout) { | |
23 | + | |
24 | + int id = _id; | |
25 | + subtitle_text = _sub_text; | |
26 | + time_in = _timein; | |
27 | + time_out = _timeout; | |
28 | + | |
29 | + } | |
30 | + | |
31 | + Subtitle::~Subtitle() { | |
32 | + //TODO: delete objects and free memory | |
33 | + } | |
34 | + | |
35 | + void Subtitle::setID(int _id) { | |
36 | + id = _id; | |
37 | + } | |
38 | + | |
39 | + int Subtitle::getID() { | |
40 | + return id; | |
41 | + } | |
42 | + | |
43 | + void Subtitle::setSubtitleText(string _subtext) { | |
44 | + subtitle_text = _subtext; | |
45 | + } | |
46 | + | |
47 | + void Subtitle::setTimeIn(int64_t _timein) { | |
48 | + time_in = _timein; | |
49 | + } | |
50 | + | |
51 | + void Subtitle::setTimeOut(int64_t _timeout) { | |
52 | + time_out = _timeout; | |
53 | + } | |
54 | + | |
55 | + std::string Subtitle::getSubtitleText() { | |
56 | + return subtitle_text; | |
57 | + } | |
58 | + | |
59 | + int64_t Subtitle::getTimeIn() { | |
60 | + return time_in; | |
61 | + } | |
62 | + | |
63 | + int64_t Subtitle::getTimeOut() { | |
64 | + return time_out; | |
65 | + } | |
66 | + | |
67 | + string Subtitle::toString() { | |
68 | + | |
69 | + string subtitle_str; | |
70 | + char buffer [MAX_FIELD]; | |
71 | + sprintf(buffer, "%d", id); | |
72 | + subtitle_str.append("\n{id: ").append((string)buffer); | |
73 | + sprintf(buffer, "%ld", time_in); | |
74 | + subtitle_str.append(", time_in: ").append((string)buffer); | |
75 | + sprintf(buffer, "%ld", time_out); | |
76 | + subtitle_str.append(", time_out: ").append((string)buffer); | |
77 | + subtitle_str.append(", text: ").append(subtitle_text).append("}\n"); | |
78 | + | |
79 | + return subtitle_str; | |
80 | + } | |
81 | + | |
82 | + } | |
0 | 83 | \ No newline at end of file | ... | ... |
extratorSRT/src/extratorSRT.cpp
... | ... | @@ -1,173 +0,0 @@ |
1 | - | |
2 | -#include "extratorSRT.h" | |
3 | - | |
4 | - | |
5 | -ExtratorSRT::ExtratorSRT(){ | |
6 | - listeners = new list<ListenerSRT*>(); | |
7 | - finish = false; | |
8 | - seek_pos = 0; | |
9 | - hasNextSub = true; | |
10 | - DPRINTF("Done!\n"); | |
11 | -} | |
12 | - | |
13 | -ExtratorSRT::~ExtratorSRT(){ | |
14 | - listeners->clear(); | |
15 | - delete listeners; | |
16 | - if (bff_reader) delete bff_reader; | |
17 | - if (file_io) delete file_io; | |
18 | - DDDPRINTF("Extractor STR finalized!\n"); | |
19 | -} | |
20 | - | |
21 | -void ExtratorSRT::initialize(){ | |
22 | - | |
23 | - file = new lavidlib::File(filepath); | |
24 | - | |
25 | - try{ | |
26 | - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
27 | - }catch(Exception ex){ | |
28 | - finish = true; | |
29 | - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de legenda não encontrado."); | |
30 | - throw ExtratorSrtException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
31 | - } | |
32 | - | |
33 | - this->Start(); | |
34 | -} | |
35 | - | |
36 | - | |
37 | -void ExtratorSRT::addListener(ListenerSRT* listener){ | |
38 | - listeners->push_back(listener); | |
39 | -} | |
40 | - | |
41 | -void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { | |
42 | - for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
43 | - (*it)->notifySubtitle(subtitle, pts); | |
44 | - } | |
45 | -} | |
46 | - | |
47 | -void ExtratorSRT::notifyEndExtraction(int sub_size) { | |
48 | - DDPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", sub_size); | |
49 | - for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
50 | - (*it)->notifyEnd(sub_size); | |
51 | - } | |
52 | -} | |
53 | - | |
54 | -void ExtratorSRT::setFilePath(char* path){ | |
55 | - filepath = (char*) path; | |
56 | - string command = "perl -p -e \'s/\n/ /\' "; | |
57 | - command.append(filepath).append(" > /dev/null"); | |
58 | - system(command.c_str()); | |
59 | -} | |
60 | - | |
61 | -bool ExtratorSRT::isFinished(){ | |
62 | - return finish; | |
63 | -} | |
64 | - | |
65 | -bool ExtratorSRT::hasNextSubtitle() { | |
66 | - return hasNextSub; | |
67 | -} | |
68 | - | |
69 | -void ExtratorSRT::Run(){ | |
70 | - printf("\n"); | |
71 | - DDPRINTF("[AGUARDE] Extraindo SRT...\n"); | |
72 | - | |
73 | - int sub_index = 0; | |
74 | - string sub_text = ""; | |
75 | - | |
76 | - while(hasNextSubtitle()){ | |
77 | - subtitle = next(); | |
78 | - sub_text = subtitle->getSubtitleText(); | |
79 | - notifyListeners((unsigned char*)sub_text.c_str(), calcula_pts((double) subtitle->getTimeIn())); | |
80 | - cout << " . "; | |
81 | - sub_index++; | |
82 | - free(subtitle); | |
83 | - } | |
84 | - printf("\n"); | |
85 | - finish = true; | |
86 | - notifyEndExtraction(sub_index); | |
87 | -} | |
88 | - | |
89 | -Subtitle* ExtratorSRT::next() { | |
90 | - | |
91 | - if (seek_pos >= file_io->getSize()) | |
92 | - throw ExtratorSrtException("[ERRO: extratorSRT.cpp] Esse arquivo já foi lido."); | |
93 | - | |
94 | - file_io->seek(seek_pos); | |
95 | - try{ | |
96 | - bff_reader = new BufferedReader(file_io); | |
97 | - }catch(Exception &ex){ | |
98 | - throw ExtratorSrtException("[ERRO: extratorSRT.cpp] O BufferedReader não foi inicializado."); | |
99 | - } | |
100 | - | |
101 | - Subtitle* sub = new Subtitle(); | |
102 | - std::string line = ""; | |
103 | - std::string text_sub = ""; | |
104 | - | |
105 | - try { | |
106 | - /* ID */ | |
107 | - int id = 0; | |
108 | - line = bff_reader->readLine(); | |
109 | - seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
110 | - id = atoi(line.c_str()); | |
111 | - sub->setID(id); | |
112 | - | |
113 | - /* TimeIn and TimeOut */ | |
114 | - int64_t t_in = 0, t_out = 0; | |
115 | - line = bff_reader->readLine(); | |
116 | - seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
117 | - | |
118 | - int target_pos = line.find(TARGET_TIME); | |
119 | - t_in = str_to_time(line.substr(0, target_pos)); | |
120 | - sub->setTimeIn(t_in); | |
121 | - t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); | |
122 | - sub->setTimeOut(t_out); | |
123 | - | |
124 | - /* Text: read until line be empty */ | |
125 | - while ((line = bff_reader->readLine()).size() > 0) { | |
126 | - text_sub += line; | |
127 | - text_sub.append(" "); | |
128 | - } | |
129 | - seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | |
130 | - | |
131 | - } catch (lavidlib::EOFException &ex) { | |
132 | - sub->setSubtitleText(text_sub); | |
133 | - sub->setStatusOfReady(true); | |
134 | - //delete(bff_reader); | |
135 | - seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; | |
136 | - hasNextSub = false; | |
137 | - return sub; | |
138 | - } | |
139 | - sub->setSubtitleText(text_sub); | |
140 | - sub->setStatusOfReady(true); | |
141 | - delete(bff_reader); | |
142 | - return sub; | |
143 | - | |
144 | - } | |
145 | - | |
146 | - | |
147 | -int64_t ExtratorSRT::str_to_time(std::string str_time) { | |
148 | - | |
149 | - int64_t ttime = 0; | |
150 | - char* tokens = new char[4]; // hh, mm, ss, ms | |
151 | - strcpy(tokens, (char*)str_time.c_str()); | |
152 | - | |
153 | - int index = 0; | |
154 | - int values [4]; // hh, mm, ss, ms | |
155 | - char * str = strtok(tokens, ":,"); | |
156 | - while (str != NULL) { | |
157 | - values[index] = atoi(str); | |
158 | - str = strtok(NULL, ":,"); | |
159 | - index++; | |
160 | - } | |
161 | - delete(tokens); | |
162 | - | |
163 | - /* calculate time */ | |
164 | - ttime = /*hour to sec*/((((values[0] * 60) * 60) + | |
165 | - /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; | |
166 | - | |
167 | - return ttime; | |
168 | - | |
169 | - } | |
170 | - | |
171 | -uint64_t ExtratorSRT::calcula_pts(double msec) { | |
172 | - return (uint64_t)(1000 /*pcr_base*/ + ((msec/1000) * 90000.0)); | |
173 | -} | |
174 | 0 | \ No newline at end of file |
extratorSRT/src/extratorSRT_exception.cpp
... | ... | @@ -1,22 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | - | |
13 | - | |
14 | - #include "extratorSRT_exception.h" | |
15 | - | |
16 | - ExtratorSrtException::ExtratorSrtException(const std::string message) | |
17 | - : RuntimeException(message) | |
18 | - { /* TODO */ } | |
19 | - ExtratorSrtException::ExtratorSrtException(const char* message) | |
20 | - : RuntimeException(message) | |
21 | - { /* TODO */ } | |
22 | - | |
23 | 0 | \ No newline at end of file |
extratorSRT/src/include/extratorSRT.h
... | ... | @@ -1,74 +0,0 @@ |
1 | -/* | |
2 | - * File: extratorSRT.h | |
3 | - * Author: leonardo | |
4 | - * | |
5 | - * Created on 17 de Fevereiro de 2012, 17:51 | |
6 | - */ | |
7 | - | |
8 | -#ifndef EXTRATORSRT_H | |
9 | -#define EXTRATORSRT_H | |
10 | - | |
11 | -#include <string.h> | |
12 | -#include <stdlib.h> | |
13 | -#include <fstream> | |
14 | -#include <stdio.h> | |
15 | -#include <list> | |
16 | -#include <lavidlib/io/File.h> | |
17 | -#include <lavidlib/io/FileIO.h> | |
18 | -#include <lavidlib/io/BufferedReader.h> | |
19 | -#include <lavidlib/io/IOException.h> | |
20 | -#include <lavidlib/io/EOFException.h> | |
21 | -#include "jthread.h" | |
22 | -#include "dprintf.h" | |
23 | -#include "logger.h" | |
24 | -#include "subtitle.h" | |
25 | -#include "listenerSRT.h" | |
26 | -#include "extratorSRT_exception.h" | |
27 | - | |
28 | -#define SIZE_CSCAPE 1 | |
29 | -#define TARGET_TIME "-->" | |
30 | -//#define MAX_LINE 1024 | |
31 | - | |
32 | -using namespace jthread; | |
33 | -using namespace std; | |
34 | -using namespace sndesc; | |
35 | - | |
36 | -class ExtratorSRT: public Thread { | |
37 | - | |
38 | -public: | |
39 | - | |
40 | - ExtratorSRT(); | |
41 | - ~ExtratorSRT(); | |
42 | - | |
43 | - void addListener(ListenerSRT* listener); | |
44 | - void notifyListeners(unsigned char* subtitle, int64_t pts); | |
45 | - void notifyEndExtraction(int sub_size); | |
46 | - | |
47 | - bool hasNextSubtitle(); | |
48 | - void setFilePath(char* path); | |
49 | - bool isFinished(); | |
50 | - void initialize(); | |
51 | - void Run(); | |
52 | - | |
53 | - Subtitle* next(); | |
54 | - | |
55 | -private: | |
56 | - | |
57 | - list<ListenerSRT*> *listeners; | |
58 | - char *filepath; | |
59 | - bool finish; | |
60 | - File *file; | |
61 | - FileIO *file_io; | |
62 | - BufferedReader *bff_reader; | |
63 | - Subtitle *subtitle; | |
64 | - | |
65 | - int64_t seek_pos; | |
66 | - bool hasNextSub; | |
67 | - | |
68 | - uint64_t calcula_pts(double msec); | |
69 | - int64_t str_to_time(std::string str_time); | |
70 | - | |
71 | -}; | |
72 | - | |
73 | -#endif /* EXTRATORSRT_H */ | |
74 | - |
extratorSRT/src/include/extratorSRT_exception.h
... | ... | @@ -1,26 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | -#ifndef EXTRATORSRTEXCEPTION_H | |
13 | -#define EXTRATORSRTEXCEPTION_H | |
14 | - | |
15 | -#include <lavidlib/base/RuntimeException.h> | |
16 | - | |
17 | -using namespace lavidlib; | |
18 | - | |
19 | - class ExtratorSrtException : public RuntimeException { | |
20 | - public: | |
21 | - ExtratorSrtException(const std::string message); | |
22 | - ExtratorSrtException(const char* message); | |
23 | - }; | |
24 | - | |
25 | - | |
26 | -#endif /* EXTRATORSRTEXCEPTION_H */ | |
27 | 0 | \ No newline at end of file |
extratorSRT/src/include/listenerSRT.h
... | ... | @@ -1,21 +0,0 @@ |
1 | -/* | |
2 | - * File: listenerSRT.h | |
3 | - * Author: leonardo | |
4 | - * | |
5 | - * Created on 17 de Fevereiro de 2012, 18:01 | |
6 | - */ | |
7 | - | |
8 | -#ifndef LISTENERSRT_H | |
9 | -#define LISTENERSRT_H | |
10 | - | |
11 | -#include <stdint.h> | |
12 | - | |
13 | -class ListenerSRT { | |
14 | - | |
15 | -public: | |
16 | - virtual void notifySubtitle(unsigned char* subtitle, int64_t pts) = 0; | |
17 | - virtual void notifyEnd(int sub_size) = 0; | |
18 | -}; | |
19 | - | |
20 | -#endif /* LISTENERSRT_H */ | |
21 | - |
extratorSRT/src/include/subtitle.h
... | ... | @@ -1,53 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | |
9 | - * Date: Qui Out 24 22:26:35 BRT 2013 * | |
10 | - * * | |
11 | - **************************************************************************/ | |
12 | - | |
13 | - #ifndef SUBTITLE_H | |
14 | - #define SUBTITLE_H | |
15 | - | |
16 | - #include <string> | |
17 | - #include <stdint.h> | |
18 | - #include <stdio.h> | |
19 | - | |
20 | - #define MAX_FIELD 64 | |
21 | - | |
22 | - namespace sndesc { | |
23 | - | |
24 | - class Subtitle { | |
25 | - | |
26 | - public: | |
27 | - Subtitle(); | |
28 | - Subtitle(int _id, std::string _sub_text, int64_t _timein, int64_t _timeout); | |
29 | - ~Subtitle(); | |
30 | - void setID(int _id); | |
31 | - void setSubtitleText(std::string _subtext); | |
32 | - void setTimeIn(int64_t _timein); | |
33 | - void setTimeOut(int64_t _timeout); | |
34 | - std::string getSubtitleText(); | |
35 | - int64_t getTimeIn(); | |
36 | - int64_t getTimeOut(); | |
37 | - int getID(); | |
38 | - void setStatusOfReady(bool status); | |
39 | - bool isReady(); | |
40 | - std::string toString(); | |
41 | - | |
42 | - private: | |
43 | - int id; | |
44 | - std::string subtitle_text; | |
45 | - int64_t time_in; | |
46 | - int64_t time_out; | |
47 | - bool ready; | |
48 | - | |
49 | - }; | |
50 | - | |
51 | -} | |
52 | - | |
53 | -#endif // SUBTITLE_H |
extratorSRT/src/subtitle.cpp
... | ... | @@ -1,92 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | |
9 | - * Date: Qui Out 24 22:31:50 BRT 2013 * | |
10 | - * * | |
11 | - **************************************************************************/ | |
12 | - | |
13 | - #include "subtitle.h" | |
14 | - | |
15 | - namespace sndesc { | |
16 | - | |
17 | - Subtitle::Subtitle() { | |
18 | - //TODO: default parameters! | |
19 | - } | |
20 | - | |
21 | - Subtitle::Subtitle (int _id, std::string _sub_text, | |
22 | - int64_t _timein, int64_t _timeout) { | |
23 | - | |
24 | - int id = _id; | |
25 | - subtitle_text = _sub_text; | |
26 | - time_in = _timein; | |
27 | - time_out = _timeout; | |
28 | - ready = true; | |
29 | - | |
30 | - } | |
31 | - | |
32 | - Subtitle::~Subtitle() { | |
33 | - //TODO: delete objects and free memory | |
34 | - } | |
35 | - | |
36 | - void Subtitle::setID(int _id) { | |
37 | - id = _id; | |
38 | - } | |
39 | - | |
40 | - int Subtitle::getID() { | |
41 | - return id; | |
42 | - } | |
43 | - | |
44 | - void Subtitle::setSubtitleText(std::string _subtext) { | |
45 | - subtitle_text = _subtext; | |
46 | - } | |
47 | - | |
48 | - void Subtitle::setTimeIn(int64_t _timein) { | |
49 | - time_in = _timein; | |
50 | - } | |
51 | - | |
52 | - void Subtitle::setTimeOut(int64_t _timeout) { | |
53 | - time_out = _timeout; | |
54 | - } | |
55 | - | |
56 | - std::string Subtitle::getSubtitleText() { | |
57 | - return subtitle_text; | |
58 | - } | |
59 | - | |
60 | - int64_t Subtitle::getTimeIn() { | |
61 | - return time_in; | |
62 | - } | |
63 | - | |
64 | - int64_t Subtitle::getTimeOut() { | |
65 | - return time_out; | |
66 | - } | |
67 | - | |
68 | - void Subtitle::setStatusOfReady(bool status) { | |
69 | - ready = status; | |
70 | - } | |
71 | - | |
72 | - bool Subtitle::isReady() { | |
73 | - return ready; | |
74 | - } | |
75 | - | |
76 | - std::string Subtitle::toString() { | |
77 | - | |
78 | - std::string subtitle_str; | |
79 | - char buffer [MAX_FIELD]; | |
80 | - sprintf(buffer, "%d", id); | |
81 | - subtitle_str.append("\n{id: ").append((std::string)buffer); | |
82 | - sprintf(buffer, "%ld", time_in); | |
83 | - subtitle_str.append(", time_in: ").append((std::string)buffer); | |
84 | - sprintf(buffer, "%ld", time_out); | |
85 | - subtitle_str.append(", time_out: ").append((std::string)buffer); | |
86 | - subtitle_str.append(", text: ").append(subtitle_text).append("}\n"); | |
87 | - | |
88 | - return subtitle_str; | |
89 | - | |
90 | - } | |
91 | - | |
92 | - } | |
93 | 0 | \ No newline at end of file |
extratorTXT/src/extratorTXT.cpp
... | ... | @@ -1,93 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | -#include "extratorTXT.h" | |
13 | - | |
14 | -ExtratorTXT::ExtratorTXT(){ | |
15 | - listeners = new list<ListenerTXT*>(); | |
16 | - finish = false; | |
17 | - DPRINTF("Done!\n"); | |
18 | -} | |
19 | - | |
20 | -ExtratorTXT::~ExtratorTXT(){ | |
21 | - listeners->clear(); | |
22 | - delete listeners; | |
23 | - delete file; | |
24 | - delete file_io; | |
25 | - delete bff_reader; | |
26 | - DDDPRINTF("Extractor TXT finalized!\n"); | |
27 | -} | |
28 | - | |
29 | -void ExtratorTXT::initialize(){ | |
30 | - file = new lavidlib::File(filepath); | |
31 | - try{ | |
32 | - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
33 | - bff_reader = new BufferedReader(file_io); | |
34 | - }catch(Exception &ex){ | |
35 | - finish = true; | |
36 | - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Arquivo de texto não encontrado."); | |
37 | - throw ExtratorTxtException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); | |
38 | - } | |
39 | - this->Start(); | |
40 | -} | |
41 | - | |
42 | -void ExtratorTXT::addListener(ListenerTXT* listener){ | |
43 | - listeners->push_back(listener); | |
44 | -} | |
45 | - | |
46 | -void ExtratorTXT::notifyListeners(unsigned char* line) { | |
47 | - for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
48 | - (*it)->notifyLine(line); | |
49 | - } | |
50 | -} | |
51 | - | |
52 | -void ExtratorTXT::notifyEndExtraction(int line_size) { | |
53 | - DDPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", line_size); | |
54 | - for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ | |
55 | - (*it)->notifyEnd(line_size); | |
56 | - } | |
57 | -} | |
58 | - | |
59 | -void ExtratorTXT::setFilePath(char* path){ | |
60 | - filepath = (char*) path; | |
61 | -} | |
62 | - | |
63 | -bool ExtratorTXT::isFinished(){ | |
64 | - return finish; | |
65 | -} | |
66 | - | |
67 | -void ExtratorTXT::Run(){ | |
68 | - | |
69 | - DDPRINTF("[AGUARDE] Extraindo Texto...\n") | |
70 | - | |
71 | - int line_index = 0; | |
72 | - bool hasNext = true; | |
73 | - string line; | |
74 | - | |
75 | - while (hasNext) { | |
76 | - try{ | |
77 | - line = bff_reader->readLine(); | |
78 | - if (line.length() > 0){ | |
79 | - notifyListeners((unsigned char*) line.c_str()); | |
80 | - cout << " . "; | |
81 | - line_index++; | |
82 | - } | |
83 | - }catch (EOFException &ex){ | |
84 | - hasNext = false; | |
85 | - }catch (...){ | |
86 | - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Erro durante a leitura do arquivo de texto."); | |
87 | - throw ExtratorTxtException("Falha desconhecida na leitura do arquivo. Tente novamente."); | |
88 | - } | |
89 | - } | |
90 | - printf("\n"); | |
91 | - finish = true; | |
92 | - notifyEndExtraction(line_index); | |
93 | -} |
extratorTXT/src/extratorTXT_exception.cpp
... | ... | @@ -1,22 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | - | |
13 | - | |
14 | - #include "extratorTXT_exception.h" | |
15 | - | |
16 | - ExtratorTxtException::ExtratorTxtException(const std::string message) | |
17 | - : RuntimeException(message) | |
18 | - { /* TODO */ } | |
19 | - ExtratorTxtException::ExtratorTxtException(const char* message) | |
20 | - : RuntimeException(message) | |
21 | - { /* TODO */ } | |
22 | - | |
23 | 0 | \ No newline at end of file |
extratorTXT/src/include/extratorTXT.h
... | ... | @@ -1,55 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | -#ifndef EXTRATORTXT_H | |
13 | -#define EXTRATORTXT_H | |
14 | - | |
15 | -#include "listenerTXT.h" | |
16 | -#include "jthread.h" | |
17 | -#include "dprintf.h" | |
18 | -#include "logger.h" | |
19 | -#include "extratorTXT_exception.h" | |
20 | -#include <list> | |
21 | -#include <lavidlib/io/File.h> | |
22 | -#include <lavidlib/io/FileIO.h> | |
23 | -#include <lavidlib/io/BufferedReader.h> | |
24 | -#include <lavidlib/io/IOException.h> | |
25 | - | |
26 | -using namespace jthread; | |
27 | -using namespace std; | |
28 | - | |
29 | -class ExtratorTXT: public Thread { | |
30 | - | |
31 | -public: | |
32 | - | |
33 | - ExtratorTXT(); | |
34 | - ~ExtratorTXT(); | |
35 | - | |
36 | - void addListener(ListenerTXT* listener); | |
37 | - void notifyListeners(unsigned char* line); | |
38 | - void notifyEndExtraction(int line_size); | |
39 | - | |
40 | - void setFilePath(char* path); | |
41 | - bool isFinished(); | |
42 | - void initialize(); | |
43 | - void Run(); | |
44 | - | |
45 | -private: | |
46 | - list<ListenerTXT*> *listeners; | |
47 | - char* filepath; | |
48 | - bool finish; | |
49 | - File *file; | |
50 | - FileIO *file_io; | |
51 | - BufferedReader *bff_reader; | |
52 | -}; | |
53 | - | |
54 | -#endif /* EXTRATORTXT_H */ | |
55 | - |
extratorTXT/src/include/extratorTXT_exception.h
... | ... | @@ -1,27 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | - #ifndef EXTRATORTXTEXCEPTION_H | |
13 | - #define EXTRATORTXTEXCEPTION_H | |
14 | - | |
15 | - #include <lavidlib/base/RuntimeException.h> | |
16 | - | |
17 | - using namespace lavidlib; | |
18 | - | |
19 | - | |
20 | - class ExtratorTxtException : public RuntimeException { | |
21 | - public: | |
22 | - ExtratorTxtException(const std::string message); | |
23 | - ExtratorTxtException(const char* message); | |
24 | - }; | |
25 | - | |
26 | - | |
27 | - #endif /* EXTRATORTXTEXCEPTION_H */ | |
28 | 0 | \ No newline at end of file |
extratorTXT/src/include/listenerTXT.h
... | ... | @@ -1,25 +0,0 @@ |
1 | -/*************************************************************************** | |
2 | - * Universidade Federal da Paraíba * | |
3 | - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * | |
4 | - * * | |
5 | - * Centro de Informática - UFPB - Campus I * | |
6 | - * João Pessoa - PB - Brasil * | |
7 | - * * | |
8 | - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * | |
9 | - * * | |
10 | - **************************************************************************/ | |
11 | - | |
12 | -#ifndef LISTENERTXT_H | |
13 | -#define LISTENERTXT_H | |
14 | - | |
15 | -#include <stdint.h> | |
16 | - | |
17 | -class ListenerTXT { | |
18 | - | |
19 | -public: | |
20 | - virtual void notifyLine(unsigned char* line) = 0; | |
21 | - virtual void notifyEnd(int line_size) = 0; | |
22 | -}; | |
23 | - | |
24 | -#endif /* LISTENERTXT_H */ | |
25 | - |
servico/src/include/serviceWindowGenerationFromSRT.h
... | ... | @@ -4,12 +4,14 @@ |
4 | 4 | #include "serviceWindowGeneration.h" |
5 | 5 | #include <pthread.h> |
6 | 6 | #include "inputFile.h" |
7 | -#include "extratorSRT.h" | |
7 | +#include "extratorFactory.h" | |
8 | 8 | #include "listenerSRT.h" |
9 | 9 | #include "stdint.h" |
10 | 10 | #include <vector> |
11 | 11 | #include "jthread.h" |
12 | 12 | |
13 | +#define SRT 1 | |
14 | + | |
13 | 15 | using namespace std; |
14 | 16 | using namespace jthread; |
15 | 17 | using namespace Util; |
... | ... | @@ -18,6 +20,7 @@ class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public Li |
18 | 20 | |
19 | 21 | private: |
20 | 22 | pthread_mutex_t *mutex_serviceSRT; |
23 | + ExtratorFactory *extrator_factory; | |
21 | 24 | ExtratorSRT * extratorSRT; |
22 | 25 | char* path_srt; |
23 | 26 | bool finish; | ... | ... |
servico/src/include/serviceWindowGenerationFromText.h
... | ... | @@ -2,16 +2,17 @@ |
2 | 2 | #define _SERVICEWINDOWGENERATIONFROMTEXT_H |
3 | 3 | |
4 | 4 | #include "serviceWindowGeneration.h" |
5 | -#include "extratorTXT.h" | |
5 | +#include "extratorFactory.h" | |
6 | 6 | #include "listenerTXT.h" |
7 | 7 | |
8 | - | |
8 | +#define TXT 2 | |
9 | 9 | /*FIXME: está restrito a 2K bytes de texto */ |
10 | 10 | #define MAX_TEXT_SIZE 2048 |
11 | 11 | |
12 | 12 | class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public Thread { |
13 | 13 | |
14 | 14 | private: |
15 | + ExtratorFactory *extrator_factory; | |
15 | 16 | ExtratorTXT * extratorTXT; |
16 | 17 | bool finish; |
17 | 18 | ... | ... |
servico/src/serviceWindowGenerationFromSRT.cpp
... | ... | @@ -4,7 +4,8 @@ |
4 | 4 | //Construtor Service 2 |
5 | 5 | ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( |
6 | 6 | char* path_video, char* path_srt, int sublanguage, int position, int size, int transparency, char* id, int serviceType) { |
7 | - setPathInput(path_video); | |
7 | + extrator_factory = new ExtratorFactory(); | |
8 | + setPathInput(path_video); | |
8 | 9 | setPathSRT(path_srt); |
9 | 10 | setPosition(position); |
10 | 11 | setSize(size); |
... | ... | @@ -18,7 +19,8 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT( |
18 | 19 | |
19 | 20 | //Construtor Service 5 |
20 | 21 | ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* path_srt, int transparency, char* id, int serviceType){ |
21 | - setPathInput(path_srt); | |
22 | + extrator_factory = new ExtratorFactory(); | |
23 | + setPathInput(path_srt); | |
22 | 24 | setTransparency(transparency); |
23 | 25 | setServiceType(serviceType); |
24 | 26 | setUserId(id); |
... | ... | @@ -67,7 +69,7 @@ void ServiceWindowGenerationFromSRT::initialize() { |
67 | 69 | |
68 | 70 | if(serviceType == 2){ |
69 | 71 | |
70 | - extratorSRT = new ExtratorSRT(); | |
72 | + extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); | |
71 | 73 | extratorSRT->addListener(this); |
72 | 74 | extratorSRT->setFilePath((char*) path_srt); |
73 | 75 | |
... | ... | @@ -75,18 +77,16 @@ void ServiceWindowGenerationFromSRT::initialize() { |
75 | 77 | |
76 | 78 | try{ |
77 | 79 | extratorSRT->initialize(); |
78 | - }catch(ExtratorSrtException ex){ | |
80 | + }catch(ExtratorException ex){ | |
79 | 81 | throw ServiceException(ex.getMessage()); |
80 | - }catch(InputException ex){ | |
81 | - throw ServiceException(ex.getMessage()); | |
82 | - } | |
82 | + } | |
83 | 83 | this->Start(); |
84 | 84 | |
85 | 85 | } else{ |
86 | 86 | /*Este serviço utiliza apenas o arquivo de legendas (SRT) como entrada, |
87 | 87 | portanto, não é preciso monitorar as informações do PCR a partir do |
88 | 88 | objeto InputFile().*/ |
89 | - extratorSRT = new ExtratorSRT(); | |
89 | + extratorSRT = (ExtratorSRT*)extrator_factory->getExtrator(SRT); | |
90 | 90 | extratorSRT->addListener(this); |
91 | 91 | extratorSRT->setFilePath((char*) path_input); |
92 | 92 | |
... | ... | @@ -94,7 +94,7 @@ void ServiceWindowGenerationFromSRT::initialize() { |
94 | 94 | |
95 | 95 | try{ |
96 | 96 | extratorSRT->initialize(); |
97 | - }catch(ExtratorSrtException ex){ | |
97 | + }catch(ExtratorException ex){ | |
98 | 98 | throw ServiceException(ex.getMessage()); |
99 | 99 | } |
100 | 100 | this->Start(); | ... | ... |
servico/src/serviceWindowGenerationFromText.cpp
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | ServiceWindowGenerationFromText::ServiceWindowGenerationFromText ( |
4 | 4 | char* path_file, char* username, int transp, int serviceType, char* client_type) { |
5 | 5 | |
6 | + extrator_factory = new ExtratorFactory(); | |
6 | 7 | setPathInput(path_file); |
7 | 8 | setClientType(client_type); |
8 | 9 | setUserId(username); |
... | ... | @@ -33,7 +34,7 @@ bool ServiceWindowGenerationFromText::isFinished() { |
33 | 34 | void ServiceWindowGenerationFromText::initialize() { |
34 | 35 | DDPRINTF("Service Text Initialize.\n"); |
35 | 36 | |
36 | - extratorTXT = new ExtratorTXT(); | |
37 | + extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(TXT); | |
37 | 38 | extratorTXT->addListener(this); |
38 | 39 | extratorTXT->setFilePath(getPathInput()); |
39 | 40 | |
... | ... | @@ -41,7 +42,7 @@ void ServiceWindowGenerationFromText::initialize() { |
41 | 42 | |
42 | 43 | try{ |
43 | 44 | extratorTXT->initialize(); |
44 | - }catch(ExtratorTxtException ex){ | |
45 | + }catch(ExtratorException ex){ | |
45 | 46 | throw ServiceException(ex.getMessage()); |
46 | 47 | } |
47 | 48 | this->Start(); | ... | ... |