/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Called when the sample grabber sink processes a sample. We can use this
        /// to do what we want with the sample
        /// </summary>
        /// <param name="guidMajorMediaType">the media type</param>
        /// <param name="sampleFlags">the sample flags</param>
        /// <param name="sampleSize">the sample size</param>
        /// <param name="sampleDuration">the sample duration</param>
        /// <param name="sampleTimeStamp">the sample time</param>
        /// <param name="sampleBuffer">the sample buffer</param>
        /// <param name="sampleAttributes">the attributes for the sample</param>
        /// <history>
        ///    01 Nov 18  Cynic - Ported in
        /// </history>
        public HResult OnProcessSampleEx(Guid guidMajorMediaType, int sampleFlags, long sampleTimeStamp, long sampleDuration, IntPtr sampleBuffer, int sampleSize, IMFAttributes sampleAttributes)
        {
            IMFSample outputSample = null;
            HResult   hr;

            try
            {
                if (sinkWriter == null)
                {
                    string errMsg = "OnProcessSample, Error sinkWriter==null";
                    SampleGrabberAsyncCallBackError(this, errMsg, null);
                    return(HResult.E_FAIL);
                }

                // we have all the information we need to create a new output sample
                outputSample = TantaWMFUtils.CreateMediaSampleFromIntPtr(sampleFlags, sampleTimeStamp, sampleDuration, sampleBuffer, sampleSize, sampleAttributes);
                if (outputSample == null)
                {
                    string errMsg = "OnProcessSample, Error on call to CreateMediaSampleFromBuffer outputSample == null";
                    SampleGrabberAsyncCallBackError(this, errMsg, null);
                    return(HResult.E_FAIL);
                }

                lock (sinkWriter)
                {
                    // write the sample out
                    hr = sinkWriter.WriteSample(sinkWriterMediaStreamId, outputSample);
                    if (Failed(hr))
                    {
                        string errMsg = "OnProcessSample, Error on WriteSample =" + hr.ToString();
                        SampleGrabberAsyncCallBackError(this, errMsg, null);
                        return(hr);
                    }

                    // if you do not set MF_SINK_WRITER_DISABLE_THROTTLING on the sink writer, the
                    // calls below can sometimes be useful to avoid the sink writer stalling for a bit
                    // while it waits for one stream or the other. In fact is a bit disconcerting
                    // that we do not seem to get any of these in the sample grabber.

                    //    sinkWriter.SendStreamTick(sinkWriterMediaStreamId, sampleTimeStamp);
                    //    sinkWriter.NotifyEndOfSegment(sinkWriterMediaStreamId);
                }
            }
            finally
            {
                if (outputSample != null)
                {
                    Marshal.ReleaseComObject(outputSample);
                    outputSample = null;
                }
            }

            return(HResult.S_OK);
        }
Esempio n. 2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Called when the sample grabber sink processes a sample. We can use this
        /// to do what we want with the media data
        /// </summary>
        /// <param name="guidMajorMediaType">the media type</param>
        /// <param name="sampleFlags">the sample flags</param>
        /// <param name="sampleSize">the sample size</param>
        /// <param name="sampleDuration">the sample duration</param>
        /// <param name="sampleTimeStamp">the sample time</param>
        /// <param name="sampleBuffer">the sample buffer</param>
        /// <param name="sampleAttributes">the attributes for the sample</param>
        /// <history>
        ///    01 Nov 18  Cynic - Ported in
        /// </history>
        public HResult OnProcessSampleEx(Guid guidMajorMediaType, int sampleFlags, long sampleTimeStamp, long sampleDuration, IntPtr sampleBuffer, int sampleSize, IMFAttributes sampleAttributes)
        {
            IMFSample outputSample = null;
            HResult   hr;

            try
            {
                if (sinkWriter == null)
                {
                    string errMsg = "OnProcessSample, Error sinkWriter==null";
                    SampleGrabberAsyncCallBackError(this, errMsg, null);
                    return(HResult.E_FAIL);
                }

                // we have all the information we need to create a new output sample
                outputSample = TantaWMFUtils.CreateMediaSampleFromIntPtr(sampleFlags, sampleTimeStamp, sampleDuration, sampleBuffer, sampleSize, null);
                if (outputSample == null)
                {
                    string errMsg = "OnProcessSample, Error on call to CreateMediaSampleFromBuffer outputSample == null";
                    SampleGrabberAsyncCallBackError(this, errMsg, null);
                    return(HResult.E_FAIL);
                }

                // write the sample out
                hr = sinkWriter.WriteSample(sinkWriterMediaStreamId, outputSample);
                if (Failed(hr))
                {
                    string errMsg = "OnProcessSample, Error on WriteSample =" + hr.ToString();
                    SampleGrabberAsyncCallBackError(this, errMsg, null);
                    return(hr);
                }
            }
            finally
            {
                if (outputSample != null)
                {
                    Marshal.ReleaseComObject(outputSample);
                    outputSample = null;
                }
            }

            return(HResult.S_OK);
        }