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

📄 gdi_video_render.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*////                  INTEL CORPORATION PROPRIETARY INFORMATION//     This software is supplied under the terms of a license agreement or//     nondisclosure agreement with Intel Corporation and may not be copied//     or disclosed except in accordance with the terms of that agreement.//       Copyright(c) 2003-2005 Intel Corporation. All Rights Reserved.//*/#include "gdi_video_render.h"#if defined(UMC_ENABLE_GDI_VIDEO_RENDER)#include "vm_debug.h"#include <stdio.h>namespace UMC{GDIVideoRenderParams::GDIVideoRenderParams() :    m_hWnd(NULL){} // GDIVideoRenderParams::GDIVideoRenderParams() :GDIVideoRender::GDIVideoRender() :    m_hWnd(NULL),    m_uiBytesPerDCPixel(0),    m_pucYUVBuffer(NULL),    m_uiYUVBufferPitch(0),    m_bFullScreen(false){} // GDIVideoRender::GDIVideoRender() :GDIVideoRender::~GDIVideoRender(){    Close();} // GDIVideoRender::~GDIVideoRender()Status GDIVideoRender::Init(MediaReceiverParams* pInit){    Status umcRes = UMC_OK;    GDIVideoRenderParams* pParams =        DynamicCast<GDIVideoRenderParams, MediaReceiverParams>(pInit);    if (NULL == pParams)        umcRes = UMC_FAILED_TO_INITIALIZE;    if (UMC_OK == umcRes)    {        m_hWnd = pParams->m_hWnd;        m_InColorFormat = pParams->color_format;        m_SrcInfo = pParams->info;    }    HDC hDC = NULL;    if (UMC_OK == umcRes)    {        hDC = ::GetDC(m_hWnd);        if (NULL == hDC)            umcRes = UMC_OPERATION_FAILED;    }    if (UMC_OK == umcRes)    {        m_uiBytesPerDCPixel = ::GetDeviceCaps( hDC, BITSPIXEL ) >> 3;        if (0 == m_uiBytesPerDCPixel)            umcRes = UMC_OPERATION_FAILED;    }    //  Release DC    if (NULL != hDC)    {        int iRes = ::ReleaseDC( m_hWnd, hDC );        assert( 1 == iRes );    }    //  Allocate YUV buffer    if (UMC_OK == umcRes)    {        unsigned int uiYUVBufSize = 0;        switch (pParams->color_format)        {        case YV12:            m_uiYUVBufferPitch = m_SrcInfo.width;            uiYUVBufSize = m_SrcInfo.height * m_SrcInfo.width * 3 / 2;            break;        case YUY2:#if defined(_WIN32_WCE)            m_uiYUVBufferPitch = m_SrcInfo.width * 2;#else /* !defined(_WIN32_WCE) */            m_uiYUVBufferPitch = m_SrcInfo.width * ((16 + 7) >> 3);#endif /* defined(_WIN32_WCE) */            uiYUVBufSize = m_SrcInfo.height * m_uiYUVBufferPitch;            break;        default:            // unsupported input color format           umcRes = UMC_UNSUPPORTED;                   return umcRes;        }        m_pucYUVBuffer = new unsigned char[uiYUVBufSize];        if (NULL == m_pucYUVBuffer)            umcRes = UMC_ALLOC;    }    //  Allocate an array of RGB buffers    if (UMC_OK == umcRes)    {        size_t uiBufSize = m_SrcInfo.height *                           m_SrcInfo.width *                           m_uiBytesPerDCPixel;        for (m_iBuffersNum = 0;             UMC_OK == umcRes && m_iBuffersNum < MAX_FRAME_BUFFERS;             m_iBuffersNum++)        {            assert( 0 <= (int)m_iBuffersNum );            m_Buffers[m_iBuffersNum].surface = new unsigned char[uiBufSize];            if ( NULL == m_Buffers[m_iBuffersNum].surface )                umcRes = UMC_ALLOC;        }        assert( 0 <= (int)m_iBuffersNum );        //  We've allocated not MAX_FRAME_BUFFERS but enough buffers:        if (UMC_OK != umcRes && MIN_FRAME_BUFFERS <= m_iBuffersNum)            umcRes = UMC_OK;    }    if (UMC_OK == umcRes)        umcRes = BaseVideoRender::Init(pInit);    return umcRes;} // Status GDIVideoRender::Init(MediaReceiverParams* pInit)Status GDIVideoRender::RenderFrame(){    Status umcRes = (m_iReadIndex >= 0 && NULL != m_hWnd) ?                    (UMC_OK) : (UMC_NOT_INITIALIZED);    m_SuncMut.Lock();    //  Blit RGB picture from m_Buffers[m_iReadIndex] to the screen    HDC hDC = NULL;    if (UMC_OK == umcRes)    {        if (m_bFullScreen)            hDC = ::GetDC(NULL);        else            hDC = ::GetDC(m_hWnd);        if (NULL == hDC)            umcRes = UMC_OPERATION_FAILED;    }    RECT CurDispRect;    CurDispRect.bottom  = m_dst_rect.bottom;    CurDispRect.top     = m_dst_rect.top;    CurDispRect.left    = m_dst_rect.left;    CurDispRect.right   = m_dst_rect.right;    if (UMC_OK == umcRes && !m_bFullScreen)    {        POINT point = {0,0};        ::ClientToScreen( m_hWnd, &point );        CurDispRect.left = static_cast<short>(CurDispRect.left - point.x);        CurDispRect.right = static_cast<short>(CurDispRect.right - point.x);        CurDispRect.top = static_cast<short> (CurDispRect.top - point.y);        CurDispRect.bottom = static_cast<short>(CurDispRect.bottom - point.y);    }    if (UMC_OK == umcRes && m_bShow)    {        BITMAPINFOHEADER BmpHdr = {0};        BmpHdr.biSize = sizeof(BmpHdr);        BmpHdr.biWidth = m_SrcInfo.width;        BmpHdr.biHeight = -((signed) m_SrcInfo.height);        BmpHdr.biPlanes = 1;        BmpHdr.biBitCount = static_cast<unsigned short>(m_uiBytesPerDCPixel << 3);        BmpHdr.biCompression = BI_RGB;        int iRes = 0;        iRes = ::StretchDIBits(            hDC,                                // handle to DC            CurDispRect.left,                   // x-coord of destination upper-left corner            CurDispRect.top,                        // y-coord of destination upper-left corner            CurDispRect.right - CurDispRect.left,   // width of destination rectangle            CurDispRect.bottom - CurDispRect.top,   // height of destination rectangle            0,                                  // x-coord of source upper-left corner            0,                                  // y-coord of source upper-left corner            m_SrcInfo.width,                    // width of source rectangle            m_SrcInfo.height,                   // height of source rectangle            m_Buffers[m_iReadIndex].surface,    // bitmap bits            (BITMAPINFO *)&BmpHdr,              // bitmap data            DIB_RGB_COLORS,                     // usage options            SRCCOPY                             // raster operation code            );        assert( GDI_ERROR != iRes );    }    if (UMC_OK == umcRes)        m_hFreeBufSema.Signal();    //  Release all allocated    if (NULL != hDC)    {        int iRes = ::ReleaseDC( m_hWnd, hDC );        assert( 1 == iRes );    }    m_SuncMut.Unlock();    return umcRes;} // Status GDIVideoRender::RenderFrame()Status GDIVideoRender::ShowLastFrame(){    Status umcRes = (m_iReadIndex >= 0 && NULL != m_hWnd) ?                    (UMC_OK) : (UMC_NOT_INITIALIZED);    m_SuncMut.Lock();    //  Blit RGB picture from m_Buffers[m_iReadIndex] to the screen    HDC hDC = NULL;    if (UMC_OK == umcRes)    {        if (m_bFullScreen)            hDC = ::GetDC(NULL);        else            hDC = ::GetDC(m_hWnd);        if (NULL == hDC)            umcRes = UMC_OPERATION_FAILED;    }    RECT CurDispRect;    CurDispRect.bottom  = m_dst_rect.bottom;    CurDispRect.top     = m_dst_rect.top;    CurDispRect.left    = m_dst_rect.left;    CurDispRect.right   = m_dst_rect.right;    if (UMC_OK == umcRes && !m_bFullScreen)    {        POINT point = {0,0};        ::ClientToScreen( m_hWnd, &point );        CurDispRect.left = static_cast<short>(CurDispRect.left - point.x);        CurDispRect.right = static_cast<short>(CurDispRect.right - point.x);        CurDispRect.top = static_cast<short> (CurDispRect.top - point.y);        CurDispRect.bottom = static_cast<short>(CurDispRect.bottom - point.y);    }    if (UMC_OK == umcRes && m_bShow)    {        BITMAPINFOHEADER BmpHdr = {0};        BmpHdr.biSize = sizeof(BmpHdr);        BmpHdr.biWidth = m_SrcInfo.width;        BmpHdr.biHeight = -((signed) m_SrcInfo.height);        BmpHdr.biPlanes = 1;        BmpHdr.biBitCount = static_cast<unsigned short>(m_uiBytesPerDCPixel << 3);        BmpHdr.biCompression = BI_RGB;        int iRes = 0;        iRes = ::StretchDIBits(            hDC,                                // handle to DC            CurDispRect.left,                   // x-coord of destination upper-left corner            CurDispRect.top,                        // y-coord of destination upper-left corner            CurDispRect.right - CurDispRect.left,   // width of destination rectangle            CurDispRect.bottom - CurDispRect.top,   // height of destination rectangle            0,                                  // x-coord of source upper-left corner            0,                                  // y-coord of source upper-left corner            m_SrcInfo.width,                    // width of source rectangle            m_SrcInfo.height,                   // height of source rectangle            m_Buffers[m_iReadIndex].surface,    // bitmap bits            (BITMAPINFO *)&BmpHdr,              // bitmap data            DIB_RGB_COLORS,                     // usage options            SRCCOPY                             // raster operation code            );        assert( GDI_ERROR != iRes );    }    //  Release all allocated    if (NULL != hDC)    {        int iRes = ::ReleaseDC( m_hWnd, hDC );        assert( 1 == iRes );    }    m_SuncMut.Unlock();    return umcRes;} // Status GDIVideoRender::ShowLastFrame()Status GDIVideoRender::SetFullScreen(ModuleContext& /*rContext*/, bool full){    m_bFullScreen = full;    return UMC_OK;} // Status GDIVideoRender::SetFullScreen(ModuleContext &, bool full)Status GDIVideoRender::Close(){    m_SuncMut.LockIfInitialized();    delete [] m_pucYUVBuffer;    m_pucYUVBuffer = NULL;    m_uiYUVBufferPitch = 0;    for ( int i = 0; i < MAX_FRAME_BUFFERS; i++ )    {        delete [] m_Buffers[i].surface;    }    memset(m_Buffers, 0, sizeof(m_Buffers));    m_uiBytesPerDCPixel = 0;    m_hWnd = 0;    m_bShow = false;    m_bFullScreen = false;    memset(&m_dst_rect, 0, sizeof(m_dst_rect));    m_SuncMut.UnlockIfInitialized();    return BaseVideoRender::Close();} // Status GDIVideoRender::Close()int GDIVideoRender::LockSurface(unsigned char** ppucVidMem){    int iRes = m_uiYUVBufferPitch;    if ( m_iWriteIndex < 0 )        iRes = 0;    else        *ppucVidMem = m_pucYUVBuffer;    return iRes;} // int GDIVideoRender::LockSurface(unsigned char** ppucVidMem)#define SATURATE(x) ((0 > x) ? 0 : ((255 < x) ? 255 : (unsigned char)x))// define internal type(s)struct YUY2QUAD{  BYTE Y1;  BYTE V;  BYTE Y2;  BYTE U;};

⌨️ 快捷键说明

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