想在dshow程序amcap中得到Sample,使用AppIPTransform程序部分代码.
用了AppIPTransform中的类CAppTransform.
AM_MEDIA_TYPE pmt;
//pPinIn->ConnectionMediaType(&pmt);
pPinOut->ConnectionMediaType(&pmt);//equ
CMediaType *p = new CMediaType(pmt);
pTransform->SetMediaType(PINDIR_INPUT,p);

pTransform->SetMediaType(PINDIR_OUTPUT,p);
IPin* pPinInXfm = InputPinOf(pTransform);
pPinInXfm->ConnectionMediaType(&pmt);根据前面输出pin的值,设置我自己的,怎么然后读取输入pin,返回结果不对.是怎么回事呢,那个设置需要什么条件么?

解决方案 »

  1.   

    代码:
    在buildcapturegraph()中添加代码
    CreateAppFilter();
    hr = ConnectUpstreamOf(gcap.pRender, gcap.pFilter);
    其中gcap.pFilter是我自己定义的CAppTransform类.
    下面是相关代码;
    IPin* GetPin(IBaseFilter* pFilter, PIN_DIRECTION dirRequest)
    {
    IPin * foundPin = NULL;    IEnumPins* pEnum = NULL;
        HRESULT hr = pFilter->EnumPins(&pEnum);
        if (SUCCEEDED(hr)) 
    {
    IPin* pPin = NULL;
            while (!foundPin && pEnum->Next(1, &pPin, 0) == S_OK) 
    {
    PIN_DIRECTION dir;
    pPin->QueryDirection(&dir);
    if (dir == dirRequest) 
    {
    foundPin = pPin;
    }
    else
    {
    pPin->Release();
    }
    }
    pEnum->Release();
        }
        return foundPin;
    }IPin* InputPinOf(IBaseFilter* pFilter) 
    {
    return GetPin(pFilter, PINDIR_INPUT);
    }
    IPin* OutputPinOf(IBaseFilter* pFilter) 
    {
    return GetPin(pFilter, PINDIR_OUTPUT);
    }
    // Connect the filter pTransform upstream of pFilter by reconnecting pins.
    // Assumes that pTransform has only one input and one output, and
    // that pFilter has only one input.
    HRESULT ConnectUpstreamOf(IBaseFilter* ppFilter, CAppTransform/*IBaseFilter*/* pTransform)
    {
    IPin* pPinOut = OutputPinOf(ppFilter);
    if (!pPinOut) 
    {
    return E_FAIL;
    } // Get the peer output pin
    IPin* pPinIn = NULL;
    HRESULT hr = pPinOut->ConnectedTo(&pPinIn);
    if (FAILED(hr)) 
    {
    pPinOut->Release();
    return hr;
    } AM_MEDIA_TYPE pmt;
    pPinIn->ConnectionMediaType(&pmt);
    pPinOut->ConnectionMediaType(&pmt);//equ
    CMediaType *p = new CMediaType(pmt);
    pTransform->SetMediaType(PINDIR_INPUT,p);

    pTransform->SetMediaType(PINDIR_OUTPUT,p); // Disconnect the current connection
    hr = gcap.pFg->Disconnect(pPinOut);
    if (SUCCEEDED(hr)) 
    {
    hr = gcap.pFg->Disconnect(pPinIn);
    } // Insert pTransform filter by connecting its input pin and output pin
    if (SUCCEEDED(hr)) 
    {
    IPin* pPinInXfm = InputPinOf(pTransform);
    pPinInXfm->ConnectionMediaType(&pmt);
    //gcap.pFg->ConnectDirect(pPinOut, pPinInXfm,&pmt);
    hr = gcap.pFg->Connect(pPinOut, pPinInXfm);
    pPinInXfm->Release();
    }
    if (SUCCEEDED(hr)) 
    {
    IPin* pPinOutXfm = OutputPinOf(pTransform);
    pPinOutXfm->ConnectionMediaType(&pmt);
    //gcap.pFg ->ConnectDirect(pPinOutXfm, pPinIn,&pmt);
    hr = gcap.pFg->Connect(pPinOutXfm, pPinIn);
    pPinOutXfm->Release();
    } pPinIn->Release();
    pPinOut->Release();
    return hr;
    }
    // Create the app-based filter and insert into graph (unconnected)
    void CreateAppFilter()
    {
    if (gcap.pFilter) 
    {
    gcap.pFilter->Release();
    gcap.pFilter = NULL;
    } HRESULT hr = S_OK;
    gcap.pFilter = new CAppTransform(NULL, &hr);
    // Make the initial refcount 1 to match COM creation!!!
    gcap.pFilter->AddRef();/* CMediaType mtGroup;
    mtGroup.SetType(&MEDIATYPE_Stream);
    mtGroup.SetSubtype(&MEDIASUBTYPE_Avi);
    mtGroup.SetFormatType(&GUID_NULL);
     
    gcap.pFilter->SetMediaType(PINDIR_INPUT,&mtGroup);
    DWORD error = GetLastError();
    gcap.pFilter->SetMediaType(PINDIR_OUTPUT,&mtGroup);
    //gcap.pFilter->m_pInput->SetMediaType(mtGroup);
    //gcap.pFilter->m_pOutput->SetMediaType(mtGroup);
    */
    // Add to graph -- nb need to Query properly for the
    // right interface before giving that to the graph object
    IBaseFilter* pFilter = NULL;
    hr = gcap.pFilter->QueryInterface(IID_IBaseFilter, (void**)&pFilter);
    if (SUCCEEDED(hr)) 
    {
    hr = gcap.pFg->AddFilter(pFilter, L"App Transform");
    //hr = m_pGraph->AddFilter(pFilter, L"App Transform");
    pFilter->Release();
    }}
      

  2.   

    找到了,给翻译一下吧
    The CTransformInputPin::SetMediaType and CTransformOutputPin::SetMediaType methods call this method when a pin's media type is set. This method does nothing in the base class, but the derived class can override it.