void TestSyncPoint() { int hr; int s1, s2; // Read the value s1 = m_ims.IsSyncPoint(); // Change the value hr = m_ims.SetSyncPoint(s1 != 0); Marshal.ThrowExceptionForHR(hr); // Re-read the value s2 = m_ims.IsSyncPoint(); // Check to see if the change took Debug.Assert(s1 != s2, "Get/Set SyncPoint"); // put the original value back hr = m_ims.SetSyncPoint(s1 == 0); Marshal.ThrowExceptionForHR(hr); // Re-read the value s2 = m_ims.IsSyncPoint(); // Check to see if the change took Debug.Assert(s1 == s2, "Get/Set SyncPoint2"); }
/// <summary> /// Called by the GenericSampleSourceFilter. This routine populates the MediaSample. /// </summary> /// <param name="sample">Pointer to a sample</param> /// <returns>0 = success, 1 = end of stream, negative values for errors</returns> public virtual int SampleCallback(IMediaSample sample) { int hr; IntPtr dataPointer; try { // Get the buffer into which we will copy the data hr = sample.GetPointer(out dataPointer); if (hr >= 0) { // Set TRUE on every sample for uncompressed frames hr = sample.SetSyncPoint(true); if (hr >= 0) { // Find out the amount of space in the buffer int callbackData = sample.GetSize(); hr = this.SetTimeStamps(sample); if (hr >= 0) { int read; // Get copy the data into the sample hr = this.GetImage(this.frameNumber, dataPointer, callbackData, out read); // 1 == End of stream if (hr == 0) { sample.SetActualDataLength(read); // increment the frame number for next time this.frameNumber++; } } } } } finally { // Release our pointer the the media sample. THIS IS ESSENTIAL! If // you don't do this, the graph will stop after about 2 samples. Marshal.ReleaseComObject(sample); } return(hr); }
public static void CopySample(IMediaSample src, IMediaSample dest, bool copySamples) { var sourceSize = src.GetActualDataLength(); if (copySamples) { IntPtr sourceBuffer; src.GetPointer(out sourceBuffer); IntPtr destBuffer; dest.GetPointer(out destBuffer); CopyMemory(destBuffer, sourceBuffer, sourceSize); } // Copy the sample times long start, end; if (src.GetTime(out start, out end) == S_OK) { dest.SetTime(start, end); } if (src.GetMediaTime(out start, out end) == S_OK) { dest.SetMediaTime(start, end); } // Copy the media type AMMediaType mediaType; var changed = src.GetMediaType(out mediaType) == 0; if (changed) { dest.SetMediaType(mediaType); DsUtils.FreeAMMediaType(mediaType); } dest.SetSyncPoint(src.IsSyncPoint() == S_OK); dest.SetPreroll(src.IsPreroll() == S_OK); dest.SetDiscontinuity(src.IsDiscontinuity() == S_OK); // Copy the actual data length dest.SetActualDataLength(sourceSize); }
/// <summary> /// This routine populates the MediaSample. /// </summary> /// <param name="pSample">Pointer to a sample</param> /// <returns>0 = success, 1 = end of stream, negative values for errors</returns> public int MediaSampleCB(IMediaSample pSample) { int hr; try { IntPtr pData; hr = pSample.GetPointer(out pData); if (hr >= 0) { hr = pSample.SetSyncPoint(true); if (hr >= 0) { var len = Source.Read(pData, Constants.DShowNumberOfPacketsTS); if (len != 0) { hr = 0; pSample.SetActualDataLength(len); } else { //hr = 1; hr = 0; } } } } catch (Exception ex) { Log.ErrorException("Error in Sample handler.", ex); hr = -1; } finally { Marshal.ReleaseComObject(pSample); } return(hr); }
/// <summary> /// Calculate and populate the timestamps /// </summary> /// <param name="pSample">The IMediaSample to set the timestamps on</param> /// <returns>HRESULT</returns> override public int SetTimeStamps(IMediaSample pSample) { // Time per frame int tpf = (UNIT / m_Fps); DsLong rtStart = new DsLong(m_rtSampleTime); m_rtSampleTime += tpf; DsLong rtStop = new DsLong(m_rtSampleTime); // Set the times into the sample int hr = pSample.SetTime(rtStart, rtStop); // Set TRUE on every sample for uncompressed frames if (hr >= 0) { hr = pSample.SetSyncPoint(true); } return(hr); }
public static void CopySample(IMediaSample src, IMediaSample dest, bool copySamples) { var sourceSize = src.GetActualDataLength(); if (copySamples) { IntPtr sourceBuffer; src.GetPointer(out sourceBuffer); IntPtr destBuffer; dest.GetPointer(out destBuffer); CopyMemory(destBuffer, sourceBuffer, sourceSize); } // Copy the sample times long start, end; if (src.GetTime(out start, out end) == S_OK) { dest.SetTime(start, end); } if (src.GetMediaTime(out start, out end) == S_OK) { dest.SetMediaTime(start, end); } // Copy the media type AMMediaType mediaType; src.GetMediaType(out mediaType); dest.SetMediaType(mediaType); DsUtils.FreeAMMediaType(mediaType); dest.SetSyncPoint(src.IsSyncPoint() == S_OK); dest.SetPreroll(src.IsPreroll() == S_OK); dest.SetDiscontinuity(src.IsDiscontinuity() == S_OK); // Copy the actual data length dest.SetActualDataLength(sourceSize); }
/// <summary> /// Calculate and populate the timestamps /// </summary> /// <param name="pSample">The IMediaSample to set the timestamps on</param> /// <returns>HRESULT</returns> public override int SetTimeStamps(IMediaSample pSample) { // Time per frame int tpf = (UNIT / m_Fps); DsLong rtStart = new DsLong(m_rtSampleTime); m_rtSampleTime += tpf; DsLong rtStop = new DsLong(m_rtSampleTime); // Set the times into the sample int hr = pSample.SetTime(rtStart, rtStop); // Set TRUE on every sample for uncompressed frames if (hr >= 0) { hr = pSample.SetSyncPoint(true); } return hr; }
/// <summary> /// Called by the GenericSampleSourceFilter. This routine populates the MediaSample. /// </summary> /// <param name="pSample">Pointer to a sample</param> /// <returns>0 = success, 1 = end of stream, negative values for errors</returns> public virtual int SampleCallback(IMediaSample pSample) { int hr; IntPtr pData; try { // Get the buffer into which we will copy the data hr = pSample.GetPointer(out pData); if (hr >= 0) { // Set TRUE on every sample for uncompressed frames hr = pSample.SetSyncPoint(true); if (hr >= 0) { // Find out the amount of space in the buffer int cbData = pSample.GetSize(); hr = SetTimeStamps(pSample); if (hr >= 0) { int iRead; // Get copy the data into the sample hr = GetImage(m_iFrameNumber, pData, cbData, out iRead); if (hr == 0) // 1 == End of stream { pSample.SetActualDataLength(iRead); // increment the frame number for next time m_iFrameNumber++; } } } } } finally { // Release our pointer the the media sample. THIS IS ESSENTIAL! If // you don't do this, the graph will stop after about 2 samples. Marshal.ReleaseComObject(pSample); } return hr; }
/// <summary> /// This routine populates the MediaSample. /// </summary> /// <param name="pSample">Pointer to a sample</param> /// <returns>0 = success, 1 = end of stream, negative values for errors</returns> public int MediaSampleCB(IMediaSample pSample) { int hr; try { IntPtr pData; hr = pSample.GetPointer(out pData); if (hr >= 0) { hr = pSample.SetSyncPoint(true); if (hr >= 0) { var len = Source.Read(pData, Constants.DShowNumberOfPacketsTS); if (len != 0) { hr = 0; pSample.SetActualDataLength(len); } else { //hr = 1; hr = 0; } } } } catch(Exception ex) { Log.ErrorException("Error in Sample handler.", ex); hr = -1; } finally { Marshal.ReleaseComObject(pSample); } return hr; }