extratorSRT.h 2.7 KB
/**
 * \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 */