예제 #1
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;
            reader.State.Picture.Reset();
            reader.State.SeenGop = false;

            if ((reader.State.LastHeaderName != null) && (reader.State.LastHeaderName != Slice.Name))
            {
                resultState.Invalidate();
                return;                 // Invalid header sequence
            }

            ISequenceState sequenceState = reader.State.Sequence;

            sequenceState.Reset();
            sequenceState.Initialized    = true;
            sequenceState.HorizontalSize = (ushort)reader.GetBits(12, Attribute.HorizontalSizeValue);
            sequenceState.VerticalSize   = (ushort)reader.GetBits(12, Attribute.VerticalSizeValue);
            reader.GetBits(4, Attribute.AspectRatioInformation, AspectRatioResultFormatter);
            reader.GetBits(4, Attribute.FrameRateCode, FrameRateResultFormatter);
            reader.GetBits(18, Attribute.BitRateValue);
            reader.GetMarker();
            reader.GetBits(10, Attribute.VbvBufferSizeValue);
            reader.GetFlag(Attribute.ConstrainedParametersFlag);

            if (reader.GetFlag(Attribute.LoadIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.IntraQuantiserMatrix, 64);
            }
            if (reader.GetFlag(Attribute.LoadNonIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.NonIntraQuantiserMatrix, 64);
            }
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            if ((reader.State.LastHeaderName != SequenceHeader.Name))
            {
                resultState.Invalidate();
                return;                 // Invalid header sequence
            }

            ISequenceState sequenceState = reader.State.Sequence;

            reader.GetBits(8, Attribute.ProfileAndLevelIndication);
            sequenceState.Progressive  = reader.GetFlag(Attribute.ProgressiveSequence);
            sequenceState.ChromaFormat = (ChromaFormat)reader.GetBits(2, Attribute.ChromaFormat);

            uint horizontalSizeExtension = reader.GetBits(2, Attribute.HorizontalSizeExtension);

            sequenceState.HorizontalSize = (ushort)((sequenceState.HorizontalSize & 0x0fff) | (horizontalSizeExtension << 12));
            uint verticalSizeExtension = reader.GetBits(2, Attribute.VerticalSizeExtension);

            sequenceState.VerticalSize = (ushort)((sequenceState.VerticalSize & 0x0fff) | (verticalSizeExtension << 12));

            reader.GetBits(12, Attribute.BitRateExtension);
            reader.GetMarker();
            reader.GetBits(8, Attribute.VbvBufferSizeExtension);
            reader.GetBits(1, Attribute.LowDelay);
            reader.GetBits(2, Attribute.FrameRateExtensionN);
            reader.GetBits(5, Attribute.FrameRateExtensionD);
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            ScalableMode scalableMode = (ScalableMode)reader.GetBits(2, Attribute.ScalableMode, _scalableModeResultFormatter);

            reader.State.Sequence.ScalableMode = scalableMode;
            reader.GetBits(4, Attribute.LayerID);

            if (scalableMode == ScalableMode.SpatialScalability)
            {
                reader.GetBits(14, Attribute.LowerLayerPredictionHorizontalSize);
                reader.GetMarker();
                reader.GetBits(14, Attribute.LowerLayerPredictionVerticalSize);
                reader.GetBits(5, Attribute.HorizontalSubsamplingFactorM);
                reader.GetBits(5, Attribute.HorizontalSubsamplingFactorN);
                reader.GetBits(5, Attribute.VerticalSubsamplingFactorM);
                reader.GetBits(5, Attribute.VerticalSubsamplingFactorN);
            }
            if (scalableMode == ScalableMode.TemporalScalability)
            {
                if (reader.GetFlag(Attribute.PictureMuxEnable))
                {
                    reader.GetFlag(Attribute.MuxToProgressiveSequence);
                }

                reader.GetBits(3, Attribute.PictureMuxOrder);
                reader.GetBits(3, Attribute.PictureMuxFactor);
            }
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            if (reader.State.LastHeaderName == null)
            {
                // MPEG data cannot start with an extension!
                resultState.Invalidate();
                return;
            }

            var extensionId = (ExtensionId)reader.GetBits(4, Attribute.ExtensionStartCodeIdentifier, _extensionTypeResultFormatter);

            IExtensionParser extensionParser;

            if (!_extensionParsers.TryGetValue(extensionId, out extensionParser) || !CheckExtensionOccurance(reader.State, extensionId))
            {
                resultState.Invalidate();
                return;
            }

            // Note: Do not invoke the reader state here, it is *NOT* recursive!!
            extensionParser.Parse(reader, resultState);

            if (resultState.Valid)
            {
                if (reader.State.Picture.Initialized)
                {
                    reader.State.Picture.AddExtension(extensionId);
                }
                else
                {
                    reader.State.Sequence.AddExtension(extensionId);
                }
            }
        }
예제 #5
0
        public void Parse <T>(IResultParser <T> parser, T reader) where T : IReader
        {
            long offset = reader.Position;

            IResultNodeBuilder resultNodeBuilder = _createResultNodeBuilder();
            IResultNodeState   resultState       = _createResultNodeReaderState(this, resultNodeBuilder);
            IState             previousState     = _activeState.ChangeState(resultState);

            try
            {
                parser.Parse(reader, resultState);
            }
            finally
            {
                _activeState.ChangeState(previousState);
            }

            if (Valid && (reader.Position > offset))
            {
                resultNodeBuilder.DataPacket = reader.GetDataPacket(offset, (reader.Position - offset));
                resultNodeBuilder.Metadata   = _resultMetadata;

                if (!resultState.Valid)
                {
                    resultNodeBuilder.Invalidate();
                }

                _resultNodeCallback.AddNode(_rootResultNode, resultNodeBuilder.Build(), resultState);
            }
        }
예제 #6
0
// ReSharper disable UnusedParameter.Local
        private static void RefPicListModification(INalUnitReader reader, IResultNodeState resultState)
// ReSharper restore UnusedParameter.Local
        {
            bool refPicListReorderingFlag = reader.GetBit();

            if (refPicListReorderingFlag)             // ref_pic_list_reordering_flag_lX
            {
                uint reorderingOfPicNumsIdc;          // reordering_of_pic_nums_idc
                do
                {
                    if (!reader.HasMoreRbspData())
                    {
                        resultState.Invalidate();
                        return;
                    }

                    reorderingOfPicNumsIdc = reader.GetExpGolombCoded();                     // reordering_of_pic_nums_idc

                    if ((reorderingOfPicNumsIdc == 0) || (reorderingOfPicNumsIdc == 1))
                    {
                        reader.GetExpGolombCoded();                         // abs_diff_pic_num_minus1
                    }
                    else if (reorderingOfPicNumsIdc == 2)
                    {
                        reader.GetExpGolombCoded();                         // long_term_pic_num
                    }
                } while (reorderingOfPicNumsIdc != 3);
            }
        }
예제 #7
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            IPictureState pictureState = reader.State.Picture;

            resultState.Name = Name;

            // It can occur after the last slice of the previous picture or after a sequence header
            // or group of pictures header, possible followed by user data and/or extensions.
            if ((reader.State.LastHeaderName != Slice.Name) && pictureState.Initialized)
            {
                resultState.Invalidate();
                return;
            }
            if (!reader.State.Sequence.Initialized && !reader.State.SeenGop)
            {
                reader.InsertReferenceHeaderBeforeStartCode();
            }

            pictureState.Reset();
            reader.State.Slice.Reset();

            reader.GetBits(10, Attribute.TemporalReference);
            var pictureCodingType = (PictureCodingType)reader.GetBits(3, Attribute.PictureCodingType, _pictureCodingTypeResultFormatter);

            pictureState.CodingType = pictureCodingType;
            reader.GetBits(16, Attribute.VbvDelay);

            if ((pictureCodingType == PictureCodingType.PType) || (pictureCodingType == PictureCodingType.BType))
            {
                reader.GetFlag(Attribute.FullPelForwardVector);

                byte forwardFCode = (byte)reader.GetBits(3, Attribute.ForwardFCode);
                pictureState.ForwardHorizontalFCode = forwardFCode;
                pictureState.ForwardVerticalFCode   = forwardFCode;
            }
            if (pictureCodingType == PictureCodingType.BType)
            {
                reader.GetFlag(Attribute.FullPelBackwardVector);

                byte backwardFCode = (byte)reader.GetBits(3, Attribute.BackwardFCode);
                pictureState.BackwardHorizontalFCode = backwardFCode;
                pictureState.BackwardVerticalFCode   = backwardFCode;
            }

            int  count = 0;             // Sanity check
            uint maxExtraInformationLength = reader.State.Configuration.PictureHeaderMaxLengthOfExtraInformation;

            while (reader.ShowBits(1) == 1)
            {
                reader.GetBits(1);                              // ExtraBitPicture
                reader.GetBits(8);                              // ExtraInformationPicture

                if (count++ > maxExtraInformationLength)
                {
                    resultState.Invalidate();
                    return;
                }
            }
        }
 public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
 {
     resultState.Name = Name;
     reader.GetBits(2, Attribute.ReferenceSelectCode);
     reader.GetBits(10, Attribute.ForwardTemporalReference);
     reader.GetMarker();
     reader.GetBits(10, Attribute.BackwardTemporalReference);
 }
예제 #9
0
 public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
 {
     resultState.Name = Name;
     reader.GetFlag(Attribute.CopyrightFlag);
     reader.GetBits(8, Attribute.CopyrightIdentifier);
     reader.GetFlag(Attribute.OriginalOrCopy);                   // TODO: true = original, false = copy
     reader.GetReservedBits(7);
     reader.GetMarker();
     reader.GetAttribute(_copyrightNumberAttribute);
 }
예제 #10
0
        /// <summary>
        /// Parse the ExampleHeader.
        /// </summary>
        /// <param name="reader">The <see cref="IExampleReader"/> for parsing the data</param>
        public void Parse(IExampleReader reader, IResultNodeState resultState)
        {
            // Now parse the header. Implement your own parsing code below.
            reader.GetEqualByteSequence(Attribute.Count);

            if (!reader.GetFinalExampleHeaderByte(Attribute.ValueOfLastByte))
            {
                resultState.Invalidate();
            }
        }
예제 #11
0
        public void Parse(INalUnitReader reader, IResultNodeState resultState)
        {
            reader.GetFixedBits(1, 0, Attribute.ForbiddenZeroBit);
            reader.State.NalRefIdc   = reader.GetBits(2, Attribute.NalRefIdc);
            reader.State.NalUnitType = (NalUnitType)reader.GetBits(5, Attribute.NalUnitType);

            INalUnitPayloadParser nalUnitPayloadParser;

            if (!_nalUnitParsers.TryGetValue(reader.State.NalUnitType, out nalUnitPayloadParser))
            {
                resultState.Invalidate();
                return;
            }

            //Parse remainder with specific nalunitparser (NOTE: Is not a sub-object)
            nalUnitPayloadParser.Parse(reader, resultState);

            if (!resultState.Valid)
            {
                return;                 // Stop processing of invalid NAL unit.
            }
            if (!CanParseNalUnitType(reader.State.SliceState, reader.State.NalUnitType))
            {
                // Forward to the estimated end of the NAL unit
                reader.Position = reader.Length;
                resultState.Invalidate();              // Invalidates the result
                resultState.Recover();                 // Revalidates the reader state so parsing can continue!
                return;
            }

            if (reader.State.NalUnitType == NalUnitType.SequenceParameterSet)
            {
                return;                 // Note: SPS validate their own data!
            }
            if (reader.State.NalUnitType == NalUnitType.PictureParameterSet)
            {
                return;                 // Note: PPS validate their own data!
            }

            if (!IsSlice(reader.State.NalUnitType) || !reader.State.SliceState.PictureState.EntropyCodingMode)
            {
                if (reader.GetBits(1) != 1)                 // rbsp_stop_one_bit (equal to 1)
                {
                    resultState.Invalidate();
                    return;
                }
            }
            if (IsSlice(reader.State.NalUnitType) && resultState.Valid)
            {
                return;                 // Random (e.g. audio) data is allowed after a valid slice
            }

            reader.ReadZeroAlignmentBits();
        }
예제 #12
0
 // 7.3.3.1 Reference picture list modification syntax
 private static void RefPicListModification(INalUnitReader reader, IResultNodeState resultState, SliceType sliceType)
 {
     if (!IsIntraCoded(sliceType))
     {
         RefPicListModification(reader, resultState);
     }
     if (sliceType == SliceType.B)
     {
         RefPicListModification(reader, resultState);
     }
 }
예제 #13
0
        public void Parse(IMpeg2SystemReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            // This header should not be the first header in a block or directly succeeding a program end code
            string lastHeaderName = reader.State.LastHeaderName;

            if ((lastHeaderName == null) || (lastHeaderName == Name))
            {
                resultState.Invalidate();
            }
        }
예제 #14
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            for (int i = GetFrameCenterOffsets(reader); i > 0; i--)
            {
                reader.GetBits(16, Attribute.FrameCenterHorizontalOffset);
                reader.GetMarker();
                reader.GetBits(16, Attribute.FrameCenterVerticalOffset);
                reader.GetMarker();
            }
        }
예제 #15
0
        public void Parse(INalUnitReader reader, IResultNodeState resultState)
        {
            _sliceHeader.Parse(reader, resultState);

            if (reader.Position < reader.Length)
            {
                reader.Result.AddAttribute(Attribute.HeaderEndPosition, GetAbsoluteOffset(reader));
            }

            _sliceData.Parse(reader, resultState);

            // Note: slice_trailing_bits() is handled by INalUnitParser
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;
            reader.State.Sequence.Reset();
            reader.State.Picture.Reset();
            reader.State.SeenGop = false;

            if (reader.State.LastHeaderName != Slice.Name)
            {
                resultState.Invalidate();
                return;                 // Invalid header sequence
            }
        }
예제 #17
0
 public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
 {
     resultState.Name = Name;
     reader.GetBits(10, Attribute.LowerLayerTemporalReference);
     reader.GetMarker();
     reader.GetBits(15, Attribute.LowerLayerHorizontalOffset);
     reader.GetMarker();
     reader.GetBits(15, Attribute.LowerLayerVerticalOffset);
     reader.State.Picture.SpatialScalability = true;
     reader.State.Picture.SpatialTemporalWeightCodeTableIndex = (byte)reader.GetBits(2, Attribute.SpatialTemporalWeightCodeTableIndex);
     reader.GetFlag(Attribute.LowerLayerProgressiveFrame);
     reader.GetFlag(Attribute.LowerLayerDeinterlacedFieldSelect);
 }
        public void Parse(IMpeg2SystemReader reader, IResultNodeState resultState)
        {
            resultState.Name       = Name;
            resultState.ParentName = PackHeader.Name;             // if no pack headers have been encountered, it ends up in the root.

            int bytesRemaining = (int)reader.GetBits(16, Attribute.ProgramStreamMapLength, n => (n >= 10) && (n <= Math.Min(1018, reader.BytesRemaining)));

            if (!resultState.Valid)
            {
                return;
            }

            reader.GetBits(1, Attribute.CurrentNextIndicator);
            reader.GetReservedBits(2);
            reader.GetBits(5, Attribute.ProgramStreamMapVersion);
            reader.GetReservedBits(7);
            reader.GetMarker();

            bytesRemaining -= 2;

            // TODO: issue 2282: MPEG-2 system detector does not implement full specification

            int  maxProgramStreamInfoLength = (bytesRemaining - 2);
            uint programStreamInfoLength    = reader.GetBits(16, Attribute.ProgramStreamInfoLength, n => n <= maxProgramStreamInfoLength);

            if (!resultState.Valid)
            {
                return;
            }

            bytesRemaining -= 2 + reader.SkipBytes((int)programStreamInfoLength);

            int  maxElementaryStreamInfoLength = (bytesRemaining - 2);
            uint elementaryStreamInfoLength    = reader.GetBits(16, Attribute.ElementaryStreamMapLength, n => n <= maxElementaryStreamInfoLength);

            if (!resultState.Valid)
            {
                return;
            }

            bytesRemaining -= 2 + reader.SkipBytes((int)elementaryStreamInfoLength);

            if (bytesRemaining < 4)
            {
                resultState.Invalidate();
                return;
            }

            reader.GetBits(32, Attribute.Crc32);
            reader.SkipBytes(bytesRemaining - 4);
        }
        private bool ParseLongLengthPrefixedNalUnit(IH264Reader reader, IResultNodeState resultState)
        {
            uint nalUnitLength      = reader.GetUInt(NalUnitParser.Attribute.NalUnitLength);
            long nalUnitEndPosition = (reader.Position + nalUnitLength);

            if (nalUnitEndPosition > reader.Length)
            {
                return(false);
            }

            //Parse remainder with specific nalunitparser (NOTE: Is not a sub-object)
            reader.ParseOneNalUnit(_nalUnitParser, resultState, nalUnitEndPosition);

            return(reader.Position == nalUnitEndPosition);
        }
예제 #20
0
        public void Parse(INalUnitReader reader, IResultNodeState resultState)
        {
            var sliceState = reader.State.SliceState;

            if (sliceState == null)
            {
                return;                //Apparently no header data is available, so skip the deepslice parsing.
            }

#if DEBUG
            H264Debug.WriteLine(sliceState.SliceType + " at " + reader.Position + " (" + sliceState.FirstMacroBlockInSlice + ")");
#endif
            var sliceData = CreateSliceData(reader, resultState, sliceState);
            sliceData.Parse();
            H264Debug.DebugEnabled = false;
        }
        public void Parse(INalUnitReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            var state = reader.State;

            if (!state.SequenceStates.Initialized && !state.PictureStates.Initialized)
            {
                if (reader.TryDefaultHeaders(resultState, () => _slice.Parse(reader, resultState)))
                {
                    return;                     // Slice successfully decoded!
                }
            }

            _slice.Parse(reader, resultState);
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;
            reader.GetBits(3, Attribute.VideoFormat, _videoFormatResultFormatter);

            if (reader.GetFlag(Attribute.ColourDescription))
            {
                reader.GetBits(8, Attribute.ColourPrimaries);
                reader.GetBits(8, Attribute.TransferCharacteristics);
                reader.GetBits(8, Attribute.MatrixCoefficients);
            }

            reader.GetBits(14, Attribute.DisplayHorizontalSize);
            reader.GetMarker();
            reader.GetBits(14, Attribute.DisplayVerticalSize);
        }
예제 #23
0
        public void Parse(IMpeg2SystemReader reader, IResultNodeState resultState)
        {
            resultState.Name       = Name;
            resultState.ParentName = PackHeader.Name;

            uint pesPacketLength = reader.GetBits(16, Attribute.PesPacketLength, n => n <= reader.BytesRemaining);

            if (!resultState.Valid)
            {
                return;
            }

            // TODO: issue 2282: MPEG-2 system detector does not implement full specification

            reader.SkipBytes((int)pesPacketLength);
        }
        public void Parse(IH264Reader reader, IResultNodeState resultState)
        {
            long bytesRemaining = (reader.Length - reader.Position);

            if (bytesRemaining < 4)
            {
                resultState.Invalidate();
                return;
            }

            long startPosition = reader.Position;

            // Check whether a sequence parameter set and a picture parameter set are
            // separated by exactly one byte in a NAL unit stream.
            // This is the case for H.264 streams embedded in 3GPP files.
            ulong nextFiveBytes = reader.PeekFiveBytes();

            if ((_state.NalUnitType == NalUnitType.SequenceParameterSet) &&
                !IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 16), bytesRemaining) &&
                IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 8) & 0xffffff, (bytesRemaining - 1)))
            {
                // Skip the byte that is part of the 3GPP container
                reader.Position++;
                bytesRemaining--;
                nextFiveBytes = reader.PeekFiveBytes();
            }
            if (IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 16), bytesRemaining))
            {
                if (ParseShortLengthPrefixedNalUnit(reader, resultState) && resultState.Valid)
                {
                    return;                     // Successfully parse SPS or PPS NAL unit
                }

                resultState.Reset();
                reader.Position = startPosition;
            }
            if (IsLongLengthPrefixedNalUnit(nextFiveBytes, bytesRemaining))
            {
                if (ParseLongLengthPrefixedNalUnit(reader, resultState))
                {
                    return;                     // Successfully parse slice NAL unit
                }
            }

            resultState.Invalidate();
        }
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            // Note: Last header must be a sequence, group of pictures or picture header, or an extension.
            // Note: Sequence end code always ends parsing of a block, so it cannot occur at this point!
            string lastHeader = reader.State.LastHeaderName;

            if ((lastHeader == Slice.Name) || (lastHeader == UserData.Name))
            {
                // User data cannot occur immediately after a slice or (another) user data
                resultState.Invalidate();
                return;
            }

            reader.GetAttribute(_userDataAttribute);
        }
예제 #26
0
        public void Parse(IMpeg2SystemReader reader, IResultNodeState resultState)
        {
            IMpeg2SystemState state = reader.State;

            // Check start code and determine header-specific parsing strategy
            state.StartCode = reader.GetBits(32, Attribute.StartCode, "{0:X8}");

            ISystemHeaderParser headerParser;

            if (!resultState.Valid || !_headerParsers.TryGetValue(state.StartCode, out headerParser))
            {
                resultState.Invalidate();
                return;
            }

            // Invoke the header-specific parsing strategy
            headerParser.Parse(reader, resultState);

            if (!reader.Valid)
            {
                return;
            }

            // Handle stuffing (leading 00's before the next start code)
            uint zeroByteStuffing = reader.GetZeroByteStuffing(Attribute.ZeroByteStuffing);

            if (IsFragmentBreakPoint(state))
            {
                reader.BreakFragment();
                return;
            }

            string headerName = resultState.Name as string;

            // Record the header and (possible) the extension
            if (state.LastHeaderName == null)
            {
                state.FirstHeaderName = headerName;
            }
            state.LastHeaderName             = headerName;
            state.LastHeaderZeroByteStuffing = zeroByteStuffing;
            state.ParsedHeaderCount++;
        }
예제 #27
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            if (reader.GetFlag(Attribute.LoadIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.IntraQuantiserMatrix, 64);
            }
            if (reader.GetFlag(Attribute.LoadNonIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.NonIntraQuantiserMatrix, 64);
            }
            if (reader.GetFlag(Attribute.LoadChromaIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.ChromaIntraQuantiserMatrix, 64);
            }
            if (reader.GetFlag(Attribute.LoadChromaNonIntraQuantiserMatrix))
            {
                reader.GetData(Attribute.ChromaNonIntraQuantiserMatrix, 64);
            }
        }
        public void AddNode(IResultNode rootNode, IResultNode newChildNode, IResultNodeState resultState)
        {
            if (IsSlice(newChildNode))
            {
                _state.SliceCount++;
            }

            // Check occurance of new child node (at this point)
            if (!IsSuitableSibling(_lastHeader, newChildNode))
            {
                resultState.Invalidate();
                return;
            }

            // Add new child node to the tree
            var parent = GetParentFor(rootNode, newChildNode);

            parent.AddChild(newChildNode);
            _lastHeader = newChildNode;
            _state.ParsedHeaderCount++;
        }
예제 #29
0
        public bool TryDefaultHeaders(IResultNodeState resultState, Action evaluateHeader)
        {
            if (!IsDetectingReferenceHeader() || !resultState.Valid)
            {
                return(false);
            }

            // This will make sure the reference headers are tested no more than twice (and not for every slice)
            _state.ReferenceHeadersTestCount++;

            long startPosition = Position;

            // Try reference headers to decode this slice
            foreach (var referenceHeader in ReferenceHeaders)
            {
                // Ignore reference headers with 'byte stream' <-> 'NAL unit stream' format mismatch
                if (referenceHeader.Value.SequenceState.ByteStreamFormat == _state.ByteStreamFormat)
                {
                    referenceHeader.Value.CopyTo(_state);

                    evaluateHeader();

                    // The restult state should be valid *AND* the slice should actually have been decoded!!!!
                    if (resultState.Valid && (_state.SliceState != null))
                    {
                        _state.ReferenceHeader = referenceHeader.Key;
                        return(true);                        // Header successfully decoded!
                    }
                }

                _state.SequenceStates.Clear();
                _state.PictureStates.Clear();

                resultState.Reset();
                Position = startPosition;
            }

            // Not able to decode slice using any reference header, defaulting to unparsable slices
            return(false);
        }
예제 #30
0
        public void Parse(IMpeg2SystemReader reader, IResultNodeState resultState)
        {
            resultState.Name       = Name;
            resultState.ParentName = PackHeader.Name;

            // This header should be preceeded by a pack header, but which may have been overwritten
            if ((reader.State.LastHeaderName != PackHeader.Name) && reader.State.SeenPackHeader /*|| SeenPesPacket)*/)
            {
                resultState.Invalidate();
                return;
            }

            reader.GetBits(16, Attribute.HeaderLength);
            reader.GetMarker();

            uint rateBound = reader.GetBits(22, Attribute.RateBound);

            if (reader.State.SeenPackHeader && (rateBound < reader.State.ProgramMuxRate))
            {
                resultState.Invalidate();
                return;
            }

            reader.GetMarker();
            reader.GetBits(6, Attribute.AudioBound, ab => ab <= 32);
            reader.GetFlag(Attribute.FixedFlag);
            reader.GetFlag(Attribute.CspsFlag);
            reader.GetFlag(Attribute.SystemAudioLockFlag);
            reader.GetFlag(Attribute.SystemVideoLockFlag);
            reader.GetMarker();
            reader.GetBits(5, Attribute.VideoBound, vb => vb <= 16);
            reader.GetFlag(Attribute.PacketRateRestrictionFlag);
            reader.GetReservedBits(7);                  // 0x7F

            // Stream information (MPEG-2 only)
            while (resultState.Valid && (reader.ShowBits(1) == 1))
            {
                resultState.Parse(_streamInfoAttributeParser, reader);
            }
        }