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

📄 fb_video_render.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
字号:
/*
//
//                  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-2007 Intel Corporation. All Rights Reserved.
//
*/

#include "fb_video_render.h"

#ifdef UMC_ENABLE_FB_VIDEO_RENDER

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <umc_video_data.h>

#include "drv.h"

#define MODULE              "FBVideoRender:"
#define FUNCTION            "Unknown"
#undef  VIDEO_DRV_RESULT
#define VIDEO_DRV_RESULT    umcRes

#define DBG_SET(msg)        VIDEO_DRV_DBG_SET   (MODULE, FUNCTION, msg)
#define ERR_SET(err,msg)    VIDEO_DRV_ERR_SET   (MODULE, err, FUNCTION, msg)
#define WRN_SET(err,msg)    VIDEO_DRV_WRN_SET   (MODULE, err, FUNCTION, msg)

namespace UMC
{

FBVideoRender::FBVideoRender() :
    m_iDevHandle(0),
    m_pbMap(NULL),
    m_uiMapSize(0)
{
#undef  FUNCTION
#define FUNCTION "FBVideoRender"
    DBG_SET("+");
    memset(&m_sFixInfo, 0, sizeof(m_sFixInfo));
    memset(&m_sVarInfo, 0, sizeof(m_sVarInfo));
    DBG_SET("-");
} // FBVideoRender::FBVideoRender

FBVideoRender::~FBVideoRender()
{
#undef  FUNCTION
#define FUNCTION "~FBVideoRender"
    DBG_SET("+");
    Close();
    DBG_SET("-");
} // FBVideoRender::~FBVideoRender

Status FBVideoRender::ShowLastFrame()
{
#undef  FUNCTION
#define FUNCTION "ShowLastFrame"
    DBG_SET("+");
    DBG_SET("-");
    return UMC_ERR_NOT_IMPLEMENTED;

} // FBVideoRender::ShowLastFrame

// Terminate the render
Status FBVideoRender::Close()
{
#undef  FUNCTION
#define FUNCTION "Close"
    DBG_SET("+");
    Status umcRes = MobileVideoRender::Close();

    if (NULL != m_pbMap)
    {
        if ((0 != m_uiMapSize) && (0 != m_iDevHandle))
        {
            munmap(m_pbMap, m_uiMapSize);
        }
        m_uiMapSize = 0;
        m_pbMap = NULL;
    }
    if (0 != m_iDevHandle)
    {
        close(m_iDevHandle);
        m_iDevHandle = 0;
    }
    memset(&m_sFixInfo, 0, sizeof(m_sFixInfo));
    memset(&m_sVarInfo, 0, sizeof(m_sVarInfo));
    DBG_SET("-");
    return umcRes;

} // Status FBVideoRender::Close()

// Initialize the render, return false if failed, call Close anyway
Status FBVideoRender::Init(MediaReceiverParams* pInit)
{
#undef  FUNCTION
#define FUNCTION "Init"
    DBG_SET("+");
    Status umcRes = UMC_OK;
    VideoRenderParams *pParams = DynamicCast<VideoRenderParams> (pInit);

    if (NULL == pParams)
    {
        ERR_SET(UMC_ERR_NULL_PTR, "'pInit' points to NULL or has incorrect type [-]");
    }
    if (UMC_OK == umcRes)
    {
        // NOTE: next Init will be removed in future.
        if (NONE == pParams->out_data_template.GetColorFormat())
            umcRes = m_OutDataTemplate.Init(pParams->info.width,
                                            pParams->info.height,
                                            pParams->color_format);
        else
            m_OutDataTemplate = pParams->out_data_template;

        // Checking color format to be used.
        switch (m_OutDataTemplate.GetColorFormat())
        {
        case RGB565:
            break;
        default:
            ERR_SET(UMC_ERR_INVALID_PARAMS, "specified color format is unsupported [-]");
            break;
        }
    }
    if (UMC_OK == umcRes)
    {
        umcRes = MobileVideoRender::Init(pInit);
    }
    if (UMC_OK == umcRes)
    {
        m_iDevHandle = open("/dev/fb0", O_RDWR);
        if (0 == m_iDevHandle)
        {
            ERR_SET(UMC_ERR_OPEN_FAILED,
                    "no Frame Buffer device was found or insufficient access rights [-]");
        }
    }
    // Get fixed screen information
    if ((UMC_OK == umcRes) &&
        (0 != ioctl(m_iDevHandle, FBIOGET_FSCREENINFO, &m_sFixInfo)))
    {
        ERR_SET(UMC_ERR_INIT, "error reading fixed information [-]");
    }
    // Get variable screen information
    if ((UMC_OK == umcRes) &&
        (0 != ioctl(m_iDevHandle, FBIOGET_VSCREENINFO, &m_sVarInfo)))
    {
        ERR_SET(UMC_ERR_INIT, "error reading variable information [-]");
    }
    if (UMC_OK == umcRes)
    {
        // Figure out the size of the screen in bytes
        m_uiMapSize = m_sVarInfo.xres *
                      m_sVarInfo.yres *
                      m_sVarInfo.bits_per_pixel / 8;

        // Map the device to memory
        m_pbMap = (Ipp8u*)mmap(NULL, m_uiMapSize,
                               PROT_READ | PROT_WRITE, MAP_SHARED,
                               m_iDevHandle, 0);
        if (MAP_FAILED == m_pbMap)
        {
            ERR_SET(UMC_ERR_ALLOC, "failed to map framebuffer device to memory [-]");
        }
    }
    if (UMC_OK != umcRes)
    {
        Close();
    }
    DBG_SET("-");
    return umcRes;

} // Status FBVideoRender::Init

Status FBVideoRender::LockInputBuffer(MediaData* pInData)
{
#undef  FUNCTION
#define FUNCTION "LockInputBuffer"
    DBG_SET("+");
    Status umcRes = UMC_OK;
    VideoData *pVideoData = DynamicCast<VideoData>(pInData);

    if (NULL == pVideoData)
    {
        ERR_SET(UMC_ERR_NULL_PTR, "'pInData' points to NULL [-]");
    }
    if ((UMC_OK == umcRes) && (NULL == m_pbMap))
    {
        ERR_SET(UMC_ERR_NOT_INITIALIZED, "render wasn't previously initialized [-]");
    }
    if (UMC_OK == umcRes)
    {
        VM_ASSERT(0 != m_uiMapSize);
        while (VM_TIMEOUT == m_ReadySema.Wait(1000))
        {
            if(m_bStopFlag || (m_dfFrameTime == -1.0))
            {
                umcRes = UMC_ERR_END_OF_STREAM;
                break;
            }
        }
    }
    if (UMC_OK == umcRes)
    {
        ColorFormat cf = RGB565;    // now only this format is supported
        pVideoData->Init(m_sVarInfo.xres,m_sVarInfo.yres,cf);
    }
    if (UMC_OK == umcRes)
    {
        umcRes = pVideoData->SetSurface(m_pbMap, m_sFixInfo.line_length);
    }
    else
    {
        pVideoData->SetSurface(NULL, 0);
    }
    DBG_SET("-");
    return umcRes;

} // Status FBVideoRender::LockInputBuffer

Status FBVideoRender::UnLockInputBuffer(MediaData *pInData, Status StreamStatus)
{
#undef  FUNCTION
#define FUNCTION "UnLockInputBuffer"
    DBG_SET("+");
    Status umcRes = UMC_OK;
    VideoData* pVideoData = DynamicCast<VideoData>(pInData);

    if (NULL == pVideoData)
    {
        ERR_SET(UMC_ERR_NULL_PTR, "'pInData' points to NULL [-]");
    }
    if (UMC_OK == umcRes)
    {
        m_dfFrameTime = pVideoData->GetTime();
        umcRes = m_DoneSema.Signal();
    }
    if (UMC_ERR_END_OF_STREAM == StreamStatus)
    {
        Stop();
    }
    DBG_SET("-");
    return umcRes;

} // Status FBVideoRender::UnLockInputBuffer

} // namespace UMC

#endif // ifdef UMC_ENABLE_FB_VIDEO_RENDER

⌨️ 快捷键说明

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