void mTickTimer_Tick(object sender, EventArgs e) { if (mPresentationClock == null) { return; } if (mMediaDuration == 0) { return; } if (mIsSeek) { return; } long lClockTime = 0; long lSystemTime = 0; mPresentationClock.GetCorrelatedTime(0, out lClockTime, out lSystemTime); mSlider.Value = ((double)((double)lClockTime / (double)mMediaDuration)) * mSlider.Maximum; }
/// <summary> /// Retrieves the last clock time that was correlated with system time. /// </summary> /// <param name="clock">A valid IMFClock instance.</param> /// <param name="clockTime">Receives the last known clock time, in units of the clock's frequency.</param> /// <param name="systemTime">Receives the system time that corresponds to the clock time.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetCorrelatedTime(this IMFClock clock, out long clockTime, out TimeSpan systemTime) { if (clock == null) { throw new ArgumentNullException("clock"); } long tmp; HResult hr = clock.GetCorrelatedTime(0, out clockTime, out tmp); systemTime = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
/// <summary> /// Polls the graph for various data about the media that is playing /// </summary> protected override void OnTimerTick() { /* Polls the current position */ if (pClock != null) { long sysTime = 0; long cTime = 0; pClock.GetCorrelatedTime(0, out cTime, out sysTime); if (cTime != m_currentPosition) { m_currentPosition = cTime; InvokeMediaPositionChanged(null); } } base.OnTimerTick(); }
protected bool IsSampleTimePassed(IMFClock pClock, IMFSample pSample) { Debug.Assert(pClock != null); Debug.Assert(pSample != null); if (pSample == null || pClock == null) { throw new COMException("IsSampleTimePassed", E_Pointer); } int hr; bool bRet = false; long hnsTimeNow = 0; long hnsSystemTime = 0; long hnsSampleStart = 0; long hnsSampleDuration = 0; // The sample might lack a time-stamp or a duration, and the // clock might not report a time. try { hr = pClock.GetCorrelatedTime(0, out hnsTimeNow, out hnsSystemTime); MFError.ThrowExceptionForHR(hr); hr = pSample.GetSampleTime(out hnsSampleStart); MFError.ThrowExceptionForHR(hr); hr = pSample.GetSampleDuration(out hnsSampleDuration); MFError.ThrowExceptionForHR(hr); if (hnsSampleStart + hnsSampleDuration < hnsTimeNow) { bRet = true; } } catch { } return bRet; }
public bool ProcessSample(IMFSample pSample, out int plNextSleep) { HResult hr; long hnsPresentationTime = 0; long hnsTimeNow = 0; long hnsSystemTime = 0; bool bPresentNow = true; plNextSleep = 0; if (m_pClock != null) { // Get the sample's time stamp. It is valid for a sample to // have no time stamp. try { hr = pSample.GetSampleTime(out hnsPresentationTime); MFError.ThrowExceptionForHR(hr); // Get the clock time. (But if the sample does not have a time stamp, // we don't need the clock time.) hr = m_pClock.GetCorrelatedTime(0, out hnsTimeNow, out hnsSystemTime); MFError.ThrowExceptionForHR(hr); } catch { } // Calculate the time until the sample's presentation time. // A negative value means the sample is late. long hnsDelta = hnsPresentationTime - hnsTimeNow; if (m_fRate < 0) { // For reverse playback, the clock runs backward. Therefore the delta is reversed. hnsDelta = -hnsDelta; } if (hnsDelta < -m_PerFrame_1_4th) { // This sample is late. bPresentNow = true; } else if (hnsDelta > (3 * m_PerFrame_1_4th)) { // This sample is still too early. Go to sleep. plNextSleep = Utils.MFTimeToMsec(hnsDelta - (3 * m_PerFrame_1_4th)); // Adjust the sleep time for the clock rate. (The presentation clock runs // at m_fRate, but sleeping uses the system clock.) plNextSleep = (int)(plNextSleep / Math.Abs(m_fRate)); // Don't present yet. bPresentNow = false; } } if (bPresentNow) { m_pCB.PresentSample(pSample, hnsPresentationTime); // pSample released by caller along with DeQueue } return(bPresentNow); }