Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webOS] Audio sink improvements #23295

Merged
merged 6 commits into from May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions xbmc/cores/AudioEngine/Sinks/AESinkStarfish.cpp
Expand Up @@ -63,6 +63,10 @@ void CAESinkStarfish::EnumerateDevicesEx(AEDeviceInfoList& list, bool force)
info.m_streamTypes.emplace_back(CAEStreamInfo::STREAM_TYPE_AC3);
info.m_streamTypes.emplace_back(CAEStreamInfo::STREAM_TYPE_EAC3);

info.m_sampleRates.emplace_back(32000);
info.m_sampleRates.emplace_back(44100);
info.m_sampleRates.emplace_back(48000);

list.emplace_back(info);
}

Expand Down Expand Up @@ -97,8 +101,6 @@ bool CAESinkStarfish::Initialize(AEAudioFormat& format, std::string& device)
payload["option"]["externalStreamingInfo"]["contents"]["format"] = "RAW";
payload["option"]["transmission"]["contentsType"] = "LIVE"; // "LIVE", "WEBRTC"

payload["option"]["lowDelayMode"] = true;

switch (m_format.m_streamInfo.m_type)
{
case CAEStreamInfo::STREAM_TYPE_AC3:
Expand All @@ -111,8 +113,7 @@ bool CAESinkStarfish::Initialize(AEAudioFormat& format, std::string& device)
}
case CAEStreamInfo::STREAM_TYPE_EAC3:
{
payload["option"]["externalStreamingInfo"]["contents"]["ac3PlusInfo"]["channels"] =
m_format.m_streamInfo.m_channels;
payload["option"]["externalStreamingInfo"]["contents"]["ac3PlusInfo"]["channels"] = 8;
payload["option"]["externalStreamingInfo"]["contents"]["ac3PlusInfo"]["frequency"] =
static_cast<double>(m_format.m_streamInfo.m_sampleRate) / 1000;

Expand Down Expand Up @@ -170,7 +171,7 @@ double CAESinkStarfish::GetCacheTotal()
{
auto frameTimeSeconds = std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::duration<double, std::milli>(m_format.m_streamInfo.GetDuration()));
return STARFISH_AUDIO_BUFFERS * frameTimeSeconds.count();
return STARFISH_AUDIO_BUFFERS * frameTimeSeconds.count() * 2;
}
else
return 0.0;
Expand All @@ -183,18 +184,19 @@ double CAESinkStarfish::GetLatency()

unsigned int CAESinkStarfish::AddPackets(uint8_t** data, unsigned int frames, unsigned int offset)
{
auto frameTime = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::duration<double, std::milli>(m_format.m_streamInfo.GetDuration()));

if (!m_firstFeed && offset == 0)
m_pts += frameTime;

CVariant payload;
uint8_t* buffer = data[0] + offset * m_format.m_frameSize;
payload["bufferAddr"] = fmt::format("{:#x}", reinterpret_cast<std::uintptr_t>(buffer));
payload["bufferSize"] = frames * m_format.m_frameSize;
payload["pts"] = m_pts.count();
payload["esData"] = 2;

auto frameTime = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::duration<double, std::milli>(m_format.m_streamInfo.GetDuration()));

m_pts += frameTime;

std::string json;
CJSONVariantWriter::Write(payload, json, true);

Expand All @@ -206,7 +208,10 @@ unsigned int CAESinkStarfish::AddPackets(uint8_t** data, unsigned int frames, un
}

if (result.find("Ok") != std::string::npos)
{
m_firstFeed = false;
return frames;
}

CLog::LogF(LOGWARNING, "CAESinkStarfish: Buffer submit returned error: {}", result);
return 0;
Expand All @@ -221,9 +226,7 @@ void CAESinkStarfish::AddPause(unsigned int millis)

void CAESinkStarfish::GetDelay(AEDelayStatus& status)
{
constexpr auto hwLatency = 250ms;
status.SetDelay(
std::chrono::duration_cast<std::chrono::duration<double>>(m_delay + hwLatency).count());
status.SetDelay(std::chrono::duration_cast<std::chrono::duration<double>>(m_delay).count());
}

void CAESinkStarfish::Drain()
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Sinks/AESinkStarfish.h
Expand Up @@ -49,4 +49,5 @@ class CAESinkStarfish : public IAESink
std::chrono::nanoseconds m_pts{0};
int64_t m_bufferSize{0};
std::chrono::nanoseconds m_delay{0};
bool m_firstFeed{true};
};
6 changes: 4 additions & 2 deletions xbmc/cores/AudioEngine/Utils/AEStreamInfo.cpp
Expand Up @@ -369,6 +369,7 @@ bool CAEStreamParser::TrySyncAC3(uint8_t* data,
// no need to resync => return true
return true;
}
m_info.m_ac3FrameSize = fsizeMain;
if (TrySyncAC3(data + fsizeMain, size - fsizeMain, resyncing, true))
{
// concatenate the main and dependent frames
Expand All @@ -392,7 +393,7 @@ bool CAEStreamParser::TrySyncAC3(uint8_t* data,
m_info.m_channels = AC3Channels[acmod] + lfeon;
m_syncFunc = &CAEStreamParser::SyncAC3;
m_info.m_type = CAEStreamInfo::STREAM_TYPE_AC3;
m_info.m_ac3FrameSize = m_fsize;
m_info.m_ac3FrameSize += m_fsize;
m_info.m_repeat = 1;

CLog::Log(LOGINFO, "CAEStreamParser::TrySyncAC3 - AC3 stream detected ({} channels, {}Hz)",
Expand Down Expand Up @@ -451,6 +452,7 @@ bool CAEStreamParser::TrySyncAC3(uint8_t* data,
// no need to resync => return true
return true;
}
m_info.m_ac3FrameSize = fsizeMain;
if (TrySyncAC3(data + fsizeMain, size - fsizeMain, resyncing, true))
{
// concatenate the main and dependent frames
Expand All @@ -467,7 +469,7 @@ bool CAEStreamParser::TrySyncAC3(uint8_t* data,
m_info.m_channels = AC3Channels[acmod] + lfeon;
m_syncFunc = &CAEStreamParser::SyncAC3;
m_info.m_type = CAEStreamInfo::STREAM_TYPE_EAC3;
m_info.m_ac3FrameSize = m_fsize;
m_info.m_ac3FrameSize += m_fsize;

CLog::Log(LOGINFO, "CAEStreamParser::TrySyncAC3 - E-AC3 stream detected ({} channels, {}Hz)",
m_info.m_channels, m_info.m_sampleRate);
Expand Down