Skip to content

Commit

Permalink
Merge pull request #101 from jcdr428/Correct_Arrival_Time_Stamps
Browse files Browse the repository at this point in the history
Fix M2TS0077
  • Loading branch information
justdan96 authored Jan 4, 2020
2 parents 86d1cd9 + a64a048 commit de44fe2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
9 changes: 4 additions & 5 deletions tsMuxer/blurayHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ bool BlurayHelper::writeBluRayFiles(bool usedBlackPL, int mplsNum, int blankNum,
emptyCommand = bdIndexData + 0x78;
memcpy(emptyCommand, "\x00\x00\x00\x20\x00\x00\x00\x18\x00\x00\x00\x01"
"\x00\x03\x00\x01\x00\x00\x00\x18\x00\x00\x00\x0C"
"\x00\x00\x00\x08\x51\x00\x00\x00\x00\x00\x00\x00", 36); // HDR data extension
"\x00\x00\x00\x08\x21\x00\x00\x00\x00\x00\x00\x00", 36); // HDR data extension
if (*HDR10_metadata & 0x20) bdIndexData[0x94] = 0x51; // 4K flag => 66/100 GB Disk, 109 MB/s Recording_Rate
bdIndexData[0x96] = (uint8_t)HDR10_metadata[0]; // HDR flags

}
Expand Down Expand Up @@ -268,7 +269,6 @@ bool BlurayHelper::createCLPIFile(TSMuxer* muxer, int clpiNum, bool doLog)
vector<int64_t> packetCount = muxer->getMuxedPacketCnt();
vector<int64_t> firstPts = muxer->getFirstPts();
vector<int64_t> lastPts = muxer->getLastPts();
vector<double> maxRates = muxer->getMaxRate();

for (unsigned i = 0; i < muxer->splitFileCnt(); i++)
{
Expand All @@ -282,10 +282,9 @@ bool BlurayHelper::createCLPIFile(TSMuxer* muxer, int clpiNum, bool doLog)
clpiParser.TS_recording_rate = MAX_SUBMUXER_RATE / 8;
else
clpiParser.TS_recording_rate = MAX_MAIN_MUXER_RATE / 8;
// max rate is 109 mbps for UHD BD 66/100 GB Default TR
if (m_dt == UHD_BLURAY)
// max rate is 109 mbps for 4K
if (*HDR10_metadata & 0x20)
clpiParser.TS_recording_rate = (clpiParser.TS_recording_rate * 109) / 48;
//clpiParser.TS_recording_rate = 188.0 / (maxRates[i] / 27000000.0);
clpiParser.number_of_source_packets = packetCount[i];
clpiParser.presentation_start_time = firstPts[i] / 2;
clpiParser.presentation_end_time = lastPts[i] / 2;
Expand Down
25 changes: 8 additions & 17 deletions tsMuxer/tsMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ TSMuxer::TSMuxer(MuxerManager* owner): AbstractMuxer(owner)
m_outBuf = 0;
m_masterMode = false;
m_subMode = false;
m_maxRates.push_back(1e12);
m_minPcrInc = 846; // min PCR between two TS packets for TS_Recording_Rate of 6 MB/s
setPtsOffset(0);
m_canSwithBlock = true;
m_additionCLPISize = 0;
Expand Down Expand Up @@ -181,6 +181,9 @@ void TSMuxer::intAddStream(const std::string& streamName,

int tsStreamIndex = streamIndex + 16;
bool isSecondary = codecReader->isSecondary();
// 4K flag => change min PCR between two TS packets for TS_Recording_Rate of 13.6 MB/s
if (*HDR10_metadata & 0x20) m_minPcrInc = 373;

if (codecName[0] == 'V')
{
if (!isSecondary)
Expand Down Expand Up @@ -469,20 +472,9 @@ void TSMuxer::processM2TSPCR(int64_t pcrVal, int64_t pcrGAP)
int64_t hiResPCR = pcrVal*300 - pcrGAP;
uint64_t pcrValDif = hiResPCR - m_prevM2TSPCR; // m2ts pcr clock based on full 27Mhz counter
double pcrIncPerFrame = double (pcrValDif + 0.1) / (double) m2tsFrameCnt;
if (pcrIncPerFrame > 1.0)
{
int val = FFMIN(pcrIncPerFrame, m_maxRates[m_maxRates.size()-1]);
m_maxRates[m_maxRates.size()-1] = val;
/*
int TS_recording_rate = 188.0 / (val / 27000000.0);
if (TS_recording_rate*8 > 40000000)
{
int gg = 4;
}
*/
// BD player cannot read faster than TS_Recording_Rate
if (pcrIncPerFrame < m_minPcrInc) pcrIncPerFrame = m_minPcrInc;

}

double curM2TSPCR = m_prevM2TSPCR;
uint8_t* curPos;
if (m_m2tsDelayBlocks.size() > 0) {
Expand Down Expand Up @@ -517,7 +509,7 @@ void TSMuxer::processM2TSPCR(int64_t pcrVal, int64_t pcrGAP)
assert(curPos == end);
m_prevM2TSPCROffset = m_outBufLen;
//assert((int64_t) curM2TSPCR == hiResPCR);
m_prevM2TSPCR = hiResPCR;
m_prevM2TSPCR = curM2TSPCR;
}

void TSMuxer::writeEmptyPacketWithPCRTest(int64_t pcrVal)
Expand All @@ -537,7 +529,7 @@ void TSMuxer::writeEmptyPacketWithPCRTest(int64_t pcrVal)
tsPacket->afExists = 1;
tsPacket->adaptiveField.setPCR33(pcrVal);
//tsPacket->counter = m_streamInfo[m_pmt.pcr_pid].m_tsCnt++;
tsPacket->counter = m_streamInfo[m_pmt.pcr_pid].m_tsCnt; // do not increment counter becouse data_exists == 0
tsPacket->counter = m_streamInfo[m_pmt.pcr_pid].m_tsCnt; // do not increment counter because data_exists == 0

memset(curBuf + tsPacket->getHeaderSize(), 0xff, TS_FRAME_SIZE - tsPacket->getHeaderSize());
tsPacket->adaptiveField.length += TS_FRAME_SIZE - tsPacket->getHeaderSize();
Expand Down Expand Up @@ -726,7 +718,6 @@ void TSMuxer::gotoNextFile(uint64_t newPts)
if (pmtInfo.m_index.size() == 0)
continue;
pmtInfo.m_index.push_back(PMTIndex());
m_maxRates.push_back(1e12);

/*
int spSize = pmtInfo.m_index.size();
Expand Down
3 changes: 1 addition & 2 deletions tsMuxer/tsMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class TSMuxer: public AbstractMuxer
bool isInterleaveMode() const;
std::vector<int32_t> getInterleaveInfo(int idx) const;
bool isSubStream() const { return m_subMode; }
std::vector<double> getMaxRate() const { return m_maxRates; }

void setPtsOffset(int64_t value);
protected:
Expand Down Expand Up @@ -188,7 +187,7 @@ class TSMuxer: public AbstractMuxer
bool m_masterMode;
bool m_subMode;
PriorityDataInfo m_priorityData;
std::vector<double> m_maxRates;
int m_minPcrInc;
int64_t m_timeOffset;
int64_t m_lastSITPCR;
bool m_canSwithBlock;
Expand Down
6 changes: 4 additions & 2 deletions tsMuxer/tsPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void CLPIParser::composeCPI(BitStreamWriter& writer, bool isCPIExt) {
writer.putBits(32,0); // skip lengthField

if (isDependStream && !isCPIExt || !isDependStream && isCPIExt)
return; // CPI_SS for MVC depend stream only and vice versa: standart CPI for standart video stream
return; // CPI_SS for MVC depend stream only and vice versa: standard CPI for standard video stream

int beforeCount = writer.getBitsCount() / 8;
//if (length != 0)
Expand Down Expand Up @@ -2606,8 +2606,10 @@ void M2TSStreamInfo::blurayStreamParams(double fps, bool interlaced, int width,
*video_format = interlaced ? 1 : 3;
else if (isPal)
*video_format = interlaced ? 2 : 7;
else if (width >= 2600)
else if (width >= 2600) {
*video_format = 8;
*HDR10_metadata |= 0x20; // 4K flag
}
else if (width >= 1300)
*video_format = interlaced ? 4 : 6; // as 1920x1080
else
Expand Down

0 comments on commit de44fe2

Please sign in to comment.