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

hyc subversion at mplayerhq.hu
Wed Jan 6 11:24:00 CET 2010


Author: hyc
Date: Wed Jan  6 11:23:59 2010
New Revision: 199

Log:
Add RTMP_SendChunk() for sending incomplete packets. Add m_header to packet,
for a copy of a received packet's raw header

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

Modified: trunk/rtmp.c
==============================================================================
--- trunk/rtmp.c	Wed Jan  6 10:42:45 2010	(r198)
+++ trunk/rtmp.c	Wed Jan  6 11:23:59 2010	(r199)
@@ -1968,6 +1968,13 @@ RTMP_ReadPacket(RTMP * r, RTMPPacket * p
 
   LogHexString(LOGDEBUG2, hbuf, hSize);
 
+  /* Does the caller want a raw copy of the header ? */
+  if (packet->m_header)
+    {
+      packet->m_headerSize = hSize;
+      memcpy(packet->m_header, hbuf, hSize);
+    }
+
   bool didAlloc = false;
   if (packet->m_nBodySize > 0 && packet->m_body == NULL)
     {
@@ -2017,10 +2024,12 @@ RTMP_ReadPacket(RTMP * r, RTMPPacket * p
       r->m_vecChannelsIn[packet->m_nChannel]->m_nBytesRead = 0;
       r->m_vecChannelsIn[packet->m_nChannel]->m_hasAbsTimestamp = false;	// can only be false if we reuse header
     }
+#if 0
   else
     {
       packet->m_body = NULL;	/* so it won't be erased on free */
     }
+#endif
 
   return true;
 }
@@ -2155,6 +2164,20 @@ SHandShake(RTMP * r)
 #endif
 
 bool
+RTMP_SendChunk(RTMP *r, RTMPPacket *packet, int offset)
+{
+  int nsize = packet->m_nBytesRead - offset;
+  int wrote;
+
+  Log(LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_socket, nsize);
+  LogHexString(LOGDEBUG2, packet->m_header, packet->m_headerSize);
+  LogHexString(LOGDEBUG2, packet->m_body+offset, nsize);
+  wrote = WriteN(r, packet->m_header, packet->m_headerSize);
+  if (!wrote) return wrote;
+  return WriteN(r, packet->m_body+offset, nsize);
+}
+
+bool
 RTMP_SendPacket(RTMP * r, RTMPPacket * packet, bool queue)
 {
   const RTMPPacket *prevPacket = r->m_vecChannelsOut[packet->m_nChannel];

Modified: trunk/rtmp.h
==============================================================================
--- trunk/rtmp.h	Wed Jan  6 10:42:45 2010	(r198)
+++ trunk/rtmp.h	Wed Jan  6 11:23:59 2010	(r199)
@@ -84,13 +84,15 @@ typedef struct RTMPPacket
 {
   BYTE m_headerType;
   BYTE m_packetType;
+  BYTE m_headerSize;
+  BYTE m_hasAbsTimestamp;	// timestamp absolute or relative?
   int m_nChannel;
   uint32_t m_nInfoField1;	// 3 first bytes
   int32_t m_nInfoField2;	// last 4 bytes in a long header, absolute timestamp for long headers, relative timestamp for short headers
-  bool m_hasAbsTimestamp;	// timestamp absolute or relative?
   uint32_t m_nTimeStamp;	// absolute timestamp
   uint32_t m_nBodySize;
   uint32_t m_nBytesRead;
+  char *m_header;
   char *m_body;
 } RTMPPacket;
 
@@ -214,6 +216,7 @@ bool RTMP_Serve(RTMP *r);
 
 bool RTMP_ReadPacket(RTMP * r, RTMPPacket * packet);
 bool RTMP_SendPacket(RTMP * r, RTMPPacket * packet, bool queue);
+bool RTMP_SendChunk(RTMP * r, RTMPPacket * packet, int offset);
 bool RTMP_IsConnected(RTMP *r);
 bool RTMP_IsTimedout(RTMP *r);
 double RTMP_GetDuration(RTMP *r);


More information about the rtmpdump mailing list