Skip to content

Commit

Permalink
Remove code no longer used after text subtitle switch to AVSubtitles.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed May 14, 2023
1 parent ff68aee commit ed3baf3
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 222 deletions.
2 changes: 0 additions & 2 deletions mythtv/libs/libmythtv/captions/subtitlereader.cpp
Expand Up @@ -15,7 +15,6 @@ SubtitleReader::SubtitleReader(MythPlayer *parent)
SubtitleReader::~SubtitleReader()
{
ClearAVSubtitles(true);
m_textSubtitles.Clear();
ClearRawTextSubtitles();
}

Expand Down Expand Up @@ -113,7 +112,6 @@ void SubtitleReader::FreeAVSubtitle(AVSubtitle &subtitle)
void SubtitleReader::LoadExternalSubtitles(const QString &subtitleFileName,
bool isInProgress)
{
m_textSubtitles.Clear();
m_textSubtitles.SetInProgress(isInProgress);
if (!subtitleFileName.isEmpty())
{
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/captions/subtitlereader.h
Expand Up @@ -53,7 +53,6 @@ class SubtitleReader : public QObject
void ClearAVSubtitles(bool force = false);
static void FreeAVSubtitle(AVSubtitle &sub);

TextSubtitles* GetTextSubtitles(void) { return &m_textSubtitles; }
TextSubtitleParser* GetParser(void) { return m_externalParser; }
bool HasTextSubtitles(void);
void LoadExternalSubtitles(const QString &subtitleFileName, bool isInProgress);
Expand Down
80 changes: 1 addition & 79 deletions mythtv/libs/libmythtv/captions/subtitlescreen.cpp
Expand Up @@ -1756,9 +1756,7 @@ void SubtitleScreen::Pulse(void)

DisplayAVSubtitles(); // allow forced subtitles to work

if (kDisplayTextSubtitle == m_subtitleType)
DisplayTextSubtitles();
else if (kDisplayCC608 == m_subtitleType)
if (kDisplayCC608 == m_subtitleType)
DisplayCC608Subtitles();
else if (kDisplayCC708 == m_subtitleType)
DisplayCC708Subtitles();
Expand Down Expand Up @@ -2102,82 +2100,6 @@ int SubtitleScreen::DisplayScaledAVSubtitles(const AVSubtitleRect *rect,
return (ysplit + 1);
}

void SubtitleScreen::DisplayTextSubtitles(void)
{
if (!m_player || !m_subreader)
return;

bool changed = (m_textFontZoom != m_textFontZoomPrev);
changed |= (m_textFontDelayMs != m_textFontDelayMsPrev);
changed |= (m_textFontMinDurationMsPrev != m_textFontMinDurationMs);
changed |= (m_textFontDurationExtensionMsPrev != m_textFontDurationExtensionMs);
MythVideoOutput *vo = m_player->GetVideoOutput();
if (!vo)
return;
m_safeArea = vo->GetSafeRect();

MythVideoFrame *currentFrame = vo->GetLastShownFrame();
if (!currentFrame)
return;

TextSubtitles *subs = m_subreader->GetTextSubtitles();
subs->Lock();
uint64_t playPos = 0;
int playPosAdj = m_textFontDelayMs.count();
if (subs->IsFrameBasedTiming())
{
// frame based subtitles get out of synch after running mythcommflag
// for the file, i.e., the following number is wrong and does not
// match the subtitle frame numbers:
playPos = currentFrame->m_frameNumber;
playPosAdj /= m_player->GetFrameRate();
}
else
{
// Use timecodes for time based SRT subtitles. Feeding this into
// NormalizeVideoTimecode() should adjust for non-zero start times
// and wraps. For MPEG, wraps will occur just once every 26.5 hours
// and other formats less frequently so this should be sufficient.
// Note: timecodes should now always be valid even in the case
// when a frame doesn't have a valid timestamp. If an exception is
// found where this is not true then we need to use the frameNumber
// when timecode is not defined by uncommenting the following lines.
//if (currentFrame->timecode == 0)
// playPos = (uint64_t)
// ((currentFrame->frameNumber / video_frame_rate) * 1000);
//else
auto tc_ms = currentFrame->m_timecode;
playPos = m_player->GetDecoder()->NormalizeVideoTimecode(tc_ms).count();
}
playPos -= playPosAdj;
if (playPos != 0)
changed |= subs->HasSubtitleChanged(playPos);
if (!changed)
{
subs->Unlock();
return;
}

SetElementDeleted();
DeleteAllChildren();

if (playPos == 0)
{
subs->Unlock();
return;
}

QStringList rawsubs = subs->GetSubtitles(m_subreader->GetParser(), playPos);
if (rawsubs.empty())
{
subs->Unlock();
return;
}

subs->Unlock();
DrawTextSubtitles(rawsubs, 0ms, 0ms);
}

void SubtitleScreen::DisplayRawTextSubtitles(void)
{
if (!m_player || !m_subreader)
Expand Down
112 changes: 0 additions & 112 deletions mythtv/libs/libmythtv/captions/textsubtitleparser.cpp
Expand Up @@ -147,123 +147,11 @@ class RemoteFileWrapper
QFile *m_localFile;
};

static bool operator<(const text_subtitle_t& left,
const text_subtitle_t& right)
{
return left.m_start < right.m_start;
}

TextSubtitles::~TextSubtitles()
{
SubtitleLoadHelper::Wait(this);
}

/** \fn TextSubtitles::HasSubtitleChanged(uint64_t timecode) const
* \brief Returns true in case the subtitle to display has changed
* since the last GetSubtitles() call.
*
* This is used to avoid redisplaying subtitles that are already displaying.
*
* \param timecode The timecode (frame number or time stamp)
* of the current video position.
* \return True in case new subtitles should be displayed.
*/
bool TextSubtitles::HasSubtitleChanged(uint64_t timecode) const
{
return (timecode < m_lastReturnedSubtitle.m_start ||
timecode > m_lastReturnedSubtitle.m_end);
}

/** \fn TextSubtitles::GetSubtitles(uint64_t timecode) const
* \brief Returns the subtitles to display at the given timecode.
*
* \param timecode The timecode (frame number or time stamp) of the
* current video position.
* \return The subtitles as a list of strings.
*/
QStringList TextSubtitles::GetSubtitles(TextSubtitleParser *parser, uint64_t timecode)
{
if (!m_isInProgress && m_subtitles.empty())
return {};

text_subtitle_t searchTarget(timecode, timecode);

auto nextSubPos =
std::lower_bound(m_subtitles.begin(), m_subtitles.end(), searchTarget);

uint64_t startCode = 0;
uint64_t endCode = 0;
if (nextSubPos != m_subtitles.begin())
{
auto currentSubPos = nextSubPos;
--currentSubPos;

const text_subtitle_t &sub = *currentSubPos;
if (sub.m_start <= timecode && sub.m_end >= timecode)
{
// found a sub to display
m_lastReturnedSubtitle = sub;
return m_lastReturnedSubtitle.m_textLines;
}

// the subtitle time span has ended, let's display a blank sub
startCode = sub.m_end + 1;
}

if (nextSubPos == m_subtitles.end())
{
if (m_isInProgress)
{
const int maxReloadInterval = 1000; // ms
if (IsFrameBasedTiming())
{
// Assume conservative 24fps
endCode = startCode + maxReloadInterval / 24;
}
else
{
endCode = startCode + maxReloadInterval;
}
QDateTime now = QDateTime::currentDateTimeUtc();
if (!m_fileName.isEmpty() &&
m_lastLoaded.msecsTo(now) >= maxReloadInterval)
{
parser->LoadSubtitles(true);
}
}
else
{
// at the end of video, the blank subtitle should last
// until forever
endCode = startCode + INT_MAX;
}
}
else
{
endCode = (*nextSubPos).m_start - 1;
}

// we are in a position in which there are no subtitles to display,
// return an empty subtitle and create a dummy empty subtitle for this
// time span so SubtitleChanged() functions also in this case
text_subtitle_t blankSub(startCode, endCode);
m_lastReturnedSubtitle = blankSub;

return {};
}

void TextSubtitles::AddSubtitle(const text_subtitle_t &newSub)
{
QMutexLocker locker(&m_lock);
m_subtitles.push_back(newSub);
}

void TextSubtitles::Clear(void)
{
QMutexLocker locker(&m_lock);
m_subtitles.clear();
}

void TextSubtitles::SetLastLoaded(void)
{
emit TextSubtitlesUpdated();
Expand Down
28 changes: 0 additions & 28 deletions mythtv/libs/libmythtv/captions/textsubtitleparser.h
Expand Up @@ -47,39 +47,13 @@ class TextSubtitles : public QObject
void TextSubtitlesUpdated();

public:
TextSubtitles()
{
m_lastReturnedSubtitle.m_start = 0;
m_lastReturnedSubtitle.m_end = 0;
}

~TextSubtitles() override;

bool HasSubtitleChanged(uint64_t timecode) const;
QStringList GetSubtitles(TextSubtitleParser *parser, uint64_t timecode);

/** \fn TextSubtitles::IsFrameBasedTiming(void) const
* \brief Returns true in case the subtitle timing data is frame-based.
*
* If the timing is frame-based, the client should use frame counts as
* timecodes for the HasSubtitleChanged() and GetSubtitles() methods,
* otherwise the timecode is milliseconds from the video start.
*/
bool IsFrameBasedTiming(void) const
{ return m_frameBasedTiming; }

void SetFrameBasedTiming(bool frameBasedTiming) {
QMutexLocker locker(&m_lock);
m_frameBasedTiming = frameBasedTiming;
}

void SetFilename(const QString &fileName) {
QMutexLocker locker(&m_lock);
m_fileName = fileName;
}

void AddSubtitle(const text_subtitle_t& newSub);
void Clear(void);
void SetLastLoaded(void);
void SetByteCount(off_t count) {
QMutexLocker locker(&m_lock);
Expand All @@ -101,8 +75,6 @@ class TextSubtitles : public QObject

private:
TextSubtitleList m_subtitles;
mutable text_subtitle_t m_lastReturnedSubtitle;
bool m_frameBasedTiming {false};
QString m_fileName;
QDateTime m_lastLoaded;
off_t m_byteCount {0};
Expand Down

0 comments on commit ed3baf3

Please sign in to comment.