⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outputpin.cpp

📁 完整的基于Conxant平台的USB电视棒的WIN驱动程序。
💻 CPP
字号:
/*+++ *******************************************************************\ 
* 
*  Copyright and Disclaimer: 
*  
*     --------------------------------------------------------------- 
*     This software is provided "AS IS" without warranty of any kind, 
*     either expressed or implied, including but not limited to the 
*     implied warranties of noninfringement, merchantability and/or 
*     fitness for a particular purpose.
*     --------------------------------------------------------------- 
*   
*     Copyright (c) 2008 Conexant Systems, Inc. 
*     All rights reserved. 
*
\******************************************************************* ---*/ 

#pragma warning(disable : 4996)
#include <streams.h>
#pragma warning(default : 4996)

#include "outputPin.h"
#include "Y8Filter.h"
#include <stdio.h>

HRESULT COutputPin::BreakConnect()
{
	return CBaseOutputPin::BreakConnect();
}

HRESULT COutputPin::CheckConnect(IPin *pPin)
{
	return CBaseOutputPin::CheckConnect(pPin);
}

HRESULT COutputPin::SetMediaType(CMediaType const *pMediaType)
{
	return CBaseOutputPin::SetMediaType(pMediaType);
}

HRESULT COutputPin::CheckMediaType(CMediaType const *pmt)
{
    if((pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_YUY2))
    {
        return S_OK;
    }
    else
    {
        return S_FALSE;
    }
}

HRESULT COutputPin::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
{
    //NOTE: The CPosPassThru class passes queries for IMediaSeeking through
    // to an upstream filter connected to the input pin.  We must do this 
    // pass through in order to pass the WHQL test, since it requires being 
    // able to get the video duration from an AVI file.

    HRESULT hr;
    if (riid == IID_IMediaPosition || riid == IID_IMediaSeeking) 
    {
        if(_p_pos_passthrough == NULL) 
        {
            // We have not created the CPosPassThru object yet. Do so now.
            hr = CreatePosPassThru(
                GetOwner(), 
                FALSE, 
                m_pSrcFilter->GetPin(INPUT_PIN_INDEX), 
                (IUnknown**) &_p_pos_passthrough);
            if (FAILED(hr)) 
            {
                return hr;
            }
        }

        return _p_pos_passthrough->QueryInterface(riid, ppv);
    } 


	return CBaseOutputPin::NonDelegatingQueryInterface(riid,ppv);
}

HRESULT COutputPin::Notify(IBaseFilter * pSender, Quality q)
{
	return S_OK;
}



HRESULT COutputPin::DecideBufferSize(IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES * pProperties)
{
    
    ASSERT(pAllocator);
    ASSERT(pProperties);
    HRESULT hr = NOERROR;
    DWORD dwWidth = m_pSrcFilter->getWidth();
    DWORD dwHeight = m_pSrcFilter->getHeight();
    
    // Output allocator
    pProperties->cBuffers = 8;
    
    pProperties->cbBuffer = (dwWidth*dwHeight*2);//0x20000;
    
    ASSERT(pProperties->cbBuffer);
    DbgLog((LOG_TRACE, 2, TEXT("Sample size = %ld\n"), pProperties->cbBuffer));
    
    // Prepare the allocator, this can succeed but not allocate what we requested
    ALLOCATOR_PROPERTIES Actual;
    hr = pAllocator->SetProperties(pProperties,&Actual);
    if (FAILED(hr)) 
        return hr;
    
   
    // If we got less than what we asked for, fail
    if (Actual.cbBuffer < pProperties->cbBuffer ||
        Actual.cBuffers < pProperties->cBuffers) 
    {
        // can't use this allocator
        return E_INVALIDARG;
    }
    return S_OK;
}

COutputPin::~COutputPin()
{
    // Release the CPosPassThruObject.
    if(_p_pos_passthrough != NULL) 
    {
        _p_pos_passthrough->Release();
    }
}

COutputPin::COutputPin(TCHAR *pObjectName,CY8Filter *pFilter, HRESULT * phr,LPCWSTR pName)
			: CBaseOutputPin(pObjectName,pFilter,pFilter->getCriticalSection(),phr,L"Out"),
            _p_pos_passthrough(NULL)
{
	m_pSrcFilter = pFilter;
}

HRESULT COutputPin::GetMediaType(int iPosition,CMediaType *pMediaType)
{

	if (iPosition < 0 || iPosition > 1)
		return E_INVALIDARG;

	pMediaType->ResetFormatBuffer();
    VIDEOINFOHEADER *pFormat = (VIDEOINFOHEADER *) pMediaType->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));

    //Copy the input format's header into the VIDEOINFOHEADER
    VIDEOINFOHEADER* p_input_format = m_pSrcFilter->getVideoInfoHeader();
    memcpy(pFormat, p_input_format, sizeof(VIDEOINFOHEADER));

    DWORD width = m_pSrcFilter->getWidth();
    DWORD height = m_pSrcFilter->getHeight();

    //  Initialize the media type structure for output
	RECT rect = {0,0,0,0};//width,height};
	pFormat->rcSource = rect;
	pFormat->rcTarget = rect;
    pFormat->dwBitRate = width* height * 2 * 30; //size of image * 30 frames per second

    pFormat->bmiHeader.biWidth = width;
    pFormat->bmiHeader.biHeight = height;
    pFormat->bmiHeader.biBitCount = 16;
    pFormat->bmiHeader.biPlanes = 1;
	pFormat->bmiHeader.biCompression = mmioFOURCC('Y','U','Y','2');
    pFormat->bmiHeader.biSizeImage = width*height*2;
    pFormat->AvgTimePerFrame = 333667;

    pMediaType->SetType(&MEDIATYPE_Video);
	pMediaType->SetSubtype(&MEDIASUBTYPE_YUY2);
	pMediaType->SetFormatType(&FORMAT_VideoInfo);
	pMediaType->SetTemporalCompression(TRUE);
	pMediaType->SetSampleSize(width * height * 2);

    
	
	m_pSrcFilter->m_pOutputMediaType = pMediaType;

	return NO_ERROR;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -