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

📄 y8filter.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 "Y8Filter.h"
#include "outputPin.h"
#include "inputPin.h"

#include <initguid.h>
#include "guiids.h"
#include "strsafe.h"

//
// CreateInstance
//
CUnknown * WINAPI CY8Filter::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) {

    CUnknown *punk = new CY8Filter(lpunk, phr);
    if (punk == NULL) {
        *phr = E_OUTOFMEMORY;
    }

    return punk;
}

//
// CY8Filter::Constructor
//
// initialize a CY8Filter object so that we have a pin.
CY8Filter::CY8Filter(LPUNKNOWN lpunk, HRESULT *phr)
    : CBaseFilter(NAME("Y8Convert Filter"),lpunk, &_critical_section,  Y8_FILTER_GUID)
{
    #if VISTA_BUILD
    _pins[OUTPUT_PIN_INDEX] = new COutputPin(L"Out", this, phr, L"Out");
    #else
    _pins[OUTPUT_PIN_INDEX] = new COutputPin("Out", this, phr, L"Out");
    #endif
	_pins[INPUT_PIN_INDEX] = new CInputPin(this, phr, (const USHORT *)(L"Input"));

    DWORD width = 720;
    DWORD height = 480;

    _video_header.bmiHeader.biWidth = width;
    _video_header.bmiHeader.biHeight = height;

    _video_header.dwBitRate = width*height*12*30;
    _video_header.AvgTimePerFrame = 333667;
    _video_header.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);

    //  Initialize the media type structure for output
    RECT rect = {0,0,width,height};
    _video_header.bmiHeader.biCompression = mmioFOURCC('Y','U','Y','2');
    _video_header.rcSource = rect;
    _video_header.rcTarget = rect;

}

CY8Filter::~CY8Filter(void) 
{
    delete _pins[0];
    delete _pins[1];
}

VOID CY8Filter::setInputFormat(VIDEOINFOHEADER* p_format)
{
    memcpy(&_video_header, p_format, sizeof(VIDEOINFOHEADER));
}


STDMETHODIMP CY8Filter::QueryFilterInfo(FILTER_INFO * pInfo)
{
    HRESULT hr = CBaseFilter::QueryFilterInfo(pInfo);
    if (SUCCEEDED(hr))
    {
        StringCchCopyW(pInfo->achName, MAX_FILTER_NAME, L"Conexant Color Format Converter");
    }
    return hr;
}

int CY8Filter::GetPinCount()
{
    return NUM_PINS;
}

//**********************************************************************
// Give out pointers to our pins.  
//**********************************************************************
CBasePin * CY8Filter::GetPin(int n)
{
    if(n >= NUM_PINS)
    {
        return NULL;
    }

    return _pins[n];
}

STDMETHODIMP CY8Filter::Stop(void) {
    long Err= 0;
    double dCurrRate= 0.0;

	DbgLog((LOG_TRACE,0,TEXT("Enter Stop command\n")));

    Err= CBaseFilter::Stop();

    DbgLog((LOG_TRACE,0,TEXT("Exit Stop command\n")));

    return Err;
}

STDMETHODIMP CY8Filter::Pause(void) {
    long Err= 0;
    double dCurrRate= 0.0;

    DbgLog((LOG_TRACE,0,TEXT("Enter Pause command\n")));

    Err= CBaseFilter::Pause();

    DbgLog((LOG_TRACE,0,TEXT("Exit Pause command\n")));

    return Err;
}

STDMETHODIMP CY8Filter::Run(REFERENCE_TIME tStart) {
    long Err= 0;
    double dCurrRate= 1.0;

    DbgLog((LOG_TRACE,0,TEXT("Enter Run command\n")));

    Err= CBaseFilter::Run(tStart);

    DbgLog((LOG_TRACE,0,TEXT("Exit Run command\n")));

    return Err;
}




VOID copyLine(
              PBYTE p_source, 
              PBYTE p_dest, 
              DWORD width,
              CMediaType* pmt)//convert from y8 to YUY2(Y0 U0 Y1 V0)
{
     if (pmt->subtype == MEDIASUBTYPE_CXY8) 
     {
         for(UINT i = 0; i < width; i++)
         {
             p_dest[2*i] = p_source[i];
             p_dest[2*i+1] = 0x80;
         }
     }
     else if (pmt->subtype == MEDIASUBTYPE_UYVY)
     {
         for(UINT i = 0; i < width*2; i+=4)
         {
             p_dest[i] = p_source[i+1];
             p_dest[i+1] = p_source[i];
             p_dest[i+2] = p_source[i+3];
             p_dest[i+3] = p_source[i+2];
         }
     }

//     //for test UYVY(U0 Y0 V0 Y1) to YUY2(Y0 U0 Y1 V0), convert colorful pic to black&white
//     for(UINT i = 0; i < width*2; i+=4)
//     {
//         p_dest[i] = p_source[i+1];
//         p_dest[i+1] = 0x80;
//         p_dest[i+2] = p_source[i+3];
//         p_dest[i+3] = 0x80;
//     }

}

VOID CY8Filter::convertBuffer(PBYTE p_input_buffer, 
                                 PBYTE p_output_buffer,
                                 DWORD input_buffer_size,
								 DWORD output_buffer_size,
                                 CMediaType* pmt)
{
    DWORD width = getWidth();
    DWORD height = getHeight();

	const DWORD INPUT_BUFFER_STRIDE = input_buffer_size/height;
	const DWORD OUTPUT_BUFFER_STRIDE = output_buffer_size/height;

    for(UINT i = 0; i < height; i++)
    {
        copyLine(p_input_buffer, p_output_buffer, width, pmt);
        p_input_buffer += INPUT_BUFFER_STRIDE;
        p_output_buffer += OUTPUT_BUFFER_STRIDE;
    }
}


⌨️ 快捷键说明

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