Example #1
0
        public int ReadFrameHeader()
        {
            if (_FirstFrameTimestamp == -1)
            {
                _FirstFrameTimestamp = ManagedStopwatch.GetTimestamp();
            }
            if (_NextFrameLength == -1)
            {
                _NextFrameLength = ReadNextFrameLength();
            }
            var frameLength = _NextFrameLength;

            _NextFrameLength = -1;
            _StreamPosition += frameLength;
            return(frameLength);
        }
Example #2
0
        public long WaitForFrameTimestamp(int clockRate)
        {
            var elapsedTicks  = ManagedStopwatch.GetTimestamp() - _FirstFrameTimestamp;
            var nanoTimestamp = (_ClusterTimecode + _ClusterBlockTimecode) * _SegmentInfo.TimecodeScale;
            var tickTimestamp = nanoTimestamp / 100;

            if (tickTimestamp > elapsedTicks)
            {
                // hold up
                ManagedThread.Sleep((int)((tickTimestamp - elapsedTicks) / Constants.TicksPerMillisecond));
            }

            _ClusterBlockTrackNumber = -1;
            _ClusterBlockTimecode    = -1;
            _ClusterBlockFlags       = 0;

            return(clockRate * tickTimestamp / Constants.TicksPerSecond);
        }