home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Input / IFOParser / print_ifo_pgc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-10  |  7.4 KB  |  338 lines

  1.  
  2. /*
  3.  * PGROGRAM CHAIN INFORMATION
  4.  *
  5.  * Copyright (C) 1998-2000  Thomas Mirlacher
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  * 
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  * 
  21.  * The author may be reached as dent@cosy.sbg.ac.at, or
  22.  * Thomas Mirlacher, Jakob-Haringerstr. 2, A-5020 Salzburg,
  23.  * Austria
  24.  *
  25.  *------------------------------------------------------------
  26.  *
  27.  * $log$
  28.  */
  29.  
  30.  
  31. #include "IFOparser.h"
  32. extern CIFOParser *IFOGlobal;
  33.  
  34. #include <stdio.h>
  35. #include <malloc.h>
  36. #include <sys/types.h>
  37. //#include <unistd.h>
  38. #include "ifo.h"
  39.  
  40. #include "misc.h"
  41. #include "decode.h"
  42.  
  43. #define OFFSET_START_TBL_CMD (12+8*2+32*4+8+16*PGCI_COLOR_LEN)
  44.  
  45. typedef struct {
  46.     u_char  foo        : 8;    // don't know
  47.     u_char    y        : 8;
  48.     u_char    cr        : 8;
  49.     u_char    cb        : 8;    
  50. } pgci_color_t;
  51.  
  52. #define PGCI_COLOR_LEN 4
  53.  
  54. void ifoPrint_cell_position (u_char *ptr, u_int num);
  55.  
  56.  
  57. /**
  58.  *
  59.  */
  60.  
  61. void ifoPrint_pgc (u_char *pgc_ptr)
  62. {
  63.     int i;
  64.     u_int num;
  65.     char *ptr = (char *)pgc_ptr;
  66.  
  67.     if (!ptr)
  68.         return;
  69.  
  70.     TPGC  *my_pgc = &IFOGlobal->pgcs[IFOGlobal->PGCptr];
  71.  
  72.     printf ("\n\tPROGRAM CHAIN\n");
  73.     printf ("\t---\n");
  74.  
  75. /*****/
  76.     printf ("foo1: %x %x\n", *ptr++, *ptr++);
  77.     printf ("num_programs: %x  num_cells: %x\n", *ptr++, *ptr++); 
  78.  
  79. /*****/
  80. #define INT_TO_HEX(x)  (((x/16)*10)+(x%16))
  81.     printf ("\n\t\tchain time: %02x:%02x:%02x:%02x\n",
  82.         ptr[0],
  83.         ptr[1],
  84.         ptr[2],
  85. //        ptr[3] & 0x1F);
  86.         ptr[3] & 0x7F);
  87.     //int x = ((ptr[1]/16)+(ptr[1]%16));
  88.     my_pgc->chain_time = INT_TO_HEX(ptr[0])*(3600*1000) + INT_TO_HEX(ptr[1])*60*1000 + INT_TO_HEX(ptr[2])*1000 + INT_TO_HEX(ptr[3]&0x7F)*10;
  89.     //  chain_time in milliseconds = hours, minutes, secods, cents
  90.  
  91. //    printf ("VideoMode: %s\n", decode_videomode (ptr[3] >> 8));
  92.     printf ("%sframes/s\n", ptr[3]&0x80 ? "30" : "25 non-drop");
  93.  
  94.     ptr += 4;
  95.  
  96. /*****/
  97. //UNKNOWN
  98.     printf ("foo2: %x %x\n", *ptr++, *ptr++);
  99.     printf ("foo3: %x %x\n", *ptr++, *ptr++);
  100.  
  101. /*****/
  102.     printf ("\n\t\tAUDIO\n");
  103.     for (i=0; i<8; i++) {        // 8 subaudio streams
  104.         if (*ptr & 0x80) {    // avail
  105.             printf ("\t\t\t0x%02x->0x%02x unknown:0x%02x\n",
  106.                 i,
  107.                 *ptr&0x7f,
  108.                 *(ptr+1));
  109.         }
  110.  
  111.         ptr+=2;
  112.     }
  113.     
  114. /*****/
  115.     printf ("\n\t\tSUBPICTURE\n");
  116.     for (i=0; i<32; i++) {
  117.         if (*ptr & 0x80) {    // avail
  118.             printf ("\t\t\t0x%02x 4:3 0x%02x wide 0x%02x letter 0x%02x pan 0x%02x\n",
  119.                 i,
  120.                 *ptr&0x7f,
  121.                 *(ptr+1),
  122.                 *(ptr+2),
  123.                 *(ptr+3));
  124.         }
  125.  
  126.         ptr+=4;
  127.     }
  128.  
  129. /*****/
  130. //UNKNOWN
  131.     for (i=0; i<8; i++) {
  132.         if (!(i%16))
  133.             printf ("\n\t0x%04x: ", i);
  134.  
  135.         printf ("%02x  ", *ptr++);
  136.     }
  137.  
  138. /*****/
  139.     if (ifoGetCLUT ((char *)pgc_ptr, &ptr) >= 0)
  140.         ifoPrintCLUT ((unsigned char *)ptr);
  141.  
  142.     ifoPrint_pgc_cmd (pgc_ptr);
  143.  
  144.     if ((num = ifoGetProgramMap ((char *)pgc_ptr, &ptr)))
  145.         ifoPrintProgramMap ((unsigned char *)ptr, num);
  146.  
  147.     if ((num = ifoGetCellPlayInfo ((char *)pgc_ptr, &ptr)))
  148.         ifoPrintCellInfo ((unsigned char *)ptr, num);
  149.     if( IFOGlobal->fatal_error_flag )
  150.         return;
  151.  
  152.     if ((num = ifoGetCellPos ((char *)pgc_ptr, &ptr)))
  153.         ifoPrintCellPos ((unsigned char *)ptr, num);
  154.     if( IFOGlobal->fatal_error_flag )
  155.         return;
  156.  
  157.  
  158. /*****/
  159.  
  160. }    
  161.  
  162.  
  163. /**
  164.  *
  165.  */
  166.  
  167. void ifoPrintCellPos (u_char *ptr, u_int num)
  168. { int i;
  169.  
  170.     TPGC  *my_pgc = &IFOGlobal->pgcs[IFOGlobal->PGCptr];
  171.  
  172.     printf ("\n\tCELL POSITION (num: %d)\n", num);
  173.  
  174.     if(num<=0){
  175.         IFOGlobal->fatal_error_flag = 1;
  176.         return;
  177.     }
  178.     for (i=0; i<num; i++) {
  179.  
  180.  
  181.         printf ("\t\tVOB ID: %02x ", get2bytes (ptr));
  182.         my_pgc->chain_cells[i].vobid  = get2bytes (ptr);
  183.         ptr += 2;
  184.         printf ("Cell ID: %02x\n", get2bytes (ptr));
  185.         my_pgc->chain_cells[i].cellid = get2bytes (ptr);
  186.         ptr += 2;
  187.     }
  188. }
  189.  
  190.  
  191. /**
  192.  *
  193.  */
  194.  
  195. void ifoPrint_pgc_cmd (u_char *pgc_ptr)
  196. {
  197.     int i;
  198.     u_int num_pre_cmd;
  199.     u_int num_post_cmd;
  200.     u_int num_cell_cmd;
  201.     u_int len_cmd_tbl;
  202.     u_char *ptr;
  203.  
  204.     if ((ptr = get2bytes (pgc_ptr + OFFSET_START_TBL_CMD) + pgc_ptr) == pgc_ptr) 
  205.         return;
  206.  
  207.     num_pre_cmd     = get2bytes (ptr);
  208.     ptr+=2;
  209.     num_post_cmd     = get2bytes (ptr);
  210.     ptr+=2;
  211.  
  212. /*****/
  213. //cell commands
  214.     num_cell_cmd = get2bytes (ptr);
  215.     ptr+=2;
  216.     len_cmd_tbl = get2bytes (ptr);
  217.     ptr+=2;
  218.  
  219.     if (num_cell_cmd)
  220.         printf ("\n\t\tcell commands: (num: 0x%02x)", num_cell_cmd);
  221.  
  222. /*****/
  223. //pre commands
  224.     if (num_pre_cmd)
  225.         printf ("\n\t\tpre commands: (num: 0x%02x)", num_pre_cmd);
  226.     for (i=1; i<=num_pre_cmd; i++) {
  227.         printf ("\n\t\t\t0x%04x: ", i);
  228.         ifoPrintVMOP (ptr);
  229.         ptr += 8;
  230.     }
  231.  
  232. /*****/
  233. //post commands
  234.     if (num_post_cmd)
  235.         printf ("\n\n\t\tpost commands: (num: 0x%02x)", num_post_cmd);
  236.     for (i=1; i<=num_post_cmd; i++) {
  237.         printf ("\n\t\t\t0x%04x: ", i);
  238.         ifoPrintVMOP (ptr);
  239.         ptr += 8;
  240.     }
  241. }
  242.  
  243.  
  244. /**
  245.  *
  246.  */
  247.  
  248. void ifoPrintCellInfo (u_char *ptr, u_int num_cell_play_info)
  249. {
  250.     int i;
  251.  
  252.     printf ("\n\tCELL PLAY INFO (num: %d)\n", num_cell_play_info);
  253.  
  254.  
  255.     TPGC  *my_pgc = &IFOGlobal->pgcs[IFOGlobal->PGCptr];
  256. //    my_pgc->vob_span_count = num_cell_play_info;
  257.     if(num_cell_play_info<=0){
  258.         IFOGlobal->fatal_error_flag = 1;
  259.         return;
  260.     }
  261.         my_pgc->chain_cells.SetArraySize( num_cell_play_info );
  262.  
  263.     for (i=0; i<num_cell_play_info; i++) {
  264.         ifo_pgci_cell_addr_t *cell_addr = (ifo_pgci_cell_addr_t *) ptr;
  265.         printf ("\t\tstill_time: %02xs\t cell_cmd: 0x%x\tlen: %02x:%02x:%02x:%02x ",
  266.             (bswap_32 (cell_addr->foo) >> 8) & 0xFF,
  267.             (bswap_32 (cell_addr->foo)) & 0xFF,
  268.             (bswap_32 (cell_addr->len_time) >> 24) & 0xFF,
  269.             (bswap_32 (cell_addr->len_time) >> 16) & 0xFF,
  270.             (bswap_32 (cell_addr->len_time) >> 8) & 0xFF,
  271.             bswap_32 (cell_addr->len_time) & 0x7F);
  272.         
  273.         printf ("%sframes/s\n", bswap_32 (cell_addr->len_time) & 0x80 ? "30" : "25 non-drop");
  274.         printf ("\t\t1st_vobu_start : 0x%08X  1st_ilvu_end : 0x%08X\n\t\tlast_vobu_start: 0x%08X  last_vobu_end: 0x%08X\n",
  275.             bswap_32 (cell_addr->vobu_start),
  276.             bswap_32 (cell_addr->ilvu_end),
  277.             bswap_32 (cell_addr->vobu_last_start),
  278.             bswap_32 (cell_addr->vobu_last_end));
  279.  
  280.  
  281.  
  282.         my_pgc->chain_cells[i].start = bswap_32(cell_addr->vobu_start)   *2048;
  283.         // Must point to last byte of the span
  284.         my_pgc->chain_cells[i].end   = bswap_32(cell_addr->vobu_last_end)*2048 + 2047;
  285.  
  286.         ptr += PGCI_CELL_ADDR_LEN;
  287.     }
  288. }        
  289.  
  290.  
  291. /**
  292.  *
  293.  */
  294.  
  295. void ifoPrintCLUT (u_char *clut)
  296. {
  297.     TPGC  *my_pgc = &IFOGlobal->pgcs[IFOGlobal->PGCptr];
  298.  
  299.     pgci_color_t *pgci_color = (pgci_color_t *) clut;
  300.     int num = 16;
  301.     int index = 0;
  302.  
  303.     printf ("\n\t\tCLUT:\n");
  304.  
  305.     while (num--) {
  306.         printf ("\t\t\tfoo:0x%x  Y:0x%x Cr:0x%x Cb:0x%x\n",
  307.             pgci_color->foo,
  308.             pgci_color->y,
  309.             pgci_color->cr,
  310.             pgci_color->cb);
  311.         my_pgc->clut[index][0]   =  pgci_color->foo;
  312.         my_pgc->clut[index][1]   =  pgci_color->y;
  313.         my_pgc->clut[index][2]   =  pgci_color->cr;
  314.         my_pgc->clut[index][3]   =  pgci_color->cb;
  315.         index ++;
  316.         pgci_color++;
  317.     }
  318. }
  319.  
  320.  
  321. /**
  322.  *
  323.  */
  324.  
  325. void ifoPrintProgramMap (u_char *ptr, u_int num)
  326. {
  327.     int i;
  328.  
  329.     printf ("\n\n\t\tcell links: (num: %d)\n", num);
  330.     for (i=0; i<num; i++) {
  331.         printf ("\t\t\t0x%02x -> 0x%02x\n",
  332.             i, *ptr);
  333.         ptr++;
  334.     }
  335. }
  336.  
  337.  
  338.