Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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.º 3
0
        /// <summary>
        /// Creates the filter based on the configuration file
        /// </summary>
        /// <param name="tvAudio">The tvaudio component</param>
        /// <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>
        /// <param name="capBuilder">The Capture graph builder</param>
        /// <returns>true, if the graph building was successful</returns>
        private bool CreateConfigurationBasedFilterInstance(Graph graph, ICaptureGraphBuilder2 capBuilder,
                                                            IFilterGraph2 graphBuilder, Tuner tuner, Crossbar crossbar,
                                                            TvAudio tvAudio)
        {
            string audioDeviceName = graph.Capture.AudioCaptureName;
            string videoDeviceName = graph.Capture.Name;

            DsDevice[] devices;
            bool       videoConnected = false;
            bool       audioConnected = false;

            //get a list of all video capture devices
            try
            {
                if (tuner.TunerName == "Adaptec USB TvTuner")
                {
                    Log.Log.WriteFile("analog: Adaptec USB device detected!");
                    devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
                }
                else
                {
                    devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCapture); //shouldn't be VideoInputDevice
                    devices = DeviceSorter.Sort(devices, tuner.TunerName, tvAudio.TvAudioName, crossbar.CrossBarName);
                }
            }
            catch (Exception)
            {
                Log.Log.WriteFile("analog: AddTvCaptureFiler error in allocating devices collection");
                return(false);
            }
            if (devices.Length == 0)
            {
                Log.Log.WriteFile("analog: AddTvCaptureFilter no tvcapture devices found");
                return(false);
            }
            //try each video capture filter
            for (int i = 0; i < devices.Length; i++)
            {
                bool        filterUsed = false;
                IBaseFilter tmp;
                if (_badCaptureDevices.Contains(devices[i].Name))
                {
                    Log.Log.WriteFile("analog: AddTvCaptureFilter bypassing: {0}", devices[i].Name);
                    continue;
                }
                Log.Log.WriteFile("analog: AddTvCaptureFilter try:{0} {1}", devices[i].Name, i);
                // if video capture filter is in use, then we can skip it
                if (DevicesInUse.Instance.IsUsed(devices[i]))
                {
                    Log.Log.WriteFile("analog: Device: {0} in use?", devices[i].Name);
                    continue;
                }
                if (!videoDeviceName.Equals(devices[i].Name) &&
                    (audioDeviceName == null || !audioDeviceName.Equals(devices[i].Name)))
                {
                    continue;
                }
                int hr;
                try
                {
                    // add video capture filter 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)
                {
                    //cannot add video capture filter to graph, try next one
                    if (tmp != null)
                    {
                        Log.Log.WriteFile("analog: cannot add filter: {0} to graph", devices[i].Name);
                        graphBuilder.RemoveFilter(tmp);
                        Release.ComObject("TvCaptureFilter", tmp);
                    }
                    continue;
                }
                // connect crossbar->video capture filter
                if (videoDeviceName.Equals(devices[i].Name) &&
                    FilterGraphTools.ConnectPin(graphBuilder, crossbar.VideoOut, tmp, graph.Capture.VideoIn))
                {
                    _filterVideoCapture = tmp;
                    _videoCaptureDevice = devices[i];
                    if (_audioCaptureDevice != _videoCaptureDevice)
                    {
                        DevicesInUse.Instance.Add(_videoCaptureDevice);
                    }
                    Log.Log.WriteFile("analog: AddTvCaptureFilter connected video to crossbar successfully");
                    videoConnected = true;
                    filterUsed     = true;
                }
                // crossbar->audio capture filter
                // Many video capture are also the audio capture filter, so we can always try it again
                if (audioDeviceName.Equals(devices[i].Name) &&
                    FilterGraphTools.ConnectPin(graphBuilder, crossbar.AudioOut, tmp, graph.Capture.AudioIn))
                {
                    _filterAudioCapture = tmp;
                    _audioCaptureDevice = devices[i];
                    if (_audioCaptureDevice != _videoCaptureDevice)
                    {
                        DevicesInUse.Instance.Add(_audioCaptureDevice);
                    }
                    Log.Log.WriteFile("analog: AddTvCaptureFilter connected audio to crossbar successfully");
                    audioConnected = true;
                    filterUsed     = true;
                }
                // _audioCaptureDevice should never be null - avoids null exception crashes with Encoder.cs
                else
                {
                    _audioCaptureDevice = devices[i];
                }

                if (!filterUsed)
                {
                    // cannot connect crossbar->video capture filter, remove filter from graph
                    // cand continue with the next vieo capture filter
                    Log.Log.WriteFile("analog: AddTvCaptureFilter failed to connect to crossbar");
                    graphBuilder.RemoveFilter(tmp);
                    Release.ComObject("capture filter", tmp);
                }
                else
                {
                    i = -1; // Go through the devices again from the start...
                }
                if (videoConnected && audioConnected)
                {
                    break;
                }
            }
            if (_filterVideoCapture != null)
            {
                if (graph.Capture.TeletextPin != -1)
                {
                    _pinVBI = DsFindPin.ByDirection(_filterVideoCapture, PinDirection.Output,
                                                    graph.Capture.TeletextPin);
                }
                _videoProcAmp              = _filterVideoCapture as IAMVideoProcAmp;
                _analogVideoDecoder        = _filterVideoCapture as IAMAnalogVideoDecoder;
                _streamConfig              = _filterVideoCapture as IAMStreamConfig;
                _videoFormats              = graph.Capture.AvailableVideoStandard;
                _defaultVideoProcAmpValues = graph.Capture.VideoProcAmpValues;
                _frameRate   = graph.Capture.FrameRate;
                _imageWidth  = graph.Capture.ImageWidth;
                _imageHeight = graph.Capture.ImageHeight;
                CheckCapabilitiesStreamConfig(graph, capBuilder);
                SetCaptureConfiguration(graph);
            }
            return(_filterVideoCapture != null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the filter based on the configuration file
        /// </summary>
        /// <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 CreateConfigurationBasedFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner)
        {
            string deviceName = graph.Crossbar.Name;

            _audioTunerIn = null;
            DsDevice[] devices;
            //get list of all crossbar devices installed on this system
            try
            {
                devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar);
                devices = DeviceSorter.Sort(devices, graph.Tuner.Name);
            }
            catch (Exception)
            {
                Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
                return(false);
            }
            if (devices == null || devices.Length == 0)
            {
                Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
                return(false);
            }
            //try each crossbar
            for (int i = 0; i < devices.Length; i++)
            {
                IBaseFilter tmp;
                //if crossbar is already in use then we can skip it
                if (DevicesInUse.Instance.IsUsed(devices[i]))
                {
                    continue;
                }
                if (!deviceName.Equals(devices[i].Name))
                {
                    continue;
                }
                Log.Log.WriteFile("analog: AddCrossBarFilter use:{0} {1}", devices[i].Name, i);
                int hr;
                try
                {
                    //add the crossbar to the 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. try next crossbar
                    if (tmp != null)
                    {
                        graphBuilder.RemoveFilter(tmp);
                        Release.ComObject("CrossBarFilter", tmp);
                    }
                    continue;
                }
                _crossBarFilter          = (IAMCrossbar)tmp;
                _videoPinMap             = graph.Crossbar.VideoPinMap;
                _audioPinMap             = graph.Crossbar.AudioPinMap;
                _videoPinRelatedAudioMap = graph.Crossbar.VideoPinRelatedAudioMap;
                _videoOutPinIndex        = graph.Crossbar.VideoOut;
                _audioOutPinIndex        = graph.Crossbar.AudioOut;
                if (_videoOutPinIndex == -1)
                {
                    Log.Log.WriteFile("analog: AddCrossbarFilter no video output found");
                    graphBuilder.RemoveFilter(tmp);
                    _crossBarFilter = null;
                    Release.ComObject("CrossBarFilter", tmp);
                    continue;
                }
                //connect tv tuner->crossbar
                IPin tunerOut = DsFindPin.ByDirection(tuner.Filter, PinDirection.Output,
                                                      graph.Tuner.VideoPin);
                if (tunerOut != null && _videoPinMap.ContainsKey(AnalogChannel.VideoInputType.Tuner) &&
                    FilterGraphTools.ConnectPin(graphBuilder, tunerOut, tmp, _videoPinMap[AnalogChannel.VideoInputType.Tuner]))
                {
                    // Got it, we're done
                    _filterCrossBar = tmp;
                    _crossBarDevice = devices[i];
                    DevicesInUse.Instance.Add(_crossBarDevice);
                    if (_audioTunerIn == null)
                    {
                        _audioTunerIn = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Input,
                                                              _audioPinMap[AnalogChannel.AudioInputType.Tuner]);
                    }
                    Release.ComObject("tuner video out", tunerOut);
                    _videoOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _videoOutPinIndex);
                    if (_audioOutPinIndex != -1)
                    {
                        _audioOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _audioOutPinIndex);
                    }
                    Log.Log.WriteFile("analog: AddCrossBarFilter succeeded");
                    break;
                }
                // cannot connect tv tuner to crossbar, try next crossbar device
                if (tmp != null)
                {
                    graphBuilder.RemoveFilter(tmp);
                    Release.ComObject("crossbarFilter filter", tmp);
                }
                if (tunerOut != null)
                {
                    Release.ComObject("tuner video out", tunerOut);
                }
            }
            return(_filterCrossBar != null);
        }