From: hyc Date: Tue, 5 Jan 2010 03:46:39 +0000 (+0000) Subject: Add optional packet param to RTMP_Connect(); rtmpsuck will just send X-Git-Tag: v2.4~322 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20b1cd954d11a7315eb2a2d981b47ac9fa75babb;p=rtmpdump Add optional packet param to RTMP_Connect(); rtmpsuck will just send the original connect packet instead of generating its own. git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@189 400ebc74-4327-4243-bc38-086b20814532 --- diff --git a/rtmp.c b/rtmp.c index 3390fb1..cf25973 100644 --- 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 d3b9aca..0830d75 100644 --- 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); diff --git a/rtmpdump.c b/rtmpdump.c index cdc69ed..ea1d846 100644 --- a/rtmpdump.c +++ b/rtmpdump.c @@ -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; diff --git a/rtmpsuck.c b/rtmpsuck.c index d0299a9..6248024 100644 --- a/rtmpsuck.c +++ b/rtmpsuck.c @@ -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; diff --git a/streams.c b/streams.c index e77e588..9120e78 100644 --- 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__); }