From patchwork Tue Jan 28 13:01:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Schmidinger X-Patchwork-Id: 21815 Received: from localhost ([127.0.0.1] helo=www.linuxtv.org) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1W88Ie-0001eC-9c; Tue, 28 Jan 2014 14:01:56 +0100 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1W88Ic-0001e7-Tv for vdr@linuxtv.org; Tue, 28 Jan 2014 14:01:55 +0100 X-tubIT-Incoming-IP: 188.40.50.18 Received: from racoon.tvdr.de ([188.40.50.18]) by mail.tu-berlin.de (exim-4.72/mailfrontend-6) with esmtps [TLSv1:AES256-SHA:256] for id 1W88Ib-0002DI-3E; Tue, 28 Jan 2014 14:01:54 +0100 Received: from dolphin.tvdr.de (dolphin.tvdr.de [192.168.100.2]) by racoon.tvdr.de (8.14.5/8.14.5) with ESMTP id s0SD1pM1001127 for ; Tue, 28 Jan 2014 14:01:51 +0100 Received: from [192.168.100.11] (falcon.tvdr.de [192.168.100.11]) by dolphin.tvdr.de (8.14.4/8.14.4) with ESMTP id s0SD1j8F001343 for ; Tue, 28 Jan 2014 14:01:45 +0100 Message-ID: <52E7AA39.5040405@tvdr.de> Date: Tue, 28 Jan 2014 14:01:45 +0100 From: Klaus Schmidinger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: vdr@linuxtv.org References: <201401142134.12999.EikeSauer@t-online.de> <201401251459.11098.EikeSauer@t-online.de> In-Reply-To: <201401251459.11098.EikeSauer@t-online.de> X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.1.28.125414 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, MIME_TEXT_ONLY_MP_MIXED 0.05, BODYTEXTP_SIZE_3000_LESS 0, NO_URI_FOUND 0, __BAT_BOUNDARY 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CP_MEDIA_BODY 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __CTYPE_MULTIPART_MIXED 0, __HAS_FROM 0, __HAS_MSGID 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MOZILLA_MSGID 0, __MOZILLA_USER_AGENT 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __USER_AGENT 0' X-LSpam-Score: -1.1 (-) X-LSpam-Report: No, score=-1.1 required=5.0 tests=BAYES_00=-1.9, RDNS_NONE=0.793 autolearn=no Subject: Re: [vdr] VDR test series about frame detector X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: vdr-bounces@linuxtv.org Errors-To: vdr-bounces@linuxtv.org The attached patch increases MIN_TS_PACKETS_FOR_FRAME_DETECTOR to 100 and itroduces counting the number of actual video TS packets in cTsPayload in order to be able to record channels that sometimes need even more than 10 TS packets for detecting frame borders. While the frame type can typically be detected by processing at most two video TS packets, there may be several TS packets from other PIDs between the first and second video TS packet. Previously cTsPayload counted all TS packets against MIN_TS_PACKETS_FOR_FRAME_DETECTOR, and that number was intentionally kept small in order to keep the actual data processing at a minimum. With this patch, MIN_TS_PACKETS_FOR_FRAME_DETECTOR will be set to a presumably very safe large value, which only has an impact on the ringbuffer and should not increase processing costs there. The new MAX_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION now defines the number of actual video TS packets that will be processed. There are also WRN_... macros in remux.c, which control some debug messages in case the safety margin for these limits is exceeded. You can try setting these to lower values for experimenting. Please try this patch and let me know if the warning is ever triggered with the given values (or, in case you're experimenting with reduced values, what were the highest values that still triggered warnings). Klaus --- remux.h 2014/01/16 10:15:50 3.1 +++ remux.h 2014/01/28 11:06:37 @@ -217,8 +217,11 @@ int length; int pid; int index; // points to the next byte to process + int numPacketsPid; // the number of TS packets with the given PID (for statistical purposes) + int numPacketsOther; // the number of TS packets with other PIDs (for statistical purposes) + uchar SetEof(void); protected: - void Reset(void) { index = 0; } + void Reset(void); public: cTsPayload(void); cTsPayload(uchar *Data, int Length, int Pid = -1); @@ -246,6 +249,10 @@ ///< is counted with its full size. bool Eof(void) const { return index >= length; } ///< Returns true if all available bytes of the TS payload have been processed. + void Statistics(void) const; + ///< May be called after a new frame has been detected, and will log a warning + ///< if the number of TS packets required to determine the frame type exceeded + ///< some safety limits. uchar GetByte(void); ///< Gets the next byte of the TS payload, skipping any intermediate TS header data. bool SkipBytes(int Bytes); @@ -462,7 +469,7 @@ // Frame detector: -#define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 10 +#define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100 class cFrameParser; --- remux.c 2014/01/18 11:27:30 3.1 +++ remux.c 2014/01/28 11:07:59 @@ -23,6 +23,10 @@ #define dbgpatpmt(a...) if (DebugPatPmt) fprintf(stderr, a) #define dbgframes(a...) if (DebugFrames) fprintf(stderr, a) +#define MAX_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION 6 +#define WRN_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION (MAX_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION / 2) +#define WRN_TS_PACKETS_FOR_FRAME_DETECTOR (MIN_TS_PACKETS_FOR_FRAME_DETECTOR / 2) + #define EMPTY_SCANNER (0xFFFFFFFF) ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader) @@ -231,7 +235,7 @@ data = NULL; length = 0; pid = -1; - index = 0; + Reset(); } cTsPayload::cTsPayload(uchar *Data, int Length, int Pid) @@ -239,12 +243,25 @@ Setup(Data, Length, Pid); } +uchar cTsPayload::SetEof(void) +{ + length = index; // triggers EOF + return 0x00; +} + +void cTsPayload::Reset(void) +{ + index = 0; + numPacketsPid = 0; + numPacketsOther = 0; +} + void cTsPayload::Setup(uchar *Data, int Length, int Pid) { data = Data; length = Length; pid = Pid >= 0 ? Pid : TsPid(Data); - index = 0; + Reset(); } uchar cTsPayload::GetByte(void) @@ -255,20 +272,20 @@ if (data[index] == TS_SYNC_BYTE && index + TS_SIZE <= length) { // to make sure we are at a TS header start and drop incomplete TS packets at the end uchar *p = data + index; if (TsPid(p) == pid) { // only handle TS packets for the initial PID + if (numPacketsPid++ > MAX_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION) + return SetEof(); if (TsHasPayload(p)) { - if (index > 0 && TsPayloadStart(p)) { // checking index to not skip the very first TS packet - length = index; // triggers EOF - return 0x00; - } + if (index > 0 && TsPayloadStart(p)) // checking index to not skip the very first TS packet + return SetEof(); index += TsPayloadOffset(p); break; } } + else + numPacketsOther++; } - else { - length = index; // triggers EOF - return 0x00; - } + else + return SetEof(); } } return data[index++]; @@ -302,6 +319,8 @@ bool cTsPayload::Find(uint32_t Code) { int OldIndex = index; + int OldNumPacketsPid = numPacketsPid; + int OldNumPacketsOther = numPacketsOther; uint32_t Scanner = EMPTY_SCANNER; while (!Eof()) { Scanner = (Scanner << 8) | GetByte(); @@ -309,9 +328,19 @@ return true; } index = OldIndex; + numPacketsPid = OldNumPacketsPid; + numPacketsOther = OldNumPacketsOther; return false; } +void cTsPayload::Statistics(void) const +{ + if (numPacketsPid + numPacketsOther > WRN_TS_PACKETS_FOR_FRAME_DETECTOR) + dsyslog("WARNING: required (%d+%d) TS packets to determine frame type", numPacketsOther, numPacketsPid); + if (numPacketsPid > WRN_TS_PACKETS_FOR_VIDEO_FRAME_DETECTION) + dsyslog("WARNING: required %d video TS packets to determine frame type", numPacketsPid); +} + // --- cPatPmtGenerator ------------------------------------------------------ cPatPmtGenerator::cPatPmtGenerator(const cChannel *Channel) @@ -1120,6 +1149,7 @@ dbgframes("%c", FrameTypes[FrameType]); } } + tsPayload.Statistics(); break; } if (tsPayload.AtPayloadStart() // stop at any new payload start to have the buffer refilled if necessary @@ -1266,6 +1296,8 @@ case nutCodedSliceIdr: if (gotAccessUnitDelimiter && gotSequenceParameterSet) { ParseSliceHeader(); gotAccessUnitDelimiter = false; + if (newFrame) + tsPayload.Statistics(); return tsPayload.Used(); } break;