2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-09-20 13:52:04 +00:00
|
|
|
#include "rtp_receiver_video.h"
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <cassert> //assert
|
|
|
|
|
#include <cstring> // memcpy()
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include "critical_section_wrapper.h"
|
|
|
|
|
#include "receiver_fec.h"
|
2011-09-20 13:52:04 +00:00
|
|
|
#include "rtp_rtcp_impl.h"
|
2011-12-16 17:21:09 +00:00
|
|
|
#include "rtp_utility.h"
|
2012-04-16 12:58:49 +00:00
|
|
|
#include "trace.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
WebRtc_UWord32 BitRateBPS(WebRtc_UWord16 x )
|
|
|
|
|
{
|
|
|
|
|
return (x & 0x3fff) * WebRtc_UWord32(pow(10.0f,(2 + (x >> 14))));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-30 09:03:37 +00:00
|
|
|
RTPReceiverVideo::RTPReceiverVideo():
|
|
|
|
|
_id(0),
|
|
|
|
|
_rtpRtcp(NULL),
|
|
|
|
|
_criticalSectionFeedback(CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_cbVideoFeedback(NULL),
|
|
|
|
|
_criticalSectionReceiverVideo(
|
|
|
|
|
CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_completeFrame(false),
|
|
|
|
|
_packetStartTimeMs(0),
|
|
|
|
|
_receivedBW(),
|
|
|
|
|
_estimatedBW(0),
|
|
|
|
|
_currentFecFrameDecoded(false),
|
|
|
|
|
_receiveFEC(NULL),
|
|
|
|
|
_overUseDetector(),
|
|
|
|
|
_videoBitRate(),
|
|
|
|
|
_lastBitRateChange(0),
|
|
|
|
|
_packetOverHead(28)
|
|
|
|
|
{
|
|
|
|
|
memset(_receivedBW, 0,sizeof(_receivedBW));
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
RTPReceiverVideo::RTPReceiverVideo(const WebRtc_Word32 id,
|
2011-09-20 13:52:04 +00:00
|
|
|
ModuleRtpRtcpImpl* owner):
|
2011-07-07 08:21:25 +00:00
|
|
|
_id(id),
|
2012-01-30 09:03:37 +00:00
|
|
|
_rtpRtcp(owner),
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionFeedback(CriticalSectionWrapper::CreateCriticalSection()),
|
2011-07-07 08:21:25 +00:00
|
|
|
_cbVideoFeedback(NULL),
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo(
|
|
|
|
|
CriticalSectionWrapper::CreateCriticalSection()),
|
2011-07-07 08:21:25 +00:00
|
|
|
_completeFrame(false),
|
|
|
|
|
_packetStartTimeMs(0),
|
|
|
|
|
_receivedBW(),
|
|
|
|
|
_estimatedBW(0),
|
|
|
|
|
_currentFecFrameDecoded(false),
|
2011-08-16 17:30:30 +00:00
|
|
|
_receiveFEC(NULL),
|
2011-07-07 08:21:25 +00:00
|
|
|
_overUseDetector(),
|
|
|
|
|
_videoBitRate(),
|
|
|
|
|
_lastBitRateChange(0),
|
|
|
|
|
_packetOverHead(28)
|
|
|
|
|
{
|
|
|
|
|
memset(_receivedBW, 0,sizeof(_receivedBW));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTPReceiverVideo::~RTPReceiverVideo()
|
|
|
|
|
{
|
2011-12-13 19:17:27 +00:00
|
|
|
delete _criticalSectionFeedback;
|
|
|
|
|
delete _criticalSectionReceiverVideo;
|
2011-07-07 08:21:25 +00:00
|
|
|
delete _receiveFEC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::Init()
|
|
|
|
|
{
|
|
|
|
|
_completeFrame = false;
|
|
|
|
|
_packetStartTimeMs = 0;
|
|
|
|
|
_estimatedBW = 0;
|
|
|
|
|
_currentFecFrameDecoded = false;
|
|
|
|
|
_packetOverHead = 28;
|
|
|
|
|
for (int i = 0; i < BW_HISTORY_SIZE; i++)
|
|
|
|
|
{
|
|
|
|
|
_receivedBW[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
ResetOverUseDetector();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
RTPReceiverVideo::ChangeUniqueId(const WebRtc_Word32 id)
|
|
|
|
|
{
|
|
|
|
|
_id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::RegisterIncomingVideoCallback(RtpVideoFeedback* incomingMessagesCallback)
|
|
|
|
|
{
|
|
|
|
|
CriticalSectionScoped lock(_criticalSectionFeedback);
|
|
|
|
|
_cbVideoFeedback = incomingMessagesCallback;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-10-13 15:19:55 +00:00
|
|
|
RTPReceiverVideo::UpdateBandwidthManagement(const WebRtc_UWord32 bitrateBps,
|
2011-07-07 08:21:25 +00:00
|
|
|
const WebRtc_UWord8 fractionLost,
|
2011-10-13 15:19:55 +00:00
|
|
|
const WebRtc_UWord16 roundTripTimeMs)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
CriticalSectionScoped lock(_criticalSectionFeedback);
|
|
|
|
|
if(_cbVideoFeedback)
|
|
|
|
|
{
|
2011-10-13 15:19:55 +00:00
|
|
|
_cbVideoFeedback->OnNetworkChanged(_id,
|
|
|
|
|
bitrateBps,
|
|
|
|
|
fractionLost,
|
|
|
|
|
roundTripTimeMs);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-24 17:16:59 +00:00
|
|
|
ModuleRTPUtility::Payload* RTPReceiverVideo::RegisterReceiveVideoPayload(
|
|
|
|
|
const char payloadName[RTP_PAYLOAD_NAME_SIZE],
|
|
|
|
|
const WebRtc_Word8 payloadType,
|
|
|
|
|
const WebRtc_UWord32 maxRate) {
|
|
|
|
|
RtpVideoCodecTypes videoType = kRtpNoVideo;
|
|
|
|
|
if (ModuleRTPUtility::StringCompare(payloadName, "VP8", 3)) {
|
|
|
|
|
videoType = kRtpVp8Video;
|
|
|
|
|
} else if (ModuleRTPUtility::StringCompare(payloadName, "I420", 4)) {
|
|
|
|
|
videoType = kRtpNoVideo;
|
|
|
|
|
} else if (ModuleRTPUtility::StringCompare(payloadName, "ULPFEC", 6)) {
|
|
|
|
|
// store this
|
|
|
|
|
if (_receiveFEC == NULL) {
|
|
|
|
|
_receiveFEC = new ReceiverFEC(_id, this);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-24 17:16:59 +00:00
|
|
|
_receiveFEC->SetPayloadTypeFEC(payloadType);
|
|
|
|
|
videoType = kRtpFecVideo;
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
ModuleRTPUtility::Payload* payload = new ModuleRTPUtility::Payload;
|
|
|
|
|
|
|
|
|
|
payload->name[RTP_PAYLOAD_NAME_SIZE - 1] = 0;
|
|
|
|
|
strncpy(payload->name, payloadName, RTP_PAYLOAD_NAME_SIZE - 1);
|
|
|
|
|
payload->typeSpecific.Video.videoCodecType = videoType;
|
|
|
|
|
payload->typeSpecific.Video.maxRate = maxRate;
|
|
|
|
|
payload->audio = false;
|
|
|
|
|
return payload;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPReceiverVideo::ResetOverUseDetector()
|
|
|
|
|
{
|
|
|
|
|
_overUseDetector.Reset();
|
|
|
|
|
_videoBitRate.Init();
|
|
|
|
|
_lastBitRateChange = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// called under _criticalSectionReceiverVideo
|
|
|
|
|
WebRtc_UWord16
|
|
|
|
|
RTPReceiverVideo::EstimateBandwidth(const WebRtc_UWord16 bandwidth)
|
|
|
|
|
{
|
|
|
|
|
// received fragments
|
|
|
|
|
// estimate BW
|
|
|
|
|
|
|
|
|
|
WebRtc_UWord16 bwSort[BW_HISTORY_SIZE];
|
|
|
|
|
for(int i = 0; i < BW_HISTORY_SIZE-1; i++)
|
|
|
|
|
{
|
|
|
|
|
_receivedBW[i] = _receivedBW[i+1];
|
|
|
|
|
bwSort[i] = _receivedBW[i+1];
|
|
|
|
|
}
|
|
|
|
|
_receivedBW[BW_HISTORY_SIZE-1] = bandwidth;
|
|
|
|
|
bwSort[BW_HISTORY_SIZE-1] = bandwidth;
|
|
|
|
|
|
|
|
|
|
WebRtc_UWord16 temp;
|
|
|
|
|
for (int i = BW_HISTORY_SIZE-1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 1; j <= i; j++)
|
|
|
|
|
{
|
|
|
|
|
if (bwSort[j-1] > bwSort[j])
|
|
|
|
|
{
|
|
|
|
|
temp = bwSort[j-1];
|
|
|
|
|
bwSort[j-1] = bwSort[j];
|
|
|
|
|
bwSort[j] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int zeroCount = 0;
|
|
|
|
|
for (; zeroCount < BW_HISTORY_SIZE; zeroCount++)
|
|
|
|
|
{
|
|
|
|
|
if (bwSort[zeroCount]!= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WebRtc_UWord32 indexMedian = (BW_HISTORY_SIZE -1) - (BW_HISTORY_SIZE-zeroCount)/2;
|
|
|
|
|
WebRtc_UWord16 bandwidthMedian = bwSort[indexMedian];
|
|
|
|
|
|
|
|
|
|
if (bandwidthMedian > 0)
|
|
|
|
|
{
|
|
|
|
|
if (_estimatedBW == bandwidth)
|
|
|
|
|
{
|
|
|
|
|
// don't trigger a callback
|
|
|
|
|
bandwidthMedian = 0;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
_estimatedBW = bandwidthMedian;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
// can't be negative
|
|
|
|
|
bandwidthMedian = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bandwidthMedian;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we have no critext when calling this
|
|
|
|
|
// we are not allowed to have any critsects when calling CallbackOfReceivedPayloadData
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::ParseVideoCodecSpecific(WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
const WebRtc_UWord8* payloadData,
|
|
|
|
|
const WebRtc_UWord16 payloadDataLength,
|
|
|
|
|
const RtpVideoCodecTypes videoType,
|
|
|
|
|
const bool isRED,
|
|
|
|
|
const WebRtc_UWord8* incomingRtpPacket,
|
2011-12-01 15:42:31 +00:00
|
|
|
const WebRtc_UWord16 incomingRtpPacketSize,
|
|
|
|
|
const WebRtc_Word64 nowMS)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WebRtc_Word32 retVal = 0;
|
|
|
|
|
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Enter();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 15:56:17 +00:00
|
|
|
_videoBitRate.Update(payloadDataLength + rtpHeader->header.paddingLength,
|
|
|
|
|
nowMS);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Add headers, ideally we would like to include for instance
|
|
|
|
|
// Ethernet header here as well.
|
|
|
|
|
const WebRtc_UWord16 packetSize = payloadDataLength + _packetOverHead +
|
|
|
|
|
rtpHeader->header.headerLength + rtpHeader->header.paddingLength;
|
2011-12-01 15:42:31 +00:00
|
|
|
_overUseDetector.Update(*rtpHeader, packetSize, nowMS);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (isRED)
|
|
|
|
|
{
|
|
|
|
|
if(_receiveFEC == NULL)
|
|
|
|
|
{
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Leave();
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-12-16 17:21:09 +00:00
|
|
|
bool FECpacket = false;
|
2012-02-09 12:34:52 +00:00
|
|
|
retVal = _receiveFEC->AddReceivedFECPacket(
|
|
|
|
|
rtpHeader,
|
|
|
|
|
incomingRtpPacket,
|
|
|
|
|
payloadDataLength,
|
|
|
|
|
FECpacket);
|
|
|
|
|
if (retVal != -1)
|
|
|
|
|
retVal = _receiveFEC->ProcessReceivedFEC();
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Leave();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-16 17:21:09 +00:00
|
|
|
if(retVal == 0 && FECpacket)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2011-12-16 17:21:09 +00:00
|
|
|
// Callback with the received FEC packet.
|
|
|
|
|
// The normal packets are delivered after parsing.
|
|
|
|
|
// This contains the original RTP packet header but with
|
|
|
|
|
// empty payload and data length.
|
2011-07-07 08:21:25 +00:00
|
|
|
rtpHeader->frameType = kFrameEmpty;
|
2011-12-16 17:21:09 +00:00
|
|
|
// We need this for the routing.
|
|
|
|
|
WebRtc_Word32 retVal = SetCodecType(videoType, rtpHeader);
|
2011-07-07 08:21:25 +00:00
|
|
|
if(retVal != 0)
|
|
|
|
|
{
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
2011-12-16 17:21:09 +00:00
|
|
|
retVal = CallbackOfReceivedPayloadData(NULL, 0, rtpHeader);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
// will leave the _criticalSectionReceiverVideo critsect
|
|
|
|
|
retVal = ParseVideoCodecSpecificSwitch(rtpHeader,
|
|
|
|
|
payloadData,
|
|
|
|
|
payloadDataLength,
|
|
|
|
|
videoType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the remote rate control object and update the overuse
|
|
|
|
|
// detector with the current rate control region.
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Enter();
|
2011-07-07 08:21:25 +00:00
|
|
|
const RateControlInput input(_overUseDetector.State(),
|
2011-12-01 15:42:31 +00:00
|
|
|
_videoBitRate.BitRate(nowMS),
|
2011-07-07 08:21:25 +00:00
|
|
|
_overUseDetector.NoiseVar());
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Leave();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Call the callback outside critical section
|
2012-01-30 09:03:37 +00:00
|
|
|
if (_rtpRtcp) {
|
|
|
|
|
const RateControlRegion region = _rtpRtcp->OnOverUseStateUpdate(input);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-01-30 09:03:37 +00:00
|
|
|
_criticalSectionReceiverVideo->Enter();
|
|
|
|
|
_overUseDetector.SetRateControlRegion(region);
|
|
|
|
|
_criticalSectionReceiverVideo->Leave();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::BuildRTPheader(const WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
WebRtc_UWord8* dataBuffer) const
|
|
|
|
|
{
|
|
|
|
|
dataBuffer[0] = static_cast<WebRtc_UWord8>(0x80); // version 2
|
|
|
|
|
dataBuffer[1] = static_cast<WebRtc_UWord8>(rtpHeader->header.payloadType);
|
|
|
|
|
if (rtpHeader->header.markerBit)
|
|
|
|
|
{
|
|
|
|
|
dataBuffer[1] |= kRtpMarkerBitMask; // MarkerBit is 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModuleRTPUtility::AssignUWord16ToBuffer(dataBuffer+2, rtpHeader->header.sequenceNumber);
|
|
|
|
|
ModuleRTPUtility::AssignUWord32ToBuffer(dataBuffer+4, rtpHeader->header.timestamp);
|
|
|
|
|
ModuleRTPUtility::AssignUWord32ToBuffer(dataBuffer+8, rtpHeader->header.ssrc);
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32 rtpHeaderLength = 12;
|
|
|
|
|
|
|
|
|
|
// Add the CSRCs if any
|
|
|
|
|
if (rtpHeader->header.numCSRCs > 0)
|
|
|
|
|
{
|
|
|
|
|
if(rtpHeader->header.numCSRCs > 16)
|
|
|
|
|
{
|
|
|
|
|
// error
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
WebRtc_UWord8* ptr = &dataBuffer[rtpHeaderLength];
|
|
|
|
|
for (WebRtc_UWord32 i = 0; i < rtpHeader->header.numCSRCs; ++i)
|
|
|
|
|
{
|
|
|
|
|
ModuleRTPUtility::AssignUWord32ToBuffer(ptr, rtpHeader->header.arrOfCSRCs[i]);
|
|
|
|
|
ptr +=4;
|
|
|
|
|
}
|
|
|
|
|
dataBuffer[0] = (dataBuffer[0]&0xf0) | rtpHeader->header.numCSRCs;
|
|
|
|
|
|
|
|
|
|
// Update length of header
|
|
|
|
|
rtpHeaderLength += sizeof(WebRtc_UWord32)*rtpHeader->header.numCSRCs;
|
|
|
|
|
}
|
|
|
|
|
return rtpHeaderLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::ReceiveRecoveredPacketCallback(WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
const WebRtc_UWord8* payloadData,
|
|
|
|
|
const WebRtc_UWord16 payloadDataLength)
|
|
|
|
|
{
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Enter();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_currentFecFrameDecoded = true;
|
|
|
|
|
|
|
|
|
|
ModuleRTPUtility::Payload* payload = NULL;
|
|
|
|
|
if (PayloadTypeToPayload(rtpHeader->header.payloadType, payload) != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// here we can re-create the original lost packet so that we can use it for the relay
|
|
|
|
|
// we need to re-create the RED header too
|
|
|
|
|
WebRtc_UWord8 recoveredPacket[IP_PACKET_SIZE];
|
|
|
|
|
WebRtc_UWord16 rtpHeaderLength = (WebRtc_UWord16)BuildRTPheader(rtpHeader, recoveredPacket);
|
|
|
|
|
|
|
|
|
|
const WebRtc_UWord8 REDForFECHeaderLength = 1;
|
|
|
|
|
|
|
|
|
|
// replace pltype
|
|
|
|
|
recoveredPacket[1] &= 0x80; // reset
|
|
|
|
|
recoveredPacket[1] += REDPayloadType(); // replace with RED payload type
|
|
|
|
|
|
|
|
|
|
// add RED header
|
|
|
|
|
recoveredPacket[rtpHeaderLength] = rtpHeader->header.payloadType; // f-bit always 0
|
|
|
|
|
|
|
|
|
|
memcpy(recoveredPacket + rtpHeaderLength + REDForFECHeaderLength, payloadData, payloadDataLength);
|
|
|
|
|
|
|
|
|
|
return ParseVideoCodecSpecificSwitch(rtpHeader,
|
|
|
|
|
payloadData,
|
|
|
|
|
payloadDataLength,
|
|
|
|
|
payload->typeSpecific.Video.videoCodecType);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-24 17:16:59 +00:00
|
|
|
WebRtc_Word32 RTPReceiverVideo::SetCodecType(const RtpVideoCodecTypes videoType,
|
|
|
|
|
WebRtcRTPHeader* rtpHeader) const {
|
|
|
|
|
switch (videoType) {
|
2011-07-07 08:21:25 +00:00
|
|
|
case kRtpNoVideo:
|
2012-01-24 17:16:59 +00:00
|
|
|
rtpHeader->type.Video.codec = kRTPVideoGeneric;
|
|
|
|
|
break;
|
2011-07-07 08:21:25 +00:00
|
|
|
case kRtpVp8Video:
|
2012-01-24 17:16:59 +00:00
|
|
|
rtpHeader->type.Video.codec = kRTPVideoVP8;
|
|
|
|
|
break;
|
2011-07-07 08:21:25 +00:00
|
|
|
case kRtpFecVideo:
|
2012-01-24 17:16:59 +00:00
|
|
|
rtpHeader->type.Video.codec = kRTPVideoFEC;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-24 17:16:59 +00:00
|
|
|
WebRtc_Word32 RTPReceiverVideo::ParseVideoCodecSpecificSwitch(
|
|
|
|
|
WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
const WebRtc_UWord8* payloadData,
|
|
|
|
|
const WebRtc_UWord16 payloadDataLength,
|
|
|
|
|
const RtpVideoCodecTypes videoType) {
|
|
|
|
|
WebRtc_Word32 retVal = SetCodecType(videoType, rtpHeader);
|
|
|
|
|
if (retVal != 0) {
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
2012-04-16 12:58:49 +00:00
|
|
|
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, "%s(timestamp:%u)",
|
|
|
|
|
__FUNCTION__, rtpHeader->header.timestamp);
|
|
|
|
|
|
2012-01-24 17:16:59 +00:00
|
|
|
// All receive functions release _criticalSectionReceiverVideo before
|
|
|
|
|
// returning.
|
|
|
|
|
switch (videoType) {
|
2011-07-07 08:21:25 +00:00
|
|
|
case kRtpNoVideo:
|
2012-01-24 17:16:59 +00:00
|
|
|
return ReceiveGenericCodec(rtpHeader, payloadData, payloadDataLength);
|
2011-07-07 08:21:25 +00:00
|
|
|
case kRtpVp8Video:
|
2012-01-24 17:16:59 +00:00
|
|
|
return ReceiveVp8Codec(rtpHeader, payloadData, payloadDataLength);
|
|
|
|
|
case kRtpFecVideo:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_criticalSectionReceiverVideo->Leave();
|
|
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::ReceiveVp8Codec(WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
const WebRtc_UWord8* payloadData,
|
|
|
|
|
const WebRtc_UWord16 payloadDataLength)
|
|
|
|
|
{
|
2011-12-20 15:56:17 +00:00
|
|
|
bool success;
|
2011-07-07 08:21:25 +00:00
|
|
|
ModuleRTPUtility::RTPPayload parsedPacket;
|
2011-12-20 15:56:17 +00:00
|
|
|
if (payloadDataLength == 0)
|
|
|
|
|
{
|
|
|
|
|
success = true;
|
|
|
|
|
parsedPacket.info.VP8.dataLength = 0;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
ModuleRTPUtility::RTPPayloadParser rtpPayloadParser(kRtpVp8Video,
|
|
|
|
|
payloadData,
|
|
|
|
|
payloadDataLength,
|
|
|
|
|
_id);
|
|
|
|
|
|
|
|
|
|
success = rtpPayloadParser.Parse(parsedPacket);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
// from here down we only work on local data
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Leave();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (parsedPacket.info.VP8.dataLength == 0)
|
|
|
|
|
{
|
|
|
|
|
// we have an "empty" VP8 packet, it's ok, could be one way video
|
2011-12-20 15:56:17 +00:00
|
|
|
// Inform the jitter buffer about this packet.
|
|
|
|
|
rtpHeader->frameType = kFrameEmpty;
|
|
|
|
|
if (CallbackOfReceivedPayloadData(NULL, 0, rtpHeader) != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
rtpHeader->frameType = (parsedPacket.frameType == ModuleRTPUtility::kIFrame) ? kVideoFrameKey : kVideoFrameDelta;
|
|
|
|
|
|
2011-08-29 15:37:12 +00:00
|
|
|
RTPVideoHeaderVP8 *toHeader = &rtpHeader->type.Video.codecHeader.VP8;
|
|
|
|
|
ModuleRTPUtility::RTPPayloadVP8 *fromHeader = &parsedPacket.info.VP8;
|
|
|
|
|
|
|
|
|
|
rtpHeader->type.Video.isFirstPacket = fromHeader->beginningOfPartition
|
|
|
|
|
&& (fromHeader->partitionID == 0);
|
|
|
|
|
toHeader->pictureId = fromHeader->hasPictureID ? fromHeader->pictureID :
|
|
|
|
|
kNoPictureId;
|
|
|
|
|
toHeader->tl0PicIdx = fromHeader->hasTl0PicIdx ? fromHeader->tl0PicIdx :
|
|
|
|
|
kNoTl0PicIdx;
|
2011-12-13 14:11:06 +00:00
|
|
|
if (fromHeader->hasTID) {
|
|
|
|
|
toHeader->temporalIdx = fromHeader->tID;
|
|
|
|
|
toHeader->layerSync = fromHeader->layerSync;
|
|
|
|
|
} else {
|
|
|
|
|
toHeader->temporalIdx = kNoTemporalIdx;
|
|
|
|
|
toHeader->layerSync = false;
|
|
|
|
|
}
|
2011-11-25 10:17:00 +00:00
|
|
|
toHeader->keyIdx = fromHeader->hasKeyIdx ? fromHeader->keyIdx : kNoKeyIdx;
|
2011-11-02 23:14:58 +00:00
|
|
|
|
|
|
|
|
toHeader->frameWidth = fromHeader->frameWidth;
|
|
|
|
|
toHeader->frameHeight = fromHeader->frameHeight;
|
|
|
|
|
|
2011-09-08 10:11:24 +00:00
|
|
|
toHeader->partitionId = fromHeader->partitionID;
|
|
|
|
|
toHeader->beginningOfPartition = fromHeader->beginningOfPartition;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if(CallbackOfReceivedPayloadData(parsedPacket.info.VP8.data,
|
|
|
|
|
parsedPacket.info.VP8.dataLength,
|
|
|
|
|
rtpHeader) != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
RTPReceiverVideo::ReceiveGenericCodec(WebRtcRTPHeader* rtpHeader,
|
|
|
|
|
const WebRtc_UWord8* payloadData,
|
|
|
|
|
const WebRtc_UWord16 payloadDataLength)
|
|
|
|
|
{
|
|
|
|
|
rtpHeader->frameType = kVideoFrameKey;
|
|
|
|
|
|
|
|
|
|
if(((SequenceNumber() + 1) == rtpHeader->header.sequenceNumber) &&
|
|
|
|
|
(TimeStamp() != rtpHeader->header.timestamp))
|
|
|
|
|
{
|
|
|
|
|
rtpHeader->type.Video.isFirstPacket = true;
|
|
|
|
|
}
|
2011-12-13 19:17:27 +00:00
|
|
|
_criticalSectionReceiverVideo->Leave();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if(CallbackOfReceivedPayloadData(payloadData, payloadDataLength, rtpHeader) != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPReceiverVideo::SetPacketOverHead(WebRtc_UWord16 packetOverHead)
|
|
|
|
|
{
|
|
|
|
|
_packetOverHead = packetOverHead;
|
|
|
|
|
}
|
|
|
|
|
} // namespace webrtc
|