TwinLink: mirror local-client talker and audio to partner
Outbound: onLocalTalkerUpdated/onLocalAudio/onLocalFlush now send MsgTrunkTalkerStart/Stop, MsgTrunkAudio, MsgTrunkFlush over the twin TCP connection when isActive(). Receive-side: handleMsgTrunkTalkerStart/Stop call TGHandler::setTrunkTalkerForTG / clearTrunkTalkerForTG, which fires trunkTalkerUpdated → Reflector::onTrunkTalkerUpdated, broadcasting MsgTalkerStart/Stop to local clients. handleMsgTrunkAudio and handleMsgTrunkFlush call Reflector::broadcastUdpMsg directly. Reflector::onTalkerUpdated (talkerUpdated signal handler) now notifies m_twin_link after the trunk/satellite loops. MsgUdpAudio and MsgUdpFlushSamples handlers similarly call m_twin_link->onLocalAudio/ onLocalFlush in the non-satellite branch. No echo loop: trunkTalkerUpdated (twin receive path) is distinct from talkerUpdated (local-client signal that drives outbound sends).
This commit is contained in:
1 parent
9b748d1bdc
commit
2554efb392
2 files changed
+72
-16
No files matched your search
@@ -1415,6 +1415,10 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
|
||||
{
|
||||
kv.second->onParentAudio(tg, msg.audioData());
|
||||
}
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
m_twin_link->onLocalAudio(tg, msg.audioData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1477,6 +1481,10 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
|
||||
{
|
||||
kv.second->onParentFlush(tg);
|
||||
}
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
m_twin_link->onLocalFlush(tg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// To be 100% correct the reflector should wait for all connected
|
||||
@@ -1629,6 +1637,13 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker,
|
||||
kv.second->onParentTalkerStop(tg);
|
||||
}
|
||||
}
|
||||
// Notify twin partner about local talker changes.
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
std::string callsign = (new_talker != nullptr) ? new_talker->callsign()
|
||||
: "";
|
||||
m_twin_link->onLocalTalkerUpdated(tg, callsign);
|
||||
}
|
||||
}
|
||||
} /* Reflector::onTalkerUpdated */
|
||||
|
||||
|
||||
@@ -194,23 +194,33 @@ void TwinLink::acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
} /* TwinLink::acceptInboundConnection */
|
||||
|
||||
|
||||
void TwinLink::onLocalTalkerUpdated(uint32_t /*tg*/,
|
||||
const std::string& /*callsign*/)
|
||||
void TwinLink::onLocalTalkerUpdated(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
// Phase C1
|
||||
if (!isActive()) return;
|
||||
if (callsign.empty())
|
||||
{
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
}
|
||||
} /* TwinLink::onLocalTalkerUpdated */
|
||||
|
||||
|
||||
void TwinLink::onLocalAudio(uint32_t /*tg*/,
|
||||
const std::vector<uint8_t>& /*audio*/)
|
||||
void TwinLink::onLocalAudio(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
// Phase C1
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
} /* TwinLink::onLocalAudio */
|
||||
|
||||
|
||||
void TwinLink::onLocalFlush(uint32_t /*tg*/)
|
||||
void TwinLink::onLocalFlush(uint32_t tg)
|
||||
{
|
||||
// Phase C1
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
} /* TwinLink::onLocalFlush */
|
||||
|
||||
|
||||
@@ -399,27 +409,58 @@ void TwinLink::handleMsgTrunkHello(std::istream& is, bool is_inbound)
|
||||
} /* TwinLink::handleMsgTrunkHello */
|
||||
|
||||
|
||||
void TwinLink::handleMsgTrunkTalkerStart(std::istream& /*is*/)
|
||||
void TwinLink::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
{
|
||||
// Phase C1
|
||||
MsgTrunkTalkerStart msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkTalkerStart" << endl;
|
||||
return;
|
||||
}
|
||||
// setTrunkTalkerForTG fires trunkTalkerUpdated → onTrunkTalkerUpdated in
|
||||
// Reflector, which broadcasts MsgTalkerStart to all local clients on this TG.
|
||||
TGHandler::instance()->setTrunkTalkerForTG(msg.tg(), msg.callsign());
|
||||
} /* TwinLink::handleMsgTrunkTalkerStart */
|
||||
|
||||
|
||||
void TwinLink::handleMsgTrunkTalkerStop(std::istream& /*is*/)
|
||||
void TwinLink::handleMsgTrunkTalkerStop(std::istream& is)
|
||||
{
|
||||
// Phase C1
|
||||
MsgTrunkTalkerStop msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkTalkerStop" << endl;
|
||||
return;
|
||||
}
|
||||
// clearTrunkTalkerForTG fires trunkTalkerUpdated → onTrunkTalkerUpdated,
|
||||
// which broadcasts MsgTalkerStop and MsgUdpFlushSamples to local clients.
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(msg.tg());
|
||||
} /* TwinLink::handleMsgTrunkTalkerStop */
|
||||
|
||||
|
||||
void TwinLink::handleMsgTrunkAudio(std::istream& /*is*/)
|
||||
void TwinLink::handleMsgTrunkAudio(std::istream& is)
|
||||
{
|
||||
// Phase C1
|
||||
MsgTrunkAudio msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkAudio" << endl;
|
||||
return;
|
||||
}
|
||||
if (msg.audio().empty()) return;
|
||||
MsgUdpAudio udp_msg(msg.audio());
|
||||
m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(msg.tg()));
|
||||
} /* TwinLink::handleMsgTrunkAudio */
|
||||
|
||||
|
||||
void TwinLink::handleMsgTrunkFlush(std::istream& /*is*/)
|
||||
void TwinLink::handleMsgTrunkFlush(std::istream& is)
|
||||
{
|
||||
// Phase C1
|
||||
MsgTrunkFlush msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkFlush" << endl;
|
||||
return;
|
||||
}
|
||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||
ReflectorClient::TgFilter(msg.tg()));
|
||||
} /* TwinLink::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user