Menu

How to Select Video Input ?

Andres
2009-04-30
2012-10-29
  • Andres

    Andres - 2009-04-30

    Hi, i am working with a TV tuner that have 3 inputs: S-Video, Composite and Tuner, the problem that i have is that the default input is S-Video, so if i change it to composite (input needed) each time i reboot the computer and the start the application again this settings come again to the default value (svideo).

    I want to store in a config file the input needed (Svideo, Composite, Tuner) and every time the app starts set the correct video input. Another way i think was change the default input in windows registry, but i didn't find any key for that.

    My question is How to achive this (Set input from code or change default input in windows registry).

    Thank's in advance

    Andres

     
    • Andres

      Andres - 2009-05-01

      I found the problem, this code:

      for (int i = 0; i < iOutputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(false, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_VideoDecoder) iPinIndexOutput = iPinIndexRelated;
      }
      for (int i = 0; i < iInputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(true, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_Composite) iPinIndexInput = iPinIndexRelated;
      }
      // connexion du crossbar
      iCrossbar.Route(iPinIndexOutput, iPinIndexInput);
      }

      Sets the input Pin for Composite to 4 and the output pin for Video Decoder to 1

      But the correct values are 1 and 0 (I saw these values in the crossbar window of Amcap),

      so this code works fine:

      iPinIndexInput=1;
      iPinIndexOutput=0;
      // connexion du crossbar
      iCrossbar.Route(iPinIndexOutput, iPinIndexInput);

       
    • chossette

      chossette - 2009-04-30

      I would suggere you using the crossbar filter, which permit to configure which input to use...

      To get the crossbar
      IAMCrossbar iCrossbar = null;
      m_fGB2.FindInterface( null, null, m_fSource, typeof(IAMCrossbar).GUID, out o );
      iCrossbar = o as IAMCrossbar; o = null;

      to seek for the composite entry for example :
      if (iCrossbar != null)
      {
      int iOutputPinCount = 0, iInputPinCount = 0, iPinIndexRelated = 0, iPinIndexOutput = 0, iPinIndexInput = 0;
      PhysicalConnectorType cPhysicalConnectorType;
      iCrossbar.get_PinCounts(out iOutputPinCount, out iInputPinCount);
      for (int i = 0; i < iOutputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(false, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_VideoDecoder) iPinIndexOutput = iPinIndexRelated;
      }
      for (int i = 0; i < iInputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(true, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_Composite) iPinIndexInput = iPinIndexRelated;
      }
      // connexion du crossbar
      iCrossbar.Route(iPinIndexOutput, iPinIndexInput);
      }

      hope that help !

       
    • chossette

      chossette - 2009-04-30

      I would suggere you using the crossbar filter, which permit to configure which input to use...

      To get the crossbar
      IAMCrossbar iCrossbar = null;
      m_fGB2.FindInterface( null, null, m_fSource, typeof(IAMCrossbar).GUID, out o );
      iCrossbar = o as IAMCrossbar; o = null;

      to seek for the composite entry for example :
      if (iCrossbar != null)
      {
      int iOutputPinCount = 0, iInputPinCount = 0, iPinIndexRelated = 0, iPinIndexOutput = 0, iPinIndexInput = 0;
      PhysicalConnectorType cPhysicalConnectorType;
      iCrossbar.get_PinCounts(out iOutputPinCount, out iInputPinCount);
      for (int i = 0; i < iOutputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(false, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_VideoDecoder) iPinIndexOutput = iPinIndexRelated;
      }
      for (int i = 0; i < iInputPinCount; i++)
      {
      iCrossbar.get_CrossbarPinInfo(true, i, out iPinIndexRelated, out cPhysicalConnectorType);
      if (cPhysicalConnectorType == PhysicalConnectorType.Video_Composite) iPinIndexInput = iPinIndexRelated;
      }
      // connexion du crossbar
      iCrossbar.Route(iPinIndexOutput, iPinIndexInput);
      }

      hope that help !

       
    • Andres

      Andres - 2009-04-30

      Thank's for your reply, i put your code in the device initialization method, but seems i made something wrong because the device keep working with SVideo, here is my code:

      private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight, string FileName, Control hControl)
      {
      int hr;

                  ISampleGrabber sampGrabber = null;
                  IBaseFilter baseGrabFlt = null;
                  IBaseFilter capFilter = null;
                  IBaseFilter muxFilter = null;
                  IFileSinkFilter fileWriterFilter = null;
                  ICaptureGraphBuilder2 capGraph = null;
                  // Get the graphbuilder object
                  m_FilterGraph = new FilterGraph() as IFilterGraph2;
                  m_mediaCtrl = m_FilterGraph as IMediaControl;
      

      if DEBUG

                  m_rot = new DsROTEntry(m_FilterGraph);
      

      endif

                  try
                  {
      
                      // Get the ICaptureGraphBuilder2
                      capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
      
                      // Get the SampleGrabber interface
                      sampGrabber = (ISampleGrabber)new SampleGrabber();
      
                      // Start building the graph
                      hr = capGraph.SetFiltergraph(m_FilterGraph);
                      DsError.ThrowExceptionForHR(hr);
      
                      // Add the video device
                      hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                      DsError.ThrowExceptionForHR(hr);
      
                      baseGrabFlt = (IBaseFilter)sampGrabber;
                      ConfigureSampleGrabber(sampGrabber);
      
                      // Add the frame grabber to the graph
                      hr = m_FilterGraph.AddFilter(baseGrabFlt, &quot;Ds.NET Grabber&quot;);
                      DsError.ThrowExceptionForHR(hr);
      
                      // If any of the default config items are set
                      if (iFrameRate + iHeight + iWidth &gt; 0)
                      {
                          SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
                      }
      
                      // To get the crossbar 
                      IAMCrossbar iCrossbar = null;
                      object o;
                      capGraph.FindInterface(null, null,capFilter, typeof(IAMCrossbar).GUID, out o);
                      iCrossbar = o as IAMCrossbar; o = null;
      
      
                      //to seek for the composite entry for example : 
                      if (iCrossbar != null)
                      {
                          int iOutputPinCount = 0, iInputPinCount = 0, iPinIndexRelated = 0, iPinIndexOutput = 0, iPinIndexInput = 0;
                          PhysicalConnectorType cPhysicalConnectorType;
                          iCrossbar.get_PinCounts(out iOutputPinCount, out iInputPinCount);
                          for (int i = 0; i &lt; iOutputPinCount; i++)
                          {
                              iCrossbar.get_CrossbarPinInfo(false, i, out iPinIndexRelated, out cPhysicalConnectorType);
                              if (cPhysicalConnectorType == PhysicalConnectorType.Video_VideoDecoder) iPinIndexOutput = iPinIndexRelated;
                          }
                          for (int i = 0; i &lt; iInputPinCount; i++)
                          {
                              iCrossbar.get_CrossbarPinInfo(true, i, out iPinIndexRelated, out cPhysicalConnectorType);
                              if (cPhysicalConnectorType == PhysicalConnectorType.Video_Composite) iPinIndexInput = iPinIndexRelated;
                          }
                          // connexion du crossbar 
                          iCrossbar.Route(iPinIndexOutput, iPinIndexInput);
                      }
      
                      bool acceptPreview = false;
                      if (this.InitMode == CaptureMode.SnapAndRec)
                      {
      
                          // Create a filter for the output avi file
                          hr = capGraph.SetOutputFileName(MediaSubType.Avi, FileName, out muxFilter, out fileWriterFilter);
                          DsError.ThrowExceptionForHR(hr);
                          hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, baseGrabFlt, muxFilter);
                          DsError.ThrowExceptionForHR(hr);
                          try
                          {
                              //Render any preview pin of the device
                              hr = capGraph.RenderStream(PinCategory.Preview, MediaType.Video, capFilter, null, null);
                              DsError.ThrowExceptionForHR(hr);
                              acceptPreview = true;
                          }
                          catch (Exception ex)
                          {
                              Debug.WriteLine(ex.Message);
                          }
                          //// Now that sizes are fixed, store the sizes
                          SaveSizeInfo(sampGrabber);
      
                          if (acceptPreview)
                          {
                              ConfigVideoWindow(hControl);
                          }
      
                      }
                      else if (this.initMode == CaptureMode.OnlySnap)
                      {
                          hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, baseGrabFlt, muxFilter);
                          DsError.ThrowExceptionForHR(hr);
                          SaveSizeInfo(sampGrabber);
                          ConfigVideoWindow(hControl);
                      }
                      this.state = CaptureState.Ready;
                  }
                  finally
                  {
                      if (fileWriterFilter != null)
                      {
                          Marshal.ReleaseComObject(fileWriterFilter);
                          fileWriterFilter = null;
                      }
                      if (muxFilter != null)
                      {
                          Marshal.ReleaseComObject(muxFilter);
                          muxFilter = null;
                      }
                      if (capFilter != null)
                      {
                          Marshal.ReleaseComObject(capFilter);
                          capFilter = null;
                      }
                      if (sampGrabber != null)
                      {
                          Marshal.ReleaseComObject(sampGrabber);
                          sampGrabber = null;
                      }
                  }
              }
      
       
      • chossette

        chossette - 2009-04-30

        Have you try debugging to verify that input and output pin of the crossbar are well finded ?

         
  • eagleeye

    eagleeye - 2009-10-03

    Hi Thanks for the help in C#.. However
    the iPinIndexOutput, iPinIndexInput should be the value of "i" in
    the FOR loops

    Vb.net working code.

    Dim o As Object = Nothing

    Dim iCrossbar As IAMCrossbar = Nothing

    Dim iOutputPinCount As Integer = 0, iInputPinCount As Integer = 0,
    iPinIndexRelated As Integer = 0, iPinIndexOutput As Integer = 0,
    iPinIndexInput As Integer = 0

    CaptureGraphBuilder.FindInterface(PinCategory.Capture, Nothing, sourceFilter,
    GetType(IAMCrossbar).GUID, o)
    iCrossbar = TryCast(o, IAMCrossbar)
    o = Nothing

    'to seek for the composite entry for example :
    If iCrossbar IsNot Nothing Then

    Dim cPhysicalConnectorType As PhysicalConnectorType
    iCrossbar.get_PinCounts(iOutputPinCount, iInputPinCount)

    ' we want the INDEX to the connectortype NOT the related index.
    '

    For i As Integer = 0 To iOutputPinCount - 1

    iCrossbar.get_CrossbarPinInfo(False, i, iPinIndexRelated,
    cPhysicalConnectorType)

    If cPhysicalConnectorType = PhysicalConnectorType.Video_VideoDecoder Then

    iPinIndexOutput = i
    Exit For

    End If
    Next

    For i As Integer = 0 To iInputPinCount - 1
    iCrossbar.get_CrossbarPinInfo(True, i, iPinIndexRelated,
    cPhysicalConnectorType)
    ' Debug.WriteLine("Inp Cphysconnectortype " *
    iPinIndexRelated.ToString & " = " &
    cPhysicalConnectorType.ToString)

    If cPhysicalConnectorType = PhysicalConnectorType.Video_Composite Then
    iPinIndexInput = i
    Exit For

    End If
    Next
    ' connexion du crossbar
    iCrossbar.Route(iPinIndexOutput, iPinIndexInput)

    End If

    Hope this helps

     

Log in to post a comment.

Auth0 Logo