Changeset ea89b9c2d9d5b13c28da56f6b5ec284614db491f

Show
Ignore:
Timestamp:
06/06/08 00:14:59 (4 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1212704099 +0200
git-parent:

[6f8ce7ca56918ca2423b8728a3276aac8ba1cfe4]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1212704007 +0200
Message:

input: Add --auto-adjust-pts-delay, this allows to stream/receive with an extremely low latency.

Simple demo:
vlc --sout="#duplicate{dst=display,dst='transcode{vcodec=mp4v}:std{access=http,dst=0.0.0.0:8080,mux=ts}'}" --ignore-config --use-stream-immediate movie.avi &
vlc --use-stream-immediate http://127.0.0.1:8080
and
vlc --use-stream-immediate http://127.0.0.1:8080 --auto-adjust-pts-delay

You'll have to wait a bit until the pts delay is auto adjusted. Generally it takes 2-4 seconds, because access set a very high default pts delay value. One amelioration would be to lower the pts_delay when this option is set to allow a quicker convergence.

The general algorithm requires some tuning, but results are here.

Note, this only works if there is a video track. A similar function could be developped for the audio tracks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/input/decoder.c

    rd666030 rea89b9c  
    727727    vlc_mutex_unlock( &p_vout->picture_lock ); 
    728728} 
     729 
     730 
     731static void optimize_video_pts( decoder_t *p_dec ) 
     732{ 
     733    picture_t * oldest_pict = NULL; 
     734    picture_t * youngest_pict = NULL; 
     735    int i; 
     736 
     737    input_thread_t * p_input = p_dec->p_owner->p_input; 
     738    vout_thread_t * p_vout = p_dec->p_owner->p_vout; 
     739    input_thread_private_t * p_priv = p_input->p; 
     740 
     741    if( !p_priv->pts_adjust.auto_adjust ) return; 
     742 
     743    for( i = 0; i < I_RENDERPICTURES; i++ ) 
     744    { 
     745        picture_t * pic = PP_RENDERPICTURE[i]; 
     746        if( pic->i_status != READY_PICTURE ) 
     747            continue; 
     748 
     749        if( !oldest_pict || pic->date < oldest_pict->date ) 
     750            oldest_pict = pic; 
     751        if( !youngest_pict || pic->date > youngest_pict->date ) 
     752            youngest_pict = pic; 
     753    } 
     754 
     755    if( !youngest_pict || !oldest_pict ) 
     756        return; 
     757 
     758    /* Try to find if we can reduce the pts 
     759     * This first draft is way to simple, and we can't say if the 
     760     * algo will converge. It's also full of constants. 
     761     * But this simple algo allows to reduce the latency 
     762     * to the minimum. */ 
     763    mtime_t buffer_size = youngest_pict->date - oldest_pict->date; 
     764    int64_t pts_slide = 0; 
     765    if( buffer_size < 10000 ) 
     766    { 
     767        if( p_priv->pts_adjust.i_num_faulty > 10 ) 
     768        { 
     769            pts_slide = __MAX(p_input->i_pts_delay *3 / 2, 10000); 
     770            p_priv->pts_adjust.i_num_faulty = 0; 
     771        } 
     772        if( p_priv->pts_adjust.to_high ) 
     773        { 
     774            p_priv->pts_adjust.to_high = !p_priv->pts_adjust.to_high; 
     775            p_priv->pts_adjust.i_num_faulty = 0; 
     776        } 
     777        p_priv->pts_adjust.i_num_faulty++; 
     778    } 
     779    else if( buffer_size > 100000 ) 
     780    { 
     781        if( p_priv->pts_adjust.i_num_faulty > 25 ) 
     782        { 
     783            pts_slide = -buffer_size/2; 
     784            p_priv->pts_adjust.i_num_faulty = 0; 
     785        } 
     786        if( p_priv->pts_adjust.to_high ) 
     787        { 
     788            p_priv->pts_adjust.to_high = !p_priv->pts_adjust.to_high; 
     789            p_priv->pts_adjust.i_num_faulty = 0; 
     790        } 
     791        p_priv->pts_adjust.i_num_faulty++; 
     792    } 
     793    if( pts_slide ) 
     794    { 
     795        mtime_t origi_delay = p_input->i_pts_delay; 
     796 
     797        p_input->i_pts_delay += pts_slide; 
     798 
     799        /* Don't play with the pts delay for more than -2<->3sec */ 
     800        if( p_input->i_pts_delay < -2000000 ) 
     801            p_input->i_pts_delay = -2000000; 
     802        else if( p_input->i_pts_delay > 3000000 ) 
     803            p_input->i_pts_delay = 3000000; 
     804        pts_slide = p_input->i_pts_delay - origi_delay; 
     805 
     806        msg_Dbg( p_input, "Sliding the pts by %dms pts delay at %dms picture buffer was %dms", 
     807            (int)pts_slide/1000, (int)p_input->i_pts_delay/1000, (int)buffer_size/1000); 
     808 
     809        vlc_mutex_lock( &p_vout->picture_lock ); 
     810        /* Slide all the picture */ 
     811        for( i = 0; i < I_RENDERPICTURES; i++ ) 
     812            PP_RENDERPICTURE[i]->date += pts_slide; 
     813        /* FIXME: slide aout/spu */ 
     814        vlc_mutex_unlock( &p_vout->picture_lock ); 
     815 
     816    } 
     817} 
     818 
    729819static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block ) 
    730820{ 
     
    758848        vout_DatePicture( p_dec->p_owner->p_vout, p_pic, 
    759849                          p_pic->date ); 
     850 
     851        optimize_video_pts( p_dec ); 
     852 
    760853        vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic ); 
    761854    } 
  • src/input/input_internal.h

    re3c6b24 rea89b9c  
    112112    int            i_slave; 
    113113    input_source_t **slave; 
     114 
     115    /* pts delay fixup */ 
     116    struct { 
     117        int  i_num_faulty; 
     118        bool to_high; 
     119        bool auto_adjust; 
     120    } pts_adjust; 
    114121 
    115122    /* Stats counters */ 
  • src/input/var.c

    rd666030 rea89b9c  
    166166    ADD_CALLBACK( "spu-delay", EsDelayCallback ); 
    167167 
     168    p_input->p->pts_adjust.auto_adjust = var_CreateGetBool( 
     169            p_input, "auto-adjust-pts-delay" ); 
     170 
    168171    /* Video ES */ 
    169172    var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ); 
  • src/libvlc-module.c

    r5df2e97 rea89b9c  
    18231823    add_bool( "use-stream-immediate", false, NULL, 
    18241824               USE_STREAM_IMMEDIATE, USE_STREAM_IMMEDIATE_LONGTEXT, false ); 
     1825    add_bool( "auto-adjust-pts-delay", false, NULL, 
     1826              "auto-adjust-pts-delay", "auto-adjust-pts-delay", false ); 
    18251827 
    18261828#if !defined(__APPLE__) && !defined(SYS_BEOS) && defined(LIBVLC_USE_PTHREAD)