From a0c7381047e408c76c1921f34ba46a10901137c3 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 28 Feb 2018 01:37:47 +0100 Subject: [PATCH] qrtplib: implemented Qt style RTP address object --- qrtplib/CMakeLists.txt | 1 + qrtplib/rtpaddress.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ qrtplib/rtpaddress.h | 68 ++++++++++++++++++++++++----------- qrtplib/rtpsession.cpp | 36 ++++++++++--------- 4 files changed, 147 insertions(+), 38 deletions(-) create mode 100644 qrtplib/rtpaddress.cpp diff --git a/qrtplib/CMakeLists.txt b/qrtplib/CMakeLists.txt index b9e1f9a39..38e1502f2 100644 --- a/qrtplib/CMakeLists.txt +++ b/qrtplib/CMakeLists.txt @@ -63,6 +63,7 @@ set(qrtplib_SOURCES rtcpsdesinfo.cpp rtcpsdespacket.cpp rtcpsrpacket.cpp + rtpaddress.cpp rtpcollisionlist.cpp rtperrors.cpp rtpinternalsourcedata.cpp diff --git a/qrtplib/rtpaddress.cpp b/qrtplib/rtpaddress.cpp new file mode 100644 index 000000000..4fe56a96b --- /dev/null +++ b/qrtplib/rtpaddress.cpp @@ -0,0 +1,80 @@ +/* + + This file is a part of JRTPLIB + Copyright (c) 1999-2017 Jori Liesenborgs + + Contact: jori.liesenborgs@gmail.com + + This library was developed at the Expertise Centre for Digital Media + (http://www.edm.uhasselt.be), a research center of the Hasselt University + (http://www.uhasselt.be). The library is based upon work done for + my thesis at the School for Knowledge Technology (Belgium/The Netherlands). + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + */ + +#include "rtpaddress.h" + +namespace qrtplib +{ + +RTPAddress *RTPAddress::CreateCopy() const +{ + RTPAddress *a = new RTPAddress(); + a->address = address; + a->port = port; + a->rtcpsendport = rtcpsendport; + return a; +} + +bool RTPAddress::IsSameAddress(const RTPAddress *addr) const +{ + if (addr == 0) { + return false; + } + + if (addr->address.protocol() != address.protocol()) { + return false; + } + + if (addr->address == address) + { + return addr->port == port; + } + else + { + return false; + } +} + +bool RTPAddress::IsFromSameHost(const RTPAddress *addr) const +{ + if (addr == 0) { + return false; + } + + if (addr->address.protocol() != address.protocol()) { + return false; + } + + return addr->address == address; +} + +} // namespace diff --git a/qrtplib/rtpaddress.h b/qrtplib/rtpaddress.h index e9d9d9f9d..68f07bd80 100644 --- a/qrtplib/rtpaddress.h +++ b/qrtplib/rtpaddress.h @@ -40,6 +40,8 @@ #include "rtpconfig.h" #include +#include +#include namespace qrtplib { @@ -48,20 +50,10 @@ namespace qrtplib class RTPAddress { public: - /** Identifies the actual implementation being used. */ - enum AddressType - { - IPv4Address, /**< Used by the UDP over IPv4 transmitter. */ - IPv6Address, /**< Used by the UDP over IPv6 transmitter. */ - ByteAddress, /**< A very general type of address, consisting of a port number and a number of bytes representing the host address. */ - UserDefinedAddress, /**< Can be useful for a user-defined transmitter. */ - TCPAddress /**< Used by the TCP transmitter. */ - }; - /** Returns the type of address the actual implementation represents. */ - AddressType GetAddressType() const + QAbstractSocket::NetworkLayerProtocol GetAddressType() const { - return addresstype; + return address.protocol(); } /** Creates a copy of the RTPAddress instance. @@ -69,31 +61,65 @@ public: * corresponding memory manager will be used to allocate the memory for the address * copy. */ - virtual RTPAddress *CreateCopy() const = 0; + RTPAddress *CreateCopy() const; /** Checks if the address \c addr is the same address as the one this instance represents. * Checks if the address \c addr is the same address as the one this instance represents. * Implementations must be able to handle a NULL argument. + * + * Note that this function is only used for received packets, and for those + * the rtcpsendport variable is not important and should be ignored. */ - virtual bool IsSameAddress(const RTPAddress *addr) const = 0; + bool IsSameAddress(const RTPAddress *addr) const; /** Checks if the address \c addr represents the same host as this instance. * Checks if the address \c addr represents the same host as this instance. Implementations * must be able to handle a NULL argument. + * + * Note that this function is only used for received packets. */ - virtual bool IsFromSameHost(const RTPAddress *addr) const = 0; + bool IsFromSameHost(const RTPAddress *addr) const; - virtual ~RTPAddress() + /** Get host address */ + const QHostAddress& getAddress() const { + return address; } -protected: - // only allow subclasses to be created - RTPAddress(const AddressType t) : - addresstype(t) + + /** Set host address */ + void setAddress(const QHostAddress& address) { + this->address = address; } + + /** Get RTP port */ + uint16_t getPort() const + { + return port; + } + + /** Set RTP port */ + void setPort(uint16_t port) + { + this->port = port; + } + + /** Get RTCP port */ + uint16_t getRtcpsendport() const + { + return rtcpsendport; + } + + /** Set RTCP port */ + void setRtcpsendport(uint16_t rtcpsendport) + { + this->rtcpsendport = rtcpsendport; + } + private: - const AddressType addresstype; + QHostAddress address; + uint16_t port; + uint16_t rtcpsendport; }; } // end namespace diff --git a/qrtplib/rtpsession.cpp b/qrtplib/rtpsession.cpp index 7f4522331..e0bc3d222 100644 --- a/qrtplib/rtpsession.cpp +++ b/qrtplib/rtpsession.cpp @@ -32,9 +32,10 @@ #include "rtpsession.h" #include "rtperrors.h" -#include "rtpudpv4transmitter.h" -#include "rtptcptransmitter.h" -#include "rtpexternaltransmitter.h" +// TODO: this is for Create with transmitter creation. See if we keep it. +//#include "rtpudpv4transmitter.h" +//#include "rtptcptransmitter.h" +//#include "rtpexternaltransmitter.h" #include "rtpsessionparams.h" #include "rtpdefines.h" #include "rtprawpacket.h" @@ -113,20 +114,21 @@ int RTPSession::Create(const RTPSessionParams &sessparams, const RTPTransmission rtptrans = 0; switch (protocol) { - case RTPTransmitter::IPv4UDPProto: - rtptrans = new RTPUDPv4Transmitter(); - break; - case RTPTransmitter::ExternalProto: - rtptrans = new RTPExternalTransmitter(); - break; - case RTPTransmitter::UserDefinedProto: - rtptrans = NewUserDefinedTransmitter(); - if (rtptrans == 0) - return ERR_RTP_SESSION_USERDEFINEDTRANSMITTERNULL; - break; - case RTPTransmitter::TCPProto: - rtptrans = new RTPTCPTransmitter(); - break; + // TODO: see if we keep this Create method or use the one with the transmitter specified +// case RTPTransmitter::IPv4UDPProto: +// rtptrans = new RTPUDPv4Transmitter(); +// break; +// case RTPTransmitter::ExternalProto: +// rtptrans = new RTPExternalTransmitter(); +// break; +// case RTPTransmitter::UserDefinedProto: +// rtptrans = NewUserDefinedTransmitter(); +// if (rtptrans == 0) +// return ERR_RTP_SESSION_USERDEFINEDTRANSMITTERNULL; +// break; +// case RTPTransmitter::TCPProto: +// rtptrans = new RTPTCPTransmitter(); +// break; default: return ERR_RTP_SESSION_UNSUPPORTEDTRANSMISSIONPROTOCOL; }