示例#1
0
        //------------------------------------------------------------------------------
        // Name: Open()
        // Desc: Creates the reader and opens the file.
        //------------------------------------------------------------------------------
        public void Open(string ptszFile)
        {
            Close();

            m_hrAsync = 0;

            //
            // Open input file
            //
            m_pStream.Open(ptszFile);

            //
            // initial state is "not set".
            //
            m_hEvent.Reset();

            //
            // Open the stream
            //
            m_pReader2.OpenStream(m_pStream, this, IntPtr.Zero);

            //
            // Wait for the open to finish
            //
            m_hEvent.WaitOne(-1, false);

            int i;

            m_pReader.GetOutputCount(out i);
            m_SampleCount = new int[i];

            // Turn on the user clock.  This will send samples to IWMReaderCallback::OnSample as fast
            // as it can.  If you comment this line out, samples will be sent at the rate specified
            // in the file (ie a 47 second clip will take 47 seconds to process).
            m_pReader2.SetUserProvidedClock(true);

            //
            // Check open operation result
            //
            if (m_hrAsync < 0)
            {
                throw new COMException("Open failed", m_hrAsync);
            }
        }
示例#2
0
        private void TestOutput()
        {
            int iCount, IFCount;
            IWMOutputMediaProps pProp;

            m_read.GetOutputCount(out iCount);
            Debug.Assert(iCount != 0);

            m_read.GetOutputProps(0, out pProp);
            Debug.Assert(pProp != null);
            m_read.SetOutputProps(0, pProp);

            m_read.GetOutputFormatCount(0, out IFCount);
            Debug.Assert(IFCount != 0);

            pProp = null;
            m_read.GetOutputFormat(0, 0, out pProp);
            Debug.Assert(pProp != null);
        }
示例#3
0
        private void GetAudioOutput()
        {
            int   cOutputs = 0;
            short i;
            IWMOutputMediaProps pProps     = null;
            AMMediaType         pMediaType = null;
            int cbType = 0;

            //
            // Sanity check
            //
            if (IsDisposed())
            {
                throw new COMException("Instance has been Disposed", E_Unexpected);
            }

            //
            // Find out the output count
            //
            m_pReader.GetOutputCount(out cOutputs);

            //
            // Find one audio output.
            // Note: This sample only shows how to handle one audio output.
            //       If there is more than one audio output, the first one will be picked.
            //
            StringBuilder sName = null;

            for (i = 0; i < cOutputs; i++)
            {
                m_pReader.GetOutputProps(i, out pProps);

                try
                {
                    //
                    // Find out the space needed for pMediaType
                    //
                    cbType     = 0;
                    pMediaType = null;
                    pProps.GetMediaType(pMediaType, ref cbType);

                    // Get the name of the output we'll be using
                    sName = null;
                    short iName = 0;
                    pProps.GetConnectionName(sName, ref iName);

                    sName = new StringBuilder(iName);
                    pProps.GetConnectionName(sName, ref iName);

                    pMediaType            = new AMMediaType();
                    pMediaType.formatSize = cbType - Marshal.SizeOf(typeof(AMMediaType));

                    //
                    // Get the value for MediaType
                    //
                    pProps.GetMediaType(pMediaType, ref cbType);

                    try
                    {
                        if (MediaType.Audio == pMediaType.majorType)
                        {
                            m_pWfx = new WaveFormatEx();
                            Marshal.PtrToStructure(pMediaType.formatPtr, m_pWfx);
                            break;
                        }
                    }
                    finally
                    {
                        WMUtils.FreeWMMediaType(pMediaType);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(pProps);
                }
            }

            if (i == cOutputs)
            {
                throw new COMException("Could not find an audio stream in the specified file", E_Unexpected);
            }

            m_dwAudioOutputNum = i;

            // Only deliver samples for the single output
            SetStreams(sName.ToString());
        }