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(const 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(const AVSubtitle &subtitle)
83 {
84  avsubtitle_free(const_cast<AVSubtitle*>(&subtitle));
85 }
86 
87 void SubtitleReader::LoadExternalSubtitles(const QString &subtitleFileName,
88  bool isInProgress)
89 {
91  m_TextSubtitles.SetInProgress(isInProgress);
93  false);
94 }
95 
97 {
98  return m_TextSubtitles.GetSubtitleCount() >= 0;
99 }
100 
101 QStringList SubtitleReader::GetRawTextSubtitles(uint64_t &duration)
102 {
103  QMutexLocker lock(&m_RawTextSubtitles.m_lock);
104  if (m_RawTextSubtitles.m_buffers.empty())
105  return QStringList();
106 
107  duration = m_RawTextSubtitles.m_duration;
108  QStringList result = m_RawTextSubtitles.m_buffers;
110  return result;
111 }
112 
113 void SubtitleReader::AddRawTextSubtitle(const QStringList& list, uint64_t duration)
114 {
115  if (!m_RawTextSubtitlesEnabled || list.empty())
116  return;
117 
118  QMutexLocker lock(&m_RawTextSubtitles.m_lock);
121  m_RawTextSubtitles.m_duration = duration;
122 }
123 
125 {
126  QMutexLocker lock(&m_RawTextSubtitles.m_lock);
128 }
AVSubtitles m_AVSubtitles
bool AddAVSubtitle(const AVSubtitle &subtitle, bool fix_position, bool allow_forced)
int GetSubtitleCount(void) const
bool m_RawTextSubtitlesEnabled
void ClearRawTextSubtitles(void)
void EnableAVSubtitles(bool enable)
static void LoadSubtitles(const QString &fileName, TextSubtitles &target, bool inBackground)
void EnableTextSubtitles(bool enable)
RawTextSubs m_RawTextSubtitles
QStringList GetRawTextSubtitles(uint64_t &duration)
bool m_TextSubtitlesEnabled
QStringList m_buffers
bool m_AVSubtitlesEnabled
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
void ClearAVSubtitles(void)
bool m_fixPosition
TextSubtitles m_TextSubtitles
void AddRawTextSubtitle(const QStringList &list, uint64_t duration)
void EnableRawTextSubtitles(bool enable)
void FreeAVSubtitle(const AVSubtitle &sub)
void SetInProgress(bool isInProgress)