+/*****************************************************************************
+ * RollOverTcp: reopen the rtsp into TCP mode
+ * XXX: ugly, a lot of code are duplicated from Open()
+ *****************************************************************************/
+static int RollOverTcp( demux_t *p_demux )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ MediaSubsessionIterator *iter;
+ MediaSubsession *sub;
+ char *psz_url;
+ char *psz_options;
+ uint8_t *p_sdp;
+ int i_tk;
+
+ /* We close the old RTSP session */
+ p_sys->rtsp->teardownMediaSession( *p_sys->ms );
+
+ Medium::close( p_sys->ms );
+ Medium::close( p_sys->rtsp );
+
+ p_sys->ms = NULL;
+ p_sys->rtsp = NULL;
+
+ /* Reopen rtsp client */
+ if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/,
+ "VLC Media Player" ) ) == NULL )
+ {
+ msg_Err( p_demux, "RTSPClient::createNew failed (%s)",
+ p_sys->env->getResultMsg() );
+ return VLC_EGENERIC;
+ }
+
+ asprintf( &psz_url, "rtsp://%s", p_sys->psz_path );
+
+ if( ( psz_options = p_sys->rtsp->sendOptionsCmd( psz_url ) ) )
+ delete [] psz_options;
+
+ p_sdp = (uint8_t*)p_sys->rtsp->describeURL( psz_url,
+ NULL, var_CreateGetBool( p_demux, "rtsp-kasenna" ) );
+ free( psz_url );
+ if( p_sdp == NULL )
+ {
+ msg_Err( p_demux, "describeURL failed (%s)",
+ p_sys->env->getResultMsg() );
+ return VLC_EGENERIC;
+ }
+
+ /* malloc-ated copy */
+ p_sys->p_sdp = strdup( (char*)p_sdp );
+ delete[] p_sdp;
+
+ if( !( p_sys->ms = MediaSession::createNew( *p_sys->env, p_sys->p_sdp ) ) )
+ {
+ msg_Err( p_demux, "MediaSession::createNew failed" );
+ return VLC_EGENERIC;
+ }
+
+ /* Initialise each media subsession */
+ iter = new MediaSubsessionIterator( *p_sys->ms );
+ while( ( sub = iter->next() ) != NULL )
+ {
+ Boolean bInit;
+
+ if( !strcmp( sub->codecName(), "X-ASF-PF" ) )
+ bInit = sub->initiate( 4 ); /* Constant ? */
+ else
+ bInit = sub->initiate();
+
+ if( !bInit )
+ {
+ msg_Warn( p_demux, "RTP subsession '%s/%s' failed (%s)",
+ sub->mediumName(), sub->codecName(),
+ p_sys->env->getResultMsg() );
+ continue;
+ }
+ msg_Dbg( p_demux, "RTP subsession '%s/%s'", sub->mediumName(),
+ sub->codecName() );
+
+ /* Issue the SETUP */
+ p_sys->rtsp->setupMediaSubsession( *sub, False, True /* tcp */ );
+ }
+
+ /* The PLAY */
+ if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
+ {
+ msg_Err( p_demux, "PLAY failed %s", p_sys->env->getResultMsg() );
+ return VLC_EGENERIC;
+ }
+
+ /* Update all tracks */
+ iter->reset();
+ i_tk = 0;
+ while( ( sub = iter->next() ) != NULL )
+ {
+ live_track_t *tk;
+
+ if( sub->readSource() == NULL )
+ continue;
+ if( i_tk >= p_sys->i_track )
+ {
+ msg_Err( p_demux, "WTF !" );
+ break;
+ }
+
+ tk = p_sys->track[i_tk];
+
+ /* Reset state */
+ tk->waiting = 0;
+ tk->i_pts = 0;
+ tk->b_rtcp_sync = VLC_FALSE;
+
+ if( sub->rtcpInstance() != NULL )
+ sub->rtcpInstance()->setByeHandler( StreamClose, tk );
+
+ tk->readSource = sub->readSource();
+ tk->rtpSource = sub->rtpSource();
+
+ i_tk++;
+ }
+
+ delete iter;
+
+ return VLC_SUCCESS;
+}
+
+