]> git.vomp.tv Git - vompclient.git/commitdiff
HDTV fix for HDTV
authorChris Tallon <chris@vomp.tv>
Sat, 15 May 2010 14:51:29 +0000 (14:51 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 15 May 2010 14:51:29 +0000 (14:51 +0000)
demuxerts.cc
demuxerts.h

index 25b4de468964d81f1a9201642709b14b855389ec..653308ec427dda115a913f0694c044a918f65bd0 100644 (file)
@@ -53,6 +53,8 @@ DemuxerTS::DemuxerTS(int p_vID, int p_aID, int p_subID, int p_tID)
   subLength = 0;
   tID = p_tID;
   havechannelinfo=false;
+  doubledframerate=false;
+  framereserve=0;
 }
 
 void DemuxerTS::flush()
@@ -80,6 +82,8 @@ tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
   subActive = false;
   subLength = 0;
   tActive = false;
+  doubledframerate=false;
+  framereserve=0;
 }
 
 int DemuxerTS::scan(UCHAR *buf, int len)
@@ -223,6 +227,7 @@ void DemuxerTS::setFrameNum(ULONG frame)
 {
   frameCounting = true;
   frameNumber = frame;
+  framereserve=0;
   Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setFrameNum %d", frame);
 }
 
@@ -621,6 +626,7 @@ ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
   while (iter != pts_map.end())
   {
     ++total;
+     //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts1 %lld pts2 %lld", pts, iter->pts);
     if (PTSDifference(iter->pts, pts) < PTS_ALLOWANCE)
     {
       difference = 0;
@@ -643,6 +649,8 @@ ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
     pts_map.erase(iter, pts_map.end());
   }
   pts_map_mutex.Unlock();
+  
+ //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts %lld deleted %d difference %lld", pts, total,difference);
 
   if (difference == (1LL<<33))
     return 0; // We cannot make sense of the pts
@@ -659,7 +667,19 @@ void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff
     {
         packetNumber++;
     }
-    UINT numpicts=packet.countPictureHeaders(h264);
+    UINT pictsinpacket=packet.countPictureHeaders(h264);
+    
+    UINT numpicts=0;
+    if (!doubledframerate)
+    {
+        numpicts=pictsinpacket;
+    }
+    else
+    {
+        numpicts=(pictsinpacket+framereserve)>>1;
+        framereserve=(pictsinpacket+framereserve)%2;
+    }
+
 
   if (frameCounting && numpicts &&
       packet.getPacketType() >= PESTYPE_VID0 &&
@@ -683,9 +703,17 @@ void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff
       pts_map_mutex.Unlock();
 
       //UINT fps = Video::getInstance()->getFPS();
-      ULLONG pts_expected = me.pts + 90000*((int)(((double)(frame_num - me.frame)) / fps));
+      double tfps=fps;
+      if (doubledframerate) tfps*=2.;
+      ULLONG pts_expected = me.pts + 90000*((int)(((double)(frame_num - me.frame)) / tfps));
       while (pts_expected > (1LL<<33)) pts_expected -= (1LL<<33);
 
+      if (!doubledframerate 
+          &&(abs(PTSDistance(pts_expected, packet.getPTS())-1800) <= 1 
+          || abs(PTSDistance(pts_expected, packet.getPTS())-1501) <= 1)) {
+              doubledframerate=true; //Detected  p50 or p60
+      }
+
       if (PTSDistance(pts_expected, packet.getPTS()) > PTS_JUMP_MARGIN) // PTS jump!
       {
         me.pts = packet.getPTS();
index 4d58840369a00859aaa05e928373d12eaf3f1e29..9023d3c6f9e438e7fc43b706abe6dc9cca5e89cb 100644 (file)
@@ -47,7 +47,7 @@ class DemuxerTS : public Demuxer
     int  getAID() { return aID; }
     int  getSubID() { return subID; }
     int put(UCHAR* buf, int len);
-    int PMTPID; //TODO HANS which of these do I Need:
+
     void setFrameNum(ULONG frame);
     void setPacketNum(ULONG npacket);
     ULONG getFrameNumFromPTS(ULLONG pts);
@@ -68,6 +68,7 @@ class DemuxerTS : public Demuxer
     PESPacket subPacket; // Subtitles PES packet under construction
     PESPacket tPacket; // Teletext PES packet under construction
     int vID, aID, subID,tID; // TS IDs for video/audio/subtitles   
+    int PMTPID; //TODO HANS which of these do I Need:
 
     int atype;
     bool subActive;        // Same for subtitles
@@ -81,6 +82,8 @@ class DemuxerTS : public Demuxer
     //TODO HANS which of next do I need
     ULONG frameNumber, packetNumber;
     bool frameCounting, packetCounting;
+    bool doubledframerate;
+    int framereserve;
     typedef struct { ULLONG pts; ULONG frame; } PTSMapEntry;
     typedef std::deque<PTSMapEntry> PTSMap;
     PTSMap pts_map;