📄 textst_api.cpp
字号:
/* Delete sempahores */
if (0 != TextSTInfo->semBOB)
{
/* Delete semaphore */
OS_SemDelete(TextSTInfo->semBOB);
TextSTInfo->semBOB = 0;
}
if (0 != TextSTInfo->semDCB)
{
/* Delete semaphore */
OS_SemDelete(TextSTInfo->semDCB);
TextSTInfo->semDCB = 0;
}
if (0 != TextSTInfo->semDB)
{
/* Delete semaphore */
OS_SemDelete(TextSTInfo->semDB);
TextSTInfo->semDB = 0;
}
/* Delete memory pools */
if (TextSTInfo->mempoolBOB != NULL)
{
OS_DeleteMemPool(TextSTInfo->mempoolBOB);
}
if (TextSTInfo->mempoolDCB != NULL)
{
OS_DeleteMemPool(TextSTInfo->mempoolDCB);
}
if (TextSTInfo->mempoolDB != NULL)
{
OS_DeleteMemPool(TextSTInfo->mempoolDB);
}
/* Delete DFB Clear Palette */
if (TextSTInfo->DFBInfo.dfb_clear_palette != NULL)
{
TextSTInfo->DFBInfo.dfb_clear_palette->Release(TextSTInfo->DFBInfo.dfb_clear_palette);
TextSTInfo->DFBInfo.dfb_clear_palette = NULL;
}
/* Delete DFB Palette */
if (TextSTInfo->DFBInfo.dfb_palette != NULL)
{
TextSTInfo->DFBInfo.dfb_palette->Release(TextSTInfo->DFBInfo.dfb_palette);
TextSTInfo->DFBInfo.dfb_palette = NULL;
}
/* release dfb surface */
if (TextSTInfo->DFBInfo.PrimarySurface != NULL)
{
TextSTInfo->DFBInfo.PrimarySurface->Release(TextSTInfo->DFBInfo.PrimarySurface);
}
/* unload font buffers */
TextSTUnloadFonts(handle);
/* Delete handle */
OS_MemFree(TextSTInfo);
TextSTInfo = NULL;
}
else
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTDelete: TextST Module not created!\n"));
return (TEXTST_NOT_INITIALIZED);
}
return (TEXTST_SUCCESS);
}
/**
* TextSTGetState -- Return the state of the TextST Module.
*
* @param
* none
*
* @retval
* TEXTST_STATE
*/
TEXTST_STATE TextSTGetState(TEXTST_HANDLE handle)
{
TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTGetState: ENTER\n"));
if (TextSTInfo != NULL)
{
return (TextSTInfo->tState);
}
else
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTGetState: TextST Module not initialized!\n"));
return (TEXTST_STATE_INVALID);
}
}
/**
* TextSTAddData -- If the text Subtitle module has been initialized, add text
* subtitle data to the Subtitle Preloading Buffer.
*
* @param
* handle -- textst handle
* pvBuffer -- pointer to buffer containing data
* ulSize -- size of buffer
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTAddData(TEXTST_HANDLE handle, PVOID pvBuffer, ULONG ulSize)
{
TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;
UBYTE *ubData = (UBYTE *)pvBuffer;
ULONG ulByteOffset;
ULONG ulPktLength;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTAddData: ENTER\n"));
if (TextSTInfo == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTAddData: TextST Module not initialized!\n"));
return (TEXTST_NOT_INITIALIZED);
}
if (TextSTInfo->tState != TEXTST_STATE_STOPPED)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTAddData: Must be in stop state!\n"));
return (TEXTST_INVALID_STATE);
}
if (pvBuffer == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTAddData: Null pointer!\n"));
return (TEXTST_NULL_PTR);
}
if (TextSTInfo->SPBInfo.ulPktBytesLeft != 0)
{
if (ulSize <= TextSTInfo->SPBInfo.ulPktBytesLeft)
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], pvBuffer, ulSize);
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += ulSize;
/* Set number of bytes left in pes packet */
TextSTInfo->SPBInfo.ulPktBytesLeft -= ulSize;
}
else
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], pvBuffer, TextSTInfo->SPBInfo.ulPktBytesLeft);
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += TextSTInfo->SPBInfo.ulPktBytesLeft;
/* Set offset into data buffer */
ulByteOffset = TextSTInfo->SPBInfo.ulPktBytesLeft;
/* Reset number of bytes left in packet */
TextSTInfo->SPBInfo.ulPktBytesLeft = 0;
/* Search for next PES header in the remaining data */
while (ulByteOffset < ulSize)
{
if ( ( (ulSize - ulByteOffset) >= 6) && (PRIVATE_STREAM_2_START_CODE == MAKE_DWORD(&ubData[ulByteOffset]) ) )
{
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTAddData: Found start of new packet in trailing data!\n"));
/* Get the packet length */
ulPktLength = MAKE_WORD(&ubData[ulByteOffset + 4]);
if ( (ulPktLength + 6) < (ulSize - ulByteOffset) )
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], &ubData[ulByteOffset], (ulPktLength + 6) );
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += (ulPktLength + 6);
/* Adjust offset into data buffer */
ulByteOffset += (ulPktLength + 6);
/* Reset number of bytes left in packet */
TextSTInfo->SPBInfo.ulPktBytesLeft = 0;
/* Search for start of another packet in the buffer */
continue;
}
else
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], &ubData[ulByteOffset], (ulSize - ulByteOffset) );
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += (ulSize - ulByteOffset);
/* Set number of bytes left in packet */
TextSTInfo->SPBInfo.ulPktBytesLeft = ulPktLength - (ulSize - (ulByteOffset + 6) );
/* Reached end of buffer */
break;
}
}
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTAddData: Throwing away data!\n"));
ulByteOffset++;
}
}
}
else
{
ulByteOffset = 0;
/* Search for next PES header in the data */
while (ulByteOffset < ulSize)
{
if ( ( (ulSize - ulByteOffset) >= 6) && (PRIVATE_STREAM_2_START_CODE == MAKE_DWORD(&ubData[ulByteOffset]) ) )
{
/* Get the packet length */
ulPktLength = MAKE_WORD(&ubData[ulByteOffset + 4]);
if ( (ulPktLength + 6) < (ulSize - ulByteOffset) )
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], &ubData[ulByteOffset], (ulPktLength + 6) );
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += (ulPktLength + 6);
/* Adjust offset into data buffer */
ulByteOffset += (ulPktLength + 6);
/* Reset number of bytes left in packet */
TextSTInfo->SPBInfo.ulPktBytesLeft = 0;
/* Search for start of another packet in the buffer */
continue;
}
else
{
/* Copy data to subtitle preloading buffer */
memcpy(&TextST_SPB[TextSTInfo->SPBInfo.ulSPBDataSize], &ubData[ulByteOffset], (ulSize - ulByteOffset) );
/* Calculate size of data in the SPB */
TextSTInfo->SPBInfo.ulSPBDataSize += (ulSize - ulByteOffset);
/* Set number of bytes left in packet */
TextSTInfo->SPBInfo.ulPktBytesLeft = ulPktLength - (ulSize - (ulByteOffset + 6) );
/* Reached end of buffer */
break;
}
}
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTAddData: Throwing away data!\n"));
ulByteOffset++;
}
}
return (TEXTST_SUCCESS);
}
/**
* TextSTLoad -- If the Text Subtitle module has been initialized, and there is
* data in the preload buffer, then load the data from the preload
* buffer.
*
* @param
* handle -- TextST Module Handle
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTLoad(TEXTST_HANDLE handle)
{
TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTLoad: ENTER\n"));
if (TextSTInfo == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoad: TextST Module not initialized!\n"));
return (TEXTST_NOT_INITIALIZED);
}
if ( (TextSTInfo->tState != TEXTST_STATE_STOPPED) || (TextSTInfo->SPBInfo.ulSPBDataSize == 0) )
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoad: Invalid state!\n"));
return (TEXTST_INVALID_STATE);
}
/* If the DSS is not loaded, then load it. */
if (TextSTInfo->fDSSLoaded == FALSE)
{
/* Load the Dialog Style Segment. Use DCB memory. */
if (textstLoadDSS(TextSTInfo) != TEXTST_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoad: Failed to load the DSS!\n"));
goto errout;
}
/* Set flag to indicate the DSS is loaded */
TextSTInfo->fDSSLoaded = TRUE;
}
/* Load the directfb palette with default palette from DSS */
if (TextSTPresCtrlLoadPalette(&TextSTInfo->pDSS->palette, TextSTInfo->DFBInfo.dfb_palette) != TEXTST_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoad: Failed to load palette!\n"));
goto errout;
}
/* Set number of DPS's */
TextSTInfo->usNumberOfDPS = MAKE_WORD(&TextST_SPB[TextSTInfo->pDSS->segment_descriptor.segment_length + 6 + 3]);
return (TEXTST_SUCCESS);
errout:
return (TEXTST_FAILURE);
}
/**
* TextSTFlush -- If the Text Subtitle module has been initialized, flush the
* Subtitle Preloading Buffer.
*
* @param
* none
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTFlush(TEXTST_HANDLE handle)
{
TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTFlush: ENTER\n"));
if (TextSTInfo == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTFlush: TextST Module not initialized!\n"));
return (TEXTST_NOT_INITIALIZED);
}
if (TextSTInfo->tState != TEXTST_STATE_STOPPED)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTFlush: Must be in stop state!\n"));
return (TEXTST_INVALID_STATE);
}
/* clear data in subtitle preloading buffer */
memset(TextST_SPB, 0x00, TextSTInfo->SPBInfo.ulSPBDataSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -