summaryrefslogtreecommitdiff
path: root/cutter.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2012-11-29 15:34:55 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2012-11-29 15:34:55 +0100
commitb73c83e2a1b2cb3e70a0b5be035ef087c9bdd045 (patch)
tree2f2175b1aefd81e9dea3df66f32de22d8f6b94d0 /cutter.c
parent2eadd7d4ddc419aafcbdbe397081acff23a541db (diff)
downloadvdr-b73c83e2a1b2cb3e70a0b5be035ef087c9bdd045.tar.gz
vdr-b73c83e2a1b2cb3e70a0b5be035ef087c9bdd045.tar.bz2
Fixed adjusting the DTS values in the cutter, to compensate for dropped B-frames
Diffstat (limited to 'cutter.c')
-rw-r--r--cutter.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/cutter.c b/cutter.c
index 21f91560..81df1869 100644
--- a/cutter.c
+++ b/cutter.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: cutter.c 2.19 2012/11/26 17:21:14 kls Exp $
+ * $Id: cutter.c 2.20 2012/11/29 15:30:01 kls Exp $
*/
#include "cutter.h"
@@ -154,8 +154,10 @@ bool cDanglingPacketStripper::Process(uchar *Data, int Length, int64_t FirstPts)
class cPtsFixer {
private:
int delta; // time between two frames
- int64_t last; // the last (i.e. highest) video PTS value seen
- int64_t offset; // offset to add to PTS values
+ int64_t deltaDts; // the difference between two consecutive DTS values (may differ from 'delta' in case of multiple fields per frame)
+ int64_t lastPts; // the video PTS of the last frame (in display order)
+ int64_t lastDts; // the last video DTS value seen
+ int64_t offset; // offset to add to all timestamps
bool fixCounters; // controls fixing the TS continuity counters (only from the second CutIn up)
uchar counter[MAXPID]; // the TS continuity counter for each PID
cPatPmtParser patPmtParser;
@@ -168,7 +170,9 @@ public:
cPtsFixer::cPtsFixer(void)
{
delta = 0;
- last = -1;
+ deltaDts = 0;
+ lastPts = -1;
+ lastDts = -1;
offset = -1;
fixCounters = false;
memset(counter, 0x00, sizeof(counter));
@@ -186,11 +190,11 @@ void cPtsFixer::Fix(uchar *Data, int Length, bool CutIn)
return;
}
// Determine the PTS offset at the beginning of each sequence (except the first one):
- if (CutIn && last >= 0) {
+ if (CutIn && lastPts >= 0) {
int64_t Pts = TsGetPts(Data, Length);
if (Pts >= 0) {
- // offset is calculated so that Pts + offset results in last + delta:
- offset = Pts - PtsAdd(last, delta);
+ // offset is calculated so that Pts + offset results in lastPts + delta:
+ offset = Pts - PtsAdd(lastPts, delta);
if (offset <= 0)
offset = -offset;
else
@@ -199,14 +203,32 @@ void cPtsFixer::Fix(uchar *Data, int Length, bool CutIn)
fixCounters = true;
}
// Keep track of the highest video PTS:
+ bool GotPts = false;
+ int64_t PrevDts = lastDts;
uchar *p = Data;
int len = Length;
while (len >= TS_SIZE && *p == TS_SYNC_BYTE) {
int Pid = TsPid(p);
if (Pid == patPmtParser.Vpid()) {
- int64_t Pts = PtsAdd(TsGetPts(p, TS_SIZE), offset); // offset is taken into account here, to make last have the "new" value already!
- if (Pts >= 0 && (last < 0 || PtsDiff(last, Pts) > 0))
- last = Pts;
+ if (!GotPts) { // in case of multiple fields per frame, the offset is calculated only with the first one
+ int64_t Pts = TsGetPts(p, TS_SIZE);
+ if (Pts >= 0) {
+ if (offset >= 0)
+ Pts = PtsAdd(Pts, offset); // offset is taken into account here, to make lastPts have the "new" value already!
+ if (lastPts < 0 || PtsDiff(lastPts, Pts) > 0)
+ lastPts = Pts;
+ }
+ GotPts = true;
+ }
+ if (!CutIn) {
+ int64_t Dts = TsGetDts(p, TS_SIZE);
+ if (Dts >= 0) {
+ if (offset >= 0)
+ Dts = PtsAdd(Dts, offset); // offset is taken into account here, to make lastDts have the "new" value already!
+ deltaDts = PtsDiff(PrevDts, Dts);
+ PrevDts = Dts;
+ }
+ }
}
// Adjust the TS continuity counter:
if (fixCounters) {
@@ -229,8 +251,14 @@ void cPtsFixer::Fix(uchar *Data, int Length, bool CutIn)
if (Pts >= 0)
TsSetPts(p, TS_SIZE, PtsAdd(Pts, offset));
int64_t Dts = TsGetDts(p, TS_SIZE);
- if (Dts >= 0)
- TsSetDts(p, TS_SIZE, PtsAdd(Dts, offset));
+ if (Dts >= 0) {
+ if (CutIn) {
+ lastDts = PtsAdd(lastDts, deltaDts);
+ TsSetDts(p, TS_SIZE, lastDts);
+ }
+ else
+ TsSetDts(p, TS_SIZE, PtsAdd(Dts, offset));
+ }
int64_t Pcr = TsGetPcr(p);
if (Pcr >= 0) {
int64_t NewPcr = Pcr + offset * PCRFACTOR;
@@ -242,6 +270,7 @@ void cPtsFixer::Fix(uchar *Data, int Length, bool CutIn)
len -= TS_SIZE;
}
}
+ lastDts = PrevDts;
}
// --- cCuttingThread --------------------------------------------------------