[vlc-devel] [PATCH 03/12] chromecast: wait until we know all the ES is use before using sending data downstream

Steve Lhomme robux4 at videolabs.io
Tue Apr 26 11:00:59 CEST 2016


This patch is replaced and merged into https://patches.videolan.org/patch/13091/

On Mon, Apr 25, 2016 at 5:46 PM, Steve Lhomme <robux4 at videolabs.io> wrote:
> ---
>  modules/stream_out/chromecast/cast.cpp | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
> index ef7f428..1581695 100644
> --- a/modules/stream_out/chromecast/cast.cpp
> +++ b/modules/stream_out/chromecast/cast.cpp
> @@ -42,14 +42,17 @@ struct sout_stream_sys_t
>          : p_out(sout)
>          , p_intf(intf)
>          , b_has_video(has_video)
> +        , last_added_ts( VLC_TS_INVALID )
>      {
>          assert(p_intf != NULL);
>          vlc_mutex_init( &es_lock );
> +        vlc_cond_init( &es_changed_cond );
>      }
>
>      ~sout_stream_sys_t()
>      {
>          sout_StreamChainDelete(p_out, p_out);
> +        vlc_cond_destroy( &es_changed_cond );
>          vlc_mutex_destroy( &es_lock );
>      }
>
> @@ -60,10 +63,16 @@ struct sout_stream_sys_t
>      sout_stream_id_sys_t *GetSubId( sout_stream_t*, sout_stream_id_sys_t* );
>
>      vlc_mutex_t                        es_lock;
> +    vlc_cond_t                         es_changed_cond;
> +    mtime_t                            last_added_ts;
>      std::vector<sout_stream_id_sys_t*> streams;
> +
> +private:
> +    int WaitEsReady( sout_stream_t * );
>  };
>
>  #define SOUT_CFG_PREFIX "sout-chromecast-"
> +const static mtime_t MAX_WAIT_BETWEEN_ADD = (CLOCK_FREQ / 3);
>
>  /*****************************************************************************
>   * Local prototypes
> @@ -134,6 +143,8 @@ static sout_stream_id_sys_t *Add(sout_stream_t *p_stream, const es_format_t *p_f
>
>          vlc_mutex_locker locker( &p_sys->es_lock );
>          p_sys->streams.push_back( p_sys_id );
> +        p_sys->last_added_ts = mdate();
> +        vlc_cond_signal( &p_sys->es_changed_cond );
>      }
>      return p_sys_id;
>  }
> @@ -159,6 +170,25 @@ static void Del(sout_stream_t *p_stream, sout_stream_id_sys_t *id)
>      }
>  }
>
> +int sout_stream_sys_t::WaitEsReady( sout_stream_t *p_stream )
> +{
> +    assert( p_stream->p_sys == this );
> +
> +    if ( last_added_ts != VLC_TS_INVALID )
> +    {
> +        while ( last_added_ts + MAX_WAIT_BETWEEN_ADD < mdate() )
> +        {
> +            // wait for adding/removing ES expired
> +            mutex_cleanup_push( &es_lock );
> +            vlc_cond_timedwait( &es_changed_cond, &es_lock, last_added_ts + MAX_WAIT_BETWEEN_ADD );
> +            vlc_cleanup_pop();
> +        }
> +        last_added_ts = VLC_TS_INVALID;
> +    }
> +
> +    return VLC_SUCCESS;
> +}
> +
>  sout_stream_id_sys_t *sout_stream_sys_t::GetSubId( sout_stream_t *p_stream,
>                                                     sout_stream_id_sys_t *id )
>  {
> @@ -167,6 +197,9 @@ sout_stream_id_sys_t *sout_stream_sys_t::GetSubId( sout_stream_t *p_stream,
>      assert( p_stream->p_sys == this );
>
>      vlc_mutex_locker locker( &es_lock );
> +    if ( WaitEsReady( p_stream ) != VLC_SUCCESS )
> +        return NULL;
> +
>      for (i = 0; i < streams.size(); ++i)
>      {
>          if ( id == (sout_stream_id_sys_t*) streams[i] )
> --
> 2.7.0
>


More information about the vlc-devel mailing list