Beispiel #1
0
        private void SetupGraphInternal(DsDevice dev, SystemCodecEntry compressor, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName)
        {
            filterGraph = (IFilterGraph2) new FilterGraph();
            mediaCtrl   = filterGraph as IMediaControl;

            capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            samplGrabber = (ISampleGrabber) new SampleGrabber();

            int hr = capBuilder.SetFiltergraph(filterGraph);

            DsError.ThrowExceptionForHR(hr);

            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }
            rot = new DsROTEntry(filterGraph);

            if (fileName != null)
            {
                deviceFilter = BuildFileCaptureGraph(dev, compressor.Device, selectedFormat, fileName, ref iFrameRate, ref iWidth, ref iHeight);
            }
            else
            {
                deviceFilter = BuildPreviewOnlyCaptureGraph(dev, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight);
            }

            // Now that sizes are fixed/known, store the sizes
            SaveSizeInfo(samplGrabber);
        }
Beispiel #2
0
        private void CloseInterfaces()
        {
            if (mediaControl != null)
            {
                mediaControl.Stop();
            }

            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            RemoveHandlers();

            if (compositor != null)
            {
                compositor.Dispose();
                compositor = null;
            }

            if (vmr9 != null)
            {
                Marshal.ReleaseComObject(vmr9);
                vmr9           = null;
                windowlessCtrl = null;
            }

            if (graphBuilder != null)
            {
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder = null;
                mediaControl = null;
            }
        }
        public void DoTests()
        {
            try
            {
                BuildGraph();

                // wait for the end of foo.avi
                // Nothing is shown in the video window since we composite nothing...
                System.Threading.Thread.Sleep(1000);

                Debug.Assert(InitCompositionDeviceCalledCount != 0, "IVMRImageCompositor.InitCompositionDevice not called");
                Debug.Assert(SetStreamMediaTypeCalledCount != 0, "IVMRImageCompositor.SetStreamMediaType not called");
                Debug.Assert(CompositeImageCalledCount != 0, "IVMRImageCompositor.CompositeImageCalled not called");
                Debug.Assert(TermCompositionDeviceCalledCount != 0, "IVMRImageCompositor.TermCompositionDevice not called");
            }
            finally
            {
                if (rot != null)
                {
                    rot.Dispose();
                }

                Marshal.ReleaseComObject(vmr);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
        /// <summary>
        /// Frees all unmanaged memory and resets the object back
        /// to its initial state
        /// </summary>
        protected override void FreeResources()
        {
#if DEBUG
            /* Remove us from the ROT */
            if (m_dsRotEntry != null)
            {
                m_dsRotEntry.Dispose();
                m_dsRotEntry = null;
            }
#endif

            /* We run the StopInternal() to avoid any
             * Dispatcher VeryifyAccess() issues because
             * this may be called from the GC */
            StopInternal();

            /* Let's clean up the base
             * class's stuff first */
            base.FreeResources();

            if (m_graph != null)
            {
                Marshal.ReleaseComObject(m_graph);
                m_graph = null;

                /* Only run the media closed if we have an
                 * initialized filter graph */
                InvokeMediaClosed(new EventArgs());
            }
        }
Beispiel #5
0
        /// <summary>
        /// Shut down capture
        /// </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (_mediaCtrl != null)
                {
                    // Stop the graph
                    hr         = _mediaCtrl.Stop();
                    _mediaCtrl = null;
                }
#if DEBUG
                if (_rot != null)
                {
                    _rot.Dispose();
                }
#endif
                if (_graphBuilder != null)
                {
                    Marshal.ReleaseComObject(_graphBuilder);
                    _graphBuilder = null;
                }

                _state = VideoCaptureState.UNINITIALIZED;

                GC.Collect();
            }
            catch (Exception e)
            {
                TraceException.WriteLine(e);
            }
        }
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr          = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
            }
#endif

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
            GC.Collect();
        }
        public void DoTests()
        {
            try
            {
                BuildGraph();

                TestONID();
                TestTSID();
                TestSID();
            }
            finally
            {
                if (rot != null)
                {
                    rot.Dispose();
                }

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #8
0
 public void Stop()
 {
     if (_parentControl != null)
     {
         _parentControl.SizeChanged -= _parentControl_SizeChanged;
     }
     if (_videoWin != null)
     {
         _videoWin.put_Visible(OABool.False);
         _videoWin = null;
     }
     if (_mediaCtrl != null)
     {
         _mediaCtrl.Stop();
         _mediaCtrl = null;
     }
     if (_rotEntry != null)
     {
         _rotEntry.Dispose();
         _rotEntry = null;
     }
     if (_graphBuilder != null)
     {
         DirectShowUtil.ReleaseComObject(_graphBuilder, 2000);
         _graphBuilder = null;
     }
 }
        private void Setup()
        {
            int         hr;
            IBaseFilter ibf;

            IFilterGraph2 ifg = new FilterGraph() as IFilterGraph2;

            m_imc = ifg as IMediaControl;
            DsROTEntry rot = new DsROTEntry(ifg);

            DsDevice[] devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            hr = ifg.AddSourceFilterForMoniker(devs[0].Mon, null, devs[0].Name, out ibf);

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            hr = icgb2.SetFiltergraph(ifg);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb2.RenderStream(null, null, ibf, null, null);
            DsError.ThrowExceptionForHR(hr);

            IBaseFilter pFilter;

            hr = ifg.FindFilterByName("Video Renderer", out pFilter);

            m_qc = pFilter as IQualityControl;

            rot.Dispose();
        }
        public void DoTests()
        {
            BuildGraph();
            MakeATuneRequestAndRunTheGraph();

            try
            {
                TestHighLowSwitchFrequency();
                TestLocalOscilatorFrequency();
            }
            finally
            {
                rot.Dispose();
                Marshal.ReleaseComObject(lnbInfo);

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #11
0
        public void DoTests()
        {
            try
            {
                BuildGraph();

                TestEnumTuningSpaces();
                TestPreferredComponentTypes();
                TestTuningSpace();
                TestTuneRequestAndValidate();
                TestTriggerSignalEvents();

                (graphBuilder as IMediaControl).Run();

                TestSignalStrength();
            }
            finally
            {
                if (rot != null)
                {
                    rot.Dispose();
                }

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #12
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                TestState();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Beispiel #13
0
        private void Shutdown()
        {
            int hr = 0;

            // Remove the ROT entry
            if (rot != null)
            {
                rot.Dispose();
            }

            if (graphBuilder != null)
            {
                // Stop DirectShow notifications
                hr = (graphBuilder as IMediaEventEx).SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);

                // Stop the graph
                hr = (graphBuilder as IMediaControl).StopWhenReady();
                hr = (graphBuilder as IMediaControl).Stop();

                // Dispose the allocator
                allocator.Dispose();

                // Release DirectShow objects
                Marshal.ReleaseComObject(vmr9);
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder = null;

                FreeResources();

                // Free the Managed Direct3D device
                device.Dispose();
            }
        }
Beispiel #14
0
        // Shut down capture
        public void CloseInterfaces()
        {
            int hr;

            IsOnDeleting = true;
            lock (this)
            {
                if (m_State != GraphState.Exiting)
                {
                    m_State = GraphState.Exiting;

                    // Release the thread (if the thread was started)
                    if (m_mre != null)
                    {
                        m_mre.Set();
                    }
                }



                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr          = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }

                if (m_mediaSeeking != null)
                {
                    Marshal.ReleaseComObject(m_mediaSeeking);
                    m_mediaSeeking = null;
                }
                if (m_sampGrabber != null)
                {
                    Marshal.ReleaseComObject(m_sampGrabber);
                    m_sampGrabber = null;
                }

#if DEBUG
                if (m_DsRot != null)
                {
                    m_DsRot.Dispose();
                }
#endif

                if (m_FilterGraph != null)
                {
                    try
                    {
                        Marshal.ReleaseComObject(m_FilterGraph);
                    }
                    catch { }
                    finally
                    {
                        m_FilterGraph = null;
                    }
                }
            }
            GC.Collect();
        }
        /// <summary>
        /// Test all IBasicVideo methods
        /// </summary>
        public void DoTests()
        {
            m_graphBuilder = BuildGraph(g_SourceTestFile);

            try
            {
                TestFilterGraph();
                TestAllocCapFile();
                TestOutputFileName();
                TestFindInterface();
                TestRenderStream();
                TestFindPin();
                TestCopyFile();
                TestControlStream();
            }
            finally
            {
                if (m_graphBuilder != null)
                {
                    Marshal.ReleaseComObject(m_graphBuilder);
                }

                m_graphBuilder = null;
                m_dsrot.Dispose();
            }
        }
Beispiel #16
0
        /// <summary>
        /// Stop recording and release the graph
        /// </summary>
        public void StopRecord()
        {
            //Stop the Graph
            mediaControl.Stop();

#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
#endif

            //Release COM objects
            Marshal.ReleaseComObject(graphBuilder);
            graphBuilder = null;

            if (tuner != null)
            {
                Marshal.ReleaseComObject(tuner);
                tuner = null;
            }

            if (crossbar != null)
            {
                Marshal.ReleaseComObject(crossbar);
                crossbar = null;
            }
        }
Beispiel #17
0
        public void CloseInterfaces()
        {
            if (mediaControl != null)
            {
                int hr = mediaControl.StopWhenReady();
                DsError.ThrowExceptionForHR(hr);
            }

            if (videoWindow != null)
            {
                videoWindow.put_Visible(OABool.False);
                videoWindow.put_Owner(IntPtr.Zero);
            }

            // Remove filter graph from the running object table.
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            // Release DirectShow interfaces.
            Marshal.ReleaseComObject(this.mediaControl); this.mediaControl = null;
            Marshal.ReleaseComObject(this.videoWindow); this.videoWindow   = null;
            Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
            Marshal.ReleaseComObject(this.captureGraphBuilder); this.captureGraphBuilder = null;
        }
        public void DoTests()
        {
            BuildGraph();
            MakeATuneRequestAndRunTheGraph();

            try
            {
                TestFEC();
                TestModulationType();
                TestSpectralInversion();
                TestSymbolRate();
            }
            finally
            {
                rot.Dispose();
                Marshal.ReleaseComObject(digitalDemux);

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
        public void DoTests()
        {
            BuildGraph();
            MakeATuneRequestAndRunTheGraph();

            try
            {
                TestAutotune();
                TestBandwidth();
                TestFrequency();
                TestFrequencyMultiplier();
                TestPolarity();
                TestRange();
            }
            finally
            {
                rot.Dispose();
                Marshal.ReleaseComObject(freqFilter);

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #20
0
        public void DoTests()
        {
            try
            {
                BuildGraph();

                MakeATuneRequestAndRunTheGraph();

                // This is also a test for the IMPEG2TuneRequestFactory interface...
                TestIMPEG2TuneRequestFactory();

                TestTSID();
                TestProgNo();
            }
            finally
            {
                if (rot != null)
                {
                    rot.Dispose();
                }

                Marshal.ReleaseComObject(mpeg2TuneRequest);

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #21
0
        public void DoTests()
        {
            int hr = 0;

            try
            {
                BuildGraph();

                hr = (graphBuilder as IMediaControl).Run();
                DsError.ThrowExceptionForHR(hr);

                // Nothing is shown in the video window since we present nothing...
                System.Threading.Thread.Sleep(2000);

                hr = (graphBuilder as IMediaControl).Stop();
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (rot != null)
                {
                    rot.Dispose();
                }

                Marshal.ReleaseComObject(vmr);
                if (defaultAllocatorPresenter != null)
                {
                    Marshal.ReleaseComObject(defaultAllocatorPresenter);
                }
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #22
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr         = m_mediaCtrl.Stop();
                    m_bRunning = false;
                }
            }
            catch
            {
            }

#if DEBUG
            // Remove graph from the ROT
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
#endif

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
        }
Beispiel #23
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                // These routines can be tested with testme.iso.  If you've got
                // nero, you can use NeroDrive to mount the iso file as a dvd drive.  Otherwise
                // burn the file to a dvd for testing.
                TestGetCurrentDomain();
                TestGetTotalTitleTime();
                TestGetCurrent();
                TestDiskInfo();
                TestTitle();
                TestButton();
                TestMisc();

                /// These routines need a fancier dvd than I can make with my dvd software.  I've tested
                /// using "The Thomas Crown Affair".  Note that TestDirectory changes the drive from MyDisk
                /// to OtherDisk.

                // Map to a different drive.  One that has multiple streams, angles, etc
                int hr;
                hr = m_imc.Stop();
                DsError.ThrowExceptionForHR(hr);
                hr = m_idc2.SetDVDDirectory(OtherDisk);
                DsError.ThrowExceptionForHR(hr);
                StartGraph();

                TestStrings();
                TestMenuLang();
                TestAudio();
                TestSubPic();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
        private void TestEm()
        {
            int hr;
            AllocatorProperties prop = new AllocatorProperties();
            Guid grf = typeof(IBaseFilter).GUID;

            prop.cbAlign  = 1;
            prop.cbBuffer = 3000000;
            prop.cbPrefix = 0;
            prop.cBuffers = 12;

            hr = m_ibn.SuggestAllocatorProperties(prop);
            DsError.ThrowExceptionForHR(hr);

            IGraphBuilder ifg = new FilterGraph() as IGraphBuilder;
            DsROTEntry    rot = new DsROTEntry(ifg);

            hr = ifg.AddFilter(m_ibf, "Device");
            DsError.ThrowExceptionForHR(hr);

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            hr = icgb2.SetFiltergraph(ifg);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb2.RenderStream(null, null, m_ibf, null, null);
            DsError.ThrowExceptionForHR(hr);

            // Returns E_FAIL for all my devices, so I wrote my own filter
            // that implements it for a test.  Note: You CANNOT use "out" here.
            hr = m_ibn.GetAllocatorProperties(prop);
            //DsError.ThrowExceptionForHR(hr);
            rot.Dispose();
        }
Beispiel #25
0
        public void DoTests()
        {
            BuildGraph();
            MakeATuneRequestAndRunTheGraph();

            try
            {
                TestGetStreamOfSection();
                TestGetTable();
                TestGetSection();
            }
            finally
            {
                rot.Dispose();
                Marshal.ReleaseComObject(mpeg2Data);

                Marshal.ReleaseComObject(bdaSecTab);
                Marshal.ReleaseComObject(bdaTIF);
                Marshal.ReleaseComObject(mpeg2Demux);
                Marshal.ReleaseComObject(bdaCapture);
                Marshal.ReleaseComObject(bdaTuner);
                Marshal.ReleaseComObject(tuneRequest);
                Marshal.ReleaseComObject(tuningSpace);
                Marshal.ReleaseComObject(networkProvider);
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
Beispiel #26
0
        private void TearDownGraph()
        {
#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
#endif

            // Stop sending event messages
            if (m_pEvent != null)
            {
                m_pEvent.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                m_pEvent = null;
            }

            if (m_pControl != null)
            {
                m_pControl.Stop();
                m_pControl = null;
            }

            if (m_pDisplay != null)
            {
                //Marshal.ReleaseComObject(m_pDisplay);
                m_pDisplay = null;
            }

            if (m_pMapper != null)
            {
                Marshal.ReleaseComObject(m_pMapper);
                m_pMapper = null;
            }

            if (m_pMixer != null)
            {
                Marshal.ReleaseComObject(m_pMixer);
                m_pMixer = null;
            }

            if (m_pEVR != null)
            {
                Marshal.ReleaseComObject(m_pEVR);
                m_pEVR = null;
            }

            if (m_pGraph != null)
            {
                Marshal.ReleaseComObject(m_pGraph);
                m_pGraph = null;
            }

            m_state    = PlaybackState.Closed;
            m_seekCaps = 0;
            m_pSeek    = null;
        }
Beispiel #27
0
        protected override void FreeResources()
        {
            /* We run the StopInternal() to avoid any
             * Dispatcher VeryifyAccess() issues */
            StopInternal();

            /* Let's clean up the base
             * class's stuff first */
            base.FreeResources();

#if DEBUG
            if (m_rotEntry != null)
            {
                m_rotEntry.Dispose();
            }

            m_rotEntry = null;
#endif
            if (m_videoFrame != null)
            {
                m_videoFrame.Dispose();
                m_videoFrame = null;
            }
            if (m_renderer != null)
            {
                Marshal.FinalReleaseComObject(m_renderer);
                m_renderer = null;
            }
            if (m_captureDevice != null)
            {
                Marshal.FinalReleaseComObject(m_captureDevice);
                m_captureDevice = null;
            }
            if (m_sampleGrabber != null)
            {
                Marshal.FinalReleaseComObject(m_sampleGrabber);
                m_sampleGrabber = null;
            }
            if (m_graph != null)
            {
                Marshal.FinalReleaseComObject(m_graph);
                m_graph = null;

                InvokeMediaClosed(new EventArgs());
            }
            if (m_cameraControl != null)
            {
                Marshal.FinalReleaseComObject(m_cameraControl);
                m_cameraControl = null;
            }
            if (m_videoProcAmp != null)
            {
                Marshal.FinalReleaseComObject(m_videoProcAmp);
                m_videoProcAmp = null;
            }
        }
Beispiel #28
0
        /// <summary>
        /// Used to signal that the graph should be cancelled.
        /// </summary>
        /// <remarks>
        /// Only has meaning if called after <see cref="DESCombine.StartRendering"/>.
        /// </remarks>
        public void Cancel()
        {
            if (m_State < ClassState.GraphStarted)
            {
                return;
                //throw new Exception("Graph not yet started");
            }

#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
#endif
            if (m_State < ClassState.GraphCompleting)
            {
                ChangeState(ClassState.Cancelling);
            }
        }
Beispiel #29
0
        void DSGraphEditPanel_Disposed(object sender, EventArgs e)
        {
            // only stop the graph if we created it
            if (_filterGraphCreated)
            {
                Stop();
            }

            timeSliderTimer.Enabled = false;

            // remove from rot table if we added it
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            try
            {
                // nix the media sink
                if (_mediaEventEx != null)
                {
                    _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                }

                _graphBuilder = null;
                _mediaControl = null;
                _mediaSeeking = null;
                _basicAudio   = null;
                _basicVideo   = null;
                _videoWindow  = null;
                _mediaEventEx = null;

                // only release the filtergraph if WE created it.  If the user passed one into a constructor,
                // it's up to them to release it.
                if (_filterGraphCreated)
                {
                    int refc = Marshal.ReleaseComObject(_graph);
                }

                // if it is a connected graph, renounce all claim on the proxie's RCW
                if (_isRemoteGraph)
                {
                    Marshal.FinalReleaseComObject(_graph);
                }
            }
            catch (InvalidComObjectException ex)
            {
                // the RCW became disconnected,  This is most likely caused by connecting to a remote graph
                // in the same AppDomain.  Just ignore it.
            }
        }
Beispiel #30
0
 /// <summary>
 /// Clean up stuff
 /// </summary>
 public void Dispose()
 {
     if (MediaControl != null)
     {
         MediaControl.Stop();
     }
     //debug
     if (rot != null)
     {
         rot.Dispose();
         rot = null;
     }
 }
Beispiel #31
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;
   }
 }
 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>
    /// Enumerate all tvcard devices and add them to the list
    /// </summary>
    private void DetectCards()
    {
      ITunerCap _providerType;
      bool genericNP = false;
      TvBusinessLayer layer = new TvBusinessLayer();
      Setting setting;
      setting = layer.GetSetting("iptvCardCount", "1");
      int iptvCardCount = Convert.ToInt32(setting.Value);      
      //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)
        {
          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)
        {
          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);
          }
        }
        else if (String.Compare(devices[i].Name, "MediaPortal VLC Source Filter", true) == 0)
        {
          for (int cardNum = 0; cardNum < iptvCardCount; cardNum++)
          {
            Log.Log.WriteFile("Detected IP TV Card " + cardNum);
            TvCardDVBIP card = new TvCardDVBIPVLC(_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());
    }
Beispiel #34
0
    private void GetTunerCapabilities()
    {
      Log.Log.WriteFile("b2c2: GetTunerCapabilities");
      _graphBuilder = (IFilterGraph2)new FilterGraph();
      _rotEntry = new DsROTEntry(_graphBuilder);
      _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
      _capBuilder.SetFiltergraph(_graphBuilder);
      //=========================================================================================================
      // add the B2C2 specific filters
      //=========================================================================================================
      Log.Log.WriteFile("b2c2:GetTunerCapabilities() create B2C2 adapter");
      _filterB2C2Adapter =
        Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter;
      if (_filterB2C2Adapter == null)
      {
        Log.Log.Error("b2c2:GetTunerCapabilities() _filterB2C2Adapter not found");
        return;
      }
      _interfaceB2C2TunerCtrl = _filterB2C2Adapter as IB2C2MPEG2TunerCtrl4;
      if (_interfaceB2C2TunerCtrl == null)
      {
        Log.Log.Error("b2c2: cannot get IB2C2MPEG2TunerCtrl4");
        return;
      }

      _interfaceB2C2DataCtrl = _filterB2C2Adapter as IB2C2MPEG2DataCtrl6;
      if (_interfaceB2C2DataCtrl == null)
      {
        Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6");
        return;
      }

      int hr = _interfaceB2C2DataCtrl.SelectDevice(_deviceInfo.DeviceId);
      if (hr != 0)
      {
        Log.Log.Error("b2c2: select device failed: {0:X}", hr);
      }

      //=========================================================================================================
      // Get tuner type (DVBS, DVBC, DVBT, ATSC)
      //=========================================================================================================
      int lTunerCapSize = Marshal.SizeOf(typeof(tTunerCapabilities));
      IntPtr ptCaps = Marshal.AllocHGlobal(lTunerCapSize);
      hr = _interfaceB2C2TunerCtrl.GetTunerCapabilities(ptCaps, ref lTunerCapSize);
      if (hr != 0)
      {
        Log.Log.Error("b2c2: 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("b2c2: Card type = DVBS");
          _cardType = CardType.DvbS;
          break;
        case TunerType.ttCable:
          Log.Log.WriteFile("b2c2: Card type = DVBC");
          _cardType = CardType.DvbC;
          break;
        case TunerType.ttTerrestrial:
          Log.Log.WriteFile("b2c2: Card type = DVBT");
          _cardType = CardType.DvbT;
          break;
        case TunerType.ttATSC:
          Log.Log.WriteFile("b2c2: Card type = ATSC");
          _cardType = CardType.Atsc;
          break;
        case TunerType.ttUnknown:
          Log.Log.WriteFile("b2c2: Card type = unknown?");
          _cardType = CardType.Unknown;
          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;
      }
    }