aboutsummaryrefslogtreecommitdiff
path: root/Src/nsv/nsvplay/subtitles.h
blob: f4951a2383c4d6d0c2223c00ef93eb8f55e323db (plain) (blame)
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
#ifndef NSVPLAY_SUBTITLES_H
#define NSVPLAY_SUBTITLES_H

#include "main.h"
#include "../nsvbs.h"

class SubsItem {
public:
  SubsItem(unsigned int ptimestart, unsigned int ptimeend, const char *ptext) :
      timestart(ptimestart) , timeend(ptimeend) { 
        text=_strdup(ptext);
        xPos=128;
        yPos=255;
        colorRed=colorGreen=colorBlue=0xff;
        extraDataSize=0;
        extraData=0;
        muxed_subtitle=0;
        fontSize=origFontSize=0;
      }
  ~SubsItem() { 
    free((void*)text); 
    if(extraDataSize) free((void *)extraData);
  }

  unsigned int timestart;
  unsigned int timeend; 
  const char *text;

  unsigned char xPos, yPos;
  unsigned char colorRed, colorGreen, colorBlue;
  int extraDataSize;
  const void *extraData;

  int muxed_subtitle; //so we free it when we seek/display

  int fontSize;

  int origFontSize;
};

class Subtitles {
public:
  Subtitles(const char *filename);

  SubsItem *getSubtitle(unsigned int time, unsigned int frame); // time in ms
  void addSubtitlePacket(SUBTITLE_INFO *sti);

  void setFontSizeModifier(int size) { m_font_size_mod=size; }
  
private:
  void decodeSrtFile(char *text);
  unsigned int getTimeFromSrtText(const char *text);

  void decodeSubFile(char *text);

  ClassList<SubsItem> m_subs;
  int m_frame_based;
  int m_last_sub;
  int m_font_size_mod;
};

#endif