Refactored ViEReceiver.
git-svn-id: http://webrtc.googlecode.com/svn/trunk@1043 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
9d8bec6f76
commit
ad4ee3659e
@ -8,525 +8,262 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ViEChannel.cpp
|
||||
*/
|
||||
|
||||
#include "vie_receiver.h"
|
||||
|
||||
#include "critical_section_wrapper.h"
|
||||
#include "rtp_rtcp.h"
|
||||
#ifdef WEBRTC_SRTP
|
||||
#include "SrtpModule.h"
|
||||
#endif
|
||||
#include "video_coding.h"
|
||||
#include "rtp_dump.h"
|
||||
#include "rtp_rtcp.h"
|
||||
#include "video_coding.h"
|
||||
#include "trace.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ViEReceiver::ViEReceiver(int engineId, int channelId,
|
||||
RtpRtcp& moduleRtpRtcp,
|
||||
VideoCodingModule& moduleVcm)
|
||||
: _receiveCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||
_engineId(engineId),
|
||||
_channelId(channelId),
|
||||
_rtpRtcp(moduleRtpRtcp),
|
||||
_vcm(moduleVcm),
|
||||
#ifdef WEBRTC_SRTP
|
||||
_ptrSrtp(NULL),
|
||||
_ptrSrtcp(NULL),
|
||||
_ptrSrtpBuffer(NULL),
|
||||
_ptrSrtcpBuffer(NULL),
|
||||
#endif
|
||||
_ptrExternalDecryption(NULL), _ptrDecryptionBuffer(NULL),
|
||||
_rtpDump(NULL), _receiving(false)
|
||||
{
|
||||
ViEReceiver::ViEReceiver(int engine_id, int channel_id,
|
||||
RtpRtcp& rtp_rtcp,
|
||||
VideoCodingModule& module_vcm)
|
||||
: receive_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||
engine_id_(engine_id),
|
||||
channel_id_(channel_id),
|
||||
rtp_rtcp_(rtp_rtcp),
|
||||
vcm_(module_vcm),
|
||||
external_decryption_(NULL),
|
||||
decryption_buffer_(NULL),
|
||||
rtp_dump_(NULL),
|
||||
receiving_(false) {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
// ----------------------------------------------------------------------------
|
||||
ViEReceiver::~ViEReceiver() {
|
||||
delete &receive_critsect_;
|
||||
|
||||
ViEReceiver::~ViEReceiver()
|
||||
{
|
||||
delete &_receiveCritsect;
|
||||
#ifdef WEBRTC_SRTP
|
||||
if (_ptrSrtpBuffer)
|
||||
{
|
||||
delete [] _ptrSrtpBuffer;
|
||||
_ptrSrtpBuffer = NULL;
|
||||
if (decryption_buffer_) {
|
||||
delete[] decryption_buffer_;
|
||||
decryption_buffer_ = NULL;
|
||||
}
|
||||
if (_ptrSrtcpBuffer)
|
||||
{
|
||||
delete [] _ptrSrtcpBuffer;
|
||||
_ptrSrtcpBuffer = NULL;
|
||||
}
|
||||
#endif
|
||||
if (_ptrDecryptionBuffer)
|
||||
{
|
||||
delete[] _ptrDecryptionBuffer;
|
||||
_ptrDecryptionBuffer = NULL;
|
||||
}
|
||||
if (_rtpDump)
|
||||
{
|
||||
_rtpDump->Stop();
|
||||
RtpDump::DestroyRtpDump(_rtpDump);
|
||||
_rtpDump = NULL;
|
||||
if (rtp_dump_) {
|
||||
rtp_dump_->Stop();
|
||||
RtpDump::DestroyRtpDump(rtp_dump_);
|
||||
rtp_dump_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Decryption
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RegisterExternalDecryption
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::RegisterExternalDecryption(Encryption* decryption)
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrExternalDecryption)
|
||||
{
|
||||
int ViEReceiver::RegisterExternalDecryption(Encryption* decryption) {
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
if (external_decryption_) {
|
||||
return -1;
|
||||
}
|
||||
_ptrDecryptionBuffer = new WebRtc_UWord8[kViEMaxMtu];
|
||||
if (_ptrDecryptionBuffer == NULL)
|
||||
{
|
||||
decryption_buffer_ = new WebRtc_UWord8[kViEMaxMtu];
|
||||
if (decryption_buffer_ == NULL) {
|
||||
return -1;
|
||||
}
|
||||
_ptrExternalDecryption = decryption;
|
||||
external_decryption_ = decryption;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DeregisterExternalDecryption
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::DeregisterExternalDecryption()
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrExternalDecryption == NULL)
|
||||
{
|
||||
int ViEReceiver::DeregisterExternalDecryption() {
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
if (external_decryption_ == NULL) {
|
||||
return -1;
|
||||
}
|
||||
_ptrExternalDecryption = NULL;
|
||||
external_decryption_ = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ViEReceiver::RegisterSimulcastRtpRtcpModules(
|
||||
const std::list<RtpRtcp*>& rtpModules)
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
_rtpRtcpSimulcast.clear();
|
||||
if (!rtpModules.empty())
|
||||
{
|
||||
_rtpRtcpSimulcast.insert(_rtpRtcpSimulcast.begin(),
|
||||
rtpModules.begin(),
|
||||
rtpModules.end());
|
||||
const std::list<RtpRtcp*>& rtp_modules) {
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
rtp_rtcp_simulcast_.clear();
|
||||
|
||||
if (!rtp_modules.empty()) {
|
||||
rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
|
||||
rtp_modules.begin(),
|
||||
rtp_modules.end());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WEBRTC_SRTP
|
||||
// ----------------------------------------------------------------------------
|
||||
// RegisterSRTPModule
|
||||
// ----------------------------------------------------------------------------
|
||||
void ViEReceiver::IncomingRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||
const WebRtc_Word32 rtp_packet_length,
|
||||
const WebRtc_Word8* from_ip,
|
||||
const WebRtc_UWord16 from_port) {
|
||||
InsertRTPPacket(rtp_packet, rtp_packet_length);
|
||||
}
|
||||
|
||||
int ViEReceiver::RegisterSRTPModule(SrtpModule* srtpModule)
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrSrtp ||
|
||||
srtpModule == NULL)
|
||||
{
|
||||
void ViEReceiver::IncomingRTCPPacket(const WebRtc_Word8* rtcp_packet,
|
||||
const WebRtc_Word32 rtcp_packet_length,
|
||||
const WebRtc_Word8* from_ip,
|
||||
const WebRtc_UWord16 from_port) {
|
||||
InsertRTCPPacket(rtcp_packet, rtcp_packet_length);
|
||||
}
|
||||
|
||||
int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
|
||||
int rtp_packet_length) {
|
||||
if (!receiving_) {
|
||||
return -1;
|
||||
}
|
||||
_ptrSrtpBuffer = new WebRtc_UWord8[kViEMaxMtu];
|
||||
if (_ptrSrtpBuffer == NULL)
|
||||
{
|
||||
return InsertRTPPacket((const WebRtc_Word8*) rtp_packet, rtp_packet_length);
|
||||
}
|
||||
|
||||
int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
|
||||
int rtcp_packet_length) {
|
||||
if (!receiving_) {
|
||||
return -1;
|
||||
}
|
||||
_ptrSrtp = srtpModule;
|
||||
return InsertRTCPPacket((const WebRtc_Word8*) rtcp_packet,
|
||||
rtcp_packet_length);
|
||||
}
|
||||
|
||||
WebRtc_Word32 ViEReceiver::OnReceivedPayloadData(
|
||||
const WebRtc_UWord8* payload_data, const WebRtc_UWord16 payload_size,
|
||||
const WebRtcRTPHeader* rtp_header) {
|
||||
if (rtp_header == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DeregisterSRTPModule
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::DeregisterSRTPModule()
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrSrtp == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_ptrSrtpBuffer)
|
||||
{
|
||||
delete [] _ptrSrtpBuffer;
|
||||
_ptrSrtpBuffer = NULL;
|
||||
}
|
||||
_ptrSrtp = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RegisterSRTCPModule
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::RegisterSRTCPModule(SrtpModule* srtcpModule)
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrSrtcp ||
|
||||
srtcpModule == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
_ptrSrtcpBuffer = new WebRtc_UWord8[kViEMaxMtu];
|
||||
if (_ptrSrtcpBuffer == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
_ptrSrtcp = srtcpModule;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DeregisterSRTPCModule
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::DeregisterSRTCPModule()
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_ptrSrtcp == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_ptrSrtcpBuffer)
|
||||
{
|
||||
delete [] _ptrSrtcpBuffer;
|
||||
_ptrSrtcpBuffer = NULL;
|
||||
}
|
||||
_ptrSrtcp = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IncomingRTPPacket
|
||||
//
|
||||
// Receives RTP packets from SocketTransport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ViEReceiver::IncomingRTPPacket(const WebRtc_Word8* incomingRtpPacket,
|
||||
const WebRtc_Word32 incomingRtpPacketLength,
|
||||
const WebRtc_Word8* fromIP,
|
||||
const WebRtc_UWord16 fromPort)
|
||||
{
|
||||
InsertRTPPacket(incomingRtpPacket, incomingRtpPacketLength);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IncomingRTCPPacket
|
||||
//
|
||||
// Receives RTCP packets from SocketTransport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ViEReceiver::IncomingRTCPPacket(const WebRtc_Word8* incomingRtcpPacket,
|
||||
const WebRtc_Word32 incomingRtcpPacketLength,
|
||||
const WebRtc_Word8* fromIP,
|
||||
const WebRtc_UWord16 fromPort)
|
||||
{
|
||||
InsertRTCPPacket(incomingRtcpPacket, incomingRtcpPacketLength);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReceivedRTPPacket
|
||||
//
|
||||
// Receives RTP packets from external transport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::ReceivedRTPPacket(const void* rtpPacket, int rtpPacketLength)
|
||||
{
|
||||
if (!_receiving)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return InsertRTPPacket((const WebRtc_Word8*) rtpPacket, rtpPacketLength);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReceivedRTCPPacket
|
||||
//
|
||||
// Receives RTCP packets from external transport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::ReceivedRTCPPacket(const void* rtcpPacket,
|
||||
int rtcpPacketLength)
|
||||
{
|
||||
if (!_receiving)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return InsertRTCPPacket((const WebRtc_Word8*) rtcpPacket, rtcpPacketLength);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// OnReceivedPayloadData
|
||||
//
|
||||
// From RtpData, callback for data from RTP module
|
||||
// ----------------------------------------------------------------------------
|
||||
WebRtc_Word32 ViEReceiver::OnReceivedPayloadData(const WebRtc_UWord8* payloadData,
|
||||
const WebRtc_UWord16 payloadSize,
|
||||
const WebRtcRTPHeader* rtpHeader)
|
||||
{
|
||||
if (rtpHeader == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_vcm.IncomingPacket(payloadData, payloadSize, *rtpHeader) != 0)
|
||||
{
|
||||
if (vcm_.IncomingPacket(payload_data, payload_size, *rtp_header) != 0) {
|
||||
// Check this...
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Private methods
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// InsertRTPPacket
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::InsertRTPPacket(const WebRtc_Word8* rtpPacket,
|
||||
int rtpPacketLength)
|
||||
{
|
||||
WebRtc_UWord8* receivedPacket = (WebRtc_UWord8*) (rtpPacket);
|
||||
int receivedPacketLength = rtpPacketLength;
|
||||
int ViEReceiver::InsertRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||
int rtp_packet_length) {
|
||||
// TODO(mflodman) Change decrypt to get rid of this cast.
|
||||
WebRtc_Word8* tmp_ptr = const_cast<WebRtc_Word8*>(rtp_packet);
|
||||
unsigned char* received_packet = reinterpret_cast<unsigned char*>(tmp_ptr);
|
||||
int received_packet_length = rtp_packet_length;
|
||||
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
|
||||
if (_ptrExternalDecryption)
|
||||
{
|
||||
int decryptedLength = 0;
|
||||
_ptrExternalDecryption->decrypt(_channelId, receivedPacket,
|
||||
_ptrDecryptionBuffer,
|
||||
(int) receivedPacketLength,
|
||||
(int*) &decryptedLength);
|
||||
if (decryptedLength <= 0)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId,
|
||||
_channelId),
|
||||
"RTP decryption failed");
|
||||
if (external_decryption_) {
|
||||
int decrypted_length = 0;
|
||||
external_decryption_->decrypt(channel_id_, received_packet,
|
||||
decryption_buffer_, received_packet_length,
|
||||
&decrypted_length);
|
||||
if (decrypted_length <= 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(engine_id_, channel_id_), "RTP decryption failed");
|
||||
return -1;
|
||||
} else if (decryptedLength > kViEMaxMtu)
|
||||
{
|
||||
} else if (decrypted_length > kViEMaxMtu) {
|
||||
WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo,
|
||||
ViEId(_engineId, _channelId),
|
||||
" %d bytes is allocated as RTP decrytption output => memory is now corrupted",
|
||||
kViEMaxMtu);
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"InsertRTPPacket: %d bytes is allocated as RTP decrytption"
|
||||
" output, external decryption used %d bytes. => memory is "
|
||||
" now corrupted", kViEMaxMtu, decrypted_length);
|
||||
return -1;
|
||||
}
|
||||
receivedPacket = _ptrDecryptionBuffer;
|
||||
receivedPacketLength = decryptedLength;
|
||||
received_packet = decryption_buffer_;
|
||||
received_packet_length = decrypted_length;
|
||||
}
|
||||
#ifdef WEBRTC_SRTP
|
||||
if (_ptrSrtp)
|
||||
|
||||
if (rtp_dump_) {
|
||||
rtp_dump_->DumpPacket(received_packet,
|
||||
static_cast<WebRtc_UWord16>(received_packet_length));
|
||||
}
|
||||
}
|
||||
return rtp_rtcp_.IncomingPacket(received_packet, received_packet_length);
|
||||
}
|
||||
|
||||
int ViEReceiver::InsertRTCPPacket(const WebRtc_Word8* rtcp_packet,
|
||||
int rtcp_packet_length) {
|
||||
// TODO(mflodman) Change decrypt to get rid of this cast.
|
||||
WebRtc_Word8* tmp_ptr = const_cast<WebRtc_Word8*>(rtcp_packet);
|
||||
unsigned char* received_packet = reinterpret_cast<unsigned char*>(tmp_ptr);
|
||||
int received_packet_length = rtcp_packet_length;
|
||||
{
|
||||
int decryptedLength = 0;
|
||||
_ptrSrtp->decrypt(_channelId, receivedPacket, _ptrSrtpBuffer, receivedPacketLength, &decryptedLength);
|
||||
if (decryptedLength <= 0)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), "RTP decryption failed");
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
|
||||
if (external_decryption_) {
|
||||
int decrypted_length = 0;
|
||||
external_decryption_->decrypt_rtcp(channel_id_, received_packet,
|
||||
decryption_buffer_,
|
||||
received_packet_length,
|
||||
&decrypted_length);
|
||||
if (decrypted_length <= 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(engine_id_, channel_id_), "RTP decryption failed");
|
||||
return -1;
|
||||
} else if (decrypted_length > kViEMaxMtu) {
|
||||
WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo,
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"InsertRTCPPacket: %d bytes is allocated as RTP "
|
||||
" decrytption output, external decryption used %d bytes. "
|
||||
" => memory is now corrupted",
|
||||
kViEMaxMtu, decrypted_length);
|
||||
return -1;
|
||||
}
|
||||
else if (decryptedLength > kViEMaxMtu)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo,ViEId(_engineId, _channelId), " %d bytes is allocated as RTP decrytption output => memory is now corrupted", kViEMaxMtu);
|
||||
return -1;
|
||||
}
|
||||
receivedPacket = _ptrSrtpBuffer;
|
||||
receivedPacketLength = decryptedLength;
|
||||
}
|
||||
#endif
|
||||
if (_rtpDump)
|
||||
{
|
||||
_rtpDump->DumpPacket(receivedPacket,
|
||||
(WebRtc_UWord16) receivedPacketLength);
|
||||
}
|
||||
}
|
||||
return _rtpRtcp.IncomingPacket(receivedPacket, receivedPacketLength);
|
||||
received_packet = decryption_buffer_;
|
||||
received_packet_length = decrypted_length;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// InsertRTCPPacket
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::InsertRTCPPacket(const WebRtc_Word8* rtcpPacket,
|
||||
int rtcpPacketLength)
|
||||
{
|
||||
WebRtc_UWord8* receivedPacket = (WebRtc_UWord8*) rtcpPacket;
|
||||
int receivedPacketLength = rtcpPacketLength;
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
|
||||
if (_ptrExternalDecryption)
|
||||
{
|
||||
int decryptedLength = 0;
|
||||
_ptrExternalDecryption->decrypt_rtcp(_channelId, receivedPacket,
|
||||
_ptrDecryptionBuffer,
|
||||
(int) receivedPacketLength,
|
||||
(int*) &decryptedLength);
|
||||
if (decryptedLength <= 0)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId,
|
||||
_channelId),
|
||||
"RTP decryption failed");
|
||||
return -1;
|
||||
} else if (decryptedLength > kViEMaxMtu)
|
||||
{
|
||||
WEBRTC_TRACE(
|
||||
webrtc::kTraceCritical,
|
||||
webrtc::kTraceVideo,
|
||||
ViEId(_engineId, _channelId),
|
||||
" %d bytes is allocated as RTP decrytption output => memory is now corrupted",
|
||||
kViEMaxMtu);
|
||||
return -1;
|
||||
}
|
||||
receivedPacket = _ptrDecryptionBuffer;
|
||||
receivedPacketLength = decryptedLength;
|
||||
}
|
||||
#ifdef WEBRTC_SRTP
|
||||
if (_ptrSrtcp)
|
||||
{
|
||||
int decryptedLength = 0;
|
||||
_ptrSrtcp->decrypt_rtcp(_channelId, receivedPacket, _ptrSrtcpBuffer, (int) receivedPacketLength, (int*) &decryptedLength);
|
||||
if (decryptedLength <= 0)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), "RTP decryption failed");
|
||||
return -1;
|
||||
}
|
||||
else if (decryptedLength > kViEMaxMtu)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo, ViEId(_engineId, _channelId), " %d bytes is allocated as RTP decrytption output => memory is now corrupted", kViEMaxMtu);
|
||||
return -1;
|
||||
}
|
||||
receivedPacket = _ptrSrtcpBuffer;
|
||||
receivedPacketLength = decryptedLength;
|
||||
}
|
||||
#endif
|
||||
if (_rtpDump)
|
||||
{
|
||||
_rtpDump->DumpPacket(receivedPacket,
|
||||
(WebRtc_UWord16) receivedPacketLength);
|
||||
if (rtp_dump_) {
|
||||
rtp_dump_->DumpPacket(
|
||||
received_packet, static_cast<WebRtc_UWord16>(received_packet_length));
|
||||
}
|
||||
}
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
std::list<RtpRtcp*>::iterator it = _rtpRtcpSimulcast.begin();
|
||||
while (it != _rtpRtcpSimulcast.end())
|
||||
{
|
||||
RtpRtcp* rtpRtcp = *it++;
|
||||
rtpRtcp->IncomingPacket(receivedPacket, receivedPacketLength);
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
|
||||
while (it != rtp_rtcp_simulcast_.end()) {
|
||||
RtpRtcp* rtp_rtcp = *it++;
|
||||
rtp_rtcp->IncomingPacket(received_packet, received_packet_length);
|
||||
}
|
||||
}
|
||||
return _rtpRtcp.IncomingPacket(receivedPacket, receivedPacketLength);
|
||||
return rtp_rtcp_.IncomingPacket(received_packet, received_packet_length);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// StartReceive
|
||||
//
|
||||
// Only used for external transport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ViEReceiver::StartReceive()
|
||||
{
|
||||
_receiving = true;
|
||||
void ViEReceiver::StartReceive() {
|
||||
receiving_ = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// StopReceive
|
||||
//
|
||||
// Only used for external transport
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ViEReceiver::StopReceive()
|
||||
{
|
||||
_receiving = false;
|
||||
void ViEReceiver::StopReceive() {
|
||||
receiving_ = false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// StartRTPDump
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::StartRTPDump(const char fileNameUTF8[1024])
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_rtpDump)
|
||||
{
|
||||
int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
if (rtp_dump_) {
|
||||
// Restart it if it already exists and is started
|
||||
_rtpDump->Stop();
|
||||
} else
|
||||
{
|
||||
_rtpDump = RtpDump::CreateRtpDump();
|
||||
if (_rtpDump == NULL)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId,
|
||||
_channelId),
|
||||
"%s: Failed to create RTP dump", __FUNCTION__);
|
||||
rtp_dump_->Stop();
|
||||
} else {
|
||||
rtp_dump_ = RtpDump::CreateRtpDump();
|
||||
if (rtp_dump_ == NULL) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"StartRTPDump: Failed to create RTP dump");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (_rtpDump->Start(fileNameUTF8) != 0)
|
||||
{
|
||||
RtpDump::DestroyRtpDump(_rtpDump);
|
||||
_rtpDump = NULL;
|
||||
if (rtp_dump_->Start(file_nameUTF8) != 0) {
|
||||
RtpDump::DestroyRtpDump(rtp_dump_);
|
||||
rtp_dump_ = NULL;
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(_engineId, _channelId),
|
||||
"%s: Failed to start RTP dump", __FUNCTION__);
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"StartRTPDump: Failed to start RTP dump");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// StopRTPDump
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int ViEReceiver::StopRTPDump()
|
||||
{
|
||||
CriticalSectionScoped cs(_receiveCritsect);
|
||||
if (_rtpDump)
|
||||
{
|
||||
if (_rtpDump->IsActive())
|
||||
{
|
||||
_rtpDump->Stop();
|
||||
} else
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId,
|
||||
_channelId),
|
||||
"%s: Dump not active", __FUNCTION__);
|
||||
}
|
||||
RtpDump::DestroyRtpDump(_rtpDump);
|
||||
_rtpDump = NULL;
|
||||
} else
|
||||
{
|
||||
int ViEReceiver::StopRTPDump() {
|
||||
CriticalSectionScoped cs(receive_critsect_);
|
||||
if (rtp_dump_) {
|
||||
if (rtp_dump_->IsActive()) {
|
||||
rtp_dump_->Stop();
|
||||
} else {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(_engineId, _channelId), "%s: RTP dump not started",
|
||||
__FUNCTION__);
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"StopRTPDump: Dump not active");
|
||||
}
|
||||
RtpDump::DestroyRtpDump(rtp_dump_);
|
||||
rtp_dump_ = NULL;
|
||||
} else {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||
ViEId(engine_id_, channel_id_),
|
||||
"StopRTPDump: RTP dump not started");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -8,12 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* vie_receiver.h
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
||||
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
||||
#ifndef WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||
#define WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
@ -23,85 +19,68 @@
|
||||
#include "udp_transport.h"
|
||||
#include "vie_defines.h"
|
||||
|
||||
#ifdef WEBRTC_SRTP
|
||||
class SrtpModule;
|
||||
#endif
|
||||
namespace webrtc {
|
||||
|
||||
namespace webrtc
|
||||
{
|
||||
class CriticalSectionWrapper;
|
||||
// Forward declarations
|
||||
class Encryption;
|
||||
class RtpDump;
|
||||
class RtpRtcp;
|
||||
class VideoCodingModule;
|
||||
class Encryption;
|
||||
|
||||
class ViEReceiver: public UdpTransportData, public RtpData
|
||||
{
|
||||
class ViEReceiver : public UdpTransportData, public RtpData {
|
||||
public:
|
||||
ViEReceiver(int engineId, int channelId, RtpRtcp& moduleRtpRtcp,
|
||||
webrtc::VideoCodingModule& moduleVcm);
|
||||
ViEReceiver(int engine_id, int channel_id, RtpRtcp& rtp_rtcp,
|
||||
VideoCodingModule& module_vcm);
|
||||
~ViEReceiver();
|
||||
|
||||
int RegisterExternalDecryption(Encryption* decryption);
|
||||
int DeregisterExternalDecryption();
|
||||
|
||||
void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtpModules);
|
||||
|
||||
#ifdef WEBRTC_SRTP
|
||||
int RegisterSRTPModule(SrtpModule* srtpModule);
|
||||
int DeregisterSRTPModule();
|
||||
|
||||
int RegisterSRTCPModule(SrtpModule* srtpModule);
|
||||
int DeregisterSRTCPModule();
|
||||
#endif
|
||||
void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
|
||||
|
||||
void StartReceive();
|
||||
void StopReceive();
|
||||
int StartRTPDump(const char fileNameUTF8[1024]);
|
||||
|
||||
int StartRTPDump(const char file_nameUTF8[1024]);
|
||||
int StopRTPDump();
|
||||
|
||||
// From SocketTransportData, receiving packets from the socket
|
||||
virtual void IncomingRTPPacket(const WebRtc_Word8* incomingRtpPacket,
|
||||
const WebRtc_Word32 incomingRtpPacketLength,
|
||||
const WebRtc_Word8* fromIP,
|
||||
const WebRtc_UWord16 fromPort);
|
||||
virtual void IncomingRTCPPacket(const WebRtc_Word8* incomingRtcpPacket,
|
||||
const WebRtc_Word32 incomingRtcpPacketLength,
|
||||
const WebRtc_Word8* fromIP,
|
||||
const WebRtc_UWord16 fromPort);
|
||||
// Implements UdpTransportData.
|
||||
virtual void IncomingRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||
const WebRtc_Word32 rtp_packet_length,
|
||||
const WebRtc_Word8* from_ip,
|
||||
const WebRtc_UWord16 from_port);
|
||||
virtual void IncomingRTCPPacket(const WebRtc_Word8* rtcp_packet,
|
||||
const WebRtc_Word32 rtcp_packet_length,
|
||||
const WebRtc_Word8* from_ip,
|
||||
const WebRtc_UWord16 from_port);
|
||||
|
||||
// Receives packets from external transport
|
||||
int ReceivedRTPPacket(const void* rtpPacket, int rtpPacketLength);
|
||||
// Receives packets from external transport.
|
||||
int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length);
|
||||
int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length);
|
||||
|
||||
int ReceivedRTCPPacket(const void* rtcpPacket, int rtcpPacketLength);
|
||||
|
||||
// From RtpData, callback for data from RTP module
|
||||
// Implements RtpData.
|
||||
virtual WebRtc_Word32 OnReceivedPayloadData(
|
||||
const WebRtc_UWord8* payloadData,
|
||||
const WebRtc_UWord16 payloadSize,
|
||||
const WebRtcRTPHeader* rtpHeader);
|
||||
private:
|
||||
int InsertRTPPacket(const WebRtc_Word8* rtpPacket, int rtpPacketLength);
|
||||
int InsertRTCPPacket(const WebRtc_Word8* rtcpPacket, int rtcpPacketLength);
|
||||
// Registered members
|
||||
CriticalSectionWrapper& _receiveCritsect;
|
||||
int _engineId;
|
||||
int _channelId;
|
||||
RtpRtcp& _rtpRtcp;
|
||||
std::list<RtpRtcp*> _rtpRtcpSimulcast;
|
||||
VideoCodingModule& _vcm;
|
||||
const WebRtc_UWord8* payload_data,
|
||||
const WebRtc_UWord16 payload_size,
|
||||
const WebRtcRTPHeader* rtp_header);
|
||||
|
||||
#ifdef WEBRTC_SRTP
|
||||
SrtpModule* _ptrSrtp;
|
||||
SrtpModule* _ptrSrtcp;
|
||||
WebRtc_UWord8* _ptrSrtpBuffer;
|
||||
WebRtc_UWord8* _ptrSrtcpBuffer;
|
||||
#endif
|
||||
Encryption* _ptrExternalDecryption;
|
||||
WebRtc_UWord8* _ptrDecryptionBuffer;
|
||||
RtpDump* _rtpDump;
|
||||
bool _receiving; // Only needed to protect external transport
|
||||
private:
|
||||
int InsertRTPPacket(const WebRtc_Word8* rtp_packet, int rtp_packet_length);
|
||||
int InsertRTCPPacket(const WebRtc_Word8* rtcp_packet, int rtcp_packet_length);
|
||||
|
||||
CriticalSectionWrapper& receive_critsect_;
|
||||
int engine_id_;
|
||||
int channel_id_;
|
||||
RtpRtcp& rtp_rtcp_;
|
||||
std::list<RtpRtcp*> rtp_rtcp_simulcast_;
|
||||
VideoCodingModule& vcm_;
|
||||
|
||||
Encryption* external_decryption_;
|
||||
WebRtc_UWord8* decryption_buffer_;
|
||||
RtpDump* rtp_dump_;
|
||||
bool receiving_;
|
||||
};
|
||||
|
||||
} // namespace webrt
|
||||
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
||||
|
||||
#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||
|
Loading…
Reference in New Issue
Block a user