protected override bool FeedDataVideo(Stream pData, uint dataLength, uint processedLength, uint totalLength, uint absoluteTimestamp,
bool isAudio)
{
var pos = pData.Position;
_videoBytesCount += dataLength;
_videoPacketsCount++;
//1. Test and see if this is an inbound RTMP stream. If so,
//we have to strip out the RTMP 9 bytes header
var inStreamType = InStream.Type;
if ((inStreamType == ST_IN_NET_RTMP)
|| (inStreamType == ST_IN_NET_LIVEFLV))
{
//2. Test and see if we have a brand new packet
if (processedLength == 0)
{
//3.This must be a payload packet, not codec setup
pData.ReadByte();
if (pData.ReadByte() != 1)
return true;
//4. since this is a brand new packet, empty previous buffer
_videoBuffer.IgnoreAll();
pData.Position -= 2;
}
//5. Store the data into the buffer
pData.CopyPartTo(_videoBuffer,(int) dataLength);
//6. Test and see if this is the last chunk of the RTMP packet
if (dataLength + processedLength == totalLength)
{
//7. This is the last chunk. Get the pointer and length
pData = _videoBuffer;
pData.Position = 0;
dataLength = (uint) _videoBuffer.GetAvaliableByteCounts();
//8. We must have at least 9 bytes (RTMP header size)
if (dataLength < 9)
{
WARN("Bogus packet");
return true;
}
//9. Read the composition timestamp and add it to the
//absolute timestamp
pData.Position = 1;
var compositionTimeStamp = (pData.ReadUInt()) & 0x00ffffff;
absoluteTimestamp += compositionTimeStamp;
//10. Ignore RTMP header and composition offset
dataLength -= 5;
uint nalSize = 0;
//uint32_t tsIncrement = 0;
//11. Start looping over the RTMP payload. Each NAL has a 4 bytes
//header indicating the length of the following NAL
while (dataLength >= 4)
{
//12. Read the nal size and compare it to the actual amount
//of data remaining on the buffer
nalSize = pData.ReadUInt();
pos = pData.Position;
if (nalSize > (dataLength - 4))
{
WARN("Bogus packet");
return true;
}
//13. skip theNAL size field
dataLength -= 4;
//14. Is this a 0 sized NAL? if so, skip it
if (nalSize == 0)
continue;
//15. Feed the NAL unit using RTP FUA
if (!FeedDataVideoFUA(pData, nalSize, 0, nalSize,
absoluteTimestamp))
{ //+ (double) tsIncrement / 90000.00)) {
FATAL("Unable to feed data");
return false;
}
//16. move to the next NAL
dataLength -= nalSize;
}
}
return true;
}
else
{
//17. This is NAL stream. Feed it as it is
return FeedDataVideoFUA(pData, dataLength, processedLength, totalLength,absoluteTimestamp);
}
}