Example #1
0
        public int Request(IMediaSample pSample, IntPtr dwUser)
        {
            int hr;

            Debug.Write(string.Format("Request {0} user: {1}", pSample != null, dwUser));

            MediaHolder mh = new MediaHolder(pSample, dwUser);

            lock (this) // Protect the m_ variables
            {
                if (!m_GraphIsFlushing)
                {
                    // Now that we have populated everything, wait for the splitter to call the
                    // WaitForNext() method to retrieve the data
                    m_Requests.Enqueue(mh);

                    // Let the waiting thread in WaitForNext know something is ready for
                    // processing
                    m_Wait.Set();

                    hr = S_Ok;
                }
                else
                {
                    hr = DsResults.E_WrongState;
                }
            }

            Debug.WriteLine(hr.ToString());

            return(hr);
        }
Example #2
0
        public int WaitForNext(int dwTimeout, out IMediaSample ppSample, out IntPtr pdwUser)
        {
            int hr;

            Debug.WriteLine(string.Format("WaitForNext {0}", dwTimeout));

            // In case something goes wrong
            ppSample = null;
            pdwUser  = IntPtr.Zero;

            if (!m_GraphIsFlushing)
            {
                // Count threads we have waiting
                Interlocked.Increment(ref m_ThreadsWaiting);

                bool bWait = m_Wait.WaitOne(dwTimeout, false);

                lock (this)
                {
                    // If we found one before timing out, send it back
                    if (bWait && !m_GraphIsFlushing)
                    {
                        MediaHolder mh = m_Requests.Dequeue() as MediaHolder;
                        ppSample = mh.Sample;
                        pdwUser  = mh.User;

                        hr = PopulateMediaSample(ppSample);
                    }
                    else
                    {
                        hr = DsResults.E_Timeout;
                    }

                    // If there is another request, reset the event.  Also
                    // if the graph is flushing, allow the other threads
                    // to exit
                    if ((m_Requests.Count > 0) || (m_GraphIsFlushing))
                    {
                        m_Wait.Set();
                    }
                }

                // Count threads we have waiting
                Interlocked.Decrement(ref m_ThreadsWaiting);
            }
            else
            {
                hr = DsResults.E_WrongState;
            }

            return(hr);
        }