📄 demux_ty_osd.c
字号:
case 0x07: // misc (TAB) { for ( x = 0 ; x < ( b2 - 0x20 ) ; x++ ) TY_CC_CUR_X++; break; } } } } CC_last = data; return 0;}// ===========================================================================// Extended Data Service Decoding and OSD Presentation// ===========================================================================#define XDS_BUFFER_LENGTH ( 16 )#define XDS_DISPLAY_FRAMES ( 120 )static char *ty_XDS_Display[ XDS_BUFFER_LENGTH ];static int ty_XDSAddLine = -1;static int ty_XDSDisplayCount = -1;static void ty_AddXDSToDisplay( char *format, ... ){ char line[ 80 ]; int index; va_list ap; if ( ty_XDSAddLine == -1 ) { for( index = 0 ; index < XDS_BUFFER_LENGTH ; index++ ) { ty_XDS_Display[ index ] = 0; } ty_XDSAddLine = 0; } va_start( ap, format ); vsnprintf( line, 80, format, ap ); va_end( ap ); mp_msg( MSGT_DEMUX, MSGL_V, "XDS: %s\n", line ); if ( ty_XDSAddLine == XDS_BUFFER_LENGTH ) { mp_msg( MSGT_DEMUX, MSGL_ERR, "XDS Buffer would have been blown\n" ); } if ( ty_XDS_Display[ ty_XDSAddLine ] != 0 ) { free( ty_XDS_Display[ ty_XDSAddLine ] ); ty_XDS_Display[ ty_XDSAddLine ] = 0; } ty_XDS_Display[ ty_XDSAddLine ] = malloc( strlen( line ) + 1 ); strcpy( ty_XDS_Display[ ty_XDSAddLine ], line ); ty_XDSAddLine++;}static void ty_DisplayXDSInfo(){ int index; int size; if ( ty_XDSDisplayCount == -1 ) { for( index = 0 ; index < XDS_BUFFER_LENGTH ; index++ ) { if ( ty_XDS_Display[ index ] != 0 ) { break; } } if ( index != XDS_BUFFER_LENGTH ) { size = strlen( ty_XDS_Display[ index ] ); // Right Justify the XDS Stuff memcpy( &( ty_OSD1.text[ 0 ][ TY_CC_MAX_X - size - 1 ] ), ty_XDS_Display[ index ], size ); free( ty_XDS_Display[ index ] ); ty_XDS_Display[ index ] = 0; ty_XDSDisplayCount = 0; tyOSDUpdate = 1; } else { // We cleaned out all the XDS stuff to be displayed ty_XDSAddLine = 0; } } else { // We displayed that piece of XDS information long enough // Let's move on ty_XDSDisplayCount++; if ( ty_XDSDisplayCount >= XDS_DISPLAY_FRAMES ) { memset( ty_OSD1.text[ 0 ], ' ', TY_CC_MAX_X - 1 ); ty_OSD1.text[ 0 ][ TY_CC_MAX_X - 1 ] = 0; ty_XDSDisplayCount = -1; tyOSDUpdate = 1; } }}static int TY_XDS_mode = 0;static int TY_XDS_type = 0;static int TY_XDS_length = 0;static char TY_XDS_checksum = 0;// Array of [ Mode ][ Type ][ Length ]static char TY_XDS [ 8 ][ 25 ][ 34 ];static char TY_XDS_new[ 8 ][ 25 ][ 34 ];// Array of [ MPAARating|TVRating ][ NumberRatings ]static char *TY_XDS_CHIP[ 2 ][ 8 ] = { { "(NOT APPLICABLE)", "G", "PG", "PG-13", "R", "NC-17", "X", "(NOT RATED)" }, { "(NOT RATED)", "TV-Y", "TV-Y7", "TV-G", "TV-PG", "TV-14", "TV-MA", "(NOT RATED)" }};static char *TY_XDS_modes[] = { "CURRENT", // 01h-02h current program "FUTURE ", // 03h-04h future program "CHANNEL", // 05h-06h channel "MISC. ", // 07h-08h miscellaneous "PUBLIC ", // 09h-0Ah public service "RESERV.", // 0Bh-0Ch reserved "UNDEF. ", "INVALID", "INVALID", "INVALID"};static int ty_XDSdecode( char b1, char b2 ){ char line[ 80 ]; if ( b1 < 0x0F ) { // start packet TY_XDS_length = 0; TY_XDS_mode = b1 >> 1; // every other mode is a resume TY_XDS_type = b2; TY_XDS_checksum = b1 + b2; return 0; } TY_XDS_checksum += b1 + b2; // eof (next byte is checksum) if ( b1 == 0x0F ) { // validity check if ( !TY_XDS_length || TY_XDS_checksum & 0x7F ) { if ( TY_OSD_debug > 3 && !TY_XDS_length ) { mp_msg( MSGT_DEMUX, MSGL_DBG3, "%% TY_XDS CHECKSUM ERROR (ignoring)\n" ); } else { TY_XDS_mode = 0; TY_XDS_type = 0; return 1; } } // check to see if the data has changed. if ( strncmp( TY_XDS[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_length - 1 ) ) { char *TY_XDS_ptr = TY_XDS[ TY_XDS_mode ][ TY_XDS_type ]; TY_XDS_ptr[ TY_XDS_length ] = 0; memcpy( TY_XDS[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_length ); // nasty hack: only print time codes if seconds are 0 if ( TY_XDS_mode == 3 && TY_XDS_type == 1 && !( TY_XDS_new[ 3 ][ 1 ][ 3 ] & 0x20 ) ) { return 0; } if ( TY_XDS_mode == 0 && TY_XDS_type == 2 && ( TY_XDS_new[ 0 ][ 2 ][ 4 ] & 0x3f ) > 1 ) { return 0; } mp_msg( MSGT_DEMUX, MSGL_DBG3, "%% %s ", TY_XDS_modes[ TY_XDS_mode ] ); line[ 0 ] = 0; // printf( "XDS Code %x\n", // ( TY_XDS_mode << 9 ) + TY_XDS_type + 0x100 ); switch ( ( TY_XDS_mode << 9 ) + TY_XDS_type + 0x100 ) { // cases are specified in 2 bytes hex representing mode, type. // TY_XDS_ptr will point to the current class buffer case 0x0101: // current case 0x0301: // future { char *mon[] = { "0", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "13", "14", "15" }; ty_AddXDSToDisplay( "AIR DATE: %s %2d %d:%02d:00", mon[ TY_XDS_ptr[ 3 ] & 0x0f ], TY_XDS_ptr[ 2 ] & 0x1f, TY_XDS_ptr[ 1 ] & 0x1f, TY_XDS_ptr[ 0 ] & 0x3f ); // Program is tape delayed if ( TY_XDS_ptr[ 3 ] & 0x10 ) ty_AddXDSToDisplay( " TAPE" ); } break; case 0x0102: // current program length case 0x0302: // future { ty_AddXDSToDisplay( "DURATION: %d:%02d:%02d of %d:%02d:%02d", TY_XDS_ptr[ 3 ] & 0x3f, TY_XDS_ptr[ 2 ] & 0x3f, TY_XDS_ptr[ 4 ] & 0x3f, TY_XDS_ptr[ 1 ] & 0x3f, TY_XDS_ptr[ 0 ] & 0x3f, 0); break; } case 0x0103: // current program name case 0x0303: // future { ty_AddXDSToDisplay( "TITLE: %s", TY_XDS_ptr ); break; } case 0x0104: // current program type case 0x0304: // future { // for now just print out the raw data // requires a 127 string array to parse // properly and isn't worth it. sprintf ( line, "%sGENRE:", line ); { int x; for ( x = 0 ; x < TY_XDS_length ; x++ ) sprintf( line, "%s %02x", line, TY_XDS_ptr[ x ] ); } ty_AddXDSToDisplay( line ); break; } case 0x0105: // current program rating case 0x0305: // future { sprintf( line, "%sRATING: %s", line, TY_XDS_CHIP[ ( TY_XDS_ptr[ 0 ] & 0x08 ) >> 3 ] [ TY_XDS_ptr[ 1 ] & 0x07 ] ); if ( TY_XDS_ptr[ 0 ] & 0x20 ) sprintf( line, "%s DIALOGUE", line ); if ( TY_XDS_ptr[ 1 ] & 0x08 ) sprintf( line, "%s LANGUAGE", line ); if ( TY_XDS_ptr[ 1 ] & 0x10 ) sprintf( line, "%s SEXUAL", line ); if ( TY_XDS_ptr[ 1 ] & 0x20 ) sprintf( line, "%s VIOLENCE", line ); ty_AddXDSToDisplay( line ); // raw output for verification. if ( TY_OSD_debug > 1 ) mp_msg( MSGT_DEMUX, MSGL_DBG3, " (%02x %02x)", TY_XDS_ptr[ 0 ], TY_XDS_ptr[ 1 ] ); break; } case 0x0106: // current program audio services case 0x0306: // future { // requires table, never actually seen it used either ty_AddXDSToDisplay( "AUDIO: %02x %02x", TY_XDS_ptr[ 0 ], TY_XDS_ptr[ 1 ] ); break; } case 0x0109: // current program aspect ratio case 0x0309: // future { // requires table, rare ty_AddXDSToDisplay( "ASPECT: %02x %02x", TY_XDS_ptr[ 0 ], TY_XDS_ptr[ 1 ] ); break; } case 0x0110 ... 0x0117: // program description { ty_AddXDSToDisplay( "DESCRIP: %s", TY_XDS_ptr ); break; } case 0x0501: // channel network name { ty_AddXDSToDisplay( "NETWORK: %s", TY_XDS_ptr ); break; } case 0x0502: // channel network call letters { ty_AddXDSToDisplay( "CALLSIGN: %s", TY_XDS_ptr ); break; } case 0x0701: // misc. time of day {#define TIMEZONE ( TY_XDS[ 3 ][ 4 ][ 0 ] & 0x1f )#define DST ( ( TY_XDS[ 3 ][ 4 ][ 0 ] & 0x20 ) >> 5 ) struct tm tm = { .tm_sec = 0, // sec .tm_min = ( TY_XDS_ptr[ 0 ] & 0x3F ), // min .tm_hour = ( TY_XDS_ptr[ 1 ] & 0x1F ), // hour .tm_mday = ( TY_XDS_ptr[ 2 ] & 0x1F ), // day .tm_mon = ( TY_XDS_ptr[ 3 ] & 0x1f ) - 1, // month .tm_year = ( TY_XDS_ptr[ 5 ] & 0x3f ) + 90, // year .tm_wday = 0, // day of week .tm_yday = 0, // day of year .tm_isdst = 0, // DST }; time_t time_t = mktime( &tm ); char *timestr; time_t -= ( ( TIMEZONE - DST ) * 60 * 60 ); timestr = ctime( &time_t ); timestr[ strlen( timestr ) - 1 ] = 0; sprintf( line, "%sCUR.TIME: %s ", line, timestr ); if ( TY_XDS[ 3 ][ 4 ][ 0 ] ) { sprintf( line, "%sUTC-%d", line, TIMEZONE ); if (DST) sprintf( line, "%s DST", line ); } else sprintf( line, "%sUTC", line ); ty_AddXDSToDisplay( line ); break; } case 0x0704: //misc. local time zone { sprintf( line, "%sTIMEZONE: UTC-%d", line, TY_XDS_ptr[ 0 ] & 0x1f ); if ( TY_XDS_ptr[ 0 ] & 0x20 ) sprintf( line, "%s DST", line ); ty_AddXDSToDisplay( line ); break; } default: { mp_msg( MSGT_DEMUX, MSGL_DBG3, "UNKNOWN CLASS %d TYPE %d", ( TY_XDS_mode << 1 ) + 1, TY_XDS_type ); if ( TY_OSD_debug > 1 ) { int x; mp_msg( MSGT_DEMUX, MSGL_DBG3, "\nDUMP:\n" ); for ( x = 0 ; x < TY_XDS_length ; x++ ) mp_msg( MSGT_DEMUX, MSGL_DBG3, " %02x %c", TY_XDS_ptr[ x ], TY_XDS_ptr[ x ] ); mp_msg( MSGT_DEMUX, MSGL_DBG3, "\n" ); } } } if ( TY_OSD_debug > 1 ) mp_msg( MSGT_DEMUX, MSGL_DBG3, " (%d)", TY_XDS_length ); } TY_XDS_mode = 0; TY_XDS_type = 0; } else if ( TY_XDS_length < 34 ) { TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ][ TY_XDS_length++ ] = b1; TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ][ TY_XDS_length++ ] = b2; } return 0;}// 42 x 10static char *testline = "0123456789012345678901234567890123456789012";// ===========================================================================// Callback from Video Display Processing to put up the OSD// ===========================================================================void ty_processuserdata( unsigned char* buf, int len ){ int index; sub_justify = 1; if ( subcc_enabled ) { if ( tyOSDInited == 0 ) { for ( index = 0; index < SUB_MAX_TEXT ; index++ ) { ty_OSD1.text[ index ] = malloc( TY_CC_MAX_X ); ty_OSD2.text[ index ] = malloc( TY_CC_MAX_X ); } ty_ClearOSD( 0 ); ty_OSD1.lines = SUB_MAX_TEXT; ty_OSD2.lines = SUB_MAX_TEXT; ty_pOSD1 = &ty_OSD1; ty_pOSD2 = &ty_OSD2; tyOSDUpdate = 0; tyOSDInited = 1; } if ( buf[ 0 ] == 0x01 ) { ty_CCdecode( buf[ 1 ], buf[ 2 ] ); } if ( buf[ 0 ] == 0x02 ) { ty_XDSdecode( buf[ 1 ], buf[ 2 ] ); } ty_DisplayXDSInfo(); if ( tyOSDUpdate ) { // for ( index = 0; index < SUB_MAX_TEXT ; index++ ) // { // printf( "OSD:%d:%s\n", index, ty_OSD1.text[ index ] ); // } vo_sub = &ty_OSD1; vo_osd_changed( OSDTYPE_SUBTITLE ); tyOSDUpdate = 0; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -