コード例 #1
0
ファイル: MainForm.cs プロジェクト: babgvant/EVRPlay
        private void SetupGraphForRateChange(double rate)
        {
            int hr = 0;

            if (ps.UseCustomAudioRenderer)
            {
                if (device == null)
                {
                    MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
                    if (!string.IsNullOrEmpty(ps.AudioPlaybackDevice))
                        device = DevEnum.GetDevice(ps.AudioPlaybackDevice);

                    if (device == null)
                        device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
                }

                //if (rate > Math.Abs(1.5))
                //{
                //    //if(fVol == float.MinValue)
                //    //    fVol = device.AudioEndpointVolume.MasterVolumeLevelScalar;
                //    //device.AudioEndpointVolume.MasterVolumeLevelScalar = 0;
                //    device.AudioEndpointVolume.Mute = true;
                //}
                //else if (rate <= Math.Abs(1.5))
                //{
                //    //if (fVol > float.MinValue)
                //    //{
                //    //    device.AudioEndpointVolume.MasterVolumeLevelScalar = fVol;
                //    //    fVol = float.MinValue;
                //    //}
                //    device.AudioEndpointVolume.Mute = false;
                //}

                IBasicAudio ba = graphBuilder as IBasicAudio;
                if (ba != null)
                {
                    int orgVol = 0;
                    hr = ba.get_Volume(out orgVol);
                    DsError.ThrowExceptionForHR(hr);

                    if (Math.Abs(rate) > 1.5)
                    {
                        hr = ba.put_Volume(-10000); //turn off the volume so we can ffwd
                        DsError.ThrowExceptionForHR(hr);
                    }
                    else if (Math.Abs(rate) <= 1.5)
                    {
                        hr = ba.put_Volume(0); //set the volume back to full
                        DsError.ThrowExceptionForHR(hr);
                    }
                }
            }
            else
            {
                IPin arIn = null;

                try
                {
                    if (Math.Abs(rate) > 4 && m_adecOut == null)
                    {
                        //find the audio renderer
                        if (audioRenderer == null)
                            audioRenderer = FilterGraphTools.FindFilterByClsid(graphBuilder, m_audioRendererClsid);

                        if (audioRenderer != null)
                        {
                            hr = audioRenderer.GetClassID(out m_audioRendererClsid);
                            DsError.ThrowExceptionForHR(hr);

                            //grab the audio decoder's output pin
                            arIn = DsFindPin.ByDirection(audioRenderer, PinDirection.Input, 0);
                            hr = arIn.ConnectedTo(out m_adecOut);
                            DsError.ThrowExceptionForHR(hr);

                            //stop the graph
                            hr = mediaControl.Stop();
                            DsError.ThrowExceptionForHR(hr);

                            //remove it
                            hr = graphBuilder.RemoveFilter(audioRenderer);
                            DsError.ThrowExceptionForHR(hr);

                            //start the graph again
                            hr = mediaControl.Run();
                            DsError.ThrowExceptionForHR(hr);
                        }
                    }
                    else if (Math.Abs(rate) <= 4 && m_adecOut != null)
                    {
                        //audioRenderer = FilterGraphTools.AddFilterFromClsid(graphBuilder, m_audioRendererClsid, "Audio Renderer");
                        if (audioRenderer != null)
                        {
                            //stop the graph
                            hr = mediaControl.Stop();
                            DsError.ThrowExceptionForHR(hr);

                            hr = graphBuilder.AddFilter(audioRenderer, "Audio Renderer");
                            DsError.ThrowExceptionForHR(hr);

                            //connect it to the decoder pin
                            arIn = DsFindPin.ByDirection(audioRenderer, PinDirection.Input, 0);
                            hr = graphBuilder.ConnectDirect(m_adecOut, arIn, null);
                            DsError.ThrowExceptionForHR(hr);

                            Marshal.ReleaseComObject(m_adecOut);
                            m_adecOut = null;

                            //start the graph again
                            hr = mediaControl.Run();
                            DsError.ThrowExceptionForHR(hr);
                        }
                    }

                    if (Math.Abs(rate) <= 4)
                    {
                        //{601D2A2B-9CDE-40BD-8650-0485E3522727}
                        //{EC9ED6FC-7B03-4CB6-8C01-4EABE109F26B}
                        IBasicAudio ba = graphBuilder as IBasicAudio;
                        if (ba != null)
                        {
                            int orgVol = 0;
                            hr = ba.get_Volume(out orgVol);
                            DsError.ThrowExceptionForHR(hr);

                            if (Math.Abs(rate) > 1.5)
                            {

                                hr = ba.put_Volume(-10000); //turn off the volume so we can ffwd
                                DsError.ThrowExceptionForHR(hr);
                            }
                            else if (Math.Abs(rate) <= 1.5)
                            {
                                hr = ba.put_Volume(0); //set the volume back to full
                                DsError.ThrowExceptionForHR(hr);
                            }
                        }
                    }
                }
                finally
                {
                    //if (audioRenderer != null)
                    //    Marshal.ReleaseComObject(audioRenderer);
                    if (arIn != null)
                        Marshal.ReleaseComObject(arIn);
                }
            }
        }