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_ptt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  3.6 KB  |  179 lines

  1.  
  2. /*
  3.  * PART OF TITLE
  4.  *
  5.  * Copyright (C) 1998,1999  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.  */
  28.  
  29.  
  30.  
  31. #include <stdio.h>
  32.  
  33. #include <stdlib.h>
  34. //#include <unistd.h>
  35. #include <sys/types.h>
  36. #include "ifo.h"
  37.  
  38. #include "misc.h"
  39. #include "decode.h"
  40.  
  41. #define PTT_LEN 4
  42.  
  43. typedef struct {
  44.     u_short pgc        : 16;    // Program Chain number
  45.     u_short    pg        : 16;    // Program number
  46. } ptt_t;
  47.  
  48.  
  49. /**
  50.  *
  51.  */
  52.  
  53. int ifoGetVMGPTT (ifo_hdr_t *hdr, char **ptr)
  54. {
  55.     *ptr = ((char *) hdr) + IFO_HDR_LEN;
  56.  
  57.     return 0;
  58. }
  59.  
  60.  
  61. /**
  62.  *
  63.  */
  64.  
  65. int ifoGetNumberOfTitles (ifo_t *ifo)
  66. {
  67.     ifo_hdr_t *hdr = (ifo_hdr_t *) ifo->data[ID_PTT];
  68.  
  69.     if (!ifo->data[ID_PTT])
  70.         return -1;
  71.     else
  72.         return bswap_16 (hdr->num);
  73. }
  74.  
  75.  
  76. /**
  77.  * DENT: change this
  78.  */
  79.  
  80. int ifoGetNumberOfParts (ifo_t *ifo)
  81. {
  82.     ifo_hdr_t *hdr = (ifo_hdr_t *) ifo->data[ID_PTT];
  83.  
  84.     if (!ifo->data[ID_PTT])
  85.         return -1;
  86.     else
  87.         return bswap_16 (hdr->num);
  88. }
  89.  
  90.  
  91. /**
  92.  *
  93.  */
  94.  
  95. ifo_ptt_t *ifo_get_ptt (ifo_t *ifo)
  96. {
  97.     u_char *ptr;
  98.     ifo_hdr_t *hdr;
  99.     ifo_ptt_t *ifo_ptt;
  100.     ifo_ptt_sub_t *ifo_ptt_sub;
  101.     ptt_t *ptt = (ptt_t *) ptr;
  102.     int i, s;
  103.     u_short prev_start = 0;
  104.     u_int num;
  105.  
  106.     if (!ifo) {
  107.         fprintf (stderr, "%s/%d:no ifo structure present\n", __FILE__, __LINE__);
  108.         return NULL;
  109.     }
  110.  
  111.     ptr = (u_char *) ifo->data[ID_PTT];
  112.     hdr = (ifo_hdr_t *) ifo->data[ID_PTT];
  113.  
  114.     if (!ptr)
  115.         return NULL;
  116.  
  117.     if (!(ifo_ptt = (ifo_ptt_t *) malloc (sizeof (ifo_ptt_t))))
  118.         return NULL;
  119.  
  120.     ifo_ptt->num = bswap_16 (hdr->num);
  121.  
  122.     if (!(ifo_ptt_sub = (ifo_ptt_sub_t *) calloc (ifo_ptt->num, sizeof (ifo_ptt_sub_t))))
  123.         return NULL;
  124.  
  125.     ifo_ptt->title = ifo_ptt_sub;
  126.  
  127.     ptr += IFO_HDR_LEN;
  128.  
  129.     prev_start = get4bytes (ptr);
  130.  
  131.     for (i=0; i< bswap_16 (hdr->num); i++) {
  132.         if (i>0) {
  133.             ifo_ptt_sub = ifo_ptt->title+i-1;
  134.  
  135.             num = (get4bytes (ptr) - prev_start)/4;
  136.  
  137.             ptt = (ptt_t *) ((u_char *) ifo->data[ID_PTT] + prev_start);
  138.  
  139.             if (!(ifo_ptt_sub->data = (ifo_ptt_data_t *) calloc (num, sizeof (ifo_ptt_data_t))))
  140.                 return NULL;
  141.  
  142.             ifo_ptt_sub->num = num;
  143.  
  144.             for (s=0; s<num; s++) {
  145.                 ifo_ptt_sub->data[s].pg = bswap_16 (ptt->pg);
  146.                 ifo_ptt_sub->data[s].pgc = bswap_16 (ptt->pgc);
  147.  
  148.                 ptt++;
  149.             }
  150.  
  151.             prev_start = get4bytes (ptr);
  152.         }
  153.  
  154.         ptr+=4;
  155.     }
  156.  
  157.     ifo_ptt_sub = ifo_ptt->title+i-1;
  158.     num = (bswap_32 (hdr->len) - prev_start + 1)/4;
  159.  
  160.     ptt = (ptt_t *) ((u_char *) ifo->data[ID_PTT] + prev_start);
  161.  
  162. // TODO: delete allocated elements when failing here
  163.     if (!(ifo_ptt_sub->data = (ifo_ptt_data_t *) calloc (num, sizeof (ifo_ptt_data_t))))
  164.         return NULL;
  165.  
  166.     ifo_ptt_sub->num = num;
  167.  
  168.     for (s=0; s<num; s++) {
  169.         ifo_ptt_sub->data[s].pg = bswap_16 (ptt->pg);
  170.         ifo_ptt_sub->data[s].pgc = bswap_16 (ptt->pgc);
  171.  
  172.         ptt++;
  173.     }
  174.  
  175.  
  176.  
  177.     return ifo_ptt;
  178. }    
  179.