TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Adjust PCR clocks when a TS is merged into a larger one. More...
#include <tsPCRMerger.h>
Public Member Functions | |
PCRMerger (DuckContext &duck) | |
Constructor. | |
void | processPacket (TSPacket &pkt, PacketCounter main_packet_index, const BitRate &main_bitrate) |
Process one packet from the TS to merge. | |
void | reset () |
Reset all collected information. | |
void | setIncremental (bool on) |
Restamp PCR in incremental fashion, not from the initial value. | |
void | setResetBackwards (bool on) |
Reset PCR progression when moving ahead of or far away from PTS or DTS. | |
Adjust PCR clocks when a TS is merged into a larger one.
In each PID with PCR's in the merged stream, we keep the first PCR value unchanged. Then, we need to adjust all subsequent PCR's. PCR's are system clock values. They must be synchronized with the transport stream rate. So, the difference between two PCR's shall be the transmission time in PCR units.
We can compute new precise PCR values when the final bitrate is fixed. However, with a variable bitrate, our computed values will be inaccurate.
Also note that we do not modify DTS and PTS. First, we can't access PTS and DTS in scrambled streams (unlike PCR's). Second, we MUST NOT change them because they indicate at which time the frame shall be processed, not transmitted.
ts::PCRMerger::PCRMerger | ( | DuckContext & | duck | ) |
Constructor.
[in,out] | duck | TSDuck execution context. The reference is kept inside the demux. Contextual information (such as standards) are accumulated in the context from demuxed sections. |
|
inline |
Reset PCR progression when moving ahead of or far away from PTS or DTS.
When restamping PCR's, the PCR adjustment is usually small and stays behind the PTS and DTS. But, after hours of continuous restamping, some inaccuracy my appear and the recomputed PCR may move ahead of PCR and DTS. Similarly, if there is a leap in the input PCR (such as a TS file looping back to the beginning), the difference between the adjusted PCR and input PTS/DTS become huge.
With this option, as soon as a recomputed PCR is ahead of the PTS or DTS in the same packet, of if the difference between PCR and PTS/DTS is larger than one second, PCR restamping is reset and restarts from the original PCR value in this packet. Note that, of course, this creates a small PCR leap in the stream.
The option has, of course, no effect on scrambled streams.
[in] | on | If true, reset PCR progression when moving ahead of PTS or DTS. The initial default is false. |
|
inline |
Restamp PCR in incremental fashion, not from the initial value.
When restamping PCR's from the merged TS into the main TS, compute each new PCR from the last restampted one. By default, all PCR's are restampted from the initial PCR in the PID. The default method is more precise on constant bitrate (CBR) streams. The incremental method gives better results on variable bitrate (VBR) streams.
[in] | on | If true, restamp PCR in incremental fashion, not from the initial value. The initial default is false. |
void ts::PCRMerger::processPacket | ( | TSPacket & | pkt, |
PacketCounter | main_packet_index, | ||
const BitRate & | main_bitrate | ||
) |
Process one packet from the TS to merge.
This method may adjust the PCR of the packet for insertion in the main TS. For accurate adjustment of clocks, all packets from the stream to merge shall pass through this method, even if this packet will not be merged into the main TS, because this method also collects information in the stream to merge.
[in,out] | pkt | One packet from the TS to merge. The PCR may be updated. |
[in] | main_packet_index | Current packet index in the main stream. |
[in] | main_bitrate | Current bitrate of the main stream. If the main bitrate is variable, the PCR adjustment may not be accurate. |