コード例 #1
0
        /// <summary>
        ///     Gets a frame
        /// </summary>
        /// <param name="frame">Referenz to texture where frame should be put in (can be null, then texture is created)</param>
        /// <param name="time">Maximum start time for frame</param>
        /// <param name="finished">Set to whether there are no more frames (stream finished, no loop, future calls will always return false)</param>
        /// <returns>True if a new frame was gotten</returns>
        public bool GetFrame(ref CTextureRef frame, ref float time, out bool finished)
        {
            bool result;

            if (Math.Abs(_LastShownTime - time) < _FrameDuration && frame != null) //Check 1 frame difference
            {
                time   = _LastShownTime;
                result = false;
            }
            else
            {
                CFramebuffer.CFrame curFrame = _FindFrame(time);
                if (curFrame != null)
                {
                    if (frame == null)
                    {
                        frame = CDraw.AddTexture(_Width, _Height, curFrame.Data);
                    }
                    else
                    {
                        CDraw.UpdateTexture(frame, _Width, _Height, curFrame.Data);
                    }
                    if (!_Paused)
                    {
                        curFrame.SetRead();
                    }
                    time           = curFrame.Time;
                    _LastShownTime = time;
                    result         = frame != null;
                }
                else
                {
                    result = false;
                }

                if (_IsSleeping)
                {
                    _IsSleeping = false;
                    _EvWakeUp.Set();
                }
            }
            finished = _NoMoreFrames && _Framebuffer.IsEmpty();

            return(result);
        }
コード例 #2
0
        private CFramebuffer.CFrame _FindFrame(float now)
        {
            CFramebuffer.CFrame result = null;
            CFramebuffer.CFrame frame;
            _Framebuffer.ResetStack();
            while ((frame = _Framebuffer.Pop()) != null)
            {
                //float frameEnd = frame.Time + _FrameDuration;
                float frameTime = frame.Time;

                if (frameTime > now)
                {
                    //2 Cases: all following frames are after this one, or we have a loop and 'now' wrapped over
                    //First case is if we have no loop or we did not wrap or frame is before last one (last is the case if frame is already one of the new iterations, e.g. Last=19 now=1 frame=2)
                    if (!Loop || _LastShownTime <= now || frameTime < _LastShownTime)
                    {
                        break; //Following frames (incl this one) are after now, so do not consider any of them
                    }
                }
                // ReSharper disable CompareOfFloatsByEqualityOperator
                else if (Loop && RequestTime == _LoopedRequestTime)
                // ReSharper restore CompareOfFloatsByEqualityOperator
                {
                    //Frame time might have wrapped but now did not
                    if (frameTime < _LastShownTime && _LastShownTime <= now)
                    {
                        break; //Following frames (incl this one) are after now, so do not consider any of them
                    }
                }
                //Get the last(newest) possible frame and skip the rest
                if (result != null)
                {
                    //Frame is to old -> Discard
                    result.SetRead();
                }
                result = frame;
                if (_Paused)
                {
                    break; //Just get 1 frame if paused otherwise a paused movie could move a bit
                }
            }
            return(result);
        }