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

📄 pe_app.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2006 Videon Central, Inc.                                 **
**  All rights reserved.                                                    **
**                                                                          **
**  The computer program contained herein contains proprietary information  **
**  which is the property of Videon Central, Inc.  The program may be used  **
**  and/or copied only with the written permission of Videon Central, Inc.  **
**  or in accordance with the terms and conditions stipulated in the        **
**  agreement/contract under which the programs have been supplied.         **
**                                                                          **
******************************************************************************
*****************************************************************************/
/**
 * @file pe_app.cpp
 *
 * $Revision: 1.11 $ 
 *
 * DVD Presentation Engine API source file.
 *
 */

#include <string.h>
#include "decoder.h"
#include "vdvd_types.h"
#include "osapi.h"
#include "pe_app.h"
#include "cStream.h"
#include "msg_app.h"
#include "pe_consumer.h"
#include "pe_types.h"
#include "dbgprint.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif

ICONFIGUREHANDLE* PECreateiConfigure(PE_HANDLE handle);
ISTREAMCTRLHANDLE* PECreateiStreamCtrl(PE_HANDLE handle);
ISPLASHSCREENHANDLE* PECreateiSplashScreen(PE_HANDLE handle);

PE_STATUS PEDeleteiConfigure(ICONFIGUREHANDLE* iConfig);
PE_STATUS PEDeleteiStreamCtrl(ISTREAMCTRLHANDLE* iStrmCtrl);
PE_STATUS PEDeleteiSplashScreen(ISPLASHSCREENHANDLE* iSplashScreen);

DfbExtHandle dfb_spu_graphics_layer = NULL;


/* PE Manager */

/**
 * Creates and initializes the PE Interface Manager.
 *
 * @param pPE - Pointer to PE component handle.
 *
 * @return PE_STATUS - PE Error code.
 */
PE_STATUS PECreate(PE_HANDLE *pPE)
{
    PEHANDLE   *pe     = NULL;

    DbgAssert(pPE != NULL);

    pe = (PEHANDLE*)OS_MemAlloc(sizeof(PEHANDLE));
    if (pe == NULL)
    {
        goto err_out;
    }
    memset( pe, 0, sizeof(PEHANDLE) );

    /* open the graphics display layers */
    pe->dfb_pg_graphics_layer = DfbExtDisplayLayerOpen(DFB_EXT_BD_HDMV_PRESENTATION_LAYER);
    if (pe->dfb_pg_graphics_layer == NULL)
    {
        DbgPrint(("PECreate -- COULD NOT OPEN PG DISPLAY LAYER!\n"));
        goto err_out;
    }
    pe->dfb_ig_graphics_layer = DfbExtDisplayLayerOpen(DFB_EXT_BD_HDMV_INTERACTIVE_LAYER);
    if (pe->dfb_ig_graphics_layer == NULL)
    {
        DbgPrint(("PECreate -- COULD NOT OPEN IG DISPLAY LAYER!\n"));
        goto err_out;
    }
    /* Replaced with a new type but splashscreen should be moved to a OSD surface !!! */
    pe->dfb_background_layer = DfbExtDisplayLayerOpen(DFB_EXT_SPLASHSCREEN_LAYER);
    if (pe->dfb_background_layer == NULL)
    {
        DbgPrint(("PECreate -- COULD NOT OPEN BACKGROUND DISPLAY LAYER!\n"));
        goto err_out;
    }

    /* don't like this, but works for now */
    dfb_spu_graphics_layer = pe->dfb_pg_graphics_layer;

    /* create the PE interfaces */
    pe->iConfigure    = PECreateiConfigure(pe);
    pe->iSplashScreen = PECreateiSplashScreen(pe);
    pe->iStreamCtrl   = PECreateiStreamCtrl(pe);

    /* create mutex sem for event callback */
    pe->eventSem = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);

    /* verify the PE interfaces */
    if ((pe->iConfigure == NULL) || (pe->iSplashScreen == NULL) || (pe->iStreamCtrl == NULL))
    {
        goto err_out;
    }

    /* verify the semaphores */
    if (pe->eventSem == 0)
    {
        goto err_out;
    }

    /* return the handle */
    *pPE = pe;

    return (PE_SUCCESS);

err_out:

    /* error... cleanup and return error status */
    if (pe != NULL)
    {
        if (pe->eventSem != 0)
        {
            OS_SemDelete(pe->eventSem);
            pe->eventSem = 0;
        }
        if (pe->iConfigure != NULL)
        {
            PEDeleteiConfigure(pe->iConfigure);
        }
        if (pe->iSplashScreen != NULL)
        {
            PEDeleteiSplashScreen(pe->iSplashScreen);
        }
        if (pe->iStreamCtrl != NULL)
        {
            PEDeleteiStreamCtrl(pe->iStreamCtrl);
        }
        OS_MemFree(pe);
    }

    /* don't like this, but works for now */
    dfb_spu_graphics_layer = NULL;

    *pPE = NULL;

    return (PE_FAILURE);
}


/**
 * PEDelete()
 *      Deletes the PE Interface Manager.
 *
 * @param tPE - PE component handle.
 *
 * @return
 *      PE_STATUS            Error code.
 *
 * @notes
 *      NONE
 */
PE_STATUS PEDelete(PE_HANDLE tPE)
{
    PEHANDLE *pe = (PEHANDLE*)tPE;

    if (pe == NULL)
    {
        return (PE_INVALID_HANDLE);
    }

    DbgAssert(pe->eventSem);
    DbgAssert(pe->iConfigure);
    DbgAssert(pe->iSplashScreen);
    DbgAssert(pe->iStreamCtrl);

    /* delete the semaphores */
    OS_SemDelete(pe->eventSem);
    pe->eventSem = 0;

    /* delete the interfaces */
    PEDeleteiConfigure(pe->iConfigure);
    PEDeleteiSplashScreen(pe->iSplashScreen);
    PEDeleteiStreamCtrl(pe->iStreamCtrl);

    /*
     * Add platform specific code here
     */

    /* close the graphics display layers */
    if (pe->dfb_pg_graphics_layer != NULL)
    {
        DfbExtDisplayLayerClose(pe->dfb_pg_graphics_layer);
    }
    if (pe->dfb_ig_graphics_layer != NULL)
    {
        DfbExtDisplayLayerClose(pe->dfb_ig_graphics_layer);
    }
    if (pe->dfb_background_layer != NULL)
    {
        DfbExtDisplayLayerClose(pe->dfb_background_layer);
    }

    /* don't like this, but works for now */
    dfb_spu_graphics_layer = NULL;

    /* free memory */
    OS_MemFree(pe);

    return (PE_SUCCESS);
}

/**
 * Provides PE event registration.
 *
 * @param hPE      - The PE handle
 * @param function - The callback function pointer to add
 * @param ulEvents - Bitmask of events to enable
 * @param pContext - An optional context to be returned with each event callback.
 *
 * @return PE_STATUS - Error code.
 */
PE_STATUS PERegisterForEvents(PE_HANDLE hPE, PE_EVENT_CALLBACK function, ULONG ulEvents, PVOID pContext)
{
    PE_STATUS status = PE_FAILURE;

    /* verify input */
    if (NULL == hPE)
    {
        return (PE_INVALID_HANDLE);
    }

    /* take critical section */
    OS_SemTake( ((PEHANDLE *)hPE)->eventSem, OS_WAIT_FOREVER );

    if (NULL == ((PEHANDLE *)hPE)->callback)
    {
        ((PEHANDLE *)hPE)->callback = (PVOID)function;
        ((PEHANDLE *)hPE)->events   = ulEvents;
        ((PEHANDLE *)hPE)->context  = pContext;
        status                      = PE_SUCCESS;
    }

    /* release critical section */
    OS_SemGive( ((PEHANDLE *)hPE)->eventSem );

    return (status);
}

/**
 * Detaches previously registered callback events.
 *
 * @param hPE           - The PE handle
 * @param eventCallback - The event Callback function pointer.
 *
 * @return PE_STATUS - Error code.
 */
PE_STATUS PEDetachEvent(PE_HANDLE hPE, PE_EVENT_CALLBACK eventCallback)
{
    PE_STATUS status = PE_FAILURE;

    /* verify input */
    if (NULL == hPE)
    {
        return (PE_INVALID_HANDLE);
    }

    /* take critical section */
    OS_SemTake( ((PEHANDLE *)hPE)->eventSem, OS_WAIT_FOREVER );

    if ( (PVOID)eventCallback == ((PEHANDLE *)hPE)->callback )
    {
        ((PEHANDLE *)hPE)->callback = NULL;
        ((PEHANDLE *)hPE)->events   = 0;
        ((PEHANDLE *)hPE)->context  = NULL;
        status                      = PE_SUCCESS;
    }

    /* release critical section */
    OS_SemGive( ((PEHANDLE *)hPE)->eventSem );

    return (status);
}

/**
 * Private function that sends a callback based on a registered event.
 *
 * @param hPE        - The PE handle
 * @param event      - The event code
 * @param pEventInfo - Pointer to a struct of event info required to process the event.
 *
 * @return PE_STATUS.
 */
PE_STATUS peSendEvent(PE_HANDLE hPE, PE_EVENT_CODE event, PVOID pEventInfo)
{
    PE_STATUS status;
    PE_EVENT_CALLBACK pe_callback_local = NULL;
    PVOID pe_context = NULL;

    DbgAssert(NULL != hPE);
    DbgAssert(event < PE_EVENT_CODE_INVALID);

    OS_SemTake( ((PEHANDLE *)hPE)->eventSem, OS_WAIT_FOREVER );
    if ( (NULL != ((PEHANDLE *)hPE)->callback) && (event & ((PEHANDLE *)hPE)->events) )
    {
        pe_callback_local = (PE_EVENT_CALLBACK)(((PEHANDLE *)hPE)->callback);
        pe_context = ((PEHANDLE *)hPE)->context;

        status = PE_SUCCESS;
    }
    else
    {
        status = PE_FAILURE;
    }
    OS_SemGive( ((PEHANDLE *)hPE)->eventSem );


    if (status == PE_SUCCESS)
    {
        status = (pe_callback_local)( pe_context, event, pEventInfo );
    }

    return (status);
}


⌨️ 快捷键说明

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