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

📄 cmdproc.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2005-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 cmdproc.cpp
 *
 * API to the Command Processor of the BD-ROM navigator.
 * The command processor handles processing of a command
 * program from a Movie Object or a Button Object.
 *
 * $Id: cmdproc.cpp,v 1.25 2006/10/25 23:38:48 rbehe Exp $
 */

#include <stdlib.h>
#include "vdvd_types.h"
#include "cmdproc.h"
#include "cmdproc_types.h"
#include "navcmd.h"
#include "../mvobjdb.h"
#include "../playctrl/playctrl.h"
#include "osapi.h"
#include "dbgprint.h"

/* Debug macros */
#define DBG_CMDPROC DBG_ERROR
#define DBG_ON(x)   (DBG_CMDPROC >= x)

#if DBG_ON(DBG_VERBOSE)
#include "cmdproc_debug.h"
#endif


/**
 * Private handle declaration
 */
CMDPROC_HANDLE  *hCmdProc = NULL;

/**
 * Local functions
 */
static CMDPROC_STATUS   CmdProcMapNavCmdFunctions(void);
static CMDPROC_STATUS   CmdProcExecuteCommandProgram(CMDPROC_CMD_PRGM *pCmdProgram, ULONG *pulStatusParam);

/**
 * CmdProcInitialize -- Initialize the command processor
 *
 * @param
 *      none.
 *
 * @retval
 *      CMDPROC_SUCCESS if successful
 *      CMDPROC_FAILURE if not successful
 */
CMDPROC_STATUS  CmdProcInitialize(void)
{
    if (hCmdProc != NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcInitialize: Already created!\n"));
        goto errout;
    }

    /* Create the private handle */
    hCmdProc = (CMDPROC_HANDLE *)OS_MemAlloc(sizeof(CMDPROC_HANDLE) );
    if (hCmdProc == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcInitialize: Failure creating local handle!\n"));
        goto errout;
    }

    /* Allocate array of function pointers */
    hCmdProc->pvCmdFunction = OS_MemAlloc(sizeof(NAVCMD_FUNC_PTR) * NAVCMD_INVALID);
    if (hCmdProc->pvCmdFunction == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcInitialize: Failure creating array of function pointers!\n"));
        goto errout;
    }

    /* Map function pointers to nav command routines */
    if (CmdProcMapNavCmdFunctions() != CMDPROC_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcInitialize: Failure mapping function pointers!\n"));
        goto errout;
    }

    /* Initialize state of Command Processor */
    hCmdProc->tState                = CMDPROC_STATE_TERMINATED;
    hCmdProc->fTransitionPending    = FALSE;
    hCmdProc->fTitleRepeatOn        = FALSE;

    /* Initially there is no movie command program */
    hCmdProc->MoviePrgm.ulLength        = 0;
    hCmdProc->MoviePrgm.ulCurrentCmdID  = 0;

    /* Initially there is no button command program */
    hCmdProc->ButtonPrgm.ulLength       = 0;
    hCmdProc->ButtonPrgm.ulCurrentCmdID = 0;

    return (CMDPROC_SUCCESS);

errout:

    if (hCmdProc != NULL)
    {
        if (hCmdProc->pvCmdFunction != NULL)
        {
            /* Delete function pointers */
            OS_MemFree(hCmdProc->pvCmdFunction);
            hCmdProc->pvCmdFunction = NULL;
        }

        /* Delete the local handle */
        OS_MemFree(hCmdProc);
        hCmdProc = NULL;
    }

    return (CMDPROC_FAILURE);
}

/**
 * CmdProcUninitialize -- Uninitialize the command processor
 *
 * @param
 *      none.
 *
 * @retval
 *      CMDPROC_SUCCESS if successful
 *      CMDPROC_FAILURE if not successful
 */
CMDPROC_STATUS  CmdProcUninitialize(void)
{
    if (hCmdProc != NULL)
    {
        /* If command processor state is not terminated, terminate the movie object */
        if ( (hCmdProc->tState != CMDPROC_STATE_TERMINATED) && (hCmdProc->tState != CMDPROC_STATE_INVALID) )
        {
            CmdProcTerminateMovieProgram();
        }

        if (hCmdProc->pvCmdFunction != NULL)
        {
            /* Delete function pointers */
            OS_MemFree(hCmdProc->pvCmdFunction);
            hCmdProc->pvCmdFunction = NULL;
        }

        /* Delete the local handle */
        OS_MemFree(hCmdProc);
        hCmdProc = NULL;
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcUninitialize: Not initialized!\n"));
        return (CMDPROC_FAILURE);
    }

    return (CMDPROC_SUCCESS);
}

/**
 * CmdProcProcessMovieProgram -- Process a movie command program.
 *
 * @param
 *      pvMovieProgram  -- Pointer to buffer containing command program
 *      ulLength        -- Number of command in the command program.
 *      pulStatusParam  -- Pointer to parameter that is associated with the return status code
 *
 * @retval
 *      CMDPROC_STATUS
 */
CMDPROC_STATUS  CmdProcProcessMovieProgram(MVOBJ_NAV_COMMAND *pMovieProgram, ULONG ulNumberOfCommands, ULONG *pulStatusParam)
{
    CMDPROC_STATUS tStatus = CMDPROC_FAILURE;

    if (hCmdProc == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcProcessMovieProgram: Command Processor not initialized!\n"));
        return (CMDPROC_FAILURE);
    }

    /* Check for valid command program buffer */
    if (pMovieProgram == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcProcessMovieProgram: Invalid command program buffer!\n"));
        return (CMDPROC_NULL_POINTER);
    }

    /* Check for valid command program size */
    if (ulNumberOfCommands > MVOBJ_MAX_NAV_COMMANDS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcProcessMovieProgram: Invalid command program size!\n"));
        return (CMDPROC_FAILURE);
    }

    /* Check for valid status param pointer */
    if (pulStatusParam == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcProcessMovieProgram: Invalid status parameter pointer!\n"));
        return (CMDPROC_NULL_POINTER);
    }

    /*
     * If there is already a movie program active, do not allow this one to be processed.
     * The already active program must first be terminated.
     */
    if (hCmdProc->tState != CMDPROC_STATE_TERMINATED)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcProcessMovieProgram: Invalid state for processing a movie program!\n"));
    }
    else
    {
        /* Copy command program */
        memcpy( (void *)hCmdProc->MoviePrgm.aCommands, (void *)pMovieProgram, (ulNumberOfCommands * sizeof(MVOBJ_NAV_COMMAND) ) );

        /* Set command program length and current command ID */
        hCmdProc->MoviePrgm.ulLength        = ulNumberOfCommands;
        hCmdProc->MoviePrgm.ulCurrentCmdID  = 0;

        /* Set the state of the command processor to processing */
        hCmdProc->tState                = CMDPROC_STATE_MOVIE_PROCESSING;
        hCmdProc->fTransitionPending    = FALSE;
        hCmdProc->fTitleRepeatOn        = FALSE;

        /* Execute the command program */
        tStatus = CmdProcExecuteCommandProgram(&hCmdProc->MoviePrgm, pulStatusParam);
    }

    return (tStatus);
}

/**
 * CmdProcSuspendMovieProgram -- Suspend a movie command program.
 *
 * @param
 *      pulCmdID -- pointer to variable that gets set to current command id.
 *
 * @retval
 *      Command ID of where Movie Program was suspended.
 */
CMDPROC_STATUS  CmdProcSuspendMovieProgram(ULONG *pulCmdID)
{
    CMDPROC_STATUS tStatus = CMDPROC_SUCCESS;

    if (hCmdProc == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcSuspendMovieProgram: Command Processor not initialized!\n"));
        return (CMDPROC_FAILURE);
    }

    /* Check for valid command id pointer */
    if (pulCmdID == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcSuspendMovieProgram: NULL pointer!\n"));
        return (CMDPROC_NULL_POINTER);
    }

    /*
     * Command processor must be in a running state to suspend.
     */
    if ( (hCmdProc->tState == CMDPROC_STATE_TERMINATED) || (hCmdProc->tState == CMDPROC_STATE_INVALID) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcSuspendMovieProgram: Invalid state to suspend!\n"));
        tStatus = CMDPROC_FAILURE;
    }
    else
    {
        /*
         * If command processor is waiting for playlist playback, then
         * suspend playback.  Otherwise, just backup the PSR's.
         */
        if (hCmdProc->tState == CMDPROC_STATE_WAITING)
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("CmdProcSuspendMovieProgram: Suspending playlist playback\n"));

            /* Entering playback control critical section */
            PlayCtrlTakeSemaphore();

            /* Tell playback control engine to suspend playback */
            if (PlayCtrlSuspend() != PLAYCTRL_SUCCESS)
            {
                DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcSuspendMovieProgram: Failed to suspend playback!\n"));
                tStatus = CMDPROC_FAILURE;
            }

            /* Leaving playback control critical section */
            PlayCtrlGiveSemaphore();
        }
        else
        {
            /* Tell playback control engine to backup PSR's */
            if (PlayCtrlStoreBackupPSR() != PLAYCTRL_SUCCESS)
            {
                DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcSuspendMovieProgram: Failed to backup PSR's!\n"));
                tStatus = CMDPROC_FAILURE;
            }
        }

        if (tStatus == CMDPROC_SUCCESS)
        {
            /* Set the command ID to the current command being processed */
            *pulCmdID = hCmdProc->MoviePrgm.ulCurrentCmdID;

            /* Set the command processor state to terminated */
            hCmdProc->tState = CMDPROC_STATE_TERMINATED;
        }
    }

    return (tStatus);
}

/**
 * CmdProcResumeMovieProgram -- Resume a movie command program.
 *
 * @param
 *      pvMovieProgram  -- Pointer to buffer containing command program
 *      ulLength        -- Number of command in the command program.
 *      ulCmdID         -- Command ID of where the execution of the command program
 *                         should start
 *      pulStatusParam  -- Pointer to parameter that is associated with the return status code
 *      fExecutePrecommands -- if this flag is set, then re-execute all "compare" or "set" commands,
 *                             up to the command specified
 *
 *
 * @retval
 *      CMDPROC_STATUS
 */
CMDPROC_STATUS  CmdProcResumeMovieProgram(MVOBJ_NAV_COMMAND *pMovieProgram, ULONG ulNumberOfCommands, ULONG ulCmdID, ULONG *pulStatusParam)
{
    CMDPROC_STATUS tStatus = CMDPROC_FAILURE;

    if (hCmdProc == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CmdProcResumeMovieProgram: Command Processor not initialized!\n"));
        return (CMDPROC_FAILURE);
    }

⌨️ 快捷键说明

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