diff --git a/TgVoip.cpp b/TgVoip.cpp index a6bd11a..ec69d53 100755 --- a/TgVoip.cpp +++ b/TgVoip.cpp @@ -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(); diff --git a/controller/audio/AudioPacketSender.cpp b/controller/audio/AudioPacketSender.cpp index 73ae2ba..4d2e2cd 100644 --- a/controller/audio/AudioPacketSender.cpp +++ b/controller/audio/AudioPacketSender.cpp @@ -3,7 +3,7 @@ using namespace tgvoip; -AudioPacketSender::AudioPacketSender(VoIPController *controller, const std::shared_ptr &_stream, const std::shared_ptr &encoder) : PacketSender(controller, dynamic_pointer_cast(_stream)), stream(_stream) +AudioPacketSender::AudioPacketSender(VoIPController *controller, std::shared_ptr _stream, const std::shared_ptr &encoder) : PacketSender(controller, dynamic_pointer_cast(_stream)), stream(_stream) { SetSource(encoder); } diff --git a/controller/audio/AudioPacketSender.h b/controller/audio/AudioPacketSender.h index 933f7c6..4ff2857 100644 --- a/controller/audio/AudioPacketSender.h +++ b/controller/audio/AudioPacketSender.h @@ -13,7 +13,7 @@ class AudioPacketSender : public PacketSender friend class VoIPController; public: - AudioPacketSender(VoIPController *controller, const std::shared_ptr &stream, const std::shared_ptr &encoder); + AudioPacketSender(VoIPController *controller, std::shared_ptr stream, const std::shared_ptr &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 &stream; + std::shared_ptr stream; #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) std::function audioPreprocDataCallback; diff --git a/controller/net/JitterBuffer.cpp b/controller/net/JitterBuffer.cpp index 7cd6b5d..e25f53c 100755 --- a/controller/net/JitterBuffer.cpp +++ b/controller/net/JitterBuffer.cpp @@ -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 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; }); } diff --git a/controller/protocol/NetworkAPI.cpp b/controller/protocol/NetworkAPI.cpp index 5005ae7..e05bb08 100644 --- a/controller/protocol/NetworkAPI.cpp +++ b/controller/protocol/NetworkAPI.cpp @@ -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 diff --git a/controller/protocol/Protocol.cpp b/controller/protocol/Protocol.cpp index 7b8c90a..ac552fc 100644 --- a/controller/protocol/Protocol.cpp +++ b/controller/protocol/Protocol.cpp @@ -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 &_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; diff --git a/controller/protocol/Reliable.cpp b/controller/protocol/Reliable.cpp index e968d04..b51040b 100644 --- a/controller/protocol/Reliable.cpp +++ b/controller/protocol/Reliable.cpp @@ -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; diff --git a/controller/protocol/Tick.cpp b/controller/protocol/Tick.cpp index f6162dc..f6f053d 100644 --- a/controller/protocol/Tick.cpp +++ b/controller/protocol/Tick.cpp @@ -141,7 +141,6 @@ void VoIPController::TickJitterBufferAndCongestionControl() double packetLossTimeout = std::max(rtt * 2.0, 0.1); for (auto &stm : outgoingStreams) { - auto *sender = dynamic_cast(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); } } } diff --git a/controller/protocol/packets/PacketManager.cpp b/controller/protocol/packets/PacketManager.cpp index 1d57dff..b78cc6f 100644 --- a/controller/protocol/packets/PacketManager.cpp +++ b/controller/protocol/packets/PacketManager.cpp @@ -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) diff --git a/controller/protocol/packets/PacketSender.cpp b/controller/protocol/packets/PacketSender.cpp index 737326c..f90c6b5 100644 --- a/controller/protocol/packets/PacketSender.cpp +++ b/controller/protocol/packets/PacketSender.cpp @@ -3,4 +3,4 @@ using namespace tgvoip; -PacketSender::PacketSender(VoIPController *_controller, const std::shared_ptr &_stream) : controller(_controller), stream(_stream), packetManager(_stream->packetManager){}; +PacketSender::PacketSender(VoIPController *_controller, std::shared_ptr _stream) : controller(_controller), stream(_stream), packetManager(_stream->packetManager){}; diff --git a/controller/protocol/packets/PacketSender.h b/controller/protocol/packets/PacketSender.h index e2e7aa9..fe6b67d 100644 --- a/controller/protocol/packets/PacketSender.h +++ b/controller/protocol/packets/PacketSender.h @@ -114,7 +114,7 @@ struct IncomingVideoStream : public VideoStreamInfo, public IncomingMediaStream class PacketSender { public: - PacketSender(VoIPController *_controller, const std::shared_ptr &_stream); + PacketSender(VoIPController *_controller, std::shared_ptr _stream); virtual ~PacketSender() = default; virtual void PacketAcknowledged(const RecentOutgoingPacket &packet){}; diff --git a/controller/protocol/protocol/Extra.cpp b/controller/protocol/protocol/Extra.cpp index dd1cde2..eaadb6f 100644 --- a/controller/protocol/protocol/Extra.cpp +++ b/controller/protocol/protocol/Extra.cpp @@ -35,7 +35,10 @@ std::shared_ptr Extra::choose(const BufferInputStream &in, const VersionI unsigned char fullHash[SHA1_LENGTH]; VoIPController::crypto.sha1(const_cast(in.GetRawBuffer()), in.Remaining(), fullHash); +#ifdef LOG_PACKETS LOGE("Got extra ID %hhu", id); +#endif + std::shared_ptr res; switch (id) { diff --git a/controller/protocol/protocol/Interface.h b/controller/protocol/protocol/Interface.h index a2ce923..d92da67 100644 --- a/controller/protocol/protocol/Interface.h +++ b/controller/protocol/protocol/Interface.h @@ -258,7 +258,9 @@ struct Wrapped : public Serializable, SingleChoice> 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) diff --git a/video/VideoPacketSender.cpp b/video/VideoPacketSender.cpp index ed43b97..f502da4 100644 --- a/video/VideoPacketSender.cpp +++ b/video/VideoPacketSender.cpp @@ -11,7 +11,7 @@ using namespace tgvoip; using namespace tgvoip::video; -VideoPacketSender::VideoPacketSender(VoIPController *controller, const std::shared_ptr &_stream, VideoSource *videoSource) : PacketSender(controller, dynamic_pointer_cast(_stream)), stream(_stream) +VideoPacketSender::VideoPacketSender(VoIPController *controller, std::shared_ptr _stream, VideoSource *videoSource) : PacketSender(controller, dynamic_pointer_cast(_stream)), stream(_stream) { SetSource(videoSource); } @@ -318,7 +318,7 @@ void VideoPacketSender::SendFrame(const Buffer &_frame, uint32_t flags, uint32_t int VideoPacketSender::GetVideoResolutionForCurrentBitrate() { - + int peerMaxVideoResolution = controller->ver.maxVideoResolution; int resolutionFromBitrate = INIT_VIDEO_RES_1080; if (VoIPController::GetCurrentTime() - sourceChangeTime > 10.0) diff --git a/video/VideoPacketSender.h b/video/VideoPacketSender.h index 0dfb244..8275466 100644 --- a/video/VideoPacketSender.h +++ b/video/VideoPacketSender.h @@ -23,7 +23,7 @@ class VideoSource; class VideoPacketSender : public PacketSender { public: - VideoPacketSender(VoIPController *controller, const std::shared_ptr &stream, VideoSource *videoSource); + VideoPacketSender(VoIPController *controller, std::shared_ptr 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 &stream; + std::shared_ptr stream; std::vector packetsForFEC;