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

📄 metanav.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  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 metanav.cpp
 *
 * Defines the cMetaNav class which will handle the initialization and creation of
 * the Media Specific Navigator.
 *
 * $Id: metanav.cpp,v 1.182 2007/01/30 22:53:14 jared Exp $
 */

#include "vdvd_types.h"
#include "metanav.h"
#include "diskinfo.h"
#include "dvd_app.h"
#include "vr_app.h"
#include "dbgprint.h"
#include "usrapi.h"
#include "../dvd/nav_task.h"
#include "../dvd/timer.h"
#include "../dvd/dvdnvpck.h"
#include "mpeg_ids.h"

#ifdef VCD_ENABLE
#include "vcd_app.h"
#endif

#ifdef MP3_ENABLE
#include "mp3main.h"
#endif

#ifdef CDDA_ENABLE
#include "cdda_app.h"
#endif

#ifdef BDROM_ENABLE
#include "bdrom_app.h"
#endif

#ifdef HDDVD_ENABLE
#include "hddvd_app.h"
#endif

#ifdef DMALLOC
#include "dmalloc.h"
#endif

/* MACROS */
#define DBG_META DBG_ERROR
#define DBG_ON(x) (DBG_META >= x)
#define META_DISC_QUEUE_DEPTH      5
#define META_SIMPLECMD_QUEUE_DEPTH 1
//#define __CALC_PEAK_ALLOCATION


/* The number of dr messages and payload size together
 * specify the size of the DRs track buffer */
#define NUM_DR_MESSAGES_LOW_BITRATE  (8)        /* Want to keep the amount of buffering to a minimum */
#define NUM_DR_MESSAGES_HIGH_BITRATE (90)

/* Frequency to test for loader unit ready in seconds */
#define META_TUR_FREQUENCY  (1)

/* metanav should not override the players default region code */
#define METANAV_USE_DEFAULT_REGION_CODE 0

/*
 * the default region codes for the player
 */
#ifndef DVD_SPRM_REGION_DEFAULT
#define DVD_SPRM_REGION_DEFAULT  0x01
#endif
#ifndef BDROM_PSR_REGION_DEFAULT
#define BDROM_PSR_REGION_DEFAULT 0x01
#endif

/* possible states of metanav's disc task */
typedef enum
{
  DISC_TASK_PROCESSING_OPENTRAY,    // loader was told to open but is not yet opening
  DISC_TASK_PROCESSING_CLOSETRAY,   // loader was told to close but is not yet closing
  DISC_TASK_PROCESSING_START,       // loader is spinning up
  DISC_TASK_TRAY_OPENING,           // loader is opening
  DISC_TASK_TRAY_CLOSING,           // loader is closing
  DISC_TASK_IDLE                    // loader is fully opened or closed
} DISC_TASK_TRAY_STATE;

/**
 * @var Global Payload Manager
 * @brief Used by all modules requiring payloads.
 */
cPayloadManager *globalPayloadManager = NULL;

#ifdef __CALC_PEAK_ALLOCATION
extern ULONG                   ulPeakAllocations;
#endif


/* PRIVATE FUNCTION PROTOTYPES */
static ULONG MetaNavDiscTask(PVOID pvParam);
static ULONG MetaNavSimpleCmdTask(PVOID pvParam);


/**
 * Sets all member variables to initial state
 */
cMetaNav::cMetaNav(void)
{
    for (int i=0; i<MAX_PE_INPUTS; i++)
    {
        m_DataStreamLowBitrate[i].pStreamBuffer     = NULL;
        m_DataStreamLowBitrate[i].pStream           = NULL;
        m_DataStreamHighBitrate[i].pStreamBuffer    = NULL;
        m_DataStreamHighBitrate[i].pStream          = NULL;
    }
    m_Loader                    = NULL;
    m_DR                        = NULL;
    m_PE                        = NULL;
    m_pDiskInfo                 = NULL;
    m_pDiscQueue                = NULL;
    m_pDiscMsgPool              = NULL;
    m_pSimpleCmdQueue           = NULL;
    m_pSimpleCmdMsgPool         = NULL;
    m_DiscTaskID                = 0;
    m_SimpleCmdTaskID           = 0;
    m_Terminate                 = FALSE;
    m_fAutoPlay                 = TRUE;
    m_MediaFormat               = MEDIA_FORMAT_UNKNOWN;
    m_fStatusCheckProcessing    = FALSE;
    m_fStandbyMode              = TRUE;
    m_fStandbyProcessing        = FALSE;
    m_LoaderStatus.ulTrayStatus = LOADER_TRAY_CLOSED;
    m_pConfigSettings           = NULL;
    m_fResumeOnStandbyMode      = TRUE;
    m_pStandbyLocation          = NULL;
    m_ulStandbyLocationSize     = 0;
    m_fResumeOnStandbySet       = FALSE;
#ifdef BDROM_ENABLE
    m_fIsDiscUnbound            = FALSE;
#endif
    m_DVD_RegionCode            = METANAV_USE_DEFAULT_REGION_CODE;
    m_BDROM_RegionCode          = METANAV_USE_DEFAULT_REGION_CODE;
	m_semStopNav				= 0;
}

cMetaNav::~cMetaNav(void)
{
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- stop media specific nav\n"));

    /* stop the current media specific nav */
    StopNav();

    /* Delete location handle */
    m_ulStandbyLocationSize = 0;
    if (m_pStandbyLocation != NULL)
    {
        OS_MemFree(m_pStandbyLocation);
        m_pStandbyLocation = NULL;
    }

    /* Uninit USR API */
    UsrUninitialize();

    /* kill all worker threads meta nav has created and wait for them to die */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- DeleteTasks\n"));
    DeleteTasks();

    /* delete message queues */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- DeleteQueues\n"));
    DeleteQueues();

    /* delete disc info class */
    if (NULL != m_pDiskInfo)
    {
        DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- delete disc info class\n"));
        delete m_pDiskInfo;
    }

    /* delete the DR */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- DRDelete\n"));
    if (m_DR != NULL)
    {
        DRDelete(m_DR);
        m_DR = NULL;
    }

    /* delete the PE */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- PEDelete\n"));
    if (NULL != m_PE)
    {
        PEDelete(m_PE);
        m_PE = NULL;
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- DeleteStreams\n"));
    if (DeleteStreams() != METANAV_SUCCESS)
    {
        DBGPRINT(1, ("NavConfigDeleteStreams Error\n"));
    }

    /* delete the loader */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::~cMetaNav() -- LoaderDestroy\n"));
    if (NULL != m_Loader)
    {
        LoaderStop(m_Loader);
        LoaderDestroy(m_Loader);
        m_Loader = NULL;
    }

	/* delete the stop nav semaphore */
	if (0 != m_semStopNav)
	{
		OS_SemDelete(m_semStopNav);
		m_semStopNav = 0;
	}

#ifdef __CALC_PEAK_ALLOCATION
    DbgPrint(("OS_MemAlloc peak allocations = %d\n", ulPeakAllocations));
#endif
}

/**
 * Creates other modules used by the meta navigator.
 * This is done here instead of in the class constructor so that we can return status.
 *
 * @param
 *      pConfigSettings - pointer to VDVD_USER_CONFIG settings
 *
 * @return
 *      METANAV_SUCCESS if successful
 *      METANAV_FAILURE if unsuccessful
 */
METANAV_STATUS cMetaNav::Initialize(const VDVD_USER_CONFIG *pConfigSettings)
{
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize() -- ENTER\n"));

    if (pConfigSettings == NULL)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() -- Config Settings pointer is NULL!\n"));
        goto error_out;
    }

    /* Set the configuration settings struct pointer */
    m_pConfigSettings = pConfigSettings;

    /* Make sure a global payload manager has been created */
    if (NULL == globalPayloadManager)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() -- PAYLOAD MANAGER MUST BE CREATED FIRST!\n"));
        goto error_out;
    }

    /* create the loader for disc access */
    m_Loader = LoaderCreate((LOADER_BUS_TYPE)0, 0);
    if (NULL == m_Loader)
    {
       DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE LOADER\n"));
       goto error_out;
    }

    /* create and initialize all of our cStreams */
    if (CreateStreams() != METANAV_SUCCESS)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE STREAMS\n"));
        goto error_out;
    }

    /* Create the PE and get the interface pointers */
    PECreate(&m_PE);
    if (NULL == m_PE)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE PE\n"));
        goto error_out;
    }

    /* Configure aspect ratio */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize() -- UpdateTvType\n"));
    UpdateTvType();

    /* Configure video format */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize() -- UpdateVideoFormat\n"));
    UpdateVideoFormat();

    /* Configure spdif setting */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize() -- UpdateSPDIF\n"));
    UpdateSPDIF();

    /* Clear video ouput, since starting off in standby */
    PEiConfigureSetVideoMute(m_PE, VIDEO_MUTE_BLACK_SCREEN);

    /* Create the DR */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize() -- DRCreate\n"));
    DRCreate(&m_DR);
    if (NULL == m_DR)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE DR\n"));
        goto error_out;
    }

    /* Attach the loader to the DR */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::Initialize: Init the DR\n"));
    if (DR_SUCCESS != DRAttachLoader(m_DR, m_Loader))
    {
        DbgPrint(("Could not attach loader to DR\n"));
        goto error_out;
    }

    /* create the disk info class */
    m_pDiskInfo = new cDiskInfo;
    if (NULL == m_pDiskInfo)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE cDiskInfo\n"));
        goto error_out;
    }

    /*
     * Create and initialize our message queues
     */
    if (CreateQueues() != METANAV_SUCCESS)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE QUEUES\n"));
        goto error_out;
    }

    /*
     * Spawn Tasks
     */
    if (CreateTasks() != METANAV_SUCCESS)
    {
        DBGPRINT(1, ("cMetaNav::Initialize() --  COULD NOT CREATE TASKS\n"));
        goto error_out;
    }

    /* Initialize the USRAPI */
    if (UsrInitialize() != USR_SUCCESS)
    {
        DbgPrint( ("cMetaNav::Initialize() -- Could not initialize USRAPI\n") );
        goto error_out;
    }

    /*
     * If Resume on standby mode is on, then allocate a location handle that
     * is large enough to be used for any of the media types.
     */
    if (m_fResumeOnStandbyMode == TRUE)
    {
        ULONG ulSize[3];

        /*
         * Get sizes of location handles of media types that support location storing.
         */
        ulSize[0] = GetLocationHandleSize(MEDIA_FORMAT_DVD_V);
        ulSize[1] = GetLocationHandleSize(MEDIA_FORMAT_BDROM);
        ulSize[2] = GetLocationHandleSize(MEDIA_FORMAT_VCD);

        /* Calculate maximum handle size */
        m_ulStandbyLocationSize = MAX( (MAX(ulSize[0], ulSize[1]) ), ulSize[2]);

        /* Create universal location handle */
        m_pStandbyLocation = OS_MemAlloc(m_ulStandbyLocationSize);
        if (m_pStandbyLocation == NULL)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("cMetaNav::Initialize -- failed to create location handle\n"));
            goto error_out;
        }
    }

	/* Create the stop nav semaphore */
	if (0 == m_semStopNav)
	{
		/* Stop nav semaphore has not yet been created */
		m_semStopNav = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
		if (0 == m_semStopNav)
		{
			DBGPRINT(DBG_ON(DBG_ERROR), ("cMetaNav::Initialize -- failed to create stop nav semaphore\n"));
			goto error_out;
		}
	}
	else
	{
		/* Stop nav semaphore has already been created */
		DBGPRINT(DBG_ON(DBG_ERROR), ("cMetaNav::Initialize -- stop nav semaphore already exists!\n"));
	}

    return (METANAV_SUCCESS);

error_out:

	/* Delete the stop nav semaphore */
	if (0 != m_semStopNav)
	{
		OS_SemDelete(m_semStopNav);
		m_semStopNav = 0;
	}

    /* Delete location handle */
    m_ulStandbyLocationSize = 0;
    if (m_pStandbyLocation != NULL)
    {
        OS_MemFree(m_pStandbyLocation);
        m_pStandbyLocation = NULL;
    }

    /* Uninit USR API */
    UsrUninitialize();

    /* kill all worker threads meta nav has created and wait for them to die */
    DeleteTasks();

    /* delete message queues */
    DeleteQueues();

    if (NULL != m_pDiskInfo)
    {
        delete m_pDiskInfo;
        m_pDiskInfo = NULL;
    }

    /* delete the DR */
    if (NULL != m_DR)
    {
        DRDelete(m_DR);
        m_DR = NULL;
    }

    /* delete the PE */
    if (NULL != m_PE)
    {
        PEDelete(m_PE);
        m_PE = NULL;
    }

    if (DeleteStreams() != METANAV_SUCCESS)
    {
        DBGPRINT(1, ("cMetaNav::Initialize -- DeleteStreams Error\n"));
    }

    if (NULL != m_Loader)
    {
        LoaderStop(m_Loader);
        LoaderDestroy(m_Loader);
        m_Loader = NULL;
    }

    return (METANAV_FAILURE);
}

/**
 * Scans the disc for available media formats. If AutoPlay is requested then it also starts the
 * appropriate media specific navigator to play one of the available media formats.
 *
 * @param fAutoPlay - Flag to enable/disable AutoPlay.
 *
 * @return
 *      METANAV_SUCCESS if successful
 *      METANAV_FAILURE if unsuccessful
 */
METANAV_STATUS cMetaNav::FindMediaFormats(BOOLEAN fAutoPlay)
{
    MESSAGE *pMessage = NULL;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::FindMediaFormats() -- ENTER, fAutoPlay=%d\n", fAutoPlay));

    /*
     * If we are in standby mode, then we don't want to do anything...
     * This should occur only on startup.
     */
#ifdef STANDBY_SUPPORT
    if (m_fStandbyMode)
    {
        DBGPRINT(DBG_ON(DBG_TRACE), ("cMetaNav::FindMediaFormats() -- STANDBY\n"));
        return (METANAV_SUCCESS);
    }
#endif

⌨️ 快捷键说明

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