[rtmpdump] r236 - in trunk: rtmp.c rtmp.h

hyc subversion at mplayerhq.hu
Fri Jan 15 09:25:44 CET 2010


Author: hyc
Date: Fri Jan 15 09:25:43 2010
New Revision: 236

Log:
Split RTMP_Connect up, add m_bSendCounter flag; proxy doesn't need to
send byte counts since the real client/server will.

Modified:
   trunk/rtmp.c
   trunk/rtmp.h

Modified: trunk/rtmp.c
==============================================================================
--- trunk/rtmp.c	Thu Jan 14 08:11:47 2010	(r235)
+++ trunk/rtmp.c	Fri Jan 15 09:25:43 2010	(r236)
@@ -330,12 +330,8 @@ add_addr_info(struct sockaddr_in *servic
 }
 
 bool
-RTMP_Connect(RTMP *r, RTMPPacket *cp)
+RTMP_Connect0(RTMP *r, struct sockaddr *service)
 {
-  struct sockaddr_in service;
-  if (!r->Link.hostname)
-    return false;
-
   // close any previous connection
   RTMP_Close(r);
 
@@ -343,28 +339,11 @@ RTMP_Connect(RTMP *r, RTMPPacket *cp)
   r->m_pausing = 0;
   r->m_fDuration = 0.0;
 
-  memset(&service, 0, sizeof(struct sockaddr_in));
-  service.sin_family = AF_INET;
-
-  if (r->Link.socksport)
-    {
-      // Connect via SOCKS
-      if (!add_addr_info(&service, r->Link.sockshost, r->Link.socksport))
-	return false;
-    }
-  else
-    {
-      // Connect directly
-      if (!add_addr_info(&service, r->Link.hostname, r->Link.port))
-	return false;
-    }
-
   r->m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   if (r->m_socket != -1)
     {
       if (connect
-	  (r->m_socket, (struct sockaddr *) &service,
-	   sizeof(struct sockaddr)) < 0)
+	  (r->m_socket, service, sizeof(struct sockaddr)) < 0)
 	{
 	  int err = GetSockError();
 	  Log(LOGERROR, "%s, failed to connect socket. %d (%s)", __FUNCTION__,
@@ -383,30 +362,6 @@ RTMP_Connect(RTMP *r, RTMPPacket *cp)
 	      return false;
 	    }
 	}
-
-      Log(LOGDEBUG, "%s, ... connected, handshaking", __FUNCTION__);
-      if (!HandShake(r, true))
-	{
-	  Log(LOGERROR, "%s, handshake failed.", __FUNCTION__);
-	  RTMP_Close(r);
-	  return false;
-	}
-
-      Log(LOGDEBUG, "%s, handshaked", __FUNCTION__);
-      if (!SendConnectPacket(r, cp))
-	{
-	  Log(LOGERROR, "%s, RTMP connect failed.", __FUNCTION__);
-	  RTMP_Close(r);
-	  return false;
-	}
-      // set timeout
-      SET_RCVTIMEO(tv, r->Link.timeout);
-      if (setsockopt
-	  (r->m_socket, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv)))
-	{
-	  Log(LOGERROR, "%s, Setting socket timeout to %ds failed!",
-	      __FUNCTION__, r->Link.timeout);
-	}
     }
   else
     {
@@ -415,11 +370,73 @@ RTMP_Connect(RTMP *r, RTMPPacket *cp)
       return false;
     }
 
+  // set timeout
+  SET_RCVTIMEO(tv, r->Link.timeout);
+  if (setsockopt
+      (r->m_socket, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv)))
+    {
+      Log(LOGERROR, "%s, Setting socket timeout to %ds failed!",
+          __FUNCTION__, r->Link.timeout);
+    }
+
   int on = 1;
   setsockopt(r->m_socket, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+
+  return true;
+}
+
+bool
+RTMP_Connect1(RTMP *r, RTMPPacket *cp)
+{
+  Log(LOGDEBUG, "%s, ... connected, handshaking", __FUNCTION__);
+  if (!HandShake(r, true))
+    {
+      Log(LOGERROR, "%s, handshake failed.", __FUNCTION__);
+      RTMP_Close(r);
+      return false;
+    }
+  Log(LOGDEBUG, "%s, handshaked", __FUNCTION__);
+
+  if (!SendConnectPacket(r, cp))
+    {
+      Log(LOGERROR, "%s, RTMP connect failed.", __FUNCTION__);
+      RTMP_Close(r);
+      return false;
+    }
   return true;
 }
 
+bool
+RTMP_Connect(RTMP *r, RTMPPacket *cp)
+{
+  struct sockaddr_in service;
+  if (!r->Link.hostname)
+    return false;
+
+  memset(&service, 0, sizeof(struct sockaddr_in));
+  service.sin_family = AF_INET;
+
+  if (r->Link.socksport)
+    {
+      // Connect via SOCKS
+      if (!add_addr_info(&service, r->Link.sockshost, r->Link.socksport))
+	return false;
+    }
+  else
+    {
+      // Connect directly
+      if (!add_addr_info(&service, r->Link.hostname, r->Link.port))
+	return false;
+    }
+
+  if (!RTMP_Connect0(r, (struct sockaddr *)&service))
+    return false;
+
+  r->m_bSendCounter = true;
+
+  return RTMP_Connect1(r, cp);
+}
+
 static bool
 SocksNegotiate(RTMP * r)
 {
@@ -762,7 +779,7 @@ ReadN(RTMP * r, char *buffer, int n)
 	  r->m_nBufferSize -= nRead;
 	  nBytes = nRead;
 	  r->m_nBytesIn += nRead;
-	  if (r->m_nBytesIn > r->m_nBytesInSent + r->m_nClientBW / 2)
+	  if (r->m_bSendCounter && r->m_nBytesIn > r->m_nBytesInSent + r->m_nClientBW / 2)
 	    SendBytesReceived(r);
 	}
 

Modified: trunk/rtmp.h
==============================================================================
--- trunk/rtmp.h	Thu Jan 14 08:11:47 2010	(r235)
+++ trunk/rtmp.h	Fri Jan 15 09:25:43 2010	(r236)
@@ -175,6 +175,7 @@ typedef struct RTMP
   uint8_t m_nClientBW2;
   bool m_bPlaying;
   bool m_bSendEncoding;
+  bool m_bSendCounter;
 
   AVal *m_methodCalls;		/* remote method calls queue */
   int m_numCalls;
@@ -219,6 +220,8 @@ void RTMP_SetupStream(RTMP *r, int proto
 		      uint32_t dLength, bool bLiveStream, long int timeout);
 
 bool RTMP_Connect(RTMP *r, RTMPPacket *cp);
+bool RTMP_Connect0(RTMP *r, struct sockaddr *svc);
+bool RTMP_Connect1(RTMP *r, RTMPPacket *cp);
 bool RTMP_Serve(RTMP *r);
 
 bool RTMP_ReadPacket(RTMP * r, RTMPPacket * packet);


More information about the rtmpdump mailing list