[MPlayer-dev-eng] [PATCH] dynamic buffer size of RTP frame

Spectr spectr at gmail.com
Thu Mar 29 23:28:54 CEST 2007


This patch change buffer size of RTP frames from fixed size to dynamically
changed, depend on real stream image size.

--- libmpdemux/demux_rtp.cpp    2007-03-29 23:31:58.000000000 +0300
+++ libmpdemux/demux_rtp.cpp    2007-03-30 00:23:42.000000000 +0300
@@ -355,17 +355,27 @@

 ////////// Extra routines that help implement the above interface
functions:

-#define MAX_RTP_FRAME_SIZE 50000
+#define MAX_RTP_FRAME_SIZE 4194304
     // >= the largest conceivable frame composed from one or more RTP
packets
+unsigned long rtp_frame_size = 65536;

 static void afterReading(void* clientData, unsigned frameSize,
-            unsigned /*numTruncatedBytes*/,
+            unsigned numTruncatedBytes,
             struct timeval presentationTime,
             unsigned /*durationInMicroseconds*/) {
   int headersize = 0;
-  if (frameSize >= MAX_RTP_FRAME_SIZE) {
-    fprintf(stderr, "Saw an input frame too large (>=%d).  Increase
MAX_RTP_FRAME_SIZE in \"demux_rtp.cpp\".\n",
-       MAX_RTP_FRAME_SIZE);
+  int size = frameSize + numTruncatedBytes;
+  size += size / 2;
+  if (size > rtp_frame_size) {
+    int i;
+    int j = size - 1;
+    for (i = 0; j >>= 1; i++);
+    rtp_frame_size = 1 << (i + 1);
+    if (rtp_frame_size > MAX_RTP_FRAME_SIZE) {
+      fprintf(stderr, "Saw an input frame too large (>=%d).  Increase
MAX_RTP_FRAME_SIZE in \"demux_rtp.cpp\".\n",
+        MAX_RTP_FRAME_SIZE);
+      rtp_frame_size = MAX_RTP_FRAME_SIZE;
+    }
   }
   ReadBufferQueue* bufferQueue = (ReadBufferQueue*)clientData;
   demuxer_t* demuxer = bufferQueue->ourDemuxer();
@@ -464,13 +474,13 @@
   }

   // Allocate a new packet buffer, and arrange to read into it:
-  dp = new_demux_packet(MAX_RTP_FRAME_SIZE);
+  dp = new_demux_packet(rtp_frame_size);
   bufferQueue->dp = dp;
   if (dp == NULL) return NULL;

   // Schedule the read operation:
   bufferQueue->blockingFlag = 0;
-  bufferQueue->readSource()->getNextFrame(&dp->buffer[headersize],
MAX_RTP_FRAME_SIZE - headersize,
+  bufferQueue->readSource()->getNextFrame(&dp->buffer[headersize],
rtp_frame_size - headersize,
                      afterReading, bufferQueue,
                      onSourceClosure, bufferQueue);
   // Block ourselves until data becomes available:


-- 
With best regards, Spectr.



More information about the MPlayer-dev-eng mailing list