Patch by Stefan Huehner / stefan % huehner ! org \
[mplayer/glamo.git] / libmpdemux / demux_ty_osd.c
blobd68c7a5ff788ea397d9311e57884fd538bfe37f1
1 // Most of this was written by mbm@linux.com and released on the GPL2 License.
2 //
3 // Modifications and SEVERE cleanup of the code was done by
4 // Christopher Wingert
5 // Copyright 2003
6 //
7 // Released under GPL2 License.
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <time.h>
13 #include <stdarg.h>
14 #include <string.h>
16 #include "config.h"
17 #include "mp_msg.h"
18 #include "help_mp.h"
20 //#include "stream.h"
21 //#include "demuxer.h"
22 //#include "parse_es.h"
23 //#include "stheader.h"
24 //#include "mp3_hdr.h"
25 //#include "subreader.h"
26 #include "sub_cc.h"
27 #include "libvo/sub.h"
29 //#include "dvdauth.h"
31 extern int sub_justify;
33 #define TY_TEXT_MODE ( 1 << 0 )
34 #define TY_OSD_MODE ( 1 << 1 )
36 static int TY_OSD_flags = TY_TEXT_MODE | TY_OSD_MODE;
37 static int TY_OSD_debug = 0;
39 // ===========================================================================
40 // Closed Caption Decoding and OSD Presentation
41 // ===========================================================================
42 #define TY_CCNONE ( -3 )
43 #define TY_CCTEXTMODE ( -2 )
44 #define TY_CCPOPUPNB ( -1 )
45 #define TY_CCPOPUP ( 0 )
46 #define TY_CCPAINTON ( 1 )
48 #define TY_CC_MAX_X ( 45 )
50 static int TY_CC_CUR_X;
51 static int TY_CC_CUR_Y;
52 static int TY_CC_stat = TY_CCNONE;
53 static char TY_CC_buf[ 255 ];
54 static char *TY_CC_ptr = TY_CC_buf;
55 static unsigned TY_CC_lastcap = 0;
56 static int TY_CC_TextItalic;
57 static int TY_CC_Y_Offset;
59 static subtitle ty_OSD1;
60 static subtitle ty_OSD2;
61 static subtitle *ty_pOSD1;
62 static subtitle *ty_pOSD2;
63 static int tyOSDInited = 0;
64 static int tyOSDUpdate = 0;
66 static void ty_DrawOSD(void)
68 // printf( "Calling ty_DrawOSD()\n" );
69 tyOSDUpdate = 1;
72 void ty_ClearOSD( int start )
74 int index;
75 // printf( "Calling ty_ClearOSD()\n" );
76 for ( index = start ; index < SUB_MAX_TEXT ; index++ )
78 memset( ty_OSD1.text[ index ], ' ', TY_CC_MAX_X - 1 );
79 ty_OSD1.text[ index ][ TY_CC_MAX_X - 1 ] = 0;
80 memset( ty_OSD2.text[ index ], ' ', TY_CC_MAX_X - 1 );
81 ty_OSD2.text[ index ][ TY_CC_MAX_X - 1 ] = 0;
85 static void ty_DrawChar( int *x, int *y, char disChar, int fgColor, int bgColor )
87 int index;
88 int cx;
89 int cy;
91 cx = *x;
92 cy = *y;
94 if ( *x >= ( TY_CC_MAX_X - 1 ) )
96 cx = 0;
98 if ( ( *y + TY_CC_Y_Offset ) > SUB_MAX_TEXT )
100 cy = SUB_MAX_TEXT - TY_CC_Y_Offset - 1;
103 // printf( "Calling ty_DrawChar() x:%d y:%d %c fg:%d bg:%d\n",
104 // cx, cy, disChar, fgColor, bgColor );
106 ty_OSD1.text[ TY_CC_Y_Offset + cy ][ cx ] = disChar;
107 memset( &( ty_OSD1.text[ TY_CC_Y_Offset + cy ][ cx + 1 ] ), ' ',
108 TY_CC_MAX_X - cx - 2 );
109 ( *x )++;
112 static void ty_RollupBuf( int dest, int source, int numLines )
114 int index;
116 // printf( "Calling ty_RollupBuf() dest:%d source %d, numLines %d\n",
117 // dest, source, numLines );
119 if ( ( source + TY_CC_Y_Offset + numLines ) > SUB_MAX_TEXT )
121 ty_ClearOSD( 1 );
122 return;
125 if ( ( source + TY_CC_Y_Offset + numLines ) < 0 )
127 ty_ClearOSD( 1 );
128 return;
131 if ( numLines > SUB_MAX_TEXT )
133 ty_ClearOSD( 1 );
134 return;
137 for ( index = 0 ; index < numLines ; index++ )
139 strcpy( ty_OSD1.text[ TY_CC_Y_Offset + dest ],
140 ty_OSD1.text[ TY_CC_Y_Offset + source ] );
141 dest++;
142 source++;
144 memset( ty_OSD1.text[ TY_CC_Y_Offset + source - 1 ], ' ', TY_CC_MAX_X - 1 );
145 ty_OSD1.text[ TY_CC_Y_Offset + source - 1 ][ TY_CC_MAX_X - 1 ] = 0;
148 static void ty_drawchar( char c )
150 if ( c < 2 ) return;
152 if ( TY_OSD_flags & TY_OSD_MODE && TY_CC_stat != TY_CCNONE &&
153 TY_CC_CUR_Y != -1 )
154 ty_DrawChar( &TY_CC_CUR_X, &TY_CC_CUR_Y, c, 4, 13 );
156 if ( TY_CC_ptr - TY_CC_buf > sizeof( TY_CC_buf ) - 1 )
157 { // buffer overflow
158 TY_CC_ptr = TY_CC_buf;
159 memset( TY_CC_buf, 0, sizeof( TY_CC_buf ) );
161 *( TY_CC_ptr++ ) = ( c == 14 ) ? '/' : c; // swap a '/' for musical note
164 static void ty_draw(void)
166 if ( TY_CC_ptr != TY_CC_buf && TY_OSD_flags & TY_TEXT_MODE )
168 if ( *( TY_CC_ptr - 1 ) == '\n' ) *( TY_CC_ptr - 1 ) = 0;
170 mp_msg( MSGT_DEMUX, MSGL_V, "CC: %s\n", TY_CC_buf );
172 TY_CC_lastcap = time( NULL );
174 TY_CC_ptr = TY_CC_buf;
175 memset( TY_CC_buf, 0, sizeof( TY_CC_buf) );
177 if ( TY_OSD_flags & TY_OSD_MODE ) ty_DrawOSD();
178 if ( TY_CC_TextItalic ) TY_CC_TextItalic = 0;
182 static int CC_last = 0;
183 static char CC_mode = 0;
184 static int CC_row[] =
186 11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
189 // char specialchar[] = { '®', '°', '½', '¿', '*', '¢', '£', 14, 'à', ' ', 'è', 'â', 'ê', 'î', 'ô', 'û' };
191 static int ty_CCdecode( char b1, char b2 )
193 int x;
194 int data = ( b2 << 8 ) + b1;
196 if ( b1 & 0x60 ) // text
198 if ( !TY_OSD_debug && TY_CC_stat == TY_CCNONE ) return 0;
199 if ( TY_OSD_debug > 3 )
201 mp_msg( MSGT_DEMUX, MSGL_DBG3, "%c %c", b1, b2 );
203 ty_drawchar( b1 );
204 ty_drawchar( b2 );
206 if ( TY_CC_stat > 0 && TY_OSD_flags & TY_OSD_MODE ) ty_DrawOSD();
208 else if ( ( b1 & 0x10 ) && ( b2 > 0x1F ) && ( data != CC_last ) )
210 #define CURRENT ( ( b1 & 0x08 ) >> 3 )
212 if ( CC_mode != CURRENT && TY_CC_stat != TY_CCNONE )
214 if ( TY_OSD_debug && TY_CC_ptr != TY_CC_buf ) ty_draw();
215 TY_CC_stat = TY_CCNONE;
216 return 0;
219 if ( TY_CC_stat == TY_CCNONE || TY_CC_CUR_Y == -1 )
221 if ( TY_CC_ptr != TY_CC_buf )
223 if ( TY_OSD_debug )
224 mp_msg( MSGT_DEMUX, MSGL_DBG3, "(TY_OSD_debug) %s\n",
225 TY_CC_buf );
226 TY_CC_ptr = TY_CC_buf;
227 memset(TY_CC_buf, 0, sizeof(TY_CC_buf));
230 if ( CC_mode != CURRENT ) return 0;
233 // preamble address code (row & indent)
234 if ( b2 & 0x40 )
236 TY_CC_CUR_Y = CC_row[ ( ( b1 << 1 ) & 14 ) | ( ( b2 >> 5 ) & 1 ) ];
238 // Offset into MPlayer's Buffer
239 if ( ( TY_CC_CUR_Y >= 1 ) && ( TY_CC_CUR_Y <= 4 ) )
241 TY_CC_Y_Offset = SUB_MAX_TEXT - 5 - 1;
243 if ( ( TY_CC_CUR_Y >= 5 ) && ( TY_CC_CUR_Y <= 10 ) )
245 TY_CC_Y_Offset = SUB_MAX_TEXT - 5 - 5;
247 if ( ( TY_CC_CUR_Y >= 12 ) && ( TY_CC_CUR_Y <= 15 ) )
249 TY_CC_Y_Offset = SUB_MAX_TEXT - 5 - 12;
252 if ( TY_OSD_debug > 3 )
253 mp_msg( MSGT_DEMUX, MSGL_DBG3, "<< preamble %d >>\n", TY_CC_CUR_Y );
255 // we still have something in the text buffer
256 if (TY_CC_ptr != TY_CC_buf)
258 *(TY_CC_ptr++) = '\n';
259 if ( TY_CC_TextItalic )
261 TY_CC_TextItalic = 0;
265 TY_CC_CUR_X = 1;
266 // row contains indent flag
267 if ( b2 & 0x10 )
269 for ( x = 0 ; x < ( ( b2 & 0x0F ) << 1 ) ; x++ )
271 TY_CC_CUR_X++;
272 *(TY_CC_ptr++) = ' ';
276 else
277 // !(b2 & 0x40)
279 if ( TY_OSD_debug > 3 )
280 mp_msg( MSGT_DEMUX, MSGL_DBG3, "<< %02x >>\n", b1 & 0x7 );
281 switch (b1 & 0x07)
283 case 0x00: // attribute
285 if ( TY_OSD_debug > 1 )
286 mp_msg( MSGT_DEMUX, MSGL_DBG3, "<<A: %d>>\n", b2 );
287 break;
289 case 0x01: // midrow or char
291 switch (b2 & 0x70)
293 case 0x20: // midrow attribute change
295 switch (b2 & 0x0e)
297 case 0x00: // italics off
299 TY_CC_TextItalic = 0;
300 *(TY_CC_ptr++) = ' ';
301 break;
303 case 0x0e: // italics on
305 ty_drawchar(' ');
306 TY_CC_TextItalic = 1;
307 break;
309 default:
311 if ( TY_OSD_debug > 1 )
312 mp_msg( MSGT_DEMUX, MSGL_DBG3, "<<D: %d>>\n",
313 b2 & 0x0e );
316 if ( b2 & 0x01 )
318 // TextUnderline = 1;
320 else
322 // TextUnderline = 0;
324 break;
326 case 0x30: // special character..
328 // transparent space
329 if ( ( b2 & 0x0f ) == 9 )
331 TY_CC_CUR_X++;
332 *(TY_CC_ptr++) = ' ';
334 else
336 // ty_drawchar(specialchar[ b2 & 0x0f ] );
337 ty_drawchar( ' ' );
339 break;
342 break;
345 case 0x04: // misc
346 case 0x05: // misc + F
348 if ( TY_OSD_debug > 3 )
349 mp_msg( MSGT_DEMUX, MSGL_DBG3, "<< misc %02x >>\n", b2 );
350 switch ( b2 )
352 case 0x20: // resume caption (new caption)
354 if ( TY_OSD_flags & TY_OSD_MODE &&
355 TY_CC_stat != TY_CCPOPUP )
356 ty_ClearOSD( 1 );
357 TY_CC_stat = TY_CCPOPUP;
358 break;
361 case 0x21: // backspace
363 TY_CC_CUR_X--;
364 break;
367 case 0x25 ... 0x27: // 2-4 row captions
369 if ( TY_CC_stat == TY_CCPOPUP ) ty_ClearOSD( 1 );
370 TY_CC_stat = b2 - 0x23;
371 if ( TY_CC_CUR_Y < TY_CC_stat ) TY_CC_CUR_Y = TY_CC_stat;
372 break;
375 case 0x29: // resume direct caption
377 TY_CC_stat = TY_CCPAINTON;
378 break;
381 case 0x2A: // text restart
383 ty_draw();
384 /* FALL */
387 case 0x2B: // resume text display
389 TY_CC_stat = TY_CCTEXTMODE;
390 break;
393 case 0x2C: // erase displayed memory
395 TY_CC_lastcap = 0;
396 if ( TY_OSD_flags & TY_OSD_MODE )
398 if ( TY_CC_stat > TY_CCPOPUP || TY_CC_ptr == TY_CC_buf )
400 ty_ClearOSD( 1 );
401 ty_draw();
403 else
405 ty_ClearOSD( 1 );
407 // CRW -
408 // new buffer
409 // Used to be a buffer swap here, dunno why
412 break;
415 case 0x2D: // carriage return
417 ty_draw();
418 TY_CC_CUR_X = 1;
419 if ( TY_OSD_flags & TY_OSD_MODE )
421 if ( TY_CC_stat > TY_CCPAINTON )
422 ty_RollupBuf
424 TY_CC_CUR_Y - TY_CC_stat + 1 ,
425 TY_CC_CUR_Y - TY_CC_stat + 2,
426 TY_CC_stat - 1
428 else
429 TY_CC_CUR_Y++;
431 break;
434 case 0x2F: // end caption + swap memory
436 ty_draw();
437 /* FALL THROUGH TO 0x2E */
440 case 0x2E: // erase non-displayed memory
442 if ( TY_OSD_debug && TY_CC_ptr != TY_CC_buf )
443 mp_msg( MSGT_DEMUX, MSGL_DBG3, "(TY_OSD_debug) %s\n",
444 TY_CC_buf );
445 if ( TY_OSD_flags & TY_OSD_MODE ) ty_ClearOSD( 1 );
447 TY_CC_CUR_X = 1;
448 TY_CC_CUR_Y = -1;
450 TY_CC_ptr = TY_CC_buf;
451 memset( TY_CC_buf, 0, sizeof( TY_CC_buf ) );
454 break;
456 case 0x07: // misc (TAB)
458 for ( x = 0 ; x < ( b2 - 0x20 ) ; x++ )
459 TY_CC_CUR_X++;
460 break;
465 CC_last = data;
466 return 0;
469 // ===========================================================================
470 // Extended Data Service Decoding and OSD Presentation
471 // ===========================================================================
472 #define XDS_BUFFER_LENGTH ( 16 )
473 #define XDS_DISPLAY_FRAMES ( 120 )
474 static char *ty_XDS_Display[ XDS_BUFFER_LENGTH ];
475 static int ty_XDSAddLine = -1;
476 static int ty_XDSDisplayCount = -1;
479 static void ty_AddXDSToDisplay( char *format, ... )
481 char line[ 80 ];
482 int index;
483 va_list ap;
485 if ( ty_XDSAddLine == -1 )
487 for( index = 0 ; index < XDS_BUFFER_LENGTH ; index++ )
489 ty_XDS_Display[ index ] = 0;
491 ty_XDSAddLine = 0;
494 va_start( ap, format );
495 vsnprintf( line, 80, format, ap );
496 va_end( ap );
497 mp_msg( MSGT_DEMUX, MSGL_V, "XDS: %s\n", line );
499 if ( ty_XDSAddLine == XDS_BUFFER_LENGTH )
501 mp_msg( MSGT_DEMUX, MSGL_ERR, "XDS Buffer would have been blown\n" );
504 if ( ty_XDS_Display[ ty_XDSAddLine ] != 0 )
506 free( ty_XDS_Display[ ty_XDSAddLine ] );
507 ty_XDS_Display[ ty_XDSAddLine ] = 0;
510 ty_XDS_Display[ ty_XDSAddLine ] = malloc( strlen( line ) + 1 );
511 strcpy( ty_XDS_Display[ ty_XDSAddLine ], line );
512 ty_XDSAddLine++;
516 static void ty_DisplayXDSInfo(void)
518 int index;
519 int size;
521 if ( ty_XDSDisplayCount == -1 )
523 for( index = 0 ; index < XDS_BUFFER_LENGTH ; index++ )
525 if ( ty_XDS_Display[ index ] != 0 )
527 break;
530 if ( index != XDS_BUFFER_LENGTH )
532 size = strlen( ty_XDS_Display[ index ] );
534 // Right Justify the XDS Stuff
535 memcpy( &( ty_OSD1.text[ 0 ][ TY_CC_MAX_X - size - 1 ] ),
536 ty_XDS_Display[ index ], size );
537 free( ty_XDS_Display[ index ] );
538 ty_XDS_Display[ index ] = 0;
539 ty_XDSDisplayCount = 0;
540 tyOSDUpdate = 1;
543 else
545 // We cleaned out all the XDS stuff to be displayed
546 ty_XDSAddLine = 0;
549 else
551 // We displayed that piece of XDS information long enough
552 // Let's move on
553 ty_XDSDisplayCount++;
554 if ( ty_XDSDisplayCount >= XDS_DISPLAY_FRAMES )
556 memset( ty_OSD1.text[ 0 ], ' ', TY_CC_MAX_X - 1 );
557 ty_OSD1.text[ 0 ][ TY_CC_MAX_X - 1 ] = 0;
558 ty_XDSDisplayCount = -1;
559 tyOSDUpdate = 1;
565 static int TY_XDS_mode = 0;
566 static int TY_XDS_type = 0;
567 static int TY_XDS_length = 0;
568 static char TY_XDS_checksum = 0;
570 // Array of [ Mode ][ Type ][ Length ]
571 static char TY_XDS [ 8 ][ 25 ][ 34 ];
572 static char TY_XDS_new[ 8 ][ 25 ][ 34 ];
574 // Array of [ MPAARating|TVRating ][ NumberRatings ]
575 static char *TY_XDS_CHIP[ 2 ][ 8 ] =
577 { "(NOT APPLICABLE)", "G", "PG", "PG-13", "R", "NC-17", "X", "(NOT RATED)" },
578 { "(NOT RATED)", "TV-Y", "TV-Y7", "TV-G", "TV-PG", "TV-14", "TV-MA",
579 "(NOT RATED)" }
582 static char *TY_XDS_modes[] =
584 "CURRENT", // 01h-02h current program
585 "FUTURE ", // 03h-04h future program
586 "CHANNEL", // 05h-06h channel
587 "MISC. ", // 07h-08h miscellaneous
588 "PUBLIC ", // 09h-0Ah public service
589 "RESERV.", // 0Bh-0Ch reserved
590 "UNDEF. ",
591 "INVALID",
592 "INVALID",
593 "INVALID"
596 static int ty_XDSdecode( char b1, char b2 )
598 char line[ 80 ];
600 if ( b1 < 0x0F )
601 { // start packet
602 TY_XDS_length = 0;
603 TY_XDS_mode = b1 >> 1; // every other mode is a resume
604 TY_XDS_type = b2;
605 TY_XDS_checksum = b1 + b2;
606 return 0;
609 TY_XDS_checksum += b1 + b2;
611 // eof (next byte is checksum)
612 if ( b1 == 0x0F )
614 // validity check
615 if ( !TY_XDS_length || TY_XDS_checksum & 0x7F )
617 if ( TY_OSD_debug > 3 && !TY_XDS_length )
619 mp_msg( MSGT_DEMUX, MSGL_DBG3,
620 "%% TY_XDS CHECKSUM ERROR (ignoring)\n" );
622 else
624 TY_XDS_mode = 0;
625 TY_XDS_type = 0;
626 return 1;
630 // check to see if the data has changed.
631 if ( strncmp( TY_XDS[ TY_XDS_mode ][ TY_XDS_type ],
632 TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_length - 1 ) )
634 char *TY_XDS_ptr = TY_XDS[ TY_XDS_mode ][ TY_XDS_type ];
636 TY_XDS_ptr[ TY_XDS_length ] = 0;
637 memcpy( TY_XDS[ TY_XDS_mode ][ TY_XDS_type ],
638 TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ], TY_XDS_length );
640 // nasty hack: only print time codes if seconds are 0
641 if ( TY_XDS_mode == 3 && TY_XDS_type == 1 &&
642 !( TY_XDS_new[ 3 ][ 1 ][ 3 ] & 0x20 ) )
644 return 0;
646 if ( TY_XDS_mode == 0 && TY_XDS_type == 2 &&
647 ( TY_XDS_new[ 0 ][ 2 ][ 4 ] & 0x3f ) > 1 )
649 return 0;
652 mp_msg( MSGT_DEMUX, MSGL_DBG3, "%% %s ", TY_XDS_modes[ TY_XDS_mode ] );
654 line[ 0 ] = 0;
655 // printf( "XDS Code %x\n",
656 // ( TY_XDS_mode << 9 ) + TY_XDS_type + 0x100 );
657 switch ( ( TY_XDS_mode << 9 ) + TY_XDS_type + 0x100 )
659 // cases are specified in 2 bytes hex representing mode, type.
660 // TY_XDS_ptr will point to the current class buffer
661 case 0x0101: // current
662 case 0x0301: // future
664 char *mon[] =
666 "0", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
667 "Aug", "Sep", "Oct", "Nov", "Dec", "13", "14", "15"
669 ty_AddXDSToDisplay( "AIR DATE: %s %2d %d:%02d:00",
670 mon[ TY_XDS_ptr[ 3 ] & 0x0f ],
671 TY_XDS_ptr[ 2 ] & 0x1f,
672 TY_XDS_ptr[ 1 ] & 0x1f,
673 TY_XDS_ptr[ 0 ] & 0x3f
676 // Program is tape delayed
677 if ( TY_XDS_ptr[ 3 ] & 0x10 ) ty_AddXDSToDisplay( " TAPE" );
679 break;
681 case 0x0102: // current program length
682 case 0x0302: // future
684 ty_AddXDSToDisplay(
685 "DURATION: %d:%02d:%02d of %d:%02d:%02d",
686 TY_XDS_ptr[ 3 ] & 0x3f,
687 TY_XDS_ptr[ 2 ] & 0x3f,
688 TY_XDS_ptr[ 4 ] & 0x3f,
689 TY_XDS_ptr[ 1 ] & 0x3f,
690 TY_XDS_ptr[ 0 ] & 0x3f, 0);
691 break;
694 case 0x0103: // current program name
695 case 0x0303: // future
697 ty_AddXDSToDisplay( "TITLE: %s", TY_XDS_ptr );
698 break;
701 case 0x0104: // current program type
702 case 0x0304: // future
704 // for now just print out the raw data
705 // requires a 127 string array to parse
706 // properly and isn't worth it.
707 sprintf ( line, "%sGENRE:", line );
709 int x;
710 for ( x = 0 ; x < TY_XDS_length ; x++ )
711 sprintf( line, "%s %02x", line, TY_XDS_ptr[ x ] );
713 ty_AddXDSToDisplay( line );
714 break;
717 case 0x0105: // current program rating
718 case 0x0305: // future
720 sprintf( line, "%sRATING: %s", line,
721 TY_XDS_CHIP[ ( TY_XDS_ptr[ 0 ] & 0x08 ) >> 3 ]
722 [ TY_XDS_ptr[ 1 ] & 0x07 ] );
723 if ( TY_XDS_ptr[ 0 ] & 0x20 )
724 sprintf( line, "%s DIALOGUE", line );
725 if ( TY_XDS_ptr[ 1 ] & 0x08 )
726 sprintf( line, "%s LANGUAGE", line );
727 if ( TY_XDS_ptr[ 1 ] & 0x10 )
728 sprintf( line, "%s SEXUAL", line );
729 if ( TY_XDS_ptr[ 1 ] & 0x20 )
730 sprintf( line, "%s VIOLENCE", line );
731 ty_AddXDSToDisplay( line );
733 // raw output for verification.
734 if ( TY_OSD_debug > 1 )
735 mp_msg( MSGT_DEMUX, MSGL_DBG3, " (%02x %02x)",
736 TY_XDS_ptr[ 0 ], TY_XDS_ptr[ 1 ] );
737 break;
740 case 0x0106: // current program audio services
741 case 0x0306: // future
743 // requires table, never actually seen it used either
744 ty_AddXDSToDisplay( "AUDIO: %02x %02x", TY_XDS_ptr[ 0 ],
745 TY_XDS_ptr[ 1 ] );
746 break;
749 case 0x0109: // current program aspect ratio
750 case 0x0309: // future
752 // requires table, rare
753 ty_AddXDSToDisplay( "ASPECT: %02x %02x",
754 TY_XDS_ptr[ 0 ], TY_XDS_ptr[ 1 ] );
755 break;
758 case 0x0110 ... 0x0117: // program description
760 ty_AddXDSToDisplay( "DESCRIP: %s", TY_XDS_ptr );
761 break;
764 case 0x0501: // channel network name
766 ty_AddXDSToDisplay( "NETWORK: %s", TY_XDS_ptr );
767 break;
770 case 0x0502: // channel network call letters
772 ty_AddXDSToDisplay( "CALLSIGN: %s", TY_XDS_ptr );
773 break;
776 case 0x0701: // misc. time of day
778 #define TIMEZONE ( TY_XDS[ 3 ][ 4 ][ 0 ] & 0x1f )
779 #define DST ( ( TY_XDS[ 3 ][ 4 ][ 0 ] & 0x20 ) >> 5 )
780 struct tm tm =
782 .tm_sec = 0, // sec
783 .tm_min = ( TY_XDS_ptr[ 0 ] & 0x3F ), // min
784 .tm_hour = ( TY_XDS_ptr[ 1 ] & 0x1F ), // hour
785 .tm_mday = ( TY_XDS_ptr[ 2 ] & 0x1F ), // day
786 .tm_mon = ( TY_XDS_ptr[ 3 ] & 0x1f ) - 1, // month
787 .tm_year = ( TY_XDS_ptr[ 5 ] & 0x3f ) + 90, // year
788 .tm_wday = 0, // day of week
789 .tm_yday = 0, // day of year
790 .tm_isdst = 0, // DST
793 time_t time_t = mktime( &tm );
794 char *timestr;
796 time_t -= ( ( TIMEZONE - DST ) * 60 * 60 );
797 timestr = ctime( &time_t );
798 timestr[ strlen( timestr ) - 1 ] = 0;
800 sprintf( line, "%sCUR.TIME: %s ", line, timestr );
801 if ( TY_XDS[ 3 ][ 4 ][ 0 ] )
803 sprintf( line, "%sUTC-%d", line, TIMEZONE );
804 if (DST) sprintf( line, "%s DST", line );
806 else
807 sprintf( line, "%sUTC", line );
809 ty_AddXDSToDisplay( line );
811 break;
814 case 0x0704: //misc. local time zone
816 sprintf( line, "%sTIMEZONE: UTC-%d",
817 line, TY_XDS_ptr[ 0 ] & 0x1f );
818 if ( TY_XDS_ptr[ 0 ] & 0x20 ) sprintf( line, "%s DST", line );
819 ty_AddXDSToDisplay( line );
820 break;
823 default:
825 mp_msg( MSGT_DEMUX, MSGL_DBG3, "UNKNOWN CLASS %d TYPE %d",
826 ( TY_XDS_mode << 1 ) + 1, TY_XDS_type );
827 if ( TY_OSD_debug > 1 )
829 int x;
830 mp_msg( MSGT_DEMUX, MSGL_DBG3, "\nDUMP:\n" );
831 for ( x = 0 ; x < TY_XDS_length ; x++ )
832 mp_msg( MSGT_DEMUX, MSGL_DBG3, " %02x %c",
833 TY_XDS_ptr[ x ], TY_XDS_ptr[ x ] );
834 mp_msg( MSGT_DEMUX, MSGL_DBG3, "\n" );
838 if ( TY_OSD_debug > 1 )
839 mp_msg( MSGT_DEMUX, MSGL_DBG3, " (%d)", TY_XDS_length );
841 TY_XDS_mode = 0;
842 TY_XDS_type = 0;
844 else if ( TY_XDS_length < 34 )
846 TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ][ TY_XDS_length++ ] = b1;
847 TY_XDS_new[ TY_XDS_mode ][ TY_XDS_type ][ TY_XDS_length++ ] = b2;
849 return 0;
853 // 42 x 10
854 static char *testline = "0123456789012345678901234567890123456789012";
856 // ===========================================================================
857 // Callback from Video Display Processing to put up the OSD
858 // ===========================================================================
859 void ty_processuserdata( unsigned char* buf, int len )
861 int index;
863 sub_justify = 1;
865 if ( subcc_enabled )
867 if ( tyOSDInited == 0 )
869 for ( index = 0; index < SUB_MAX_TEXT ; index++ )
871 ty_OSD1.text[ index ] = malloc( TY_CC_MAX_X );
872 ty_OSD2.text[ index ] = malloc( TY_CC_MAX_X );
874 ty_ClearOSD( 0 );
875 ty_OSD1.lines = SUB_MAX_TEXT;
876 ty_OSD2.lines = SUB_MAX_TEXT;
877 ty_pOSD1 = &ty_OSD1;
878 ty_pOSD2 = &ty_OSD2;
879 tyOSDUpdate = 0;
880 tyOSDInited = 1;
883 if ( buf[ 0 ] == 0x01 )
885 ty_CCdecode( buf[ 1 ], buf[ 2 ] );
887 if ( buf[ 0 ] == 0x02 )
889 ty_XDSdecode( buf[ 1 ], buf[ 2 ] );
892 ty_DisplayXDSInfo();
894 if ( tyOSDUpdate )
896 // for ( index = 0; index < SUB_MAX_TEXT ; index++ )
897 // {
898 // printf( "OSD:%d:%s\n", index, ty_OSD1.text[ index ] );
899 // }
900 vo_sub = &ty_OSD1;
901 vo_osd_changed( OSDTYPE_SUBTITLE );
902 tyOSDUpdate = 0;