Skip to content

Commit

Permalink
AESinkAudioTrack: Help broken firmwares to make kodi ignore broken delay
Browse files Browse the repository at this point in the history
Kodi can supervise the sink for being stuck, which means: if you open a sink
with 160 ms buffer and it does not move while eating more than twice of the
buffer's audio data, it is considered a bug. Sadly - there is a whole
lot of broken firmwares out there, one of the leards: Ugoos. Which is the
reason I make disabled by default. That means that FireTV Cube 3rd Gen and
others would need to enable this - once again - via an advanced settings.

<advancedsettings>
<audio>
<superviseaudiodelay>true</superviseaudiodelay>
<audio>
</advancedsettings>
  • Loading branch information
fritsch committed Jan 28, 2024
1 parent b11eb7c commit 6fc5510
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ bool CAESinkAUDIOTRACK::Initialize(AEAudioFormat &format, std::string &device)
}
}

m_superviseAudioDelay = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_superviseAudioDelay;

int atChannelMask = AEChannelMapToAUDIOTRACKChannelMask(m_format.m_channelLayout);
m_format.m_channelLayout = AUDIOTRACKChannelMaskToAEChannelMap(atChannelMask);
if (m_encoding == CJNIAudioFormat::ENCODING_IEC61937)
Expand Down Expand Up @@ -825,7 +827,7 @@ unsigned int CAESinkAUDIOTRACK::AddPackets(uint8_t **data, unsigned int frames,
const double max_stuck_delay_ms = m_audiotrackbuffer_sec_orig * 2000.0;
const double stime_ms = 1000.0 * frames / m_format.m_sampleRate;

if (m_stuckCounter * stime_ms > max_stuck_delay_ms)
if (m_superviseAudioDelay && (m_stuckCounter * stime_ms > max_stuck_delay_ms))
{
CLog::Log(LOGERROR, "Sink got stuck with {:f} ms - ask AE for reopening", max_stuck_delay_ms);
usleep(max_stuck_delay_ms * 1000);
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CAESinkAUDIOTRACK : public IAESink
double m_hw_delay = 0.0;
CJNIAudioTimestamp m_timestamp;
XbmcThreads::EndTime<> m_stampTimer;
bool m_superviseAudioDelay = false;

std::vector<float> m_floatbuf;
std::vector<int16_t> m_shortbuf;
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/AdvancedSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ void CAdvancedSettings::ParseSettingsFile(const std::string &file)
XMLUtils::GetUInt(pElement, "maxpassthroughoffsyncduration", m_maxPassthroughOffSyncDuration,
10, 100);
XMLUtils::GetBoolean(pElement, "allowmultichannelfloat", m_AllowMultiChannelFloat);
XMLUtils::GetBoolean(pElement, "superviseaudiodelay", m_superviseAudioDelay);
}

pElement = pRootElement->FirstChildElement("x11");
Expand Down
3 changes: 2 additions & 1 deletion xbmc/settings/AdvancedSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class CAdvancedSettings : public ISettingCallback, public ISettingsHandler
float m_videoIgnorePercentAtEnd;
float m_audioApplyDrc;
unsigned int m_maxPassthroughOffSyncDuration = 10; // when 10 ms off adjust
bool m_AllowMultiChannelFloat = false; // Android only switch to be remved in v22
bool m_AllowMultiChannelFloat = false; // Android only switch to be removed in v22
bool m_superviseAudioDelay = false; // Android only to not correct broken audio firmwares

int m_videoVDPAUScaling;
float m_videoNonLinStretchRatio;
Expand Down

0 comments on commit 6fc5510

Please sign in to comment.