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

📄 subtitle.c

📁 dvd里面的一个文件系统的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
}

// **************************************************************************************** //
static inline void supSetSubtitleIdxBuffer( UINT32* pBufAddr, UINT32 uiSize )
{
    s_pSupIdxBasePtr    = pBufAddr;
    s_uiSupIdxBaseSize  = uiSize << 10;
    s_pSubIdxBaseEndPtr = (UINT32*)( (UINT8*)pBufAddr + s_uiSupIdxBaseSize );   // 2004/01/27 yltseng
}

// **************************************************************************************** //
static UINT32 supFillBuffer( BYTE** ppCurrent, UINT32* pByteRead )
{
    if( !ppCurrent || !pByteRead || ( s_uiSupLen <= *pByteRead ) )
        return FALSE;
        
    BYTE*   pCurrent    = *ppCurrent;   
    UINT32  uiOffset    = SUBTITLE_RELOAD_LIMIT - ( s_pSupBufEndPtr - pCurrent );
    UINT32  uiReadCount = ( s_uiSupLen - *pByteRead ) > ( s_uiSupBufSize - SUBTITLE_RELOAD_LIMIT ) ? 
                          ( s_uiSupBufSize - SUBTITLE_RELOAD_LIMIT ) : ( s_uiSupLen - *pByteRead );
        
    *ppCurrent = (BYTE*)( s_pSupBufPtr + uiOffset );
    memcpy( *ppCurrent, pCurrent, s_pSupBufEndPtr - pCurrent );

    FS_SetOutOfFileReading();
#if defined(SUPPORT_CARD_STORAGE)||defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)//2005-8-24 17:23 zhoulin  
    if( ran_read( (BYTE*)( s_pSupBufPtr + SUBTITLE_RELOAD_LIMIT ), l2msf( s_uiSupLba + ( (*pByteRead) >> ((media_type == MEDIA_CARD)?9:11) ) ), uiReadCount  ) != ATAPI_OK )
#else
    if( ran_read( (BYTE*)( s_pSupBufPtr + SUBTITLE_RELOAD_LIMIT ), l2msf( s_uiSupLba + ( (*pByteRead) >> 11 ) ), uiReadCount  ) != ATAPI_OK )
#endif
    {
        printf( "supFillBuffer fail! can't read file\n" );
        return FALSE;
    }
    FS_ResetOutOfFileReading();
#ifdef DBG_PRINT_LOADED_BUFFER
    print_block( (BYTE*)( s_pSupBufPtr + SUBTITLE_RELOAD_LIMIT ), 16 );
#endif    
    (*pByteRead) += uiReadCount;
    return TRUE;
}

// **************************************************************************************** //
extern int supAddSubtitleFileInfo( UINT32 uiLoc, UINT32 uiSize, const char* pFileName )
{
    if( !pFsJpeg || !pFileName )
        return 0;

    if( s_uiSupCnt < VIDEO_SUBTITLE_MAX )
    {                
        int iInfoSize = sizeof( s_aSubtitleInfo ) / sizeof( SUBTITLE_INFO_ENTRY );
        int i = 0;

        for( ; i < iInfoSize; i++ )
        {
            #ifdef SUPPORT_NATIVE_FSNAME //DENGHG don't conver file name to uppercase 2006-6-9 19:03
            char* tmpPfileName = (BYTE*)(((BYTE*)pFsJpeg) + sizeof(FSJPEGDATA));
            strcpy(tmpPfileName,pFileName); 
            ConvertLowerCaseToUpperCase( tmpPfileName );            
            if( FindFileExt( tmpPfileName, s_aSubtitleInfo[i].aExtName ) )
            #else
            if( FindFileExt( pFileName, s_aSubtitleInfo[i].aExtName ) )
            #endif
            {    
                break;
        	}
        }

        if( i == iInfoSize )
            return 0;

        subtitle_array[ s_uiSupCnt ].uiType    = i;
        subtitle_array[ s_uiSupCnt ].loc       = msf2l( uiLoc );
        subtitle_array[ s_uiSupCnt ].size      = uiSize;

        supAddVideoFileInfo( s_uiSupCnt, 1, pFileName );
        s_uiSupCnt++;
        
        return 1;
    }

    return 0;
}

// **************************************************************************************** //
extern void supRunSubtitleMatch()
{
    SUBTITLE_TEMP_DATA* pSupBase    = (SUBTITLE_TEMP_DATA*) MATCHBUFSTART;
    SUBTITLE_TEMP_DATA* pSupEnd     = (SUBTITLE_TEMP_DATA*) s_pSupBufPtr;

    SUBTITLE_TEMP_DATA *pOutter, *pInner;
    UINT8 i, belongIdx=0;
   
#ifdef DBG_SUBTITLE_BELONG_TO
    for( pOutter = pSupBase; pOutter < pSupEnd; pOutter++ )
        printf( "type = %d, idx = %d, name = %s\n", pOutter->uiType, pOutter->uiIndex, pOutter->aName );
#endif

    for( pOutter = pSupBase; pOutter < pSupEnd; pOutter++ )
    {
        if( pOutter->uiType == 1 )  // subtitle file
        {
            for(i = 0; i < NUM_OF_BELONGTO; i++)
                subtitle_array[ pOutter->uiIndex ].uiBelongTo[i] = 0xffff;
                //subtitle_array[ pOutter->uiIndex ].uiBelongTo = 0xffff;

            for( pInner = pSupBase; pInner < pSupEnd; pInner++ )
            {
                if( pInner->uiType == 0 )   // video file
                {
                  #ifdef ORITRON_HK_DVD //qinhua,2006-2-20 19:54
                    if((strncmpIgnoreCase( pOutter->aName, pInner->aName, strlen( pInner->aName ))==0)
                    &&(strncmpIgnoreCase(  pInner->aName, pOutter->aName, strlen( pOutter->aName))==0) )
                   #else//#ifdef ORITRON_HK_DVD //qinhua,2006-2-20 19:54
                    if( (strinstr( pOutter->aName, pInner->aName, strlen( pOutter->aName )))
                        ||(strinstr(  pInner->aName, pOutter->aName, strlen( pInner->aName ))) 
                        #ifdef THAKRAL_DVD//liweihua add for THAKRAL DVD 2005-3-11 9:45
                        //for sometime the mp4 file and its subtitle file have different file name
                        ||(GetMatchCharacterCount(pOutter->aName, pInner->aName) >= 8)
                        #endif
                        )
                    #endif//#ifdef ORITRON_HK_DVD //qinhua,2006-2-20 19:54
                    {
#ifdef DBG_SUBTITLE_BELONG_TO
                        printf( "avi = %s, sup = %s\n", pInner->aName, pOutter->aName );
#endif
                        subtitle_array[ pOutter->uiIndex ].uiBelongTo[belongIdx] = pInner->uiIndex;
                        //subtitle_array[ pOutter->uiIndex ].uiBelongTo = pInner->uiIndex;
                        //printf_w( "subtitle_array[%d].uiBelongTo[%d] = %d\n\n", pOutter->uiIndex, belongIdx, pInner->uiIndex);
                        belongIdx ++;
                        if(belongIdx >= NUM_OF_BELONGTO)
                        break;
                    }
                }   // if video
            }   // for pInner
        }   // if subtitle            
        belongIdx = 0;
        
    }   // for pOutter
}

// **************************************************************************************** //
static inline int supGetNthSubtitle( int iAVIFile, int iSubFile )
{
    if( iAVIFile < 0 )
        return 0;

    int i,j;
    int iSubCntOfCurFile    = 0;

    for( i = 0; i < s_uiSupCnt; i++ )
    {
        for(j=0;j<NUM_OF_BELONGTO;j++)
        {
            if( subtitle_array[i].uiBelongTo[j] == iAVIFile )
        {
            if( iSubCntOfCurFile == iSubFile )
                return i;

            iSubCntOfCurFile++;
        }
    }
    }

    return -1;
}

// **************************************************************************************** //
static inline int supParseSubtitleEntry( int iSubFileIdx )
{
    if( iSubFileIdx < 0 || iSubFileIdx >= s_uiSupCnt )
        return FALSE;
    
    s_uiSupLba      = subtitle_array[ iSubFileIdx ].loc;
    s_uiSupLen      = subtitle_array[ iSubFileIdx ].size;
    s_uiSupStart    = 0;
    s_uiSupEnd      = 0;
    BYTE*   bufptr  = s_pSupBufPtr;

    FS_SetOutOfFileReading();
    /* ----------------------------------------------------------
    New FS -- Simon 2006.3.3
    ---------------------------------------------------------- */
#if defined(SUPPORT_CARD_STORAGE)||defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
    subStLBA = s_uiSupLba;
    
    if (media_type == MEDIA_CARD)
    {
        fs_file_close(pSubFile);
        fs_file_open2(pReadDrive, pSubFile, FSLBA2Clus(subStLBA), s_uiSupLen);
    }
#endif
    /* ----------------------------------------------------------
    End of New FS
    ---------------------------------------------------------- */
    if( ran_read( bufptr, l2msf( s_uiSupLba ), s_uiSupLen > s_uiSupBufSize ? s_uiSupBufSize : s_uiSupLen ) != ATAPI_OK )
    {
        printf("subtitle load fail! can't read file\n");
        return FALSE;
    }
    FS_ResetOutOfFileReading();
    #ifdef SUPPORT_SMI_MultiLanguage//2005-8-16 20:38 zhoulin
    lang_num=0;
    #endif
    
    if(((s_pfnParsingSubtitleFunc())&&(s_pSupIdxEnd>=s_pSupIdxPtr+EXTSUPENTRYSIZE)) //lyc add 2006-3-10,idx table not empty ,do by the default format 
    #ifdef Support_SubExName_Changed
     ||(supGetOtherFormat())  //otherwise try other format do
    #endif
    ) 
    {
        // preload subtitle into buffer
        UINT32 len = s_uiSupLen;
        if( len > s_uiSupBufSize )
            len = s_uiSupBufSize;

        FS_SetOutOfFileReading();
        if( ran_read( s_pSupBufPtr, l2msf(s_uiSupLba), len ) != ATAPI_OK )
        {
            printf("external subtitle read error!!\n");
            RESET_EXT_SUP();
            return FALSE;
        }
        FS_ResetOutOfFileReading();
        s_uiSupEnd      = len;
        return TRUE;
    }
    #ifdef SHOW_UNSUPPORTED_SUBTITLE//zxb 2006-5-12 16:51
   	else if(disp_time > 0)    
   	{              
    	psprintf(RegionValStr[1], ":[UNSUPPORTED]");
    	PrintOsdMsg(109, 1, 1, 1);	
    }           
    #endif
    return FALSE;
}

// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SRT
static int ParsingSubtitleSRT()
{
    BYTE    tbuf[12];
    UINT32  spnum, bcnt;
    UINT32  hr, min, sec, ms;
    UINT32  sttime, endtime;
    
    UINT32  uiByteRead  = s_uiSupBufSize;
    UINT32  uiOffset    = 0;
    BYTE*   base        = s_pSupBufPtr;
    BYTE*   bufend      = s_pSupBufEndPtr;
    BYTE*   bufptr      = base;
    BYTE*   suptr       = NULL;
    UINT32* idxptr      = s_pSupIdxBasePtr;

    // parse subpicture
    do
    {
        if(( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT)&&(s_uiSupLen>s_uiSupBufSize)) //lyc update 2006-8-9;only fileszie>supbufsize,do supFillBuffer
        {            
            if( !supFillBuffer( &bufptr, &uiByteRead ) )
                break;

            uiOffset += ( s_uiSupBufSize - SUBTITLE_RELOAD_LIMIT );
        }
            
        while ( !_isdigit( *bufptr ) )
            bufptr++;

        if( (UINT32)( bufptr + uiOffset - base ) > s_uiSupLen )
            break;
        
        // get subpicture number
        spnum = 0;
        while ( _isdigit( *bufptr ) )
            spnum = (spnum*10) + (*bufptr++ - '0');
      
        // error check omitted, should be "0x0D 0x0A" or "0x20"
        while ( _isspace(*bufptr) )
            bufptr++;

        // get start time, xx:xx:xx,xxx format, 12 bytes
        memcpy(tbuf, bufptr, 12);
        bufptr += 12;
#if 0//liumzh 2005-9-19 16:28 , for both xx:xx:xx,xxx format &  x: x: x,  x format
        hr  = ((tbuf[0]-'0') * 10) + (tbuf[1]-'0');
        min = ((tbuf[3]-'0') * 10) + (tbuf[4]-'0');
        sec = ((tbuf[6]-'0') * 10) + (tbuf[7]-'0');
        ms  = ((tbuf[9]-'0') * 100) + ((tbuf[10]-'0') * 10) + (tbuf[11]-'0');
#else
        #define IsDigitTime( chr )      ( chr >= '0' && chr <= '6' )
        hr =  ((IsDigitTime(tbuf[0]))?((tbuf[0]-'0') * 10) : 0) + (tbuf[1]-'0');
        min = ((IsDigitTime(tbuf[3]))?((tbuf[3]-'0') * 10) : 0) + (tbuf[4]-'0');
        sec = ((IsDigitTime(tbuf[6]))?((tbuf[6]-'0') * 10) : 0) + (tbuf[7]-'0');
        ms  = 0; //((IsDigit(tbuf[9]))?((tbuf[9]-'0') * 100) : 0) + ((IsDigit(tbuf[10]))?((tbuf[10]-'0') * 10) : 0) + (tbuf[11]-'0');
        #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
            if( (!_isdigit(tbuf[1]))||(!_isdigit(tbuf[4]))||(!_isdigit(tbuf[7])) )
               goto Change_To_Next_SubT;
       #endif  
#endif
        sttime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;

        // drop seperation, " --> "
        while ( !_isdigit( *bufptr ) )
            bufptr++;

        // get end time, xx:xx:xx,xxx format, 12 bytes
        memcpy(tbuf, bufptr, 12);
        bufptr += 12;
#if 0 //liumzh 2005-9-19 16:28 , for both xx:xx:xx,xxx format &  x: x: x,  x format
        hr  = ((tbuf[0]-'0') * 10) + (tbuf[1]-'0');
        min = ((tbuf[3]-'0') * 10) + (tbuf[4]-'0');
        sec = ((tbuf[6]-'0') * 10) + (tbuf[7]-'0');
        ms  = ((tbuf[9]-'0') * 100) + ((tbuf[10]-'0') * 10) + (tbuf[11]-'0');
#else
        hr =  ((IsDigitTime(tbuf[0]))?((tbuf[0]-'0') * 10) : 0) + (tbuf[1]-'0');
        min = ((IsDigitTime(tbuf[3]))?((tbuf[3]-'0') * 10) : 0) + (tbuf[4]-'0');
        sec = ((IsDigitTime(tbuf[6]))?((tbuf[6]-'0') * 10) : 0) + (tbuf[7]-'0');
        ms  = 0; //((IsDigit(tbuf[9]))?((tbuf[9]-'0') * 100) : 0) + ((IsDigit(tbuf[10]))?((tbuf[10]-'0') * 10) : 0) + (tbuf[11]-'0');
        //#ifdef Support_SubExName_Changed  //lyc add-2006-2-20
        //    if( (!_isdigit(tbuf[1]))||(!_isdigit(tbuf[4]))||(!_isdigit(tbuf[7])) )
        //       goto Change_To_Next_SubT;
        //#endif  
#endif
        endtime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;

        while( !_iseol( bufptr ) )
            bufptr++;
            
        if( _iseol_unix( bufptr ) )
            bufptr += 1;
        else
            bufptr += 2;
        
        // skip blank string
        if( _iseol( bufptr ) )
            continue;

        bcnt = 0;
        suptr = bufptr;

        while( bufptr < bufend )
        {
            if( _iseol( bufptr ) )
            {
                UINT32 uiEolOffset = _iseol_unix( bufptr ) ? 1 : 2;
                if( _iseol( ( bufptr + uiEolOffset ) ) )
                {
                    bufptr += ( uiEolOffset * 2 );
                    break;
                }
            }

            bufptr++;
            bcnt++;
        }

        *idxptr++ = sttime;
        *idxptr++ = endtime;
        *idxptr++ = suptr + uiOffset - base;
        *idxptr++ = bcnt;

        if( idxptr + 3 >= s_pSubIdxBaseEndPtr )
        {
#ifdef DBG_KEYFRAME
            printf( "Subpicture index buffer too small, can't record all index\n" );            
#endif            
            break;
        }
        
#ifdef DBG_KEYFRAME
        printf( "st = %d, end = %d, offset = %d, cnt = %d\n", sttime, endtime, suptr + uiOffset - base, bcnt );
#endif
    } while (1);

    s_pSupIdxPtr    = s_pSupIdxBasePtr;
    s_pSupIdxEnd    = idxptr;
    s_pSupBufPtr    = s_pSupBufPtr;

    printf("SRT subtitile initialized!!\n" );
    #ifdef Support_SubExName_Changed  //hongfeng 2006/8/9 15:41
    if(s_uiSupType != INTERNAL_SUBTITLE_SRT)  
        s_uiSupType = INTERNAL_SUBTITLE_SRT;
    #endif    

    return 1;

⌨️ 快捷键说明

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