Пример #1
0
    IEnumerator DoSeek()
    {
        Transform playerBodyTrans = mPlayer.controller.body.transform;

        while (true)
        {
            switch (mCurSeekMode)
            {
            case SeekMode.Wait:
                DoOrientation(playerBodyTrans.rotation, Time.fixedDeltaTime);

                mCurSeekTime += Time.fixedDeltaTime;
                if (mCurSeekTime >= seekWaitDelay)
                {
                    mCurSeekMode = SeekMode.Towards;
                    mCurSeekTime = 0.0f;
                }
                break;

            case SeekMode.Towards:
                DoOrientation(playerBodyTrans.rotation, Time.fixedDeltaTime);

                mCurSeekTime += Time.fixedDeltaTime;
                if (mCurSeekTime >= seekDelay)
                {
                    mCurSeekTime  = 0.0f;
                    mCurSeekMode  = SeekMode.Return;
                    mSeekToPos    = mLastMoverPos;
                    mLastMoverPos = mEnemy.mover.position;
                }
                else
                {
                    float t = Holoville.HOTween.Core.Easing.Back.EaseInOut(mCurSeekTime, 0.0f, 1.0f, seekDelay, 0, 0);
                    mEnemy.mover.position = Vector3.Lerp(mLastMoverPos, mSeekToPos, t);
                }
                break;

            case SeekMode.Return:
                DoOrientation(mLastMoverRot, Time.fixedDeltaTime);

                mCurSeekTime += Time.fixedDeltaTime;
                if (mCurSeekTime >= returnDelay)
                {
                    mEnemy.mover.rotation = mLastMoverRot;
                    mEnemy.state          = (int)Enemy.State.Normal;
                    yield break;
                }
                else
                {
                    float t = Holoville.HOTween.Core.Easing.Quart.EaseOut(mCurSeekTime, 0.0f, 1.0f, returnDelay, 0, 0);
                    mEnemy.mover.position = Vector3.Lerp(mLastMoverPos, mSeekToPos, t);
                }
                break;
            }

            yield return(mWait);
        }
    }
Пример #2
0
        /// <summary>
        /// Push the current position into a stack and move to a new one.
        /// </summary>
        /// <param name="shift">Distance to move position.</param>
        /// <param name="mode">Mode to move position.</param>
        public void PushToPosition(long shift, SeekMode mode = SeekMode.Start)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(DataStream));
            }

            positionStack.Push(Position);
            Seek(shift, mode);
        }
Пример #3
0
        public void Seek(TimeSpan position, SeekMode mode = SeekMode.Current)
        {
            if (this._connection == null || !this._connection.IsConnected)
            {
                return;
            }

            var offset = (mode == SeekMode.Current) ? (this.GetCurrentPlaybackPosition() + position) : position;

            this._connection.Seek(offset);
        }
Пример #4
0
        /// <summary>
        /// Run a method in a specific position.
        /// This command will move into the position, run the method and return
        /// to the current position.
        /// </summary>
        /// <param name="action">Action to run.</param>
        /// <param name="position">Position to move.</param>
        /// <param name="mode">Mode to move position.</param>
        public void RunInPosition(
            Action action,
            long position,
            SeekMode mode = SeekMode.Start)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            PushToPosition(position, mode);
            action();
            PopPosition();
        }
Пример #5
0
        private static int SeekToSpaceBalanced(this StringView str, int start, SeekMode mode, int step, int indexer_offset)
        {
            int  bracketRank = 0;
            bool quotingFlag = false;
            int  i           = start;

            for (; i.IsWithinRange(0, str.Length); i += step)
            {
                char chr = str[i + indexer_offset];
                if ((mode & SeekMode.PassingQuotation).Flagged())
                {
                    if (chr == '\'')
                    {
                        quotingFlag = !quotingFlag;
                    }
                }
                if (!quotingFlag)
                {
                    if ((mode & SeekMode.BracketBalanced).Flagged())
                    {
                        if (chr.IsOpeningBracket())
                        {
                            bracketRank += 1;
                        }
                        if (chr.IsClosingBracket())
                        {
                            bracketRank -= 1;
                        }
                        if (bracketRank == 0)
                        {
                            if (chr == ' ')
                            {
                                return(i);
                            }
                        }
                    }
                }
            }
            return(i);
        }
Пример #6
0
 private static extern uint Seek(IntPtr pStream, Int64 iOffset, SeekMode eSeekMode);
Пример #7
0
 public uint Seek(long offset, SeekMode mode)
 {
     return Seek(StreamPtr, offset, mode);
 }
Пример #8
0
 // required
 public void Seek(SeekMode unit, string target)
 {
     UPnP.InvokeAction(_service, "Seek", InstanceId, unit.ToString(), target);
 }
Пример #9
0
 // required
 public void Seek(SeekMode unit, string target)
 {
     UPnP.InvokeAction(_service, "Seek", InstanceId, unit.ToString(), target);
 }
Пример #10
0
        /// <summary>
        /// Create a <see cref="FFMSSharp.VideoSource">VideoSource object</see>
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_CreateVideoSource</c>.</para>
        /// <para>Note that the index object is copied into the <see cref="FFMSSharp.VideoSource">VideoSource object</see> upon its creation, so once you've created the video source you can generally destroy the index object immediately, since all info you can retrieve from it is also retrievable from the <see cref="FFMSSharp.VideoSource">VideoSource object</see>.</para>
        /// </remarks>
        /// <param name="sourceFile">The media file. Can be an absolute or relative path</param>
        /// <param name="track">Track number of the specific video track</param>
        /// <param name="threads">Number of threads used for decoding
        /// <para>Anything less than 1 will use threads equal to the number of CPU cores.</para>
        /// <para>Values &gt;1 have no effect if FFmpeg was not compiled with threading support.</para></param>
        /// <param name="seekMode">Controls how seeking (random access) is handled and hence affects frame accuracy
        /// <para>Has no effect on Matroska files, where the equivalent of Normal is always used.</para>
        /// <para>LinearNoRw may come in handy if you want to open images.</para></param>
        /// <returns>The generated <see cref="FFMSSharp.VideoSource">VideoSource object</see></returns>
        /// <seealso cref="AudioSource"/>
        /// <seealso cref="GetFirstTrackOfType"/>
        /// <seealso cref="GetFirstIndexedTrackOfType"/>
        /// <exception cref="System.IO.FileLoadException">Failure to open the <paramref name="sourceFile"/></exception>
        /// <exception cref="System.IO.FileNotFoundException">Trying to read a file that does not exist.</exception>
        /// <exception cref="ArgumentException">Trying to make a VideoSource out of an invalid track</exception>
        /// <exception cref="InvalidOperationException">Supplying the wrong <paramref name="sourceFile"/></exception>
        public VideoSource VideoSource(string sourceFile, int track, int threads = 1, SeekMode seekMode = SeekMode.Normal)
        {
            if (sourceFile == null) throw new ArgumentNullException(@"sourceFile");

            var err = new FFMS_ErrorInfo
            {
                BufferSize = 1024,
                Buffer = new String((char) 0, 1024)
            };

            var sourceFileBytes = Encoding.UTF8.GetBytes(sourceFile);
            var videoSource = NativeMethods.FFMS_CreateVideoSource(sourceFileBytes, track, _handle, threads, (int)seekMode, ref err);

            if (videoSource != IntPtr.Zero) return new VideoSource(videoSource);

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_PARSER && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_READ)
                throw new System.IO.FileLoadException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_NO_FILE)
                throw new System.IO.FileNotFoundException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT)
                throw new ArgumentException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_MISMATCH)
                throw new InvalidOperationException(err.Buffer);

            throw new NotImplementedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown FFMS2 error encountered: ({0}, {1}, '{2}'). Please report this issue on FFMSSharp's GitHub.", err.ErrorType, err.SubType, err.Buffer));
        }
Пример #11
0
 /// <summary>
 /// Seeks within a file.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="seekOffset">The seek offset.</param>
 /// <param name="seekFrom">The seek from.</param>
 /// <returns>The new byte position within the file.</returns>
 public static int FileSeek(UIntPtr handle, int seekOffset, SeekMode seekFrom) => BoardException.ValidateResult(FileSeekUnmanaged(handle, seekOffset, seekFrom));
Пример #12
0
        //============================================================
        //------------------------------------------------------------
        //private static void TopDownTerms(AirTree<StringView>.Node node, StringView str) {
        //  foreach ((BalancedTermType termType, StringView termStr) in str.EachTerm()) {
        //    AirTree<StringView>.Node child = node.AddChild(termStr);
        //    if (termType == BalancedTermType.Bracketed) {
        //      TopDownTerms(child, termStr.GetSubView(+1, termStr.Length - 1));
        //    }
        //  }
        //}
        //public static AirTree<StringView> TopDownTerms(this StringView str) {
        //  var tree = new AirTree<StringView>(str);
        //  TopDownTerms(tree.root, str);
        //  return tree;
        //}
        //public static string TopDownTerms(this string str) {
        //  return str.GetFullView().TopDownTerms().ToString();
        //}
        //------------------------------------------------------------
        //private static void HeadTail(AirTree<StringView>.Node node, StringView str) {
        //  int count = 0;
        //  foreach ((BalancedTermType termType, StringView termStr) in str.EachTerm()) {
        //    if (count++ == 0) {
        //      node.Value = termStr;
        //    } else {
        //      AirTree<StringView>.Node child = node.AddChild(termStr);
        //      if (termType == BalancedTermType.Bracketed) {
        //        HeadTail(child, termStr.GetSubView(+1, termStr.Length - 1));
        //      }
        //    }
        //  }
        //}
        //public static AirTree<StringView> HeadTail(this StringView str) {
        //  var tree = new AirTree<StringView>(str);
        //  HeadTail(tree.root, str);
        //  return tree;
        //}
        //public static string HeadTail(this string str) {
        //  return str.GetFullView().HeadTail().ToString();
        //}
        //============================================================

        public static int Seek(this StringView str, int start, SeekMode mode, Ward1D ward)
        {
            str.ValidateIndex(start);
            return(Mathf.Clamp(str.SeekWithoutClamping(start, mode, ward), 0, str.Length));
        }
Пример #13
0
        /// <summary>
        /// Create a <see cref="FFMSSharp.VideoSource">VideoSource object</see>
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_CreateVideoSource</c>.</para>
        /// <para>Note that the index object is copied into the <see cref="FFMSSharp.VideoSource">VideoSource object</see> upon its creation, so once you've created the video source you can generally destroy the index object immediately, since all info you can retrieve from it is also retrievable from the <see cref="FFMSSharp.VideoSource">VideoSource object</see>.</para>
        /// </remarks>
        /// <param name="sourceFile">The media file. Can be an absolute or relative path</param>
        /// <param name="track">Track number of the specific video track</param>
        /// <param name="threads">Number of threads used for decoding
        /// <para>Anything less than 1 will use threads equal to the number of CPU cores.</para>
        /// <para>Values &gt;1 have no effect if FFmpeg was not compiled with threading support.</para></param>
        /// <param name="seekMode">Controls how seeking (random access) is handled and hence affects frame accuracy
        /// <para>Has no effect on Matroska files, where the equivalent of Normal is always used.</para>
        /// <para>LinearNoRw may come in handy if you want to open images.</para></param>
        /// <returns>The generated <see cref="FFMSSharp.VideoSource">VideoSource object</see></returns>
        /// <seealso cref="AudioSource"/>
        /// <seealso cref="GetFirstTrackOfType"/>
        /// <seealso cref="GetFirstIndexedTrackOfType"/>
        /// <exception cref="System.IO.FileLoadException">Failure to open the <paramref name="sourceFile"/></exception>
        /// <exception cref="System.IO.FileNotFoundException">Trying to read a file that does not exist.</exception>
        /// <exception cref="ArgumentException">Trying to make a VideoSource out of an invalid track</exception>
        /// <exception cref="InvalidOperationException">Supplying the wrong <paramref name="sourceFile"/></exception>
        public VideoSource VideoSource(string sourceFile, int track, int threads = 1, SeekMode seekMode = SeekMode.Normal)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException(@"sourceFile");
            }

            var err = new FFMS_ErrorInfo
            {
                BufferSize = 1024,
                Buffer     = new String((char)0, 1024)
            };

            var sourceFileBytes = Encoding.UTF8.GetBytes(sourceFile);
            var videoSource     = NativeMethods.FFMS_CreateVideoSource(sourceFileBytes, track, _handle, threads, (int)seekMode, ref err);

            if (videoSource != IntPtr.Zero)
            {
                return(new VideoSource(videoSource));
            }

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_PARSER && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_READ)
            {
                throw new System.IO.FileLoadException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_NO_FILE)
            {
                throw new System.IO.FileNotFoundException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT)
            {
                throw new ArgumentException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_MISMATCH)
            {
                throw new InvalidOperationException(err.Buffer);
            }

            throw new NotImplementedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown FFMS2 error encountered: ({0}, {1}, '{2}'). Please report this issue on FFMSSharp's GitHub.", err.ErrorType, err.SubType, err.Buffer));
        }
Пример #14
0
 public static extern void glk_stream_set_position(strid_t str, int pos, SeekMode seekmode);
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SeekOperation"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="mode">The mode.</param>
 public SeekOperation(TimeSpan position, SeekMode mode)
 {
     Position = position;
     Mode     = mode;
 }
Пример #16
0
        public void Seek(long shift, SeekMode mode)
        {
            if (mode == SeekMode.Current)
                this.Position += shift;
            else if (mode == SeekMode.Origin)
                this.Position = this.Offset + shift;
            else if (mode == SeekMode.End)
                this.Position = this.Offset + this.Length - shift;
            else if (mode == SeekMode.Absolute)
                this.Position = shift;

            if (this.Position < this.Offset)
                this.Position = this.Offset;
            if (this.Position > this.Offset + this.Length)
                this.Position = this.Offset + this.Length;

            this.BaseStream.Position = this.Position;
        }
Пример #17
0
        /// <summary>
        /// Seeks the chunk.
        /// </summary>
        /// <returns>The chunk.</returns>
        /// <param name="position">Position.</param>
        /// <param name="mode">Mode.</param>
        public long SeekChunk(int position, SeekMode mode)
        {
            var top = GetCurrentContext();

            if (top == null)
            {
                return((long)ParserStatus.EndOfFile);
            }
            /* pick offset base depending on mode */
            ulong baseOffset;

            switch (mode)
            {
            case SeekMode.Start:
                baseOffset = 0;
                break;

            case SeekMode.Current:
                baseOffset = top.Offset;
                break;

            case SeekMode.End:
                baseOffset = top.Size;
                break;

            default:
                return((long)ParserStatus.BadMode);
            }
            /* Clip position in range of -base..cn_Size-base. Result in newOffset is in range of 0..cn_Size */
            ulong pos;
            ulong newOffset = 0;

            if (position >= 0)
            {
                pos = (ulong)position;
                if (pos < top.Size - baseOffset)
                {
                    newOffset = baseOffset + pos;
                }
                else
                {
                    newOffset = top.Size;
                }
            }
            /* seek on stream */
            var  seekOffset = (long)(newOffset - top.Offset);
            long newStreamPosition, oldStreamPosition;

            if ((oldStreamPosition = _streamOperations.Seek(_ioContext, seekOffset)) < 0)
            {
                return(oldStreamPosition);
            }
            if ((newStreamPosition = _streamOperations.Seek(_ioContext, 0)) < 0)
            {
                return(newStreamPosition);
            }
            if ((newStreamPosition - oldStreamPosition) != seekOffset)
            {
                return((long)ParserStatus.PrematureEndOfFile);
            }
            top.Offset = newOffset;
            return(0);
        }
Пример #18
0
 private static extern int FileSeekUnmanaged(UIntPtr handle, int seekOffset, SeekMode seekFrom);
Пример #19
0
        private IEnumerable <MemoryStream> GetImages(
            int index,
            int count,
            SeekMode seekMode)
        {
            if (count <= 0)
            {
                yield break;
            }

            if (index >= PartitionCount || index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index),
                                                      "Index out of range.");
            }

            if (!Duration.HasValue)
            {
                Duration = GetDuration(FilePath);
            }

            try
            {
                PrepareImageHandle();

                Set(MpvHandle, "hr-seek",
                    seekMode == SeekMode.Precise ? "yes" : "no");
                var stepping = Math.Max(
                    (long)(Duration.Value.TotalSeconds / (PartitionCount + 1)),
                    1);
                Set(MpvHandle, "sstep",
                    stepping.ToString(CultureInfo.InvariantCulture));
                var start = stepping * (index + 1);
                Set(MpvHandle, "start",
                    start.ToString(CultureInfo.InvariantCulture));
                var end = stepping * (index + 1 + count);
                Set(MpvHandle, "end",
                    end.ToString(CultureInfo.InvariantCulture));

                Execute(MpvHandle, "loadfile", FilePath);
            }
            catch (MpvException exc)
            {
                throw new AggregateException(
                          $"Error getting images from '{FilePath}'", exc);
            }

            var counter = 0;

            while (true)
            {
                var eventId = GetEventId(MpvHandle, GetEventIdTimeout);

                if (eventId == EventId.Seek)
                {
                    foreach (var filePath in Directory.GetFiles(OutputPath))
                    {
                        counter++;
                        yield return(new MemoryStream(File.ReadAllBytes(filePath)));

                        File.Delete(filePath);
                        if (counter == count)
                        {
                            yield break;
                        }
                    }
                }

                if (eventId == EventId.EndFile)
                {
                    break;
                }
                if (eventId == EventId.Shutdown)
                {
                    break;
                }
                if (eventId == EventId.None)
                {
                    break;
                }
            }
        }