aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Borges de Freitas <92enen@gmail.com>2023-04-03 21:57:33 +0100
committerenen92 <92enen@gmail.com>2023-04-04 09:35:07 +0100
commitffad7a1c08dbb7de3114ac7e149ce440871ab33a (patch)
tree62f5f278c78c02695ca4b81a0852e1eacd087dc6
parentaf1c10ca441fb7fc9a85714b8c1ac01a099f5df1 (diff)
[subtitles] Fix mkv subtitles without duration
-rw-r--r--xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp27
-rw-r--r--xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.h2
2 files changed, 28 insertions, 1 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp
index db9379c2a7..0c4d81719f 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp
@@ -18,6 +18,15 @@
#include <memory>
+namespace
+{
+// Subtitle packets reaching the decoder may not have the stop PTS value,
+// the stop value can be taken from the start PTS of the next subtitle.
+// Otherwise we fallback to a default of 20 secs duration. This is only
+// applied if the subtitle packets have 0 duration (stop > start).
+constexpr double DEFAULT_DURATION = 20.0 * static_cast<double>(DVD_TIME_BASE);
+} // namespace
+
CDVDOverlayCodecText::CDVDOverlayCodecText() : CDVDOverlayCodec("Text Subtitle Decoder")
{
m_pOverlay = nullptr;
@@ -83,7 +92,23 @@ OverlayMessage CDVDOverlayCodecText::Decode(DemuxPacket* pPacket)
{
TagConv.ConvertLine(text);
TagConv.CloseTag(text);
- AddSubtitle(text, PTSStartTime, PTSStopTime);
+
+ // similar to CC text, if the subtitle duration is invalid (stop > start)
+ // we might want to assume the stop time will be set by the next received
+ // packet
+ if (PTSStopTime < PTSStartTime)
+ {
+ if (m_changePrevStopTime)
+ {
+ ChangeSubtitleStopTime(m_prevSubId, PTSStartTime);
+ m_changePrevStopTime = false;
+ }
+
+ PTSStopTime = PTSStartTime + DEFAULT_DURATION;
+ m_changePrevStopTime = true;
+ }
+
+ m_prevSubId = AddSubtitle(text, PTSStartTime, PTSStopTime);
}
else
CLog::Log(LOGERROR, "{} - Failed to initialize tag converter", __FUNCTION__);
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.h b/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.h
index 98db5cbc3c..5a5c3bfec6 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.h
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecText.h
@@ -37,5 +37,7 @@ private:
void Dispose() override;
CDVDOverlay* m_pOverlay;
CDVDStreamInfo m_hints;
+ int m_prevSubId{-1};
+ bool m_changePrevStopTime{false};
AVCodecID m_codecId{AV_CODEC_ID_NONE};
};