📄 textst_api.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 textst_api.cpp
*
* $Revision: 1.7 $
*
* Public API to the TextST Module.
* The TextST Module is responsible for decoding text subtitle
* streams and rendering text subtitles.
*
*/
#include <directfb.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include "vdvd_types.h"
#include "textst_decoder.h"
#include "textst_render.h"
#include "textst_presctrl.h"
#include "textst_types.h"
#include "osapi.h"
#include "utility.h"
#include "dbgprint.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* Debug macros */
#define DBG_TEXTST DBG_ERROR
#define DBG_ON(x) (DBG_TEXTST >= x)
#define USING_OLDER_VERSION 0
/**
* Local variables
*/
static BYTE TextST_SPB[TEXTST_SPB_SIZE]; // Subtitle Preloading Buffer
static BYTE TextST_DB[TEXTST_DB_SIZE]; // Dialog Buffer
static BYTE TextST_DCB[TEXTST_DCB_SIZE]; // Dialog Composition Buffer
static BYTE TextST_BOB[TEXTST_BOB_SIZE]; // Bitmap Object Buffer
/**
* Local functions
*/
static TEXTST_STATUS textstLoadDSS(TEXTST_INFO *TextSTInfo);
static void textstClearDSS(TEXTST_INFO *TextSTInfo);
static ULONG textstGetNextDPS(TEXTST_INFO *TextSTInfo, ULONG ulPTS);
static TEXTST_STATUS textstGetInitialCounter(TEXTST_INFO *TextSTInfo, ULONG &ulInitalCounter);
/**
* TextSTInitialize -- Initialize the TextST Module. This will start up the threads
* and allocate memory for palettes and buffer memory.
*
* @param handle -- pointer to textst handle
* @param screen_width -- width of primary surface
* @param screen_height -- height of primary surface
* @param dfb -- handle to directfb
* @param sfc -- handle to primary surface for pg/textst
* @param disp_layer -- handle to presentation display layer
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTCreate(TEXTST_HANDLE *handle, int screen_width, int screen_height,
IDirectFB *dfb, IDirectFBDisplayLayer *disp_layer)
{
TEXTST_INFO *TextSTInfo = NULL;
TEXTST_STATUS err = TEXTST_FAILURE;
DFBColor dfb_palette_entry[256];
DFBPaletteDescription pal_desc;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTCreate: ENTER\n"));
if ( (handle == NULL) || (dfb == NULL) || (disp_layer == NULL) )
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: NULL Pointer!\n"));
return (TEXTST_NULL_PTR);
}
/* Create the local handle */
TextSTInfo = (TEXTST_INFO *)OS_MemAlloc(sizeof(TEXTST_INFO) );
if (TextSTInfo == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating handle!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Initialize handle data */
memset(TextSTInfo, 0, sizeof(TEXTST_INFO) );
/* Initialize PTS's */
TextSTInfo->ulWaitStartPTS = 0xffffffff;
TextSTInfo->ulWaitEndPTS = 0xffffffff;
TextSTInfo->SysTimeBase = 0xffffffff;
TextSTInfo->ulCurPTS = 0xffffffff;
/* Set pointer to preload buffer */
TextSTInfo->bSPB = TextST_SPB;
/* set dfb info */
TextSTInfo->DFBInfo.pDFBHandle = dfb;
TextSTInfo->DFBInfo.DispLayer = disp_layer;
TextSTInfo->DFBInfo.ScreenWidth = screen_width;
TextSTInfo->DFBInfo.ScreenHeight = screen_height;
/* turn textst display on */
if (TextSTInfo->DFBInfo.DispLayer->SetLevel(TextSTInfo->DFBInfo.DispLayer, 1) != DFB_OK)
{
OS_MemFree(TextSTInfo);
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failed to set the level to 1\n"));
return (TEXTST_FAILURE);
}
/* get the primary surface for the TextST diplay layer */
if (TextSTInfo->DFBInfo.DispLayer->GetSurface(TextSTInfo->DFBInfo.DispLayer, &TextSTInfo->DFBInfo.PrimarySurface) != DFB_OK)
{
DbgPrint(("TextSTCreate: Failed to get surface\n"));
goto errout;
}
/* initialize all colors in palette to clear */
memset(dfb_palette_entry, 0x00000000, sizeof(DFBColor) * 256);
/* set default dfb palette descriptions */
pal_desc.flags = (DFBPaletteDescriptionFlags)(DPDESC_SIZE | DPDESC_ENTRIES);
pal_desc.size = 256;
pal_desc.entries = dfb_palette_entry;
/* Create the directfb default palette */
if (TextSTInfo->DFBInfo.pDFBHandle->CreatePalette(TextSTInfo->DFBInfo.pDFBHandle, &pal_desc, &TextSTInfo->DFBInfo.dfb_palette) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failed to create palette!\n"));
goto errout;
}
/* Create the directfb clear palette to use when textst hidden */
if (TextSTInfo->DFBInfo.pDFBHandle->CreatePalette(TextSTInfo->DFBInfo.pDFBHandle, &pal_desc, &TextSTInfo->DFBInfo.dfb_clear_palette) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failed to create palette!\n"));
goto errout;
}
/* Create mempool for Dialog Buffer */
TextSTInfo->mempoolDB = OS_CreateMemPool((PVOID)TextST_DB, TEXTST_DB_SIZE, sizeof(TEXTST_RENDER_INFO));
if (TextSTInfo->mempoolDB == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating DB memory pool!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create mempool for Dialog Composition Buffer */
TextSTInfo->mempoolDCB = OS_CreateMemPool((PVOID)TextST_DCB, TEXTST_DCB_SIZE, sizeof(TEXTST_COMPOSITION_INFO));
if (TextSTInfo->mempoolDCB == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating DCB memory pool!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create mempool for Bitmap Object Buffer */
TextSTInfo->mempoolBOB = OS_CreateMemPool( (PVOID)TextST_BOB, TEXTST_BOB_SIZE, (TEXTST_BOB_SIZE / TEXTST_BOB_DEPTH) );
if (TextSTInfo->mempoolBOB == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating BOB memory pool!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create semaphore to protect Dialog Buffer */
TextSTInfo->semDB = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (TextSTInfo->semDB == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating DB semaphore!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create semaphore to protect Composition Buffer */
TextSTInfo->semDCB = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (TextSTInfo->semDCB == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating DCB semaphore!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create semaphore to protect Bitmap Object Buffer */
TextSTInfo->semBOB = OS_SemBCreate(OS_SEM_Q_FIFO, OS_SEM_FULL);
if (TextSTInfo->semBOB == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating BOB semaphore!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create the TextST Decoder */
if (TextSTDecoderCreate(TextSTInfo) != TEXTST_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating TextST Decoder!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create the TextST Render */
if (TextSTRenderCreate(TextSTInfo) != TEXTST_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating TextST Render!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Create the TextST Presentation Controller */
if (TextSTPresCtrlCreate(TextSTInfo) != TEXTST_SUCCESS)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTCreate: Failure creating TextST Presentation Controller!\n"));
err = TEXTST_FAILURE;
goto errout;
}
/* Set state */
TextSTInfo->tState = TEXTST_STATE_STOPPED;
/* Set handle to textst info */
*handle = (PVOID)TextSTInfo;
return (TEXTST_SUCCESS);
errout:
if (TextSTInfo != NULL)
{
/* Delete TextST Presentation Controller */
TextSTPresCtrlDelete();
/* Delete TextST Render */
TextSTRenderDelete();
/* Delete the TextST Decoder */
TextSTDecoderDelete();
/* 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);
}
/* Delete handle */
OS_MemFree(TextSTInfo);
TextSTInfo = NULL;
}
/* Set handle to NULL */
*handle = NULL;
return (err);
}
/**
* TextSTUninitialize -- Make sure the Text Subtitle module is in the stopped state
* and then stop all threads and deallocate all heap memory the
* module is using
*
* @param
* handle -- textst handle
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTDelete(TEXTST_HANDLE handle)
{
TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTDelete: ENTER\n"));
if (TextSTInfo != NULL)
{
/* Delete TextST Presentation Controller */
TextSTPresCtrlDelete();
/* Delete TextST Render */
TextSTRenderDelete();
/* Delete the TextST Decoder */
TextSTDecoderDelete();
if (TextSTInfo->fDSSLoaded == TRUE)
{
/* Clear the DSS */
textstClearDSS(TextSTInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -