]> git.sesse.net Git - vlc/blobdiff - modules/access/dvdread.c
* modules/access/dvdnav.c,dvdread.c: backport of #11308.
[vlc] / modules / access / dvdread.c
index 297701164ada56b9418df97b882c4e23eef87324..3192ba8a3b36cf122c3fde7009ccf06c025801bb 100644 (file)
@@ -87,7 +87,10 @@ static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin();
-    set_description( _("DVDRead Input") );
+    set_shortname( _("DVD without menus") );
+    set_description( _("DVDRead Input (DVD without menu support)") );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_ACCESS );
     add_integer( "dvdread-angle", 1, NULL, ANGLE_TEXT,
         ANGLE_LONGTEXT, VLC_FALSE );
     add_integer( "dvdread-caching", DEFAULT_PTS_DELAY / 1000, NULL,
@@ -260,7 +263,13 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_angle = val.i_int > 0 ? val.i_int : 1;
 
     DemuxTitles( p_demux, &p_sys->i_angle );
-    DvdReadSetArea( p_demux, 0, 0, p_sys->i_angle );
+    if( DvdReadSetArea( p_demux, 0, 0, p_sys->i_angle ) != VLC_SUCCESS )
+    {
+        Close( p_this );
+        msg_Err( p_demux, "DvdReadSetArea(0,0,%i) failed (can't decrypt DVD?)",
+                 p_sys->i_angle );
+        return VLC_EGENERIC;
+    }
 
     /* Update default_pts to a suitable value for dvdread access */
     var_Create( p_demux, "dvdread-caching",
@@ -297,6 +306,44 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }
 
+static int64_t dvdtime_to_time( dvd_time_t *dtime, uint8_t still_time )
+{
+/* Macro to convert Binary Coded Decimal to Decimal */
+#define BCD2D(__x__) (((__x__ & 0xf0) >> 4) * 10 + (__x__ & 0x0f))
+
+    double f_fps, f_ms;
+    int64_t i_micro_second = 0;
+
+    if (still_time == 0 || still_time == 0xFF)
+    {
+        i_micro_second += (int64_t)(BCD2D(dtime->hour)) * 60 * 60 * 1000000;
+        i_micro_second += (int64_t)(BCD2D(dtime->minute)) * 60 * 1000000;
+        i_micro_second += (int64_t)(BCD2D(dtime->second)) * 1000000;
+
+        switch((dtime->frame_u & 0xc0) >> 6) 
+        {
+        case 1:
+            f_fps = 25.0;
+            break;
+        case 3:
+            f_fps = 29.97;
+            break;
+        default:
+            f_fps = 2500.0;
+            break;
+        }
+        f_ms = BCD2D(dtime->frame_u&0x3f) * 1000.0 / f_fps;
+        i_micro_second += (int64_t)(f_ms * 1000.0);
+    }
+    else
+    {
+        i_micro_second = still_time;
+        i_micro_second = (int64_t)((double)i_micro_second * 1000000.0);
+    }
+    
+    return i_micro_second;
+}
+
 /*****************************************************************************
  * Control:
  *****************************************************************************/
@@ -344,10 +391,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_LENGTH:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            if( p_sys->i_mux_rate > 0 )
+            if (p_demux->info.i_title >= 0 && p_demux->info.i_title < p_sys->i_titles)
             {
-                *pi64 = (int64_t)1000000 * DVD_VIDEO_LB_LEN *
-                        p_sys->i_title_blocks / 50 / p_sys->i_mux_rate;
+                *pi64 = dvdtime_to_time( &p_sys->p_cur_pgc->playback_time, 0 );
+                p_sys->i_mux_rate = p_sys->i_title_blocks * DVD_VIDEO_LB_LEN / (*pi64 / 20000);
                 return VLC_SUCCESS;
             }
             *pi64 = 0;
@@ -450,7 +497,7 @@ static int Demux( demux_t *p_demux )
         DvdReadHandleDSI( p_demux, p_buffer );
 
         /* End of title */
-        if( p_sys->i_next_vobu > p_sys->i_title_end_block )
+        if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells )
         {
             if( p_sys->i_title + 1 >= p_sys->i_titles )
             {
@@ -475,7 +522,7 @@ static int Demux( demux_t *p_demux )
         DemuxBlock( p_demux, p_buffer, DVD_VIDEO_LB_LEN );
     }
 
-    if( p_sys->i_cur_block > p_sys->i_title_end_block )
+    if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells )
     {
         if( p_sys->i_title + 1 >= p_sys->i_titles )
         {
@@ -568,7 +615,7 @@ static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt )
             if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
             {
                 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr );
-                if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
+/*                if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;*/
             }
             block_Release( p_pkt );
             break;
@@ -619,7 +666,7 @@ static void ESNew( demux_t *p_demux, int i_id, int i_lang )
 
     if( tk->b_seen ) return;
 
-    if( ps_track_fill( tk, i_id ) )
+    if( ps_track_fill( tk, 0, i_id ) )
     {
         msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
         return;
@@ -1137,6 +1184,10 @@ static void DvdReadHandleDSI( demux_t *p_demux, uint8_t *p_data )
     else if( p_sys->dsi_pack.vobu_sri.next_vobu == SRI_END_OF_CELL )
     {
         p_sys->i_cur_cell = p_sys->i_next_cell;
+
+        /* End of title */
+        if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells ) return;
+
         DvdReadFindCell( p_demux );
 
         p_sys->i_next_vobu =