protected override void AddSourceFilter()
        {
            string sourceFilterName = GetSourceFilterName(_resourceAccessor.ResourcePathName);

            if (!string.IsNullOrEmpty(sourceFilterName))
            {
                IBaseFilter sourceFilter = null;
                try
                {
                    if (sourceFilterName == MPUrlSourceFilter.Downloader.FilterName)
                    {
                        _filterWrapper = FilterLoader.LoadFilterFromDll(
                            Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"MPUrlSourceSplitter\MPUrlSourceSplitter.ax"),
                            new Guid(MPUrlSourceFilter.Downloader.FilterCLSID));
                        sourceFilter = _filterWrapper.GetFilter();
                        if (sourceFilter != null)
                        {
                            _graphBuilder.AddFilter(sourceFilter, MPUrlSourceFilter.Downloader.FilterName);
                        }
                    }
                    else
                    {
                        sourceFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, sourceFilterName);
                    }

                    if (sourceFilter == null)
                    {
                        throw new OnlineVideosException(string.Format("Could not create instance of source filter: '{0}'", sourceFilterName));
                    }

                    var filterStateEx = sourceFilter as MPUrlSourceFilter.IFilterStateEx;
                    if (filterStateEx != null)
                    {
                        LoadAndWaitForMPUrlSourceFilter(filterStateEx);
                    }
                    else
                    {
                        var fileSourceFilter = sourceFilter as IFileSourceFilter;
                        if (fileSourceFilter != null)
                        {
                            Marshal.ThrowExceptionForHR(fileSourceFilter.Load(_resourceAccessor.ResourcePathName, null));
                        }
                        else
                        {
                            throw new OnlineVideosException(string.Format("'{0}' does not implement IFileSourceFilter", sourceFilterName));
                        }
                    }

                    FilterGraphTools.RenderOutputPins(_graphBuilder, sourceFilter);
                }
                finally
                {
                    FilterGraphTools.TryRelease(ref sourceFilter);
                }
            }
            else
            {
                base.AddSourceFilter();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructs a new OggWriter
        /// </summary>
        public OggWriter() : base()
        {
            oggMux = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.LegacyAmFilterCategory, "LEAD Ogg Multiplexer");
            if (oggMux == null)
            {
                throw new Exception("Could not instantiate OGG Mux!");
            }

            fileWriter = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.LegacyAmFilterCategory, "File writer");
            if (fileWriter == null)
            {
                throw new Exception("File writer could not be instantiated");
            }

            IFileSinkFilter fs = fileWriter as IFileSinkFilter;

            if (fs == null)
            {
                throw new Exception(@"Can't get IFileSinkFilter interface!");
            }

            string datetime = DateTime.Now.ToString("yyMMdd HHmmss");

            int hr = fs.SetFileName(@"C:\temp\" + datetime + " oggwriter.ogm", null);

            DsError.ThrowExceptionForHR(hr);
        }
Beispiel #3
0
        public FVDO2FCNSink()
        {
            fastVDO = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "FastVDO-SmartCapture QBoxSplitter");
            fcsink  = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "FC Network Sink");

            FilterGraphTools.ConnectFilters(_graphBuilder, fastVDO, "Video", fcsink, "Input 1", false);
        }
Beispiel #4
0
        public FVDO2FCNSink()
        {
            fastVDO = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FastVDO-SmartCapture QBoxSplitter");
            fcsink  = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FC Network Sink");

            FilterGraphTools.ConnectFilters(graph, fastVDO, "Video", fcsink, "Input 1", false);

            FCNSinkProxy p = new FCNSinkProxy(fcsink);


            UInt16 basePort = 5000;

            for (int i = 0; i < p.StreamCount; i++)
            {
                p.Interface.SetPortAllocation(i, basePort, 0);
                basePort += 2;
            }

            List <RTPStreamDescription> streams = p.Streams;

            //System.Diagnostics.Debug.WriteLine("streams.Count");

            //XmlSerializer s = new XmlSerializer(typeof(RTPStreamDescription));
            //MemoryStream mem = new MemoryStream();
            //s.Serialize(mem, streams[0]);
        }
Beispiel #5
0
        /// <summary>
        /// Adds the subtitle filter to the graph. The caller need to call <see cref="Marshal.ReleaseComObject"/> on the
        /// returned instance when done.
        /// </summary>
        /// <param name="graphBuilder">The IGraphBuilder</param>
        /// <returns>DvbSub2(3) filter instance</returns>
        public IBaseFilter AddSubtitleFilter(IGraphBuilder graphBuilder)
        {
            try
            {
                _filter    = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, FilterName);
                _subFilter = _filter as IDVBSubtitleSource;
                ServiceRegistration.Get <ILogger>().Debug("SubtitleRenderer: CreateFilter success: " + (_filter != null) + " & " + (_subFilter != null));
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error(e);
            }
            if (_subFilter != null)
            {
                _subFilter.StatusTest(111);
                _callBack = OnSubtitle;

                IntPtr pCallback = Marshal.GetFunctionPointerForDelegate(_callBack);
                _subFilter.SetBitmapCallback(pCallback);

                _subFilter.StatusTest(222);

                IntPtr pResetCallBack = Marshal.GetFunctionPointerForDelegate(_resetCallBack);
                _subFilter.SetResetCallback(pResetCallBack);

                IntPtr pUpdateTimeoutCallBack = Marshal.GetFunctionPointerForDelegate(_updateTimeoutCallBack);
                _subFilter.SetUpdateTimeoutCallback(pUpdateTimeoutCallBack);
            }
            return(_filter);
        }
Beispiel #6
0
        public ATSCTuner(Config.Graph sourceConfig, Control hostControl)
            : base(sourceConfig, hostControl)
        {
            tunerFilter   = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDASourceFiltersCategory, GraphConfig[FilterType.Tuner].Name);
            captureFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDAReceiverComponentsCategory, GraphConfig[FilterType.Capture].Name);

            r_videoTee = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Infinite Pin Tee Filter");
            r_audioTee = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Infinite Pin Tee Filter");

            if (audioDecoder != null)
            {
                mediaLooksAudioDecoder = audioDecoder as IMLAudioDecoder;
                if (mediaLooksAudioDecoder != null)
                {
                    Debug.WriteLine("MediaLooks Audio Decoder detected! Setting Pass-through Input Time Stamps = true");
                    mediaLooksAudioDecoder.UseInputTimeStamps(1);
                }

                AddAudioVolumeFilter();
                AddAudioRenderer();
            }

            if ((AppUser.Current.ChannelIndex >= 0) && (AppUser.Current.ChannelIndex < this.KnownChannels.Count))
            {
                this.StartupChannel = this.KnownChannels.Items[AppUser.Current.ChannelIndex];
            }
        }
Beispiel #7
0
        public override void Render()
        {
            if (_tuner == null)
            {
                throw new ArgumentNullException("_tuner", "No Tuner Device present");
            }

            _timeStampAdjustFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "FC Time Stamp Adjust");
            _smartTeeFilter        = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Smart Tee");

            ConnectFilters(_tuner, "Analog Video", _crossbar2, "0: Video Tuner In", true);
            ConnectFilters(_tuner, "Analog Audio", _tvaudio, "TVAudio In", true);
            ConnectFilters(_tvaudio, "TVAudio Out", _crossbar2, "3: Audio Tuner In", true);

            ConnectFilters(_crossbar2, "0: Video Decoder Out", _captureFilter, "Analog Video In", true);
            ConnectFilters(_crossbar2, "1: Audio Decoder Out", _captureFilter, "Analog Audio In", true);
//            ConnectFilters(_captureFilter, "Capture",  _videoRender, "VMR Input0", true);
            ConnectFilters(_captureFilter, "Capture", _timeStampAdjustFilter, "Input", true);
            ConnectFilters(_timeStampAdjustFilter, "Output", _smartTeeFilter, "Input", true);
            ConnectFilters(_smartTeeFilter, "Capture", _videoRender, "VMR Input0", true);

            AddAudioRenderer();

            ConnectToAudio(_captureFilter, "Audio", true);

            ConfigTV();

            RouteCrossbarPins(DirectShowLib.PhysicalConnectorType.Video_VideoDecoder, DirectShowLib.PhysicalConnectorType.Video_Tuner);
            RouteCrossbarPins(DirectShowLib.PhysicalConnectorType.Audio_AudioDecoder, DirectShowLib.PhysicalConnectorType.Audio_Tuner);

            this.SaveGraphFile();
            CaptureRequiresNewGraph = false;

            base.Render();
        }
Beispiel #8
0
        /// <summary>
        /// Call this method to insert the Audio Volume filter into your graph. Input pin is "In" and output pin is "Out"
        /// </summary>
        protected void AddAudioVolumeFilter()
        {
            _audioVolumeFilter          = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, @"FC Volume Filter");
            _audioVolumeFilterInterface = (IFCVolumeMute)_audioVolumeFilter;

            MaxVolume = 0;
            MinVolume = -40;
        }
        /// <summary>
        /// Try to add filter by name to graph.
        /// </summary>
        /// <param name="codecInfo">Filter name to add</param>
        /// <param name="filterCategory">GUID of filter category (<see cref="FilterCategory"/> members)></param>
        /// <returns>true if successful</returns>
        protected bool TryAdd(CodecInfo codecInfo, Guid filterCategory)
        {
            if (codecInfo == null)
            {
                return(false);
            }
            IBaseFilter tempFilter = FilterGraphTools.AddFilterByName(_graphBuilder, filterCategory, codecInfo.Name);

            return(tempFilter != null);
        }
Beispiel #10
0
        protected IBaseFilter AddFilterByName(IGraphBuilder gb, Guid filterCategory, string friendlyName)
        {
            IBaseFilter filter = FilterGraphTools.AddFilterByName(gb, filterCategory, friendlyName);

            if (filter == null)
            {
                throw new Exception("The DirectShow filter " + friendlyName + " not found.");
            }
            return(filter);
        }
Beispiel #11
0
        public static void AddStreamSourceFilter(string sourceFilterName, IResourceAccessor resourceAccessor, IGraphBuilder graphBuilder, out FilterFileWrapper filterWrapper)
        {
            filterWrapper = null;
            IBaseFilter sourceFilter = null;

            try
            {
                if (sourceFilterName == Utils.FilterName)
                {
                    var filterPath = FileUtils.BuildAssemblyRelativePath(@"MPUrlSourceSplitter\MPUrlSourceSplitter.ax");
                    filterWrapper = FilterLoader.LoadFilterFromDll(filterPath, new Guid(Utils.FilterCLSID));
                    sourceFilter  = filterWrapper.GetFilter();
                    if (sourceFilter != null)
                    {
                        graphBuilder.AddFilter(sourceFilter, Utils.FilterName);
                    }
                }
                else
                {
                    sourceFilter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, sourceFilterName);
                }

                if (sourceFilter == null)
                {
                    throw new UPnPRendererExceptions(string.Format("Could not create instance of source filter: '{0}'", sourceFilterName));
                }

                string url = resourceAccessor.ResourcePathName;

                var filterStateEx = sourceFilter as OnlineVideos.MPUrlSourceFilter.IFilterStateEx;
                if (filterStateEx != null)
                {
                    LoadAndWaitForMPUrlSourceFilter(url, filterStateEx);
                }
                else
                {
                    var fileSourceFilter = sourceFilter as IFileSourceFilter;
                    if (fileSourceFilter != null)
                    {
                        Marshal.ThrowExceptionForHR(fileSourceFilter.Load(resourceAccessor.ResourcePathName, null));
                    }
                    else
                    {
                        throw new UPnPRendererExceptions(string.Format("'{0}' does not implement IFileSourceFilter", sourceFilterName));
                    }
                }

                FilterGraphTools.RenderOutputPins(graphBuilder, sourceFilter);
            }
            finally
            {
                FilterGraphTools.TryRelease(ref sourceFilter);
            }
        }
Beispiel #12
0
        public FCNSource2VMR()
        {
            source = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FC Network Source");
            xform  = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "H.264 Byte Stream Transform");
            dec    = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "LEAD H264 Decoder (3.0)");
            vmr    = FilterGraphTools.AddFilterByDevicePath(graph, @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{6BC1CFFA-8FC1-4261-AC22-CFB4CC38DB50}", "VMR7");

            FilterGraphTools.ConnectFilters(graph, source, "Output 1", xform, "XForm In", false);
            FilterGraphTools.ConnectFilters(graph, xform, "XForm Out", dec, "XForm In", false);
            FilterGraphTools.ConnectFilters(graph, dec, "XForm Out", vmr, "VMR Input0", false);
        }
Beispiel #13
0
        private void btnVideoDecoderSettings_Click(object sender, EventArgs e)
        {
            string        decoderName = null;
            SourcesConfig config      = SourcesConfig.LoadFromFile();
            Source        s           = config[cbTunerDevice.SelectedItem as string];

            if (s.Name.Equals(VideoInputDeviceList.NetworkDeviceName))
            {
                decoderName = s[TVSource.Network][FilterType.VideoDecoder].Name;
            }
            else if (s.HasGraphFor(TVSource.LocalDigital))
            {
                decoderName = s[TVSource.LocalDigital][FilterType.VideoDecoder].Name;
            }

            if (string.IsNullOrEmpty(decoderName))
            {
                FCMessageBox.Show("No Decoder Specified!", "No video decoder is specified for this particular tuner.", this);
                return;
            }

            IGraphBuilder g = null;
            IBaseFilter   f = null;

            try
            {
                g = (IGraphBuilder) new FilterGraph();
                f = FilterGraphTools.AddFilterByName(g, FilterCategory.LegacyAmFilterCategory, decoderName) as IBaseFilter;

                if (f == null)
                {
                    throw new Exception("Could not instantiate video decoder \"" + decoderName + "\"!");
                }

                FilterPropertyPage propPage = new FilterPropertyPage(this, f);
                propPage.Show();
            }
            catch (Exception ex)
            {
                FCMessageBox.Show("Error!", ex.Message, this);
            }
            finally
            {
                if (f != null)
                {
                    Marshal.ReleaseComObject(f);
                }
                if (g != null)
                {
                    Marshal.ReleaseComObject(g);
                }
            }
        }
Beispiel #14
0
        protected void AddFileSource()
        {
            IBaseFilter sourceFilter = null;

            try
            {
                sourceFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, SOURCE_FILTER_NAME);
                FilterGraphTools.RenderOutputPins(_graphBuilder, sourceFilter);
            }
            finally
            {
                FilterGraphTools.TryRelease(ref sourceFilter);
            }
        }
Beispiel #15
0
        private void AddLeadNetSrc()
        {
            int hr;

            _netSrcMediaType           = new AMMediaType();
            _netSrcMediaType.majorType = MediaType.Stream;
            _netSrcMediaType.subType   = MediaSubType.LeadToolsStreamFormat;

            _netSrc     = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD Network Source (2.0)");
            _fileSource = (IFileSourceFilter)_netSrc;
            if (_fileSource == null)
            {
                throw new Exception("IFileSourceFilter not found on lmNetSrc");
            }
            LoadNetSrcURL();
        }
Beispiel #16
0
        protected override void AddSourceFilter()
        {
            base.AddSourceFilter();
            //var muxer = new CodecInfo { CLSID = "{E4B7FAF9-9CFF-4FD5-AC16-0F250F5F97B7}", Name = "SolveigMM Matroska Muxer" };
            var muxer = new CodecInfo {
                CLSID = "{A28F324B-DDC5-4999-AA25-D3A7E25EF7A8}", Name = "Haali Matroska Muxer"
            };
            IBaseFilter muxerFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, muxer.Name);

            // FileSink can be supported by muxer directly (Haali), or we need an additional file sink
            var fileSink = muxerFilter as IFileSinkFilter;

            if (fileSink == null)
            {
                var writer = new CodecInfo {
                    CLSID = "{8596E5F0-0DA5-11D0-BD21-00A0C911CE86}", Name = "File writer"
                };
                fileSink = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, writer.Name) as IFileSinkFilter;
            }

            if (fileSink != null)
            {
                fileSink.SetFileName(_targetFilename, null);
            }

            using (DSFilter sourceFilter = new DSFilter(_streamSourceFilter))
                using (DSFilter muxerF = new DSFilter(muxerFilter))
                {
                    for (int index = 0; index < sourceFilter.Output.Count; index++)
                    {
                        DSPin pin = sourceFilter.Output[index];
                        using (pin)
                        {
                            if (index < muxerF.Input.Count)
                            {
                                pin.Connect(muxerF.Input[index]);
                            }
                        }
                    }

                    if (muxerF.OutputPin != null)
                    {
                        using (DSFilter writerF = new DSFilter((IBaseFilter)fileSink))
                            muxerF.OutputPin.Connect(writerF.InputPin);
                    }
                }
        }
Beispiel #17
0
        /// <summary>
        /// Add the LEAD DVR Source filter to a graph (builder) and
        /// load the fileSource using the associated input graph's
        /// source name (from sourceConfig).  For example, if the output
        /// graph source name was "Vid1-RTSP" then the input graph
        /// source name will have a name of "Vid1".
        /// <DVRSourceName> --> <LeftOfSinkSourceName>
        /// Vid1-RTSP (the output graph source name) --> Vid1 (the input graph source name)
        /// </summary>
        public static IBaseFilter GetAndConfigureDVRSourceForSink(IGraphBuilder builder, StreamSourceInfo sourceConfig)
        {
            IBaseFilter result = FilterGraphTools.AddFilterByName(builder, FilterCategory.LegacyAmFilterCategory, "LEAD DVR Source");

            if (result == null)
            {
                throw new Exception("The LEADTOOLS DVR Source filter is not registered");
            }
            IFileSourceFilter fileSource = (IFileSourceFilter)result;

            String[]    sourceNameParts = sourceConfig.SourceName.Split('-');
            DVRSettings dvrSettings     = DVRSettings.LoadFromFile();
            int         hr = fileSource.Load(dvrSettings.RootFolder + sourceNameParts[0] + @"/Stream.LBL", null);

            DsError.ThrowExceptionForHR(hr);
            ILMDVRSource sourceControl = (ILMDVRSource)result;

            sourceControl.ResetToDefaultsEx(LMDVRSource_APILEVEL.LMDVRSource_APILEVEL_1);
            return(result);
        }
Beispiel #18
0
        public override void RenderCapture(string fileName)
        {
            //add new filters
            r_oggMux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD Ogg Multiplexer");
            if (r_oggMux == null)
            {
                throw new Exception("Could not instantiate OGG Multiplexer!");
            }
            _fileWriter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, GraphConfig[FilterType.Writer].Name);
            if (_fileWriter == null)
            {
                throw new Exception("Could not instatiate \"" + GraphConfig[FilterType.Writer].Name + "\"!");
            }

            //and path to OGG mux
            ConnectFilters(r_videoTee, VideoTeeOutputName, r_oggMux, "Stream 0", false);

            //path to OGG mux
            ConnectFilters(r_audioTee, AudioTeeOutputName, r_oggMux, "Stream 1", false);

            //configure File Sink / File Writer
            IFileSinkFilter fileSink = (IFileSinkFilter)_fileWriter;
            int             hr       = fileSink.SetFileName(fileName + ".ogm", _emptyAMMediaType);

            if (hr != 0)
            {
                this.CaptureRequiresNewGraph = true;
            }

            DsError.ThrowExceptionForHR(hr);

            StartDVRWriter(_fileWriter);


            ConnectFilters(r_oggMux, "Ogg Stream", _fileWriter, GraphConfig[FilterType.Writer].InPin[0], false);

            CaptureRequiresNewGraph = false;

            this.SaveGraphFile();
        }
Beispiel #19
0
        private void Construct(bool compressVideo)
        {
            this.Output = (IBaseFilter)this.Controller.InsertSinkFilter(this.graph);

            bouncingBall = FilterGraphTools.AddFilterByDevicePath(this.graph, @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{8D234572-35E6-495D-98AE-9A36856C49C8}", "Bouncing Ball");
            if (compressVideo)
            {
                videoEncoder = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.VideoCompressorCategory, "LEAD H264 Encoder (4.0)");
                h264Encoder  = (LMH264Encoder)videoEncoder;
                h264Encoder.EnableRateControl      = true;
                h264Encoder.EnableSuperCompression = false;
                h264Encoder.BitRate         = 10000;
                h264Encoder.FrameRate       = -1;
                h264Encoder.EncodingSpeed   = eH264ENCODINGSPEED.H264SPEED_1;
                h264Encoder.EncodingThreads = eH264ENCODINGTHREADS.H264THREAD_AUTO;
                FilterGraphTools.ConnectFilters(this.graph, bouncingBall, "A Bouncing Ball!", videoEncoder, "XForm In", false);
                FilterGraphTools.ConnectFilters(this.graph, videoEncoder, "XForm Out", this.Output, "Input 1", false);
            }
            else
            {
                FilterGraphTools.ConnectFilters(this.graph, bouncingBall, "A Bouncing Ball!", this.Output, "Input 1", false);
            }
        }
Beispiel #20
0
        public IBaseFilter AddFilterByName(Guid filterCategory, string friendlyName)
        {
            if (_graphBuilder == null)
            {
                throw new Exception("_graphBuilder == null");
            }
            if (filterCategory == null)
            {
                throw new Exception("filterCategory == null");
            }
            if (friendlyName == null)
            {
                throw new Exception("friendlyName == null");
            }
            Console.WriteLine("AddFilterByName {0} {1}", filterCategory.ToString(), friendlyName);
            IBaseFilter filter = FilterGraphTools.AddFilterByName(_graphBuilder, filterCategory, friendlyName);

            if (filter == null)
            {
                throw new Exception("The DirectShow filter " + friendlyName + " not found.");
            }
            return(filter);
        }
Beispiel #21
0
        public override void Render()
        {
            _graphControlClient         = new FutureConcepts.Media.Client.TVStreamControl(AppUser.Current.ServerAddress);
            _graphControlClient.Closed += new EventHandler(_graphControlClient_Closed);

            Message = "Connecting to " + _graphControlClient.ServerAddress + " " + AppUser.Current.ServerSourceName + "...";

            ClientConnectRequest clientRequest = new ClientConnectRequest(AppUser.Current.ServerSourceName);

            _sessionInfo = _graphControlClient.OpenGraph(clientRequest);

            //attach the event listeners only after successful connection
            _graphControlClient.ChannelScanStarted        += new EventHandler(_graphControlClient_ChannelScanStarted);
            _graphControlClient.ChannelScanProgressUpdate += new EventHandler(_graphControlClient_ChannelScanProgressUpdate);
            _graphControlClient.ChannelScanComplete       += new EventHandler <ChannelScanCompleteEventArgs>(_graphControlClient_ChannelScanComplete);
            _graphControlClient.PropertyChanged           += new PropertyChangedEventHandler(_graphControlClient_PropertyChanged);

            this.Connected = ConnectionState.WCFOnly;

            if (_sessionInfo.TVSessionInfo == null)
            {
                throw new Exception("VideoServer Source is not a TV Source");
            }

            if (_sessionInfo.TVSessionInfo.ChannelScanInProgress)
            {
                //TODO...is this the best way?
                //throw new Exception("The TV server is currently in the middle of scanning for channels.");
                return;
            }

            Profile currentProfile = null;

            foreach (ProfileGroup g in _sessionInfo.ProfileGroups.Items)
            {
                foreach (Profile p in g.Items)
                {
                    if (_sessionInfo.CurrentProfileName.Equals(p.Name))
                    {
                        currentProfile = p;
                    }
                }
            }

            if (currentProfile != null)
            {
                //determine if we have a preferred video decoder for the specified Video codec
                if (currentProfile.Video != null)
                {
                    if (currentProfile.Video.CodecType != VideoCodecType.Undefined)
                    {
                        Filter vdFilter = this.GraphConfig.GetFilterForCodec(currentProfile.Video.CodecType, FilterType.VideoDecoder);
                        if (vdFilter != null)
                        {
                            _videoDecoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, vdFilter.Name);
                        }
                    }
                }
                //determine if we have a preferred audio decoder for the specified Audio codec
                if (currentProfile.Audio != null)
                {
                    if (currentProfile.Audio.CodecType != AudioCodecType.Undefined)
                    {
                        Filter adFilter = this.GraphConfig.GetFilterForCodec(currentProfile.Audio.CodecType, FilterType.AudioDecoder);
                        if (adFilter != null)
                        {
                            _audioDecoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, adFilter.Name);
                        }
                    }
                }
            }

            AddLeadNetSrc();
            AddLeadNetDemux();
            ConnectFilters(_netSrc, "Output", _netDmx, "Input 01", true);

            RenderNetDemux();

            NotifyPropertyChanged("Channel");
            NotifyPropertyChanged("TVMode");

            this.Connected = ConnectionState.Full;

            this.SaveGraphFile();
        }
Beispiel #22
0
        /// <summary>
        /// Constructs the remainder of the graph (after the Demuxer) according to the source config and profile.
        /// </summary>
        private void BuildForProfile()
        {
            //Configure for specific codec / transcoding
            //if UseHardwareEncoder is checked, we will simply hand off the Elementry Streams from the Air
            if (SourceConfig.TVTuner.UseHardwareEncoder)
            {
                //connect video
                ConnectFilterToNetMux(mpeg2Demux, "2", "Input 01");
                //connect audio
                ConnectFilterToNetMux(mpeg2Demux, "3", "Input 02");
            }
            else // if they want to use software encoder, we will encode using the default profile
            {
                if (CurrentProfile.Video != null)
                {
                    if (CurrentProfile.Video.CodecType != VideoCodecType.H264)
                    {
                        throw new NotSupportedException("H.264 is the only supported target codec in software transcoding mode!");
                    }

                    if (CurrentProfile.Video.ImageSize != VideoImageSize.Undefined)
                    {
                        throw new NotSupportedException("Resizing is not supported!");
                    }

                    videoEncoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD H264 Encoder (4.0)");
                    if (videoEncoder == null)
                    {
                        throw new Exception("Could not instantiate H264 Encoder!");
                    }
                    h264Encoder = (ILMH264Encoder)videoEncoder;
                    if (h264Encoder == null)
                    {
                        throw new Exception("Could not query for ILMH264Encoder interface!");
                    }

                    FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Elecard MPEG-2 Video Decoder");

                    FilterGraphTools.ConnectFilters(_graphBuilder, mpeg2Demux, "2", videoEncoder, "XForm In", true);

                    h264Encoder.EncodingThreads = eH264ENCODINGTHREADS.H264THREAD_AUTO;
                    h264Encoder.FrameRate       = -1;
                    h264Encoder.EncodingSpeed   = eH264ENCODINGSPEED.H264SPEED_1;
                    //h264Encoder.EncodingSpeed = eH264ENCODINGSPEED.H264SPEED_2;

                    h264Encoder.EnableRateControl = true;
                    h264Encoder.BitRate           = CurrentProfile.Video.ConstantBitRate * 1024;

                    h264Encoder.EnableSuperCompression = false;
                    h264Encoder.SymbolMode             = eH264SYMBOLMODE.H264SYMBOL_CAVLC;
                    h264Encoder.OutputFormat           = eH264OUTPUTFORMAT.H264FORMAT_STANDARD_H264;

                    h264Encoder.IFrameInterval = CurrentProfile.Video.KeyFrameRate;
                    h264Encoder.PFrameInterval = 0;

                    //connect video
                    ConnectFilterToNetMux(videoEncoder, "XForm Out", "Input 01");
                }
                if (CurrentProfile.Audio != null)
                {
                    if (CurrentProfile.Audio.CodecType != AudioCodecType.DolbyDigital)
                    {
                        throw new NotSupportedException("Audio transcoding is not implemented!");
                    }
                    //connect audio
                    ConnectFilterToNetMux(mpeg2Demux, "3", (CurrentProfile.Video != null) ? "Input 02" : "Input 01");
                }
            }
        }
Beispiel #23
0
        public WinTV418ATSC(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest)
            : base(sourceConfig, openGraphRequest)
        {
            if (SourceConfig.TVTuner == null)
            {
                throw new SourceConfigException("TVTuner config section not found!");
            }

            _deviceIndex = sourceConfig.TVTuner.DeviceIndex;

            tuningSpace = GetTuningSpace();

            Guid networkType;

            tuningSpace.get__NetworkType(out networkType);
            if (networkType.Equals(Guid.Empty))
            {
                throw new Exception("Not a digital Network Type!");
            }

            networkProvider = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(networkType));
            int hr = _graphBuilder.AddFilter(networkProvider, "Network Provider");

            DsError.ThrowExceptionForHR(hr);
            tuner = (ITuner)networkProvider;

            //add MPEG2 Demux
            mpeg2Demux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "MPEG-2 Demultiplexer");

            //add BDA MPEG-2 Transport Information Filter
            bdaTransportInfo = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "BDA MPEG2 Transport Information Filter");
            //add MPEG-2 Sections and Tables Filter
            mpeg2SectionsAndTables = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "MPEG-2 Sections and Tables");

            //tunerFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner");
            DsDevice tunerDevice = FindDevice(FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner");

            tunerFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, tunerDevice.DevicePath, tunerDevice.Name);
            //captureFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture");
            DsDevice captureDevice = FindDevice(FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture");

            captureFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, captureDevice.DevicePath, captureDevice.Name);

            //connect network provider to BDA tuner
            ConnectFilters(networkProvider, "Antenna Out", (IBaseFilter)tunerFilter, "Input0", false);
            ConnectFilters((IBaseFilter)tunerFilter, "MPEG2 Transport", captureFilter, "MPEG2 Transport", false);

            //These filters need to be connected via their explicit pins,
            //  because Hauppauge saw fit to name all the pins on the capture filter the same name.
            IPin captureFilterOut = DsFindPin.ByDirection(captureFilter, PinDirection.Output, 0);
            IPin mpeg2DemuxIn     = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Input, 0);

            FilterGraphTools.ConnectFilters(_graphBuilder, captureFilterOut, mpeg2DemuxIn, false);
            //clean up the two pins
            Marshal.ReleaseComObject(captureFilterOut);
            Marshal.ReleaseComObject(mpeg2DemuxIn);

            //add and connect meta data filters and connect them to the Demux
            ConnectFilters(mpeg2Demux, "1", bdaTransportInfo, "Input", false);
            ConnectFilters(mpeg2Demux, "5", mpeg2SectionsAndTables, "In", false);

            //this interface must be queried after the S&T filter has been connected.
            mpeg2Data  = (IMpeg2Data)mpeg2SectionsAndTables;
            _vctParser = new Parser(mpeg2Data);

            //build out the rest of the graph for the given source config / profile
            BuildForProfile();

            ConnectNetMuxToNetSnk();

            if (KnownChannels.Count > 0)
            {
                this.Channel = KnownChannels.Items[0];
            }

            SaveGraphFile("WinTV418ATSC.grf");
        }
Beispiel #24
0
        public DigitalTuner(Config.Graph sourceConfig, Control hostControl)
            : base(sourceConfig, hostControl)
        {
            //deal with the Tuning Space and Network Provider
            tuningSpace = GetTuningSpace();

            Guid networkProviderCLSID;
            Guid networkTypeCLSID;

            tuningSpace.get__NetworkType(out networkTypeCLSID);
            if (networkTypeCLSID.Equals(Guid.Empty))
            {
                throw new Exception("Not a digital Network Type!");
            }

            if (UseGenericNetworkProvider)
            {
                networkProviderCLSID = CLSID_NetworkProvider;
            }
            else
            {
                networkProviderCLSID = networkTypeCLSID;
            }

            networkProvider = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(networkProviderCLSID));

            tuner = (ITuner)networkProvider;

            //   if (UseGenericNetworkProvider)
            {
                tuner.put_TuningSpace(tuningSpace);
            }

            int hr = _graphBuilder.AddFilter(networkProvider, "Network Provider");

            DsError.ThrowExceptionForHR(hr);

            //add MPEG2 Demux
            mpeg2Demux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "MPEG-2 Demultiplexer");

            //add video decoder
            videoDecoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, GraphConfig[FilterType.VideoDecoder].Name);
            if (videoDecoder == null)
            {
                throw new Exception("Could not instantiate video decoder!");
            }

            //add audio decoder
            if (GraphConfig[FilterType.AudioDecoder] != null)
            {
                audioDecoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, GraphConfig[FilterType.AudioDecoder].Name);
                if (audioDecoder == null)
                {
                    throw new Exception("Could not instantiate audio decoder!");
                }
            }

            //add BDA MPEG-2 Transport Information Filter
            bdaTransportInfo = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "BDA MPEG2 Transport Information Filter");
            //add MPEG-2 Sections and Tables Filter
            mpeg2SectionsAndTables = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "MPEG-2 Sections and Tables");

            //        sampleGrabberFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "SampleGrabber");
            //        sampleGrabber = (ISampleGrabber)sampleGrabberFilter;
        }