BuildGraph() публичный Метод

public BuildGraph ( ) : void
Результат void
Пример #1
0
        public GraphBuilderTV TuneChannel(Channel channel, bool needRebuild, GraphBuilderBase currentGraph, VideoControl hostingControl)
        {
            if (needRebuild && currentGraph != null)
            {
                ClearGraph();
                //OnGraphStop();
                //currentGraph.Dispose();
                //currentGraph = null;
            }

            GraphBuilderTV currentGraphTV = currentGraph as GraphBuilderTV;

            if (channel is ChannelDVB)
            {
                ChannelDVB channelDVB = channel as ChannelDVB;

                if (needRebuild)
                {
                    GraphBuilderBDA newGraph = null;
                    switch(this.graphBuilderType)
                    {
                        case GraphBuilderType.BDA:
                            newGraph = new GraphBuilderBDA(hostingControl);
                            break;
                        case GraphBuilderType.BDATimeShifting:
                            newGraph = new GraphBuilderBDATimeShifting(hostingControl);
                            break;
                        case GraphBuilderType.BDAMosaic:
                            newGraph = new GraphBuilderBDAMosaic(hostingControl);
                            break;
                    }
                    newGraph.GraphStarted += new EventHandler(newGraph_GraphStarted);
                    newGraph.GraphEnded += new EventHandler(newGraph_GraphEnded);
                    newGraph.PossibleChanged += new EventHandler<GraphBuilderBase.PossibleEventArgs>(newGraph_PossibleChanged);
                    newGraph.Settings = Settings;
                    currentGraphTV = newGraph;

                    newGraph.ReferenceClock = channelDVB.ReferenceClock;

                    newGraph.AudioDecoderType = channelDVB.AudioDecoderType;
                    DsDevice device;
                    if (!string.IsNullOrEmpty(channelDVB.AudioDecoderDevice))
                    {
                        if (GraphBuilderBDA.AudioDecoderDevices.TryGetValue(channelDVB.AudioDecoderDevice, out device))
                            newGraph.AudioDecoderDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.AudioDeviceNotFound, channelDVB.AudioDecoderDevice));
                    }
                    if (channelDVB.VideoDecoderType == ChannelDVB.VideoType.MPEG2)
                    {
                        if (!string.IsNullOrEmpty(channelDVB.MPEG2DecoderDevice))
                        {
                            if (GraphBuilderBDA.MPEG2DecoderDevices.TryGetValue(channelDVB.MPEG2DecoderDevice, out device))
                                newGraph.Mpeg2DecoderDevice = device;
                            else
                                throw new Exception(string.Format(Properties.Resources.MPEG2DecoderDeviceNotFound, channelDVB.MPEG2DecoderDevice));
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(channelDVB.H264DecoderDevice))
                        {
                            if (GraphBuilderBDA.H264DecoderDevices.TryGetValue(channelDVB.H264DecoderDevice, out device))
                                newGraph.H264DecoderDevice = device;
                            else
                                throw new Exception(string.Format(Properties.Resources.H264DecoderDeviceNotFound, channelDVB.H264DecoderDevice));
                        }
                    }
                    if (!string.IsNullOrEmpty(channelDVB.AudioRendererDevice))
                    {
                        if (GraphBuilderBDA.AudioRendererDevices.TryGetValue(channelDVB.AudioRendererDevice, out device))
                            newGraph.AudioRendererDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.AudioRendererDeviceNotFound, channelDVB.AudioRendererDevice));
                    }
                    if (!string.IsNullOrEmpty(channelDVB.TunerDevice))
                    {
                        if (GraphBuilderBDA.TunerDevices.TryGetValue(channelDVB.TunerDevice, out device))
                            newGraph.TunerDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.TunerDeviceNotFound, channelDVB.TunerDevice));
                    }
                    if (!string.IsNullOrEmpty(channelDVB.CaptureDevice))
                    {
                        if (GraphBuilderBDA.CaptureDevices.TryGetValue(channelDVB.CaptureDevice, out device))
                            newGraph.CaptureDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.CaptureDeviceNotFound, channelDVB.CaptureDevice));
                    }

                    IDVBTuningSpace tuningSpace = (IDVBTuningSpace)new DVBTuningSpace();
                    if (channel is ChannelDVBT)
                    {
                        tuningSpace.put_UniqueName("DVBT TuningSpace");
                        tuningSpace.put_FriendlyName("DVBT TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBTNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Terrestrial);
                    }
                    else if (channel is ChannelDVBC)
                    {
                        tuningSpace.put_UniqueName("DVBC TuningSpace");
                        tuningSpace.put_FriendlyName("DVBC TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBCNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Cable);
                    }
                    else if (channel is ChannelDVBS)
                    {
                        tuningSpace.put_UniqueName("DVBS TuningSpace");
                        tuningSpace.put_FriendlyName("DVBS TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBSNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Satellite);
                    }
                    newGraph.TuningSpace = tuningSpace as ITuningSpace;
                    newGraph.BuildGraph();
                }

                currentGraphTV.SubmitTuneRequest(channel);

                currentGraphTV.VideoZoomMode = channelDVB.VideoZoomMode;
                currentGraphTV.VideoKeepAspectRatio = channelDVB.VideoKeepAspectRatio;
                currentGraphTV.VideoOffset = channelDVB.VideoOffset;
                currentGraphTV.VideoZoom = channelDVB.VideoZoom;
                currentGraphTV.VideoAspectRatioFactor = channelDVB.VideoAspectRatioFactor;

                currentGraphTV.RunGraph();
                //currentGraph.VideoResizer();
                currentGraphTV.CurrentChannel = channel;
            }
            else if (channel is ChannelAnalogic)
            {
                ChannelAnalogic channelAnalogic = channel as ChannelAnalogic;

                if (needRebuild)
                {
                    GraphBuilderWDM newGraph = new GraphBuilderWDM(hostingControl);
                    newGraph.GraphStarted += new EventHandler(newGraph_GraphStarted);
                    newGraph.GraphEnded += new EventHandler(newGraph_GraphEnded);
                    newGraph.PossibleChanged += new EventHandler<GraphBuilderBase.PossibleEventArgs>(newGraph_PossibleChanged);
                    newGraph.Settings = Settings;
                    currentGraphTV = newGraph;

                    DsDevice device;
                    if (GraphBuilderWDM.AudioRendererDevices.TryGetValue(channelAnalogic.AudioRendererDevice, out device))
                        newGraph.AudioRendererDevice = device;
                    if (GraphBuilderWDM.VideoInputDevices.TryGetValue(channelAnalogic.VideoCaptureDeviceName, out device))
                        newGraph.VideoCaptureDevice = device;
                    if (GraphBuilderWDM.AudioInputDevices.TryGetValue(channelAnalogic.AudioCaptureDeviceName, out device))
                        newGraph.AudioCaptureDevice = device;

                    newGraph.FormatOfCapture = channelAnalogic.FormatOfCapture;

                    newGraph.BuildGraph();
                }

                bool goodTuning = true;
                try
                {
                    currentGraphTV.SubmitTuneRequest(channel);
                }
                catch (COMException)
                {
                    goodTuning = false;
                }
                if (goodTuning)
                {
                    currentGraphTV.VideoZoomMode = channelAnalogic.VideoZoomMode;
                    currentGraphTV.VideoKeepAspectRatio = channelAnalogic.VideoKeepAspectRatio;
                    currentGraphTV.VideoOffset = channelAnalogic.VideoOffset;
                    currentGraphTV.VideoZoom = channelAnalogic.VideoZoom;
                    currentGraphTV.VideoAspectRatioFactor = channelAnalogic.VideoAspectRatioFactor;

                    currentGraphTV.RunGraph();
                    //currentGraph.VideoResizer();
                    currentGraphTV.CurrentChannel = channel;
                }
                else
                    currentGraphTV.CurrentChannel = null;
            }
            return currentGraphTV;
        }