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

📄 textst_api.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

    /* Set data size of SPB to 0 */
    TextSTInfo->SPBInfo.ulSPBDataSize = 0;

    /* clear user style info */
    TextSTInfo->ubUserStyleID = 0;

    if (TextSTInfo->fDSSLoaded == TRUE)
    {
        /* Clear the DSS */
        textstClearDSS(TextSTInfo);
        TextSTInfo->fDSSLoaded = FALSE;
    }

    /* unload font buffers */
    TextSTUnloadFonts(handle);

    return (TEXTST_SUCCESS);
}

/**
 * TextSTRun -- If the Text Subtitle module has been initialized, notify the module to
 *              start decoding subtitle data from the Subtitle Preloading Buffer.
 *
 * @param
 *      handle -- textst handle
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  TextSTRun(TEXTST_HANDLE handle)
{
    TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTRun: ENTER\n"));

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRun: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    if ( (TextSTInfo->tState != TEXTST_STATE_STOPPED) || (TextSTInfo->SPBInfo.ulSPBDataSize == 0) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRun: Invalid state!\n"));
        return (TEXTST_INVALID_STATE);
    }

    if (TextSTInfo->tDisplay == TEXTST_DISPLAY_ON)
    {
        /* Set the display palette to the primary surface */
        if (TextSTPresCtrlSetPalette(TextSTInfo->DFBInfo.dfb_palette) != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRun: Failed to set palette!\n"));
            goto errout;
        }
    }
    else
    {
        /* Set the fully transparent palette to the primary surface */
        if (TextSTPresCtrlSetPalette(TextSTInfo->DFBInfo.dfb_clear_palette) != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRun: Failed to set palette!\n"));
            goto errout;
        }
    }

    /* Set the initial counter time */
    if (textstGetInitialCounter(TextSTInfo, TextSTInfo->InitalCounterTime) != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRun: Failed to get initial counter time!\n"));
        goto errout;
    }

    /*
     * Set flag to indicate a start is pending.  The decoder will be started on the
     * next valid timestamp update.
     */
    TextSTInfo->fStartPending = TRUE;

    /* Set state to running */
    TextSTInfo->tState = TEXTST_STATE_RUNNING;

    return (TEXTST_SUCCESS);

errout:

    return (TEXTST_FAILURE);
}

/**
 * TextSTStop --    If the Text Subtitle module has been initialized, stop decoding subtitle
 *                  data from the Subtitle Preloading Buffer.
 *
 * @param
 *      handle -- textst handle
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  TextSTStop(TEXTST_HANDLE handle)
{
    TEXTST_INFO *TextSTInfo = (TEXTST_INFO *)handle;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTStop: ENTER\n"));

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    if (TextSTInfo->tState != TEXTST_STATE_RUNNING)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Must be in running state!\n"));
        return (TEXTST_INVALID_STATE);
    }

    /* Erase the textst display */
    if (TextSTPresCtrlErase() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to erase dps!\n"));
        return (TEXTST_FAILURE);
    }

    /* Suspend the TextST Presentation Controller */
    if (TextSTPresCtrlSuspend() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to suspend Presentation controller!\n"));
        return (TEXTST_FAILURE);
    }

    /* Suspend the TextST Renderer */
    if (TextSTRenderSuspend() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to suspend Renderer!\n"));
        return (TEXTST_FAILURE);
    }

    /* Stop the TextST Decoder */
    if (TextSTDecoderStop() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to stop TextST Decoder!\n"));
        return (TEXTST_FAILURE);
    }

    /* Flush the TextST Renderer */
    if (TextSTRenderFlush() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to flush TextST Render!\n"));
        return (TEXTST_FAILURE);
    }

    /* Flush the TextST Presentation Controller's Composition Queue */
    if (TextSTPresCtrlFlushCompQ() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to flush TextST Presentation Controller's Composition Queue!\n"));
        return (TEXTST_FAILURE);
    }

    /* Flush the TextST Presentation Controller's Bitmap Queue */
    if (TextSTPresCtrlFlushBmpQ() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to flush TextST Presentation Controller's Bitmap Queue!\n"));
        return (TEXTST_FAILURE);
    }

    /* Resume the TextST Renderer */
    if (TextSTRenderResume() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to resume Renderer!\n"));
        return (TEXTST_FAILURE);
    }

    /* Resume the TextST Presentation Controller */
    if (TextSTPresCtrlResume() != TEXTST_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTStop: Failed to resume TextST Presentation controller!\n"));
        return (TEXTST_FAILURE);
    }

    /* Set state to stopped */
    TextSTInfo->tState = TEXTST_STATE_STOPPED;

    /* Reset pts times */
    TextSTInfo->ulWaitStartPTS  = 0xffffffff;
    TextSTInfo->ulWaitEndPTS    = 0xffffffff;
    TextSTInfo->ulCurPTS        = 0xffffffff;

    /* Clear start pending flag */
    TextSTInfo->fStartPending = FALSE;

    return (TEXTST_SUCCESS);
}

/**
 * TextSTShow --    If the Text Subtitle module is in the running state, present the text subtitles.
 *
 * @param
 *      handle -- textst handle
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  TextSTShow(TEXTST_HANDLE handle)
{
    TEXTST_INFO         *TextSTInfo     = (TEXTST_INFO *)handle;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTShow: ENTER\n"));

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTShow: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    if (TextSTInfo->tState == TEXTST_STATE_RUNNING)
    {
        /* Set the display palette to the primary surface */
        if (TextSTPresCtrlSetPalette(TextSTInfo->DFBInfo.dfb_palette) != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTShow: Failed to set palette!\n"));
            return (TEXTST_FAILURE);
        }

        /* Flip primary surface to show palette change */
        if (TextSTPresCtrlFlip() != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTShow: Failed to flip surface!\n"));
            return (TEXTST_FAILURE);
        }
    }

    /* Set state for display of subtitles */
    TextSTInfo->tDisplay = TEXTST_DISPLAY_ON;

    return (TEXTST_SUCCESS);
}

/**
 * TextSTHide --    If the Text Subtitle module is in the running state, stop presenting the
 *                  text subtitles.  This will not stop the decoding of the subtitles.
 *
 * @param
 *      handle -- textst handle
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  TextSTHide(TEXTST_HANDLE handle)
{
    TEXTST_INFO         *TextSTInfo     = (TEXTST_INFO *)handle;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTHide: ENTER\n"));

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTHide: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    /* Set state for no display of subtitles */
    TextSTInfo->tDisplay = TEXTST_DISPLAY_OFF;

    if (TextSTInfo->tState == TEXTST_STATE_RUNNING)
    {
        /* Set the fully transparent palette to the primary surface */
        if (TextSTPresCtrlSetPalette(TextSTInfo->DFBInfo.dfb_clear_palette) != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTHide: Failed to set palette!\n"));
            return (TEXTST_FAILURE);
        }

        /* Flip primary surface to show palette change */
        if (TextSTPresCtrlFlip() != TEXTST_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTHide: Failed to flip surface!\n"));
            return (TEXTST_FAILURE);
        }
    }

    return (TEXTST_SUCCESS);
}

/**
 * TextSTSetColorSpace --  setup the colorspace used for palette conversion from ycrcb to rgb
 *
 * @param
 *      handle -- textst handle
 *      ColorSpace -- number indicating colorspace
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS TextSTSetColorSpace(TEXTST_HANDLE handle, int ColorSpace)
{
    TEXTST_INFO         *TextSTInfo     = (TEXTST_INFO *)handle;

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoadFonts: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    /* store the color space */
    if (ColorSpace == 0)
    {
        TextSTInfo->ulColorSpace = REC_601;
    }
    else
    {
        TextSTInfo->ulColorSpace = REC_709;
    }

    return (TEXTST_SUCCESS);
}


/**
 * TextSTLoadFonts --   If the Text Subtitle module is in the stopped state, load all
 *                      fonts on the list into the Font Preloading Buffer.
 *
 * @param
 *      handle -- textst handle
 *      pvFontList -- pointer to list of fonts
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  TextSTLoadFonts(TEXTST_HANDLE handle, PVOID pvFontList)
{
    TEXTST_INFO         *TextSTInfo     = (TEXTST_INFO *)handle;
    BYTE                *bFontList      = (BYTE *)pvFontList;
    ULONG               ulByteOffset;
    char                font_filename[65];
    FILE                *otf_file       = NULL;
    struct stat         stat_buf;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTLoadFonts: ENTER\n"));

    if (TextSTInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoadFonts: TextST Module not initialized!\n"));
        return (TEXTST_NOT_INITIALIZED);
    }

    if (TextSTInfo->tState != TEXTST_STATE_STOPPED)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoadFonts: Must be in stop state!\n"));
        return (TEXTST_INVALID_STATE);
    }

    if (pvFontList == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTLoadFonts: Null pointer!\n"));
        return (TEXTST_NULL_PTR);
    }

    /* Set number of font files */
    TextSTInfo->ubNumberOfFonts = bFontList[0];

⌨️ 快捷键说明

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