[rtmpdump] r205 - in trunk: rtmp.c rtmp.h rtmpsuck.c

hyc subversion at mplayerhq.hu
Thu Jan 7 23:28:55 CET 2010


Author: hyc
Date: Thu Jan  7 23:28:54 2010
New Revision: 205

Log:
Fixed per-chunk sending

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

Modified: trunk/rtmp.c
==============================================================================
--- trunk/rtmp.c	Thu Jan  7 08:35:35 2010	(r204)
+++ trunk/rtmp.c	Thu Jan  7 23:28:54 2010	(r205)
@@ -1968,13 +1968,6 @@ RTMP_ReadPacket(RTMP * r, RTMPPacket * p
 
   LogHexString(LOGDEBUG2, hbuf, hSize);
 
-  /* Does the caller want a raw copy of the header ? */
-  packet->m_headerSize = hSize;
-  if (packet->m_header)
-    {
-      memcpy(packet->m_header, hbuf, hSize);
-    }
-
   bool didAlloc = false;
   if (packet->m_nBodySize > 0 && packet->m_body == NULL)
     {
@@ -1992,6 +1985,15 @@ RTMP_ReadPacket(RTMP * r, RTMPPacket * p
   if (nToRead < nChunk)
     nChunk = nToRead;
 
+  /* Does the caller want the raw chunk? */
+  if (packet->m_chunk)
+    {
+      packet->m_chunk->c_headerSize = hSize;
+      memcpy(packet->m_chunk->c_header, hbuf, hSize);
+      packet->m_chunk->c_chunk = packet->m_body+packet->m_nBytesRead;
+      packet->m_chunk->c_chunkSize = nChunk;
+    }
+
   if (ReadN(r, packet->m_body + packet->m_nBytesRead, nChunk) != nChunk)
     {
       Log(LOGERROR, "%s, failed to read RTMP packet body. len: %lu",
@@ -2024,7 +2026,7 @@ 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
     }
-  else if (!packet->m_header)
+  else
     {
       packet->m_body = NULL;	/* so it won't be erased on free */
     }
@@ -2162,17 +2164,18 @@ SHandShake(RTMP * r)
 #endif
 
 bool
-RTMP_SendChunk(RTMP *r, RTMPPacket *packet, int offset)
+RTMP_SendChunk(RTMP *r, RTMPChunk *chunk)
 {
-  int nsize = packet->m_nBytesRead - offset;
-  int wrote;
+  bool 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);
+  Log(LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_socket, chunk->c_chunkSize);
+  LogHexString(LOGDEBUG2, chunk->c_header, chunk->c_headerSize);
+  if (chunk->c_chunkSize)
+    LogHexString(LOGDEBUG2, chunk->c_chunk, chunk->c_chunkSize);
+  wrote = WriteN(r, chunk->c_header, chunk->c_headerSize);
+  if (wrote && chunk->c_chunkSize)
+    wrote = WriteN(r, chunk->c_chunk, chunk->c_chunkSize);
+  return wrote;
 }
 
 bool

Modified: trunk/rtmp.h
==============================================================================
--- trunk/rtmp.h	Thu Jan  7 08:35:35 2010	(r204)
+++ trunk/rtmp.h	Thu Jan  7 23:28:54 2010	(r205)
@@ -80,11 +80,18 @@ uint32_t RTMP_GetTime();
 
 typedef unsigned char BYTE;
 
+typedef struct RTMPChunk
+{
+  int c_headerSize;
+  int c_chunkSize;
+  char *c_chunk;
+  char c_header[RTMP_MAX_HEADER_SIZE];
+} RTMPChunk;
+
 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
@@ -92,7 +99,7 @@ typedef struct RTMPPacket
   uint32_t m_nTimeStamp;	// absolute timestamp
   uint32_t m_nBodySize;
   uint32_t m_nBytesRead;
-  char *m_header;
+  RTMPChunk *m_chunk;
   char *m_body;
 } RTMPPacket;
 
@@ -216,7 +223,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_SendChunk(RTMP * r, RTMPChunk *chunk);
 bool RTMP_IsConnected(RTMP *r);
 bool RTMP_IsTimedout(RTMP *r);
 double RTMP_GetDuration(RTMP *r);

Modified: trunk/rtmpsuck.c
==============================================================================
--- trunk/rtmpsuck.c	Thu Jan  7 08:35:35 2010	(r204)
+++ trunk/rtmpsuck.c	Thu Jan  7 23:28:54 2010	(r205)
@@ -698,7 +698,8 @@ void doServe(STREAMING_SERVER * server,	
   )
 {
   RTMPPacket pc = { 0 }, ps = { 0 };
-  char *buf, hbuf[RTMP_MAX_HEADER_SIZE];
+  RTMPChunk rk = { 0 };
+  char *buf;
   unsigned int buflen = 131072;
   bool paused = false;
 
@@ -744,7 +745,7 @@ void doServe(STREAMING_SERVER * server,	
         break;
     }
 
-/*   pc.m_header = hbuf; */
+  pc.m_chunk = &rk;
 
   /* We have our own timeout in select() */
   server->rc.Link.timeout = 10;
@@ -852,9 +853,10 @@ void doServe(STREAMING_SERVER * server,	
       if (cr)
         {
           while (RTMP_ReadPacket(&server->rc, &pc))
+            {
+              int sendit = 1;
               if (RTMPPacket_IsReady(&pc))
                 {
-                  int sendit = 1;
                   if (paused)
                     {
                       if (pc.m_nTimeStamp <= server->rc.m_mediaStamp)
@@ -909,11 +911,13 @@ void doServe(STREAMING_SERVER * server,	
                           server->f_cur = NULL;
                         }
                     }
-                  if (sendit && RTMP_IsConnected(&server->rs))
-                    RTMP_SendPacket(&server->rs, &pc, false);
-                  RTMPPacket_Free(&pc);
-                  break;
                 }
+              if (sendit && RTMP_IsConnected(&server->rs))
+                RTMP_SendChunk(&server->rs, &rk);
+              if (RTMPPacket_IsReady(&pc))
+                  RTMPPacket_Free(&pc);
+              break;
+            }
         }
       if (!RTMP_IsConnected(&server->rs) && RTMP_IsConnected(&server->rc)
         && !server->f_cur)


More information about the rtmpdump mailing list