[libdvdnav-devel] [Git][videolan/libdvdread][master] 5 commits: DVD-Audio: insure DVD type for SAMG IFO in public API

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue Aug 19 04:06:50 UTC 2025



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread


Commits:
5e464550 by Saifelden Mohamed Ismail at 2025-08-16T15:04:49+03:00
DVD-Audio: insure DVD type for SAMG IFO in public API

- - - - -
fc941b05 by Saifelden Mohamed Ismail at 2025-08-16T15:04:57+03:00
DVD-Audio: sanity check for ATS title table

- - - - -
c6d9b60d by Saifelden Mohamed Ismail at 2025-08-16T15:04:57+03:00
DVD-Audio: clean up formatting for ifo_read.c

- - - - -
cf551b7a by Saifelden Mohamed Ismail at 2025-08-16T15:20:04+03:00
DVD-Audio: fix downmix coefficients in IFO files

- - - - -
6df1a3f8 by Saifelden Mohamed Ismail at 2025-08-18T17:01:53+03:00
DVD-Audio: add public API for standalone ifo reads

- - - - -


5 changed files:

- src/dvd_reader.c
- src/dvdread/ifo_read.h
- src/dvdread/ifo_types.h
- src/ifo_print.c
- src/ifo_read.c


Changes:

=====================================
src/dvd_reader.c
=====================================
@@ -1185,6 +1185,10 @@ dvd_file_t *DVDOpenFile( dvd_reader_t *ctx, int titlenum,
     break;
   case DVD_READ_SAMG_INFO:
     /* no other way to reach SAMG menu*/
+    if( ctx->dvd_type == DVD_V ) {
+      Log1( ctx, "SAMG IFO is exclusive to DVD-Audio" );
+      return NULL;
+    }
     strcpy( filename, "/AUDIO_TS/AUDIO_PP.IFO" );
     break;
   default:
@@ -1372,7 +1376,13 @@ int DVDFileStat( dvd_reader_t *reader, int titlenum,
 
     break;
   case DVD_READ_SAMG_INFO:
+    /* no other way to reach SAMG menu*/
+    if( reader->dvd_type == DVD_V ) {
+      Log1( reader, "SAMG IFO is exclusive to DVD-Audio" );
+      return -1;
+    }
     strcpy( filename, "/AUDIO_TS/AUDIO_PP.IFO" );
+
     break;
   default:
     Log1(reader, "Invalid domain for file stat." );


=====================================
src/dvdread/ifo_read.h
=====================================
@@ -44,7 +44,7 @@ DVDREAD_API ifo_handle_t *ifoOpen(dvd_reader_t *, int );
  *
  * Opens an IFO and reads in _only_ the vmgi_mat data.  This call can be used
  * together with the calls below to read in each segment of the IFO file on
- * demand.
+ * demand. If the dvd_reader opened an DVD-Audio Disc, this will open the AMGI
  */
 DVDREAD_API ifo_handle_t *ifoOpenVMGI(dvd_reader_t *);
 
@@ -53,7 +53,7 @@ DVDREAD_API ifo_handle_t *ifoOpenVMGI(dvd_reader_t *);
  *
  * Opens an IFO and reads in _only_ the vtsi_mat data.  This call can be used
  * together with the calls below to read in each segment of the IFO file on
- * demand.
+ * demand. If the dvd_reader opened an DVD-Audio Disc, this will open the ATSI
  */
 DVDREAD_API ifo_handle_t *ifoOpenVTSI(dvd_reader_t *, int);
 
@@ -204,6 +204,25 @@ DVDREAD_API int ifoRead_TITLE_VOBU_ADMAP(ifo_handle_t *);
  */
 DVDREAD_API int ifoRead_TXTDT_MGI(ifo_handle_t *);
 
+/**
+ * okay = ifoRead_TT(ifofile);
+ *
+ * Reads the Title Track Table in ATS IFO's.
+ * This structure. This structure is mandatory, and must be included
+ * in the AMGI file.
+ */
+DVDREAD_API int ifoRead_TT(ifo_handle_t *);
+
+/**
+ * okay = ifoRead_TIF(ifofile);
+ *
+ * Reads either table in AUDIO_TS.IFO based on the sector offset given,
+ * either 1,2. The first table being one with video titles, the second one
+ * without. This structure. This structure is mandatory, and must be included
+ * in the AMGI file.
+ */
+DVDREAD_API int ifoRead_TIF(ifo_handle_t *, int);
+
 /**
  * The following functions are used for freeing parsed sections of the
  * ifo_handle_t structure and the allocated substructures.  The free calls
@@ -223,6 +242,7 @@ DVDREAD_API void ifoFree_TITLE_C_ADT(ifo_handle_t *);
 DVDREAD_API void ifoFree_VOBU_ADMAP(ifo_handle_t *);
 DVDREAD_API void ifoFree_TITLE_VOBU_ADMAP(ifo_handle_t *);
 DVDREAD_API void ifoFree_TXTDT_MGI(ifo_handle_t *);
+DVDREAD_API void ifoFree_TT(ifo_handle_t *);
 
 #ifdef __cplusplus
 };


=====================================
src/dvdread/ifo_types.h
=====================================
@@ -449,6 +449,48 @@ typedef struct {
 } ATTRIBUTE_PACKED vmgi_mat_t;
 #define VMGI_MAT_SIZE 510U
 
+/* Downmix coefficients can be used to reduce 5.1 channels to stereo in DVD-Audio Discs */
+/** Downmix equations
+ * Left_out  = Lf_left  * Lf
+ *           + Rf_left  * Rf
+ *           + C_left   * C
+ *           + LFE_left * LFE
+ *           + Ls_left  * Ls
+ *           + Rs_left  * Rs;
+ * 
+ * Right_out = Lf_right  * Lf
+ *           + Rf_right  * Rf
+ *           + C_right   * C
+ *           + LFE_right * LFE
+ *           + Ls_right  * Ls
+ *           + Rs_right  * Rs;
+ * 
+ * Where:
+ *   - Lf, Rf, C, LFE, Ls, Rs are the 5.1 input channels
+ *   - Left_out, Right_out are the stereo output channels
+ *   - Each coefficient (e.g. Lf_left, C_right) is an 8-bit gain factor
+ */
+
+typedef struct {
+  /* it seems each entry is started and ended with padding */
+  uint16_t zero_1;
+  /* each coefficient corresponds to stereo side for a channel in 5.1 */
+  uint8_t Lf_left;
+  uint8_t Lf_right;
+  uint8_t Rf_left;
+  uint8_t Rf_right;
+  uint8_t C_left;
+  uint8_t C_right;
+  uint8_t LFE_left;
+  uint8_t LFE_right;
+  uint8_t Ls_left;
+  uint8_t Ls_right;
+  uint8_t Rs_left;
+  uint8_t Rs_right;
+
+  uint16_t zero_2;
+} ATTRIBUTE_PACKED downmix_coeff_t;
+#define DOWNMIX_COEFF_SIZE 16U
 
 
 /**
@@ -472,6 +514,8 @@ typedef struct {
   uint8_t  bit_depth;
   uint8_t  sampling_rate;
   uint8_t  nr_channels; 
+  /* some DVD's made with authoring software keep downmix coefficients here */
+  /* since I do not have samples of commercial discs that do this, I will not include it */
   uint8_t  zero_3[20];
   uint32_t start_sector_1; /*aob start sector*/
   uint32_t start_sector_2; /*aob start sector is repeated again */
@@ -834,10 +878,11 @@ typedef struct {
   uint32_t      vts_c_adt;       /* sector */
   uint32_t      vts_vobu_admap;  /* sector */
   uint8_t       zero_4[24];
+  /* the majority, or even all of these entries may be zero*/
   atsi_record_t atsi_record[ATSI_RECORD_MAX_SIZE];
-  uint64_t      downmix_coeff[DOWNMIX_COEFF_MAX_SIZE];
+  downmix_coeff_t downmix_coefficients[DOWNMIX_COEFF_MAX_SIZE];
 } ATTRIBUTE_PACKED atsi_mat_t;
-#define ATSI_MAT_SIZE 512U
+#define ATSI_MAT_SIZE 640U
 
 typedef struct {
   uint16_t unknown_1; /* appears to be index, +0x100 for each iter*/


=====================================
src/ifo_print.c
=====================================
@@ -641,6 +641,31 @@ static void ifo_print_atsi_records(atsi_record_t *records){
   }
 }
 
+static void ifo_print_downmix_coefficients(downmix_coeff_t *downmix_coefficients) {
+  for (int i = 0; i < DOWNMIX_COEFF_MAX_SIZE; i++) {
+    printf("DOWNMIX COEFFICIENTS:\n");
+
+    printf("Lf_left, Lf_right: %02x, %02x\n ", 
+           downmix_coefficients[i].Lf_left, downmix_coefficients[i].Lf_right);
+
+    printf("Rf_left, Rf_right: %02x, %02x\n ", 
+           downmix_coefficients[i].Rf_left, downmix_coefficients[i].Rf_right);
+
+    printf("C_left, C_right: %02x, %02x\n ", 
+           downmix_coefficients[i].C_left, downmix_coefficients[i].C_right);
+
+    printf("LFE_left, LFE_right: %02x, %02x\n ",
+           downmix_coefficients[i].LFE_left, downmix_coefficients[i].LFE_right);
+
+    printf("Ls_left, Ls_right: %02x, %02x\n ", 
+           downmix_coefficients[i].Ls_left, downmix_coefficients[i].Ls_right);
+
+    printf("Rs_left, Rs_right: %02x, %02x\n ", 
+           downmix_coefficients[i].Rs_left, downmix_coefficients[i].Rs_right);
+
+  }
+}
+
 void ifoPrint_TT(atsi_title_table_t *atsi_title_table){
   printf("Number of titles: %04x\n", atsi_title_table->nr_titles);
   printf("Last byte address: %08x\n", atsi_title_table->last_byte_address);
@@ -708,9 +733,9 @@ void ifoPrint_ATSI_MAT(atsi_mat_t *atsi_mat) {
   printf("ATSI_RECORDS: ");
   ifo_print_atsi_records(atsi_mat->atsi_record);
   printf("\n");
+  ifo_print_downmix_coefficients(atsi_mat->downmix_coefficients);
+
 
-  for (int i =0; i<16; i++)
-    printf("DOWNMIX COEFFICIENTS:  %" PRIx64 "\n", atsi_mat->downmix_coeff[i]);
 }
 
 static void ifoPrint_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl) {


=====================================
src/ifo_read.c
=====================================
@@ -92,8 +92,6 @@ static const uint8_t my_friendly_zeros[2048];
 /* Prototypes for internal functions */
 static int ifoRead_VMG(ifo_handle_t *ifofile);
 static int ifoRead_AMG(ifo_handle_t *ifofile);
-static int ifoRead_TT(ifo_handle_t *ifofile);
-static int ifoRead_TIF(ifo_handle_t *ifofile, int sector);
 /* Can be used to make simple dvd-a playback, no menus*/
 static int ifoRead_SAMG(ifo_handle_t *ifofile);
 
@@ -196,6 +194,7 @@ CHECK_STRUCT_SIZE(atsi_track_timestamp_t, 0, ATSI_TRACK_TIMESTAMP_SIZE);
 CHECK_STRUCT_SIZE(atsi_track_pointer_t,   0, ATSI_TRACK_POINTER_SIZE);
 CHECK_STRUCT_SIZE(atsi_title_record_t,    2, ATSI_TITLE_ROW_TABLE_SIZE);
 CHECK_STRUCT_SIZE(atsi_title_table_t,     2, ATSI_TITLE_TABLE_SIZE);
+CHECK_STRUCT_SIZE(downmix_coeff_t,        0, DOWNMIX_COEFF_SIZE);
 
 static void read_video_attr(video_attr_t *va) {
   getbits_state_t state;
@@ -539,15 +538,19 @@ ifo_handle_t *ifoOpenVMGI(dvd_reader_t *ctx) {
     ifop->ctx = ctx;
     ifop->file = DVDOpenFile(ctx, 0, domain);
     if(!ifop->file) { /* Should really catch any error */
-      Log1(ctx, "Can't open file VIDEO_TS.%s.", ext);
+      Log1(ctx, "Can't open file %s_TS.%s.", 
+           DVD_TYPE_STRING( ctx->dvd_type ), ext);
       free(ifop);
       return NULL;
     }
 
-    if(ifoRead_VMG(&ifop->handle))
+    if((ctx->dvd_type == DVD_V ? ifoRead_VMG : ifoRead_AMG)(&ifop->handle)){
+      ifop->handle.ifo_format = ctx->dvd_type == DVD_V ? IFO_VIDEO : IFO_AUDIO;
       return &ifop->handle;
+     }
 
-    Log1(ctx, "ifoOpenVMGI(): Invalid main menu IFO (%s_TS.%s).", DVD_TYPE_STRING( ctx->dvd_type ), ext);
+    Log1(ctx, "ifoOpenVMGI(): Invalid main menu IFO (%s_TS.%s).", 
+         DVD_TYPE_STRING( ctx->dvd_type ), ext);
     ifoClose(&ifop->handle);
   }
   return NULL;
@@ -575,13 +578,18 @@ ifo_handle_t *ifoOpenVTSI(dvd_reader_t *ctx, int title) {
     ifop->file = DVDOpenFile(ctx, title, domain);
     /* Should really catch any error */
     if(!ifop->file) {
-      Log1(ctx, "Can't open file %cTS_%02d_0.%s.", STREAM_TYPE_STRING( ctx->dvd_type ), title, ext);
+      Log1(ctx, "Can't open file %cTS_%02d_0.%s.",
+           STREAM_TYPE_STRING( ctx->dvd_type ), title, ext);
       free(ifop);
       continue;
     }
 
-    if(ifoRead_VTS(&ifop->handle) && ifop->handle.vtsi_mat)
-      return &ifop->handle;
+      if ((ctx->dvd_type == DVD_V
+              ? (ifoRead_VTS(&ifop->handle) && ifop->handle.vtsi_mat)
+              : (ifoRead_ATS(&ifop->handle) && ifop->handle.atsi_mat))) {
+        ifop->handle.ifo_format = ctx->dvd_type == DVD_V ? IFO_VIDEO : IFO_AUDIO;
+        return &ifop->handle;
+      }
 
     Log1(ctx, "Invalid IFO for title %d (%cTS_%02d_0.%s).",
             title, STREAM_TYPE_STRING( ctx->dvd_type ), title, ext);
@@ -592,21 +600,26 @@ ifo_handle_t *ifoOpenVTSI(dvd_reader_t *ctx, int title) {
 }
 
 void ifoFree_TT(ifo_handle_t *ifofile){
-  for (int j=0;j<ifofile->atsi_title_table->nr_titles;j++){
-    free((ifofile->atsi_title_table->atsi_title_row_tables+j)->atsi_track_pointer_rows);
-    free((ifofile->atsi_title_table->atsi_title_row_tables+j)->atsi_track_timestamp_rows);
+  if(!ifofile)
+    return;
+
+  if (ifofile->atsi_title_table) {
+    for (int j=0;j<ifofile->atsi_title_table->nr_titles;j++){
+      free((ifofile->atsi_title_table->atsi_title_row_tables+j)->atsi_track_pointer_rows);
+      free((ifofile->atsi_title_table->atsi_title_row_tables+j)->atsi_track_timestamp_rows);
+    }
+    free(ifofile->atsi_title_table->atsi_title_row_tables);
+    free(ifofile->atsi_title_table->atsi_index_rows);
+    free(ifofile->atsi_title_table);
+    ifofile->atsi_title_table= NULL;
   }
-  free(ifofile->atsi_title_table->atsi_title_row_tables);
-  free(ifofile->atsi_title_table->atsi_index_rows);
-  free(ifofile->atsi_title_table);
-  ifofile->atsi_title_table= NULL;
 }
 
 void ifoClose(ifo_handle_t *ifofile) {
   if(!ifofile)
     return;
 
-  switch (ifofile->ifo_format) {
+  switch(ifofile->ifo_format) {
     case IFO_VIDEO:
       ifoFree_VOBU_ADMAP(ifofile);
       ifoFree_TITLE_VOBU_ADMAP(ifofile);
@@ -783,20 +796,21 @@ static int ifoRead_SAMG(ifo_handle_t *ifofile) {
   B2N_16(samg_mat->specification_version);
 
   samg_mat->samg_chapters = calloc(samg_mat->nr_chapters, sizeof(samg_chapter_t));
-  if(!samg_mat->samg_chapters){
+  if(!samg_mat->samg_chapters) {
     free(ifofile->samg_mat);
     ifofile->samg_mat = NULL;
     return 0;
   }
 
-  if(!DVDReadBytes(ifop->file, samg_mat->samg_chapters, samg_mat->nr_chapters* sizeof(samg_chapter_t))) {
+  if(!DVDReadBytes(ifop->file, samg_mat->samg_chapters, 
+                   samg_mat->nr_chapters * sizeof(samg_chapter_t))) {
     free(ifofile->samg_mat->samg_chapters);
     free(ifofile->samg_mat);
     ifofile->samg_mat = NULL;
     return 0;
   }
 
-  for (int i=0; i<samg_mat->nr_chapters; i++) {
+  for (int i = 0; i < samg_mat->nr_chapters; i++) {
     samg_chapter_t *index = &samg_mat->samg_chapters[i];
     CHECK_ZERO(index->zero_1);
     B2N_32(index->timestamp_pts);
@@ -808,138 +822,147 @@ static int ifoRead_SAMG(ifo_handle_t *ifofile) {
     CHECK_ZERO(index->zero_3);
   }
 
-
   return 1;
 }
 
-static int ifoRead_TT(ifo_handle_t *ifofile){
+int ifoRead_TT(ifo_handle_t *ifofile) {
 
   struct ifo_handle_private_s *ifop = PRIV(ifofile);
-  atsi_title_table_t* atsi_title_table;
+  atsi_title_table_t *atsi_title_table;
 
   atsi_title_table= calloc(1, sizeof(atsi_title_table_t));
+
   if(!atsi_title_table)
     return 0;
 
-  ifofile->atsi_title_table= atsi_title_table;
+  ifofile->atsi_title_table = atsi_title_table;
 
   if(!DVDFileSeek_(ifop->file, DVD_BLOCK_LEN)) {
     free(ifofile->atsi_title_table);
-    ifofile->atsi_title_table= NULL;
+    ifofile->atsi_title_table = NULL;
     return 0;
   }
 
   if(!DVDReadBytes(ifop->file, atsi_title_table, ATSI_TITLE_TABLE_SIZE)) {
     free(ifofile->atsi_title_table);
-    ifofile->atsi_title_table= NULL;
+    ifofile->atsi_title_table = NULL;
     return 0;
   }
 
   B2N_16(atsi_title_table->nr_titles);
   B2N_32(atsi_title_table->last_byte_address);
 
-  atsi_title_table->atsi_index_rows= calloc(atsi_title_table->nr_titles,sizeof(atsi_title_index_t));
-  if(!atsi_title_table->atsi_index_rows){
+  atsi_title_table->atsi_index_rows = calloc(atsi_title_table->nr_titles,sizeof(atsi_title_index_t));
+  if(!atsi_title_table->atsi_index_rows) {
     free(ifofile->atsi_title_table);
-    ifofile->atsi_title_table= NULL;
+    ifofile->atsi_title_table = NULL;
     return 0;
   }
 
 
-  if(!DVDReadBytes(ifop->file, atsi_title_table->atsi_index_rows, atsi_title_table->nr_titles * sizeof(atsi_title_index_t))) {
+  if(!DVDReadBytes(ifop->file, atsi_title_table->atsi_index_rows, 
+                   atsi_title_table->nr_titles * sizeof(atsi_title_index_t))) {
     free(ifofile->atsi_title_table->atsi_index_rows);
-
     free(ifofile->atsi_title_table);
-    ifofile->atsi_title_table= NULL;
+    ifofile->atsi_title_table = NULL;
     return 0;
   }
   
-  for(int i=0; i<atsi_title_table->nr_titles;i++)
+  for(int i=0; i<atsi_title_table->nr_titles; i++)
     B2N_32(atsi_title_table->atsi_index_rows[i].offset_record_table);
   
   
-  atsi_title_table->atsi_title_row_tables= calloc(atsi_title_table->nr_titles,sizeof(atsi_title_record_t));
+  atsi_title_table->atsi_title_row_tables = calloc(atsi_title_table->nr_titles, sizeof(atsi_title_record_t));
 
-  if(!atsi_title_table->atsi_title_row_tables){
+  if(!atsi_title_table->atsi_title_row_tables) {
     free(ifofile->atsi_title_table->atsi_index_rows);
     free(ifofile->atsi_title_table);
-    ifofile->atsi_title_table= NULL;
+    ifofile->atsi_title_table = NULL;
     return 0;
   }
 
   int i;
-  for (i=0;i<atsi_title_table->nr_titles; i++){
-    atsi_title_record_t *index=(atsi_title_table->atsi_title_row_tables+i);
+  for (i=0; i < atsi_title_table->nr_titles; i++){
+    atsi_title_record_t *index = (atsi_title_table->atsi_title_row_tables + i);
 
-    if(!DVDFileSeek_(ifop->file, (atsi_title_table->atsi_index_rows+i)->offset_record_table +DVD_BLOCK_LEN))
+    uint32_t record_offset = (atsi_title_table->atsi_index_rows+i)->offset_record_table;
+    if(!DVDFileSeek_(ifop->file, record_offset + DVD_BLOCK_LEN))
       goto fail_audio;
 
-    if(!DVDReadBytes(ifop->file, index,ATSI_TITLE_ROW_TABLE_SIZE))
+    if(!DVDReadBytes(ifop->file, index, ATSI_TITLE_ROW_TABLE_SIZE))
       goto fail_audio;
 
     B2N_16(index->start_sector_pointers_table);
     B2N_32(index->length_pts);
     int nr_tracks=index->nr_tracks;
-    int nr_pointer_records=index->nr_pointer_records;
+    int nr_pointer_records = index->nr_pointer_records;
 
-    index->atsi_track_timestamp_rows= calloc(nr_tracks,sizeof(atsi_track_timestamp_t));
+    index->atsi_track_timestamp_rows = calloc(nr_tracks, sizeof(atsi_track_timestamp_t));
     if(!index->atsi_track_timestamp_rows)
       goto fail_audio;
 
-    index->atsi_track_pointer_rows= calloc(nr_pointer_records,sizeof(atsi_track_pointer_t));
+    index->atsi_track_pointer_rows = calloc(nr_pointer_records, sizeof(atsi_track_pointer_t));
     if(!index->atsi_track_pointer_rows)
       goto fail_audio;
 
-    if(!DVDReadBytes(ifop->file, index->atsi_track_timestamp_rows, nr_tracks* sizeof(atsi_track_timestamp_t))) {
+    if(!DVDReadBytes(ifop->file, index->atsi_track_timestamp_rows,
+                     nr_tracks * sizeof(atsi_track_timestamp_t))) {
       free(index->atsi_track_timestamp_rows);
       goto fail_audio;
     }
 
-    if(!DVDFileSeek_(ifop->file, (atsi_title_table->atsi_index_rows+i)->offset_record_table +index->start_sector_pointers_table + DVD_BLOCK_LEN)) {
+    if(!DVDFileSeek_(ifop->file, (atsi_title_table->atsi_index_rows + i)->offset_record_table
+                     + index->start_sector_pointers_table + DVD_BLOCK_LEN)) {
       free(index->atsi_track_timestamp_rows);
       free(index->atsi_track_pointer_rows);
       goto fail_audio;
     }
 
-    if(!DVDReadBytes(ifop->file, index->atsi_track_pointer_rows, nr_pointer_records* sizeof(atsi_track_pointer_t))) {
+    if(!DVDReadBytes(ifop->file, index->atsi_track_pointer_rows,
+                     nr_pointer_records * sizeof(atsi_track_pointer_t))) {
       free(index->atsi_track_timestamp_rows);
       free(index->atsi_track_pointer_rows);
       goto fail_audio;
     }
     
-    for ( int j=0; j<nr_tracks;j++){
+    for (int j = 0; j<nr_tracks; j++) {
       CHECK_ZERO(index->atsi_track_timestamp_rows[j].zero);
       B2N_32(index->atsi_track_timestamp_rows[j].first_pts_of_track);
       B2N_32(index->atsi_track_timestamp_rows[j].length_pts_of_track);
     }
 
-    for ( int j=0; j<nr_pointer_records;j++){
+    for (int j = 0; j<nr_pointer_records; j++) {
       B2N_32(index->atsi_track_pointer_rows[j].start_sector);
       B2N_32(index->atsi_track_pointer_rows[j].end_sector);
     }
 
+    /* Sanity Check */
+    CHECK_VALUE( index->start_sector_pointers_table
+                 == ( ATSI_TITLE_ROW_TABLE_SIZE 
+                 + index->nr_tracks * ATSI_TRACK_TIMESTAMP_SIZE ) );
+
   }
   return 1;
 
   fail_audio:
-      for (int j=0;j<i;j++){
-        free((atsi_title_table->atsi_title_row_tables+j)->atsi_track_pointer_rows);
-        free((atsi_title_table->atsi_title_row_tables+j)->atsi_track_timestamp_rows);
+      for (int j = 0; j < i; j++){
+        free((atsi_title_table->atsi_title_row_tables + j)->atsi_track_pointer_rows);
+        free((atsi_title_table->atsi_title_row_tables + j)->atsi_track_timestamp_rows);
       }
       free(atsi_title_table->atsi_title_row_tables);
       free(ifofile->atsi_title_table->atsi_index_rows);
       free(ifofile->atsi_title_table);
-      ifofile->atsi_title_table= NULL;
+      ifofile->atsi_title_table = NULL;
       return 0;
 }
 
-static int ifoRead_TIF(ifo_handle_t *ifofile, int sector_offset){
+int ifoRead_TIF(ifo_handle_t *ifofile, int sector_offset) {
   /* check early if sector_offset corresponds to one of the tables */
-  if ( sector_offset != 2 && sector_offset != 1 )
+  if (sector_offset != 2 && sector_offset != 1)
     return 0;
 
   struct ifo_handle_private_s *ifop = PRIV(ifofile);
-  tracks_info_table_t* tracks_info_table;
+  tracks_info_table_t *tracks_info_table;
 
   tracks_info_table= calloc(1, sizeof(tracks_info_table_t));
   if(!tracks_info_table)
@@ -958,24 +981,25 @@ static int ifoRead_TIF(ifo_handle_t *ifofile, int sector_offset){
   B2N_16(tracks_info_table->nr_of_titles);
   B2N_16(tracks_info_table->last_byte_in_table);
 
-  tracks_info_table->tracks_info= calloc(tracks_info_table->nr_of_titles,sizeof(track_info_t));
-  if(!tracks_info_table->tracks_info){
+  tracks_info_table->tracks_info = calloc(tracks_info_table->nr_of_titles,sizeof(track_info_t));
+  if(!tracks_info_table->tracks_info) {
     free(tracks_info_table);
     return 0;
   }
 
-  if(!DVDReadBytes(ifop->file, tracks_info_table->tracks_info, tracks_info_table->nr_of_titles * sizeof(track_info_t) )) {
+  if(!DVDReadBytes(ifop->file, tracks_info_table->tracks_info,
+                   tracks_info_table->nr_of_titles * sizeof(track_info_t))) {
     free(tracks_info_table->tracks_info);
     free(tracks_info_table);
     return 0;
   }
 
   /* the second table is an audio_ts only table, the first is audio_ts, video_ts, strangly the nr_titles in second table doesnt match up with the true nr_titles for this table. Need to subtract video titles*/
-  for(int i=0; i<tracks_info_table->nr_of_titles;i++){
-    if (tracks_info_table->tracks_info[i].type_and_rank==0 && sector_offset == 2){
-     tracks_info_table->tracks_info = realloc(tracks_info_table->tracks_info,i*sizeof(track_info_t));
-     tracks_info_table->nr_of_titles=i;
-     break;
+  for(int i=0; i<tracks_info_table->nr_of_titles; i++) {
+    if(tracks_info_table->tracks_info[i].type_and_rank==0 && sector_offset == 2) {
+      tracks_info_table->tracks_info = realloc(tracks_info_table->tracks_info, i * sizeof(track_info_t));
+      tracks_info_table->nr_of_titles = i;
+      break;
     }
     B2N_32(tracks_info_table->tracks_info[i].len_audio_zone_pts);
     CHECK_ZERO(tracks_info_table->tracks_info[i].zero_1);
@@ -986,17 +1010,17 @@ static int ifoRead_TIF(ifo_handle_t *ifofile, int sector_offset){
   /* sector table two's size and end byte are always the same as sector one's table
    * even though it will be equal to or smaller, since it only lists audio titles 
    * sector two's table has been resized in the ifo to match it's true size */
-  if( sector_offset == 1 )
+  if(sector_offset == 1)
     CHECK_VALUE( (TRACKS_INFO_TABLE_SIZE + 
                   tracks_info_table->nr_of_titles * TRACK_INFO_SIZE -
                   1) == tracks_info_table->last_byte_in_table );
 
-  switch (sector_offset) {
+  switch(sector_offset) {
     case 1:
-      ifofile->info_table_first_sector= tracks_info_table;
+      ifofile->info_table_first_sector = tracks_info_table;
       break;
     case 2:
-      ifofile->info_table_second_sector= tracks_info_table;
+      ifofile->info_table_second_sector = tracks_info_table;
       break;
   }
 
@@ -1200,13 +1224,9 @@ static int ifoRead_ATS(ifo_handle_t *ifofile) {
     return 0;
   }
 
-  //for (int i=0; i<ATSI_RECORD_MAX_SIZE;i++){
-  //  B2N_16(atsi_mat->atsi_record[i].encoding);
-  //  B2N_32(atsi_mat->atsi_record[i].audio_format);
-  //}
-
-  for (int i=0; i<DOWNMIX_COEFF_MAX_SIZE;i++){
-      B2N_64(atsi_mat->downmix_coeff[i]);
+  for (int i=0; i < DOWNMIX_COEFF_MAX_SIZE; i++) {
+    CHECK_ZERO(atsi_mat->downmix_coefficients[i].zero_1);
+    CHECK_ZERO(atsi_mat->downmix_coefficients[i].zero_2);
   }
   
 
@@ -1230,8 +1250,6 @@ static int ifoRead_ATS(ifo_handle_t *ifofile) {
   return 1;
 }
 
-
-
 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile,
                                    pgc_command_tbl_t *cmd_tbl,
                                    unsigned int offset) {



View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/3d973d0be47a009a1468b3b9340c1c290bf5ee4a...6df1a3f8c8e3f9dd8c50926e3c33885531d41c8e

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/3d973d0be47a009a1468b3b9340c1c290bf5ee4a...6df1a3f8c8e3f9dd8c50926e3c33885531d41c8e
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the libdvdnav-devel mailing list