📄 dr_app.cpp
字号:
/******************************************************************************
*******************************************************************************
** **
** 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 dr_app.cpp
*
* DR Application source file.
*
* $Id: dr_app.cpp,v 1.166 2007/01/26 20:50:22 rbehe Exp $
*/
#include "vdvd_types.h"
#include "osapi.h"
#include "utility.h"
#include "css.h"
#include "loader_app.h"
#include "dr_types.h"
#include "dr_prefetch.h"
#include "dr_prefetch_dvd.h"
#include "dr_prefetch_vcd.h"
#include "dr_prefetch_cdda.h"
#ifdef BDROM_ENABLE
#include "dr_prefetch_bdrom.h"
#endif
#ifdef HDDVD_ENABLE
#include "dr_prefetch_hddvd_std.h"
#include "dr_prefetch_hddvd_adv.h"
#endif
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define AACS_CCC_SZ 100
#define DEBUG_DR_APP DBG_ERROR
#define DBG_ON(x) (DEBUG_DR_APP >= x)
/******************************************************************************
*******************************************************************************
** **
** Private variables **
** **
*******************************************************************************
******************************************************************************/
//jared - aacs (begin) - (ISSUE #1) Samsung HD DVD drive does not retrieve the correct copyright type from the inserted media
/*
* HACK ALERT
*
* This variable is a temporary solution for the issue in which
* drGetCopyrightType() does not work correctly for HD DVD. As soon as this
* function works correctly, this temporary solution must be removed.
*/
BYTE bHDDVDEncryptionType = LOADER_COPYRIGHT_TYPE_NONE;
//jared - aacs (end)
typedef struct tagDRHANDLE
{
DR_STATE State;
OS_SEM_ID semDRMutex; /**< a semaphore to require synchronous calls */
LOADER_HANDLE tLoaderDev;
ENCRYPTION_TYPE EncryptionType;
DR_EVENT eventCallback;
PVOID eventContext;
DRPrefetch *prefetch[BDROM_NUM_MAX_PREFETCH];
} DRHANDLE;
/******************************************************************************
*******************************************************************************
** **
** Private Function Prototypes **
** **
*******************************************************************************
******************************************************************************/
static DR_ERROR drGetCopyrightType(DRHANDLE *dr, BYTE *type);
static DR_ERROR drIdentifyDiscType(DRHANDLE *dr, DR_DISK_TYPE drType);
static DRPrefetch *drNewPrefetchForState(DR_STATE &state);
static DR_ERROR drEventPasser(PVOID context, DR_EVENT_CODE event, PVOID pvEventInfo);
static DR_ERROR drIsBdDiscAacs(DRHANDLE *dr, BYTE *bAacs);
/******************************************************************************
*******************************************************************************
** **
** Public Functions **
** **
*******************************************************************************
******************************************************************************/
/**
* Initializes the DR and creates all of the internal objects.
*
* @param handle - Operating system handle for the DR object.
*/
DR_ERROR DRCreate(DR_HANDLE *handle)
{
DRHANDLE *dr;
/* validate input */
if (handle == NULL)
{
return (DR_FAILURE);
}
/* allocate DR_HANDLE */
dr = (DRHANDLE*)OS_MemAlloc(sizeof(DRHANDLE));
if (dr == NULL)
{
*handle = NULL;
return (DR_FAILURE);
}
/* set state */
dr->State = DR_STATE_UNREALIZED;
dr->EncryptionType = NONE;
dr->tLoaderDev = NULL;
dr->eventCallback = NULL;
for (int i=0; i<BDROM_NUM_MAX_PREFETCH; i++)
{
dr->prefetch[i] = NULL;
}
dr->semDRMutex = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (dr->semDRMutex == 0)
{
DBGPRINT(DEBUG_DR_APP, ("DRCreate: Unable to create DR mutex semaphore!\n"));
goto error_out;
}
/* return the handle */
*handle = (DR_HANDLE)dr;
/* return success */
return (DR_SUCCESS);
error_out:
if (dr->semDRMutex != 0)
{
OS_SemDelete(dr->semDRMutex);
dr->semDRMutex = 0;
}
OS_MemFree(dr);
*handle = NULL;
return (DR_FAILURE);
} /* DRCreate() */
/**
* Destroys the DR object along with the objects that DRCreate() created.
*
* @param handle - Operating system handle for the DR object.
*/
DR_ERROR DRDelete(DR_HANDLE handle)
{
DRHANDLE *dr = (DRHANDLE*)handle;
/* validate input */
if (handle == NULL)
{
return (DR_FAILURE);
}
if (dr->semDRMutex != 0)
{
OS_SemDelete(dr->semDRMutex);
dr->semDRMutex = 0;
}
/* free the dr handle */
OS_MemFree(handle);
/* return success */
return (DR_SUCCESS);
} /* DRDelete() */
/**
* Attaches the loader to the DR object.
*
* @param handle - Operating system handle for the DR object.
* @param loader - The loader of type LOADER_HANDLE attached to the DR.
*/
DR_ERROR DRAttachLoader(DR_HANDLE handle, LOADER_HANDLE loader)
{
DRHANDLE *dr = (DRHANDLE*)handle;
DR_ERROR status = DR_SUCCESS;
/* validate our input */
if (NULL == handle)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_HANDLE\n", __FUNCTION__));
return(DR_FAILURE);
}
if (NULL == loader)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL LOADER_HANDLE\n", __FUNCTION__));
return(DR_FAILURE);
}
OS_SemTake(dr->semDRMutex, OS_WAIT_FOREVER);
DBGPRINT(DBG_ON(DBG_TRACE), ("%s\n", __FUNCTION__));
/* check state */
if (dr->State != DR_STATE_UNREALIZED)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("%s: attach loader: Invalid State\n", __FUNCTION__));
status = DR_INVALID_STATE;
goto errout;
}
/* make sure loader isn't already attached */
if (dr->tLoaderDev != NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Loader already attached\n", __FUNCTION__));
status = DR_ALREADY_ATTACHED;
goto errout;
}
/* it's all good. attach loader and update state */
if (status == DR_SUCCESS)
{
dr->tLoaderDev = loader;
dr->State = DR_STATE_DISCID;
DBGPRINT(DBG_ON(DBG_TRACE), ("dr->State: DR_STATE_DISCID\n"));
}
errout:
OS_SemGive(dr->semDRMutex);
/* Return status */
return (status);
} /* end DRAttachLoader() */
/**
* Attaches the event handler to the DR object.
*
* @param handle - Operating system handle for the DR object.
* @param event - The event callback the DR should notify of events.
* @param context - The context that goes along with the event.
*/
DR_ERROR DRAttachEvent(DR_HANDLE handle, DR_EVENT event, PVOID context)
{
DRHANDLE *dr = (DRHANDLE*)handle;
DR_ERROR status = DR_SUCCESS;
/* validate our input */
if (NULL == handle)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_HANDLE\n", __FUNCTION__));
return(DR_FAILURE);
}
if (NULL == event)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_EVENT\n", __FUNCTION__));
return(DR_FAILURE);
}
OS_SemTake(dr->semDRMutex, OS_WAIT_FOREVER);
DBGPRINT(DBG_ON(DBG_TRACE), ("%s\n", __FUNCTION__));
/* happens regardless of state */
/* allowed to attach, even if already attached (replaces old one) */
dr->eventCallback = event;
dr->eventContext = context;
/* If the command failed, signal the command error event */
if (DR_SUCCESS != status)
{
if (dr->eventCallback != NULL)
{
dr->eventCallback(dr->eventContext, DR_EVENT_COMMAND_ERROR, (PVOID)DR_ATTACH_EVENT);
}
}
OS_SemGive(dr->semDRMutex);
/* Return status */
return (status);
} /* DRAttachEvent() */
/**
* Detaches the event handler from the DR object.
*
* @param handle - Operating system handle for the DR object.
*/
DR_ERROR DRDetachEvent(DR_HANDLE handle)
{
DRHANDLE *dr = (DRHANDLE*)handle;
/* validate our input */
if (NULL == handle)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_HANDLE\n", __FUNCTION__));
return(DR_FAILURE);
}
OS_SemTake(dr->semDRMutex, OS_WAIT_FOREVER);
/* clear event callback pointer */
dr->eventCallback = NULL;
OS_SemGive(dr->semDRMutex);
return (DR_SUCCESS);
}
/**
* Tell the DR what kind of disk it is.
*
* @param handle - Handle for the DR object.
* @param disktype - Identifier for the type of data on the disk.
*/
DR_ERROR DRIdentifyType(DR_HANDLE handle, DR_DISK_TYPE diskType)
{
DRHANDLE *dr = (DRHANDLE*)handle;
DR_ERROR status = DR_SUCCESS;
/* validate our input */
if (NULL == handle)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_HANDLE\n", __FUNCTION__));
return(DR_FAILURE);
}
OS_SemTake(dr->semDRMutex, OS_WAIT_FOREVER);
DBGPRINT(DBG_ON(DBG_TRACE), ("%s\n", __FUNCTION__));
/* check state */
if ( dr->State != DR_STATE_DISCID )
{
DBGPRINT(DBG_ON(DBG_ERROR), ("%s: DR_IDENTIFY_TYPE: could not complete. Invalid State\n", __FUNCTION__));
status = DR_INVALID_STATE;
}
/* it's all good, identify disk type (which updates state) */
if (status == DR_SUCCESS)
{
if (drIdentifyDiscType(dr, diskType) != DR_SUCCESS)
{
DbgPrint(("Error in drIdentifyDiscType\n"));
status = DR_FAILURE;
}
/* if successful return, state is now one of the Attach_Stream states */
DBGPRINT(DBG_ON(DBG_TRACE), ("dr->State: %x\n", dr->State));
}
/* If the command failed, signal the command error event */
if (DR_SUCCESS != status)
{
if (dr->eventCallback != NULL)
{
dr->eventCallback(dr->eventContext, DR_EVENT_COMMAND_ERROR, (PVOID)DR_IDENTIFY_TYPE);
}
}
OS_SemGive(dr->semDRMutex);
/* Return status */
return (status);
} /* end DRIdentifyType() */
/**
* Attaches a stream to the DR object.
*
* @param handle - Operating system handle for the DR object.
* @param stream_handle - The handle of the stream component attached to the DR.
* @param streamType - The DR stream to attach.
*/
DR_ERROR DRAttachStream(DR_HANDLE handle, STREAM_HANDLE stream_handle, DR_STREAM streamType)
{
DRHANDLE *dr = (DRHANDLE*)handle;
UBYTE ubStreamIndex;
DR_ERROR status = DR_SUCCESS;
/* validate our input */
if (NULL == handle)
{
DBGPRINT(DEBUG_DR_APP, ("%s: NULL DR_HANDLE\n", __FUNCTION__));
return(DR_INVALID_PARAM);
}
if (NULL == stream_handle)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -