public InNetRTPStream(RtspProtocol _rtsp, StreamsManager streamsManager, string _streamName, StreamCapabilities _streamCapabilities, TimeSpan _rtcpDetectionInterval) : base(_rtsp, streamsManager, _streamName) { bandwidth = _streamCapabilities.BandwidthHint; this._rtcpDetectionInterval = _rtcpDetectionInterval; Capabilities = _streamCapabilities; _currentNalu = Utils.Rms.GetStream(); _hasAudio = _streamCapabilities.AudioCodecId != AudioCodec.Unknown; _hasVideo = _streamCapabilities.VideoCodecId != VideoCodec.Unknown; _rtcpPresence = RtcpPresence.Unknown; }
public override bool FeedData(Stream pData, uint dataLength, uint processedLength, uint totalLength, uint absoluteTimestamp, bool isAudio) { switch (_rtcpPresence) { case RtcpPresence.Unknown: if (_rtcpDetectionInterval == TimeSpan.Zero) { WARN("RTCP disabled on stream {0}({1}) with name {2}. A/V drifting may occur over long periods of time", Type.TagToString(), UniqueId, Name); _rtcpPresence = RtcpPresence.Absent; return(true); } if (_rtcpDetectionStart == DateTime.MinValue) { _rtcpDetectionStart = DateTime.Now; return(true); } if (DateTime.Now - _rtcpDetectionStart > _rtcpDetectionInterval) { WARN("Stream {0}({1}) with name {2} doesn't have RTCP. A/V drifting may occur over long periods of time", Type.TagToString(), UniqueId, Name); _rtcpPresence = RtcpPresence.Absent; return(true); } var audioRTCPPresent = !_hasAudio || _audioNTP != 0; var videoRTCPPresent = !_hasVideo || _videoNTP != 0; if (audioRTCPPresent && videoRTCPPresent) { _rtcpPresence = RtcpPresence.Available; } return(true); case RtcpPresence.Available: var rtp = isAudio ? _audioRTP : _videoRTP; var ntp = isAudio ? _audioNTP : _videoNTP; absoluteTimestamp = (uint)(ntp + absoluteTimestamp - rtp); break; case RtcpPresence.Absent: var firstTimestamp = isAudio ? _audioFirstTimestamp : _videoFirstTimestamp; if (firstTimestamp < 0) { firstTimestamp = absoluteTimestamp; } absoluteTimestamp -= (uint)firstTimestamp; break; default: return(false); } var lastTs = isAudio ? _audioLastTs : _videoLastTs; if (-1.0 < lastTs * 100.0 - absoluteTimestamp * 100.0 && lastTs * 100.0 - absoluteTimestamp * 100.0 < 1.0) { absoluteTimestamp = lastTs; } if (lastTs > absoluteTimestamp) { WARN("Back time on {0} ATS:{1} LTS:{2} D:{3}", Name, absoluteTimestamp, lastTs, lastTs - absoluteTimestamp); return(true); } if (isAudio) { _audioLastTs = absoluteTimestamp; } else { _videoLastTs = absoluteTimestamp; } if (!_avCodecsSent) { foreach (var temp in OutStreams.Where(x => !x.IsEnqueueForDelete())) { SignalOutStreamAttached(temp); } if (!_avCodecsSent) { return(true); } } if (_hasAudio && _hasVideo && ((_audioLastTs == 0) || (_videoLastTs == 0))) { return(true); } return(base.FeedData(pData, dataLength, processedLength, totalLength, absoluteTimestamp, isAudio)); }