1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-30 04:39:03 +01:00

Fix bugs, now working

This commit is contained in:
Daniil Gentili 2020-03-26 20:37:25 +01:00
parent beb0a3124a
commit 6e715d8b39
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
15 changed files with 34 additions and 31 deletions

View File

@ -187,7 +187,7 @@ public:
setNetworkType(initialNetworkType);
controller_->SetEncryptionKey(encryptionKey.value, encryptionKey.isOutgoing);
controller_->SetRemoteEndpoints(mappedEndpoints, config.enableP2P, config.maxApiLayer);
controller_->SetRemoteEndpoints(mappedEndpoints, config.enableP2P, 110);
controller_->Start();

View File

@ -3,7 +3,7 @@
using namespace tgvoip;
AudioPacketSender::AudioPacketSender(VoIPController *controller, const std::shared_ptr<OutgoingAudioStream> &_stream, const std::shared_ptr<OpusEncoder> &encoder) : PacketSender(controller, dynamic_pointer_cast<OutgoingStream>(_stream)), stream(_stream)
AudioPacketSender::AudioPacketSender(VoIPController *controller, std::shared_ptr<OutgoingAudioStream> _stream, const std::shared_ptr<OpusEncoder> &encoder) : PacketSender(controller, dynamic_pointer_cast<OutgoingStream>(_stream)), stream(_stream)
{
SetSource(encoder);
}

View File

@ -13,7 +13,7 @@ class AudioPacketSender : public PacketSender
friend class VoIPController;
public:
AudioPacketSender(VoIPController *controller, const std::shared_ptr<OutgoingAudioStream> &stream, const std::shared_ptr<OpusEncoder> &encoder);
AudioPacketSender(VoIPController *controller, std::shared_ptr<OutgoingAudioStream> stream, const std::shared_ptr<OpusEncoder> &encoder);
virtual ~AudioPacketSender() = default;
virtual void PacketAcknowledged(const RecentOutgoingPacket &packet) override{};
virtual void PacketLost(const RecentOutgoingPacket &packet) override{};
@ -62,7 +62,7 @@ private:
BufferPool<1024, 32> outgoingAudioBufferPool;
const std::shared_ptr<OutgoingAudioStream> &stream;
std::shared_ptr<OutgoingAudioStream> stream;
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
std::function<void(int16_t *, size_t)> audioPreprocDataCallback;

View File

@ -101,7 +101,7 @@ void JitterBuffer::PutInternal(jitter_packet_t &pkt, bool overwriteExisting)
for (auto &slot : slots)
{
if (slot.timestamp == pkt.timestamp && !slot.buffer->IsEmpty())
if (slot.timestamp == pkt.timestamp && slot.buffer)
{
if (overwriteExisting)
{
@ -126,7 +126,7 @@ void JitterBuffer::PutInternal(jitter_packet_t &pkt, bool overwriteExisting)
for (auto &slot : slots)
{
// Clear packets older than the last packet pulled from jitter buffer
if (slot.timestamp < nextFetchTimestamp - 1 && !slot.buffer->IsEmpty())
if (slot.timestamp < nextFetchTimestamp - 1 && slot.buffer)
{
slot.buffer = nullptr;
}
@ -178,14 +178,14 @@ void JitterBuffer::PutInternal(jitter_packet_t &pkt, bool overwriteExisting)
// If no free slots or too many used up slots to be useful
auto slot = GetCurrentDelay() >= maxUsedSlots ? slots.end() : std::find_if(slots.begin(), slots.end(), [](const jitter_packet_t &a) -> bool {
return a.buffer->IsEmpty();
return !a.buffer;
});
if (slot == slots.end())
{
LOGW("No free slots!");
slot = std::min_element(slots.begin(), slots.end(), [](const jitter_packet_t &a, const jitter_packet_t &b) -> bool {
return !a.buffer->IsEmpty() && a.timestamp < b.timestamp;
return a.buffer && a.timestamp < b.timestamp;
});
slot->buffer = nullptr;
Advance();
@ -238,7 +238,7 @@ std::unique_ptr<Buffer> JitterBuffer::HandleOutput(bool advance, int &playbackSc
auto slot = std::find_if(slots.begin(), slots.end(), [&](const jitter_packet_t &a) -> bool {
return a.timestamp == nextFetchTimestamp;
});
if (slot != slots.end() && !slot->buffer->IsEmpty())
if (slot != slots.end() && slot->buffer)
{
slot->buffer = nullptr;
}
@ -288,7 +288,7 @@ int JitterBuffer::GetInternal(jitter_packet_t &pkt, bool advance)
int64_t timestampToGet = nextFetchTimestamp;
auto slot = std::find_if(slots.begin(), slots.end(), [timestampToGet](const jitter_packet_t &a) -> bool {
return a.timestamp == timestampToGet && !a.buffer->IsEmpty();
return a.timestamp == timestampToGet && a.buffer;
});
if (slot != slots.end())
@ -347,7 +347,7 @@ void JitterBuffer::Advance()
unsigned int JitterBuffer::GetCurrentDelay()
{
return std::count_if(slots.begin(), slots.end(), [](const jitter_packet_t &a) -> bool {
return !a.buffer->IsEmpty();
return !!a.buffer;
});
}

View File

@ -10,7 +10,9 @@ using namespace tgvoip;
PendingOutgoingPacket VoIPController::PreparePacket(unsigned char *data, size_t len, Endpoint &ep, CongestionControlPacket &&pkt)
{
#ifdef LOG_PACKETS
LOGV("Preparing packet of length=%u, seq=%u, streamId=%hhu", (unsigned int)len, pkt.seq, pkt.streamId);
#endif
BufferOutputStream out(len + 128);
if (ep.IsReflector())
@ -36,7 +38,7 @@ void VoIPController::SendPacket(OutgoingPacket &&pkt, double retryInterval, doub
if (ver.isNew())
{
packet.prepare(pm, currentExtras, endpoint.id);
LOGW("Sending outgoing packet: %s", packet.print().c_str());
//LOGW("Sending outgoing packet: %s", packet.print().c_str());
//BufferOutputStream out(packet.getSize()); // Can precalc, should check if it's worth it
BufferOutputStream out(1500);
@ -139,7 +141,7 @@ void VoIPController::SendOrEnqueuePacket(PendingOutgoingPacket &pkt, bool enqueu
unacknowledgedIncomingPacketCount = 0;
outgoingStreams[pkt.pktInfo.streamId]->packetManager.addRecentOutgoingPacket(pkt);
LOGV("Sending: to=%s:%u, seq=%u, length=%u, streamId=%hhu", endpoint.GetAddress().ToString().c_str(), endpoint.port, pkt.pktInfo.seq, (unsigned int)pkt.packet->Length(), pkt.pktInfo.streamId);
//LOGV("Sending: to=%s:%u, seq=%u, length=%u, streamId=%hhu", endpoint.GetAddress().ToString().c_str(), endpoint.port, pkt.pktInfo.seq, (unsigned int)pkt.packet->Length(), pkt.pktInfo.streamId);
//LOGV("Sending %d bytes to %s:%d", out.GetLength(), ep.address.ToString().c_str(), ep.port);
#ifdef LOG_PACKETS

View File

@ -91,9 +91,10 @@ void VoIPController::ProcessIncomingPacket(NetworkPacket &npacket, Endpoint &src
return;
}
}
return;
}
#ifdef LOG_PACKETS
LOGW("Got%s incoming packet: %s", packet.legacy ? " legacy" : "", packet.print().c_str());
#endif
packetsReceived++;
ProcessIncomingPacket(packet, srcEndpoint);
@ -114,15 +115,9 @@ void VoIPController::ProcessIncomingPacket(Packet &packet, Endpoint &srcEndpoint
if (!manager.ackRemoteSeq(packet))
{
LOGE("Failure acking remote seq!");
return;
}
LOGE("Received packet!");
#ifdef LOG_PACKETS
LOGV("Received: from=%s:%u, seq=%u, length=%u, type=%s, transportId=%hhu", srcEndpoint.GetAddress().ToString().c_str(), srcEndpoint.port, pseq, (unsigned int)packet.data.Length(), GetPacketTypeString(type).c_str(), transportId);
#endif
for (auto &extra : packet.extraSignaling)
{
ProcessExtraData(extra, srcEndpoint);
@ -306,7 +301,9 @@ void VoIPController::ProcessExtraData(const Wrapped<Extra> &_data, Endpoint &src
auto type = _data.getID();
if (_data.d->hash && lastReceivedExtrasByType[type] == _data.d->hash)
{
#ifdef LOG_PACKETS
LOGE("Received duplicate hash for extra=%s!", _data.print().c_str());
#endif
return;
}
lastReceivedExtrasByType[type] = _data.d->hash;

View File

@ -44,9 +44,9 @@ void VoIPController::UpdateReliablePackets()
{
messageThread.Post(std::bind(&VoIPController::UpdateReliablePackets, this), qp->retryInterval);
qp->lastSentTime = GetCurrentTime();
//#ifdef LOG_PACKETS
#ifdef LOG_PACKETS
LOGD("Sending reliable queued packet, seq=%u, len=%lu", qp->pkt.pktInfo.seq, qp->pkt.packet->Length());
//#endif
#endif
if (qp->firstSentTime == 0)
qp->firstSentTime = qp->lastSentTime;

View File

@ -141,7 +141,6 @@ void VoIPController::TickJitterBufferAndCongestionControl()
double packetLossTimeout = std::max(rtt * 2.0, 0.1);
for (auto &stm : outgoingStreams)
{
auto *sender = dynamic_cast<AudioPacketSender *>(stm->packetSender.get());
for (RecentOutgoingPacket &pkt : stm->packetManager.getRecentOutgoingPackets())
{
if (pkt.ackTime || pkt.lost)
@ -153,7 +152,7 @@ void VoIPController::TickJitterBufferAndCongestionControl()
LOGW("Outgoing packet lost: seq=%u, streamId=%hhu, size=%u", pkt.pkt.seq, pkt.pkt.streamId, (unsigned int)pkt.size);
conctl.PacketLost(pkt.pkt);
sender->PacketLost(pkt);
stm->packetSender->PacketLost(pkt);
}
}
}

View File

@ -50,7 +50,7 @@ bool PacketManager::ackRemoteSeq(const uint32_t ackId)
{
if (ackId == lastRemoteSeq)
{
LOGW("Received duplicated packet for seq %u, streamId=%hhu", ackId, transportId);
//LOGW("Received duplicated packet for seq %u, streamId=%hhu", ackId, transportId);
return false;
}
else if (ackId > lastRemoteSeq)

View File

@ -3,4 +3,4 @@
using namespace tgvoip;
PacketSender::PacketSender(VoIPController *_controller, const std::shared_ptr<OutgoingStream> &_stream) : controller(_controller), stream(_stream), packetManager(_stream->packetManager){};
PacketSender::PacketSender(VoIPController *_controller, std::shared_ptr<OutgoingStream> _stream) : controller(_controller), stream(_stream), packetManager(_stream->packetManager){};

View File

@ -114,7 +114,7 @@ struct IncomingVideoStream : public VideoStreamInfo, public IncomingMediaStream
class PacketSender
{
public:
PacketSender(VoIPController *_controller, const std::shared_ptr<OutgoingStream> &_stream);
PacketSender(VoIPController *_controller, std::shared_ptr<OutgoingStream> _stream);
virtual ~PacketSender() = default;
virtual void PacketAcknowledged(const RecentOutgoingPacket &packet){};

View File

@ -35,7 +35,10 @@ std::shared_ptr<Extra> Extra::choose(const BufferInputStream &in, const VersionI
unsigned char fullHash[SHA1_LENGTH];
VoIPController::crypto.sha1(const_cast<uint8_t *>(in.GetRawBuffer()), in.Remaining(), fullHash);
#ifdef LOG_PACKETS
LOGE("Got extra ID %hhu", id);
#endif
std::shared_ptr<Extra> res;
switch (id)
{

View File

@ -258,7 +258,9 @@ struct Wrapped : public Serializable, SingleChoice<Wrapped<T>>
uint8_t len;
if (!in.TryRead(len))
return false;
#ifdef LOG_PACKETS
LOGW("Got buffer of length %hhu", len);
#endif
auto buf = in.GetPartBuffer(len);
d = T::choose(buf, ver);
if (!d)

View File

@ -11,7 +11,7 @@
using namespace tgvoip;
using namespace tgvoip::video;
VideoPacketSender::VideoPacketSender(VoIPController *controller, const std::shared_ptr<OutgoingVideoStream> &_stream, VideoSource *videoSource) : PacketSender(controller, dynamic_pointer_cast<OutgoingStream>(_stream)), stream(_stream)
VideoPacketSender::VideoPacketSender(VoIPController *controller, std::shared_ptr<OutgoingVideoStream> _stream, VideoSource *videoSource) : PacketSender(controller, dynamic_pointer_cast<OutgoingStream>(_stream)), stream(_stream)
{
SetSource(videoSource);
}

View File

@ -23,7 +23,7 @@ class VideoSource;
class VideoPacketSender : public PacketSender
{
public:
VideoPacketSender(VoIPController *controller, const std::shared_ptr<OutgoingVideoStream> &stream, VideoSource *videoSource);
VideoPacketSender(VoIPController *controller, std::shared_ptr<OutgoingVideoStream> stream, VideoSource *videoSource);
virtual ~VideoPacketSender();
virtual void PacketAcknowledged(const RecentOutgoingPacket &packet) override;
virtual void PacketLost(const RecentOutgoingPacket &packet) override;
@ -58,7 +58,7 @@ private:
double lastVideoResolutionChangeTime = 0.0;
double sourceChangeTime = 0.0;
const std::shared_ptr<OutgoingVideoStream> &stream;
std::shared_ptr<OutgoingVideoStream> stream;
std::vector<Buffer>
packetsForFEC;