Ejemplo n.º 1
0
        void BuildGraph()
        {
            DsDevice [] devs;
            string      s;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
            DsDevice dev = devs[0];

            dev.Mon.GetDisplayName(null, null, out s);
            m_itva = Marshal.BindToMoniker(s) as IAMTVAudio;
        }
Ejemplo n.º 2
0
        //#endif

        // ---------------- Public Methods ---------------

        /// <summary>
        /// Dispose Tuner property
        /// </summary>
        new public void Dispose()
        {
            if (_tvTuner != null)
            {
                Marshal.ReleaseComObject(_tvTuner);
                _tvTuner = null;
            }

            //#if NEWCODE
            if (tvAudio != null)
            {
                Marshal.ReleaseComObject(tvAudio);
                tvAudio = null;
            }
            //#endif
        }
Ejemplo n.º 3
0
        private void GetControlInterface()
        {
            this.tuner    = null;
            this.crossbar = null;

            object o;

            int hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVTuner).GUID, out o);

            if (hr >= 0)
            {
                this.tuner = o as IAMTVTuner;
                o          = null;

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    this.crossbar = o as IBaseFilter;
                    o             = null;
                }

                // Use the crossbar class to help us sort out all the possible video inputs
                // The class needs to be given the capture filters ANALOGVIDEO input pin
                IPin pinVideo = DsFindPin.ByCategory(this.videoCaptureFilter, PinCategory.AnalogVideoIn, 0);
                if (pinVideo != null)
                {
                    try
                    {
                        this.crossbarHelper = new CrossbarHelper(pinVideo);
                    }
                    catch {}
                    Marshal.ReleaseComObject(pinVideo);
                }

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVAudio).GUID, out o);
                if (hr >= 0)
                {
                    this.amTVAudio = o as IAMTVAudio;
                    o = null;
                }
            }
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
        protected override void Decompose()
        {
            if (this.graphBuilder != null)
            {
                int hr = 0;

                OnGraphEnded();

                // Decompose the graph
                try { hr = (this.graphBuilder as IMediaControl).StopWhenReady(); }
                catch { }
                try { hr = (this.graphBuilder as IMediaControl).Stop(); }
                catch { }
                RemoveHandlers();


                FilterGraphTools.RemoveAllFilters(this.graphBuilder);

                if (this.crossbarHelper != null)
                {
                    this.crossbarHelper.Dispose();
                }
                this.crossbarHelper = null;
                if (this.tuner != null)
                {
                    Marshal.ReleaseComObject(this.tuner);
                }
                this.tuner = null;
                if (this.amTVAudio != null)
                {
                    Marshal.ReleaseComObject(this.amTVAudio);
                }
                this.amTVAudio = null;
                if (this.crossbar != null)
                {
                    Marshal.ReleaseComObject(this.crossbar);
                }
                this.crossbar = null;
                if (this.videoCaptureFilter != null)
                {
                    Marshal.ReleaseComObject(this.videoCaptureFilter);
                }
                this.videoCaptureFilter = null;
                if (this.audioCaptureFilter != null)
                {
                    Marshal.ReleaseComObject(this.audioCaptureFilter);
                }
                this.audioCaptureFilter = null;
                if (this.audioRenderer != null)
                {
                    Marshal.ReleaseComObject(this.audioRenderer);
                }
                this.audioRenderer = null;
                if (this.videoRenderer != null)
                {
                    Marshal.ReleaseComObject(this.videoRenderer);
                }
                this.videoRenderer = null;
                if (this.captureGraphBuilder != null)
                {
                    Marshal.ReleaseComObject(this.captureGraphBuilder);
                }
                this.captureGraphBuilder = null;

                if (useWPF)
                {
                    WPFStop();
                }

                try { rot.Dispose(); }
                catch { }
                try { Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; }
                catch { }
            }
        }
Ejemplo n.º 7
0
        private void GetControlInterface()
        {
            this.tuner = null;
            this.crossbar = null;

            object o;

            int hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                this.tuner = o as IAMTVTuner;
                o = null;

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    this.crossbar = o as IBaseFilter;
                    o = null;
                }

                // Use the crossbar class to help us sort out all the possible video inputs
                // The class needs to be given the capture filters ANALOGVIDEO input pin
                IPin pinVideo = DsFindPin.ByCategory(this.videoCaptureFilter, PinCategory.AnalogVideoIn, 0);
                if (pinVideo != null)
                {
                    try
                    {
                        this.crossbarHelper = new CrossbarHelper(pinVideo);
                    }
                    catch{}
                    Marshal.ReleaseComObject(pinVideo);
                }

                hr = this.captureGraphBuilder.FindInterface(null, null, this.videoCaptureFilter, typeof(IAMTVAudio).GUID, out o);
                if (hr >= 0)
                {
                    this.amTVAudio = o as IAMTVAudio;
                    o = null;
                }
            }
        }
Ejemplo n.º 8
0
        protected override void Decompose()
        {
            if (this.graphBuilder != null)
            {
                int hr = 0;

                OnGraphEnded();

                // Decompose the graph
                try { hr = (this.graphBuilder as IMediaControl).StopWhenReady(); }
                catch { }
                try { hr = (this.graphBuilder as IMediaControl).Stop(); }
                catch { }
                RemoveHandlers();

                FilterGraphTools.RemoveAllFilters(this.graphBuilder);

                if (this.crossbarHelper != null) this.crossbarHelper.Dispose(); this.crossbarHelper = null;
                if (this.tuner != null) Marshal.ReleaseComObject(this.tuner); this.tuner = null;
                if (this.amTVAudio != null) Marshal.ReleaseComObject(this.amTVAudio); this.amTVAudio = null;
                if (this.crossbar != null) Marshal.ReleaseComObject(this.crossbar); this.crossbar = null;
                if (this.videoCaptureFilter != null) Marshal.ReleaseComObject(this.videoCaptureFilter); this.videoCaptureFilter = null;
                if (this.audioCaptureFilter != null) Marshal.ReleaseComObject(this.audioCaptureFilter); this.audioCaptureFilter = null;
                if (this.audioRenderer != null) Marshal.ReleaseComObject(this.audioRenderer); this.audioRenderer = null;
                if (this.videoRenderer != null) Marshal.ReleaseComObject(this.videoRenderer); this.videoRenderer = null;
                if (this.captureGraphBuilder != null) Marshal.ReleaseComObject(this.captureGraphBuilder); this.captureGraphBuilder = null;

                if (useWPF)
                    WPFStop();

                try { rot.Dispose(); }
                catch { }
                try { Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; }
                catch { }
            }
        }