OSDN Git Service

BuildSystem:
[handbrake-jp/handbrake-jp-git.git] / libhb / dvd.c
index 05e9bde..85fe47e 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
 
    This file is part of the HandBrake source code.
-   Homepage: <http://handbrake.m0k.org/>.
+   Homepage: <http://handbrake.fr/>.
    It may be used under the terms of the GNU General Public License. */
 
 #include "hb.h"
@@ -83,7 +83,10 @@ hb_dvd_t * hb_dvd_init( char * path )
     /* Open device */
     if( !( d->reader = DVDOpen( path ) ) )
     {
-        hb_error( "dvd: DVDOpen failed (%s)", path );
+        /*
+         * Not an error, may be a stream - which we'll try in a moment.
+         */
+        hb_log( "dvd: not a dvd - trying as a stream/file instead" );
         goto fail;
     }
 
@@ -162,6 +165,11 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         goto fail;
     }
 
+    if( global_verbosity_level == 3 )
+    {
+        ifoPrint( d->reader, title->vts );
+    }
+
     /* Position of the title in the VTS */
     title->ttn = d->vmg->tt_srpt->title[t-1].vts_ttn;
 
@@ -178,6 +186,12 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         goto fail;
     }
 
+    if( pgn <= 0 || pgn > 99 )
+    {
+        hb_error( "scan: pgn %d not valid, skipping", pgn );
+        goto fail;
+    }
+
     /* Start cell */
     title->cell_start  = d->pgc->program_map[pgn-1] - 1;
     title->block_start = d->pgc->cell_playback[title->cell_start].first_sector;
@@ -228,6 +242,7 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         int          audio_format, lang_code, audio_control,
                      position, j;
         iso639_lang_t * lang;
+        int lang_extension = 0;
 
         hb_log( "scan: checking audio %d", i + 1 );
 
@@ -235,6 +250,7 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
 
         audio_format  = vts->vtsi_mat->vts_audio_attr[i].audio_format;
         lang_code     = vts->vtsi_mat->vts_audio_attr[i].lang_code;
+        lang_extension = vts->vtsi_mat->vts_audio_attr[i].code_extension;
         audio_control =
             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->audio_control[i];
 
@@ -251,28 +267,28 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         {
             case 0x00:
                 audio->id    = ( ( 0x80 + position ) << 8 ) | 0xbd;
-                audio->codec = HB_ACODEC_AC3;
+                audio->config.in.codec = HB_ACODEC_AC3;
                 break;
 
             case 0x02:
             case 0x03:
                 audio->id    = 0xc0 + position;
-                audio->codec = HB_ACODEC_MPGA;
+                audio->config.in.codec = HB_ACODEC_MPGA;
                 break;
 
             case 0x04:
                 audio->id    = ( ( 0xa0 + position ) << 8 ) | 0xbd;
-                audio->codec = HB_ACODEC_LPCM;
+                audio->config.in.codec = HB_ACODEC_LPCM;
                 break;
 
             case 0x06:
                 audio->id    = ( ( 0x88 + position ) << 8 ) | 0xbd;
-                audio->codec = HB_ACODEC_DCA;
+                audio->config.in.codec = HB_ACODEC_DCA;
                 break;
 
             default:
                 audio->id    = 0;
-                audio->codec = 0;
+                audio->config.in.codec = 0;
                 hb_log( "scan: unknown audio codec (%x)",
                         audio_format );
                 break;
@@ -300,21 +316,43 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
             continue;
         }
 
+        audio->config.lang.type = lang_extension;
+
         lang = lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code );
 
-        snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)",
+        snprintf( audio->config.lang.description, sizeof( audio->config.lang.description ), "%s (%s)",
             strlen(lang->native_name) ? lang->native_name : lang->eng_name,
-            audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec ==
-                HB_ACODEC_DCA ? "DTS" : ( audio->codec ==
+            audio->config.in.codec == HB_ACODEC_AC3 ? "AC3" : ( audio->config.in.codec ==
+                HB_ACODEC_DCA ? "DTS" : ( audio->config.in.codec ==
                 HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) ) );
-        snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s",
+        snprintf( audio->config.lang.simple, sizeof( audio->config.lang.simple ), "%s",
                   strlen(lang->native_name) ? lang->native_name : lang->eng_name );
-        snprintf( audio->iso639_2, sizeof( audio->iso639_2 ), "%s",
+        snprintf( audio->config.lang.iso639_2, sizeof( audio->config.lang.iso639_2 ), "%s",
                   lang->iso639_2);
 
-        hb_log( "scan: id=%x, lang=%s, 3cc=%s", audio->id,
-                audio->lang, audio->iso639_2 );
+        switch( lang_extension )
+        {
+        case 0:
+        case 1:
+            break;
+        case 2:
+            strcat( audio->config.lang.description, " (Visually Impaired)" );
+            break;
+        case 3:
+            strcat( audio->config.lang.description, " (Director's Commentary 1)" );
+            break;
+        case 4:
+            strcat( audio->config.lang.description, " (Director's Commentary 2)" );
+            break;
+        default:
+            break;
+        }
+
+        hb_log( "scan: id=%x, lang=%s, 3cc=%s ext=%i", audio->id,
+                audio->config.lang.description, audio->config.lang.iso639_2,
+                lang_extension );
 
+        audio->config.in.track = i;
         hb_list_add( title->list_audio, audio );
     }
 
@@ -335,6 +373,7 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         int spu_control;
         int position;
         iso639_lang_t * lang;
+        int lang_extension = 0;
 
         hb_log( "scan: checking subtitle %d", i + 1 );
 
@@ -366,14 +405,64 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
             position = ( spu_control >> 24 ) & 0x7F;
         }
 
+        lang_extension = vts->vtsi_mat->vts_subp_attr[i].code_extension;
+
         lang = lang_for_code( vts->vtsi_mat->vts_subp_attr[i].lang_code );
 
         subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
         subtitle->id = ( ( 0x20 + position ) << 8 ) | 0xbd;
         snprintf( subtitle->lang, sizeof( subtitle->lang ), "%s",
              strlen(lang->native_name) ? lang->native_name : lang->eng_name);
-       snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "%s",
-                 lang->iso639_2);
+        snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "%s",
+                  lang->iso639_2);
+
+        subtitle->type = lang_extension;
+
+        switch( lang_extension )
+        {  
+        case 0:
+            break;
+        case 1:
+            break;
+        case 2:
+            strcat( subtitle->lang, " (Caption with bigger size character)");
+            break;
+        case 3: 
+            strcat( subtitle->lang, " (Caption for Children)");
+            break;
+        case 4:
+            break;
+        case 5:
+            strcat( subtitle->lang, " (Closed Caption)");
+            break;
+        case 6:
+            strcat( subtitle->lang, " (Closed Caption with bigger size character)");
+            break;
+        case 7:
+            strcat( subtitle->lang, " (Closed Caption for Children)");
+            break;
+        case 8:
+            break;
+        case 9:
+            strcat( subtitle->lang, " (Forced Caption)");
+            break;
+        case 10:
+            break;
+        case 11:
+            break;
+        case 12:
+            break;
+        case 13:
+            strcat( subtitle->lang, " (Director's Commentary)");
+            break;
+        case 14:
+            strcat( subtitle->lang, " (Director's Commentary with bigger size character)");
+            break;
+        case 15:
+            strcat( subtitle->lang, " (Director's Commentary for Children)");
+        default:
+            break;
+        }
 
         hb_log( "scan: id=%x, lang=%s, 3cc=%s", subtitle->id,
                 subtitle->lang, subtitle->iso639_2 );
@@ -478,17 +567,17 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
     switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
     {
         case 0:
-            title->aspect = HB_ASPECT_BASE * 4 / 3;
+            title->container_aspect = 4. / 3.;
             break;
         case 3:
-            title->aspect = HB_ASPECT_BASE * 16 / 9;
+            title->container_aspect = 16. / 9.;
             break;
         default:
             hb_log( "scan: unknown aspect" );
             goto fail;
     }
 
-    hb_log( "scan: aspect = %d", title->aspect );
+    hb_log( "scan: aspect = %g", title->aspect );
 
     /* This title is ok so far */
     goto cleanup;
@@ -861,11 +950,14 @@ int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
             }
             else
             {
-                hb_log( "dvd: Beginning of Cell (%d) at block %d", d->cell_cur,
-                       d->block );
+                if ( d->block != d->pgc->cell_playback[d->cell_cur].first_sector )
+                {
+                    hb_log( "dvd: beginning of cell %d at block %d", d->cell_cur,
+                           d->block );
+                }
                 if( d->in_cell )
                 {
-                    hb_error( "dvd: Assuming missed End of Cell (%d)", d->cell_cur );
+                    hb_error( "dvd: assuming missed end of cell %d", d->cell_cur );
                     d->cell_cur  = d->cell_next;
                     d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
                     FindNextCell( d );
@@ -888,8 +980,12 @@ int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
         if( ( dsi_pack.vobu_sri.next_vobu & (1 << 31 ) ) == 0 ||
             ( dsi_pack.vobu_sri.next_vobu & 0x3fffffff ) == 0x3fffffff )
         {
-            hb_log( "dvd: End of Cell (%d) at block %d", d->cell_cur,
-                    d->block );
+            if ( d->block <= d->pgc->cell_playback[d->cell_cur].first_sector ||
+                 d->block > d->pgc->cell_playback[d->cell_cur].last_sector )
+            {
+                hb_log( "dvd: end of cell %d at block %d", d->cell_cur,
+                        d->block );
+            }
             d->cell_cur  = d->cell_next;
             d->in_cell = 0;
             d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
@@ -955,7 +1051,7 @@ int hb_dvd_chapter( hb_dvd_t * d )
 /***********************************************************************
  * hb_dvd_is_break
  ***********************************************************************
- * Returns 1 if the current block is a new chapter start
+ * Returns chapter number if the current block is a new chapter start
  **********************************************************************/
 int hb_dvd_is_break( hb_dvd_t * d )
 {
@@ -981,8 +1077,7 @@ int hb_dvd_is_break( hb_dvd_t * d )
         // This must not match against the start cell.
         if( pgc->cell_playback[cell].first_sector == d->block && cell != d->cell_start )
         {
-            hb_log("dvd: Chapter Break Cell Found");
-            return 1;
+            return i + 1;
         }
     }