📄 playctrl.cpp
字号:
/*****************************************************************************
******************************************************************************
** **
** 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 playctrl.cpp
*
* Public API to the Playback Control Engine.
* The Playback Control Engine provides playlist playback capability,
* AV presentation control, Interactive Graphics control, and Player
* Register access.
*
* $Id: playctrl.cpp,v 1.79 2007/01/26 22:24:54 rbehe Exp $
*/
#include "vdvd_types.h"
#include "playctrl.h"
#include "pbc_types.h"
#include "pbc_engine.h"
#include "pbc_register.h"
#include "pbc_plcontrol.h"
#include "../mvplaylistdb.h"
#include "dr_app.h"
#include "pe_app.h"
#include "utility.h"
#include "dbgprint.h"
#include "clpinfodb.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* Debug macros */
#define DBG_PLAYCTRL DBG_ERROR
#define DBG_ON(x) (DBG_PLAYCTRL >= x)
/**
* Local variables
*/
static PBC_HANDLE *hPBC = NULL;
/**
* PlayCtrlCreate -- Create and Initialize the playback control engine.
*
* @param
* hDR -- handle to the DR
* hPE -- handle to the PE
* pCallback -- callback to receive playback control events
* pvContext -- callback context
*
* @retval
* PLAYCTRL_STATUS
*/
PLAYCTRL_STATUS PlayCtrlCreate(DR_HANDLE hDR, PE_HANDLE hPE, PLAYCTRL_CALLBACK pCallback, PVOID pvContext)
{
if (hPBC != NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: playback control engine already created!\n"));
return (PLAYCTRL_FAILURE);
}
/* Allocate private handle for playback control engine */
hPBC = (PBC_HANDLE *)OS_MemAlloc(sizeof(PBC_HANDLE) );
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: failed to create handle!\n"));
goto errout;
}
/* Initialize pbc data */
memset( hPBC, 0, sizeof(PBC_HANDLE) );
/* Set DR and PE handles */
hPBC->hDR = hDR;
hPBC->hPE = hPE;
/* Initialize playitem information */
hPBC->newpi.abort = FALSE;
hPBC->newpi.fReverse = FALSE;
hPBC->newpi.playitemID = INVALID_PLAYITEM;
hPBC->newpi.marker_pts = 0;
hPBC->newpi.doneState = PBC_DECDONE_STATE_INACTIVE;
/* Set callback information */
hPBC->pCallback = pCallback;
hPBC->pvCallbackContext = pvContext;
/* Create synchronization semaphore */
hPBC->semSynch = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (hPBC->semSynch == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: Failure creating synchronization semaphore!\n"));
goto errout;
}
/* Create mutual exclusion semaphore for player register access */
hPBC->semRegisterMutex = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (hPBC->semRegisterMutex == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: Failure creating register mutex semaphore!\n"));
goto errout;
}
/* Create mutual exclusion semaphore for clip info access */
hPBC->semClipInfo = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (hPBC->semClipInfo == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: Failure creating clipinfo mutex semaphore!\n"));
goto errout;
}
/* Create interface to clip info database */
hPBC->hClipInfo = new ClpInfo;
if (hPBC->hClipInfo == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: Failure creating clip info class!\n"));
goto errout;
}
/* Initialize player registers */
PbcRegInitialize();
/*
* Create the playback control engine core module, which contains
* the playback control engine task.
*/
if (PbcEngineCreate(hPBC) != PLAYCTRL_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlCreate: Failure creating pbc engine core module!\n"));
goto errout;
}
return (PLAYCTRL_SUCCESS);
errout:
PlayCtrlDelete();
return (PLAYCTRL_FAILURE);
}
/**
* PlayCtrlDelete -- Delete the playback control engine.
*
* @param
* none
*
* @retval
* PLAYCTRL_STATUS
*/
PLAYCTRL_STATUS PlayCtrlDelete(void)
{
if (hPBC != NULL)
{
/* Delete playback control engine core module */
PbcEngineDelete(hPBC);
/*
* If playlist playback is active...
* 1. Stop playback
* 2. flush the input queue to remove any PE/DR events
*/
if (hPBC->tState != PLAYCTRL_STATE_STOP)
{
/* Stop Playback */
DRStop(hPBC->hDR);
PEiStreamCtrlStop(hPBC->hPE, FALSE);
}
hPBC->tState = PLAYCTRL_STATE_STOP;
/* Unload any loaded clip info */
ClpInfoMgrUnload();
/* Delete interface to clip info database */
if (hPBC->hClipInfo != NULL)
{
delete hPBC->hClipInfo;
}
/* Delete mutual exclusion semaphore */
if (hPBC->semClipInfo != 0)
{
OS_SemDelete(hPBC->semClipInfo);
hPBC->semClipInfo = 0;
}
/* Delete mutual exclusion semaphore */
if (hPBC->semRegisterMutex != 0)
{
OS_SemDelete(hPBC->semRegisterMutex);
hPBC->semRegisterMutex = 0;
}
/* Delete synchronization semaphore */
if (hPBC->semSynch != 0)
{
OS_SemDelete(hPBC->semSynch);
hPBC->semSynch = 0;
}
/* Delete handle */
OS_MemFree(hPBC);
hPBC = NULL;
}
else
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlDelete: playback control engine not created!\n"));
return (PLAYCTRL_FAILURE);
}
return (PLAYCTRL_SUCCESS);
}
/**
* PlayCtrlGetState -- Get state of playback control engine.
*
* @param
* none
*
* @retval
* PLAYCTRL_STATE
*/
PLAYCTRL_STATE PlayCtrlGetState(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetState: playback control engine not created!\n"));
return (PLAYCTRL_STATE_STOP);
}
else
{
return (hPBC->tState);
}
}
/**
* PlayCtrlIsPopupOn -- Return the Popup Menu On/Off State.
*
* @param
* None
*
* @retval
* FALSE - Pop up is OFF
* TRUE - Pop up is ON
*/
BOOLEAN PlayCtrlIsPopupOn(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlIsPopupOn: playback control engine not created!\n"));
return (FALSE);
}
/* check the playback control engines state */
if (hPBC->tState == PLAYCTRL_STATE_STOP)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlIsPopupOn: PLAYCTRL_STATE_STOP!\n"));
return (FALSE);
}
return ( PEiStreamCtrlIsPopupOn(hPBC->hPE) );
}
/**
* PlayCtrlIsButtonSelected - Check if there is an IG button currently selected.
*
* @param
* None
*
* @retval
* FALSE - No button in the selected state.
* TRUE - A button is in the selected state.
*/
BOOLEAN PlayCtrlIsButtonSelected(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlIsButtonSelected: playback control engine not created!\n"));
return (FALSE);
}
/* check the playback control engines state */
if (hPBC->tState == PLAYCTRL_STATE_STOP)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlIsButtonSelected: PLAYCTRL_STATE_STOP!\n"));
return (FALSE);
}
return ( PEiStreamCtrlIsButtonSelected(hPBC->hPE) );
}
/**
* PlayCtrlGetRepeatMode -- Return the repeat mode.
*
* @param
* None
*
* @retval
* VDVD_INFO_REPEAT repeat mode - should be chapter/a-b/off
*/
uint8 PlayCtrlGetRepeatMode(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetRepeatMode: playback control engine not created!\n"));
return (FALSE);
}
return (hPBC->RepeatBlock.repeat_mode);
}
/**
* PlayCtrlIsStillOn -- Check if still is on or off.
*
* @param
* none
*
* @retval
* If still is on, return TRUE
*/
BOOLEAN PlayCtrlIsStillOn(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlIsStillOn: playback control engine not created!\n"));
return (FALSE);
}
else
{
return (hPBC->ulStillTime != 0);
}
}
/**
* PlayCtrlGetPlayRate -- Get the playback rate.
*
* @param
* none
*
* @retval
* Play speed (1000 is normal play speed; negative value indicates reverse)
*/
int32 PlayCtrlGetPlayRate(void)
{
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetPlayRate: playback control engine not created!\n"));
return (0);
}
else
{
/* If playback is playing, return playrate in positive or negative direction*/
if (hPBC->tState == PLAYCTRL_STATE_PLAY)
{
return ((int32)hPBC->ulPlayRate * (hPBC->fReverse ? -1 : 1));
}
else
{
return (0);
}
}
}
/**
* PlayCtrlGetPlayTime -- Get the current time.
*
* @param
* none
*
* @retval
* current time into the playitem (in units of 45khz clock)
*/
uint32 PlayCtrlGetPlayTime(void)
{
PLAYITEM *pPlayitem = NULL;
uint32 uiPlayitemId;
uint32 uiTime;
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetPlayTime: playback control engine not created!\n"));
return (0);
}
/* Get current playitem register value */
PbcRegGetPSR(PLAYCTRL_PSR_PLAYITEM, &uiPlayitemId);
/* Pull out playitem id from register value */
uiPlayitemId &= 0x0000ffff;
/* Get the playitem info */
if (MPLSGetPlayItem( (uint16)(uiPlayitemId), &pPlayitem) != MPLS_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetPlayTime: Failed to get playitem info\n"));
uiTime = 0;
goto errout;
}
uiTime = (PlayCtrlGetRawPTS() - pPlayitem->IN_time);
errout:
return (uiTime);
}
/**
* PlayCtrlGetRawPTS -- Get the current time.
*
* @param
* none
*
* @retval
* current raw pts (in 45kHz clock time)
*/
uint32 PlayCtrlGetRawPTS(void)
{
uint32 uiTime;
if (hPBC == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PlayCtrlGetPlayTime: playback control engine not created!\n"));
return (0);
}
/* Get current time register value */
PbcRegGetPSR(PLAYCTRL_PSR_PRES_TIME, &uiTime);
return (uiTime);
}
/**
* PlayCtrlGetNumberOfPlayItems -- Get the number playitems in the current playlist.
*
* @param
* None
*
* @retval
* The number playitems in the current playlist.
*/
uint16 PlayCtrlGetNumberOfPlayItems(void)
{
uint16 uiNumPlayItems;
if (hPBC == NULL)
{
DbgPrint(("PlayCtrlGetNumberOfPlayItems: playback control engine not created!\n"));
return (0);
}
/* Get number of playitems */
if (MPLSGetNumberOfPlayItems(&uiNumPlayItems) != MPLS_SUCCESS)
{
DbgPrint(("PlayCtrlGetNumberOfPlayItems: Failed to get number of playitems!\n"));
uiNumPlayItems = 0;
}
return (uiNumPlayItems);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -