]> granicus.if.org Git - rtmpdump/commitdiff
Add optional packet param to RTMP_Connect(); rtmpsuck will just send
authorhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Tue, 5 Jan 2010 03:46:39 +0000 (03:46 +0000)
committerhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Tue, 5 Jan 2010 03:46:39 +0000 (03:46 +0000)
the original connect packet instead of generating its own.

git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@189 400ebc74-4327-4243-bc38-086b20814532

rtmp.c
rtmp.h
rtmpdump.c
rtmpsuck.c
streams.c

diff --git a/rtmp.c b/rtmp.c
index 3390fb1400dd9acb8fd4813e8b33a6d601a82eb9..cf25973faa1606b417304560c15dc9f853ac6623 100644 (file)
--- a/rtmp.c
+++ b/rtmp.c
@@ -67,7 +67,7 @@ static bool DumpMetaData(AMFObject * obj);
 static bool HandShake(RTMP * r, bool FP9HandShake);
 static bool SocksNegotiate(RTMP * r);
 
-static bool SendConnectPacket(RTMP * r);
+static bool SendConnectPacket(RTMP * r, RTMPPacket *cp);
 static bool SendServerBW(RTMP * r);
 static bool SendCheckBW(RTMP * r);
 static bool SendCheckBWResult(RTMP * r, double txn);
@@ -330,7 +330,7 @@ add_addr_info(struct sockaddr_in *service, const char *hostname, int port)
 }
 
 bool
-RTMP_Connect(RTMP * r)
+RTMP_Connect(RTMP *r, RTMPPacket *cp)
 {
   struct sockaddr_in service;
   if (!r->Link.hostname)
@@ -393,7 +393,7 @@ RTMP_Connect(RTMP * r)
        }
 
       Log(LOGDEBUG, "%s, handshaked", __FUNCTION__);
-      if (!SendConnectPacket(r))
+      if (!SendConnectPacket(r, cp))
        {
          Log(LOGERROR, "%s, RTMP connect failed.", __FUNCTION__);
          RTMP_Close(r);
@@ -868,11 +868,14 @@ SAVC(secureToken);
 SAVC(secureTokenResponse);
 
 static bool
-SendConnectPacket(RTMP * r)
+SendConnectPacket(RTMP *r, RTMPPacket *cp)
 {
   RTMPPacket packet;
   char pbuf[4096], *pend = pbuf+sizeof(pbuf);
 
+  if (cp)
+    return RTMP_SendPacket(r, cp, true);
+
   packet.m_nChannel = 0x03;    // control channel (invoke)
   packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
   packet.m_packetType = 0x14;  // INVOKE
diff --git a/rtmp.h b/rtmp.h
index d3b9acacbd56f3c700b50ef382500be0f92e38cb..0830d75617c584da94b71463a07e70a0dd60a46e 100644 (file)
--- a/rtmp.h
+++ b/rtmp.h
@@ -209,7 +209,7 @@ void RTMP_SetupStream(RTMP *r, int protocol,
                      double dTime,
                      uint32_t dLength, bool bLiveStream, long int timeout);
 
-bool RTMP_Connect(RTMP *r);
+bool RTMP_Connect(RTMP *r, RTMPPacket *cp);
 bool RTMP_Serve(RTMP *r);
 
 bool RTMP_ReadPacket(RTMP * r, RTMPPacket * packet);
index cdc69ed7c2f5babcb70045a8b748101d98ee16cc..ea1d84687fc4ccf0d128c6cdea45a91f7afff662 100644 (file)
@@ -1615,7 +1615,7 @@ main(int argc, char **argv)
          first = 0;
          LogPrintf("Connecting ...\n");
 
-         if (!RTMP_Connect(&rtmp))
+         if (!RTMP_Connect(&rtmp, NULL))
            {
              nStatus = RD_FAILED;
              break;
index d0299a98edc7352d9141b0bd531af0f3fa8622f1..624802455a0cf90cd4fb7a6f93f38eadc51b78c9 100644 (file)
@@ -124,6 +124,7 @@ SAVC(objectEncoding);
 SAVC(_result);
 SAVC(createStream);
 SAVC(play);
+SAVC(closeStream);
 SAVC(fmsVer);
 SAVC(mode);
 SAVC(level);
@@ -297,7 +298,7 @@ ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *b
           }
         }
 
-      if (!RTMP_Connect(&server->rc))
+      if (!RTMP_Connect(&server->rc, pack))
         {
           /* failed */
           return 1;
@@ -313,6 +314,7 @@ ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *b
          0x00, 0x00, 0x00, 0x00      // first prevTagSize=0
        };
 
+      server->rc.m_stream_id = pack->m_nInfoField2;
       AMFProp_GetString(AMF_GetProp(&obj, NULL, 3), &av);
       server->rc.Link.playpath = av;
       q = strchr(av.av_val, '?');
@@ -371,6 +373,10 @@ ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *b
          ret = 1;
        }
     }
+  else if (AVMATCH(&method, &av_closeStream))
+    {
+      ret = 1;
+    }
   else if (AVMATCH(&method, &av_close))
     {
       RTMP_Close(&server->rc);
@@ -385,8 +391,8 @@ ServePacket(STREAMING_SERVER *server, int which, RTMPPacket *packet)
 {
   int ret = 0;
 
-  Log(LOGDEBUG, "%s, received packet type %02X, size %lu bytes", __FUNCTION__,
-    packet->m_packetType, packet->m_nBodySize);
+  Log(LOGDEBUG, "%s, %s sent packet type %02X, size %lu bytes", __FUNCTION__,
+    cst[which], packet->m_packetType, packet->m_nBodySize);
 
   switch (packet->m_packetType)
     {
@@ -432,20 +438,6 @@ ServePacket(STREAMING_SERVER *server, int which, RTMPPacket *packet)
 
     case 0x11:                 // flex message
       {
-       Log(LOGDEBUG, "%s, flex message, size %lu bytes, not fully supported",
-           __FUNCTION__, packet->m_nBodySize);
-       //LogHex(packet.m_body, packet.m_nBodySize);
-
-       // some DEBUG code
-       /*RTMP_LIB_AMFObject obj;
-          int nRes = obj.Decode(packet.m_body+1, packet.m_nBodySize-1);
-          if(nRes < 0) {
-          Log(LOGERROR, "%s, error decoding AMF3 packet", __FUNCTION__);
-          //return;
-          }
-
-          obj.Dump(); */
-
        ret = ServeInvoke(server, which, packet, packet->m_body + 1);
        break;
       }
@@ -459,10 +451,6 @@ ServePacket(STREAMING_SERVER *server, int which, RTMPPacket *packet)
 
     case 0x14:
       // invoke
-      Log(LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__,
-         packet->m_nBodySize);
-      //LogHex(packet.m_body, packet.m_nBodySize);
-
       ret = ServeInvoke(server, which, packet, packet->m_body);
       break;
 
@@ -794,18 +782,24 @@ void doServe(STREAMING_SERVER * server,   // server socket and state (our listenin
                         if (id)
                           {
                             len = AMF_DecodeInt32(ptr+4);
+#if 1
                             /* request a big buffer */
                             if (len < BUFFERTIME)
                               {
                                 AMF_EncodeInt32(ptr+4, ptr+8, BUFFERTIME);
                               }
+#endif
                             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, 0, &ps);
+                else if (ps.m_packetType == 0x11 || ps.m_packetType == 0x14)
+                  if (ServePacket(server, 0, &ps) && server->out)
+                    {
+                      fclose(server->out);
+                      server->out = NULL;
+                    }
                 RTMP_SendPacket(&server->rc, &ps, false);
                 RTMPPacket_Free(&ps);
                 break;
@@ -1048,7 +1042,7 @@ main(int argc, char **argv)
   LogPrintf("RTMP Proxy Server %s\n", RTMPDUMP_VERSION);
   LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
 
-  debuglevel = LOGDEBUG;
+  debuglevel = LOGINFO;
 
   if (argc > 1 && !strcmp(argv[1], "-z"))
     debuglevel = LOGALL;
index e77e588b0e3b1c5fad7633cafbc209ebf195ea64..9120e7823c1e8ec4b96da81dd31ece416dfb59f4 100644 (file)
--- a/streams.c
+++ b/streams.c
@@ -639,7 +639,7 @@ void processTCPrequest(STREAMING_SERVER * server,   // server socket and state (ou
   rtmp.Link.token = req.token;
 
   LogPrintf("Connecting ... port: %d, app: %s\n", req.rtmpport, req.app);
-  if (!RTMP_Connect(&rtmp))
+  if (!RTMP_Connect(&rtmp, NULL))
     {
       LogPrintf("%s, failed to connect!\n", __FUNCTION__);
     }