]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/dvd_ifo.c
* It now compiles under FreeBSD (though DeCSS stuff probably doesn't
[vlc] / plugins / dvd / dvd_ifo.c
index 86ccffe78eca5db158fbaf901bc739bd4e28e575..6e2d74858ac8eb1e9b5e6144d235592f8294461f 100644 (file)
@@ -2,7 +2,7 @@
  * dvd_ifo.c: Functions for ifo parsing
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: dvd_ifo.c,v 1.11 2001/02/20 02:53:13 stef Exp $
+ * $Id: dvd_ifo.c,v 1.15 2001/03/06 10:21:59 massiot Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include "defs.h"
+#include "config.h"
+
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
@@ -39,6 +43,7 @@
 #include "intf_msg.h"
 #include "dvd_ifo.h"
 #include "dvd_udf.h"
+#include "dvd_css.h"
 #include "input_dvd.h"
 
 /*
@@ -224,12 +229,12 @@ static pgc_t ReadPGC( ifo_t* p_ifo )
     int     i;
     off_t   i_start = p_ifo->i_pos;
 
-fprintf( stderr, "PGC\n" );
+//fprintf( stderr, "PGC\n" );
 
     FLUSH(2);
     GETC( &pgc.i_prg_nb );
     GETC( &pgc.i_cell_nb );
-fprintf( stderr, "PGC: Prg: %d Cell: %d\n", pgc.i_prg_nb, pgc.i_cell_nb );
+//fprintf( stderr, "PGC: Prg: %d Cell: %d\n", pgc.i_prg_nb, pgc.i_cell_nb );
     GETL( &pgc.i_play_time );
     GETL( &pgc.i_prohibited_user_op );
     for( i=0 ; i<8 ; i++ )
@@ -243,7 +248,7 @@ fprintf( stderr, "PGC: Prg: %d Cell: %d\n", pgc.i_prg_nb, pgc.i_cell_nb );
     GETS( &pgc.i_next_pgc_nb );
     GETS( &pgc.i_prev_pgc_nb );
     GETS( &pgc.i_goup_pgc_nb );
-fprintf( stderr, "PGC: Prev: %d Next: %d Up: %d\n",pgc.i_prev_pgc_nb ,pgc.i_next_pgc_nb, pgc.i_goup_pgc_nb );
+//fprintf( stderr, "PGC: Prev: %d Next: %d Up: %d\n",pgc.i_prev_pgc_nb ,pgc.i_next_pgc_nb, pgc.i_goup_pgc_nb );
     GETC( &pgc.i_still_time );
     GETC( &pgc.i_play_mode );
     for( i=0 ; i<16 ; i++ )
@@ -382,7 +387,7 @@ static pgci_inf_t ReadUnit( ifo_t* p_ifo )
     int             i;
     off_t           i_start = p_ifo->i_pos;
 
-fprintf( stderr, "Unit\n" );
+//fprintf( stderr, "Unit\n" );
 
     GETS( &inf.i_srp_nb );
     FLUSH( 2 );
@@ -406,7 +411,7 @@ fprintf( stderr, "Unit\n" );
         p_ifo->i_pos = lseek( p_ifo->i_fd,
                          i_start + inf.p_srp[i].i_pgci_sbyte,
                          SEEK_SET );
-fprintf( stderr, "Unit: PGC %d\n", i );
+//fprintf( stderr, "Unit: PGC %d\n", i );
         inf.p_srp[i].pgc = ReadPGC( p_ifo );
     }
 
@@ -422,7 +427,7 @@ static pgci_ut_t ReadUnitTable( ifo_t* p_ifo )
     int             i;
     off_t           i_start = p_ifo->i_pos;
 
-fprintf( stderr, "Unit Table\n" );
+//fprintf( stderr, "Unit Table\n" );
 
     GETS( &pgci.i_lu_nb );
     FLUSH( 2 );
@@ -527,6 +532,7 @@ static vobu_admap_t ReadMap( ifo_t* p_ifo )
 static vmgi_mat_t ReadVMGInfMat( ifo_t* p_ifo )
 {
     vmgi_mat_t  mat;
+    u64         i_temp;
     int         i;
 //    off_t     i_start = p_ifo->i_pos;
 
@@ -560,20 +566,21 @@ static vmgi_mat_t ReadVMGInfMat( ifo_t* p_ifo )
     GETL( &mat.i_c_adt_ssector );
     GETL( &mat.i_vobu_admap_ssector );
     FLUSH( 32 );
-    GETS( &mat.i_video_atrt );
+//    GETS( &mat.video_atrt );
+FLUSH(2);
     FLUSH( 1 );
     GETC( &mat.i_audio_nb );
 //fprintf( stderr, "vmgi audio nb : %d\n", mat.i_audio_nb );
     for( i=0 ; i < 8 ; i++ )
     {
-        GETLL( &mat.pi_audio_atrt[i] );
+        GETLL( &i_temp );
     }
     FLUSH( 17 );
     GETC( &mat.i_subpic_nb );
 //fprintf( stderr, "vmgi subpic nb : %d\n", mat.i_subpic_nb );
     for( i=0 ; i < mat.i_subpic_nb ; i++ )
     {
-        GET( &mat.pi_subpic_atrt[i], 6 );
+        GET( &i_temp, 6 );
         /* FIXME : take care of endianness */
     }
 
@@ -589,10 +596,10 @@ static vmg_ptt_srpt_t ReadVMGTitlePointer( ifo_t* p_ifo )
     int             i;
 //    off_t           i_start = p_ifo->i_pos;
 
-fprintf( stderr, "PTR\n" );
+//fprintf( stderr, "PTR\n" );
 
     GETS( &ptr.i_ttu_nb );
-fprintf( stderr, "PTR: TTU nb %d\n", ptr.i_ttu_nb );
+//fprintf( stderr, "PTR: TTU nb %d\n", ptr.i_ttu_nb );
     FLUSH( 2 );
     GETL( &ptr.i_ebyte );
     /* Parsing of tts */
@@ -612,7 +619,7 @@ fprintf( stderr, "PTR: TTU nb %d\n", ptr.i_ttu_nb );
         GETC( &ptr.p_tts[i].i_tts_nb );
         GETC( &ptr.p_tts[i].i_vts_ttn );
         GETL( &ptr.p_tts[i].i_ssector );
-fprintf( stderr, "PTR: %d %d %d\n", ptr.p_tts[i].i_ptt_nb, ptr.p_tts[i].i_tts_nb,ptr.p_tts[i].i_vts_ttn );
+//fprintf( stderr, "PTR: %d %d %d\n", ptr.p_tts[i].i_ptt_nb, ptr.p_tts[i].i_tts_nb,ptr.p_tts[i].i_vts_ttn );
     }
 
     return ptr;
@@ -684,12 +691,13 @@ static vmg_vts_atrt_t ReadVTSAttr( ifo_t* p_ifo )
 {
     vmg_vts_atrt_t  atrt;
     int             i, j;
+    u64             i_temp;
     off_t           i_start = p_ifo->i_pos;
 
-fprintf( stderr, "VTS ATTR\n" );
+//fprintf( stderr, "VTS ATTR\n" );
 
     GETS( &atrt.i_vts_nb );
-fprintf( stderr, "VTS ATTR Nb: %d\n", atrt.i_vts_nb );
+//fprintf( stderr, "VTS ATTR Nb: %d\n", atrt.i_vts_nb );
     FLUSH( 2 );
     GETL( &atrt.i_ebyte );
     atrt.pi_vts_atrt_sbyte = malloc( atrt.i_vts_nb *sizeof(u32) );
@@ -717,37 +725,39 @@ fprintf( stderr, "VTS ATTR Nb: %d\n", atrt.i_vts_nb );
                                 SEEK_SET );
         GETL( &atrt.p_vts_atrt[i].i_ebyte );
         GETL( &atrt.p_vts_atrt[i].i_cat_app_type );
-        GETS( &atrt.p_vts_atrt[i].i_vtsm_video_atrt );
+//        GETS( &atrt.p_vts_atrt[i].vtsm_video_atrt );
+FLUSH(2);
         FLUSH( 1 );
         GETC( &atrt.p_vts_atrt[i].i_vtsm_audio_nb );
 //fprintf( stderr, "m audio nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_audio_nb );
         for( j=0 ; j<8 ; j++ )
         {
-            GETLL( &atrt.p_vts_atrt[i].pi_vtsm_audio_atrt[j] );
+            GETLL( &i_temp );
         }
         FLUSH( 17 );
         GETC( &atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
 //fprintf( stderr, "m subp nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
         for( j=0 ; j<28 ; j++ )
         {
-            GET( &atrt.p_vts_atrt[i].pi_vtsm_subpic_atrt[j], 6 );
+            GET( &i_temp, 6 );
             /* FIXME : Fix endianness issue here */
         }
         FLUSH( 2 );
-        GETS( &atrt.p_vts_atrt[i].i_vtstt_video_atrt );
+//        GETS( &atrt.p_vts_atrt[i].vtstt_video_atrt );
+FLUSH(2);
         FLUSH( 1 );
         GETL( &atrt.p_vts_atrt[i].i_vtstt_audio_nb );
 //fprintf( stderr, "tt audio nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_audio_nb );
         for( j=0 ; j<8 ; j++ )
         {
-            GETLL( &atrt.p_vts_atrt[i].pi_vtstt_audio_atrt[j] );
+            GETLL( &i_temp );
         }
         FLUSH( 17 );
         GETC( &atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
 //fprintf( stderr, "tt subp nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
         for( j=0 ; j<28/*atrt.p_vts_atrt[i].i_vtstt_subpic_nb*/ ; j++ )
         {
-            GET( &atrt.p_vts_atrt[i].pi_vtstt_subpic_atrt[j], 6 );
+            GET( &i_temp, 6 );
             /* FIXME : Fix endianness issue here */
         }
     }
@@ -824,6 +834,7 @@ static vtsi_mat_t ReadVTSInfMat( ifo_t* p_ifo )
 {
     vtsi_mat_t  mat;
     int         i;
+    u64         i_temp;
 //    off_t       i_start = p_ifo->i_pos;
 
 //fprintf( stderr, "VTSI\n" );
@@ -850,36 +861,61 @@ static vtsi_mat_t ReadVTSInfMat( ifo_t* p_ifo )
     GETL( &mat.i_c_adt_ssector );
     GETL( &mat.i_vobu_admap_ssector );
     FLUSH( 24 );
-    GETS( &mat.i_m_video_atrt );
+//    GETS( &mat.m_video_atrt );
+FLUSH(2);
     FLUSH( 1 );
     GETC( &mat.i_m_audio_nb );
     for( i=0 ; i<8 ; i++ )
     {
-        GETLL( &mat.pi_m_audio_atrt[i] );
+        GETLL( &i_temp );
     }
     FLUSH( 17 );
     GETC( &mat.i_m_subpic_nb );
     for( i=0 ; i<28 ; i++ )
     {
-        GET( &mat.pi_m_subpic_atrt[i], 6 );
+        GET( &i_temp, 6 );
         /* FIXME : take care of endianness */
     }
     FLUSH( 2 );
-    GETS( &mat.i_video_atrt );
+//    GETS( &mat.video_atrt );
+FLUSH(2);
     FLUSH( 1 );
     GETC( &mat.i_audio_nb );
 //fprintf( stderr, "vtsi audio nb : %d\n", mat.i_audio_nb );
     for( i=0 ; i<8 ; i++ )
     {
-        GETLL( &mat.pi_audio_atrt[i] );
+        GETLL( &i_temp );
+//fprintf( stderr, "Audio %d: %llx\n", i, i_temp );
+        i_temp >>= 32;
+        mat.p_audio_atrt[i].i_lang_code = i_temp & 0xffff;
+        i_temp >>= 16;
+        mat.p_audio_atrt[i].i_num_channels = i_temp & 0x7;
+        i_temp >>= 4;
+        mat.p_audio_atrt[i].i_sample_freq = i_temp & 0x3;
+        i_temp >>= 2;
+        mat.p_audio_atrt[i].i_quantization = i_temp & 0x3;
+        i_temp >>= 2;
+        mat.p_audio_atrt[i].i_appl_mode = i_temp & 0x3;
+        i_temp >>= 2;
+        mat.p_audio_atrt[i].i_type = i_temp & 0x3;
+        i_temp >>= 2;
+        mat.p_audio_atrt[i].i_multichannel_extension = i_temp & 0x1;
+        i_temp >>= 1;
+        mat.p_audio_atrt[i].i_coding_mode = i_temp & 0x7;
     }
     FLUSH( 17 );
     GETC( &mat.i_subpic_nb );
 //fprintf( stderr, "vtsi subpic nb : %d\n", mat.i_subpic_nb );
     for( i=0 ; i<mat.i_subpic_nb ; i++ )
     {
-        GET( &mat.pi_subpic_atrt[i], 6 );
-        /* FIXME : take care of endianness */
+        GET( &i_temp, 6 );
+        i_temp = hton64( i_temp ) >> 16;
+//fprintf( stderr, "Subpic %d: %llx\n", i, i_temp );
+        mat.p_subpic_atrt[i].i_caption = i_temp & 0xff;
+        i_temp >>= 16;
+        mat.p_subpic_atrt[i].i_lang_code = i_temp & 0xffff;
+        i_temp >>= 16;
+        mat.p_subpic_atrt[i].i_prefix = i_temp & 0xffff;
     }
 
     return mat;
@@ -894,10 +930,10 @@ static vts_ptt_srpt_t ReadVTSTitlePointer( ifo_t* p_ifo )
     int             i;
     off_t           i_start = p_ifo->i_pos;
 
-fprintf( stderr, "VTS PTR\n" );
+//fprintf( stderr, "VTS PTR\n" );
 
     GETS( &ptr.i_ttu_nb );
-fprintf( stderr, "VTS PTR nb: %d\n", ptr.i_ttu_nb );
+//fprintf( stderr, "VTS PTR nb: %d\n", ptr.i_ttu_nb );
     FLUSH( 2 );
     GETL( &ptr.i_ebyte );
     ptr.pi_ttu_sbyte = malloc( ptr.i_ttu_nb *sizeof(u32) );
@@ -925,7 +961,7 @@ fprintf( stderr, "VTS PTR nb: %d\n", ptr.i_ttu_nb );
                         ptr.pi_ttu_sbyte[i], SEEK_SET );
         GETS( &ptr.p_ttu[i].i_pgc_nb );
         GETS( &ptr.p_ttu[i].i_prg_nb );
-fprintf( stderr, "VTS %d PTR Pgc: %d Prg: %d\n", i,ptr.p_ttu[i].i_pgc_nb, ptr.p_ttu[i].i_prg_nb );
+//fprintf( stderr, "VTS %d PTR Pgc: %d Prg: %d\n", i,ptr.p_ttu[i].i_pgc_nb, ptr.p_ttu[i].i_prg_nb );
     }
 
     return ptr;
@@ -998,7 +1034,8 @@ int IfoReadVTS( ifo_t* p_ifo )
     intf_WarnMsg( 2, "ifo: initializing VTS %d", p_ifo->i_title );
 
     i_title = p_ifo->i_title;
-    i_off = (off_t)( p_ifo->vmg.ptt_srpt.p_tts[i_title].i_ssector ) *DVD_LB_SIZE
+    i_off = (off_t)( p_ifo->vmg.ptt_srpt.p_tts[i_title-1].i_ssector )
+                   * DVD_LB_SIZE
                    + p_ifo->i_off;
 
     p_ifo->i_pos = lseek( p_ifo->i_fd, i_off, SEEK_SET );