Changeset 25db1407866634d0c9b7cd3bcf5a063735be55d0

Show
Ignore:
Timestamp:
16/02/05 22:16:34 (4 years ago)
Author:
Steve Lhomme <robux@videolan.org>
git-committer:
Steve Lhomme <robux@videolan.org> 1108588594 +0000
git-parent:

[ce1647fa1324d99f7ff13354f85b3b6fa13a2b2e]

git-author:
Steve Lhomme <robux@videolan.org> 1108588594 +0000
Message:

mkv.cpp: use time-based seeking whenever possible

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/mkv.cpp

    rc464008 r25db140  
    13561356#endif 
    13571357 
    1358         if (i_pts < p_sys->i_start_pts) 
    1359         { 
    1360             p_block->i_pts = -1; 
    1361         } 
    1362         else if( tk.fmt.i_cat != VIDEO_ES ) 
     1358        if( tk.fmt.i_cat != VIDEO_ES ) 
    13631359        { 
    13641360            p_block->i_dts = p_block->i_pts = i_pts; 
     
    13921388    int64_t     i_block_ref2; 
    13931389 
    1394     int         i_index
     1390    int         i_index = 0
    13951391    int         i_track_skipping; 
    13961392    int         i_track; 
     
    14101406    if( i_percent >= 0 && (config_GetInt( p_demux, "mkv-seek-percent" ) || !p_sys->b_cues || i_date < 0 )) 
    14111407    { 
    1412         int64_t i_pos = i_percent * stream_Size( p_demux->s ) / 100; 
    1413  
    1414         msg_Dbg( p_demux, "inacurate way of seeking" ); 
    1415         for( i_index = 0; i_index < p_sys->i_index; i_index++ ) 
    1416         { 
    1417             if( p_sys->index[i_index].i_position >= i_pos) 
    1418             { 
    1419                 break; 
    1420             } 
    1421         } 
    1422         if( i_index == p_sys->i_index ) 
    1423         { 
    1424             i_index--; 
    1425         } 
    1426  
    1427         p_sys->in->setFilePointer( p_sys->index[i_index].i_position, 
    1428                                    seek_beginning ); 
    1429  
    1430         if( p_sys->index[i_index].i_position < i_pos ) 
    1431         { 
    1432             EbmlElement *el; 
    1433  
    1434             msg_Warn( p_demux, "searching for cluster, could take some time" ); 
    1435  
    1436             /* search a cluster */ 
    1437             while( ( el = p_sys->ep->Get() ) != NULL ) 
    1438             { 
    1439                 if( MKV_IS_ID( el, KaxCluster ) ) 
    1440                 { 
    1441                     KaxCluster *cluster = (KaxCluster*)el; 
    1442  
    1443                     /* add it to the index */ 
    1444                     IndexAppendCluster( p_demux, cluster ); 
    1445  
    1446                     if( (int64_t)cluster->GetElementPosition() >= i_pos ) 
     1408        if (p_sys->f_duration >= 0) 
     1409        { 
     1410            i_date = i_percent * p_sys->f_duration * 10; 
     1411        } 
     1412        else 
     1413        { 
     1414            int64_t i_pos = i_percent * stream_Size( p_demux->s ) / 100; 
     1415 
     1416            msg_Dbg( p_demux, "inacurate way of seeking" ); 
     1417            for( i_index = 0; i_index < p_sys->i_index; i_index++ ) 
     1418            { 
     1419                if( p_sys->index[i_index].i_position >= i_pos) 
     1420                { 
     1421                    break; 
     1422                } 
     1423            } 
     1424            if( i_index == p_sys->i_index ) 
     1425            { 
     1426                i_index--; 
     1427            } 
     1428 
     1429            i_date = p_sys->index[i_index].i_time; 
     1430 
     1431#if 0 
     1432            if( p_sys->index[i_index].i_position < i_pos ) 
     1433            { 
     1434                EbmlElement *el; 
     1435 
     1436                msg_Warn( p_demux, "searching for cluster, could take some time" ); 
     1437 
     1438                /* search a cluster */ 
     1439                while( ( el = p_sys->ep->Get() ) != NULL ) 
     1440                { 
     1441                    if( MKV_IS_ID( el, KaxCluster ) ) 
    14471442                    { 
    1448                         p_sys->cluster = cluster; 
    1449                         p_sys->ep->Down(); 
    1450                         break; 
     1443                        KaxCluster *cluster = (KaxCluster*)el; 
     1444 
     1445                        /* add it to the index */ 
     1446                        IndexAppendCluster( p_demux, cluster ); 
     1447 
     1448                        if( (int64_t)cluster->GetElementPosition() >= i_pos ) 
     1449                        { 
     1450                            p_sys->cluster = cluster; 
     1451                            p_sys->ep->Down(); 
     1452                            break; 
     1453                        } 
    14511454                    } 
    14521455                } 
    14531456            } 
    1454         } 
    1455    
    1456     else 
    1457     { 
    1458         for( i_index = 0; i_index < p_sys->i_index; i_index++ ) 
    1459        
    1460             if( p_sys->index[i_index].i_time >= i_date ) 
    1461            
    1462                 break; 
    1463            
    1464        
    1465  
    1466         if( i_index > 0 ) 
    1467        
    1468             i_index--; 
    1469        
    1470  
    1471         msg_Dbg( p_demux, "seek got "I64Fd" (%d%%)", 
    1472                 p_sys->index[i_index].i_time, 
    1473                 (int)( 100 * p_sys->index[i_index].i_position / 
    1474                         stream_Size( p_demux->s ) ) ); 
    1475  
    1476         p_sys->in->setFilePointer( p_sys->index[i_index].i_position, 
    1477                                    seek_beginning ); 
    1478     } 
     1457#endif 
     1458       
     1459    } 
     1460 
     1461    for( ; i_index < p_sys->i_index; i_index++ ) 
     1462   
     1463        if( p_sys->index[i_index].i_time > i_date ) 
     1464       
     1465            break; 
     1466       
     1467   
     1468 
     1469    if( i_index > 0 ) 
     1470   
     1471        i_index--; 
     1472   
     1473 
     1474    msg_Dbg( p_demux, "seek got "I64Fd" (%d%%)", 
     1475                p_sys->index[i_index].i_time, 
     1476                (int)( 100 * p_sys->index[i_index].i_position / 
     1477                    stream_Size( p_demux->s ) ) ); 
     1478 
     1479    p_sys->in->setFilePointer( p_sys->index[i_index].i_position, 
     1480                                seek_beginning ); 
     1481 
    14791482 
    14801483    /* now parse until key frame */ 
     
    15131516        if( i_track < p_sys->i_track ) 
    15141517        { 
    1515             if( tk.fmt.i_cat == VIDEO_ES && i_block_ref1 == -1 && tk.b_search_keyframe ) 
    1516             { 
    1517                 tk.b_search_keyframe = VLC_FALSE; 
    1518                 i_track_skipping--; 
    1519             } 
    1520             if( tk.fmt.i_cat == VIDEO_ES && !tk.b_search_keyframe ) 
    1521             { 
    1522                 BlockDecode( p_demux, block, 0, 0 ); 
     1518            if( tk.fmt.i_cat == VIDEO_ES ) 
     1519            { 
     1520                if( i_block_ref1 == -1 && tk.b_search_keyframe ) 
     1521                { 
     1522                    tk.b_search_keyframe = VLC_FALSE; 
     1523                    i_track_skipping--; 
     1524                } 
     1525                if( !tk.b_search_keyframe ) 
     1526                { 
     1527                    BlockDecode( p_demux, block, 0, 0 ); 
     1528/*                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, block->GlobalTimecode() / (mtime_t) 1000 );*/ 
     1529                } 
    15231530            } 
    15241531        } 
     
    15581565        p_sys->i_pts = block->GlobalTimecode() / (mtime_t) 1000; 
    15591566 
    1560         if( p_sys->i_pts > p_sys->i_start_pts  ) 
     1567        if( p_sys->i_pts >= p_sys->i_start_pts  ) 
    15611568        { 
    15621569            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pts ); 
     
    15681575        i_block_count++; 
    15691576 
    1570         if( i_start_pts == -1 ) 
    1571         { 
    1572             i_start_pts = p_sys->i_pts; 
    1573         } 
    1574         else if( p_sys->i_pts > i_start_pts + (mtime_t)100000 || i_block_count > 5 ) 
     1577        if( p_sys->i_pts > i_start_pts + (mtime_t)100000 || i_block_count > 5 ) 
    15751578        { 
    15761579            return 1; 
     
    26242627    } 
    26252628 
    2626     p_sys->f_duration = p_sys->f_duration * p_sys->i_timescale / 1000000.0; 
     2629    p_sys->f_duration *= p_sys->i_timescale / 1000000.0; 
    26272630} 
    26282631