diff options
author | dknn <yoann.blein@free.fr> | 2012-08-04 09:13:14 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:01:49 (GMT) |
commit | 5ed2b62239eda07de84142e63fad31ccc194d379 (patch) | |
tree | 47d7dd469b7f637ee125371d267eaae17a6978a7 /Swiften | |
parent | 292967c02ffc2ff0b53df526af2965a03916290c (diff) | |
download | swift-contrib-5ed2b62239eda07de84142e63fad31ccc194d379.zip swift-contrib-5ed2b62239eda07de84142e63fad31ccc194d379.tar.bz2 |
Fix bug with ipv6 + add new feature in disco
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/DiscoInfo.cpp | 1 | ||||
-rw-r--r-- | Swiften/Elements/DiscoInfo.h | 1 | ||||
-rw-r--r-- | Swiften/Examples/ScreenSharing/Client.cpp | 1 | ||||
-rw-r--r-- | Swiften/ScreenSharing/IncomingScreenSharing.cpp | 5 | ||||
-rw-r--r-- | Swiften/ScreenSharing/IncomingScreenSharing.h | 2 | ||||
-rw-r--r-- | Swiften/ScreenSharing/RTPSessionImpl.cpp | 51 | ||||
-rw-r--r-- | Swiften/ScreenSharing/RTPSessionImpl.h | 8 | ||||
-rw-r--r-- | Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp | 3 |
8 files changed, 53 insertions, 19 deletions
diff --git a/Swiften/Elements/DiscoInfo.cpp b/Swiften/Elements/DiscoInfo.cpp index c20f989..6aaee54 100644 --- a/Swiften/Elements/DiscoInfo.cpp +++ b/Swiften/Elements/DiscoInfo.cpp @@ -25,6 +25,7 @@ const std::string DiscoInfo::MessageDeliveryReceiptsFeature = std::string("urn:x const std::string DiscoInfo::WhiteboardFeature = std::string("http://swift.im/whiteboard"); const std::string DiscoInfo::JingleRTPFeature = std::string("urn:xmpp:jingle:apps:rtp:1"); const std::string DiscoInfo::JingleTransportRawUDPFeature = std::string("urn:xmpp:jingle:transports:raw-udp:1"); +const std::string DiscoInfo::JingleScreenSharingFeature = std::string("urn:xmpp:jingle:apps:screen-sharing:0"); bool DiscoInfo::Identity::operator<(const Identity& other) const { if (category_ == other.category_) { diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h index 9ef3ab6..12d32fd 100644 --- a/Swiften/Elements/DiscoInfo.h +++ b/Swiften/Elements/DiscoInfo.h @@ -36,6 +36,7 @@ namespace Swift { static const std::string WhiteboardFeature; static const std::string JingleRTPFeature; static const std::string JingleTransportRawUDPFeature; + static const std::string JingleScreenSharingFeature; class Identity { public: diff --git a/Swiften/Examples/ScreenSharing/Client.cpp b/Swiften/Examples/ScreenSharing/Client.cpp index 71dff34..6d5a6b3 100644 --- a/Swiften/Examples/ScreenSharing/Client.cpp +++ b/Swiften/Examples/ScreenSharing/Client.cpp @@ -71,6 +71,7 @@ class ScreenReceiver { discoInfo.addFeature(DiscoInfo::JingleFeature); discoInfo.addFeature(DiscoInfo::JingleRTPFeature); discoInfo.addFeature(DiscoInfo::JingleTransportRawUDPFeature); + discoInfo.addFeature(DiscoInfo::JingleScreenSharingFeature); client->getDiscoManager()->setCapsNode(CLIENT_NODE); client->getDiscoManager()->setDiscoInfo(discoInfo); client->getPresenceSender()->sendPresence(Presence::create()); diff --git a/Swiften/ScreenSharing/IncomingScreenSharing.cpp b/Swiften/ScreenSharing/IncomingScreenSharing.cpp index 3807a0f..bbbfbad 100644 --- a/Swiften/ScreenSharing/IncomingScreenSharing.cpp +++ b/Swiften/ScreenSharing/IncomingScreenSharing.cpp @@ -79,6 +79,11 @@ void IncomingScreenSharing::accept() onStateChange(ScreenSharing::Connecting); } +const JID &IncomingScreenSharing::getSender() const +{ + return jingleSession->getInitiator(); +} + JingleContentID IncomingScreenSharing::getContentID() const { return JingleContentID(initialContent->getName(), initialContent->getCreator()); diff --git a/Swiften/ScreenSharing/IncomingScreenSharing.h b/Swiften/ScreenSharing/IncomingScreenSharing.h index f6d9b62..cc25a9f 100644 --- a/Swiften/ScreenSharing/IncomingScreenSharing.h +++ b/Swiften/ScreenSharing/IncomingScreenSharing.h @@ -30,6 +30,8 @@ namespace Swift { void accept(); + const JID& getSender() const; + public: boost::signal<void (const Image&)> onNewImageReceived; diff --git a/Swiften/ScreenSharing/RTPSessionImpl.cpp b/Swiften/ScreenSharing/RTPSessionImpl.cpp index bbd3d72..922ffa2 100644 --- a/Swiften/ScreenSharing/RTPSessionImpl.cpp +++ b/Swiften/ScreenSharing/RTPSessionImpl.cpp @@ -20,11 +20,20 @@ #include <rtppacket.h> #include <rtpsourcedata.h> #include <rtpsessionparams.h> +#include <rtpipv4address.h> +#include <rtpipv6address.h> + +#include <arpa/inet.h> namespace Swift { Sender::Sender(boost::shared_ptr<UDPSocket> udpSocket) - : udpSocket(udpSocket) { + : udpSocket(udpSocket), jRTPLocalAddress(RTPSessionImpl::nativeAddressToJRTPAddress(udpSocket->getLocalAddress())) { +} + +Sender::~Sender() +{ + delete jRTPLocalAddress; } bool Sender::SendRTP(const void *data, size_t len) { @@ -38,7 +47,7 @@ bool Sender::SendRTCP(const void* data, size_t len) { } bool Sender::ComesFromThisSender (const jrtplib::RTPAddress* address) { - return RTPSessionImpl::nativeAddressToJRTPAddress(udpSocket->getLocalAddress()).IsSameAddress(address); + return jRTPLocalAddress->IsSameAddress(address); } void Sender::send(const void* data, size_t len) { @@ -46,7 +55,7 @@ void Sender::send(const void* data, size_t len) { udpSocket->send(SafeByteArray(uint8Data, uint8Data + len)); } -RTPSessionImpl::RTPSessionImpl(boost::shared_ptr<UDPSocket> udpSocket, const RTPPayloadType &payloadType) +RTPSessionImpl::RTPSessionImpl(boost::shared_ptr<UDPSocket> udpSocket, const RTPPayloadType& payloadType) : udpSocket(udpSocket), payloadType(payloadType), jRTPRemotePeer(nativeAddressToJRTPAddress(udpSocket->getRemoteAddress())), sender(udpSocket) { jrtplib::RTPExternalTransmissionParams transparams(&sender, 0); @@ -64,6 +73,7 @@ RTPSessionImpl::RTPSessionImpl(boost::shared_ptr<UDPSocket> udpSocket, const RTP RTPSessionImpl::~RTPSessionImpl() { + delete jRTPRemotePeer; } void RTPSessionImpl::poll() @@ -74,7 +84,7 @@ void RTPSessionImpl::poll() void RTPSessionImpl::checkIncomingPackets() { // session.BeginDataAccess(); // useless without threading - if (session.GotoFirstSourceWithData() && session.GetCurrentSourceInfo()->GetRTPDataAddress()->IsSameAddress(&jRTPRemotePeer)) { + if (session.GotoFirstSourceWithData() && session.GetCurrentSourceInfo()->GetRTPDataAddress()->IsSameAddress(jRTPRemotePeer)) { do { jrtplib::RTPPacket *pack; while ((pack = session.GetNextPacket()) != NULL) { @@ -94,7 +104,7 @@ void RTPSessionImpl::sendPacket(const SafeByteArray& data, int timestampinc, boo void RTPSessionImpl::injectData(const SafeByteArray& data) { - packetInjecter->InjectRTPorRTCP((void*)(data.data()), data.size(), jRTPRemotePeer); + packetInjecter->InjectRTPorRTCP((void*)(data.data()), data.size(), *jRTPRemotePeer); checkIncomingPackets(); poll(); } @@ -122,18 +132,29 @@ void RTPSessionImpl::handleDataRead(boost::shared_ptr<SafeByteArray> data) injectData(*data); } -jrtplib::RTPIPv4Address RTPSessionImpl::nativeAddressToJRTPAddress(const HostAddressPort& hostAddressPort) +jrtplib::RTPAddress* RTPSessionImpl::nativeAddressToJRTPAddress(const HostAddressPort& hostAddressPort) { - // Split address - std::vector<std::string> subStrings; + jrtplib::RTPAddress* jrtpAddress = 0; std::string ipAddress = hostAddressPort.getAddress().toString(); - boost::algorithm::split(subStrings, ipAddress, boost::is_any_of(".")); - // Cast sub strings array to array of byte - uint8_t ipNumbers[4]; - for (int i = 0; i < std::min(4, (int)subStrings.size()); ++i) - ipNumbers[i] = boost::numeric_cast<uint8_t>(boost::lexical_cast<int>(subStrings[i])); - - return jrtplib::RTPIPv4Address(ipNumbers, boost::numeric_cast<uint16_t>(hostAddressPort.getPort())); + uint16_t port = boost::numeric_cast<uint16_t>(hostAddressPort.getPort()); + + if (hostAddressPort.getAddress().getRawAddress().is_v4()) { + // Split address + std::vector<std::string> subStrings; + boost::algorithm::split(subStrings, ipAddress, boost::is_any_of(".")); + // Cast sub strings array to array of byte + uint8_t ipNumbers[4]; + for (int i = 0; i < std::min(4, (int)subStrings.size()); ++i) + ipNumbers[i] = boost::numeric_cast<uint8_t>(boost::lexical_cast<int>(subStrings[i])); + + jrtpAddress = new jrtplib::RTPIPv4Address(ipNumbers, port); + } + else if (hostAddressPort.getAddress().getRawAddress().is_v6()) { + in6_addr addr; + inet_pton(AF_INET6, ipAddress.c_str(), &addr); + jrtpAddress = new jrtplib::RTPIPv6Address(addr, port); + } + return jrtpAddress; } } diff --git a/Swiften/ScreenSharing/RTPSessionImpl.h b/Swiften/ScreenSharing/RTPSessionImpl.h index 2c6fed2..47af60b 100644 --- a/Swiften/ScreenSharing/RTPSessionImpl.h +++ b/Swiften/ScreenSharing/RTPSessionImpl.h @@ -14,12 +14,13 @@ #include <rtpsession.h> #pragma clang diagnostic pop #include <rtpexternaltransmitter.h> -#include <rtpipv4address.h> +#include <rtpaddress.h> namespace Swift { class Sender : public jrtplib::RTPExternalSender { public: Sender(boost::shared_ptr<UDPSocket> udpSocket); + ~Sender(); virtual bool SendRTP(const void* data, size_t len); virtual bool SendRTCP(const void* data, size_t len); @@ -30,6 +31,7 @@ namespace Swift { private: boost::shared_ptr<UDPSocket> udpSocket; + jrtplib::RTPAddress* jRTPLocalAddress; }; class RTPSessionImpl : public RTPSession { @@ -49,7 +51,7 @@ namespace Swift { virtual size_t getMaxRTPPayloadSize() const; public: - static jrtplib::RTPIPv4Address nativeAddressToJRTPAddress(const HostAddressPort& hostAddressPort); + static jrtplib::RTPAddress* nativeAddressToJRTPAddress(const HostAddressPort& hostAddressPort); private: void checkError(int rtperr) const; @@ -58,7 +60,7 @@ namespace Swift { private: boost::shared_ptr<UDPSocket> udpSocket; RTPPayloadType payloadType; - jrtplib::RTPIPv4Address jRTPRemotePeer; + jrtplib::RTPAddress* jRTPRemotePeer; Sender sender; jrtplib::RTPSession session; jrtplib::RTPExternalPacketInjecter *packetInjecter; diff --git a/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp b/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp index a747b81..b0e337a 100644 --- a/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp +++ b/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp @@ -56,7 +56,8 @@ boost::optional<JID> ScreenSharingManagerImpl::highestPriorityJIDSupportingScree DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom()); // look up caps from the jid if (info && info->hasFeature(DiscoInfo::JingleFeature) && info->hasFeature(DiscoInfo::JingleRTPFeature) - && info->hasFeature(DiscoInfo::JingleTransportRawUDPFeature)) { + && info->hasFeature(DiscoInfo::JingleTransportRawUDPFeature) + && info->hasFeature(DiscoInfo::JingleScreenSharingFeature)) { priority = pres->getPriority(); fullRecipientJID = pres->getFrom(); } |