コード例 #1
0
        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);
                }
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #5
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;
                }
            }
        }
コード例 #6
0
 public Mpeg2VideoCarver(IMpeg2VideoReader reader, IResultParser <IMpeg2VideoReader> videoHeaderParser, IScanContext scanContext)
 {
     _reader            = reader;
     _videoHeaderParser = videoHeaderParser;
     _scanContext       = scanContext;
     _state             = reader.State;
     _minHeaderCount    = (uint)Mpeg2VideoDetector.Configurable[Mpeg2VideoDetector.ConfigurationKey.MinVideoHeaderCount];
 }
 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);
 }
コード例 #8
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);
 }
コード例 #9
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();
            }
        }
コード例 #10
0
        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
            }
        }
コード例 #11
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);
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
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);
            }
        }
コード例 #15
0
 /// <summary>
 /// Computes the number of frame center offsets in the header.
 /// </summary>
 private static int GetFrameCenterOffsets(IMpeg2VideoReader reader)
 {
     if (reader.State.Sequence.Progressive)
     {
         if (reader.State.Picture.RepeatFirstField)
         {
             if (reader.State.Picture.TopFieldFirst)
             {
                 return(3);
             }
             else
             {
                 return(2);
             }
         }
         else
         {
             return(1);
         }
     }
     else
     {
         // TODO: next line may be wrong !!!!
         if (reader.State.Picture.Structure != PictureStructure.FramePicture)
         {
             return(1);
         }
         else
         {
             if (reader.State.Picture.RepeatFirstField)
             {
                 return(3);
             }
             else
             {
                 return(2);
             }
         }
     }
 }
 public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
 {
     resultState.Name = Name;
     reader.GetReservedBits(1);
     reader.GetBits(7, Attribute.CameraID);
     reader.GetMarker();
     reader.GetBits(22, Attribute.HeightOfImageDevice);
     reader.GetMarker();
     reader.GetBits(22, Attribute.FNumber);
     reader.GetMarker();
     reader.GetBits(22, Attribute.VerticalAngleOfView);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionXUpper);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionXLower);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionYUpper);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionYLower);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionZUpper);
     reader.GetMarker();
     reader.GetBits(16, Attribute.CameraPositionZLower);
     reader.GetMarker();
     reader.GetBits(22, Attribute.CameraDirectionX);
     reader.GetMarker();
     reader.GetBits(22, Attribute.CameraDirectionY);
     reader.GetMarker();
     reader.GetBits(22, Attribute.CameraDirectionZ);
     reader.GetMarker();
     reader.GetBits(22, Attribute.ImagePlaneVerticalX);
     reader.GetMarker();
     reader.GetBits(22, Attribute.ImagePlaneVerticalY);
     reader.GetMarker();
     reader.GetBits(22, Attribute.ImagePlaneVerticalZ);
     reader.GetMarker();
     reader.GetReservedBits(32);
 }
コード例 #17
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

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

            IPictureState pictureState = reader.State.Picture;

            pictureState.ForwardHorizontalFCode  = (byte)reader.GetBits(4, Attribute.ForwardHorizontalFCode);
            pictureState.ForwardVerticalFCode    = (byte)reader.GetBits(4, Attribute.ForwardVerticalFCode);
            pictureState.BackwardHorizontalFCode = (byte)reader.GetBits(4, Attribute.BackwardHorizontalFCode);
            pictureState.BackwardVerticalFCode   = (byte)reader.GetBits(4, Attribute.BackwardVerticalFCode);
            reader.GetBits(2, Attribute.IntraDCPrecision);
            pictureState.Structure                = (PictureStructure)reader.GetBits(2, Attribute.PictureStructure, _pictureStructureResultFormatter);
            pictureState.TopFieldFirst            = reader.GetFlag(Attribute.TopFieldFirst);
            pictureState.FramePredFrameDct        = reader.GetFlag(Attribute.FramePredFrameDct);
            pictureState.ConcealmentMotionVectors = reader.GetFlag(Attribute.ConcealmentMotionVectors);
            reader.GetBits(1, Attribute.QuantiserScaleType);
            pictureState.IntraVlcFormat = (reader.GetBits(1, Attribute.IntraVlcFormat) == 0) ? false : true;
            reader.GetFlag(Attribute.AlternateScan);
            pictureState.RepeatFirstField = reader.GetFlag(Attribute.RepeatFirstField);
            reader.GetFlag(Attribute.Chroma420Type);
            reader.GetFlag(Attribute.ProgressiveFrame);

            if (reader.GetFlag(Attribute.CompositeDisplayFlag))
            {
                reader.GetBits(1, Attribute.VAxis);
                reader.GetBits(3, Attribute.FieldSequence);
                reader.GetBits(1, Attribute.SubCarrier);
                reader.GetBits(7, Attribute.BurstAmplitude);
                reader.GetBits(8, Attribute.SubCarrierPhase);
            }
        }
コード例 #18
0
        public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
        {
            resultState.Name = Name;

            IMpeg2VideoState state = reader.State;

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

            state.SeenGop = true;
            state.Picture.Reset();

            reader.GetAttribute(_timeCodeAttribute);
            reader.GetFlag(Attribute.ClosedGop);
            reader.GetFlag(Attribute.BrokenLink);
        }
コード例 #19
0
 public void Parse(IMpeg2VideoReader reader, IResultNodeState resultState)
 {
     resultState.Name = Name;
 }