/// <summary> /// Retrieves the presentation time of the sample. /// </summary> /// <param name="sample">A valid IMFSample instance.</param> /// <param name="sampleTime">Receives the presentation 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 GetSampleTime(this IMFSample sample, out TimeSpan sampleTime) { if (sample == null) { throw new ArgumentNullException("sample"); } long tmp; HResult hr = sample.GetSampleDuration(out tmp); sampleTime = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
private void DuplicateSample(IMFSample pInSample, out IMFSample pOutSample) { MFError throwonhr; int flags; long lTime; throwonhr = MFExtern.MFCreateSample(out pOutSample); throwonhr = pInSample.CopyAllItems(pOutSample); HResult hr = pInSample.GetSampleDuration(out lTime); if (Succeeded(hr)) { throwonhr = pOutSample.SetSampleDuration(lTime); } hr = pInSample.GetSampleTime(out lTime); if (Succeeded(hr)) { throwonhr = pOutSample.SetSampleTime(lTime); } hr = pInSample.GetSampleFlags(out flags); if (Succeeded(hr)) { throwonhr = pOutSample.SetSampleFlags(flags); } IMFMediaBuffer mb; throwonhr = MFExtern.MFCreateMemoryBuffer(m_imageHeightInPixels * m_imageWidthInPixels * 4, out mb); try { // Set the data size on the output buffer. throwonhr = mb.SetCurrentLength(m_cbImageSizeOutput); throwonhr = pOutSample.AddBuffer(mb); } finally { SafeRelease(mb); } }
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; }