From 407f0fedd7df7ea31b9f7de34b149e730d3ece3a Mon Sep 17 00:00:00 2001 From: hyc Date: Fri, 8 Jan 2010 04:53:39 +0000 Subject: [PATCH] Fallback to Reconnect if ToggleStream didn't work, then give up if both fail git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@209 400ebc74-4327-4243-bc38-086b20814532 --- rtmpdump.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/rtmpdump.c b/rtmpdump.c index be524c9..3f6f7b0 100644 --- a/rtmpdump.c +++ b/rtmpdump.c @@ -1082,6 +1082,7 @@ main(int argc, char **argv) AVal subscribepath = { 0, 0 }; int port = -1; int protocol = RTMP_PROTOCOL_UNDEFINED; + int retries = 0; bool bLiveStream = false; // is it a live stream? then we can't seek/resume bool bHashes = false; // display byte counters not hashes by default @@ -1663,8 +1664,43 @@ main(int argc, char **argv) { nInitialFrameSize = 0; + if (retries) + { + Log(LOGERROR, "Failed to resume the stream\n\n"); + if (!RTMP_IsTimedout(&rtmp)) + nStatus = RD_FAILED; + else + nStatus = RD_INCOMPLETE; + break; + } Log(LOGINFO, "Connection timed out, trying to resume.\n\n"); - if (!RTMP_ToggleStream(&rtmp)) + /* Did we already try pausing, and it still didn't work? */ + if (rtmp.m_pausing == 3) + { + /* Only one try at reconnecting... */ + retries = 1; + dSeek = rtmp.m_pauseStamp; + if (dStopOffset > 0) + { + dLength = dStopOffset - dSeek; + if (dLength <= 0) + { + LogPrintf("Already Completed\n"); + nStatus = RD_SUCCESS; + break; + } + } + if (!RTMP_ReconnectStream(&rtmp, bufferTime, dSeek, dLength)) + { + Log(LOGERROR, "Failed to resume the stream\n\n"); + if (!RTMP_IsTimedout(&rtmp)) + nStatus = RD_FAILED; + else + nStatus = RD_INCOMPLETE; + break; + } + } + else if (!RTMP_ToggleStream(&rtmp)) { Log(LOGERROR, "Failed to resume the stream\n\n"); if (!RTMP_IsTimedout(&rtmp)) -- 2.50.1