MythTV  master
textsubtitleparser.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
7 #ifndef TEXT_SUBTITLE_PARSER_H
8 #define TEXT_SUBTITLE_PARSER_H
9 
10 // C++ headers
11 #include <cstdint>
12 #include <vector>
13 using namespace std;
14 
15 // Qt headers
16 #include <QStringList>
17 #include <QDateTime>
18 
20 {
21  public:
22  text_subtitle_t(long start_, long end_) : m_start(start_), m_end(end_) {}
23  text_subtitle_t() = default;
25  m_start(other.m_start), m_end(other.m_end),
26  m_textLines(other.m_textLines) {}
27  text_subtitle_t& operator= (const text_subtitle_t &rhs)
28  {
29  m_start = rhs.m_start;
30  m_end = rhs.m_end;
31  m_textLines = rhs.m_textLines;
32  return *this;
33  }
34 
35  public:
36  uint64_t m_start {0};
37  uint64_t m_end {0};
38  QStringList m_textLines;
39 };
40 
41 typedef vector<text_subtitle_t> TextSubtitleList;
42 
44 {
45  public:
47  {
48  m_lastReturnedSubtitle.m_start = 0;
49  m_lastReturnedSubtitle.m_end = 0;
50  }
51 
52  virtual ~TextSubtitles();
53 
54  bool HasSubtitleChanged(uint64_t timecode) const;
55  QStringList GetSubtitles(uint64_t timecode);
56 
64  bool IsFrameBasedTiming(void) const
65  { return m_frameBasedTiming; }
66 
67  void SetFrameBasedTiming(bool frameBasedTiming) {
68  QMutexLocker locker(&m_lock);
69  m_frameBasedTiming = frameBasedTiming;
70  }
71 
72  void SetFilename(const QString &fileName) {
73  QMutexLocker locker(&m_lock);
74  m_fileName = fileName;
75  }
76 
77  void AddSubtitle(const text_subtitle_t& newSub);
78  void Clear(void);
79  void SetLastLoaded(void);
80  void SetByteCount(off_t count) {
81  QMutexLocker locker(&m_lock);
82  m_byteCount = count;
83  }
84  off_t GetByteCount(void) const { return m_byteCount; }
85  void SetInProgress(bool isInProgress) {
86  QMutexLocker locker(&m_lock);
87  m_isInProgress = isInProgress;
88  }
89  void SetHasSubtitles(bool hasSubs) { m_hasSubtitles = hasSubs; }
90 
91  // Returns -1 if there is no subtitle file.
92  int GetSubtitleCount(void) const
93  { return m_hasSubtitles ? m_subtitles.size() : -1; }
94 
95  void Lock(void) { m_lock.lock(); }
96  void Unlock(void) { m_lock.unlock(); }
97 
98  private:
101  bool m_frameBasedTiming {false};
102  QString m_fileName;
103  QDateTime m_lastLoaded;
104  off_t m_byteCount {0};
105  // Note: m_isInProgress is overly conservative because it doesn't
106  // change from true to false after a recording completes.
107  bool m_isInProgress {false};
108  // It's possible to have zero subtitles at the start of playback
109  // because none have yet been written for an in-progress
110  // recording, so use m_hasSubtitles instead of m_subtitles.size().
111  bool m_hasSubtitles {false};
112  QMutex m_lock {QMutex::Recursive};
113 };
114 
116 {
117  public:
118  static void LoadSubtitles(const QString &fileName, TextSubtitles &target,
119  bool inBackground);
120 };
121 
122 #endif
QStringList m_textLines
text_subtitle_t(long start_, long end_)
vector< text_subtitle_t > TextSubtitleList
text_subtitle_t m_lastReturnedSubtitle
int GetSubtitleCount(void) const
#define off_t
void SetFilename(const QString &fileName)
off_t GetByteCount(void) const
void SetByteCount(off_t count)
TextSubtitleList m_subtitles
void SetHasSubtitles(bool hasSubs)
text_subtitle_t(const text_subtitle_t &other)
uint64_t m_end
Ending time in msec or ending frame.
QDateTime m_lastLoaded
uint64_t m_start
Starting time in msec or starting frame.
bool IsFrameBasedTiming(void) const
Returns true in case the subtitle timing data is frame-based.
#define Clear(a)
void SetInProgress(bool isInProgress)
void SetFrameBasedTiming(bool frameBasedTiming)