出来た!

くまさん

神社,ダムと温泉好きな「システムアーキテクト」

おすすめ

2件のフィードバック

  1. jin より:

    すみません。ソースをもっと詳しくみたいのですが、載せてもらうことは無理でしょうか?

  2. くまさん より:

    >>jin さま

    呼び出し元を全文掲載しておきます
    参考にドゾー♪

    ///

    build the capture graph for grabber. private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP, Control hControl)
    {
    int hr;

    ISampleGrabber sampGrabber = null;
    IBaseFilter capFilter = null;
    IPin pCaptureOut = null;
    IPin pSampleIn = null;
    IPin pRenderIn = null;
    IAMAnalogVideoDecoder vdDec;

    // Get the graphbuilder object
    m_graphBuilder = new FilterGraph() as IFilterGraph2;
    try
    {
    #if DEBUG
    m_rot = new DsROTEntry(m_graphBuilder);
    #endif
    // add the video input device
    hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
    DsError.ThrowExceptionForHR( hr );
    vdDec = capFilter as IAMAnalogVideoDecoder;
    vdDec.put_TVFormat(AnalogVideoStandard.NTSC_M);
    // Find the still pin
    //m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0);
    // Didn’t find one. Is there a preview pin?
    //if (m_pinStill == null)
    //{
    // m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0);
    //}

    m_pinStill = null;
    // Still haven’t found one. Need to put a splitter in so we have
    // one stream to capture the bitmap from, and one to display. Ok, we
    // don’t *have* to do it that way, but we are going to anyway.
    if (m_pinStill == null)
    {
    IPin pRaw = null;
    IPin pSmart = null;
    // There is no still pin
    m_VidControl = null;
    // Add a splitter
    IBaseFilter iSmartTee = (IBaseFilter)new SmartTee();
    try
    {
    hr = m_graphBuilder.AddFilter(iSmartTee, “SmartTee”);
    DsError.ThrowExceptionForHR( hr );
    // Find the find the capture pin from the video device and the
    // input pin for the splitter, and connnect them
    pRaw = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
    pSmart = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0);
    hr = m_graphBuilder.Connect(pRaw, pSmart);
    DsError.ThrowExceptionForHR( hr );
    // Now set the capture and still pins (from the splitter)
    m_pinStill = DsFindPin.ByName(iSmartTee, “Preview”);
    pCaptureOut = DsFindPin.ByName(iSmartTee, “Capture”);
    // If any of the default config items are set, perform the config
    // on the actual video device (rather than the splitter)
    if (iHeight + iWidth + iBPP > 0)
    {
    SetConfigParms(pRaw, iWidth, iHeight, iBPP);
    }
    }
    finally
    {
    if (pRaw != null)
    {
    Marshal.ReleaseComObject(pRaw);
    }
    if (pRaw != pSmart)
    {
    Marshal.ReleaseComObject(pSmart);
    }
    if (pRaw != iSmartTee)
    {
    Marshal.ReleaseComObject(iSmartTee);
    }
    }
    }
    else
    {
    // Get a control pointer (used in Click())
    m_VidControl = capFilter as IAMVideoControl;
    pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
    // If any of the default config items are set
    if (iHeight + iWidth + iBPP > 0)
    {
    SetConfigParms(m_pinStill, iWidth, iHeight, iBPP);
    }
    }

    // Get the SampleGrabber interface
    sampGrabber = new SampleGrabber() as ISampleGrabber;
    // Configure the sample grabber
    IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
    ConfigureSampleGrabber(sampGrabber);
    pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
    // Get the default video renderer
    //hr = m_graphBuilder.AddFilter(pRenderer, “Renderer”);
    //DsError.ThrowExceptionForHR( hr );
    //pRenderIn = DsFindPin.ByDirection(pRenderer, PinDirection.Input, 0);
    m_pvmr = new VideoMixingRenderer9() as IBaseFilter;
    m_graphBuilder.AddFilter(m_pvmr, “Renderer”);
    ConfigVideoWindow(hControl);
    pRenderIn = DsFindPin.ByDirection(m_pvmr, PinDirection.Input, 0);
    // Learn the video properties

    // Add the sample grabber to the graph
    hr = m_graphBuilder.AddFilter( baseGrabFlt, “Ds.NET Grabber” );
    DsError.ThrowExceptionForHR( hr );
    IPin pAVIDec1_PinI = null;
    IPin pAVIDec1_PinO = null;
    IPin pAVIDec2_PinI = null;
    IPin pAVIDec2_PinO = null;
    IBaseFilter iAVIDec1 = (IBaseFilter)new AVIDec();
    hr = m_graphBuilder.AddFilter(iAVIDec1, “AVIDec1”);
    DsError.ThrowExceptionForHR( hr );
    IBaseFilter iAVIDec2 = (IBaseFilter)new AVIDec();
    hr = m_graphBuilder.AddFilter(iAVIDec2, “AVIDec2”);
    DsError.ThrowExceptionForHR( hr );
    pAVIDec1_PinI = DsFindPin.ByDirection(iAVIDec1, PinDirection.Input, 0);
    pAVIDec1_PinO = DsFindPin.ByDirection(iAVIDec1, PinDirection.Output, 0);
    pAVIDec2_PinI = DsFindPin.ByDirection(iAVIDec2, PinDirection.Input, 0);
    pAVIDec2_PinO = DsFindPin.ByDirection(iAVIDec2, PinDirection.Output, 0);
    try
    {
    if (m_VidControl == null)
    {
    // Connect the Still pin to the sample grabber
    hr = m_graphBuilder.Connect(m_pinStill, pAVIDec1_PinI);
    DsError.ThrowExceptionForHR( hr );

    hr = m_graphBuilder.Connect(pAVIDec1_PinO, pSampleIn);
    DsError.ThrowExceptionForHR( hr );

    hr = m_graphBuilder.Connect(pCaptureOut, pAVIDec2_PinI);
    DsError.ThrowExceptionForHR( hr );
    // Connect the capture pin to the renderer
    hr = m_graphBuilder.Connect(pAVIDec2_PinO, pRenderIn);
    DsError.ThrowExceptionForHR( hr );
    }
    else
    {
    hr = m_graphBuilder.Connect(pCaptureOut, pAVIDec1_PinI);
    DsError.ThrowExceptionForHR( hr );
    // Connect the capture pin to the renderer
    hr = m_graphBuilder.Connect(pAVIDec1_PinO, pRenderIn);
    DsError.ThrowExceptionForHR( hr );
    hr = m_graphBuilder.Connect(m_pinStill, pAVIDec2_PinI);
    DsError.ThrowExceptionForHR( hr );
    // Connect the Still pin to the sample grabber
    hr = m_graphBuilder.Connect(pAVIDec2_PinO, pSampleIn);
    DsError.ThrowExceptionForHR( hr );
    }

    SaveSizeInfo(sampGrabber);
    }
    finally
    {
    if (pAVIDec1_PinI != null) { Marshal.ReleaseComObject(pAVIDec1_PinI); pAVIDec1_PinI = null; }
    if (pAVIDec1_PinO != null) { Marshal.ReleaseComObject(pAVIDec1_PinO); pAVIDec1_PinI = null; }
    if (pAVIDec2_PinI != null) { Marshal.ReleaseComObject(pAVIDec2_PinI); pAVIDec1_PinI = null; }
    if (pAVIDec2_PinO != null) { Marshal.ReleaseComObject(pAVIDec2_PinO); pAVIDec1_PinI = null; }
    if (iAVIDec1 != null) { Marshal.ReleaseComObject(iAVIDec1); iAVIDec1 = null; }
    if (iAVIDec2 != null) { Marshal.ReleaseComObject(iAVIDec2); iAVIDec2 = null; }
    }
    // Start the graph
    //IMediaControl mediaCtrl = m_graphBuilder as IMediaControl;
    //hr = mediaCtrl.Run();
    //DsError.ThrowExceptionForHR( hr );
    }
    finally
    {
    if (sampGrabber != null)
    {
    Marshal.ReleaseComObject(sampGrabber);
    sampGrabber = null;
    }
    if (pCaptureOut != null)
    {
    Marshal.ReleaseComObject(pCaptureOut);
    pCaptureOut = null;
    }
    if (pRenderIn != null)
    {
    Marshal.ReleaseComObject(pRenderIn);
    pRenderIn = null;
    }
    if (pSampleIn != null)
    {
    Marshal.ReleaseComObject(pSampleIn);
    pSampleIn = null;
    }
    }
    }

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください