[vlc-devel] [PATCH 2/3] chromecast: send a STOP message when we have no ES to send

Rémi Denis-Courmont remi at remlab.net
Mon May 9 19:07:19 CEST 2016


On Monday 09 May 2016 18:56:37 Steve Lhomme wrote:
> ---
>  modules/stream_out/chromecast/cast.cpp            |  2 ++
>  modules/stream_out/chromecast/chromecast.h        |  4 ++++
>  modules/stream_out/chromecast/chromecast_ctrl.cpp | 19 ++++++++++++++++++-
>  3 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/modules/stream_out/chromecast/cast.cpp
> b/modules/stream_out/chromecast/cast.cpp index 94808f5..bc4c462 100644
> --- a/modules/stream_out/chromecast/cast.cpp
> +++ b/modules/stream_out/chromecast/cast.cpp
> @@ -187,6 +187,8 @@ static void Del(sout_stream_t *p_stream,
> sout_stream_id_sys_t *id)
> 
>      if ( p_sys->streams.empty() )
>      {
> +        p_sys->p_intf->requestPlayerStop();
> +
>          sout_StreamChainDelete( p_sys->p_out, p_sys->p_out );
>          p_sys->p_out = NULL;
>          p_sys->sout = "";
> diff --git a/modules/stream_out/chromecast/chromecast.h
> b/modules/stream_out/chromecast/chromecast.h index fd26d6a..1cd55db 100644
> --- a/modules/stream_out/chromecast/chromecast.h
> +++ b/modules/stream_out/chromecast/chromecast.h
> @@ -34,6 +34,7 @@
>  #include <vlc_tls.h>
>  #include <vlc_interrupt.h>
> 
> +#include <atomic>
>  #include <sstream>
> 
>  #include "cast_channel.pb.h"
> @@ -88,6 +89,8 @@ struct intf_sys_t
> 
>      void setHasInput( bool has_input, const std::string mime_type = "");
> 
> +    void requestPlayerStop();
> +
>  private:
>      vlc_object_t  * const p_module;
>      const int      i_port;
> @@ -147,6 +150,7 @@ private:
>      void processMessage(const castchannel::CastMessage &msg);
> 
>      void notifySendRequest();
> +    std::atomic_bool requested_stop;
> 
>      int sendMessage(const castchannel::CastMessage &msg);
> 
> diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp
> b/modules/stream_out/chromecast/chromecast_ctrl.cpp index 22461b4..1dbba93
> 100644
> --- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
> +++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
> @@ -100,6 +100,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int
> port, std::string device , i_sock_fd(-1)
>   , p_creds(NULL)
>   , p_tls(NULL)
> + , requested_stop(false)
>   , conn_status(CHROMECAST_DISCONNECTED)
>   , cmd_status(NO_CMD_PENDING)
>   , i_receiver_requestId(0)
> @@ -882,11 +883,21 @@ bool intf_sys_t::handleMessages()
>      bool b_msgReceived = false;
>      uint32_t i_payloadSize = 0;
> 
> +    int canc = vlc_savecancel();
> +    // Not cancellation-safe part.
> +
> +    if ( requested_stop.exchange(false) && !mediaSessionId.empty() )
> +    {
> +        msgPlayerStop();
> +    }
> +
> +    vlc_restorecancel(canc);

Just remove the vlc_cancel() call. Cancelling a C++ thread is not portably 
defined.

> +
>      int i_ret = recvPacket( p_module, b_msgReceived, i_payloadSize,
> i_sock_fd, p_tls, &i_received, p_packet, &b_pingTimeout, &i_waitdelay,
> &i_retries);
> 
> -    int canc = vlc_savecancel();
> +    canc = vlc_savecancel();
>      // Not cancellation-safe part.
> 
>  #if defined(_WIN32)
> @@ -922,3 +933,9 @@ void intf_sys_t::notifySendRequest()
>  {
>      vlc_interrupt_raise( p_ctl_thread_interrupt );
>  }
> +
> +void intf_sys_t::requestPlayerStop()
> +{
> +    requested_stop = true;
> +    notifySendRequest();
> +}

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list