/// <summary>
 /// Disposes the capture component
 /// </summary>
 public void Dispose()
 {
     if (_pinVBI != null)
     {
         Release.ComObject("vbipin filter", _pinVBI);
         _pinVBI = null;
     }
     if (_filterAudioCapture != null && _filterVideoCapture != _filterAudioCapture)
     {
         Release.ComObject("audio capture filter", _filterAudioCapture);
     }
     if (_filterVideoCapture != null)
     {
         Release.ComObject("video capture filter", _filterVideoCapture);
         _filterVideoCapture = null;
         _analogVideoDecoder = null;
     }
     _filterAudioCapture = null;
     if (_audioCaptureDevice != null && _audioCaptureDevice != _videoCaptureDevice)
     {
         DevicesInUse.Instance.Remove(_audioCaptureDevice);
     }
     if (_videoCaptureDevice != null)
     {
         DevicesInUse.Instance.Remove(_videoCaptureDevice);
         _videoCaptureDevice = null;
     }
     _audioCaptureDevice = null;
 }
Example #2
0
 /// <summary>
 /// Disposes the crossbar component
 /// </summary>
 public void Dispose()
 {
     if (_audioTunerIn != null)
     {
         Release.ComObject("_audioTunerIn", _audioTunerIn);
     }
     if (_videoOut != null)
     {
         Release.ComObject("_videoOut", _videoOut);
     }
     if (_audioOut != null)
     {
         Release.ComObject("_audioOut", _audioOut);
     }
     if (_filterCrossBar != null)
     {
         Release.ComObject("crossbar filter", _filterCrossBar);
         _filterCrossBar = null;
     }
     if (_crossBarDevice != null)
     {
         DevicesInUse.Instance.Remove(_crossBarDevice);
         _crossBarDevice = null;
     }
 }
Example #3
0
        /// <summary>
        /// adds the TsFileSink filter to the graph
        /// </summary>
        /// <returns></returns>
        private bool AddTsFileSink()
        {
            if (!CheckThreadId())
            {
                return(false);
            }
            Log.Log.WriteFile("analog:AddTsFileSink");
            _tsFileSink = (IBaseFilter) new MpFileWriter();
            int hr = _graphBuilder.AddFilter(_tsFileSink, "TsFileSink");

            if (hr != 0)
            {
                Log.Log.WriteFile("analog:AddTsFileSink returns:0x{0:X}", hr);
                throw new TvException("Unable to add TsFileSink");
            }
            Log.Log.WriteFile("analog:connect muxer->tsfilesink");
            IPin pin = DsFindPin.ByDirection(_encoder.MultiplexerFilter, PinDirection.Output, 0);

            if (!FilterGraphTools.ConnectPin(_graphBuilder, pin, _tsFileSink, 0))
            {
                Log.Log.WriteFile("analog:unable to connect muxer->tsfilesink");
                throw new TvException("Unable to connect pins");
            }
            Release.ComObject("mpegmux pinin", pin);
            if (_capture.SupportsTeletext)
            {
                Log.Log.WriteFile("analog:connect wst/vbi codec->tsfilesink");
                if (!FilterGraphTools.ConnectPin(_graphBuilder, _teletext.WST_VBI_Pin, _tsFileSink, 1))
                {
                    Log.Log.WriteFile("analog:unable to connect wst/vbi->tsfilesink");
                    throw new TvException("Unable to connect pins");
                }
            }
            return(true);
        }
Example #4
0
 /// <summary>
 /// Dispose resources
 /// </summary>
 public override void Dispose()
 {
     base.Dispose();
     if (_filterStreamSource != null)
     {
         Release.ComObject("_filterStreamSource filter", _filterStreamSource);
         _filterStreamSource = null;
     }
 }
 /// <summary>
 /// RemoveStreamSourceFilter
 /// </summary>
 protected override void RemoveStreamSourceFilter()
 {
   if (_filterStreamSource != null)
   {
     _graphBuilder.RemoveFilter(_filterStreamSource);
     Release.ComObject("MediaPortal IPTV Source Filter", _filterStreamSource);
     _filterStreamSource = null;
   }
 }
Example #6
0
 /// <summary>
 /// RemoveStreamSourceFilter
 /// </summary>
 protected override void RemoveStreamSourceFilter()
 {
     if (_filterStreamSource != null)
     {
         _graphBuilder.RemoveFilter(_filterStreamSource);
         Release.ComObject("Elecard NWSource-Plus", _filterStreamSource);
         _filterStreamSource = null;
     }
 }
Example #7
0
        private static bool ConnectFilter(IFilterGraph2 graphBuilder, IBaseFilter networkFilter, IBaseFilter tunerFilter)
        {
            IPin pinOut = DsFindPin.ByDirection(networkFilter, PinDirection.Output, 0);
            IPin pinIn  = DsFindPin.ByDirection(tunerFilter, PinDirection.Input, 0);
            int  hr     = graphBuilder.Connect(pinOut, pinIn);

            Release.ComObject(pinOut);
            Release.ComObject(pinIn);
            return(hr == 0);
        }
Example #8
0
 protected void Decompose()
 {
     base.Decompose();
     if (_pbdaFilter != null)
     {
         Release.ComObject(_pbdaFilter);
         _pbdaFilter = null;
     }
     _bdaCa = null;
 }
        /// <summary>
        /// Finds the VBI pin on the video capture device.
        /// If it existst the pin is stored in _pinVBI
        /// </summary>
        /// <param name="graph">The stored graph</param>
        private void FindVBIPin(Graph graph)
        {
            Log.Log.WriteFile("analog: FindVBIPin on VideoCapture");
            int pinIndex;

            try
            {
                IPin pinVBI = FilterGraphTools.GetPinByCategoryAndDirection(_filterVideoCapture, PinCategory.VideoPortVBI, 0,
                                                                            PinDirection.Output, out pinIndex);
                if (pinVBI != null)
                {
                    Log.Log.WriteFile("analog: VideoPortVBI pin found");
                    Release.ComObject(pinVBI);
                    return;
                }
                pinVBI = FilterGraphTools.GetPinByCategoryAndDirection(_filterVideoCapture, PinCategory.VBI, 0,
                                                                       PinDirection.Output, out pinIndex);
                if (pinVBI != null)
                {
                    Log.Log.WriteFile("analog: VBI pin found");
                    graph.Capture.TeletextPin = pinIndex;
                    _pinVBI = pinVBI;
                    return;
                }
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode.Equals(unchecked ((Int32)0x80070490)))
                {
                    // pin on a NVTV capture filter is named VBI..
                    Log.Log.WriteFile("analog: getCategory not supported by collection ? ERROR:0x{0:x} :" + ex.Message,
                                      ex.ErrorCode);

                    if (_filterVideoCapture == null)
                    {
                        return;
                    }
                    Log.Log.WriteFile("analog: find VBI pin by name");

                    IPin pinVBI = FilterGraphTools.GetPinByName(_filterVideoCapture, "VBI", PinDirection.Output, out pinIndex);
                    if (pinVBI != null)
                    {
                        Log.Log.WriteFile("analog: pin named VBI found");
                        graph.Capture.TeletextPin = pinIndex;
                        _pinVBI = pinVBI;
                        return;
                    }
                }
                Log.Log.WriteFile("analog: Error in searching vbi pin - Skipping error");
            }
            Log.Log.WriteFile("analog: FindVBIPin on VideoCapture no vbi pin found");
        }
 /// <summary>
 /// Diposes the tuner component
 /// </summary>
 public void Dispose()
 {
     _tuner = null;
     if (_audioPin != null)
     {
         Release.ComObject("_audioPin", _audioPin);
     }
     if (_filterTvTuner != null)
     {
         while (Release.ComObject(_filterTvTuner) > 0)
         {
         }
         _filterTvTuner = null;
     }
     DevicesInUse.Instance.Remove(_tunerDevice);
 }
 /// <summary>
 /// Disposes the teletext component
 /// </summary>
 public void Dispose()
 {
     if (_filterWstDecoder != null)
     {
         Release.ComObject("wst codec filter", _filterWstDecoder);
         _filterWstDecoder = null;
     }
     if (_teeSink != null)
     {
         Release.ComObject("teesink filter", _teeSink);
         _teeSink = null;
     }
     if (_pinWST_VBI != null)
     {
         Release.ComObject("wst/vbi codec pinout", _pinWST_VBI);
         _pinWST_VBI = null;
     }
 }
Example #12
0
 /// <summary>
 /// Disposes the TvAudio component
 /// </summary>
 public void Dispose()
 {
     if (mode == TvAudioVariant.Normal)
     {
         if (_filterTvAudioTuner != null)
         {
             while (Release.ComObject(_filterTvAudioTuner) > 0)
             {
             }
             _filterTvAudioTuner = null;
         }
         if (_audioDevice != null)
         {
             DevicesInUse.Instance.Remove(_audioDevice);
             _audioDevice = null;
         }
     }
 }
Example #13
0
        public void Stop()
        {
            _videoWin.put_Visible(OABool.False);
            _mediaCtrl.Stop();

            if (_pinAudio != null)
            {
                Release.ComObject(_pinAudio);
                _pinAudio = null;
            }
            if (_pinVideo != null)
            {
                Release.ComObject(_pinVideo);
                _pinVideo = null;
            }
            if (_mpegDemux != null)
            {
                Release.ComObject(_mpegDemux);
                _mpegDemux = null;
            }
            if (_tsFileSource != null)
            {
                Release.ComObject(_tsFileSource);
                _tsFileSource = null;
            }
            if (_rotEntry != null)
            {
                _rotEntry.Dispose();
                _rotEntry = null;
            }

            if (_graphBuilder != null)
            {
                Release.ComObject(_graphBuilder);
                _graphBuilder = null;
            }
        }
Example #14
0
        public void Stop()
        {
            if (_videoWin != null)
            {
                _videoWin.put_Visible(OABool.False);
            }
            if (_mediaCtrl != null)
            {
                _mediaCtrl.Stop();
            }
            if (_pinAudio != null)
            {
                Release.ComObject(_pinAudio);
                _pinAudio = null;
            }
            if (_pinVideo != null)
            {
                Release.ComObject(_pinVideo);
                _pinVideo = null;
            }
            if (_tsReader != null)
            {
                Release.ComObject(_tsReader);
                _tsReader = null;
            }
            if (_rotEntry != null)
            {
                _rotEntry.Dispose();
                _rotEntry = null;
            }

            if (_graphBuilder != null)
            {
                Release.ComObject(_graphBuilder);
                _graphBuilder = null;
            }
        }
 private void AddTsWriterFilterToGraph()
 {
     if (_filterTsWriter == null)
     {
         Log.Log.WriteFile("HDPVR: Add Mediaportal TsWriter filter");
         _filterTsWriter = (IBaseFilter) new MpTsAnalyzer();
         int hr = _graphBuilder.AddFilter(_filterTsWriter, "MediaPortal Ts Analyzer");
         if (hr != 0)
         {
             Log.Log.Error("HDPVR:  Add main Ts Analyzer returns:0x{0:X}", hr);
             throw new TvException("Unable to add Ts Analyzer filter");
         }
         IPin pinOut = DsFindPin.ByDirection(_filterEncoder, PinDirection.Output, 0);
         if (pinOut == null)
         {
             Log.Log.Error("HDPVR:  Unable to find output pin on the encoder filter");
             throw new TvException("unable to find output pin on the encoder filter");
         }
         IPin pinIn = DsFindPin.ByDirection(_filterTsWriter, PinDirection.Input, 0);
         if (pinIn == null)
         {
             Log.Log.Error("HDPVR:  Unable to find the input pin on ts analyzer filter");
             throw new TvException("Unable to find the input pin on ts analyzer filter");
         }
         //Log.Log.Info("HDPVR: Render [Encoder]->[TsWriter]");
         hr = _graphBuilder.Connect(pinOut, pinIn);
         Release.ComObject("pinTsWriterIn", pinIn);
         Release.ComObject("pinEncoderOut", pinOut);
         if (hr != 0)
         {
             Log.Log.Error("HDPVR:  Unable to connect encoder to ts analyzer filter :0x{0:X}", hr);
             throw new TvException("unable to connect encoder to ts analyzer filter");
         }
         Log.Log.WriteFile("HDPVR: AddTsWriterFilterToGraph connected to encoder successfully");
     }
 }
Example #16
0
        /// <summary>
        /// Connects the SS2 filter to the infTee
        /// </summary>
        private void ConnectInfTeeToSS2(out IBaseFilter lastFilter)
        {
            Log.Log.WriteFile("dvb:add Inf Tee filter");
            _infTeeMain = (IBaseFilter) new InfTee();
            int hr = _graphBuilder.AddFilter(_infTeeMain, "Inf Tee");

            if (hr != 0)
            {
                Log.Log.Error("dvb:Add main InfTee returns:0x{0:X}", hr);
                throw new TvException("Unable to add  mainInfTee");
            }

            Log.Log.WriteFile("ss2:ConnectMainTee()");
            IPin pinOut = DsFindPin.ByDirection(_filterB2C2Adapter, PinDirection.Output, 2);
            IPin pinIn  = DsFindPin.ByDirection(_infTeeMain, PinDirection.Input, 0);

            if (pinOut == null)
            {
                Log.Log.Error("ss2:unable to find pin 2 of b2c2adapter");
                throw new TvException("unable to find pin 2 of b2c2adapter");
            }
            if (pinIn == null)
            {
                Log.Log.Error("ss2:unable to find pin 0 of _infTeeMain");
                throw new TvException("unable to find pin 0 of _infTeeMain");
            }
            hr = _graphBuilder.Connect(pinOut, pinIn);
            Release.ComObject("b2c2pin2", pinOut);
            Release.ComObject("mpeg2demux pinin", pinIn);
            if (hr != 0)
            {
                Log.Log.Error("ss2:unable to connect b2c2->_infTeeMain");
                throw new TvException("unable to connect b2c2->_infTeeMain");
            }
            lastFilter = _infTeeMain;
        }
Example #17
0
        /// <summary>
        /// Disposes this instance.
        /// </summary>
        public override void Dispose()
        {
            if (_graphBuilder == null)
            {
                return;
            }
            if (!CheckThreadId())
            {
                return;
            }

            base.Dispose();

            Log.Log.WriteFile("ss2:Decompose");

            _interfaceB2C2DataCtrl  = null;
            _interfaceB2C2TunerCtrl = null;

            if (_filterB2C2Adapter != null)
            {
                Release.ComObject("tuner filter", _filterB2C2Adapter);
                _filterB2C2Adapter = null;
            }
        }
Example #18
0
        /// <summary>
        /// Clean up, dispose, release.
        /// </summary>
        public void Dispose()
        {
            Stop();

            if (_rwsTuner != null)
            {
                _rwsTuner.Dispose();
                _rwsTuner = null;
            }
            if (_rotEntry != null)
            {
                _rotEntry.Dispose();
            }
            if (_graphBuilder != null)
            {
                FilterGraphTools.RemoveAllFilters(_graphBuilder);
                Release.ComObject("device detection graph builder", _graphBuilder);
            }
            Release.ComObject("device detection ATSC network provider", _atscNp);
            Release.ComObject("device detection DVB-C network provider", _dvbcNp);
            Release.ComObject("device detection DVB-S network provider", _dvbsNp);
            Release.ComObject("device detection DVB-T network provider", _dvbtNp);
            Release.ComObject("device detection MediaPortal network provider", _mpNp);
        }
Example #19
0
        public bool Play(string fileName, Form form)
        {
            fileName += ".tsbuffer";
            Log.WriteFile("play:{0}", fileName);
            _graphBuilder = (IFilterGraph2) new FilterGraph();
            _rotEntry     = new DsROTEntry(_graphBuilder);


            Log.WriteFile("add tsfilesource");
            _tsFileSource = new TsFileSource();
            _graphBuilder.AddFilter((IBaseFilter)_tsFileSource, "TsFileSource");

            #region add mpeg-2 demux filter

            Log.WriteFile("add mpeg-2 demux");
            MPEG2Demultiplexer demux = new MPEG2Demultiplexer();
            _mpegDemux = (IBaseFilter)demux;
            int hr = _graphBuilder.AddFilter(_mpegDemux, "MPEG-2 Demultiplexer");

            #endregion

            #region create mpeg2 demux pins

            Log.WriteFile("create mpeg-2 demux pins");
            //create mpeg-2 demux output pins
            IMpeg2Demultiplexer demuxer = _mpegDemux as IMpeg2Demultiplexer;


            if (demuxer != null)
            {
                hr = demuxer.CreateOutputPin(GetAudioMpg2Media(), "Audio", out _pinAudio);
            }
            if (hr != 0)
            {
                Log.WriteFile("unable to create audio pin");
                return(false);
            }
            if (demuxer != null)
            {
                hr = demuxer.CreateOutputPin(GetVideoMpg2Media(), "Video", out _pinVideo);
            }
            if (hr != 0)
            {
                Log.WriteFile("unable to create video pin");
                return(false);
            }

            #endregion

            #region load file in tsfilesource

            Log.WriteFile("load file in tsfilesource");
            IFileSourceFilter interfaceFile = (IFileSourceFilter)_tsFileSource;
            if (interfaceFile == null)
            {
                Log.WriteFile("TSStreamBufferPlayer9:Failed to get IFileSourceFilter");
                return(false);
            }

            AMMediaType mpeg2ProgramStream = new AMMediaType();
            mpeg2ProgramStream.majorType = MediaType.Stream;
            mpeg2ProgramStream.subType   = MediaSubType.Mpeg2Program;

            mpeg2ProgramStream.unkPtr              = IntPtr.Zero;
            mpeg2ProgramStream.sampleSize          = 0;
            mpeg2ProgramStream.temporalCompression = false;
            mpeg2ProgramStream.fixedSizeSamples    = true;
            mpeg2ProgramStream.formatType          = FormatType.None;
            mpeg2ProgramStream.formatSize          = 0;
            mpeg2ProgramStream.formatPtr           = IntPtr.Zero;
            hr = interfaceFile.Load(fileName, mpeg2ProgramStream);

            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9:Failed to load file");
                return(false);
            }

            #region connect tsfilesource->demux

            Log.WriteFile("connect tsfilesource->demux");
            Log.WriteFile("TSStreamBufferPlayer9:connect tsfilesource->mpeg2 demux");
            IPin pinTsOut = DsFindPin.ByDirection((IBaseFilter)_tsFileSource, PinDirection.Output, 0);
            if (pinTsOut == null)
            {
                Log.WriteFile("TSStreamBufferPlayer9:failed to find output pin of tsfilesource");
                return(false);
            }
            IPin pinDemuxIn = DsFindPin.ByDirection(_mpegDemux, PinDirection.Input, 0);
            if (pinDemuxIn == null)
            {
                Log.WriteFile("TSStreamBufferPlayer9:failed to find output pin of tsfilesource");
                return(false);
            }

            hr = _graphBuilder.Connect(pinTsOut, pinDemuxIn);
            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9:failed to connect tsfilesource->mpeg2 demux:{0:X}", hr);
                return(false);
            }
            Release.ComObject(pinTsOut);
            Release.ComObject(pinDemuxIn);

            #endregion

            #region map demux pids

            Log.WriteFile("map mpeg2 pids");
            IMPEG2StreamIdMap pStreamId = (IMPEG2StreamIdMap)_pinVideo;
            hr = pStreamId.MapStreamId(0xe0, MPEG2Program.ElementaryStream, 0, 0);
            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9: failed to map pid 0xe0->video pin");
                return(false);
            }
            pStreamId = (IMPEG2StreamIdMap)_pinAudio;
            hr        = pStreamId.MapStreamId(0xc0, MPEG2Program.ElementaryStream, 0, 0);
            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9: failed  to map pid 0xc0->audio pin");
                return(false);
            }

            #endregion

            #region render demux audio/video pins

            Log.WriteFile("render pins");
            hr = _graphBuilder.Render(_pinAudio);
            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9:failed to render video output pin:{0:X}", hr);
            }

            hr = _graphBuilder.Render(_pinVideo);
            if (hr != 0)
            {
                Log.WriteFile("TSStreamBufferPlayer9:failed to render audio output pin:{0:X}", hr);
            }

            #endregion

            #endregion

            _videoWin = _graphBuilder as IVideoWindow;
            if (_videoWin != null)
            {
                _videoWin.put_Visible(OABool.True);
                _videoWin.put_Owner(form.Handle);
                _videoWin.put_WindowStyle(
                    (WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipSiblings + (int)WindowStyle.ClipChildren));
                _videoWin.put_MessageDrain(form.Handle);
                _videoWin.SetWindowPosition(190, 250, 150, 150);
            }

            Log.WriteFile("run graph");
            _mediaCtrl = (IMediaControl)_graphBuilder;
            hr         = _mediaCtrl.Run();
            Log.WriteFile("TSStreamBufferPlayer9:running:{0:X}", hr);

            return(true);
        }
Example #20
0
        /// <summary>
        /// Builds the graph.
        /// </summary>
        public override void BuildGraph()
        {
            try
            {
                Log.Log.WriteFile("ss2: build graph");
                if (_graphState != GraphState.Idle)
                {
                    Log.Log.Error("ss2: Graph already built");
                    throw new TvException("Graph already built");
                }
                DevicesInUse.Instance.Add(_tunerDevice);
                _managedThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
                _graphBuilder    = (IFilterGraph2) new FilterGraph();
                _rotEntry        = new DsROTEntry(_graphBuilder);
                _capBuilder      = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
                _capBuilder.SetFiltergraph(_graphBuilder);
                //=========================================================================================================
                // add the skystar 2 specific filters
                //=========================================================================================================
                Log.Log.WriteFile("ss2:CreateGraph() create B2C2 adapter");
                _filterB2C2Adapter =
                    (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(DVBSkyStar2Helper.CLSID_B2C2Adapter, false));
                if (_filterB2C2Adapter == null)
                {
                    Log.Log.Error("ss2:creategraph() _filterB2C2Adapter not found");
                    DevicesInUse.Instance.Remove(_tunerDevice);
                    return;
                }
                Log.Log.WriteFile("ss2:creategraph() add filters to graph");
                int hr = _graphBuilder.AddFilter(_filterB2C2Adapter, "B2C2-Source");
                if (hr != 0)
                {
                    Log.Log.Error("ss2: FAILED to add B2C2-Adapter");
                    DevicesInUse.Instance.Remove(_tunerDevice);
                    return;
                }
                // get interfaces
                _interfaceB2C2DataCtrl = _filterB2C2Adapter as DVBSkyStar2Helper.IB2C2MPEG2DataCtrl3;
                if (_interfaceB2C2DataCtrl == null)
                {
                    Log.Log.Error("ss2: cannot get IB2C2MPEG2DataCtrl3");
                    DevicesInUse.Instance.Remove(_tunerDevice);
                    return;
                }
                _interfaceB2C2TunerCtrl = _filterB2C2Adapter as DVBSkyStar2Helper.IB2C2MPEG2TunerCtrl2;
                if (_interfaceB2C2TunerCtrl == null)
                {
                    Log.Log.Error("ss2: cannot get IB2C2MPEG2TunerCtrl3");
                    DevicesInUse.Instance.Remove(_tunerDevice);
                    return;
                }
                //=========================================================================================================
                // initialize skystar 2 tuner
                //=========================================================================================================
                Log.Log.WriteFile("ss2: Initialize Tuner()");
                hr = _interfaceB2C2TunerCtrl.Initialize();
                if (hr != 0)
                {
                    //System.Diagnostics.Debugger.Launch();
                    Log.Log.Error("ss2: Tuner initialize failed:0x{0:X}", hr);
                    // if the skystar2 card is detected as analogue, it needs a device reset

                    ((IMediaControl)_graphBuilder).Stop();
                    FreeAllSubChannels();
                    FilterGraphTools.RemoveAllFilters(_graphBuilder);

                    if (_graphBuilder != null)
                    {
                        Release.ComObject("graph builder", _graphBuilder);
                        _graphBuilder = null;
                    }

                    if (_capBuilder != null)
                    {
                        Release.ComObject("capBuilder", _capBuilder);
                        _capBuilder = null;
                    }

                    DevicesInUse.Instance.Remove(_tunerDevice);

                    /*
                     * if (initResetTries == 0)
                     * {
                     * Log.Log.Error("ss2: resetting driver");
                     * HardwareHelperLib.HH_Lib hwHelper = new HardwareHelperLib.HH_Lib();
                     * string[] deviceDriverName = new string[1];
                     * deviceDriverName[0] = DEVICE_DRIVER_NAME;
                     * hwHelper.SetDeviceState(deviceDriverName, false);
                     * hwHelper.SetDeviceState(deviceDriverName, true);
                     * initResetTries++;
                     *
                     * BuildGraph();
                     * }
                     * else
                     * {
                     * Log.Log.Error("ss2: resetting driver did not help");
                     * CardPresent = false;
                     * }
                     */
                    CardPresent = false;
                    return;
                }
                // call checklock once, the return value dont matter
                _interfaceB2C2TunerCtrl.CheckLock();
                AddTsWriterFilterToGraph();
                IBaseFilter lastFilter;
                ConnectInfTeeToSS2(out lastFilter);
                AddMdPlugs(ref lastFilter);
                if (!ConnectTsWriter(lastFilter))
                {
                    throw new TvExceptionGraphBuildingFailed("Graph building failed");
                }
                SendHwPids(new List <ushort>());
                _graphState = GraphState.Created;
            }
            catch (Exception ex)
            {
                Log.Log.Write(ex);
                Dispose();
                _graphState = GraphState.Idle;
                throw new TvExceptionGraphBuildingFailed("Graph building failed", ex);
            }
        }
Example #21
0
        private void GetTunerCapabilities()
        {
            Log.Log.WriteFile("ss2: GetTunerCapabilities");
            _graphBuilder = (IFilterGraph2) new FilterGraph();
            _rotEntry     = new DsROTEntry(_graphBuilder);
            _capBuilder   = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            _capBuilder.SetFiltergraph(_graphBuilder);
            //=========================================================================================================
            // add the skystar 2 specific filters
            //=========================================================================================================
            Log.Log.WriteFile("ss2:GetTunerCapabilities() create B2C2 adapter");
            _filterB2C2Adapter =
                (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(DVBSkyStar2Helper.CLSID_B2C2Adapter, false));
            if (_filterB2C2Adapter == null)
            {
                Log.Log.Error("ss2:GetTunerCapabilities() _filterB2C2Adapter not found");
                return;
            }
            _interfaceB2C2TunerCtrl = _filterB2C2Adapter as DVBSkyStar2Helper.IB2C2MPEG2TunerCtrl2;
            if (_interfaceB2C2TunerCtrl == null)
            {
                Log.Log.Error("ss2: cannot get IB2C2MPEG2TunerCtrl3");
                return;
            }
            //=========================================================================================================
            // initialize skystar 2 tuner
            //=========================================================================================================

            /* Not necessary for query-only application
             *
             * Log.Log.WriteFile("ss2: Initialize Tuner()");
             * hr = _interfaceB2C2TunerCtrl.Initialize();
             * if (hr != 0)
             * {
             * Log.Log.Error("ss2: Tuner initialize failed:0x{0:X}", hr);
             * //return;
             * }*/
            //=========================================================================================================
            // Get tuner type (DVBS, DVBC, DVBT, ATSC)
            //=========================================================================================================
            int    lTunerCapSize = Marshal.SizeOf(typeof(tTunerCapabilities));
            IntPtr ptCaps        = Marshal.AllocHGlobal(lTunerCapSize);
            int    hr            = _interfaceB2C2TunerCtrl.GetTunerCapabilities(ptCaps, ref lTunerCapSize);

            if (hr != 0)
            {
                Log.Log.Error("ss2: Tuner Type failed:0x{0:X}", hr);
                return;
            }
            tTunerCapabilities tc = (tTunerCapabilities)Marshal.PtrToStructure(ptCaps, typeof(tTunerCapabilities));

            switch (tc.eModulation)
            {
            case TunerType.ttSat:
                Log.Log.WriteFile("ss2: Card type = DVBS");
                _cardType = CardType.DvbS;
                break;

            case TunerType.ttCable:
                Log.Log.WriteFile("ss2: Card type = DVBC");
                _cardType = CardType.DvbC;
                break;

            case TunerType.ttTerrestrial:
                Log.Log.WriteFile("ss2: Card type = DVBT");
                _cardType = CardType.DvbT;
                break;

            case TunerType.ttATSC:
                Log.Log.WriteFile("ss2: Card type = ATSC");
                _cardType = CardType.Atsc;
                break;

            case TunerType.ttUnknown:
                Log.Log.WriteFile("ss2: Card type = unknown?");
                _cardType = CardType.DvbS;
                break;
            }
            Marshal.FreeHGlobal(ptCaps);
            // Release all used object
            if (_filterB2C2Adapter != null)
            {
                Release.ComObject("tuner filter", _filterB2C2Adapter);
                _filterB2C2Adapter = null;
            }
            _rotEntry.Dispose();
            if (_capBuilder != null)
            {
                Release.ComObject("capture builder", _capBuilder);
                _capBuilder = null;
            }
            if (_graphBuilder != null)
            {
                Release.ComObject("graph builder", _graphBuilder);
                _graphBuilder = null;
            }
        }
Example #22
0
        /// <summary>
        /// Creates the tuning space.
        /// </summary>
        protected void CreateTuningSpace()
        {
            Log.Log.WriteFile("dvbs:CreateTuningSpace()");
            ITuner                tuner = (ITuner)_filterNetworkProvider;
            SystemTuningSpaces    systemTuningSpaces = new SystemTuningSpaces();
            ITuningSpaceContainer container          = systemTuningSpaces as ITuningSpaceContainer;

            if (container == null)
            {
                Log.Log.Error("CreateTuningSpace() Failed to get ITuningSpaceContainer");
                return;
            }
            IEnumTuningSpaces enumTuning;

            ITuningSpace[] spaces = new ITuningSpace[2];
            int            lowOsc;
            int            hiOsc;
            int            lnbSwitch;

            if (_parameters.UseDefaultLnbFrequencies)
            {
                lowOsc    = 9750;
                hiOsc     = 10600;
                lnbSwitch = 11700;
            }
            else
            {
                lowOsc    = _parameters.LnbLowFrequency;
                hiOsc     = _parameters.LnbHighFrequency;
                lnbSwitch = _parameters.LnbSwitchFrequency;
            }
            ITuneRequest request;

            container.get_EnumTuningSpaces(out enumTuning);
            IDVBSTuningSpace tuningSpace;

            while (true)
            {
                int fetched;
                enumTuning.Next(1, spaces, out fetched);
                if (fetched != 1)
                {
                    break;
                }
                string name;
                spaces[0].get_UniqueName(out name);
                if (name == "MediaPortal DVBS TuningSpace")
                {
                    Log.Log.WriteFile("dvbs:found correct tuningspace {0}", name);

                    _tuningSpace = (IDVBSTuningSpace)spaces[0];
                    tuningSpace  = (IDVBSTuningSpace)_tuningSpace;
                    tuningSpace.put_LNBSwitch(lnbSwitch * 1000);
                    tuningSpace.put_SpectralInversion(SpectralInversion.Automatic);
                    tuningSpace.put_LowOscillator(lowOsc * 1000);
                    tuningSpace.put_HighOscillator(hiOsc * 1000);
                    tuner.put_TuningSpace(tuningSpace);
                    tuningSpace.CreateTuneRequest(out request);
                    _tuneRequest = (IDVBTuneRequest)request;
                    return;
                }
                Release.ComObject("ITuningSpace", spaces[0]);
            }
            Release.ComObject("IEnumTuningSpaces", enumTuning);
            Log.Log.WriteFile("dvbs:Create new tuningspace");
            _tuningSpace = (IDVBSTuningSpace) new DVBSTuningSpace();
            tuningSpace  = (IDVBSTuningSpace)_tuningSpace;
            tuningSpace.put_UniqueName("MediaPortal DVBS TuningSpace");
            tuningSpace.put_FriendlyName("MediaPortal DVBS TuningSpace");
            tuningSpace.put__NetworkType(typeof(DVBSNetworkProvider).GUID);
            tuningSpace.put_SystemType(DVBSystemType.Satellite);
            tuningSpace.put_LNBSwitch(lnbSwitch * 1000);
            tuningSpace.put_LowOscillator(lowOsc * 1000);
            tuningSpace.put_HighOscillator(hiOsc * 1000);
            IDVBSLocator locator = (IDVBSLocator) new DVBSLocator();

            locator.put_CarrierFrequency(-1);
            locator.put_InnerFEC(FECMethod.MethodNotSet);
            locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_Modulation(ModulationType.ModNotSet);
            locator.put_OuterFEC(FECMethod.MethodNotSet);
            locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_SymbolRate(-1);
            object newIndex;

            _tuningSpace.put_DefaultLocator(locator);
            container.Add(_tuningSpace, out newIndex);
            tuner.put_TuningSpace(_tuningSpace);
            Release.ComObject("TuningSpaceContainer", container);
            _tuningSpace.CreateTuneRequest(out request);
            _tuneRequest = (IDVBTuneRequest)request;
        }
Example #23
0
 /// <summary>
 /// Creates the filter by trying to detect it
 /// </summary>
 /// <param name="crossbar">The crossbar componen</param>
 /// <param name="tuner">The tuner component</param>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphBuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 private bool CreateAutomaticFilterInstance(Graph graph, Tuner tuner, Crossbar crossbar, IFilterGraph2 graphBuilder)
 {
     //get all tv audio tuner devices on this system
     DsDevice[] devices = null;
     try
     {
         devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
         devices = DeviceSorter.Sort(devices, tuner.TunerName, crossbar.CrossBarName);
     }
     catch (Exception)
     {
         Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
     }
     if (devices != null && devices.Length > 0)
     {
         // try each tv audio tuner
         for (int i = 0; i < devices.Length; i++)
         {
             IBaseFilter tmp;
             Log.Log.WriteFile("analog: AddTvAudioFilter try:{0} {1}", devices[i].Name, i);
             //if tv audio tuner is currently in use we can skip it
             if (DevicesInUse.Instance.IsUsed(devices[i]))
             {
                 continue;
             }
             int hr;
             try
             {
                 //add tv audio tuner to graph
                 hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
             }
             catch (Exception)
             {
                 Log.Log.WriteFile("analog: cannot add filter to graph");
                 continue;
             }
             if (hr != 0)
             {
                 //failed to add tv audio tuner to graph, continue with the next one
                 if (tmp != null)
                 {
                     graphBuilder.RemoveFilter(tmp);
                     Release.ComObject("tvAudioFilter filter", tmp);
                 }
                 continue;
             }
             // try connecting the tv tuner-> tv audio tuner
             if (FilterGraphTools.ConnectPin(graphBuilder, tuner.AudioPin, tmp, 0))
             {
                 // Got it !
                 // Connect tv audio tuner to the crossbar
                 IPin pin = DsFindPin.ByDirection(tmp, PinDirection.Output, 0);
                 hr = graphBuilder.Connect(pin, crossbar.AudioTunerIn);
                 if (hr < 0)
                 {
                     //failed
                     graphBuilder.RemoveFilter(tmp);
                     Release.ComObject("audiotuner pinin", pin);
                     Release.ComObject("audiotuner filter", tmp);
                 }
                 else
                 {
                     //succeeded. we're done
                     Log.Log.WriteFile("analog: AddTvAudioFilter succeeded:{0}", devices[i].Name);
                     Release.ComObject("audiotuner pinin", pin);
                     _filterTvAudioTuner = tmp;
                     _audioDevice        = devices[i];
                     DevicesInUse.Instance.Add(_audioDevice);
                     _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
                     break;
                 }
             }
             else
             {
                 // cannot connect tv tuner-> tv audio tuner, try next one...
                 graphBuilder.RemoveFilter(tmp);
                 Release.ComObject("audiotuner filter", tmp);
             }
         }
     }
     if (_filterTvAudioTuner == null)
     {
         Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
         int hr = graphBuilder.Connect(tuner.AudioPin, crossbar.AudioTunerIn);
         if (hr != 0)
         {
             Log.Log.Error("analog: unable to add TvAudioTuner to graph - even TvTuner as TvAudio fails");
             mode = TvAudioVariant.Unavailable;
         }
         else
         {
             Log.Log.WriteFile("analog: AddTvAudioFilter connected TvTuner with Crossbar directly succeeded!");
             mode = TvAudioVariant.TvTunerConnection;
             _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
             if (_tvAudioTunerInterface != null)
             {
                 Log.Log.WriteFile("analog: AddTvAudioFilter succeeded - TvTuner is also TvAudio");
                 _filterTvAudioTuner = tuner.Filter;
                 mode = TvAudioVariant.TvTuner;
             }
         }
         graph.TvAudio.Mode = mode;
     }
     else
     {
         mode = TvAudioVariant.Normal;
         graph.TvAudio.Name = _audioDevice.Name;
     }
     if (mode != TvAudioVariant.Unavailable && mode != TvAudioVariant.TvTunerConnection &&
         _tvAudioTunerInterface != null)
     {
         CheckCapabilities(graph);
     }
     return(true);
 }
Example #24
0
        private void DetectSupportedBdaSourceDevices(ref HashSet <string> previouslyKnownDevices, ref HashSet <string> knownDevices)
        {
            Log.Log.Debug("Detect BDA source devices");

            // MS generic, MCE 2005 roll-up 2 or better
            bool isMsGenericNpAvailable = FilterGraphTools.IsThisComObjectInstalled(typeof(NetworkProvider).GUID);

            DsDevice[] connectedDevices = DsDevice.GetDevicesOfCat(FilterCategory.BDASourceFiltersCategory);
            foreach (DsDevice connectedDevice in connectedDevices)
            {
                string name       = connectedDevice.Name;
                string devicePath = connectedDevice.DevicePath;
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(devicePath))
                {
                    continue;
                }
                if (previouslyKnownDevices.Contains(devicePath))
                {
                    knownDevices.Add(devicePath);
                    continue;
                }

                // North American CableCARD tuners [PBDA].
                if (name.StartsWith("HDHomeRun Prime") || name.StartsWith("Ceton InfiniTV"))
                {
                    Log.Log.Info("Detected new PBDA CableCARD tuner device {0} {1}", name, devicePath);
                    TunerPbdaCableCard cableCardTuner = new TunerPbdaCableCard(connectedDevice);
                    knownDevices.Add(devicePath);
                    _deviceEventListener.OnDeviceAdded(cableCardTuner);
                    continue;
                }

                IBaseFilter tmpDeviceFilter;
                try
                {
                    _graphBuilder.AddSourceFilterForMoniker(connectedDevice.Mon, null, name, out tmpDeviceFilter);
                }
                catch (Exception ex)
                {
                    Log.Log.Error("Failed to add filter to detect device type for {0}!\r\n{1}", name, ex);
                    continue;
                }

                try
                {
                    // Silicondust regular (non-CableCARD) HDHomeRun. Workaround for tuner type
                    // detection issue. The MS generic provider would always detect DVB-T.
                    bool isCablePreferred = false;
                    if (name.StartsWith("Silicondust HDHomeRun Tuner"))
                    {
                        isCablePreferred = GetHdHomeRunSourceType(name).Equals("Digital Cable");
                    }

                    Log.Log.Info("Detected new digital BDA tuner device {0} {1}", name, devicePath);

                    // Try the MediaPortal network provider first.
                    ITVCard deviceToAdd = null;
                    if (_mpNp != null)
                    {
                        Log.Log.Debug("  check type with MP NP");
                        IDvbNetworkProvider interfaceNetworkProvider = (IDvbNetworkProvider)_mpNp;
                        string hash = GetHash(devicePath);
                        interfaceNetworkProvider.ConfigureLogging(GetFileName(devicePath), hash, LogLevelOption.Debug);
                        if (ConnectFilter(_graphBuilder, _mpNp, tmpDeviceFilter))
                        {
                            TuningType tuningTypes;
                            interfaceNetworkProvider.GetAvailableTuningTypes(out tuningTypes);
                            Log.Log.Debug("  tuning types = {0}, hash = {1}", tuningTypes, hash);
                            if ((tuningTypes & TuningType.DvbT) != 0 && !isCablePreferred)
                            {
                                deviceToAdd = new TvCardDVBT(connectedDevice);
                            }
                            else if ((tuningTypes & TuningType.DvbS) != 0 && !isCablePreferred)
                            {
                                deviceToAdd = new TvCardDVBS(connectedDevice);
                            }
                            else if ((tuningTypes & TuningType.DvbC) != 0)
                            {
                                deviceToAdd = new TvCardDVBC(connectedDevice);
                            }
                            else if ((tuningTypes & TuningType.Atsc) != 0)
                            {
                                deviceToAdd = new TvCardATSC(connectedDevice);
                            }
                            else
                            {
                                Log.Log.Debug("  connected to MP NP but type not recognised");
                            }
                        }
                        else
                        {
                            Log.Log.Debug("  failed to connect to MP NP");
                        }
                    }
                    // Try the Microsoft network provider next if the MP NP
                    // failed and the MS generic NP is available.
                    if (deviceToAdd == null && isMsGenericNpAvailable)
                    {
                        // Note: the MS NP must be added/removed to/from the graph for each
                        // device that is checked. If you don't do this, the networkTypes
                        // list gets longer and longer and longer.
                        Log.Log.Debug("  check type with MS NP");
                        IBaseFilter genericNp = null;
                        try
                        {
                            genericNp = FilterGraphTools.AddFilterFromClsid(_graphBuilder, typeof(NetworkProvider).GUID, "Microsoft Network Provider");
                        }
                        catch
                        {
                            genericNp = null;
                        }
                        if (genericNp == null)
                        {
                            Log.Log.Error(" failed to add MS NP to graph");
                        }
                        else
                        {
                            if (ConnectFilter(_graphBuilder, genericNp, tmpDeviceFilter))
                            {
                                int    networkTypesMax = 5;
                                int    networkTypeCount;
                                Guid[] networkTypes = new Guid[networkTypesMax];
                                int    hr           = (genericNp as ITunerCap).get_SupportedNetworkTypes(networkTypesMax, out networkTypeCount, networkTypes);
                                Log.Log.Debug("  network type count = {0}", networkTypeCount);
                                for (int n = 0; n < networkTypeCount; n++)
                                {
                                    Log.Log.Debug("  network type {0} = {1}", n, networkTypes[n]);
                                }
                                for (int n = 0; n < networkTypeCount; n++)
                                {
                                    if (networkTypes[n] == typeof(DVBTNetworkProvider).GUID && !isCablePreferred)
                                    {
                                        deviceToAdd = new TvCardDVBT(connectedDevice);
                                    }
                                    else if (networkTypes[n] == typeof(DVBSNetworkProvider).GUID && !isCablePreferred)
                                    {
                                        deviceToAdd = new TvCardDVBS(connectedDevice);
                                    }
                                    else if (networkTypes[n] == typeof(DVBCNetworkProvider).GUID)
                                    {
                                        deviceToAdd = new TvCardDVBC(connectedDevice);
                                    }
                                    else if (networkTypes[n] == typeof(ATSCNetworkProvider).GUID)
                                    {
                                        deviceToAdd = new TvCardATSC(connectedDevice);
                                    }
                                    if (deviceToAdd != null)
                                    {
                                        break;
                                    }
                                    else if (n == (networkTypeCount - 1))
                                    {
                                        Log.Log.Debug(" connected to MS NP but type not recognised");
                                    }
                                }
                            }
                            else
                            {
                                Log.Log.Debug("  failed to connect to MS NP");
                            }

                            _graphBuilder.RemoveFilter(genericNp);
                            Release.ComObject("device detection generic network provider", genericNp);
                            genericNp = null;
                        }
                    }
                    // Last shot is the old style Microsoft network providers.
                    if (deviceToAdd == null)
                    {
                        Log.Log.Debug("  check type with specific NPs");
                        if (ConnectFilter(_graphBuilder, _dvbtNp, tmpDeviceFilter))
                        {
                            deviceToAdd = new TvCardDVBT(connectedDevice);
                        }
                        else if (ConnectFilter(_graphBuilder, _dvbcNp, tmpDeviceFilter))
                        {
                            deviceToAdd = new TvCardDVBC(connectedDevice);
                        }
                        else if (ConnectFilter(_graphBuilder, _dvbsNp, tmpDeviceFilter))
                        {
                            deviceToAdd = new TvCardDVBS(connectedDevice);
                        }
                        else if (ConnectFilter(_graphBuilder, _atscNp, tmpDeviceFilter))
                        {
                            deviceToAdd = new TvCardATSC(connectedDevice);
                        }
                        else
                        {
                            Log.Log.Debug("  failed to connect to specific NP");
                        }
                    }

                    if (deviceToAdd != null)
                    {
                        Log.Log.Info("  tuner type = {0}", deviceToAdd.CardType);
                        knownDevices.Add(devicePath);
                        _deviceEventListener.OnDeviceAdded(deviceToAdd);
                    }
                }
                finally
                {
                    _graphBuilder.RemoveFilter(tmpDeviceFilter);
                    Release.ComObject("device detection device filter", tmpDeviceFilter);
                }
            }
        }
Example #25
0
        public bool Play(string fileName, Form form)
        {
            _form = form;
            Log.WriteFile("play:{0}", fileName);
            _graphBuilder = (IFilterGraph2) new FilterGraph();
            _rotEntry     = new DsROTEntry(_graphBuilder);

            TsReader reader = new TsReader();

            _tsReader = (IBaseFilter)reader;
            Log.Info("TSReaderPlayer:add TsReader to graph");
            _graphBuilder.AddFilter(_tsReader, "TsReader");

            #region load file in TsReader

            Log.WriteFile("load file in Ts");
            IFileSourceFilter interfaceFile = (IFileSourceFilter)_tsReader;
            if (interfaceFile == null)
            {
                Log.WriteFile("TSReaderPlayer:Failed to get IFileSourceFilter");
                return(false);
            }
            int hr = interfaceFile.Load(fileName, null);

            if (hr != 0)
            {
                Log.WriteFile("TSReaderPlayer:Failed to load file");
                return(false);
            }

            #endregion

            #region render pin

            Log.Info("TSReaderPlayer:render TsReader outputs");
            IEnumPins enumPins;
            _tsReader.EnumPins(out enumPins);
            IPin[] pins = new IPin[2];
            int    fetched;
            while (enumPins.Next(1, pins, out fetched) == 0)
            {
                if (fetched != 1)
                {
                    break;
                }
                PinDirection direction;
                pins[0].QueryDirection(out direction);
                if (direction == PinDirection.Input)
                {
                    Release.ComObject(pins[0]);
                    continue;
                }
                _graphBuilder.Render(pins[0]);
                Release.ComObject(pins[0]);
            }
            Release.ComObject(enumPins);

            #endregion

            _videoWin = _graphBuilder as IVideoWindow;
            if (_videoWin != null)
            {
                _videoWin.put_Visible(OABool.True);
                _videoWin.put_Owner(form.Handle);
                _videoWin.put_WindowStyle(
                    (WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipSiblings + (int)WindowStyle.ClipChildren));
                _videoWin.put_MessageDrain(form.Handle);

                _videoWin.SetWindowPosition(form.ClientRectangle.X, form.ClientRectangle.Y, form.ClientRectangle.Width,
                                            form.ClientRectangle.Height);
            }

            Log.WriteFile("run graph");
            _mediaCtrl = (IMediaControl)_graphBuilder;
            hr         = _mediaCtrl.Run();
            Log.WriteFile("TSReaderPlayer:running:{0:X}", hr);

            return(true);
        }
Example #26
0
        /// <summary>
        /// Creates the tuning space.
        /// </summary>
        protected void CreateTuningSpace()
        {
            Log.Log.WriteFile("dvbt:CreateTuningSpace()");
            ITuner                tuner = (ITuner)_filterNetworkProvider;
            SystemTuningSpaces    systemTuningSpaces = new SystemTuningSpaces();
            ITuningSpaceContainer container          = systemTuningSpaces as ITuningSpaceContainer;

            if (container == null)
            {
                Log.Log.Error("CreateTuningSpace() Failed to get ITuningSpaceContainer");
                return;
            }
            IEnumTuningSpaces enumTuning;

            ITuningSpace[] spaces = new ITuningSpace[2];
            ITuneRequest   request;

            container.get_EnumTuningSpaces(out enumTuning);
            while (true)
            {
                int fetched;
                enumTuning.Next(1, spaces, out fetched);
                if (fetched != 1)
                {
                    break;
                }
                string name;
                spaces[0].get_UniqueName(out name);
                if (name == "MediaPortal DVBT TuningSpace")
                {
                    Log.Log.WriteFile("dvbt:found correct tuningspace {0}", name);
                    _tuningSpace = (IDVBTuningSpace)spaces[0];
                    tuner.put_TuningSpace(_tuningSpace);
                    _tuningSpace.CreateTuneRequest(out request);
                    _tuneRequest = (IDVBTuneRequest)request;
                    return;
                }
                Release.ComObject("ITuningSpace", spaces[0]);
            }
            Release.ComObject("IEnumTuningSpaces", enumTuning);
            Log.Log.WriteFile("dvbt:Create new tuningspace");
            _tuningSpace = (IDVBTuningSpace) new DVBTuningSpace();
            IDVBTuningSpace tuningSpace = (IDVBTuningSpace)_tuningSpace;

            tuningSpace.put_UniqueName("MediaPortal DVBT TuningSpace");
            tuningSpace.put_FriendlyName("MediaPortal DVBT TuningSpace");
            tuningSpace.put__NetworkType(typeof(DVBTNetworkProvider).GUID);
            tuningSpace.put_SystemType(DVBSystemType.Terrestrial);

            IDVBTLocator locator = (IDVBTLocator) new DVBTLocator();

            locator.put_CarrierFrequency(-1);
            locator.put_InnerFEC(FECMethod.MethodNotSet);
            locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_Modulation(ModulationType.ModNotSet);
            locator.put_OuterFEC(FECMethod.MethodNotSet);
            locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_SymbolRate(-1);
            object newIndex;

            _tuningSpace.put_DefaultLocator(locator);
            container.Add(_tuningSpace, out newIndex);
            tuner.put_TuningSpace(_tuningSpace);
            Release.ComObject("ITuningSpaceContainer", container);
            _tuningSpace.CreateTuneRequest(out request);
            _tuneRequest = request;
        }
Example #27
0
        private void handleInternalNetworkProviderFilter(DsDevice[] devices, IFilterGraph2 graphBuilder,
                                                         Guid networkProviderClsId, DsROTEntry rotEntry)
        {
            IDvbNetworkProvider interfaceNetworkProvider;
            TuningType          tuningTypes;

            for (int i = 0; i < devices.Length; i++)
            {
                bool   isCablePreferred = false;
                string name             = devices[i].Name ?? "unknown";
                name = name.ToLowerInvariant();
                Log.Log.WriteFile("Found card:{0}", name);
                //silicondust work-around for dvb type detection issue. generic provider would always use dvb-t
                if (name.Contains("silicondust hdhomerun tuner"))
                {
                    isCablePreferred = CheckHDHomerunCablePrefered(name);
                    Log.Log.WriteFile("silicondust hdhomerun detected - prefer cable mode: {0}", isCablePreferred);
                }
                IBaseFilter tmp;
                graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, name, out tmp);
                //Use the Microsoft Network Provider method first but only if available
                IBaseFilter networkDVB = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                             "MediaPortal Network Provider");
                interfaceNetworkProvider = (IDvbNetworkProvider)networkDVB;
                string hash = GetHash(devices[i].DevicePath);
                interfaceNetworkProvider.ConfigureLogging(GetFileName(devices[i].DevicePath), hash, LogLevelOption.Debug);
                if (ConnectFilter(graphBuilder, networkDVB, tmp))
                {
                    Log.Log.WriteFile("Detected DVB card:{0}- Hash: {1}", name, hash);
                    interfaceNetworkProvider.GetAvailableTuningTypes(out tuningTypes);
                    Log.Log.WriteFile("TuningTypes: " + tuningTypes);
                    // determine the DVB card supported GUIDs here!
                    if ((tuningTypes & TuningType.DvbT) != 0 && !isCablePreferred)
                    {
                        Log.Log.WriteFile("Detected DVB-T* card:{0}", name);
                        TvCardDVBT dvbtCard = new TvCardDVBT(_epgEvents, devices[i]);
                        _cards.Add(dvbtCard);
                    }
                    if ((tuningTypes & TuningType.DvbS) != 0 && !isCablePreferred)
                    {
                        Log.Log.WriteFile("Detected DVB-S* card:{0}", name);
                        TvCardDVBS dvbsCard = new TvCardDVBS(_epgEvents, devices[i]);
                        _cards.Add(dvbsCard);
                    }
                    if ((tuningTypes & TuningType.DvbC) != 0)
                    {
                        Log.Log.WriteFile("Detected DVB-C* card:{0}", name);
                        TvCardDVBC dvbcCard = new TvCardDVBC(_epgEvents, devices[i]);
                        _cards.Add(dvbcCard);
                    }
                    if ((tuningTypes & TuningType.Atsc) != 0 && !isCablePreferred)
                    {
                        Log.Log.WriteFile("Detected ATSC* card:{0}", name);
                        TvCardATSC dvbsCard = new TvCardATSC(_epgEvents, devices[i]);
                        _cards.Add(dvbsCard);
                    }
                }
                graphBuilder.RemoveFilter(tmp);
                Release.ComObject("tmp filter", tmp);
                graphBuilder.RemoveFilter(networkDVB);
                Release.ComObject("ms provider", networkDVB);
            }
            FilterGraphTools.RemoveAllFilters(graphBuilder);
            rotEntry.Dispose();
            Release.ComObject("graph builder", graphBuilder);
        }
        /// <summary>
        /// Creates the teletext component in the graph. First we try to use the stored informations in the graph
        /// </summary>
        /// <param name="graph">The stored graph</param>
        /// <param name="graphBuilder">The graphbuilder</param>
        /// <param name="capture">The capture component</param>
        /// <returns>true, if the building was successful; false otherwise</returns>
        public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Capture capture)
        {
            Log.Log.WriteFile("analog: SetupTeletext()");
            Guid   guidBaseFilter = typeof(IBaseFilter).GUID;
            object obj;

            //find and add tee/sink to sink filter
            DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSSplitter);
            devices[0].Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
            _teeSink = (IBaseFilter)obj;
            int hr = graphBuilder.AddFilter(_teeSink, devices[0].Name);

            if (hr != 0)
            {
                Log.Log.Error("analog:SinkGraphEx.SetupTeletext(): Unable to add tee/sink filter");
                return(false);
            }
            //connect capture filter -> tee sink filter
            IPin pin = DsFindPin.ByDirection(_teeSink, PinDirection.Input, 0);

            hr = graphBuilder.Connect(capture.VBIPin, pin);
            Release.ComObject(pin);
            if (hr != 0)
            {
                //failed...
                Log.Log.Error("analog: unable  to connect capture->tee/sink");
                graphBuilder.RemoveFilter(_teeSink);
                Release.ComObject(_teeSink);
                _teeSink = _filterWstDecoder = null;
                return(false);
            }
            if (!string.IsNullOrEmpty(graph.Teletext.Name))
            {
                Log.Log.WriteFile("analog: Using Teletext-Component configuration from stored graph");
                devices = DsDevice.GetDevicesOfCat(graph.Teletext.Category);
                foreach (DsDevice device in devices)
                {
                    if (device.Name != null && device.Name.Equals(graph.Teletext.Name))
                    {
                        //found it, add it to the graph
                        Log.Log.Info("analog:Using teletext component - {0}", graph.Teletext.Name);
                        device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
                        _filterWstDecoder = (IBaseFilter)obj;
                        hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
                        if (hr != 0)
                        {
                            //failed...
                            Log.Log.Error("analog:SinkGraphEx.SetupTeletext(): Unable to add WST Codec filter");
                            graphBuilder.RemoveFilter(_filterWstDecoder);
                            _filterWstDecoder = null;
                        }
                        break;
                    }
                }
            }
            if (_filterWstDecoder == null)
            {
                Log.Log.WriteFile("analog: No stored or invalid graph for Teletext component - Trying to detect");

                //find the WST codec filter
                devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSVBICodec);
                foreach (DsDevice device in devices)
                {
                    if (device.Name != null && device.Name.IndexOf("WST") >= 0)
                    {
                        //found it, add it to the graph
                        Log.Log.Info("analog:Found WST Codec filter");
                        device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
                        _filterWstDecoder = (IBaseFilter)obj;
                        hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
                        if (hr != 0)
                        {
                            //failed...
                            Log.Log.Error("analog:Unable to add WST Codec filter");
                            graphBuilder.RemoveFilter(_teeSink);
                            Release.ComObject(_teeSink);
                            _teeSink = _filterWstDecoder = null;
                            return(false);
                        }
                        graph.Teletext.Name     = device.Name;
                        graph.Teletext.Category = FilterCategory.AMKSVBICodec;
                        break;
                    }
                }
                //Look for VBI Codec for Vista users as Vista doesn't use WST Codec anymore
                if (_filterWstDecoder == null)
                {
                    devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSMULTIVBICodec);
                    foreach (DsDevice device in devices)
                    {
                        if (device.Name != null && device.Name.IndexOf("VBI") >= 0)
                        {
                            //found it, add it to the graph
                            Log.Log.Info("analog:Found VBI Codec filter");
                            device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
                            _filterWstDecoder = (IBaseFilter)obj;
                            hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
                            if (hr != 0)
                            {
                                //failed...
                                Log.Log.Error("analog:Unable to add VBI Codec filter");
                                graphBuilder.RemoveFilter(_teeSink);
                                Release.ComObject(_teeSink);
                                _teeSink = _filterWstDecoder = null;
                                return(false);
                            }
                            graph.Teletext.Name     = device.Name;
                            graph.Teletext.Category = FilterCategory.AMKSMULTIVBICodec;
                            break;
                        }
                    }
                }
            }
            if (_filterWstDecoder == null)
            {
                Log.Log.Error("analog: unable to find WST Codec or VBI Codec filter");
                graphBuilder.RemoveFilter(_teeSink);
                Release.ComObject(_teeSink);
                _teeSink = _filterWstDecoder = null;
                return(false);
            }
            //connect tee sink filter-> wst codec filter
            IPin pinOut = DsFindPin.ByDirection(_teeSink, PinDirection.Output, 0);

            pin = DsFindPin.ByDirection(_filterWstDecoder, PinDirection.Input, 0);
            hr  = graphBuilder.Connect(pinOut, pin);
            Release.ComObject(pin);
            Release.ComObject(pinOut);
            if (hr != 0)
            {
                //failed
                Log.Log.Error("analog: unable  to tee/sink->wst codec");
                graphBuilder.RemoveFilter(_filterWstDecoder);
                graphBuilder.RemoveFilter(_teeSink);
                Release.ComObject(_filterWstDecoder);
                Release.ComObject(_teeSink);
                _teeSink                = _filterWstDecoder = null;
                _teeSink                = null;
                graph.Teletext.Name     = null;
                graph.Teletext.Category = new Guid();
                return(false);
            }
            //done
            Log.Log.WriteFile("analog: teletext setup");

            if (_filterWstDecoder != null)
            {
                Log.Log.WriteFile("analog:connect wst/vbi codec->tsfilesink");
                _pinWST_VBI = DsFindPin.ByDirection(_filterWstDecoder, PinDirection.Output, 0);
            }

            return(true);
        }
Example #29
0
        /// <summary>
        /// Enumerate all tvcard devices and add them to the list
        /// </summary>
        private void DetectCards()
        {
            ITunerCap _providerType;
            bool      genericNP = false;

            //SkyStar 2 & IP Streaming
            DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.LegacyAmFilterCategory);
            for (int i = 0; i < devices.Length; ++i)
            {
                if (String.Compare(devices[i].Name, "B2C2 MPEG-2 Source", true) == 0)
                {
                    Log.Log.WriteFile("Detected SkyStar 2 card");
                    TvCardDvbSS2 card = new TvCardDvbSS2(_epgEvents, devices[i]);
                    _cards.Add(card);
                    //break;  maybe more than one B2C2 card ?
                }
                else if (String.Compare(devices[i].Name, "Elecard NWSource-Plus", true) == 0)
                {
                    TvBusinessLayer layer = new TvBusinessLayer();
                    Setting         setting;
                    setting = layer.GetSetting("iptvCardCount", "1");
                    int iptvCardCount = Convert.ToInt32(setting.Value);
                    for (int cardNum = 0; cardNum < iptvCardCount; cardNum++)
                    {
                        Log.Log.WriteFile("Detected IP TV Card " + cardNum);
                        TvCardDVBIP card = new TvCardDVBIPElecard(_epgEvents, devices[i], cardNum);
                        _cards.Add(card);
                    }
                }
                else if (String.Compare(devices[i].Name, "MediaPortal IPTV Source Filter", true) == 0)
                {
                    TvBusinessLayer layer = new TvBusinessLayer();
                    Setting         setting;
                    setting = layer.GetSetting("iptvCardCount", "1");
                    int iptvCardCount = Convert.ToInt32(setting.Value);
                    for (int cardNum = 0; cardNum < iptvCardCount; cardNum++)
                    {
                        Log.Log.WriteFile("Detected IP TV Card " + cardNum);
                        TvCardDVBIP card = new TvCardDVBIPBuiltIn(_epgEvents, devices[i], cardNum);
                        _cards.Add(card);
                    }
                }
            }
            //Hauppauge HD PVR & Colossus
            devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar);
            for (int i = 0; i < devices.Length; ++i)
            {
                if (devices[i].Name == null)
                {
                    continue;
                }
                if (devices[i].Name.Equals("Hauppauge HD PVR Crossbar"))
                {
                    Log.Log.WriteFile("Detected Hauppauge HD PVR");
                    TvCardHDPVR card = new TvCardHDPVR(devices[i]);
                    _cards.Add(card);
                }
                else if (devices[i].Name.Contains("Hauppauge Colossus Crossbar"))
                {
                    Log.Log.WriteFile("Detected Hauppauge Colossus");
                    TvCardHDPVR card = new TvCardHDPVR(devices[i]);
                    _cards.Add(card);
                }
            }
            //BDA TV devices
            devices = DsDevice.GetDevicesOfCat(FilterCategory.BDASourceFiltersCategory);
            if (devices.Length > 0)
            {
                IFilterGraph2 graphBuilder = (IFilterGraph2) new FilterGraph();
                DsROTEntry    rotEntry     = new DsROTEntry(graphBuilder);

                Guid networkProviderClsId = new Guid("{D7D42E5C-EB36-4aad-933B-B4C419429C98}");
                if (FilterGraphTools.IsThisComObjectInstalled(networkProviderClsId))
                {
                    handleInternalNetworkProviderFilter(devices, graphBuilder, networkProviderClsId, rotEntry);
                }
                else
                {
                    ITuningSpace tuningSpace = null;
                    ILocator     locator     = null;

                    //DVBT
                    IBaseFilter networkDVBT = null;
                    try
                    {
                        networkProviderClsId = typeof(DVBTNetworkProvider).GUID;
                        networkDVBT          = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                                   "DVBT Network Provider");
                        tuningSpace = (ITuningSpace) new DVBTuningSpace();
                        tuningSpace.put_UniqueName("DVBT TuningSpace");
                        tuningSpace.put_FriendlyName("DVBT TuningSpace");
                        tuningSpace.put__NetworkType(typeof(DVBTNetworkProvider).GUID);
                        ((IDVBTuningSpace)tuningSpace).put_SystemType(DVBSystemType.Terrestrial);
                        locator = (ILocator) new DVBTLocator();
                        locator.put_CarrierFrequency(-1);
                        locator.put_InnerFEC(FECMethod.MethodNotSet);
                        locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
                        locator.put_Modulation(ModulationType.ModNotSet);
                        locator.put_OuterFEC(FECMethod.MethodNotSet);
                        locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
                        locator.put_SymbolRate(-1);
                        tuningSpace.put_DefaultLocator(locator);
                        ((ITuner)networkDVBT).put_TuningSpace(tuningSpace);
                    }
                    catch (Exception ex)
                    {
                        Log.Log.Error("DVBT card detection error: {0}", ex.ToString());
                    }

                    //DVBS
                    networkProviderClsId = typeof(DVBSNetworkProvider).GUID;
                    IBaseFilter networkDVBS = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                                  "DVBS Network Provider");
                    tuningSpace = (ITuningSpace) new DVBSTuningSpace();
                    tuningSpace.put_UniqueName("DVBS TuningSpace");
                    tuningSpace.put_FriendlyName("DVBS TuningSpace");
                    tuningSpace.put__NetworkType(typeof(DVBSNetworkProvider).GUID);
                    ((IDVBSTuningSpace)tuningSpace).put_SystemType(DVBSystemType.Satellite);
                    locator = (ILocator) new DVBTLocator();
                    locator.put_CarrierFrequency(-1);
                    locator.put_InnerFEC(FECMethod.MethodNotSet);
                    locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_Modulation(ModulationType.ModNotSet);
                    locator.put_OuterFEC(FECMethod.MethodNotSet);
                    locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_SymbolRate(-1);
                    tuningSpace.put_DefaultLocator(locator);
                    ((ITuner)networkDVBS).put_TuningSpace(tuningSpace);

                    //ATSC
                    networkProviderClsId = typeof(ATSCNetworkProvider).GUID;
                    IBaseFilter networkATSC = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                                  "ATSC Network Provider");
                    tuningSpace = (ITuningSpace) new ATSCTuningSpace();
                    tuningSpace.put_UniqueName("ATSC TuningSpace");
                    tuningSpace.put_FriendlyName("ATSC TuningSpace");
                    ((IATSCTuningSpace)tuningSpace).put_MaxChannel(10000);
                    ((IATSCTuningSpace)tuningSpace).put_MaxMinorChannel(10000);
                    ((IATSCTuningSpace)tuningSpace).put_MinChannel(0);
                    ((IATSCTuningSpace)tuningSpace).put_MinMinorChannel(0);
                    ((IATSCTuningSpace)tuningSpace).put_MinPhysicalChannel(0);
                    ((IATSCTuningSpace)tuningSpace).put_InputType(TunerInputType.Antenna);
                    locator = (IATSCLocator) new ATSCLocator();
                    locator.put_CarrierFrequency(-1);
                    locator.put_InnerFEC(FECMethod.MethodNotSet);
                    locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_Modulation(ModulationType.ModNotSet);
                    locator.put_OuterFEC(FECMethod.MethodNotSet);
                    locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_SymbolRate(-1);
                    locator.put_CarrierFrequency(-1);
                    ((IATSCLocator)locator).put_PhysicalChannel(-1);
                    ((IATSCLocator)locator).put_TSID(-1);
                    tuningSpace.put_DefaultLocator(locator);
                    ((ITuner)networkATSC).put_TuningSpace(tuningSpace);

                    //DVBC
                    networkProviderClsId = typeof(DVBCNetworkProvider).GUID;
                    IBaseFilter networkDVBC = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                                  "DVBC Network Provider");
                    tuningSpace = (ITuningSpace) new DVBTuningSpace();
                    tuningSpace.put_UniqueName("DVBC TuningSpace");
                    tuningSpace.put_FriendlyName("DVBC TuningSpace");
                    tuningSpace.put__NetworkType(typeof(DVBCNetworkProvider).GUID);
                    ((IDVBTuningSpace)tuningSpace).put_SystemType(DVBSystemType.Cable);
                    locator = (ILocator) new DVBCLocator();
                    locator.put_CarrierFrequency(-1);
                    locator.put_InnerFEC(FECMethod.MethodNotSet);
                    locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_Modulation(ModulationType.ModNotSet);
                    locator.put_OuterFEC(FECMethod.MethodNotSet);
                    locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
                    locator.put_SymbolRate(-1);
                    tuningSpace.put_DefaultLocator(locator);
                    ((ITuner)networkDVBC).put_TuningSpace(tuningSpace);

                    //MS Network Provider - MCE Roll-up 2 or better
                    networkProviderClsId = typeof(NetworkProvider).GUID;
                    // First test if the Generic Network Provider is available (only on MCE 2005 + Update Rollup 2)
                    if (FilterGraphTools.IsThisComObjectInstalled(networkProviderClsId))
                    {
                        genericNP = true;
                    }
                    for (int i = 0; i < devices.Length; i++)
                    {
                        bool   connected        = false;
                        bool   isCablePreferred = false;
                        string name             = devices[i].Name ?? "unknown";
                        name = name.ToLowerInvariant();
                        Log.Log.WriteFile("Found card:{0}", name);
                        //silicondust work-around for dvb type detection issue. generic provider would always use dvb-t
                        if (name.Contains("silicondust hdhomerun tuner"))
                        {
                            isCablePreferred = CheckHDHomerunCablePrefered(name);
                            Log.Log.WriteFile("silicondust hdhomerun detected - prefer cable mode: {0}", isCablePreferred);
                        }
                        IBaseFilter tmp;
                        try
                        {
                            graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, name, out tmp);
                        }
                        catch (InvalidComObjectException)
                        {
                            //ignore bad card
                            Log.Log.WriteFile("cannot add filter {0} to graph", devices[i].Name);
                            continue;
                        }
                        //Use the Microsoft Network Provider method first but only if available
                        if (genericNP)
                        {
                            IBaseFilter networkDVB = FilterGraphTools.AddFilterFromClsid(graphBuilder, networkProviderClsId,
                                                                                         "Microsoft Network Provider");
                            if (ConnectFilter(graphBuilder, networkDVB, tmp))
                            {
                                Log.Log.WriteFile("Detected DVB card:{0}", name);
                                // determine the DVB card supported GUIDs here!
                                _providerType = networkDVB as ITunerCap;
                                int    ulcNetworkTypesMax = 5;
                                int    pulcNetworkTypes;
                                Guid[] pguidNetworkTypes = new Guid[ulcNetworkTypesMax];
                                int    hr = _providerType.get_SupportedNetworkTypes(ulcNetworkTypesMax, out pulcNetworkTypes,
                                                                                    pguidNetworkTypes);
                                for (int n = 0; n < pulcNetworkTypes; n++)
                                {
                                    Log.Log.Debug("Detecting type by MSNP {0}: {1}", n, pguidNetworkTypes[n]);
                                    //test the first found guid to determine the DVB card type
                                    if (pguidNetworkTypes[n] == (typeof(DVBTNetworkProvider).GUID) && !isCablePreferred)
                                    {
                                        Log.Log.WriteFile("Detected DVB-T* card:{0}", name);
                                        TvCardDVBT dvbtCard = new TvCardDVBT(_epgEvents, devices[i]);
                                        _cards.Add(dvbtCard);
                                        connected = true;
                                    }
                                    else if (pguidNetworkTypes[n] == (typeof(DVBSNetworkProvider).GUID) && !isCablePreferred)
                                    {
                                        Log.Log.WriteFile("Detected DVB-S* card:{0}", name);
                                        TvCardDVBS dvbsCard = new TvCardDVBS(_epgEvents, devices[i]);
                                        _cards.Add(dvbsCard);
                                        connected = true;
                                    }
                                    else if (pguidNetworkTypes[n] == (typeof(DVBCNetworkProvider).GUID))
                                    {
                                        Log.Log.WriteFile("Detected DVB-C* card:{0}", name);
                                        TvCardDVBC dvbcCard = new TvCardDVBC(_epgEvents, devices[i]);
                                        _cards.Add(dvbcCard);
                                        connected = true;
                                    }
                                    else if (pguidNetworkTypes[n] == (typeof(ATSCNetworkProvider).GUID))
                                    {
                                        Log.Log.WriteFile("Detected ATSC* card:{0}", name);
                                        TvCardATSC dvbsCard = new TvCardATSC(_epgEvents, devices[i]);
                                        _cards.Add(dvbsCard);
                                        connected = true;
                                    }
                                    if (connected)
                                    {
                                        graphBuilder.RemoveFilter(tmp);
                                        Release.ComObject("tmp filter", tmp);
                                        break; // already found one, no need to continue
                                    }
                                    else if (n == (pulcNetworkTypes - 1))
                                    {
                                        Log.Log.WriteFile("Connected with generic MS Network Provider however network types don't match, using the original method");
                                    }
                                }
                            }
                            else
                            {
                                Log.Log.WriteFile("Not connected with generic MS Network Provider, using the original method");
                                connected = false;
                            }
                            graphBuilder.RemoveFilter(networkDVB);
                            Release.ComObject("ms provider", networkDVB);
                        }
                        if (!genericNP || !connected)
                        {
                            if (ConnectFilter(graphBuilder, networkDVBT, tmp))
                            {
                                Log.Log.WriteFile("Detected DVB-T card:{0}", name);
                                TvCardDVBT dvbtCard = new TvCardDVBT(_epgEvents, devices[i]);
                                _cards.Add(dvbtCard);
                            }
                            else if (ConnectFilter(graphBuilder, networkDVBC, tmp))
                            {
                                Log.Log.WriteFile("Detected DVB-C card:{0}", name);
                                TvCardDVBC dvbcCard = new TvCardDVBC(_epgEvents, devices[i]);
                                _cards.Add(dvbcCard);
                            }
                            else if (ConnectFilter(graphBuilder, networkDVBS, tmp))
                            {
                                Log.Log.WriteFile("Detected DVB-S card:{0}", name);
                                TvCardDVBS dvbsCard = new TvCardDVBS(_epgEvents, devices[i]);
                                _cards.Add(dvbsCard);
                            }
                            else if (ConnectFilter(graphBuilder, networkATSC, tmp))
                            {
                                Log.Log.WriteFile("Detected ATSC card:{0}", name);
                                TvCardATSC dvbsCard = new TvCardATSC(_epgEvents, devices[i]);
                                _cards.Add(dvbsCard);
                            }
                            graphBuilder.RemoveFilter(tmp);
                            Release.ComObject("tmp filter", tmp);
                        }
                    }
                    FilterGraphTools.RemoveAllFilters(graphBuilder);
                    Release.ComObject("dvbc provider", networkDVBC);
                    Release.ComObject("atsc provider", networkATSC);
                    Release.ComObject("dvbs provider", networkDVBS);
                    Release.ComObject("dvbt provider", networkDVBT);
                    rotEntry.Dispose();
                    Release.ComObject("graph builder", graphBuilder);
                }
            }
            //Analogue TV devices
            devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVTuner);
            for (int i = 0; i < devices.Length; i++)
            {
                string name = devices[i].Name ?? "unknown";
                name = name.ToLowerInvariant();
                Log.Log.WriteFile("Detected analog card:{0}", name);
                TvCardAnalog analogCard = new TvCardAnalog(devices[i]);
                _cards.Add(analogCard);
            }
            _cards.Add(new RadioWebStreamCard());
        }
Example #30
0
        /// <summary>
        /// Creates the tuning space.
        /// </summary>
        protected void CreateTuningSpace()
        {
            Log.Log.WriteFile("atsc:CreateTuningSpace()");
            ITuner                tuner = (ITuner)_filterNetworkProvider;
            SystemTuningSpaces    systemTuningSpaces = new SystemTuningSpaces();
            ITuningSpaceContainer container          = systemTuningSpaces as ITuningSpaceContainer;

            if (container == null)
            {
                Log.Log.Error("CreateTuningSpace() Failed to get ITuningSpaceContainer");
                return;
            }
            IEnumTuningSpaces enumTuning;

            ITuningSpace[] spaces = new ITuningSpace[2];
            ITuneRequest   request;

            container.get_EnumTuningSpaces(out enumTuning);
            while (true)
            {
                int fetched;
                enumTuning.Next(1, spaces, out fetched);
                if (fetched != 1)
                {
                    break;
                }
                string name;
                spaces[0].get_UniqueName(out name);
                if (name == "MediaPortal ATSC TuningSpace")
                {
                    Log.Log.WriteFile("atsc:found correct tuningspace {0}", name);
                    _tuningSpace = (IATSCTuningSpace)spaces[0];
                    tuner.put_TuningSpace(_tuningSpace);
                    _tuningSpace.CreateTuneRequest(out request);
                    _tuneRequest = (IATSCChannelTuneRequest)request;
                    return;
                }
                Release.ComObject("ITuningSpace", spaces[0]);
            }
            Release.ComObject("IEnumTuningSpaces", enumTuning);
            Log.Log.WriteFile("atsc:Create new tuningspace");
            _tuningSpace = (IATSCTuningSpace) new ATSCTuningSpace();
            IATSCTuningSpace tuningSpace = (IATSCTuningSpace)_tuningSpace;

            tuningSpace.put_UniqueName("MediaPortal ATSC TuningSpace");
            tuningSpace.put_FriendlyName("MediaPortal ATSC TuningSpace");
            tuningSpace.put__NetworkType(typeof(ATSCNetworkProvider).GUID);
            tuningSpace.put_CountryCode(0);
            tuningSpace.put_InputType(TunerInputType.Antenna);
            tuningSpace.put_MaxMinorChannel(999);    //minor channels per major
            tuningSpace.put_MaxPhysicalChannel(158); //69 for OTA 158 for QAM
            tuningSpace.put_MaxChannel(99);          //major channels
            tuningSpace.put_MinMinorChannel(0);
            tuningSpace.put_MinPhysicalChannel(1);   //OTA 1, QAM 2
            tuningSpace.put_MinChannel(1);

            IATSCLocator locator = (IATSCLocator) new ATSCLocator();

            locator.put_CarrierFrequency(-1);
            locator.put_InnerFEC(FECMethod.MethodNotSet);
            locator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_Modulation(ModulationType.Mod8Vsb); //OTA modultation, QAM = .Mod256Qam
            locator.put_OuterFEC(FECMethod.MethodNotSet);
            locator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
            locator.put_PhysicalChannel(-1);
            locator.put_SymbolRate(-1);
            locator.put_TSID(-1);
            object newIndex;

            _tuningSpace.put_DefaultLocator(locator);
            container.Add(_tuningSpace, out newIndex);
            tuner.put_TuningSpace(_tuningSpace);
            Release.ComObject("TuningSpaceContainer", container);
            _tuningSpace.CreateTuneRequest(out request);
            _tuneRequest = (IATSCChannelTuneRequest)request;
        }