2018-02-26 19:35:16 -05:00
|
|
|
/*
|
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
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.
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
*/
|
2018-02-26 19:35:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file rtpexternaltransmitter.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RTPEXTERNALTRANSMITTER_H
|
|
|
|
|
|
|
|
#define RTPEXTERNALTRANSMITTER_H
|
|
|
|
|
|
|
|
#include "rtpconfig.h"
|
|
|
|
#include "rtptransmitter.h"
|
|
|
|
#include "rtpabortdescriptors.h"
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace qrtplib
|
|
|
|
{
|
|
|
|
|
|
|
|
class RTPExternalTransmitter;
|
|
|
|
|
|
|
|
/** Base class to specify a mechanism to transmit RTP packets outside of this library.
|
|
|
|
* Base class to specify a mechanism to transmit RTP packets outside of this library. When
|
|
|
|
* you want to use your own mechanism to transmit RTP packets, you need to specify that
|
|
|
|
* you'll be using the external transmission component, and derive a class from this base
|
|
|
|
* class. An instance should then be specified in the RTPExternalTransmissionParams object,
|
|
|
|
* so that the transmitter will call the \c SendRTP, \c SendRTCP and \c ComesFromThisSender
|
|
|
|
* methods of this instance when needed.
|
|
|
|
*/
|
2018-02-27 17:26:03 -05:00
|
|
|
class RTPExternalSender
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalSender()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~RTPExternalSender()
|
|
|
|
{
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
/** This member function will be called when RTP data needs to be transmitted. */
|
2018-02-28 07:31:44 -05:00
|
|
|
virtual bool SendRTP(const void *data, std::size_t len) = 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
/** This member function will be called when an RTCP packet needs to be transmitted. */
|
2018-02-28 07:31:44 -05:00
|
|
|
virtual bool SendRTCP(const void *data, std::size_t len) = 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
/** Used to identify if an RTPAddress instance originated from this sender (to be able to detect own packets). */
|
|
|
|
virtual bool ComesFromThisSender(const RTPAddress *a) = 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Interface to inject incoming RTP and RTCP packets into the library.
|
|
|
|
* Interface to inject incoming RTP and RTCP packets into the library. When you have your own
|
|
|
|
* mechanism to receive incoming RTP/RTCP data, you'll need to pass these packets to the library.
|
|
|
|
* By first retrieving the RTPExternalTransmissionInfo instance for the external transmitter you'll
|
|
|
|
* be using, you can obtain the associated RTPExternalPacketInjecter instance. By calling it's
|
|
|
|
* member functions, you can then inject RTP or RTCP data into the library for further processing.
|
|
|
|
*/
|
2018-02-27 17:26:03 -05:00
|
|
|
class RTPExternalPacketInjecter
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalPacketInjecter(RTPExternalTransmitter *trans)
|
|
|
|
{
|
|
|
|
transmitter = trans;
|
|
|
|
}
|
|
|
|
~RTPExternalPacketInjecter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This function can be called to insert an RTP packet into the transmission component. */
|
2018-02-28 07:31:44 -05:00
|
|
|
void InjectRTP(const void *data, std::size_t len, const RTPAddress &a);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
|
|
|
/** This function can be called to insert an RTCP packet into the transmission component. */
|
2018-02-28 07:31:44 -05:00
|
|
|
void InjectRTCP(const void *data, std::size_t len, const RTPAddress &a);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
|
|
|
/** Use this function to inject an RTP or RTCP packet and the transmitter will try to figure out which type of packet it is. */
|
2018-02-28 07:31:44 -05:00
|
|
|
void InjectRTPorRTCP(const void *data, std::size_t len, const RTPAddress &a);
|
2018-02-26 19:35:16 -05:00
|
|
|
private:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalTransmitter *transmitter;
|
2018-02-26 19:35:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Parameters to initialize a transmitter of type RTPExternalTransmitter. */
|
2018-02-27 17:26:03 -05:00
|
|
|
class RTPExternalTransmissionParams: public RTPTransmissionParams
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-02-27 17:05:46 -05:00
|
|
|
/** Using this constructor you can specify which RTPExternalSender object you'll be using
|
|
|
|
* and how much the additional header overhead for each packet will be. */
|
|
|
|
RTPExternalTransmissionParams(RTPExternalSender *s, int headeroverhead) :
|
|
|
|
RTPTransmissionParams(RTPTransmitter::ExternalProto)
|
|
|
|
{
|
|
|
|
sender = s;
|
|
|
|
headersize = headeroverhead;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTPExternalSender *GetSender() const
|
|
|
|
{
|
|
|
|
return sender;
|
|
|
|
}
|
|
|
|
int GetAdditionalHeaderSize() const
|
|
|
|
{
|
|
|
|
return headersize;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
private:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalSender *sender;
|
|
|
|
int headersize;
|
2018-02-26 19:35:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Additional information about the external transmission component. */
|
2018-02-27 17:26:03 -05:00
|
|
|
class RTPExternalTransmissionInfo: public RTPTransmissionInfo
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalTransmissionInfo(RTPExternalPacketInjecter *p) :
|
|
|
|
RTPTransmissionInfo(RTPTransmitter::ExternalProto)
|
|
|
|
{
|
|
|
|
packetinjector = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Tells you which RTPExternalPacketInjecter you need to use to pass RTP or RTCP
|
|
|
|
* data on to the transmission component. */
|
|
|
|
RTPExternalPacketInjecter *GetPacketInjector() const
|
|
|
|
{
|
|
|
|
return packetinjector;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
private:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalPacketInjecter *packetinjector;
|
2018-02-26 19:35:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A transmission component which will use user specified functions to transmit the data and
|
|
|
|
* which will expose functions to inject received RTP or RTCP data into this component.
|
|
|
|
* A transmission component which will use user specified functions to transmit the data and
|
|
|
|
* which will expose functions to inject received RTP or RTCP data into this component. Use
|
|
|
|
* a class derived from RTPExternalSender to specify the functions which need to be used for
|
|
|
|
* sending the data. Obtain the RTPExternalTransmissionInfo object associated with this
|
|
|
|
* transmitter to obtain the functions needed to pass RTP/RTCP packets on to the transmitter.
|
|
|
|
*/
|
2018-02-27 17:26:03 -05:00
|
|
|
class RTPExternalTransmitter: public RTPTransmitter
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalTransmitter();
|
|
|
|
~RTPExternalTransmitter();
|
|
|
|
|
|
|
|
int Init(bool treadsafe);
|
2018-02-28 07:31:44 -05:00
|
|
|
int Create(std::size_t maxpacksize, const RTPTransmissionParams *transparams);
|
2018-02-27 17:05:46 -05:00
|
|
|
void Destroy();
|
|
|
|
RTPTransmissionInfo *GetTransmissionInfo();
|
|
|
|
void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int GetLocalHostName(uint8_t *buffer, std::size_t *bufferlength);
|
2018-02-27 17:05:46 -05:00
|
|
|
bool ComesFromThisTransmitter(const RTPAddress *addr);
|
2018-02-28 07:31:44 -05:00
|
|
|
std::size_t GetHeaderOverhead()
|
2018-02-27 17:05:46 -05:00
|
|
|
{
|
|
|
|
return headersize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Poll();
|
|
|
|
int WaitForIncomingData(const RTPTime &delay, bool *dataavailable = 0);
|
|
|
|
int AbortWait();
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int SendRTPData(const void *data, std::size_t len);
|
|
|
|
int SendRTCPData(const void *data, std::size_t len);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
|
|
|
int AddDestination(const RTPAddress &addr);
|
|
|
|
int DeleteDestination(const RTPAddress &addr);
|
|
|
|
void ClearDestinations();
|
|
|
|
|
|
|
|
bool SupportsMulticasting();
|
|
|
|
int JoinMulticastGroup(const RTPAddress &addr);
|
|
|
|
int LeaveMulticastGroup(const RTPAddress &addr);
|
|
|
|
void LeaveAllMulticastGroups();
|
|
|
|
|
|
|
|
int SetReceiveMode(RTPTransmitter::ReceiveMode m);
|
|
|
|
int AddToIgnoreList(const RTPAddress &addr);
|
|
|
|
int DeleteFromIgnoreList(const RTPAddress &addr);
|
|
|
|
void ClearIgnoreList();
|
|
|
|
int AddToAcceptList(const RTPAddress &addr);
|
|
|
|
int DeleteFromAcceptList(const RTPAddress &addr);
|
|
|
|
void ClearAcceptList();
|
2018-02-28 07:31:44 -05:00
|
|
|
int SetMaximumPacketSize(std::size_t s);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
|
|
|
bool NewDataAvailable();
|
|
|
|
RTPRawPacket *GetNextPacket();
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
void InjectRTP(const void *data, std::size_t len, const RTPAddress &a);
|
|
|
|
void InjectRTCP(const void *data, std::size_t len, const RTPAddress &a);
|
|
|
|
void InjectRTPorRTCP(const void *data, std::size_t len, const RTPAddress &a);
|
2018-02-26 19:35:16 -05:00
|
|
|
private:
|
2018-02-27 17:05:46 -05:00
|
|
|
void FlushPackets();
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
bool init;
|
|
|
|
bool created;
|
|
|
|
bool waitingfordata;
|
|
|
|
RTPExternalSender *sender;
|
|
|
|
RTPExternalPacketInjecter packetinjector;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
std::list<RTPRawPacket*> rawpacketlist;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
uint8_t *localhostname;
|
2018-02-28 07:31:44 -05:00
|
|
|
std::size_t localhostnamelength;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
std::size_t maxpacksize;
|
2018-02-27 17:05:46 -05:00
|
|
|
int headersize;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPAbortDescriptors m_abortDesc;
|
|
|
|
int m_abortCount;
|
2018-02-26 19:35:16 -05:00
|
|
|
};
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
inline void RTPExternalPacketInjecter::InjectRTP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
transmitter->InjectRTP(data, len, a);
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
inline void RTPExternalPacketInjecter::InjectRTCP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
transmitter->InjectRTCP(data, len, a);
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
inline void RTPExternalPacketInjecter::InjectRTPorRTCP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
transmitter->InjectRTPorRTCP(data, len, a);
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
#endif // RTPTCPSOCKETTRANSMITTER_H
|
|
|
|
|