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;
24  text_subtitle_t(const text_subtitle_t&) = default;
25  text_subtitle_t& operator= (const text_subtitle_t&) = default;
26 
27  public:
28  uint64_t m_start {0};
29  uint64_t m_end {0};
30  QStringList m_textLines;
31 };
32 
33 using TextSubtitleList = vector<text_subtitle_t>;
34 
36 {
37  public:
39  {
40  m_lastReturnedSubtitle.m_start = 0;
41  m_lastReturnedSubtitle.m_end = 0;
42  }
43 
44  virtual ~TextSubtitles();
45 
46  bool HasSubtitleChanged(uint64_t timecode) const;
47  QStringList GetSubtitles(uint64_t timecode);
48 
56  bool IsFrameBasedTiming(void) const
57  { return m_frameBasedTiming; }
58 
59  void SetFrameBasedTiming(bool frameBasedTiming) {
60  QMutexLocker locker(&m_lock);
61  m_frameBasedTiming = frameBasedTiming;
62  }
63 
64  void SetFilename(const QString &fileName) {
65  QMutexLocker locker(&m_lock);
66  m_fileName = fileName;
67  }
68 
69  void AddSubtitle(const text_subtitle_t& newSub);
70  void Clear(void);
71  void SetLastLoaded(void);
72  void SetByteCount(off_t count) {
73  QMutexLocker locker(&m_lock);
74  m_byteCount = count;
75  }
76  off_t GetByteCount(void) const { return m_byteCount; }
77  void SetInProgress(bool isInProgress) {
78  QMutexLocker locker(&m_lock);
79  m_isInProgress = isInProgress;
80  }
81  void SetHasSubtitles(bool hasSubs) { m_hasSubtitles = hasSubs; }
82 
83  // Returns -1 if there is no subtitle file.
84  int GetSubtitleCount(void) const
85  { return m_hasSubtitles ? m_subtitles.size() : -1; }
86 
87  void Lock(void) { m_lock.lock(); }
88  void Unlock(void) { m_lock.unlock(); }
89 
90  private:
93  bool m_frameBasedTiming {false};
94  QString m_fileName;
95  QDateTime m_lastLoaded;
96  off_t m_byteCount {0};
97  // Note: m_isInProgress is overly conservative because it doesn't
98  // change from true to false after a recording completes.
99  bool m_isInProgress {false};
100  // It's possible to have zero subtitles at the start of playback
101  // because none have yet been written for an in-progress
102  // recording, so use m_hasSubtitles instead of m_subtitles.size().
103  bool m_hasSubtitles {false};
104  QMutex m_lock {QMutex::Recursive};
105 };
106 
108 {
109  public:
110  static void LoadSubtitles(const QString &fileName, TextSubtitles &target,
111  bool inBackground);
112 };
113 
114 #endif
text_subtitle_t::text_subtitle_t
text_subtitle_t(const text_subtitle_t &)=default
TextSubtitleParser
Definition: textsubtitleparser.h:108
TextSubtitles::Unlock
void Unlock(void)
Definition: textsubtitleparser.h:88
text_subtitle_t
Definition: textsubtitleparser.h:20
TextSubtitles::SetInProgress
void SetInProgress(bool isInProgress)
Definition: textsubtitleparser.h:77
TextSubtitles::m_lastLoaded
QDateTime m_lastLoaded
Definition: textsubtitleparser.h:95
text_subtitle_t::m_textLines
QStringList m_textLines
Definition: textsubtitleparser.h:30
text_subtitle_t::text_subtitle_t
text_subtitle_t(long start_, long end_)
Definition: textsubtitleparser.h:22
TextSubtitles::SetByteCount
void SetByteCount(off_t count)
Definition: textsubtitleparser.h:72
text_subtitle_t::text_subtitle_t
text_subtitle_t()=default
TextSubtitles::TextSubtitles
TextSubtitles()
Definition: textsubtitleparser.h:38
TextSubtitles
Definition: textsubtitleparser.h:36
TextSubtitleList
vector< text_subtitle_t > TextSubtitleList
Definition: textsubtitleparser.h:33
TextSubtitles::GetSubtitleCount
int GetSubtitleCount(void) const
Definition: textsubtitleparser.h:84
off_t
#define off_t
Definition: mythiowrapper.cpp:238
TextSubtitles::Lock
void Lock(void)
Definition: textsubtitleparser.h:87
TextSubtitles::SetHasSubtitles
void SetHasSubtitles(bool hasSubs)
Definition: textsubtitleparser.h:81
TextSubtitles::GetByteCount
off_t GetByteCount(void) const
Definition: textsubtitleparser.h:76
TextSubtitles::m_lastReturnedSubtitle
text_subtitle_t m_lastReturnedSubtitle
Definition: textsubtitleparser.h:92
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:49
TextSubtitles::m_fileName
QString m_fileName
Definition: textsubtitleparser.h:94
TextSubtitles::IsFrameBasedTiming
bool IsFrameBasedTiming(void) const
Returns true in case the subtitle timing data is frame-based.
Definition: textsubtitleparser.h:56
TextSubtitles::m_subtitles
TextSubtitleList m_subtitles
Definition: textsubtitleparser.h:91
TextSubtitles::SetFrameBasedTiming
void SetFrameBasedTiming(bool frameBasedTiming)
Definition: textsubtitleparser.h:59
TextSubtitles::SetFilename
void SetFilename(const QString &fileName)
Definition: textsubtitleparser.h:64