Hi<br><br>I try to stream MPEG2 TS DVB-T channel using your library (through the MediaPortal TV Server project) and I have problem with some particular channels. <br>In VLC, I get a lot of "PTS out of range" messages, the video is choppy and most of the time stops. I have tested with the mediaServer application distributed with the library and the same problem occurs, so I think the problem comes from incompatibility between the streaming server and the TS recordings.<br>I suspected that the problem comes from the way the PCR is broadcast inside the Transport stream. I have enabled the DEBUG_PCR in the MPEG2TransportStreamFramer.cpp file to check the evolution of time. As you can see, the packet duration estimation is not good and leads to a accumulate delays. I think the problem comes from the fact the PCR is not periodically announced in the Transport Stream. Sometimes, there is very few packets between two PCR announcements. In this case, the calculation made two
estimate the packet duration (fTSPacketDurationEstimate) is not reliable. <br>So I added a new test in MPEG2TransportStreamFramer::updateTSPacketDurationEstimate method in order to check there are enough packets between two packet duration estimation. With at least 20 packets, it seems the estimation converges to the right value and there is no more problem in VLC :)<br><br>That's the code and my log in attached file. <br>It would be better to add a new define value for the minimum number of packets that must be processed before re-estimating the packet duration.<br><br>Thank you<br>Romain<br><br><br>void MPEG2TransportStreamFramer<br>::updateTSPacketDurationEstimate(unsigned char* pkt, double timeNow) {<br> // Sanity check: Make sure we start with the sync byte:<br> if (pkt[0] != TRANSPORT_SYNC_BYTE) {<br> envir() << "Missing sync byte!\n";<br> return;<br> }<br><br> ++fTSPacketCount;<br><br> // If
this packet doesn't contain a PCR, then we're not interested in it:<br> u_int8_t const adaptation_field_control = (pkt[3]&0x30)>>4;<br> if (adaptation_field_control != 2 && adaptation_field_control != 3) return;<br> // there's no adaptation_field<br><br> u_int8_t const adaptation_field_length = pkt[4];<br> if (adaptation_field_length == 0) return;<br><br> u_int8_t const discontinuity_indicator = pkt[5]&0x80;<br> u_int8_t const pcrFlag = pkt[5]&0x10;<br> if (pcrFlag == 0) return; // no PCR<br><br> // There's a PCR. Get it, and the PID:<br> u_int32_t pcrBaseHigh = (pkt[6]<<24)|(pkt[7]<<16)|(pkt[8]<<8)|pkt[9];<br> double clock = pcrBaseHigh/45000.0;<br> if ((pkt[10]&0x80) != 0) clock += 1/90000.0; // add in low-bit (if set)<br> unsigned short pcrExt = ((pkt[10]&0x01)<<8) | pkt[11];<br> clock +=
pcrExt/27000000.0;<br><br> unsigned pid = ((pkt[1]&0x1F)<<8) | pkt[2];<br><br> // Check whether we already have a record of a PCR for this PID:<br> PIDStatus* pidStatus = (PIDStatus*)(fPIDStatusTable->Lookup((char*)pid));<br> <br><br> if (pidStatus == NULL) {<br> // We're seeing this PID's PCR for the first time:<br> pidStatus = new PIDStatus(clock, timeNow);<br> fPIDStatusTable->Add((char*)pid, pidStatus);<br>#ifdef DEBUG_PCR<br> fprintf(stderr, "PID 0x%x, FIRST PCR 0x%08x+%d:%03x == %f @ %f, pkt #%lu\n", pid, pcrBaseHigh, pkt[10]>>7, pcrExt, clock, timeNow, fTSPacketCount);<br>#endif<br> } else {<br> // We've seen this PID's PCR before; update our per-packet duration estimate:<br> double durationPerPacket<br> = (clock - pidStatus->lastClock)/(fTSPacketCount -
pidStatus->lastPacketNum);<br><br>==> if (fTSPacketCount - pidStatus->lastPacketNum<=20) // The new test<br>==> return;<br><br> if (fTSPacketDurationEstimate == 0.0) { // we've just started<br> fTSPacketDurationEstimate = durationPerPacket;<br> } else if (discontinuity_indicator == 0 && durationPerPacket >= 0.0) {<br> fTSPacketDurationEstimate<br> = durationPerPacket*NEW_DURATION_WEIGHT<br> + fTSPacketDurationEstimate*(1-NEW_DURATION_WEIGHT);<br><br> // Also adjust the duration estimate to try to ensure that the transmission<br> // rate matches the playout rate:<br> double transmitDuration = timeNow - pidStatus->firstRealTime;<br>
double playoutDuration = clock - pidStatus->firstClock;<br> if (transmitDuration > playoutDuration) {<br> fTSPacketDurationEstimate *= TIME_ADJUSTMENT_FACTOR; // reduce estimate<br> } else if (transmitDuration + MAX_PLAYOUT_BUFFER_DURATION < playoutDuration) {<br> fTSPacketDurationEstimate /= TIME_ADJUSTMENT_FACTOR; // increase estimate<br> }<br> } else {<br> // the PCR has a discontinuity from its previous value; don't use it now,<br> // but reset our PCR and real-time values to compensate:<br> pidStatus->firstClock = clock;<br> pidStatus->firstRealTime = timeNow;<br> }<br>#ifdef DEBUG_PCR<br> fprintf(stderr, "PID 0x%x, PCR 0x%08x+%d:%03x == %f @ %f (diffs %f @
%f), pkt #%lu, discon %d => this duration %f, new estimate %f\n", pid, pcrBaseHigh, pkt[10]>>7, pcrExt, clock, timeNow, clock - pidStatus->firstClock, timeNow - pidStatus->firstRealTime, fTSPacketCount, discontinuity_indicator != 0, durationPerPacket, fTSPacketDurationEstimate);<br>#endif<br> }<br><br> pidStatus->lastClock = clock;<br> pidStatus->lastRealTime = timeNow;<br> pidStatus->lastPacketNum = fTSPacketCount;<br>}<br><br><br><BR><BR><p> 
<hr size="1">
Ne gardez plus qu'une seule adresse mail ! <a href="http://fr.rd.yahoo.com/mail/mail_taglines/trueswitch/SIG=11gshn0bu/**http%3A%2F%2Fwww.trueswitch.com%2Fyahoo-fr%2F">Copiez vos mails</a> vers Yahoo! Mail