?? subtitle.c
字號:
// 2005/09/22 yltseng, add support for unix format new line
#include "SET.H"
#include "user_init.h"
#ifdef SUPPORT_MP4_SUBTITLE
#include "Subtitle.h"
#include "navdata.h"
#include "avsync.h"
#include "memmap0.h"
#include "atapi_if.h"
#include "util.h"
#include "stc.h"
#include "avd.h"
#include "kinf.h"
#include "file_if.h"
#include "cardfs.h"
#ifdef SUPPORT_UNICODE_FONT //joshua 2005/9/2
#include "font_unicode.h"
#endif
#ifndef DVDRELEASE
#define SUBTITLE_DBG 1
#endif
#include "fs_new.h"
#ifdef SUBTITLE_DBG
//#define DBG_SUBTITLE_BELONG_TO
//#define DBG_KEYFRAME
//#define DBG_FILL_SUBTITLE_BUFFER
//#define DBG_GET_CURRENT_STR
//#define DBG_PRINT_LOADED_BUFFER
#endif
#ifndef SUBTITLE_DBG
#undef printf
#undef print_block
#define printf(f, a...) do {} while (0)
#define print_block(x,y) do {} while (0)
#endif
#if defined (SUPPORT_SMI_MultiLanguage)||defined(SUPPORT_SMI_MultiColor)//2005-8-16 20:38 zhoulin
UINT8 SmiSupType;
#endif
#ifdef SUPPORT_SMI_MultiColor//2005-8-16 20:38 zhoulin
extern UINT32 palette_16color_MP4_SUB[16];
#define CLUTE_TRANS 0x80808000
typedef struct
{ UINT32 value;
BYTE *name;
} color_value;
const color_value color_mapping_table[]=//RGB
{
{0x00FFFF,"aqua"}, {0x808080 ,"gray"},
{0x000080,"navy"}, {0xC0C0C0 ,"silver"},
{0x000000,"black"}, {0x008000,"green"},
{0x808000,"olive"}, {0x008080,"teal"},
{0x0000FF,"blue"}, {0x00FF00,"lime"},
{0x800080,"purple"}, {0xFFFF00,"yellow"},
{0xFF00FF,"fuchsia"}, {0x800000,"maroon"},
{0xFF0000, "red"}, {0xFFFFFF,"white"},
};
#define MAX_color_mapping_Nm sizeof(color_mapping_table)/sizeof(color_value)
#define MAX_palette_colors 16
BYTE color_temp[MAX_palette_colors][20];
BYTE palette_color_num;
#endif//endif SUPPORT_SMI_MultiColor
#ifdef SUPPORT_SMI_MultiLanguage//2005-8-16 20:38 zhoulin
#define MAX_langs 5
BYTE lang_temp[MAX_langs][15];
BYTE lang_num;
BYTE nowSupLang=0;
#endif
#ifdef SUBTITLE_SUPPORT_ALL_FORMAT
#define SUBTITLE_SUPPORT_SRT
#define SUBTITLE_SUPPORT_SUB_MICRODVD
#define SUBTITLE_SUPPORT_SUB_SUBVIEWER
#define SUBTITLE_SUPPORT_SSA
#define SUBTITLE_SUPPORT_ASS
#define SUBTITLE_SUPPORT_SMI
#define SUBTITLE_SUPPORT_PSB
#define SUBTITLE_SUPPORT_TXT
#elif defined( SUBTITLE_SUPPORT_COMMON_FORMAT )
#define SUBTITLE_SUPPORT_SRT
#define SUBTITLE_SUPPORT_SMI
#endif
#ifdef SUBTITLE_SUPPORT_TXT
#define SUBTITLE_SUPPORT_SUB_SUBVIEWER
#define SUBTITLE_SUPPORT_TMplayerTXT
#endif
// **************************************************************************************** //
extern FSJPEGDATA* pFsJpeg;
extern BYTE ran_read( UINT8 *ptr,UINT32 msf,UINT32 len );
extern void DispCookOSD0(BYTE bChange);
extern void ShowOSDText(const char *p, UINT16 size);
extern void set_sub_title_Ns(UINT8 Ns);
extern void osd_ClearOneRegion(BYTE region, BYTE bkColor);//linrc 20050324
extern void osd_init_OSDSRT(void);
// **************************************************************************************** //
enum INTERNAL_SUP_TYPE
{
INTERNAL_SUBTITLE_UNKNOWN,
INTERNAL_SUBTITLE_SRT,
INTERNAL_SUBTITLE_SUB_MICRODVD,
INTERNAL_SUBTITLE_SUB_SUBVIEWER,
INTERNAL_SUBTITLE_SSA,
INTERNAL_SUBTITLE_ASS,
INTERNAL_SUBTITLE_SMI,
INTERNAL_SUBTITLE_PSB,
INTERNAL_SUBTITLE_TXT,
};
#define NUM_OF_BELONGTO 5
typedef struct
{
UINT32 loc;
UINT32 size;
UINT16 uiBelongTo[NUM_OF_BELONGTO];
UINT8 uiType;
} MP4_SUBTITLE;
typedef struct
{
char aName[128]; // file name( without extension )
UINT16 uiIndex; // Index to iso9660 DIR_REC( for video file ) or
// Index to subtitle_array( for subtitle file )
UINT8 uiType; // 0 for video file, 1 for subtitle file
} SUBTITLE_TEMP_DATA;
typedef struct
{
ifunc pfnParsingSubtitleFunc;
void (*pfnGetSubtitleData)( UINT32, void**, UINT32* );
char aExtName[4];
UINT8 uiExternalType;
UINT8 uiInternalType;
} SUBTITLE_INFO_ENTRY;
// **************************************************************************************** //
#define VIDEO_SUBTITLE_OFFSET ( _fs9660_buf + ( ( FS9660_SIZE - 1 ) << 10 ) ) // use last 1K size of file system structure
#define VIDEO_SUBTITLE_MAX ( 1024 / sizeof(MP4_SUBTITLE) )
#define subtitle_array ( (MP4_SUBTITLE *) VIDEO_SUBTITLE_OFFSET )
#define MATCHBUFSTART ( SDRAM_BASE_UNCACHED + ( ( SSAVER_YA ) << 10 ) )//( SDRAM_BASE_UNCACHED + ( ( JPEG_YA ) << 10 ) )
#define MATCHBUFSIZE ( ( SSAVER_PIC_SIZE ) << 10 )//( ( JPEG_CDBUF_SIZE ) << 10 )
#define MATCHBUFEND ( MATCHBUFSTART + MATCHBUFSIZE )
#define MS_STC_CLK (STC_CLK / 1000)
#define EXTSUPENTRYSIZE 4
#define SUBTITLE_RELOAD_LIMIT 2048 // must be mutiples of 1024
// avi_sup_state
#define EXT_SUP_RESET 0
#define EXT_SUP_INITIALIZED (1<<0)
#define EXT_SUP_ACTIVATED (1<<1)
#define EXT_SUP_INDISPLAY (1<<2)
#define EXT_SUP_NEXTREADY (1<<3)
#define EXT_SUP_NEEDDATA (1<<4)
// **************************************************************************************** //
void (*s_pfnGetSubtitleData)( UINT32, void**, UINT32* ) = NULL;
static ifunc s_pfnParsingSubtitleFunc = NULL;
ifunc g_pfnPollingSubtitle = NULL;
static UINT32 s_uiSupState;
static UINT32 s_uiSupLen;
static UINT32 s_uiSupLba;
static UINT32 s_uiSupStart;
static UINT32 s_uiSupEnd;
static UINT32* s_pSupIdxPtr = NULL;
static UINT32* s_pSupIdxEnd = NULL;
static UINT32 s_uiSupType = INTERNAL_SUBTITLE_UNKNOWN;
static UINT32* s_pSupIdxBasePtr = NULL;
static UINT32* s_pSubIdxBaseEndPtr = NULL;
static UINT32 s_uiSupIdxBaseSize = 0;
static BYTE* s_pSupBufPtr = NULL;
static BYTE* s_pSupBufEndPtr = NULL;
static UINT32 s_uiSupBufSize = 0;
static UINT16 s_uiSupCnt = 0;
static void* s_pPrevSup = NULL;
BYTE show_unsupported_message = 0;
// When Changing subtitle initiallization flowchart.
// we should parser two times and check s_supParseAgain.
//BYTE s_supParseAgain = 0; //2006-02-14 mimitsai add for changing sub-title language bug.
// **************************************************************************************** //
extern void ACTIVATE_EXT_SUP() { s_uiSupState |= EXT_SUP_ACTIVATED; }
extern void DISPLAY_EXT_SUP() { s_uiSupState |= EXT_SUP_INDISPLAY; }
extern void DEACTIVATE_EXT_SUP() { s_uiSupState &= (~EXT_SUP_ACTIVATED); }
extern void TURNOFF_EXT_SUP() { s_uiSupState &= (~EXT_SUP_INDISPLAY); }
extern int IS_EXT_SUP_INITIALIZED() { return s_uiSupState & EXT_SUP_INITIALIZED; }
extern int IS_EXT_SUP_ACTIVATED() { return s_uiSupState & EXT_SUP_ACTIVATED; }
extern int IS_EXT_SUP_INDISPLAY() { return s_uiSupState & EXT_SUP_INDISPLAY; }
extern int IS_EXT_SUP_NEEDDATA() { return s_uiSupState & EXT_SUP_NEEDDATA; }
static inline void RESET_EXT_SUP() { s_uiSupState = EXT_SUP_RESET; }
static inline void INITIALIZE_EXT_SUP() { s_uiSupState |= EXT_SUP_INITIALIZED; }
static inline void NEEDDATA_EXT_SUP() { s_uiSupState |= EXT_SUP_NEEDDATA; }
static inline void GOTDATA_EXT_SUP() { s_uiSupState &= (~EXT_SUP_NEEDDATA); }
static inline int supParseSubtitle( int iAVIFile, int iSubFile );
static inline int supParseSubtitleEntry( int );
static inline int supGetSubtitleCount( int iAVIFile );
static inline int supGetNthSubtitle( int iAVIFile, int iSubFile );
static inline void supSetSubtitleIdxBuffer( UINT32* pBufAddr, UINT32 uiSize );
static inline void supSetSubtitleDataBuffer( BYTE* pBufAddr, UINT32 uiSize );
static void supGetSubtitleDataTXT( UINT32 uiCurTime, void** pData, UINT32* pSize );
static UINT32 supFillBuffer( BYTE** ppCurrent, UINT32* pByteRead );
static inline int supPollingSubtitleSRT();
static int supReplaceSubString( char* pStr, int iSrcLen, const char* pStrSearch, const char* pStrReplace, int iMode );
static int supReplacePropertyString( char* pStr, int iSrcLen, const char* pStrSearch );
#if defined (SUPPORT_SMI_MultiLanguage)||defined(SUPPORT_SMI_MultiColor)
static int supReplacePropertyString_rt(char *pStr, int iSrcLen);
#endif
static inline void supModifyString( char* pStr, int iCnt );
// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SRT
static int ParsingSubtitleSRT();
#endif
#if defined( SUBTITLE_SUPPORT_SUB_MICRODVD ) || defined( SUBTITLE_SUPPORT_SUB_SUBVIEWER )
static int ParsingSubtitleSUB();
#ifdef SUBTITLE_SUPPORT_SUB_MICRODVD
static int ParsingSubtitleSUB_MicroDVD();
#endif
#ifdef SUBTITLE_SUPPORT_SUB_SUBVIEWER
static int ParsingSubtitleSUB_SubViewer();
#endif
#endif
#ifdef SUBTITLE_SUPPORT_SSA
static int ParsingSubtitleSSA();
#endif
#ifdef SUBTITLE_SUPPORT_ASS
static int ParsingSubtitleASS();
#endif
#ifdef SUBTITLE_SUPPORT_SMI
static int ParsingSubtitleSMI();
#endif
#ifdef SUBTITLE_SUPPORT_PSB
static int ParsingSubtitlePSB();
#endif
#ifdef SUBTITLE_SUPPORT_TXT
static int ParsingSubtitleTXT();
static int ParsingSubtitleTXT_TXT();
static int ParsingSubtitleTXT_TXT_OTHER();//denghg add for some Polish format x:xx:xx:
static int ParsingSubtitleTXT_TXT_Two_STimeData(); //lyc add 2006-3-15,for TCL more format .txt
static int ParsingSubtitleTXT_TXT_Two_USTimeData(); //lyc add 2006-3-15,for TCL more format .txt
static int ParsingSubtitleTXT_TXT_INTERFACE_TIME(); //lyc add 2006-3-15,an interface function for xx:xx:xx:/x:xx:xx:/xx:xx:xx:xx/ xx:xx:xx:xx aa xx:xx:xx:xx
#ifdef SUBTITLE_SUPPORT_TMplayerTXT
static int ParsingSubtitleTmPlayerTXT();
#endif
#endif
// **************************************************************************************** //
static SUBTITLE_INFO_ENTRY s_aSubtitleInfo[] =
{
#ifdef SUBTITLE_SUPPORT_SRT
{ ParsingSubtitleSRT, supGetSubtitleDataTXT, "SRT", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_SRT },
#endif
#if defined( SUBTITLE_SUPPORT_SUB_MICRODVD ) || defined( SUBTITLE_SUPPORT_SUB_SUBVIEWER )
{ ParsingSubtitleSUB, supGetSubtitleDataTXT, "SUB", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_SUB_MICRODVD },
#endif
#ifdef SUBTITLE_SUPPORT_SSA
{ ParsingSubtitleSSA, supGetSubtitleDataTXT, "SSA", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_SSA },
#endif
#ifdef SUBTITLE_SUPPORT_ASS
{ ParsingSubtitleASS, supGetSubtitleDataTXT, "ASS", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_ASS },
#endif
#ifdef SUBTITLE_SUPPORT_SMI
{ ParsingSubtitleSMI, supGetSubtitleDataTXT, "SMI", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_SMI },
#endif
#ifdef SUBTITLE_SUPPORT_PSB
{ ParsingSubtitlePSB, supGetSubtitleDataTXT, "PSB", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_PSB },
#endif
#ifdef SUBTITLE_SUPPORT_TXT
{ ParsingSubtitleTXT, supGetSubtitleDataTXT, "TXT", EXT_SUBTITLE_TXT, INTERNAL_SUBTITLE_TXT },
#endif
};
//#define Support_SubExName_Changed
#ifdef Support_SubExName_Changed //lyc add-2006-2-20
int supGetOtherFormat()
{
int i = 0;
int iResult = 0;
int InfoSize = sizeof( s_aSubtitleInfo ) / sizeof( SUBTITLE_INFO_ENTRY );
for( ; i <InfoSize; i++ )
{
s_pfnParsingSubtitleFunc = s_aSubtitleInfo[ i ].pfnParsingSubtitleFunc;
iResult = s_pfnParsingSubtitleFunc();
if((iResult == 1)&&(s_pSupIdxEnd>=s_pSupIdxPtr+EXTSUPENTRYSIZE)) //lyc add 2006-3-10,idx table not empty
break;
}
#ifdef DBG_KEYFRAME
printf("===Wrong Sub ExName !!, Now changed to Idx %d==\n",i);
#endif
return iResult;
}
#endif
//*********************************************************************************************//
#define _isascii(c) ( ((c) >= 0x00) && ((c) <= 0x7F) )
#define _iscntrl(c) ( ( ((c) >= 0x00) && ((c) <= 0x1F) ) || ((c) == 0x7F) )
#define _isprint(c) ( ((c) >= 0x20) && ((c) <= 0x7E) )
#define _isspace(c) ( ( ((c) >= 0x09) && ((c) <= 0x0D) ) || ((c) == 0x20) )
#define _islower(c) ( ((c) >= 'a') && ((c) <= 'z') )
#define _isupper(c) ( ((c) >= 'A') && ((c) <= 'Z') )
#define _isalpha(c) ( _isupper() || _islower() )
#define _isdigit(c) ( ((c) >= '0') && ((c) <= '9') )
#define _isxdigit(c) ( ( ((c) >= 'A') && ((c) <= 'F') ) || ( ((c) >= 'a') && ((c) <= 'f') ) || _isdigit() )
#define _isalnum(c) ( _isalpha(c) || _isdigit(c) )
//lyc add 2005-12-29,for SUBT FILE eol flag not "0D0A" but null
//denghg modify for || TO &&.if it is unix tail,last word will be eaten!!
#define _iseol_null(p) (( *((UINT8*)(p)) == 0x00 ) && ( *((UINT8*)(p+1)) == 0x00 ))
#define _iseol_unix(p) ( *((UINT8*)(p)) == 0x0A )
#define _iseol_win(p) ( ( *((UINT8*)(p)) == 0x0D ) && ( *(((UINT8*)(p))+1) == 0x0A ) )
#define _iseol(p) ( _iseol_unix(p) || _iseol_win(p) || _iseol_null(p))
//*********************************************************************************************//
// mimitsai move from avi_if.c
// FUNCTION
// supInitSubtitleParam()
//
// DESCRIPTION
// init Subtitle related parameters, variables
void supInitSubtitleParam()
{
file_extsub_buf = AVISUPBUF_START;
file_extsub_bufend = AVISUPBUF_END;
file_extsub_bufsize = AVISUPBUF_SIZE;
file_extsub_idx_buf = AVISUPIDX_START;
file_extsub_idx_bufend = AVISUPIDX_END;
file_extsub_idx_bufsize = AVISUPIDX_SIZE;
}
//*********************************************************************************************//
//compare two strings ,ignore uppercase and lowercase
extern int strncmpIgnoreCase(char *a,char *b,unsigned i)
{ unsigned j;
char c[i],d[i];
for(j=0;j<i;j++)
{
if(a[j]>='a'&&a[j]<='z')
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -