当前位置:编程学习 > html/css >>

视频捕获增加color space converter + Transform Filter

其它不解释,贴是代码:

IPFilter.h

[html]
// 
// Sample DirectShow In-Place Transform Filter that accepts data for use in application 
// 
 
#include <streams.h> 
 
// This is an example transform filter that is created within 
// the application, and not by CoCreateInstance 
class CAppTransform : public CTransformFilter 

public: 
    CAppTransform(LPUNKNOWN pUnkOuter, HRESULT *phr); 
 
    HRESULT CheckInputType(const CMediaType* mtIn); 
     
    HRESULT Transform(IMediaSample *pIn, IMediaSample *pOut); 
    HRESULT CheckTransform(const CMediaType *mtIn,const CMediaType *mtOut); 
    HRESULT DecideBufferSize(IMemAllocator *pAlloc, 
        ALLOCATOR_PROPERTIES *pProperties); 
    HRESULT GetMediaType(int iPosition, CMediaType *pMediaType); 
private: 
    HRESULT Copy(IMediaSample *pSource, IMediaSample *pDest) const; 
    HRESULT Transform(IMediaSample *pSample); 
}; 
 
 
// DirectShow graph management sample code: 
// This builds a playback graph using RenderFile 
// and then inserts a transform filter on the uncompressed video. 
class CAppGraphBuilder 

private: 
    CAppTransform*   m_pFilter; 
    DWORD            m_dwObjectTable;  
    ICaptureGraphBuilder2 *m_pBuild; 
    IGraphBuilder *m_pGraph; 
 
public: 
    CAppGraphBuilder(); 
    ~CAppGraphBuilder(); 
 
    void DestroyGraph(void); 
 
    HRESULT BuildFromFile(LPCWSTR pszFile); 
    HRESULT Run(void); 
    HRESULT MakeChild(HWND hwnd); 
    HRESULT ResizeVideoWindow(RECT* prc); 
 
private: 
    void CreateAppFilter(void); 
    HRESULT FindFilterByInte易做图ce(REFIID riid, IBaseFilter** ppFilter); 
    HRESULT ConnectUpstreamOf(IBaseFilter* pFilter,IBaseFilter*pColor, IBaseFilter* pTransform); 
    HRESULT NextUpstream(IBaseFilter* pFilter, IBaseFilter** ppNext);   
    HRESULT CAppGraphBuilder::AddFilterByCLSID(IGraphBuilder *pGraph,const GUID& clsid,LPCWSTR wszName,IBaseFilter **ppF); 
     
    HRESULT InitCaptureGraphBuilder(IGraphBuilder **ppGraph,ICaptureGraphBuilder2 **ppBuild); 
    HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum); 
    void DisplayDeviceInformation(IEnumMoniker *pEnum, IMoniker** pMoniker); 
 
    IPin* GetPin(IBaseFilter* pFilter, PIN_DIRECTION dirRequest); 
    // Helper methods 
    IPin* InputPinOf(IBaseFilter* pFilter)  
    { 
        return GetPin(pFilter, PINDIR_INPUT); 
    } 
    IPin* OutputPinOf(IBaseFilter* pFilter)  
    { 
        return GetPin(pFilter, PINDIR_OUTPUT); 
    } 
 
    void AddToObjectTable(void) ; 
    void RemoveFromObjectTable(void); 
}; 

IPFilter.cpp

[html] view plaincopy
// 
// Sample DirectShow Transform Filter that accepts data for use in application 
// 
 
#include "stdafx.h" 
#include "IPFilter.h" 
 
//////////////////////////////////////////////////////////////////////////////// 
CAppTransform::CAppTransform(LPUNKNOWN pUnkOuter, HRESULT *phr) :  
CTransformFilter(NAME("App Transform"), pUnkOuter, GUID_NULL) 


// 
// CheckTransform 
// 
// To be able to transform the formats must be identical 
// 
HRESULT CAppTransform::CheckTransform(const CMediaType *mtIn,const CMediaType *mtOut) 

    CheckPointer(mtIn,E_POINTER); 
    CheckPointer(mtOut,E_POINTER); 
 
    HRESULT hr; 
    if(FAILED(hr = CheckInputType(mtIn))) 
    { 
        return hr; 
    } 
 
    // format must be a VIDEOINFOHEADER 
    if(*mtOut->FormatType() != FORMAT_VideoInfo) 
    { 
        return E_INVALIDARG; 
    } 
 
    // formats must be big enough  
    if(mtIn->FormatLength() < sizeof(VIDEOINFOHEADER) || 
        mtOut->FormatLength() < sizeof(VIDEOINFOHEADER)) 
        return E_INVALIDARG; 
 
    VIDEOINFO *pInput  = (VIDEOINFO *) mtIn->Format(); 
    VIDEOINFO *pOutput = (VIDEOINFO *) mtOut->Format(); 
 
    if(memcmp(&pInput->bmiHeader,&pOutput->bmiHeader,sizeof(BITMAPINFOHEADER)) == 0) 
    { 
        return NOERROR; 
    } 
 
    return E_INVALIDARG; 
 
} // CheckTransform 
// 
// DecideBufferSize 
// 
// Tell the output pin's allocator what size buffers we 
// require. Can only do this when the input is connected 
// 
HRESULT CAppTransform::DecideBufferSize(IMemAllocator *pAlloc,ALLOCATOR_PROPERTIES *pProperties) 

    CheckPointer(pAlloc,E_POINTER); 
    CheckPointer(pProperties,E_POINTER); 
 
    // Is the input pin connected 
 
    if(m_pInput->IsConnected() == FALSE) 
    { 
        return E_UNEXPECTED; 
    } 
    HRESULT hr = NOERROR; 
    pProperties->cBuffers = 1; 
    pProperties->cbBuffer = m_pInput->CurrentMediaType().GetSampleSize(); 
 
    ASSERT(pProperties->cbBuffer); 
 
    // If we don't have fixed sized samples we must guess some size 
 
    if(!m_pInput->CurrentMediaType().bFixedSizeSamples) 
    { 
        if(pProperties->cbBuffer < 100000) 

补充:web前端 , HTML 5 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,