All pastes #210224 Raw Edit

Mine

public text v1 · immutable
#210224 ·published 2006-10-19 16:28 UTC
rendered paste body
Index: libmpdemux/demux_rtp_codec.cpp
===================================================================
--- libmpdemux/demux_rtp_codec.cpp      (Revision 20307)
+++ libmpdemux/demux_rtp_codec.cpp      (Arbeitskopie)
@@ -86,6 +86,27 @@
     } while (!parseQTState_video(qtRTPSource->qtState, fourcc));

     bih->biCompression = sh_video->format = fourcc;
+    bih->biWidth = qtRTPSource->qtState.width;
+    bih->biHeight = qtRTPSource->qtState.height;
+    if (bih->biCompression == mmioFOURCC('a','v','c','1')) {
+      uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86;
+      uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom
+                        + qtRTPSource->qtState.sdAtomSize;
+      while (pos+8 < endpos) {
+        unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3];
+        if (atomLength == 0 || atomLength > endpos-pos) break;
+        if (memcmp(pos+4, "avcC", 4) == 0 &&
+            atomLength > 8 &&
+            atomLength <= INT_MAX-sizeof(BITMAPINFOHEADER)) {
+          bih->biSize = sizeof(BITMAPINFOHEADER)+atomLength-8;
+          sh_video->bih = bih = (BITMAPINFOHEADER*)realloc(bih, bih->biSize);
+          memcpy(bih+1, pos+8, atomLength-8);
+          break;
+        }
+        pos += atomLength;
+      }
+      needVideoFrameRate(demuxer, subsession);
+    }
   } else {
     fprintf(stderr,
            "Unknown MPlayer format code for MIME type \"video/%s\"\n",
@@ -201,6 +222,9 @@
            subsession->codecName());
   }
 }
+extern "C" {
+#include "math.h"
+}

 static void needVideoFrameRate(demuxer_t* demuxer,
                               MediaSubsession* subsession) {
@@ -225,19 +249,24 @@
   unsigned char* packetData; unsigned packetDataLen;
   float lastPTS = 0.0, curPTS;
   unsigned const maxNumFramesToWaitFor = 300;
+  int lastfps = 0;
   for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) {
     if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) {
       break;
     }

-    if (curPTS > lastPTS && lastPTS != 0.0) {
+    if (curPTS != lastPTS && lastPTS != 0.0) {
       // Use the difference between these two "pts"s to guess the frame rate.
       // (should really check that there were no missing frames inbetween)#####
       // Guess the frame rate as an integer.  If it's not, use "-fps" instead.
-      fps = (int)(1/(curPTS-lastPTS) + 0.5); // rounding
+      fps = (int)(1/fabs(curPTS-lastPTS) + 0.5); // rounding
+        if (fps == lastfps) {
       fprintf(stderr, "demux_rtp: Guessed the video frame rate as %d frames-per-second.\n\t(If this is wrong, use the \"-fps <frame-rate>\" option instead.)\n", fps);
+      sh_video->frametime=1.0f/fps;
       sh_video->fps = fps;
       return;
+        }
+      if (fps>lastfps) lastfps = fps;
     }
     lastPTS = curPTS;
   }