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