From 4f69bda7c493f88bae4db803eca7b67a77fec0d6 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 15 May 2010 14:51:29 +0000 Subject: [PATCH] HDTV fix for HDTV --- demuxerts.cc | 32 ++++++++++++++++++++++++++++++-- demuxerts.h | 5 ++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/demuxerts.cc b/demuxerts.cc index 25b4de4..653308e 100644 --- a/demuxerts.cc +++ b/demuxerts.cc @@ -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(); diff --git a/demuxerts.h b/demuxerts.h index 4d58840..9023d3c 100644 --- a/demuxerts.h +++ b/demuxerts.h @@ -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 PTSMap; PTSMap pts_map; -- 2.39.5