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.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* ViEChannel.cpp
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vie_receiver.h"
|
#include "vie_receiver.h"
|
||||||
|
|
||||||
#include "critical_section_wrapper.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_dump.h"
|
||||||
|
#include "rtp_rtcp.h"
|
||||||
|
#include "video_coding.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEReceiver::ViEReceiver(int engine_id, int channel_id,
|
||||||
// Constructor
|
RtpRtcp& rtp_rtcp,
|
||||||
// ----------------------------------------------------------------------------
|
VideoCodingModule& module_vcm)
|
||||||
|
: receive_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
ViEReceiver::ViEReceiver(int engineId, int channelId,
|
engine_id_(engine_id),
|
||||||
RtpRtcp& moduleRtpRtcp,
|
channel_id_(channel_id),
|
||||||
VideoCodingModule& moduleVcm)
|
rtp_rtcp_(rtp_rtcp),
|
||||||
: _receiveCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
|
vcm_(module_vcm),
|
||||||
_engineId(engineId),
|
external_decryption_(NULL),
|
||||||
_channelId(channelId),
|
decryption_buffer_(NULL),
|
||||||
_rtpRtcp(moduleRtpRtcp),
|
rtp_dump_(NULL),
|
||||||
_vcm(moduleVcm),
|
receiving_(false) {
|
||||||
#ifdef WEBRTC_SRTP
|
|
||||||
_ptrSrtp(NULL),
|
|
||||||
_ptrSrtcp(NULL),
|
|
||||||
_ptrSrtpBuffer(NULL),
|
|
||||||
_ptrSrtcpBuffer(NULL),
|
|
||||||
#endif
|
|
||||||
_ptrExternalDecryption(NULL), _ptrDecryptionBuffer(NULL),
|
|
||||||
_rtpDump(NULL), _receiving(false)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEReceiver::~ViEReceiver() {
|
||||||
// Destructor
|
delete &receive_critsect_;
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ViEReceiver::~ViEReceiver()
|
if (decryption_buffer_) {
|
||||||
{
|
delete[] decryption_buffer_;
|
||||||
delete &_receiveCritsect;
|
decryption_buffer_ = NULL;
|
||||||
#ifdef WEBRTC_SRTP
|
}
|
||||||
if (_ptrSrtpBuffer)
|
if (rtp_dump_) {
|
||||||
{
|
rtp_dump_->Stop();
|
||||||
delete [] _ptrSrtpBuffer;
|
RtpDump::DestroyRtpDump(rtp_dump_);
|
||||||
_ptrSrtpBuffer = NULL;
|
rtp_dump_ = NULL;
|
||||||
}
|
}
|
||||||
if (_ptrSrtcpBuffer)
|
|
||||||
{
|
|
||||||
delete [] _ptrSrtcpBuffer;
|
|
||||||
_ptrSrtcpBuffer = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (_ptrDecryptionBuffer)
|
|
||||||
{
|
|
||||||
delete[] _ptrDecryptionBuffer;
|
|
||||||
_ptrDecryptionBuffer = NULL;
|
|
||||||
}
|
|
||||||
if (_rtpDump)
|
|
||||||
{
|
|
||||||
_rtpDump->Stop();
|
|
||||||
RtpDump::DestroyRtpDump(_rtpDump);
|
|
||||||
_rtpDump = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
int ViEReceiver::RegisterExternalDecryption(Encryption* decryption) {
|
||||||
// Decryption
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
// ============================================================================
|
if (external_decryption_) {
|
||||||
|
return -1;
|
||||||
// ----------------------------------------------------------------------------
|
}
|
||||||
// RegisterExternalDecryption
|
decryption_buffer_ = new WebRtc_UWord8[kViEMaxMtu];
|
||||||
// ----------------------------------------------------------------------------
|
if (decryption_buffer_ == NULL) {
|
||||||
|
return -1;
|
||||||
int ViEReceiver::RegisterExternalDecryption(Encryption* decryption)
|
}
|
||||||
{
|
external_decryption_ = decryption;
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
return 0;
|
||||||
if (_ptrExternalDecryption)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_ptrDecryptionBuffer = new WebRtc_UWord8[kViEMaxMtu];
|
|
||||||
if (_ptrDecryptionBuffer == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_ptrExternalDecryption = decryption;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEReceiver::DeregisterExternalDecryption() {
|
||||||
// DeregisterExternalDecryption
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
// ----------------------------------------------------------------------------
|
if (external_decryption_ == NULL) {
|
||||||
|
return -1;
|
||||||
int ViEReceiver::DeregisterExternalDecryption()
|
}
|
||||||
{
|
external_decryption_ = NULL;
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
return 0;
|
||||||
if (_ptrExternalDecryption == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_ptrExternalDecryption = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViEReceiver::RegisterSimulcastRtpRtcpModules(
|
void ViEReceiver::RegisterSimulcastRtpRtcpModules(
|
||||||
const std::list<RtpRtcp*>& rtpModules)
|
const std::list<RtpRtcp*>& rtp_modules) {
|
||||||
{
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
rtp_rtcp_simulcast_.clear();
|
||||||
_rtpRtcpSimulcast.clear();
|
|
||||||
if (!rtpModules.empty())
|
if (!rtp_modules.empty()) {
|
||||||
{
|
rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
|
||||||
_rtpRtcpSimulcast.insert(_rtpRtcpSimulcast.begin(),
|
rtp_modules.begin(),
|
||||||
rtpModules.begin(),
|
rtp_modules.end());
|
||||||
rtpModules.end());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WEBRTC_SRTP
|
void ViEReceiver::IncomingRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||||
// ----------------------------------------------------------------------------
|
const WebRtc_Word32 rtp_packet_length,
|
||||||
// RegisterSRTPModule
|
const WebRtc_Word8* from_ip,
|
||||||
// ----------------------------------------------------------------------------
|
const WebRtc_UWord16 from_port) {
|
||||||
|
InsertRTPPacket(rtp_packet, rtp_packet_length);
|
||||||
|
}
|
||||||
|
|
||||||
int ViEReceiver::RegisterSRTPModule(SrtpModule* srtpModule)
|
void ViEReceiver::IncomingRTCPPacket(const WebRtc_Word8* rtcp_packet,
|
||||||
{
|
const WebRtc_Word32 rtcp_packet_length,
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
const WebRtc_Word8* from_ip,
|
||||||
if (_ptrSrtp ||
|
const WebRtc_UWord16 from_port) {
|
||||||
srtpModule == NULL)
|
InsertRTCPPacket(rtcp_packet, rtcp_packet_length);
|
||||||
{
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_ptrSrtpBuffer = new WebRtc_UWord8[kViEMaxMtu];
|
|
||||||
if (_ptrSrtpBuffer == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_ptrSrtp = srtpModule;
|
|
||||||
|
|
||||||
|
int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
|
||||||
|
int rtp_packet_length) {
|
||||||
|
if (!receiving_) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vcm_.IncomingPacket(payload_data, payload_size, *rtp_header) != 0) {
|
||||||
|
// Check this...
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEReceiver::InsertRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||||
// DeregisterSRTPModule
|
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;
|
||||||
|
|
||||||
int ViEReceiver::DeregisterSRTPModule()
|
{
|
||||||
{
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
|
||||||
if (_ptrSrtp == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (_ptrSrtpBuffer)
|
|
||||||
{
|
|
||||||
delete [] _ptrSrtpBuffer;
|
|
||||||
_ptrSrtpBuffer = NULL;
|
|
||||||
}
|
|
||||||
_ptrSrtp = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
if (external_decryption_) {
|
||||||
// RegisterSRTCPModule
|
int decrypted_length = 0;
|
||||||
// ----------------------------------------------------------------------------
|
external_decryption_->decrypt(channel_id_, received_packet,
|
||||||
|
decryption_buffer_, received_packet_length,
|
||||||
int ViEReceiver::RegisterSRTCPModule(SrtpModule* srtcpModule)
|
&decrypted_length);
|
||||||
{
|
if (decrypted_length <= 0) {
|
||||||
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)
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
|
||||||
|
|
||||||
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");
|
|
||||||
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 (_ptrSrtp)
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
|
||||||
std::list<RtpRtcp*>::iterator it = _rtpRtcpSimulcast.begin();
|
|
||||||
while (it != _rtpRtcpSimulcast.end())
|
|
||||||
{
|
|
||||||
RtpRtcp* rtpRtcp = *it++;
|
|
||||||
rtpRtcp->IncomingPacket(receivedPacket, receivedPacketLength);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _rtpRtcp.IncomingPacket(receivedPacket, receivedPacketLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// StartReceive
|
|
||||||
//
|
|
||||||
// Only used for external transport
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void ViEReceiver::StartReceive()
|
|
||||||
{
|
|
||||||
_receiving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// StopReceive
|
|
||||||
//
|
|
||||||
// Only used for external transport
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void ViEReceiver::StopReceive()
|
|
||||||
{
|
|
||||||
_receiving = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// StartRTPDump
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int ViEReceiver::StartRTPDump(const char fileNameUTF8[1024])
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
|
||||||
if (_rtpDump)
|
|
||||||
{
|
|
||||||
// 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__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_rtpDump->Start(fileNameUTF8) != 0)
|
|
||||||
{
|
|
||||||
RtpDump::DestroyRtpDump(_rtpDump);
|
|
||||||
_rtpDump = NULL;
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||||
ViEId(_engineId, _channelId),
|
ViEId(engine_id_, channel_id_), "RTP decryption failed");
|
||||||
"%s: Failed to start RTP dump", __FUNCTION__);
|
|
||||||
return -1;
|
return -1;
|
||||||
|
} else if (decrypted_length > kViEMaxMtu) {
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
received_packet = decryption_buffer_;
|
||||||
|
received_packet_length = decrypted_length;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
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,
|
||||||
// StopRTPDump
|
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;
|
||||||
|
{
|
||||||
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
|
|
||||||
int ViEReceiver::StopRTPDump()
|
if (external_decryption_) {
|
||||||
{
|
int decrypted_length = 0;
|
||||||
CriticalSectionScoped cs(_receiveCritsect);
|
external_decryption_->decrypt_rtcp(channel_id_, received_packet,
|
||||||
if (_rtpDump)
|
decryption_buffer_,
|
||||||
{
|
received_packet_length,
|
||||||
if (_rtpDump->IsActive())
|
&decrypted_length);
|
||||||
{
|
if (decrypted_length <= 0) {
|
||||||
_rtpDump->Stop();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId,
|
|
||||||
_channelId),
|
|
||||||
"%s: Dump not active", __FUNCTION__);
|
|
||||||
}
|
|
||||||
RtpDump::DestroyRtpDump(_rtpDump);
|
|
||||||
_rtpDump = NULL;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||||
ViEId(_engineId, _channelId), "%s: RTP dump not started",
|
ViEId(engine_id_, channel_id_), "RTP decryption failed");
|
||||||
__FUNCTION__);
|
|
||||||
return -1;
|
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;
|
||||||
|
}
|
||||||
|
received_packet = decryption_buffer_;
|
||||||
|
received_packet_length = decrypted_length;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
if (rtp_dump_) {
|
||||||
|
rtp_dump_->DumpPacket(
|
||||||
|
received_packet, static_cast<WebRtc_UWord16>(received_packet_length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
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 rtp_rtcp_.IncomingPacket(received_packet, received_packet_length);
|
||||||
}
|
}
|
||||||
} // namespace webrtc
|
|
||||||
|
void ViEReceiver::StartReceive() {
|
||||||
|
receiving_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViEReceiver::StopReceive() {
|
||||||
|
receiving_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
|
||||||
|
CriticalSectionScoped cs(receive_critsect_);
|
||||||
|
if (rtp_dump_) {
|
||||||
|
// Restart it if it already exists and is started
|
||||||
|
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 (rtp_dump_->Start(file_nameUTF8) != 0) {
|
||||||
|
RtpDump::DestroyRtpDump(rtp_dump_);
|
||||||
|
rtp_dump_ = NULL;
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
|
||||||
|
ViEId(engine_id_, channel_id_),
|
||||||
|
"StartRTPDump: Failed to start RTP dump");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(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.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#ifndef WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||||
* vie_receiver.h
|
#define WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
|
||||||
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -23,85 +19,68 @@
|
|||||||
#include "udp_transport.h"
|
#include "udp_transport.h"
|
||||||
#include "vie_defines.h"
|
#include "vie_defines.h"
|
||||||
|
|
||||||
#ifdef WEBRTC_SRTP
|
namespace webrtc {
|
||||||
class SrtpModule;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace webrtc
|
|
||||||
{
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
// Forward declarations
|
class Encryption;
|
||||||
class RtpDump;
|
class RtpDump;
|
||||||
class RtpRtcp;
|
class RtpRtcp;
|
||||||
class VideoCodingModule;
|
class VideoCodingModule;
|
||||||
class Encryption;
|
|
||||||
|
|
||||||
class ViEReceiver: public UdpTransportData, public RtpData
|
class ViEReceiver : public UdpTransportData, public RtpData {
|
||||||
{
|
public:
|
||||||
public:
|
ViEReceiver(int engine_id, int channel_id, RtpRtcp& rtp_rtcp,
|
||||||
ViEReceiver(int engineId, int channelId, RtpRtcp& moduleRtpRtcp,
|
VideoCodingModule& module_vcm);
|
||||||
webrtc::VideoCodingModule& moduleVcm);
|
~ViEReceiver();
|
||||||
~ViEReceiver();
|
|
||||||
|
|
||||||
int RegisterExternalDecryption(Encryption* decryption);
|
int RegisterExternalDecryption(Encryption* decryption);
|
||||||
int DeregisterExternalDecryption();
|
int DeregisterExternalDecryption();
|
||||||
|
|
||||||
void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtpModules);
|
void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
|
||||||
|
|
||||||
#ifdef WEBRTC_SRTP
|
void StartReceive();
|
||||||
int RegisterSRTPModule(SrtpModule* srtpModule);
|
void StopReceive();
|
||||||
int DeregisterSRTPModule();
|
|
||||||
|
|
||||||
int RegisterSRTCPModule(SrtpModule* srtpModule);
|
int StartRTPDump(const char file_nameUTF8[1024]);
|
||||||
int DeregisterSRTCPModule();
|
int StopRTPDump();
|
||||||
#endif
|
|
||||||
|
|
||||||
void StartReceive();
|
// Implements UdpTransportData.
|
||||||
void StopReceive();
|
virtual void IncomingRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||||
int StartRTPDump(const char fileNameUTF8[1024]);
|
const WebRtc_Word32 rtp_packet_length,
|
||||||
int StopRTPDump();
|
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);
|
||||||
|
|
||||||
// From SocketTransportData, receiving packets from the socket
|
// Receives packets from external transport.
|
||||||
virtual void IncomingRTPPacket(const WebRtc_Word8* incomingRtpPacket,
|
int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length);
|
||||||
const WebRtc_Word32 incomingRtpPacketLength,
|
int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length);
|
||||||
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);
|
|
||||||
|
|
||||||
// Receives packets from external transport
|
// Implements RtpData.
|
||||||
int ReceivedRTPPacket(const void* rtpPacket, int rtpPacketLength);
|
virtual WebRtc_Word32 OnReceivedPayloadData(
|
||||||
|
const WebRtc_UWord8* payload_data,
|
||||||
|
const WebRtc_UWord16 payload_size,
|
||||||
|
const WebRtcRTPHeader* rtp_header);
|
||||||
|
|
||||||
int ReceivedRTCPPacket(const void* rtcpPacket, int rtcpPacketLength);
|
private:
|
||||||
|
int InsertRTPPacket(const WebRtc_Word8* rtp_packet, int rtp_packet_length);
|
||||||
|
int InsertRTCPPacket(const WebRtc_Word8* rtcp_packet, int rtcp_packet_length);
|
||||||
|
|
||||||
// From RtpData, callback for data from RTP module
|
CriticalSectionWrapper& receive_critsect_;
|
||||||
virtual WebRtc_Word32 OnReceivedPayloadData(
|
int engine_id_;
|
||||||
const WebRtc_UWord8* payloadData,
|
int channel_id_;
|
||||||
const WebRtc_UWord16 payloadSize,
|
RtpRtcp& rtp_rtcp_;
|
||||||
const WebRtcRTPHeader* rtpHeader);
|
std::list<RtpRtcp*> rtp_rtcp_simulcast_;
|
||||||
private:
|
VideoCodingModule& vcm_;
|
||||||
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;
|
|
||||||
|
|
||||||
#ifdef WEBRTC_SRTP
|
Encryption* external_decryption_;
|
||||||
SrtpModule* _ptrSrtp;
|
WebRtc_UWord8* decryption_buffer_;
|
||||||
SrtpModule* _ptrSrtcp;
|
RtpDump* rtp_dump_;
|
||||||
WebRtc_UWord8* _ptrSrtpBuffer;
|
bool receiving_;
|
||||||
WebRtc_UWord8* _ptrSrtcpBuffer;
|
|
||||||
#endif
|
|
||||||
Encryption* _ptrExternalDecryption;
|
|
||||||
WebRtc_UWord8* _ptrDecryptionBuffer;
|
|
||||||
RtpDump* _rtpDump;
|
|
||||||
bool _receiving; // Only needed to protect external transport
|
|
||||||
};
|
};
|
||||||
} // namespace webrt
|
|
||||||
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RECEIVER_H_
|
} // namespace webrt
|
||||||
|
|
||||||
|
#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user