extratorVTT.h 1.77 KB
/**
 * \file extratorVTT.h
 *
 * \author Wesnydy Ribeiro <wesnydy@lavid.ufpb.br>
 * \date 2015
 */

#ifndef EXTRATORVTT_H
#define EXTRATORVTT_H

#include <list>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "jthread.h"
#include "extrator.h"
#include "subtitle.h"
#include "listenerSub.h"
#include <iostream>

#define SIGNATURE "WEBVTT"
#define TARGET_TIME "-->"
#define LESS_THAN "<"
#define MORE_THAN ">"
#define SIZE_SCAPE 1

using namespace std;
using namespace sndesc;
using namespace jthread;

/** \brief Classe que implementa o extrator de legenda.
*
* Instâncias desta classe extraem o conteúdo de
* arquivos webVTT.
*
* \headerfile extrator/src/include/extratorVTT.h
*/
class ExtratorVTT: public Extrator, public Thread {

public:
	/** Construtor */
	ExtratorVTT();

	/** Destrutor */
	~ExtratorVTT();

	/** Define o path do arquivo de entrada.
	 *
	 * \param path O path do arquivo.
	 */
	void setFilePath(char* path);

	/** Adiciona ouvintes do extratorVTT.
	 *
	 * \param listener O ouvinte a ser registrado.
	 */
	void addListener(ListenerSub* listener);

	/** 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();

	/** Este método é chamado quando a Thread for iniciada. */
	void Run();

private:
	Subtitle* subtitle;
	list<ListenerSub*> *listeners;

	int64_t seekPos;
	bool hasNextCue;

	void notifyEndExtraction(int size);
	void notifyListeners(unsigned char* subtitle, uint64_t pts);

	Subtitle* nextCue();
	void encodingfiletoUTF8();
	string formatText(string line);
	int64_t str_to_time(string str_time);
};

#endif /* EXTRATORVTT_H */