[rtmpdump] r144 - in trunk: hashswf.c rtmp.c rtmp.h rtmpdump.c rtmpsuck.c streams.c

hyc subversion at mplayerhq.hu
Wed Dec 30 09:17:28 CET 2009


Author: hyc
Date: Wed Dec 30 09:17:27 2009
New Revision: 144

Log:
Add 'ask' param back to HashSWF, expose HandlePacket as RTMP_ClientPacket

Modified:
   trunk/hashswf.c
   trunk/rtmp.c
   trunk/rtmp.h
   trunk/rtmpdump.c
   trunk/rtmpsuck.c
   trunk/streams.c

Modified: trunk/hashswf.c
==============================================================================
--- trunk/hashswf.c	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/hashswf.c	Wed Dec 30 09:17:27 2009	(r144)
@@ -222,7 +222,7 @@ leave:
 #define HEX2BIN(a)      (((a)&0x40)?((a)&0xf)+9:((a)&0xf))
 
 int
-RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash)
+RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, int ask)
 {
   FILE *f = NULL;
   char *path, *home, date[64];
@@ -291,6 +291,9 @@ RTMP_HashSWF(const char *url, unsigned i
         }
     }
 
+  if (got && !ask)
+    return 0;
+
   in.first = 1;
   in.date = date;
   HMAC_CTX_init(&ctx);

Modified: trunk/rtmp.c
==============================================================================
--- trunk/rtmp.c	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/rtmp.c	Wed Dec 30 09:17:27 2009	(r144)
@@ -93,7 +93,6 @@ static bool SendPlay(RTMP * r);
 static bool SendSeek(RTMP * r, double dTime);
 static bool SendBytesReceived(RTMP * r);
 
-static int HandlePacket(RTMP * r, RTMPPacket * packet);
 static int HandleInvoke(RTMP * r, const char *body, unsigned int nBodySize);
 static bool HandleMetadata(RTMP * r, char *body, unsigned int len);
 static void HandleChangeChunkSize(RTMP * r, const RTMPPacket * packet);
@@ -495,7 +494,7 @@ RTMP_ConnectStream(RTMP * r, double seek
 	      break;
 	    }
 
-	  HandlePacket(r, &packet);
+	  RTMP_ClientPacket(r, &packet);
 	  RTMPPacket_Free(&packet);
 	}
     }
@@ -555,7 +554,7 @@ RTMP_GetNextMediaPacket(RTMP * r, RTMPPa
 	  continue;
 	}
 
-      bHasMediaPacket = HandlePacket(r, packet);
+      bHasMediaPacket = RTMP_ClientPacket(r, packet);
 
       if (!bHasMediaPacket)
 	{
@@ -587,8 +586,8 @@ RTMP_GetNextMediaPacket(RTMP * r, RTMPPa
   return bHasMediaPacket;
 }
 
-static int
-HandlePacket(RTMP * r, RTMPPacket * packet)
+int
+RTMP_ClientPacket(RTMP * r, RTMPPacket * packet)
 {
   int bHasMediaPacket = 0;
   switch (packet->m_packetType)

Modified: trunk/rtmp.h
==============================================================================
--- trunk/rtmp.h	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/rtmp.h	Wed Dec 30 09:17:27 2009	(r144)
@@ -198,6 +198,7 @@ bool RTMP_ConnectStream(RTMP *r, double 
 bool RTMP_ReconnectStream(RTMP *r, int bufferTime, double seekTime, uint32_t dLength);
 void RTMP_DeleteStream(RTMP *r);
 int RTMP_GetNextMediaPacket(RTMP *r, RTMPPacket *packet);
+int RTMP_ClientPacket(RTMP *r, RTMPPacket *packet);
 
 void RTMP_Init(RTMP *r);
 void RTMP_Close(RTMP *r);
@@ -211,7 +212,7 @@ bool RTMP_FindFirstMatchingProperty(AMFO
 /* hashswf.c */
 #define HASHLEN	32
 
-int RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash);
+int RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, int ask);
 #endif
 
 #endif

Modified: trunk/rtmpdump.c
==============================================================================
--- trunk/rtmpdump.c	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/rtmpdump.c	Wed Dec 30 09:17:27 2009	(r144)
@@ -1284,7 +1284,7 @@ main(int argc, char **argv)
 	  }
         case 'W':
 	  STR2AVAL(swfUrl, optarg);
-          if (RTMP_HashSWF(optarg, &swfSize, hash) == 0)
+          if (RTMP_HashSWF(optarg, &swfSize, hash, 1) == 0)
             {
               swfHash.av_val = (char *)hash;
               swfHash.av_len = HASHLEN;

Modified: trunk/rtmpsuck.c
==============================================================================
--- trunk/rtmpsuck.c	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/rtmpsuck.c	Wed Dec 30 09:17:27 2009	(r144)
@@ -110,6 +110,8 @@ FILE *netstackdump = NULL;
 FILE *netstackdump_read = NULL;
 #endif
 
+#define BUFFERTIME	(4*60*60*1000)	/* 4 hours */
+
 #define SAVC(x) static const AVal av_##x = AVC(#x)
 
 SAVC(app);
@@ -299,6 +301,11 @@ ServeInvoke(STREAMING_SERVER *server, RT
       for (p=file; *p; p++)
         if (*p == '/')
           *p = '_';
+        else if (*p == '?')
+          {
+            *p = '\0';
+            break;
+          }
       LogPrintf("Playpath: %.*s, writing to %s\n", server->rc.Link.playpath.av_len,
         server->rc.Link.playpath.av_val, file);
       server->out = fopen(file, "wb");
@@ -664,6 +671,7 @@ void doServe(STREAMING_SERVER * server,	
   RTMPPacket pc = { 0 }, ps = { 0 };
   char *buf;
   unsigned int buflen = 131072;
+  bool paused = false;
 
   // timeout for http requests
   fd_set rfds;
@@ -708,8 +716,8 @@ void doServe(STREAMING_SERVER * server,	
     }
 
   /* We have our own timeout in select() */
-  server->rc.Link.timeout = 1;
-  server->rs.Link.timeout = 1;
+  server->rc.Link.timeout = 10;
+  server->rs.Link.timeout = 10;
   while (RTMP_IsConnected(&server->rs) || RTMP_IsConnected(&server->rc))
     {
       int n;
@@ -738,12 +746,17 @@ void doServe(STREAMING_SERVER * server,	
 
 	  if (select(n + 1, &rfds, NULL, NULL, &tv) <= 0)
 	    {
-              /* FIXME: Need to get the ToggleStream support in place */
-              /* if (!server->out || !RTMP_ToggleStream(&server->rc)) */
+              if (server->out && server->rc.m_mediaChannel && !paused)
                 {
-	          Log(LOGERROR, "Request timeout/select failed, ignoring request");
-	          goto cleanup;
+                  server->rc.m_pauseStamp = server->rc.m_channelTimestamp[server->rc.m_mediaChannel];
+                  if (RTMP_ToggleStream(&server->rc))
+                    {
+                      paused = true;
+                      continue;
+                    }
                 }
+	      Log(LOGERROR, "Request timeout/select failed, ignoring request");
+	      goto cleanup;
 	    }
           if (FD_ISSET(server->rs.m_socket, &rfds))
             sr = 1;
@@ -766,6 +779,31 @@ void doServe(STREAMING_SERVER * server,	
                         server->rc.m_outChunkSize = server->rs.m_inChunkSize;
                       }
                   }
+                /* ctrl */
+                else if (ps.m_packetType == 0x04)
+                  {
+                    short nType = AMF_DecodeInt16(ps.m_body);
+                    /* UpdateBufferMS */
+                    if (nType == 0x03)
+                      {
+                        char *ptr = ps.m_body+2;
+                        int id;
+                        int len;
+                        id = AMF_DecodeInt32(ptr);
+                        /* Assume the interesting media is on a non-zero stream */
+                        if (id)
+                          {
+                            len = AMF_DecodeInt32(ptr+4);
+                            /* request a big buffer */
+                            if (len < BUFFERTIME)
+                              {
+                                AMF_EncodeInt32(ptr+4, ptr+8, BUFFERTIME);
+                              }
+                            Log(LOGDEBUG, "%s, client: BufferTime change in stream %d to %d", __FUNCTION__,
+                                id, len);
+                          }
+                      }
+                  }
                 else if (!server->out && (ps.m_packetType == 0x11 || ps.m_packetType == 0x14))
                   ServePacket(server, &ps);
                 RTMP_SendPacket(&server->rc, &ps, false);
@@ -779,6 +817,13 @@ void doServe(STREAMING_SERVER * server,	
             if (RTMPPacket_IsReady(&pc))
               {
                 int sendit = 1;
+                if (paused)
+                  {
+                    if (pc.m_nTimeStamp <= server->rc.m_mediaStamp)
+                      continue;
+                    paused = 0;
+                    server->rc.m_pausing = 0;
+                  }
                 /* change chunk size */
                 if (pc.m_packetType == 0x01)
                   {
@@ -804,7 +849,8 @@ void doServe(STREAMING_SERVER * server,	
                      pc.m_packetType == 0x08 ||
                      pc.m_packetType == 0x09 ||
                      pc.m_packetType == 0x12 ||
-                     pc.m_packetType == 0x16))
+                     pc.m_packetType == 0x16) &&
+                     RTMP_ClientPacket(&server->rc, &pc))
                   {
                     int len = WriteStream(&buf, &buflen, &server->stamp, &pc);
                     if (len > 0 && fwrite(buf, 1, len, server->out) != len)
@@ -814,11 +860,11 @@ void doServe(STREAMING_SERVER * server,	
                      pc.m_packetType == 0x11 ||
                      pc.m_packetType == 0x14))
                   {
-                     if (ServePacket(server, &pc))
-                       {
-                         fclose(server->out);
-                         server->out = NULL;
-                       }
+                    if (ServePacket(server, &pc))
+                      {
+                        fclose(server->out);
+                        server->out = NULL;
+                      }
                   }
 
                 if (sendit && RTMP_IsConnected(&server->rs))
@@ -994,6 +1040,8 @@ main(int argc, char **argv)
   LogPrintf("RTMP Proxy Server %s\n", RTMPDUMP_PROXY_VERSION);
   LogPrintf("(c) 2009 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
 
+  debuglevel = LOGDEBUG;
+
   if (argc > 1 && !strcmp(argv[1], "-z"))
     debuglevel = LOGALL;
 

Modified: trunk/streams.c
==============================================================================
--- trunk/streams.c	Wed Dec 30 07:23:42 2009	(r143)
+++ trunk/streams.c	Wed Dec 30 09:17:27 2009	(r144)
@@ -942,7 +942,7 @@ ParseOption(char opt, char *arg, RTMP_RE
         unsigned char hash[HASHLEN];
 
         STR2AVAL(req->swfUrl, arg);
-        if (RTMP_HashSWF(arg, &req->swfSize, hash) == 0)
+        if (RTMP_HashSWF(arg, &req->swfSize, hash, 1) == 0)
           {
             req->swfHash.av_val = malloc(HASHLEN);
             req->swfHash.av_len = HASHLEN;


More information about the rtmpdump mailing list