From 91b3041e298fa532e77c240c482a9a3d843f7269 Mon Sep 17 00:00:00 2001 From: hyc Date: Mon, 9 Nov 2009 01:48:30 +0000 Subject: [PATCH] More fixes for auto-retry git-svn-id: svn://svn.mplayerhq.hu/rtmpdump@33 400ebc74-4327-4243-bc38-086b20814532 --- rtmp.cpp | 7 ++++- rtmpdump.cpp | 74 +++++++++++++++++++++++++--------------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/rtmp.cpp b/rtmp.cpp index 1d6a00e..a075647 100644 --- a/rtmp.cpp +++ b/rtmp.cpp @@ -884,6 +884,8 @@ bool CRTMP::SendBytesReceived() bool CRTMP::SendCheckBW() { RTMPPacket packet; + bool res; + packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_LARGE; packet.m_packetType = 0x14; // INVOKE @@ -898,7 +900,10 @@ bool CRTMP::SendCheckBW() packet.m_nBodySize = enc - packet.m_body; - return SendRTMP(packet); + res = SendRTMP(packet); + /* The result of this message is _onbwcheck, not _result */ + m_methodCalls.erase(m_methodCalls.end()); + return res; } bool CRTMP::SendCheckBWResult() diff --git a/rtmpdump.cpp b/rtmpdump.cpp index c16da6d..5cbba33 100644 --- a/rtmpdump.cpp +++ b/rtmpdump.cpp @@ -1259,7 +1259,6 @@ int main(int argc, char **argv) off_t size = 0; uint32_t timestamp = 0; - int tries = 2; /* 1 retry */ // ok, we have to get the timestamp of the last keyframe (only keyframes are seekable) / last audio frame (audio only streams) if(bResume) { @@ -1306,9 +1305,7 @@ int main(int argc, char **argv) netstackdump_read = fopen("netstackdump_read", "wb"); #endif - while (tries > 0 && !bCtrlC) { - tries--; - + while (!bCtrlC) { Log(LOGDEBUG, "Setting buffer time to: %dms", bufferTime); rtmp->SetBufferMS(bufferTime); @@ -1356,6 +1353,41 @@ int main(int argc, char **argv) nStatus = RD_FAILED; break; } + } else { + nInitialFrameSize = 0; + + Log(LOGINFO, "Connection timed out, trying to reconnect.\n\n"); + + nStatus = GetLastKeyframe(file, nSkipKeyFrames, + &dSeek, &initialFrame, + &initialFrameType, + &nInitialFrameSize); + if (nStatus != RD_SUCCESS) { + Log(LOGDEBUG, "Failed to get last keyframe."); + break; + } + + // Calculate the length of the stream to still play + if (dStopOffset > 0) { + dLength = dStopOffset - dSeek; + + // Quit if start seek is past required stop offset + if(dLength <= 0) { + LogPrintf("Already Completed\n"); + nStatus = RD_SUCCESS; + break; + } + } + + if (!rtmp->ReconnectStream(bufferTime, dSeek, dLength)) { + Log(LOGERROR, "Failed to resume the stream\n\n"); + if (!rtmp->IsTimedout()) + nStatus = RD_FAILED; + else + nStatus = RD_INCOMPLETE; + break; + } + bResume = true; } nStatus = Download(rtmp, file, dSeek, dLength, duration, bResume, @@ -1371,40 +1403,6 @@ int main(int argc, char **argv) */ if (nStatus != RD_INCOMPLETE || bStdoutMode || !rtmp->IsTimedout()) break; - - nInitialFrameSize = 0; - - Log(LOGINFO, "Connection timed out, trying to reconnect.\n\n"); - - nStatus = GetLastKeyframe(file, nSkipKeyFrames, - &dSeek, &initialFrame, - &initialFrameType, - &nInitialFrameSize); - if (nStatus != RD_SUCCESS) { - Log(LOGDEBUG, "Failed to get last keyframe."); - break; - } - - // Calculate the length of the stream to still play - if (dStopOffset > 0) { - dLength = dStopOffset - dSeek; - - // Quit if start seek is past required stop offset - if(dLength <= 0) { - LogPrintf("Already Completed\n"); - nStatus = RD_SUCCESS; - break; - } - } - - if (!rtmp->ReconnectStream(bufferTime, dSeek, dLength)) { - Log(LOGERROR, "Failed to resume the stream\n\n"); - if (!rtmp->IsTimedout()) { - nStatus = RD_FAILED; - break; - } - } - bResume = true; } if (nStatus == RD_SUCCESS) { -- 2.40.0