コード例 #1
0
        /// <summary>
        /// Waits for the frame extractor to be ready for playback.
        /// Returns true if successful, false if it timed out.
        /// </summary>
        private bool WaitForPlaybackReadyState()
        {
            RealtimeClock.Pause();

            var renderTime = RealtimeClock.PositionSeconds;
            var startTime  = DateTime.UtcNow;
            var cycleCount = -1;
            FFmpegMediaFrame playbackFrame = null;

            while (IsCancellationPending == false)
            {
                if (DateTime.UtcNow.Subtract(startTime) > Constants.WaitForPlaybackReadyStateTimeout)
                {
                    ErrorOccurredCallback(this, new MediaPlaybackException(MediaPlaybackErrorSources.WaitForPlaybackReadyState,
                                                                           MediaPlaybackErrorCode.WaitForPlaybackTimedOut,
                                                                           string.Format("Waiting for playback ready state @ {0:0.000} timed Out in {1} cycles", renderTime, cycleCount)));
                    return(false);
                }

                cycleCount++;

                // Wait for a decoding cycle.
                MediaFramesExtractedDone.Wait(Constants.FrameExtractorWaitMs);
                renderTime    = RealtimeClock.PositionSeconds;
                playbackFrame = PrimaryFramesCache.GetFrame(renderTime, CheckFrameBounds);

                if (playbackFrame == null && PrimaryFramesCache.Count > 0)
                {
                    playbackFrame = PrimaryFramesCache.FirstFrame;
                    RealtimeClock.PositionSeconds = playbackFrame.StartTime;
                }

                if (playbackFrame != null)
                {
                    break;
                }
            }

            // Do some additional logging
            System.Diagnostics.Debug.WriteLineIf(
                cycleCount >= 0,
                string.Format("WaitForPlaybackReadyState @ {0:0.000} = {1} cycles. Leading Frames: {2}, Frame Index: {3}, Frame Start: {4}",
                              renderTime,
                              cycleCount,
                              PrimaryFramesCache.Count,
                              PrimaryFramesCache.IndexOf(playbackFrame),
                              (playbackFrame != null ?
                               playbackFrame.StartTime.ToString("0.000") : "NULL")));

            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Queries if a leading frame for the given position is immediately available.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <returns></returns>
 public bool QueryIsFrameAvailable(decimal position)
 {
     return(PrimaryFramesCache.GetFrame(position, true) != null);
 }