diff options
Diffstat (limited to 'remux.c')
-rw-r--r-- | remux.c | 60 |
1 files changed, 18 insertions, 42 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: remux.c 2.60 2011/08/27 14:20:18 kls Exp $ + * $Id: remux.c 2.61 2011/09/04 10:13:14 kls Exp $ */ #include "remux.h" @@ -785,8 +785,7 @@ cFrameDetector::cFrameDetector(int Pid, int Type) { SetPid(Pid, Type); synced = false; - newPayload = newFrame = independentFrame = false; - frameTypeOffset = -1; + newFrame = independentFrame = false; numPtsValues = 0; numFrames = 0; numIFrames = 0; @@ -813,8 +812,7 @@ void cFrameDetector::SetPid(int Pid, int Type) void cFrameDetector::Reset(void) { - newPayload = newFrame = independentFrame = false; - frameTypeOffset = -1; + newFrame = independentFrame = false; payloadUnitOfFrame = 0; scanning = false; scanner = EMPTY_SCANNER; @@ -822,8 +820,9 @@ void cFrameDetector::Reset(void) int cFrameDetector::Analyze(const uchar *Data, int Length) { + int SeenPayloadStart = false; int Processed = 0; - newPayload = newFrame = independentFrame = false; + newFrame = independentFrame = false; while (Length >= TS_SIZE) { if (Data[0] != TS_SYNC_BYTE) { int Skipped = 1; @@ -836,8 +835,11 @@ int cFrameDetector::Analyze(const uchar *Data, int Length) int Pid = TsPid(Data); if (Pid == pid) { if (TsPayloadStart(Data)) { + SeenPayloadStart = true; if (synced && Processed) - return Processed; // flush everything before this new payload + return Processed; + if (Length < MIN_TS_PACKETS_FOR_FRAME_DETECTOR * TS_SIZE) + return Processed; // need more data, in case the frame type is not stored in the first TS packet if (framesPerSecond <= 0.0) { // frame rate unknown, so collect a sequence of PTS values: if (numPtsValues < 2 || numPtsValues < MaxPtsValues && numIFrames < 2) { // collect a sequence containing at least two I-frames @@ -902,10 +904,6 @@ int cFrameDetector::Analyze(const uchar *Data, int Length) if (scanning) { int PayloadOffset = TsPayloadOffset(Data); if (TsPayloadStart(Data)) { - if (synced && Processed) - return Processed; // flush everything before this new payload - newPayload = true; - scanner = EMPTY_SCANNER; PayloadOffset += PesPayloadOffset(Data + PayloadOffset); if (!framesPerPayloadUnit) framesPerPayloadUnit = framesInPayloadUnit; @@ -913,29 +911,17 @@ int cFrameDetector::Analyze(const uchar *Data, int Length) dbgframes("/"); } for (int i = PayloadOffset; scanning && i < TS_SIZE; i++) { - if (frameTypeOffset < 0) { - scanner <<= 8; - scanner |= Data[i]; - } - else - frameTypeOffset += PayloadOffset; + scanner <<= 8; + scanner |= Data[i]; switch (type) { case 0x01: // MPEG 1 video case 0x02: // MPEG 2 video if (scanner == 0x00000100) { // Picture Start Code - if (frameTypeOffset < 0) { - frameTypeOffset = i + 2; - if (frameTypeOffset >= TS_SIZE) { // the byte to check is in the next TS packet - frameTypeOffset -= TS_SIZE; - if (!synced) - dbgframes("%d>", frameTypeOffset); - break; - } - } scanner = EMPTY_SCANNER; + if (synced && !SeenPayloadStart && Processed) + return Processed; // flush everything before this new frame newFrame = true; - uchar FrameType = (Data[frameTypeOffset] >> 3) & 0x07; - frameTypeOffset = -1; + uchar FrameType = (Data[i + 2] >> 3) & 0x07; independentFrame = FrameType == 1; // I-Frame if (synced) { if (framesPerPayloadUnit <= 1) @@ -955,29 +941,19 @@ int cFrameDetector::Analyze(const uchar *Data, int Length) break; case 0x1B: // MPEG 4 video if (scanner == 0x00000109) { // Access Unit Delimiter - if (frameTypeOffset < 0) { - frameTypeOffset = i + 1; - if (frameTypeOffset >= TS_SIZE) { // the byte to check is in the next TS packet - frameTypeOffset -= TS_SIZE; - if (!synced) - dbgframes("%d>", frameTypeOffset); - break; - } - } scanner = EMPTY_SCANNER; + if (synced && !SeenPayloadStart && Processed) + return Processed; // flush everything before this new frame newFrame = true; - uchar FrameType = Data[frameTypeOffset]; - frameTypeOffset = -1; + uchar FrameType = Data[i + 1]; independentFrame = FrameType == 0x10; if (synced) { if (framesPerPayloadUnit < 0) { payloadUnitOfFrame = (payloadUnitOfFrame + 1) % -framesPerPayloadUnit; if (payloadUnitOfFrame != 0 && independentFrame) payloadUnitOfFrame = 0; - if (payloadUnitOfFrame) { - newPayload = false; + if (payloadUnitOfFrame) newFrame = false; - } } if (framesPerPayloadUnit <= 1) scanning = false; |