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

  1.  
  2. /*
  3.  *
  4.  * Copyright (C) 1998,1999  Thomas Mirlacher
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * 
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  * 
  20.  * The author may be reached as dent@cosy.sbg.ac.at, or
  21.  * Thomas Mirlacher, Jakob-Haringerstr. 2, A-5020 Salzburg,
  22.  * Austria
  23.  *
  24.  *------------------------------------------------------------
  25.  *
  26.  */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. //#include <unistd.h>
  33. #include <errno.h>
  34. //#include <unistd.h>
  35. #include <sys/types.h>
  36. //#include <sys/mman.h>
  37.  
  38. #include "ifo.h"
  39. #include "misc.h"
  40.  
  41.  
  42. /**
  43.  *
  44.  */
  45.  
  46. int ifoIsVTS (ifo_t *ifo)
  47. {
  48.         if (!strncmp ((char *)ifo->data[ID_MAT], "DVDVIDEO-VTS", 12)) 
  49.         return 0;
  50.  
  51.     return -1;
  52. }
  53.  
  54.  
  55. /**
  56.  *
  57.  */
  58.  
  59. int ifoIsVMG (ifo_t *ifo)
  60. {
  61.         if (!strncmp ((char *)ifo->data[ID_MAT], "DVDVIDEO-VMG", 12))
  62.         return 0;
  63.  
  64.     return -1;
  65. }
  66.  
  67.  
  68. /**
  69.  *
  70.  */
  71.  
  72. int ifoGetVOBStart (ifo_t *ifo)
  73. {
  74.     return ifo->vob_start;
  75. }
  76.  
  77.  
  78. #define OFF_PTT get4bytes (ifo->data[ID_MAT] + 0xC8)
  79. #define OFF_TITLE_PGCI get4bytes (ifo->data[ID_MAT] + 0xCC)
  80. #define OFF_MENU_PGCI get4bytes (ifo->data[ID_MAT] + 0xD0)
  81. #define OFF_TMT get4bytes (ifo->data[ID_MAT] + 0xD4)
  82. #define OFF_MENU_CELL_ADDR get4bytes (ifo->data[ID_MAT] + 0xD8)
  83. #define OFF_MENU_VOBU_ADDR_MAP get4bytes (ifo->data[ID_MAT] + 0xDC)
  84. #define OFF_TITLE_CELL_ADDR get4bytes (ifo->data[ID_MAT] + 0xE0)
  85. #define OFF_TITLE_VOBU_ADDR_MAP get4bytes (ifo->data[ID_MAT] + 0xE4)
  86.  
  87. #define OFF_VMG_PTT get4bytes (ifo->data[ID_MAT] + 0xC4)
  88. #define OFF_VMG_MENU_PGCI get4bytes (ifo->data[ID_MAT] + 0xC8)
  89. #define OFF_VMG_TMT get4bytes (ifo->data[ID_MAT] + 0xD0)
  90.  
  91.  
  92. /**
  93.  *
  94.  */
  95.  
  96. ifo_t *ifoOpen (int fd, __off64_t pos)
  97. {
  98.     ifo_t *ifo;
  99.  
  100.     if (!(ifo = (ifo_t *) calloc (sizeof (ifo_t), 1))) {
  101.         fprintf (stderr, "%s/%d: memory squeeze (ifo)\n", __FILE__, __LINE__);
  102.         return NULL;
  103.     }
  104.  
  105.     if (!(ifo->data[ID_MAT] = (unsigned char *) calloc (DVD_VIDEO_LB_LEN, 1))) {
  106.         fprintf (stderr, "%s/%d: memory squeeze (data)\n", __FILE__, __LINE__);
  107.         return NULL;
  108.     }
  109.  
  110.     ifo->pos = pos; 
  111.     ifo->fd = fd;
  112.  
  113.     if (ifoReadLB (fd, pos, DVD_VIDEO_LB_LEN, ifo->data[ID_MAT]) < 0) {
  114.         fprintf (stderr, "%s/%d: something went wrong when reading file. (pos %x) \n", __FILE__, __LINE__, ifo->pos);
  115.         return NULL;
  116.     }
  117.  
  118.     ifo->num_menu_vobs    = get4bytes (ifo->data[ID_MAT] + 0xC0);
  119.     ifo->vob_start        = get4bytes (ifo->data[ID_MAT] + 0xC4);
  120.  
  121. printf ("num of vobs: %x vob_start %x\n", ifo->num_menu_vobs, ifo->vob_start);
  122.  
  123.     if (!ifoIsVTS (ifo)) {
  124.         ifoReadTBL (ifo, OFF_PTT, ID_PTT);
  125.         ifoReadTBL (ifo, OFF_TITLE_PGCI, ID_TITLE_PGCI);
  126.         ifoReadTBL (ifo, OFF_MENU_PGCI, ID_MENU_PGCI);
  127.         ifoReadTBL (ifo, OFF_TMT, ID_TMT);
  128.         ifoReadTBL (ifo, OFF_MENU_CELL_ADDR, ID_MENU_CELL_ADDR);
  129.         ifoReadTBL (ifo, OFF_MENU_VOBU_ADDR_MAP, ID_MENU_VOBU_ADDR_MAP);
  130.         ifoReadTBL (ifo, OFF_TITLE_CELL_ADDR, ID_TITLE_CELL_ADDR);
  131.         ifoReadTBL (ifo, OFF_TITLE_VOBU_ADDR_MAP, ID_TITLE_VOBU_ADDR_MAP);
  132.     } else if (!ifoIsVMG (ifo)) {
  133.         ifoReadTBL (ifo, OFF_VMG_PTT, ID_PTT);
  134. //        ifoReadTBL (ifo, OFF_TITLE_PGCI, ID_TITLE_PGCI);
  135.         ifoReadTBL (ifo, OFF_VMG_MENU_PGCI, ID_MENU_PGCI);
  136.         ifoReadTBL (ifo, OFF_VMG_TMT, ID_TMT);
  137. //        ifoReadTBL (ifo, OFF_MENU_CELL_ADDR, ID_MENU_CELL_ADDR);
  138. //        ifoReadTBL (ifo, OFF_MENU_VOBU_ADDR_MAP, ID_MENU_VOBU_ADDR_MAP);
  139.         ifoReadTBL (ifo, OFF_TITLE_CELL_ADDR, ID_TITLE_CELL_ADDR);
  140.         ifoReadTBL (ifo, OFF_TITLE_VOBU_ADDR_MAP, ID_TITLE_VOBU_ADDR_MAP);
  141.     }
  142.     else return NULL;
  143.  
  144.     return ifo;
  145. }
  146.  
  147.  
  148. /**
  149.  *
  150.  */
  151.  
  152. int ifoClose (ifo_t *ifo)
  153. {
  154.     free (ifo->data[ID_MAT]);
  155.     free (ifo->data[ID_PTT]);
  156.     free (ifo->data[ID_TITLE_PGCI]);
  157.     free (ifo->data[ID_MENU_PGCI]);
  158.     free (ifo->data[ID_TMT]);
  159.     free (ifo->data[ID_MENU_CELL_ADDR]);
  160.     free (ifo->data[ID_MENU_VOBU_ADDR_MAP]);
  161.     free (ifo->data[ID_TITLE_CELL_ADDR]);
  162.     free (ifo->data[ID_TITLE_VOBU_ADDR_MAP]);
  163.  
  164.     free (ifo);
  165.  
  166.     return 0;
  167. }
  168.