Fixed pause/resume synch
authorhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Thu, 12 Nov 2009 11:45:40 +0000 (11:45 +0000)
committerhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Thu, 12 Nov 2009 11:45:40 +0000 (11:45 +0000)
git-svn-id: svn://svn.mplayerhq.hu/rtmpdump@47 400ebc74-4327-4243-bc38-086b20814532

rtmp.cpp
rtmp.h

index 1d2b272..903ff72 100644 (file)
--- a/rtmp.cpp
+++ b/rtmp.cpp
@@ -426,10 +426,12 @@ int CRTMP::GetNextMediaPacket(RTMPPacket &packet)
 
     if (!bHasMediaPacket) { 
       packet.FreePacket();
-    }
-    if (m_bPausing == 3) {
-      if (packet.m_nTimeStamp <= m_pauseStamp) {
-       bHasMediaPacket = false;
+    } else if (m_bPausing == 3) {
+      if (packet.m_nTimeStamp <= m_mediaStamp) {
+       bHasMediaPacket = 0;
+#ifdef _DEBUG
+       Log(LOGDEBUG, "Skipped type: %02X, size: %d, TS: %d ms, abs TS: %d, pause: %d ms", packet.m_packetType, packet.m_nBodySize, packet.m_nTimeStamp, packet.m_hasAbsTimestamp, m_mediaStamp);
+#endif
        continue;
       }
       m_bPausing = 0;
@@ -438,11 +440,6 @@ int CRTMP::GetNextMediaPacket(RTMPPacket &packet)
         
   if (bHasMediaPacket)
     m_bPlaying = true;
-/*
-  else if (m_bTimedout) {
-    m_pauseStamp = m_channelTimestamp[m_mediaChannel];
-    m_bPausing = 3;
-  } */
 
   return bHasMediaPacket;
 }
@@ -483,6 +480,8 @@ int CRTMP::HandlePacket(RTMPPacket &packet) {
         bHasMediaPacket = 1;
        if (!m_mediaChannel)
          m_mediaChannel = packet.m_nChannel;
+       if (!m_bPausing)
+         m_mediaStamp = packet.m_nTimeStamp;
         break;
 
       case 0x09:
@@ -492,6 +491,8 @@ int CRTMP::HandlePacket(RTMPPacket &packet) {
         bHasMediaPacket = 1;
        if (!m_mediaChannel)
          m_mediaChannel = packet.m_nChannel;
+       if (!m_bPausing)
+         m_mediaStamp = packet.m_nTimeStamp;
         break;
 
       case 0x0F: // flex stream send
@@ -545,6 +546,7 @@ int CRTMP::HandlePacket(RTMPPacket &packet) {
       {
        // go through FLV packets and handle metadata packets
         unsigned int pos=0;
+       uint32_t nTimeStamp = packet.m_nTimeStamp;
 
         while(pos+11 < packet.m_nBodySize) {
                uint32_t dataSize = CRTMP::ReadInt24(packet.m_body+pos+1); // size without header (11) and prevTagSize (4)
@@ -555,10 +557,15 @@ int CRTMP::HandlePacket(RTMPPacket &packet) {
                 }
                if(packet.m_body[pos] == 0x12) {
                        HandleMetadata(packet.m_body+pos+11, dataSize);
+               } else if (packet.m_body[pos] == 8 || packet.m_body[pos] == 9) {
+                       nTimeStamp = CRTMP::ReadInt24(packet.m_body+pos+4);
+                       nTimeStamp |= (packet.m_body[pos+7]<<24);
                }
                 pos += (11+dataSize+4);
        }
-       
+       if (!m_bPausing)
+         m_mediaStamp = nTimeStamp;
+
         // FLV tag(s)
         //Log(LOGDEBUG, "%s, received: FLV tag(s) %lu bytes", __FUNCTION__, packet.m_nBodySize);
         bHasMediaPacket = 1;
diff --git a/rtmp.h b/rtmp.h
index 3b2abce..65558fe 100644 (file)
--- a/rtmp.h
+++ b/rtmp.h
@@ -213,16 +213,17 @@ class CRTMP
       int  m_nBWCheckCounter;
       int  m_nBytesIn;
       int  m_nBytesInSent;
-      bool m_bPlaying;
       int  m_nBufferMS;
       int  m_stream_id; // returned in _result from invoking createStream
       int  m_mediaChannel;
+      uint32_t  m_mediaStamp;
       uint32_t  m_pauseStamp;
-      bool m_bTimedout;
       int m_bPausing;
+      int m_nServerBW;
       int m_nClientBW;
       uint8_t m_nClientBW2;
-      int m_nServerBW;
+      bool m_bPlaying;
+      bool m_bTimedout;
 
       //std::string m_strPlayer;
       //std::string m_strPageUrl;