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

📄 vcd_app.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2002 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
 * vcd_app.cpp
 *
 * Application for playing VCDs
 *
 * $Id: vcd_app.cpp,v 1.34 2007/01/26 21:11:50 rbehe Exp $
 */

#include <string.h>
#include "version.h"
#include "vdvd_types.h"
#include "osapi.h"
#include "loader_app.h"
#include "dr_app.h"
#include "pe_app.h"
#include "dbgprint.h"
#include "utility.h"
#include "usrapi.h"
#include "vcd.h"
#include "vcd_app.h"
#include "../dvd/timer.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif

using namespace vcd;

/* MACROS */
#define VCDAPP_DEBUG DBG_ERROR
#define DBG_ON(x) (VCDAPP_DEBUG >= x)

#define MSQ_QUEUE_SIZE 320  /**< defines the number of ULONG */

typedef enum tagVCDAPPEVENTSOURCE
{
    VCDAPP_EVENTSOURCE_DR = 0,
    VCDAPP_EVENTSOURCE_PE = 1
} VcdAppEventSource;

/* LOCALS */
static ULONG   ulVcdTaskID        = 0;
static BOOLEAN fVCDAppStarted     = FALSE;

/*
 * PRIVATE FUNCTION PROTOTYPES
 *****************************************************************************/
static void      VcdAppStopNav(void);
static PE_STATUS vcdappPEEventCallback(PVOID pContext, PE_EVENT_CODE event, PVOID pEventInfo);
static DR_ERROR  vcdappDrEventCallback(PVOID pContext, DR_EVENT_CODE event, PVOID pEventInfo);

OS_STATUS VcdAppInitialize(LOADER_HANDLE loader, DR_HANDLE dr, PE_HANDLE pe)
{
    ULONG ulEvents = PE_EVENT_BEG_OF_STREAM | PE_EVENT_END_OF_STREAM | PE_EVENT_DISCONTINUITY |
        PE_EVENT_ASYNC_PREFILL | PE_EVENT_AUTO_PAUSE | PE_EVENT_POSITION;

    tLoader = loader;
    tDR     = dr;
    tPE     = pe;

    DbgPrint(("%s, %s\n", VERSION_STRING, VERSION_DATE_STRING));

    /* attach PE event handler */
    if (PERegisterForEvents(tPE, vcdappPEEventCallback, ulEvents, tPE) != PE_SUCCESS)
    {
        DbgPrint(("VcdAppInitialize() - PERegisterForEvents FAILED\n"));
        goto error_out;
    }

    /* attach DR event handler */
    if (DRAttachEvent (tDR, vcdappDrEventCallback, tDR) != DR_SUCCESS)
    {
        DbgPrint(("VcdAppInitialize() - DRAttachEvent FAILED\n"));
        goto error_out;
    }

    return (OS_OK);

error_out:
    VcdAppUnInitialize();
    return (OS_FAILURE);
}

OS_STATUS VcdAppUnInitialize(void)
{
    /* stop the DR */
    DRStop(tDR);

    DRDetachStream(tDR, DR_STREAM_MAIN);

    DRReset(tDR);

    /* detach DR event handler */
    DRDetachEvent(tDR);

    /* unregister PE events */
    PEDetachEvent(tPE, vcdappPEEventCallback);

    if (TRUE == fVCDAppStarted)
    {
        DBGPRINT(DBG_ON(DBG_TRACE), ("VcdAppUnInitialize: VcdAppStopNav\n"));
        VcdAppStopNav();
    }

    /* set global pointers to NULL */
    tLoader = NULL;
    tDR     = NULL;
    tPE     = NULL;

    return (OS_OK);
}


/**
 * Sends messages to nav_task in responce to input commands.
 */
OS_STATUS VcdAppCommandHandler(ULONG ulCommand, ULONG ulInfo)
{
    BOOLEAN fIsSupported = TRUE;
    ULONG   msg[4];

    msg[0] = MSG_KEY;

    /* Map command to a nav_task command */
    switch (ulCommand)
    {
    case VDVD_COMMAND_STEP_FWD:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_STEP_FWD\n"));
        msg[1] = KEY_STEP;
        break;

    case VDVD_COMMAND_FWD_PLAY:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_FWD_PLAY\n"));
        msg[1] = KEY_FWD_PLAY;
        msg[2] = ulInfo;
        break;

    case VDVD_COMMAND_MENU:
    case VDVD_COMMAND_TITLE:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_TITLE\n"));
        msg[1] = KEY_PBC;
        break;

    case VDVD_COMMAND_PLAY:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_PLAY\n"));
        msg[1] = KEY_PLAY;
        break;

    case VDVD_COMMAND_PAUSE_ON:
    case VDVD_COMMAND_PAUSE_OFF:
        if (ulPlaySpeed != 0)
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_PAUSE\n"));
            msg[1] = KEY_PAUSE_ON;
        }
        else
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_PAUSE\n"));
            msg[1] = KEY_PAUSE_OFF;
        }
        break;

    case VDVD_COMMAND_STOP:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): VDVD_COMMAND_STOP\n"));
        msg[1] = KEY_STOP;
        break;

    case VDVD_COMMAND_NEXT_CHAPTER:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_SKIP_FWD\n"));
        msg[1] = KEY_NEXT_PG;
        msg[2] = 0;
        break;

    case VDVD_COMMAND_PREV_CHAPTER:
    case VDVD_COMMAND_RESTART_CHAPTER:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_SKIP_BWD\n"));
        msg[1] = KEY_PREV_PG;
        msg[2] = ( (VDVD_COMMAND_PREV_CHAPTER == ulCommand) ? PREV_TRACK : CUR_TRACK );
        break;

    case VDVD_COMMAND_NUMBER:
        DBGPRINT(DBG_ON(DBG_ALL), ("\n\nprocessIrRemoteKeys: VDVD_COMMAND_NUMBER %u\n", ulInfo));
        msg[1] = KEY_NUMBER;
        msg[2] = ulInfo;
        break;

    case VDVD_COMMAND_RETURN:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_RETURN\n"));
        msg[1] = KEY_RETURN;
        break;

    case VDVD_COMMAND_GOTO_CHAPTER:
    case VDVD_COMMAND_GOTO_TITLE:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_TITLE\n"));
        msg[1] = KEY_TITLE_PLAY;
        msg[2] = ulInfo;
        break;

    case VDVD_COMMAND_GOTO_TIME:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_GOTO_TIME\n"));
        msg[1] = KEY_TIME_SEARCH;
        msg[2] = ulInfo;
        break;

    case VDVD_COMMAND_REPEAT:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys: VDVD_COMMAND_REPEAT\n"));
        if ( (ulInfo == VDVD_INFO_REPEAT_A) || (ulInfo == VDVD_INFO_REPEAT_AB) )
        {
            msg[1] = KEY_A_B;
        }
        else
        {
            msg[1] = KEY_REPEAT;
        }
        msg[2] = ulInfo;
        break;

    case VDVD_COMMAND_PLAY_LOCATION:
        msg[1] = KEY_PLAY_LOCATION;
        msg[2] = ulInfo;
        break;

    default:
        DBGPRINT(DBG_ON(DBG_TRACE), ("processIrRemoteKeys(): KeyCode %d NOT SUPPORTED\n", ulCommand));
        fIsSupported = FALSE;
        goto out;
    }

    /* send the message to the queue */
    if (fIsSupported == TRUE)
    {
        OS_MsgQSend(queue_vcd, (char *)&msg[0], VCD_MSG_SIZE, OS_NO_WAIT, OS_MSG_PRI_NORMAL);
    }
    else
    {
        /* notifiy unsupported command */
        UsrSendProhibitedEvent(VDVD_INFO_PROH_CMD_NOT_SUPPORTED, ulCommand);
    }

out:
    return (OS_OK);
}

/**
 * VcdAppSetVideoFormat -- Set the video format
 *
 * @param
 *      ucVideoFormat - video format
 *
 * @retval
 *      none.
 */
void VcdAppSetVideoFormat(UCHAR ucVideoFormat)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppSetVideoFormat: stubbed\n"));
}

/**
 * VcdAppSetAspectRatio -- Set the aspect ratio
 *
 * @param
 *      ucAspectRatio - aspect ratio
 *
 * @retval
 *      none.
 */
void VcdAppSetAspectRatio(UCHAR ucAspectRatio)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppSetAspectRatio: stubbed\n"));
}

/**
 * VcdAppSetDigitalAudioOutput -- Set the digital audio output
 *
 * @param
 *      ucDigOut - digital output
 *
 * @retval
 *      none.
 */
void VcdAppSetDigitalAudioOutput(UCHAR ucDigOut)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppSetDigitalAudioOutput: stubbed\n"));
}

/**
 * Initialize the navigator, create threads, semaphores, timers, queues, etc.
 */
void VcdAppStartNav(void)
{
    ULONG  stacksize = 8*1024;
    ULONG  msg[4];

    /* initialize */
    fVCDAppStarted = TRUE;

    /* Create message queues */
    queue_vcd = OS_MsgQCreate(MSQ_QUEUE_SIZE/4, VCD_MSG_SIZE, OS_MSG_Q_FIFO);
    DbgAssert(queue_vcd != 0);

    /*  create vcd navigators command processing task */
    ulVcdTaskID = OS_TaskSpawnParam("VCDTask", OS_TASK_HIGH_PRIORITY, stacksize, pbc_main, NULL, NULL);
    if (ulVcdTaskID == (ULONG)OS_FAILURE)
    {
        DBGPRINT(VCDAPP_DEBUG, ("VcdAppStartNav: Create VCDTask failed!\n"));
        ulVcdTaskID = 0;
    }
    DbgAssert(ulVcdTaskID != 0);

    /* start vcd */
    msg[0] = MSG_START_VCD;
    OS_MsgQSend(queue_vcd, (char *)&msg[0], VCD_MSG_SIZE, OS_WAIT_FOREVER, OS_MSG_PRI_NORMAL);
}

/*
 * Functions for querying the vcd nav for state information
 ******************************************************************************/

/**
 * VcdAppGetPlayState -- Get play state of the nav
 *
 * @param
 *      none
 *
 * @retval
 *      play state
 */
USHORT VcdAppGetPlayState(void)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppGetPlayState: stubbed\n"));
    return (0);
}

/**
 * VcdAppGetNumberOfTitles -- Get number of titles on the disc
 *
 * @param
 *      none
 *
 * @retval
 *      Number of titles
 */
USHORT VcdAppGetNumberOfTitles(void)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppGetNumberOfTitles: stubbed\n"));
    return (0);
}

/**
 * VcdAppGetNumberOfChapters -- Get number of chapters on the current title
 *
 * @param
 *      none
 *
 * @retval
 *      Number of chapters
 */
USHORT VcdAppGetNumberOfChapters(void)
{
    DBGPRINT(DBG_ON(DBG_ERROR), ("VcdAppGetNumberOfTitles: stubbed\n"));
    return (0);
}

/**
 * VcdAppGetCurrentTitle -- Get the current title number
 *
 * @param

⌨️ 快捷键说明

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