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
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
Contact: jori.liesenborgs@gmail.com
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
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).
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
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:
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
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
|
|
|
|
|
|
|
#include "rtpexternaltransmitter.h"
|
|
|
|
#include "rtprawpacket.h"
|
|
|
|
#include "rtptimeutilities.h"
|
|
|
|
#include "rtpdefines.h"
|
|
|
|
#include "rtperrors.h"
|
|
|
|
#include "rtpsocketutilinternal.h"
|
|
|
|
#include "rtpselect.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace qrtplib
|
|
|
|
{
|
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
RTPExternalTransmitter::RTPExternalTransmitter() :
|
|
|
|
packetinjector((RTPExternalTransmitter *) this)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
created = false;
|
|
|
|
init = false;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTPExternalTransmitter::~RTPExternalTransmitter()
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
Destroy();
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::Init(bool tsafe)
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
if (init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_ALREADYINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
if (tsafe)
|
|
|
|
return ERR_RTP_NOTHREADSUPPORT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
init = true;
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int RTPExternalTransmitter::Create(std::size_t maximumpacketsize, const RTPTransmissionParams *transparams)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
const RTPExternalTransmissionParams *params;
|
|
|
|
int status;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
if (created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_ALREADYCREATED;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
// Obtain transmission parameters
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
if (transparams == 0)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_ILLEGALPARAMETERS;
|
|
|
|
}
|
|
|
|
if (transparams->GetTransmissionProtocol() != RTPTransmitter::ExternalProto)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_ILLEGALPARAMETERS;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
params = (const RTPExternalTransmissionParams *) transparams;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
if ((status = m_abortDesc.Init()) < 0)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
m_abortCount = 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
maxpacksize = maximumpacketsize;
|
|
|
|
sender = params->GetSender();
|
|
|
|
headersize = params->GetAdditionalHeaderSize();
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
localhostname = 0;
|
|
|
|
localhostnamelength = 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 17:05:46 -05:00
|
|
|
waitingfordata = false;
|
|
|
|
created = true;
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::Destroy()
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
if (!init)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localhostname)
|
|
|
|
{
|
|
|
|
delete[] localhostname;
|
|
|
|
localhostname = 0;
|
|
|
|
localhostnamelength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlushPackets();
|
|
|
|
created = false;
|
|
|
|
|
|
|
|
if (waitingfordata)
|
|
|
|
{
|
|
|
|
m_abortDesc.SendAbortSignal();
|
|
|
|
m_abortCount++;
|
|
|
|
m_abortDesc.Destroy();
|
2018-02-27 18:19:19 -05:00
|
|
|
// to make sure that the WaitForIncomingData function ended
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_abortDesc.Destroy();
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTPTransmissionInfo *RTPExternalTransmitter::GetTransmissionInfo()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPTransmissionInfo *tinf = new RTPExternalTransmissionInfo(&packetinjector);
|
|
|
|
return tinf;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::DeleteTransmissionInfo(RTPTransmissionInfo *i)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
delete i;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int RTPExternalTransmitter::GetLocalHostName(uint8_t *buffer, std::size_t *bufferlength)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (localhostname == 0)
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
// We'll just use 'gethostname' for simplicity
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
char name[1024];
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (gethostname(name, 1023) != 0)
|
|
|
|
strcpy(name, "localhost"); // failsafe
|
|
|
|
else
|
|
|
|
name[1023] = 0; // ensure null-termination
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
localhostnamelength = strlen(name);
|
|
|
|
localhostname = new uint8_t[localhostnamelength + 1];
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
memcpy(localhostname, name, localhostnamelength);
|
|
|
|
localhostname[localhostnamelength] = 0;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if ((*bufferlength) < localhostnamelength)
|
|
|
|
{
|
|
|
|
*bufferlength = localhostnamelength; // tell the application the required size of the buffer
|
|
|
|
return ERR_RTP_TRANS_BUFFERLENGTHTOOSMALL;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
memcpy(buffer, localhostname, localhostnamelength);
|
|
|
|
*bufferlength = localhostnamelength;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTPExternalTransmitter::ComesFromThisTransmitter(const RTPAddress *addr)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
|
|
|
|
bool value = false;
|
|
|
|
if (sender)
|
|
|
|
value = sender->ComesFromThisSender(addr);
|
|
|
|
return value;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::Poll()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-27 17:05:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::WaitForIncomingData(const RTPTime &delay, bool *dataavailable)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
if (waitingfordata)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_ALREADYWAITING;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
waitingfordata = true;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!rawpacketlist.empty())
|
|
|
|
{
|
|
|
|
if (dataavailable != 0)
|
|
|
|
*dataavailable = true;
|
|
|
|
waitingfordata = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
int8_t isset = 0;
|
|
|
|
SocketType abortSock = m_abortDesc.GetAbortSocket();
|
|
|
|
int status = RTPSelect(&abortSock, &isset, 1, delay);
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
waitingfordata = false;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return status;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
waitingfordata = false;
|
|
|
|
if (!created) // destroy called
|
|
|
|
{
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
// if aborted, read from abort buffer
|
|
|
|
if (isset)
|
|
|
|
{
|
|
|
|
m_abortDesc.ClearAbortSignal();
|
|
|
|
m_abortCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataavailable != 0)
|
|
|
|
{
|
|
|
|
if (rawpacketlist.empty())
|
|
|
|
*dataavailable = false;
|
|
|
|
else
|
|
|
|
*dataavailable = true;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::AbortWait()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
if (!waitingfordata)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTWAITING;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
m_abortDesc.SendAbortSignal();
|
|
|
|
m_abortCount++;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int RTPExternalTransmitter::SendRTPData(const void *data, std::size_t len)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
if (len > maxpacksize)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_SPECIFIEDSIZETOOBIG;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!sender)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOSENDER;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!sender->SendRTP(data, len))
|
|
|
|
return ERR_RTP_EXTERNALTRANS_SENDERROR;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int RTPExternalTransmitter::SendRTCPData(const void *data, std::size_t len)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
if (len > maxpacksize)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_SPECIFIEDSIZETOOBIG;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!sender)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOSENDER;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!sender->SendRTCP(data, len))
|
|
|
|
return ERR_RTP_EXTERNALTRANS_SENDERROR;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::AddDestination(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NODESTINATIONSSUPPORTED;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::DeleteDestination(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NODESTINATIONSSUPPORTED;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::ClearDestinations()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTPExternalTransmitter::SupportsMulticasting()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return false;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::JoinMulticastGroup(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOMULTICASTSUPPORT;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::LeaveMulticastGroup(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOMULTICASTSUPPORT;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::LeaveAllMulticastGroups()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::SetReceiveMode(RTPTransmitter::ReceiveMode m)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
if (m != RTPTransmitter::AcceptAll)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_BADRECEIVEMODE;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::AddToIgnoreList(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOIGNORELIST;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::DeleteFromIgnoreList(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOIGNORELIST;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::ClearIgnoreList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::AddToAcceptList(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOACCEPTLIST;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int RTPExternalTransmitter::DeleteFromAcceptList(const RTPAddress &)
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
return ERR_RTP_EXTERNALTRANS_NOACCEPTLIST;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::ClearAcceptList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
int RTPExternalTransmitter::SetMaximumPacketSize(std::size_t s)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTINIT;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return ERR_RTP_EXTERNALTRANS_NOTCREATED;
|
|
|
|
}
|
|
|
|
maxpacksize = s;
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTPExternalTransmitter::NewDataAvailable()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return false;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
bool v;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
v = false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rawpacketlist.empty())
|
|
|
|
v = false;
|
|
|
|
else
|
|
|
|
v = true;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return v;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTPRawPacket *RTPExternalTransmitter::GetNextPacket()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return 0;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPRawPacket *p;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (rawpacketlist.empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
p = *(rawpacketlist.begin());
|
|
|
|
rawpacketlist.pop_front();
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
return p;
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Here the private functions start...
|
|
|
|
|
|
|
|
void RTPExternalTransmitter::FlushPackets()
|
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
std::list<RTPRawPacket*>::const_iterator it;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
for (it = rawpacketlist.begin(); it != rawpacketlist.end(); ++it)
|
|
|
|
delete *it;
|
|
|
|
rawpacketlist.clear();
|
2018-02-26 19:35:16 -05:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
void RTPExternalTransmitter::InjectRTP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPAddress *addr = a.CreateCopy();
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
uint8_t *datacopy;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
datacopy = new uint8_t[len];
|
|
|
|
if (datacopy == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(datacopy, data, len);
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPTime curtime = RTPTime::CurrentTime();
|
|
|
|
RTPRawPacket *pack;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
pack = new RTPRawPacket(datacopy, len, addr, curtime, true);
|
|
|
|
if (pack == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
delete[] localhostname;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rawpacketlist.push_back(pack);
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (m_abortCount == 0)
|
|
|
|
{
|
|
|
|
m_abortDesc.SendAbortSignal();
|
|
|
|
m_abortCount++;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
void RTPExternalTransmitter::InjectRTCP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPAddress *addr = a.CreateCopy();
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
uint8_t *datacopy;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
datacopy = new uint8_t[len];
|
|
|
|
if (datacopy == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(datacopy, data, len);
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPTime curtime = RTPTime::CurrentTime();
|
|
|
|
RTPRawPacket *pack;
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
pack = new RTPRawPacket(datacopy, len, addr, curtime, false);
|
|
|
|
if (pack == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
delete[] localhostname;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rawpacketlist.push_back(pack);
|
2018-02-26 19:35:16 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (m_abortCount == 0)
|
|
|
|
{
|
|
|
|
m_abortDesc.SendAbortSignal();
|
|
|
|
m_abortCount++;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-28 07:31:44 -05:00
|
|
|
void RTPExternalTransmitter::InjectRTPorRTCP(const void *data, std::size_t len, const RTPAddress &a)
|
2018-02-26 19:35:16 -05:00
|
|
|
{
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!init)
|
|
|
|
return;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (!created)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPAddress *addr = a.CreateCopy();
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
uint8_t *datacopy;
|
|
|
|
bool rtp = true;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (len >= 2)
|
|
|
|
{
|
|
|
|
const uint8_t *pData = (const uint8_t *) data;
|
|
|
|
if (pData[1] >= 200 && pData[1] <= 204)
|
|
|
|
rtp = false;
|
|
|
|
}
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
datacopy = new uint8_t[len];
|
|
|
|
if (datacopy == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(datacopy, data, len);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
RTPTime curtime = RTPTime::CurrentTime();
|
|
|
|
RTPRawPacket *pack;
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
pack = new RTPRawPacket(datacopy, len, addr, curtime, rtp);
|
|
|
|
if (pack == 0)
|
|
|
|
{
|
|
|
|
delete addr;
|
|
|
|
delete[] localhostname;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rawpacketlist.push_back(pack);
|
2018-02-27 17:05:46 -05:00
|
|
|
|
2018-02-27 18:19:19 -05:00
|
|
|
if (m_abortCount == 0)
|
|
|
|
{
|
|
|
|
m_abortDesc.SendAbortSignal();
|
|
|
|
m_abortCount++;
|
|
|
|
}
|
2018-02-26 19:35:16 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|