[vlc-commits] chromecast: retry connection after a Dead state

2018-03-29 Thread Thomas Guillem
vlc/vlc-3.0 | branch: master | Thomas Guillem  | Thu Mar 29 
10:15:24 2018 +0200| [1fca7d2edd7fda7bc61baf3679ae9cd0772ebf32] | committer: 
Thomas Guillem

chromecast: retry connection after a Dead state

Retry only when playing a new input in order to avoid retry busy loops.

(cherry picked from commit 400fa1a9906bb8d53875c6475eed69a60cdb19f2)
Signed-off-by: Thomas Guillem 

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=1fca7d2edd7fda7bc61baf3679ae9cd0772ebf32
---

 modules/stream_out/chromecast/chromecast.h|   4 +-
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 102 --
 2 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h 
b/modules/stream_out/chromecast/chromecast.h
index 50c678f188..19b0c9dea1 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -185,6 +185,7 @@ struct intf_sys_t
 int httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *pi_data 
);
 void interrupt_wake_up();
 private:
+void reinit();
 bool handleMessages();
 
 bool processMessage(const castchannel::CastMessage );
@@ -237,7 +238,9 @@ private:
 private:
 vlc_object_t  * const m_module;
 const int  m_streaming_port;
+const int  m_device_port;
 std::stringm_mime;
+std::stringm_device_addr;
 
 std::string m_appTransportId;
 unsigned m_last_request_id;
@@ -248,7 +251,6 @@ private:
 vlc_cond_t   m_pace_cond;
 vlc_thread_t m_chromecastThread;
 
-
 on_input_event_itfm_on_input_event;
 void *m_on_input_event_data;
 
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp 
b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index c293261594..184e516e39 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -91,6 +91,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, 
std::string device
int device_port, httpd_host_t *httpd_host)
  : m_module(p_this)
  , m_streaming_port(port)
+ , m_device_port(device_port)
+ , m_device_addr(device_addr)
  , m_last_request_id( 0 )
  , m_mediaSessionId( 0 )
  , m_on_input_event( NULL )
@@ -116,7 +118,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int 
port, std::string device
  , m_pause_delay( VLC_TS_INVALID )
  , m_pingRetriesLeft( PING_WAIT_RETRIES )
 {
-m_communication = new ChromecastCommunication( p_this, 
device_addr.c_str(), device_port );
+m_communication = new ChromecastCommunication( p_this, 
m_device_addr.c_str(),
+   m_device_port );
 
 m_ctl_thread_interrupt = vlc_interrupt_create();
 if( unlikely(m_ctl_thread_interrupt == NULL) )
@@ -159,36 +162,40 @@ intf_sys_t::~intf_sys_t()
 var_Destroy( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME );
 
 vlc_mutex_lock(_lock);
-switch ( m_state )
+if( m_communication )
 {
-case Ready:
-case Loading:
-case Buffering:
-case Playing:
-case Paused:
-case Stopping:
-case Stopped:
-// Generate the close messages.
-m_communication->msgReceiverClose( m_appTransportId );
-/* fallthrough */
-case Connecting:
-case Connected:
-case Launching:
-m_communication->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
-/* fallthrough */
-default:
-break;
-}
-vlc_mutex_unlock(_lock);
+switch ( m_state )
+{
+case Ready:
+case Loading:
+case Buffering:
+case Playing:
+case Paused:
+case Stopping:
+case Stopped:
+// Generate the close messages.
+m_communication->msgReceiverClose( m_appTransportId );
+/* fallthrough */
+case Connecting:
+case Connected:
+case Launching:
+m_communication->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
+/* fallthrough */
+default:
+break;
+}
 
-vlc_interrupt_kill( m_ctl_thread_interrupt );
+vlc_mutex_unlock(_lock);
+vlc_interrupt_kill( m_ctl_thread_interrupt );
+vlc_join(m_chromecastThread, NULL);
 
-vlc_join(m_chromecastThread, NULL);
+delete m_communication;
+}
+else
+vlc_mutex_unlock(_lock);
 
 vlc_interrupt_destroy( m_ctl_thread_interrupt );
 
-delete m_communication;
-
 if (m_meta != NULL)
 vlc_meta_Delete(m_meta);
 
@@ -202,6 +209,38 @@ intf_sys_t::~intf_sys_t()
 vlc_mutex_destroy(_lock);
 }
 
+void intf_sys_t::reinit()
+{
+assert( m_state == Dead );
+
+if( m_communication )
+{
+vlc_join( m_chromecastThread, NULL );
+delete m_communication;
+m_communication = NULL;
+}
+
+try
+{
+m_communication = new ChromecastCommunication( m_module,

[vlc-commits] chromecast: retry connection after a Dead state

2018-03-29 Thread Thomas Guillem
vlc | branch: master | Thomas Guillem  | Thu Mar 29 10:15:24 
2018 +0200| [400fa1a9906bb8d53875c6475eed69a60cdb19f2] | committer: Thomas 
Guillem

chromecast: retry connection after a Dead state

Retry only when playing a new input in order to avoid retry busy loops.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=400fa1a9906bb8d53875c6475eed69a60cdb19f2
---

 modules/stream_out/chromecast/chromecast.h|   4 +-
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 102 --
 2 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h 
b/modules/stream_out/chromecast/chromecast.h
index 50c678f188..19b0c9dea1 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -185,6 +185,7 @@ struct intf_sys_t
 int httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *pi_data 
);
 void interrupt_wake_up();
 private:
+void reinit();
 bool handleMessages();
 
 bool processMessage(const castchannel::CastMessage );
@@ -237,7 +238,9 @@ private:
 private:
 vlc_object_t  * const m_module;
 const int  m_streaming_port;
+const int  m_device_port;
 std::stringm_mime;
+std::stringm_device_addr;
 
 std::string m_appTransportId;
 unsigned m_last_request_id;
@@ -248,7 +251,6 @@ private:
 vlc_cond_t   m_pace_cond;
 vlc_thread_t m_chromecastThread;
 
-
 on_input_event_itfm_on_input_event;
 void *m_on_input_event_data;
 
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp 
b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index c293261594..184e516e39 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -91,6 +91,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, 
std::string device
int device_port, httpd_host_t *httpd_host)
  : m_module(p_this)
  , m_streaming_port(port)
+ , m_device_port(device_port)
+ , m_device_addr(device_addr)
  , m_last_request_id( 0 )
  , m_mediaSessionId( 0 )
  , m_on_input_event( NULL )
@@ -116,7 +118,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int 
port, std::string device
  , m_pause_delay( VLC_TS_INVALID )
  , m_pingRetriesLeft( PING_WAIT_RETRIES )
 {
-m_communication = new ChromecastCommunication( p_this, 
device_addr.c_str(), device_port );
+m_communication = new ChromecastCommunication( p_this, 
m_device_addr.c_str(),
+   m_device_port );
 
 m_ctl_thread_interrupt = vlc_interrupt_create();
 if( unlikely(m_ctl_thread_interrupt == NULL) )
@@ -159,36 +162,40 @@ intf_sys_t::~intf_sys_t()
 var_Destroy( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME );
 
 vlc_mutex_lock(_lock);
-switch ( m_state )
+if( m_communication )
 {
-case Ready:
-case Loading:
-case Buffering:
-case Playing:
-case Paused:
-case Stopping:
-case Stopped:
-// Generate the close messages.
-m_communication->msgReceiverClose( m_appTransportId );
-/* fallthrough */
-case Connecting:
-case Connected:
-case Launching:
-m_communication->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
-/* fallthrough */
-default:
-break;
-}
-vlc_mutex_unlock(_lock);
+switch ( m_state )
+{
+case Ready:
+case Loading:
+case Buffering:
+case Playing:
+case Paused:
+case Stopping:
+case Stopped:
+// Generate the close messages.
+m_communication->msgReceiverClose( m_appTransportId );
+/* fallthrough */
+case Connecting:
+case Connected:
+case Launching:
+m_communication->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
+/* fallthrough */
+default:
+break;
+}
 
-vlc_interrupt_kill( m_ctl_thread_interrupt );
+vlc_mutex_unlock(_lock);
+vlc_interrupt_kill( m_ctl_thread_interrupt );
+vlc_join(m_chromecastThread, NULL);
 
-vlc_join(m_chromecastThread, NULL);
+delete m_communication;
+}
+else
+vlc_mutex_unlock(_lock);
 
 vlc_interrupt_destroy( m_ctl_thread_interrupt );
 
-delete m_communication;
-
 if (m_meta != NULL)
 vlc_meta_Delete(m_meta);
 
@@ -202,6 +209,38 @@ intf_sys_t::~intf_sys_t()
 vlc_mutex_destroy(_lock);
 }
 
+void intf_sys_t::reinit()
+{
+assert( m_state == Dead );
+
+if( m_communication )
+{
+vlc_join( m_chromecastThread, NULL );
+delete m_communication;
+m_communication = NULL;
+}
+
+try
+{
+m_communication = new ChromecastCommunication( m_module,
+   m_device_addr.c_str(),
+