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

📄 dvd_vtsi.c

📁 这是DVD中伺服部分的核心代码
💻 C
📖 第 1 页 / 共 3 页
字号:
 *
 *   Returns:     sa    start address of new location
 *                ea    end address
 *
 *   Structures:  vts_tmapti
 *                VTS_TMAP_SRP
 *
 */
BOOLEAN get_tmap_entry(ULONG *sa, ULONG *ea, USHORT pgcn, ULONG map_ent, ULONG vts_sa)
{
    ULONG byte_vts_tmapt_sa = 0;   /* offset in bytes from vts_tmapt_sa */
    ULONG sector_vts_tmapt_sa = 0; /* offset in sectors from vts_tmapt_sa */
    ULONG last_sector_byte_offset = 0;
    ULONG tmap_sa;

    sbuf = (UBYTE *) lbuf;

    byte_vts_tmapt_sa = vts_tmap_srp[pgcn];
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("\n\nget_tmap_entry():  start of vts_tmap: %u\n", byte_vts_tmapt_sa));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("\n\nget_tmap_entry():  we want %u vts_tmap[pgcn].map_en_n %u\n", map_ent, vts_tmap[pgcn].map_en_n));

    byte_vts_tmapt_sa += 4;                   /* Move past TMU and MAP_EN_Ns */

    /* Use the next to last entry as the search start point */
    if ((map_ent == vts_tmap[pgcn].map_en_n))
    {
        map_ent--;
    }

    if ((map_ent > vts_tmap[pgcn].map_en_n) || (vts_tmap[pgcn].map_en_n > 2048)) /* map_en_n is supposed to be less than 2048 */
    {
       return(FAILURE);
    }

    byte_vts_tmapt_sa += map_ent << 2;   //*4

    sector_vts_tmapt_sa = byte_vts_tmapt_sa >> 11;  /* offset in bytes / 2048
                                                          bytes per sector */
    tmap_sa = vts_sa + vtsi_mat.vts_tmapt_sa + sector_vts_tmapt_sa;

    if (LoaderSectorRead(tLoader, tmap_sa, sbuf, 2) != LOADER_SUCCESS)
    {
        return (FAILURE);
    }

    last_sector_byte_offset = byte_vts_tmapt_sa % 2048;  /* offset in bytes */

    *sa = MAKE_DWORD(&sbuf[last_sector_byte_offset]) & 0x7fffffff;
    *ea = MAKE_DWORD(&sbuf[last_sector_byte_offset + 4]) & 0x7fffffff;

    DBGPRINT(DBG_ON(DBG_VERBOSE), ("get_tmap_entry():  sa: %x\n", *sa));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("get_tmap_entry():  ea: %x\n\n", *ea));

    return (SUCCESS);
}

/**
 **  Name:  Parse_VTSI_MAT
 **
 **  Description: Parses the Video Title Set Information Management Table
 **  DVD Part 3:Video Spec Version 1.0 section 4.2.1
 **
 **  Arguments:   None
 **
 **  Returns:     fills in structures
 **
 **  Structures:  VTSI_MAT
 **
 **/
void Parse_VTSI_MAT()
{
    ULONG index = 0;
    ULONG offset;
    ULONG Stream_Num, Byte_Num;

    offset = 0;

    /* parse VTS identifier  (VTS_ID) */
    store((UBYTE *) & vtsi_mat.vts_id[0], offset, 12, STORE_BIG_ENDIAN);

    /* End address of VTS  (VTS_EA) */
    store((UBYTE *) & vtsi_mat.vts_ea, offset + 12, 4, STORE_LITTLE_ENDIAN);

    /* End address of VTSI  (VTSI_EA) */
    store((UBYTE *) & vtsi_mat.vtsi_ea, offset + 28, 4, STORE_LITTLE_ENDIAN);

    /* Version number of DVD Video Specificatins  (VERN) */
    store((UBYTE *) & vtsi_mat.vern, offset + 32, 2, STORE_LITTLE_ENDIAN);

    /* Video Manager Category   (VTS_CAT) */
    store((UBYTE *) & vtsi_mat.vts_cat[0], offset + 34, 4, STORE_BIG_ENDIAN);

    /* store End Address of vtsi_mat */
    store((UBYTE *) & vtsi_mat.vtsi_mat_ea, offset + 128, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTSM_VOBS_SA */
    store((UBYTE *) & vtsi_mat.vtsm_vobs_sa, offset + 192, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTSTT_VOBS */
    store((UBYTE *) & vtsi_mat.vtstt_vobs_sa, offset + 196, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTS_PTT_SRPT */
    store((UBYTE *) & vtsi_mat.vts_ptt_srpt_sa, offset + 200, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTS_PGCIT */
    store((UBYTE *) & vtsi_mat.vts_pgcit_sa, offset + 204, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTSM_PGCI_UT */
    store((UBYTE *) & vtsi_mat.vtsm_pgci_ut_sa, offset + 208, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTS_TMAPT */
    store((UBYTE *) & vtsi_mat.vts_tmapt_sa, offset + 212, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTSM_C_ADT */
    store((UBYTE *) & vtsi_mat.vtsm_c_adt_sa, offset + 216, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTSM_VOBU_ADMAP */
    store((UBYTE *) & vtsi_mat.vtsm_vobu_admap_sa, offset + 220, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTS_C_ADT */
    store((UBYTE *) & vtsi_mat.vts_c_adt_sa, offset + 224, 4, STORE_LITTLE_ENDIAN);

    /* store Start Address of VTS_VOBU_ADMAP */
    store((UBYTE *) & vtsi_mat.vts_vobu_admap_sa, offset + 228, 4, STORE_LITTLE_ENDIAN);

    /* store the video attributes  VTSM_V_ATR */
    store((UBYTE *) & vtsi_mat.vtsm_v_atr[0], offset + 256, 2, STORE_BIG_ENDIAN);

    /* store the number of audio streams VTSM_AST_N */
    store((UBYTE *) & vtsi_mat.vtsm_ast_n[0], offset + 258, 2, STORE_BIG_ENDIAN);

    /* store the audio attributes VTSM_AST_ATR */
    store((UBYTE *) & vtsi_mat.vtsm_ast_atr.flags[0], offset + 260, 2, STORE_BIG_ENDIAN);
/*
    store( (UBYTE*) &vtsi_mat.vtsm_ast_atr.specific_code, offset + 260 + 2, 2, STORE_LITTLE_ENDIAN);

    store( (UBYTE*) &vtsi_mat.vtsm_ast_atr.specific_code_ext, offset + 260 + 5, 1, STORE_LITTLE_ENDIAN);

    store( (UBYTE*) &vtsi_mat.vtsm_ast_atr.app_info, offset + 260 + 7, 1, STORE_LITTLE_ENDIAN);
*/
    /* store Start Address of VTSM_SPST_N */
    store((UBYTE *) & vtsi_mat.vtsm_spst_n[0], offset + 340, 2, STORE_BIG_ENDIAN);

    /* store Start Address of VTSM_SPST_ATR */
    store((UBYTE *) & vtsi_mat.vtsm_spst_atr.flags, offset + 342, 1, STORE_LITTLE_ENDIAN);

    store((UBYTE *) & vtsi_mat.vtsm_spst_atr.specific_code, offset + 342 + 2, 2, STORE_LITTLE_ENDIAN);

    store((UBYTE *) & vtsi_mat.vtsm_spst_atr.specific_code_ext, offset + 342 + 5, 1, STORE_LITTLE_ENDIAN);

    /* store video attributes  VTS_V_ATR */
    store((UBYTE *) & vtsi_mat.vts_v_atr[0], offset + 512, 2, STORE_BIG_ENDIAN);

    /* store number of audio streams of VTS_AST_N */
    store((UBYTE *) & vtsi_mat.vts_ast_n[0], offset + 514, 2, STORE_BIG_ENDIAN);

    /* store the audio attributes VTSI_AST_ATR */
    for (index = 0; index < vtsi_mat.vts_ast_n[1]; index++)
    {
        store((UBYTE *) & vtsi_mat.vts_ast_atrt[index].flags[0], offset + 516 + (index * 8), 2, STORE_BIG_ENDIAN);

        store((UBYTE *) & vtsi_mat.vts_ast_atrt[index].specific_code, offset + 516 + (index * 8) + 2, 2, STORE_LITTLE_ENDIAN);

        store((UBYTE *) & vtsi_mat.vts_ast_atrt[index].specific_code_ext, offset + 516 + (index * 8) + 5, 1, STORE_LITTLE_ENDIAN);

        store((UBYTE *) & vtsi_mat.vts_ast_atrt[index].app_info, offset + 516 + (index * 8) + 7, 1, STORE_LITTLE_ENDIAN);
    }

    /* store number of sub-picture streams  VTS_SPST_N */
    store((UBYTE *) & vtsi_mat.vts_spst_n[0], offset + 596, 2, STORE_BIG_ENDIAN);

    /* store the sub-picture stream attributes VTS_SPST_ATRT */
    for (index = 0; index < vtsi_mat.vts_spst_n[1]; index++)
    {
        store((UBYTE *) & vtsi_mat.vts_spst_atrt[index].flags, offset + 598 + (index * 6), 1, STORE_LITTLE_ENDIAN);

        store((UBYTE *) & vtsi_mat.vts_spst_atrt[index].specific_code, offset + 598 + (index * 6) + 2, 2, STORE_LITTLE_ENDIAN);

        store((UBYTE *) & vtsi_mat.vts_spst_atrt[index].specific_code_ext, offset + 598 + (index * 6) + 5, 1, STORE_LITTLE_ENDIAN);
    }

    /* store Multichannel audio Stream Attribute table of VTS */
    for (Stream_Num = 0; Stream_Num < 8; Stream_Num++)
    {
        for (Byte_Num = 0; Byte_Num < 24; Byte_Num++)
        {
            store((UBYTE *) & vtsi_mat.vts_mu_ast_atrt[Stream_Num][Byte_Num], offset + 792 + Byte_Num, 1, STORE_LITTLE_ENDIAN);
        }
    }
}

/**
 **  Name:  Parse_VTS_PTT_SRPT
 **
 **  Description: Parses the Video Title Set Part of Title Search Pointer Table
 **  DVD Part 3:Video Spec Version 1.0 section 4.2.2
 **
 **  Arguments:   vts_ptt_srpt_sa start address of the VTS_PTT_SRPT
 **
 **  Returns:     Fills in structures
 **
 **  Structures:  ptt_srpti
 **               PTT_SRP
 **               TTU_SRP
 **
 **/
void Parse_VTS_PTT_SRPT(ULONG vts_ptt_srpt_sa)
{
    USHORT index = 0;
    ULONG index2 = 0;
    ULONG offset = 0;
#ifndef FIXED_PTT
    ptt_srp_struct *ptt_srp_ptr = (ptt_srp_struct *)ptt_srp_buf;
    ptt_srp_struct *ptt_buf_end_adr = ptt_srp_buf + MAX_PTT_BUF;
#endif

    /* Parse the ptt_srpti */
    /* store the Number of TTUs in the VTS */
    store((UBYTE *) & ptt_srpti.vts_ttu_n, vts_ptt_srpt_sa, 2, STORE_LITTLE_ENDIAN);

    /* store the end address of VTS_PTT_SRPT */
    store((UBYTE *) & ptt_srpti.vts_ptt_srpt_ea, vts_ptt_srpt_sa + 4, 4, STORE_LITTLE_ENDIAN);

    /* Move past the ptt_srpti */
    offset = vts_ptt_srpt_sa + 8;

    /* store the TTU_SRP data */
    for (index = 0; (index < ptt_srpti.vts_ttu_n) && (index < MAX_NUM_TT); index++)
    {
        store((UBYTE *) & ttu_srp[index], offset, 4, STORE_LITTLE_ENDIAN);
        offset += 4;
    }
    ERROR_CHECK(index, MAX_NUM_TT, "MAX_NUM_TT");

    /* Calculate and store the number of SRP for each TTU */
    for (index = 0; (index < ptt_srpti.vts_ttu_n) && (index < MAX_NUM_TT); index++)
    {
        if (index == (ptt_srpti.vts_ttu_n - 1))
        {
            ttu_srp_num[index] = (USHORT) (((ptt_srpti.vts_ptt_srpt_ea + 1) - ttu_srp[index]) / 4);
        }
        else if (index < (MAX_NUM_TT-1))
        {
            ttu_srp_num[index] = (USHORT) ((ttu_srp[index + 1] - ttu_srp[index]) / 4);
        }
    }

    /* Search through the TTU to get the PTT_SR */
    offset = ttu_srp[0];

    for (index = 0; (index < ptt_srpti.vts_ttu_n) && (index < MAX_NUM_TT); index++)
    {
#ifdef FIXED_PTT
        for (index2 = 0; index2 < ttu_srp_num[index] &&
            index2 < MAX_PTT_SRP; index2++)
#else
        ptt_srp[index] = (ptt_srp_struct *) ptt_srp_ptr;
        /* Report an OSD message if ERROR_REPORTING enabled */
        ERROR_CHECK(((ULONG) ptt_srp_ptr - (ULONG) ptt_srp_buf + (ULONG) ttu_srp_num[index]),
            sizeof(ptt_srp_struct)*MAX_PTT_BUF, "MAX_PTT_BUF");

        /* Check end address to prevent writing past the ptt_srp_buf buffer */
        for (index2=0; (index2 < ttu_srp_num[index]) && ((ULONG)&ptt_srp[index][index2+1] < (ULONG)ptt_buf_end_adr);  index2++)
#endif
        {
            /* store the Program Chain Number */
            store((UBYTE *) & ptt_srp[index][index2].pgcn, offset, 2, STORE_LITTLE_ENDIAN);

            /* store the Program Number */
            store((UBYTE *) & ptt_srp[index][index2].pgn, (offset + 3), 1, STORE_LITTLE_ENDIAN);
            offset += 4;
        }
#ifdef FIXED_PTT
        ERROR_CHECK(index2, MAX_PTT_SRP, "MAX_PTT_SRP");
#else
        ptt_srp_ptr += index2;
#endif
    }
    ERROR_CHECK(index, MAX_NUM_TT, "MAX_NUM_TT");
}

/**
 **  Name:  Parse_VTS_PGCIT
 **
 **  Description:    Parses the Video Title Set Program Chain Information Table (VTS_PGCIT)
 **                  DVD Part 3:Video Spec Version 1.0 section 4.2.3
 **
 **  Arguments:   vts_pgcit_sa  start address of VTS_PGCIT
 **
 **  Returns:     Fills in structures
 **
 **  Structures:  VTS_PGCITI
 **               VTS_PGCI_SRP
 **
 **
 **/
void Parse_VTS_PGCIT(ULONG vts_pgcit_sa)
{
    ULONG index = 0;
    ULONG offset = 0;

    offset = vts_pgcit_sa;

    /* Parse the VTS_PGCITI */
    /* store the number of VTS_PGCI_SRP s */
    store((UBYTE *) & vts_pgciti.vts_pgci_srp_n, offset, 2, STORE_LITTLE_ENDIAN);

    /* store the end address of the VTS_PGCIT */
    store((UBYTE *) & vts_pgciti.vts_pgcit_ea, offset + 4, 4, STORE_LITTLE_ENDIAN);

    offset += 8;        /* Move past the VTS_PGCITI */

    /* store all the VTS_PGCI_SRP */
    for (index = 0; (index < vts_pgciti.vts_pgci_srp_n) && (index < MAX_NUM_TMAP); index++)
    {
        /* store the VTS_PGC Category information */
        store((UBYTE *) & vts_pgci_srp[index].vts_pgc_cat[0], offset, 4, STORE_BIG_ENDIAN);

        /* store the Start Address of the VTS_PGCI */
        store((UBYTE *) & vts_pgci_srp[index].vts_pgci_sa, (offset + 4), 4, STORE_LITTLE_ENDIAN);
        offset += 8;
    }
    ERROR_CHECK(index, MAX_NUM_TMAP, "MAX_NUM_TMAP");
}

/**
 *  Name:  Parse_VTSM_PGCI_UT
 *
 *  Description: Parses the Video Title Set Menu Program Chain Information Unit Table (VTSM_PGCI_UT)
 *               DVD Part 3:Video Spec Version 1.0 section 4.2.4
 *
 *  Arguments:   VTSM_PGCI_UT address of VTSM_PGCI_UT
 *
 *  Returns:     Fills in structures
 *
 *  Structures:  vtsm_pgci_uti
 *               vtsm_lu_srp
 *               vtsm_lui
 *               VTSM_PGCI_SRP
 *
 */
void Parse_VTSM_PGCI_UT(ULONG vtsm_pgci_ut)
{
    ULONG index  = 0;
    ULONG index2 = 0;
    ULONG offset = 0;
#ifndef FIXED_PGC
    vts_pgci_srp_struct *vtsm_pgci_srp_ptr     = (vts_pgci_srp_struct *)vtsm_pgci_srp_buf;
    vts_pgci_srp_struct *vtsm_pgci_buf_end_adr = vtsm_pgci_srp_buf + MAX_VTSM_PGCI_BUF;

⌨️ 快捷键说明

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