Skip to content

Commit

Permalink
New option to manage 10sec subs latency workaround
Browse files Browse the repository at this point in the history
Revisit 10sec subs latency workaround: new option to enable it at 'start only' or 'start+resume'. Default is disabled.
    (Reason is fast multiple resumes and seek baack can sometimes generate restart or freeze due to large audio/video desynch)
  • Loading branch information
rockrider69 committed Jan 10, 2024
1 parent 457df25 commit 786f695
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
3 changes: 2 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<addon
id="service.languagepreferencemanager"
name="Language Preference Manager"
version="1.0.3BETA5"
version="1.0.3BETA6"
provider-name="ace20022/scott967/rockrider69"
>
<requires>
Expand Down Expand Up @@ -33,6 +33,7 @@
1.0.3BETA4: Fix random video/audio freeze at resume due to previous "Fix 10sec latency". Rewrite it and add debug messages.
1.0.3BETA5: Fix multiple 3 digit codes per language (ex. German ger,deu). Now OK also for Conditional Subtitles preferences.
Fix Serbian language codes, now 'srp,scc' according to last iso639-2/T
1.0.3BETA6: 10sec subs latency workaround: new option to disable it (default), or enable it at 'start only' or 'start+resume'.

</news>
<assets>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--- Version 1.0.3BETA6

- 10sec subs latency workaround: new option to enable it at 'start only' or 'start+resume'. Default is disabled.
(fast multiple resumes can sometimes generate restart or freeze due to audio/video desynch)

--- Version 1.0.3BETA5

- Fix multiple 3 digit codes per language (ex. German ger,deu). Now OK also for Conditional Subtitles preferences.
Expand Down
16 changes: 16 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ msgctxt "#30130"
msgid "Audio Keyword List:"
msgstr "
msgctxt "#30131"
msgid "Fast Subtitles Display:"
msgstr "
msgctxt "#30132"
msgid "Disabled"
msgstr "
msgctxt "#30133"
msgid "New Start only"
msgstr "
msgctxt "#30134"
msgid "Start & Resume"
msgstr "
msgctxt "#30201"
msgid "Albanian"
msgstr ""
Expand Down
8 changes: 6 additions & 2 deletions resources/lib/prefsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def readSettings(self):
'cond subs on: {3}\n' \
'turn subs on: {4}, turn subs off: {5}\n' \
'signs: {15}\n' \
'blacklisted keywords: {16}\n' \
'blacklisted keywords (subtitles): {16}\n' \
'blacklisted keywords (audio): {17}\n' \
'fast subtitles display (10sec latency workaround): {18}\n' \
'use file name: {6}, file name regex: {7}\n' \
'at least one pref on: {8}\n'\
'audio prefs: {9}\n' \
Expand All @@ -66,7 +68,8 @@ def readSettings(self):
self.AudioPrefs, self.SubtitlePrefs, self.CondSubtitlePrefs,
self.custom_audio, self.custom_subs, self.custom_condsub, self.ignore_signs_on,
','.join(self.subtitle_keyword_blacklist),
','.join(self.audio_keyword_blacklist)
','.join(self.audio_keyword_blacklist),
self.fast_subs_display
)
)

Expand All @@ -93,6 +96,7 @@ def readPrefs(self):
self.audio_keyword_blacklist = self.audio_keyword_blacklist.lower().split(',')
else:
self.audio_keyword_blacklist = []
self.fast_subs_display = int(addon.getSetting('FastSubsDisplay'))
self.useFilename = addon.getSetting('useFilename') == 'true'
self.filenameRegex = addon.getSetting('filenameRegex')
if self.useFilename:
Expand Down
20 changes: 12 additions & 8 deletions resources/lib/prefutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,24 @@ def evalPrefs(self):

# Workaround to an old Kodi bug creating 10-15 sec latency when activating a subtitle track.
# Force a short rewind to avoid 10-15sec delay and first few subtitles lines potentially lost
# but if we are very close to beginning, then restart from time 0
# but if we are very close to beginning, then restart from time 0
# Ignore this workaround if fast_subs_display option is disabled (default = 0)
current_time = self.getTime()
if (current_time <= 10):
# This is a probably an initial start, seek back to 0 is securing subs are displayed immediately
log(LOG_DEBUG, 'Forced rewind - Position time is {0} sec. Too close to start, restart from 0.'.format(current_time))
if (settings.fast_subs_display == 0):
# Default is no seek back, which sometimes generate restart or freeze on slower systems
log(LOG_DEBUG, 'Fast Subs Display disabled - Subs display will be slightly delayed 8-10sec.')
elif (current_time <= 10 and settings.fast_subs_display >= 1):
# This is an initial start, seek back to 0 is securing subs are displayed immediately
log(LOG_DEBUG, 'Fast Subs Display on Start - Position time is {0} sec. Restart from 0.'.format(current_time))
self.seekTime(0)
elif (not self.LPM_initial_run_done):
elif (not self.LPM_initial_run_done and settings.fast_subs_display == 2):
# This is a resume, seek back 10sec to secure the 8sec normal Aud/Vid buffers are flushed
# Seek back less while resuming (ex. 1sec) create too many Large Audio Sync errors, with some unwanted restart from 0, or even possible bug freeze
log(LOG_DEBUG, 'Forced rewind - Position time was {0} sec. Resume with 10 sec rewind.'.format(current_time))
log(LOG_DEBUG, 'Fast Subs Display on Resume - Position time is {0} sec. Resume with 10 sec rewind.'.format(current_time))
self.seekTime(current_time - 10)
else:
# This is an Audio Track change on-the-fly, accept the subs latency to keep snappyness. No seek back at all.
log(LOG_DEBUG, 'No Forced rewind - Position time was {0} sec. Audio switch - Subs display slightly delayed.'.format(current_time))
# This is an Audio Track change on-the-fly or a Resume with fast_sub_display on 'Start Only', accept the subs latency to keep snappyness. No seek back at all.
log(LOG_DEBUG, 'Position time was {0} sec. Subs display slightly delayed.'.format(current_time))

def evalFilenamePrefs(self):
log(LOG_DEBUG, 'Evaluating filename preferences' )
Expand Down
13 changes: 13 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@
</dependencies>
</setting>
</group>
<group id="5">
<setting id="FastSubsDisplay" type="integer" label="30131">
<default>0</default>
<constraints>
<options>
<option label="30132">0</option>
<option label="30133">1</option>
<option label="30134">2</option>
</options>
</constraints>
<control type="spinner" format="string"/>
</setting>
</group>
</category>
<category id="Audio Preferences" label="30104">
<group id="1">
Expand Down

0 comments on commit 786f695

Please sign in to comment.