Ejemplo n.º 1
0
        public bool ValidateDataBlock(IDataBlockBuilder dataBlockBuilder, long startOffset, long endOffset)
        {
            if (!IsValidResult())
            {
                return(false);
            }

            dataBlockBuilder.DataFormat   = _state.IsMpeg2() ? CodecID.Mpeg2System : CodecID.Mpeg1System;
            dataBlockBuilder.IsFullFile   = IsFullFile();
            dataBlockBuilder.IsFragmented = _state.IsFragmented;

            // Trim zero byte stuffing from last header (if any)
            if (_state.LastHeaderZeroByteStuffing > 0)
            {
                dataBlockBuilder.EndOffset = endOffset - _state.LastHeaderZeroByteStuffing;
            }
            foreach (ushort streamId in _state.Streams.StreamIds)
            {
                IDataPacket streamData = _state.Streams[streamId].GetStreamData();
                if (streamData != null)
                {
                    string name = GetStreamName(streamId);
                    if (name != null)
                    {
                        ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder.AddCodecStream();
                        codecStreamBuilder.Name                = name;
                        codecStreamBuilder.DataFormat          = name.StartsWith("Video") ? CodecID.Mpeg2Video : CodecID.Unknown;
                        codecStreamBuilder.StreamNumber        = streamId;
                        codecStreamBuilder.Data                = streamData;
                        codecStreamBuilder.AbsoluteStartOffset = codecStreamBuilder.Data.StartOffset;
                    }
                }
            }
            return(true);
        }
            private bool IsContinuousStream(IMpeg2SystemState state, ulong systemClockReference)
            {
                ulong lastSystemClockReference = state.LastSystemClockReference;

                if (lastSystemClockReference == FirstSystemClockReference)
                {
                    return(true);
                }

                // Compare system clock reference to last system clock reference.
                // It should be higher and have a limited time gap.

                if (systemClockReference < lastSystemClockReference)
                {
                    return(false);                    // Indicates a discontinuity because of a backwards jump in time
                }

                ulong timeGap = (systemClockReference - lastSystemClockReference);

                return(timeGap < ((state.IsMpeg2() ? 27E6 : 90E3) * _maxTimeGapSeconds));
            }