📄 subtitle.c
字号:
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
Change_To_Next_SubT:
return 0;
#endif
}
#endif
// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SUB_MICRODVD
static int ParsingSubtitleSUB_MicroDVD()
{
UINT32 uiFrame = 0;
UINT32 sttime = 0;
UINT32 endtime = 0;
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( !(( *bufptr == '{' ) || ( *bufptr == '[' )) )
{
if( bufptr >bufend ) //lyc add-2006-2-20
break;
bufptr++;
}
// skip "{"
bufptr++;
if( (UINT32)( bufptr + uiOffset - base ) > s_uiSupLen )
break;
// get start time, {xx...xx} format
uiFrame = 0;
while( !(( *bufptr == '}' ) || ( *bufptr == ']' )) )
{
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
if(!_isdigit( *bufptr ))
goto Change_To_Next_SubT;
#endif
uiFrame = uiFrame * 10 + ( *bufptr++ - '0' );
}
if( *bufptr == ']' ) ////DENGHG modify [XXXXX] is not uiFrame ,it is ms time.2006-3-22 15:43
{
sttime = uiFrame * 100 * MS_STC_CLK;
}
else
sttime = frctl_frame_to_stc( uiFrame );
// drop seperation, "{"
bufptr += 2;
// get end time, {xx...xx} format
uiFrame = 0;
while( !(( *bufptr == '}' ) || ( *bufptr == ']' )) )
{
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
if(!_isdigit( *bufptr ))
goto Change_To_Next_SubT;
#endif
uiFrame = uiFrame * 10 + ( *bufptr++ - '0' );
}
if( *bufptr == ']' )
{
endtime = uiFrame * 100 * MS_STC_CLK;
}
else
endtime = frctl_frame_to_stc( uiFrame );
// skip "}"
bufptr++;
// skip space
while( _isspace( *bufptr ) )
bufptr++;
suptr = bufptr;
while( !_iseol( bufptr ) )
bufptr++;
if(uiFrame == 0) //get end time //some polish MicroDVD SUBTITLE has no end time denghg2006-1-10 11:40
{
UINT32 i=0;
UINT32 sttime1=0;
while( !(( *(bufptr+i) == '{' )||( *(bufptr+i) == '[' ))&&( (bufptr+i) < bufend ) )
i++;
if( ( *(bufptr+i) == '{' ) || ( *(bufptr+i) == '[' ) ) i++;
while( !(( *(bufptr+i) == '}' )||( *(bufptr+i) == ']' ))&&( ( bufptr+i) < bufend ) )
{
uiFrame = uiFrame * 10 + ( *(bufptr+i) - '0' );
i++;
if( *(bufptr+i) == ']' )
sttime1 = uiFrame * 100 * MS_STC_CLK;
else
sttime1 = frctl_frame_to_stc( uiFrame );
}
#ifdef SUPPORT_TXTSUB_4S_OFF
endtime = ( sttime1 > ( sttime+4*STC_CLK ) ) ? sttime+4*STC_CLK : sttime1;
#else
endtime= sttime1;
#endif
}
*idxptr++ = sttime;
*idxptr++ = endtime;
*idxptr++ = suptr + uiOffset- base;
*idxptr++ = bufptr - suptr;
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, bufptr - suptr );
#endif
} while (1);
s_pSupIdxPtr = s_pSupIdxBasePtr;
s_pSupIdxEnd = idxptr;
s_pSupBufPtr = s_pSupBufPtr;
printf("MicroDVD subtitile initialized!! %x %x %x\n\n", s_pSupIdxPtr, s_pSupIdxEnd, s_pSupBufPtr );
#ifdef Support_SubExName_Changed //hongfeng 2006/8/9 15:59
if(s_uiSupType != INTERNAL_SUBTITLE_SUB_MICRODVD) //hongfeng 2006/8/9 15:41
s_uiSupType = INTERNAL_SUBTITLE_SUB_MICRODVD;
#endif
return 1;
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
Change_To_Next_SubT:
return 0;
#endif
}
#endif
// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SUB_SUBVIEWER
static int ParsingSubtitleSUB_SubViewer()
{
BYTE tbuf[12];
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 header
while( strncmp( (const char*) bufptr, "[FONT]", 6 ) != 0 )
{
if( bufptr >= bufend )
{
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
goto Change_To_Next_SubT;
#endif
goto err_sub;
}
bufptr++;
}
while( !_iseol( bufptr ) )
bufptr++;
// 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 start time, xx:xx:xx.xx format, 11 bytes
memcpy(tbuf, bufptr, 11);
bufptr += 11;
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);
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
if((!_isdigit(tbuf[1]))||(!_isdigit(tbuf[4]))||(!_isdigit(tbuf[7]))||(!_isdigit(tbuf[10])))
goto Change_To_Next_SubT;
#endif
sttime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;
// drop seperation, ","
bufptr++;
// get end time, xx:xx:xx.xx format, 11 bytes
memcpy(tbuf, bufptr, 11);
bufptr += 11;
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);
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
if((!_isdigit(tbuf[1]))||(!_isdigit(tbuf[4]))||(!_isdigit(tbuf[7]))||(!_isdigit(tbuf[10])))
goto Change_To_Next_SubT;
#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;
suptr = bufptr;
while( !_iseol( bufptr ) )
bufptr++;
*idxptr++ = sttime;
*idxptr++ = endtime;
*idxptr++ = suptr + uiOffset - base;
*idxptr++ = bufptr - suptr;
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, bufptr - suptr );
#endif
} while (1);
s_pSupIdxPtr = s_pSupIdxBasePtr;
s_pSupIdxEnd = idxptr;
s_pSupBufPtr = s_pSupBufPtr;
printf("SubViewer subtitile initialized!! %x %x %x\n\n", s_pSupIdxPtr, s_pSupIdxEnd, s_pSupBufPtr );
#ifdef Support_SubExName_Changed //hongfeng 2006/8/9 15:59
if(s_uiSupType != INTERNAL_SUBTITLE_SUB_SUBVIEWER) //hongfeng 2006/8/9 15:41
s_uiSupType = INTERNAL_SUBTITLE_SUB_SUBVIEWER;
#endif
return 1;
err_sub:
return 0;
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
Change_To_Next_SubT:
return 0;
#endif
}
#endif
// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SSA
static int ParsingSubtitleSSA()
{
//BYTE tbuf[10];
UINT32 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 header ... until "[Events]"
while( strncmp( (const char*) bufptr, "[Events]", 8 ) != 0 )
{
if( bufptr >= bufend )
{
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
goto Change_To_Next_SubT;
#endif
goto err_sub;
}
bufptr++;
}
bufptr += 10;
while( !_iseol( bufptr ) )
bufptr++;
// 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 );
}
// error check omitted, should be "0x0D 0x0A" or "0x20"
while( _isspace( *bufptr ) )
bufptr++;
//until start time
while (*bufptr != ',')
bufptr++;
bufptr++;
if( (UINT32)( bufptr + uiOffset - base ) > s_uiSupLen )
break;
// mimitsai modify for another subtitle format of ssa
// get start time, xx:xx:xx,xx format, 11 bytes
if( *(bufptr + 1) != ':' )
{
hr = ((bufptr[0]-'0') * 10) + (bufptr[1]-'0');
bufptr += 3;
}
else // get start time, x:xx:xx,xx format, 10 bytes
{
hr = (bufptr[0]-'0');
bufptr += 2;
}
min = ((bufptr[0]-'0') * 10) + (bufptr[1]-'0');
sec = ((bufptr[3]-'0') * 10) + (bufptr[4]-'0');
ms = ((bufptr[6]-'0') * 100) + ((bufptr[7]-'0') * 10);
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
if((!_isdigit(bufptr[1]))||(!_isdigit(bufptr[4]))||(!_isdigit(bufptr[7])))
goto Change_To_Next_SubT;
#endif
sttime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;
bufptr += 8;
// drop seperation, ","
while ( !_isdigit( *bufptr ) )
bufptr++;
// get end time, x:xx:xx,xx format, 10 bytes
// get start time, xx:xx:xx,xx format, 11 bytes
if( *(bufptr + 1) != ':' )
{
hr = ((bufptr[0]-'0') * 10) + (bufptr[1]-'0');
bufptr += 3;
}
else // get start time, x:xx:xx,xx format, 10 bytes
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -