Ejemplo n.º 1
0
        public bool TryDefaultHeaders(IResultState resultState, Action evaluateHeader)
        {
            if (_state.ReferenceHeadersTested)
            {
                return(false);                // TODO: If the first picture fail to decode using any of the reference headers, subsequent pictures that may work will not be tested!
            }

            // This will make sure the default headers are tested just once and not for every slice
            _state.ReferenceHeadersTested = true;

            if (ReferenceHeaders.Count == 0)
            {
                return(false);
            }

            long startPosition = Position;
            bool isMpeg2       = _state.Picture.HasExtension(ExtensionId.PictureCodingExtensionId);

            // Try reference headers to decode this slice
            foreach (var referenceHeader in ReferenceHeaders)
            {
                // Ignore reference headers with MPEG-1 <-> MPEG-2 mismatch
                if (referenceHeader.Value.HasExtension(ExtensionId.SequenceExtensionId) == isMpeg2)
                {
                    referenceHeader.Value.CopyTo(_state.Sequence);

                    evaluateHeader();
                    //ParseSlice(reader, resultState);

                    if (resultState.Valid)
                    {
                        _state.ReferenceHeader = referenceHeader.Key;
                        return(true);                        // Header successfully decoded!
                    }
                }

                resultState.Reset();
                _dataReader.Position = startPosition;
            }

            // Not able to decode slice using any default header, defaulting to unparsable slices
            _state.Sequence.Reset();

            return(false);
        }
 public void EndResult()
 {
     Result = null;
 }
        //public override ExampleHeader GetNextHeader(ExampleHeader previousHeader, long offsetLimit)
        //{
        //    const int nextHeaderLength = 1;

        //    if (Position > (Length - nextHeaderLength))
        //    {
        //        return null;
        //    }

        //    // Try to read the directly succeeding chunk
        //    byte nextExampleHeaderType = NextExampleHeaderType();

        //    return CreateExampleHeader(previousHeader, nextExampleHeaderType);
        //}

        ///// <summary>
        ///// Creates an example header of the given <param name="exampleHeaderType"/>.
        ///// </summary>
        ///// <param name="previousHeader">the directly preceeding header</param>
        ///// <param name="exampleHeaderType">the type of example header to create</param>
        ///// <returns>the example header</returns>
        //private static ExampleHeader CreateExampleHeader(ExampleHeader previousHeader, byte exampleHeaderType)
        //{
        //    switch (exampleHeaderType)
        //    {
        //        case (byte)ExampleHeaderName.ExampleHeader: return new ExampleHeader(previousHeader);
        //    }
        //    return null;
        //}

        public void StartResult(IResultState resultState)
        {
            Result = resultState;
        }