MythTV  master
subtitlereader.cpp
Go to the documentation of this file.
1 #include "mythlogging.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  if (!subtitleFileName.isEmpty())
93  TextSubtitleParser::LoadSubtitles(subtitleFileName, m_textSubtitles, 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 }
TextSubtitles::SetInProgress
void SetInProgress(bool isInProgress)
Definition: textsubtitleparser.h:77
SubtitleReader::GetRawTextSubtitles
QStringList GetRawTextSubtitles(uint64_t &duration)
Definition: subtitlereader.cpp:101
SubtitleReader::m_textSubtitles
TextSubtitles m_textSubtitles
Definition: subtitlereader.h:59
SubtitleReader::AddAVSubtitle
bool AddAVSubtitle(AVSubtitle &subtitle, bool fix_position, bool allow_forced)
Definition: subtitlereader.cpp:26
TextSubtitles::Clear
void Clear(void)
Definition: textsubtitleparser.cpp:258
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
subtitlereader.h
SubtitleReader::~SubtitleReader
~SubtitleReader()
Definition: subtitlereader.cpp:4
SubtitleReader::EnableAVSubtitles
void EnableAVSubtitles(bool enable)
Definition: subtitlereader.cpp:11
SubtitleReader::ClearAVSubtitles
void ClearAVSubtitles(void)
Definition: subtitlereader.cpp:71
mythlogging.h
SubtitleReader::LoadExternalSubtitles
void LoadExternalSubtitles(const QString &subtitleFileName, bool isInProgress)
Definition: subtitlereader.cpp:87
SubtitleReader::EnableTextSubtitles
void EnableTextSubtitles(bool enable)
Definition: subtitlereader.cpp:16
SubtitleReader::ClearRawTextSubtitles
void ClearRawTextSubtitles(void)
Definition: subtitlereader.cpp:124
SubtitleReader::FreeAVSubtitle
static void FreeAVSubtitle(AVSubtitle &sub)
Definition: subtitlereader.cpp:82
RawTextSubs::m_lock
QMutex m_lock
Definition: subtitlereader.h:29
SubtitleReader::m_rawTextSubtitles
RawTextSubs m_rawTextSubtitles
Definition: subtitlereader.h:61
SubtitleReader::EnableRawTextSubtitles
void EnableRawTextSubtitles(bool enable)
Definition: subtitlereader.cpp:21
SubtitleReader::AddRawTextSubtitle
void AddRawTextSubtitle(const QStringList &list, uint64_t duration)
Definition: subtitlereader.cpp:113
TextSubtitles::GetSubtitleCount
int GetSubtitleCount(void) const
Definition: textsubtitleparser.h:84
SubtitleReader::m_rawTextSubtitlesEnabled
bool m_rawTextSubtitlesEnabled
Definition: subtitlereader.h:62
SubtitleReader::m_avSubtitlesEnabled
bool m_avSubtitlesEnabled
Definition: subtitlereader.h:58
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:60
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:96
SubtitleReader::m_avSubtitles
AVSubtitles m_avSubtitles
Definition: subtitlereader.h:57
TextSubtitleParser::LoadSubtitles
static void LoadSubtitles(const QString &fileName, TextSubtitles &target, bool inBackground)
Definition: textsubtitleparser.cpp:270