MythTV  master
subtitlereader.cpp
Go to the documentation of this file.
1 #include "mythlogging.h"
2 #include "subtitlereader.h"
3 
5 {
9 }
10 
12 {
13  m_avSubtitlesEnabled = enable;
14 }
15 
17 {
18  m_textSubtitlesEnabled = enable;
19 }
20 
22 {
24 }
25 
26 bool SubtitleReader::AddAVSubtitle(AVSubtitle &subtitle,
27  bool fix_position,
28  bool allow_forced)
29 {
30  bool enableforced = false;
31  if (!m_avSubtitlesEnabled && !subtitle.forced)
32  {
33  FreeAVSubtitle(subtitle);
34  return enableforced;
35  }
36 
37  if (!m_avSubtitlesEnabled && subtitle.forced)
38  {
39  if (!allow_forced)
40  {
41  LOG(VB_PLAYBACK, LOG_INFO,
42  "SubtitleReader: Ignoring forced AV subtitle.");
43  FreeAVSubtitle(subtitle);
44  return enableforced;
45  }
46  LOG(VB_PLAYBACK, LOG_INFO,
47  "SubtitleReader: Allowing forced AV subtitle.");
48  enableforced = true;
49  }
50 
51  bool clearsubs = false;
52  m_avSubtitles.m_lock.lock();
53  m_avSubtitles.m_fixPosition = fix_position;
54  m_avSubtitles.m_buffers.push_back(subtitle);
55  // in case forced subtitles aren't displayed, avoid leaking by
56  // manually clearing the subtitles
57  if (m_avSubtitles.m_buffers.size() > 40)
58  {
59  LOG(VB_GENERAL, LOG_ERR,
60  "SubtitleReader: >40 AVSubtitles queued - clearing.");
61  clearsubs = true;
62  }
63  m_avSubtitles.m_lock.unlock();
64 
65  if (clearsubs)
67 
68  return enableforced;
69 }
70 
72 {
73  m_avSubtitles.m_lock.lock();
74  while (!m_avSubtitles.m_buffers.empty())
75  {
77  m_avSubtitles.m_buffers.pop_front();
78  }
79  m_avSubtitles.m_lock.unlock();
80 }
81 
82 void SubtitleReader::FreeAVSubtitle(AVSubtitle &subtitle)
83 {
84  avsubtitle_free(&subtitle);
85 }
86 
87 void SubtitleReader::LoadExternalSubtitles(const QString &subtitleFileName,
88  bool isInProgress)
89 {
91  m_textSubtitles.SetInProgress(isInProgress);
92  TextSubtitleParser::LoadSubtitles(subtitleFileName, m_textSubtitles, false);
93 }
94 
96 {
97  return m_textSubtitles.GetSubtitleCount() >= 0;
98 }
99 
100 QStringList SubtitleReader::GetRawTextSubtitles(uint64_t &duration)
101 {
102  QMutexLocker lock(&m_rawTextSubtitles.m_lock);
103  if (m_rawTextSubtitles.m_buffers.empty())
104  return QStringList();
105 
106  duration = m_rawTextSubtitles.m_duration;
107  QStringList result = m_rawTextSubtitles.m_buffers;
109  return result;
110 }
111 
112 void SubtitleReader::AddRawTextSubtitle(const QStringList& list, uint64_t duration)
113 {
114  if (!m_rawTextSubtitlesEnabled || list.empty())
115  return;
116 
117  QMutexLocker lock(&m_rawTextSubtitles.m_lock);
120  m_rawTextSubtitles.m_duration = duration;
121 }
122 
124 {
125  QMutexLocker lock(&m_rawTextSubtitles.m_lock);
127 }
AVSubtitles m_avSubtitles
TextSubtitles m_textSubtitles
int GetSubtitleCount(void) const
void ClearRawTextSubtitles(void)
void EnableAVSubtitles(bool enable)
static void LoadSubtitles(const QString &fileName, TextSubtitles &target, bool inBackground)
bool AddAVSubtitle(AVSubtitle &subtitle, bool fix_position, bool allow_forced)
void EnableTextSubtitles(bool enable)
RawTextSubs m_rawTextSubtitles
QStringList GetRawTextSubtitles(uint64_t &duration)
QStringList m_buffers
bool HasTextSubtitles(void)
void LoadExternalSubtitles(const QString &subtitleFileName, bool isInProgress)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
MythDeque< AVSubtitle > m_buffers
uint64_t m_duration
static void FreeAVSubtitle(AVSubtitle &sub)
void ClearAVSubtitles(void)
bool m_fixPosition
bool m_textSubtitlesEnabled
void AddRawTextSubtitle(const QStringList &list, uint64_t duration)
bool m_avSubtitlesEnabled
void EnableRawTextSubtitles(bool enable)
bool m_rawTextSubtitlesEnabled
void SetInProgress(bool isInProgress)