From da948a50d2318fd9c818a4b969b74555ce577b1e Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 8 Jan 2006 18:00:00 +0100 Subject: =?UTF-8?q?Version=201.3.38=20-=20Fixed=20handling=20second=20audi?= =?UTF-8?q?o=20and=20Dolby=20Digital=20PIDs=20for=20encrypted=20channels?= =?UTF-8?q?=20=20=20(was=20broken=20in=20version=201.3.37).=20-=20Improved?= =?UTF-8?q?=20TS/PES=20conversion=20to=20better=20handle=20lost=20TS=20pac?= =?UTF-8?q?kets=20(thanks=20to=20=20=20Reinhard=20Nissl).=20-=20Limited=20?= =?UTF-8?q?the=20frequency=20of=20log=20messages=20from=20the=20cRepackers?= =?UTF-8?q?.=20-=20Now=20using=20the=20gettid()=20syscall=20to=20get=20a?= =?UTF-8?q?=20thread's=20pid,=20so=20that=20we=20get=20a=20=20=20useful=20?= =?UTF-8?q?value=20on=20NPTL=20systems=20(suggested=20by=20Johannes=20Stez?= =?UTF-8?q?enbach).=20-=20Fixed=20the=20RCU=20remote=20control=20handling?= =?UTF-8?q?=20to=20avoid=20problems=20with=20NPTL=20(thanks=20=20=20to=20A?= =?UTF-8?q?ndreas=20Share=20for=20reporting=20a=20lockup=20with=20the=20RC?= =?UTF-8?q?U=20on=20NPTL=20systems).=20-=20When=20displaying=20the=20amoun?= =?UTF-8?q?t=20of=20free=20disk=20space,=20the=20space=20consumed=20by=20?= =?UTF-8?q?=20=20recordings=20that=20have=20been=20"deleted"=20but=20not?= =?UTF-8?q?=20yet=20actually=20"removed"=20is=20now=20=20=20taken=20into?= =?UTF-8?q?=20account=20(suggested=20by=20Christian=20Vogt).=20-=20Now=20a?= =?UTF-8?q?voiding=20unnecessary=20disk=20access=20when=20checking=20if=20?= =?UTF-8?q?there=20are=20deleted=20=20=20recordings=20that=20need=20to=20b?= =?UTF-8?q?e=20removed=20(reported=20by=20Carsten=20Koch).=20-=20Fixed=20h?= =?UTF-8?q?andling=20the=20DELETEDLIFETIME=20when=20removing=20deleted=20r?= =?UTF-8?q?ecordings.=20Now=20=20=20a=20deleted=20recording=20is=20retaine?= =?UTF-8?q?d=20at=20least=20DELETEDLIFETIME=20seconds=20before=20=20=20act?= =?UTF-8?q?ually=20removing=20it.=20=20=20The=20value=20of=20DELETEDLIFETI?= =?UTF-8?q?ME=20has=20been=20changed=20to=20300.=20So=20after=20(possibly?= =?UTF-8?q?=20=20=20inadvertently)=20deleting=20a=20recording,=20there=20w?= =?UTF-8?q?ill=20be=20at=20least=205=20minutes=20=20=20in=20which=20it=20c?= =?UTF-8?q?an=20be=20recovered=20(unless=20a=20new=20recording=20immediate?= =?UTF-8?q?ly=20requires=20=20=20the=20disk=20space).=20The=20count=20star?= =?UTF-8?q?ts=20again=20at=200=20every=20time=20VDR=20is=20started.=20-=20?= =?UTF-8?q?Fixed=20a=20possible=20crash=20when=20displaying=20the=20"Low?= =?UTF-8?q?=20disk=20space!"=20message=20from=20=20=20a=20background=20thr?= =?UTF-8?q?ead=20(thanks=20to=20Christof=20Steininger).=20-=20Fixed=20hand?= =?UTF-8?q?ling=20OSD=20areas=20that=20have=20invalid=20sizes=20(thanks=20?= =?UTF-8?q?to=20Marco=20Schl=C3=BC=C3=9Fler).=20-=20Added=20a=20mutex=20to?= =?UTF-8?q?=20AssertFreeDiskSpace()=20to=20make=20sure=20calls=20from=20fo?= =?UTF-8?q?reground=20=20=20and=20background=20threads=20won't=20interfere?= =?UTF-8?q?.=20-=20The=20main=20menu=20now=20dynamically=20updates=20its?= =?UTF-8?q?=20contents=20in=20case=20an=20instant=20=20=20recording=20or?= =?UTF-8?q?=20replay=20stops,=20etc.=20-=20The=20version=20number=20of=20E?= =?UTF-8?q?PG=20events=20is=20now=20also=20stored=20in=20the=20epg.data=20?= =?UTF-8?q?file=20=20=20(thanks=20to=20Kendy=20Kutzner).=20-=20EPG=20event?= =?UTF-8?q?s=20that=20are=20no=20longer=20in=20the=20currently=20broadcast?= =?UTF-8?q?ed=20data=20stream=20are=20=20=20now=20automatically=20deleted.?= =?UTF-8?q?=20-=20Removed=20an=20invalid=20access=20to=20Event->schedule?= =?UTF-8?q?=20in=20cSchedule::DelEvent().=20-=20Modified=20cSchedule::Clea?= =?UTF-8?q?nup()=20(events=20are=20always=20sorted=20by=20time).=20-=20Sch?= =?UTF-8?q?edules=20are=20now=20cleaned=20up=20once=20every=20hour=20(not?= =?UTF-8?q?=20only=20at=2005:00).=20-=20The=20"Schedule"=20and=20"What's?= =?UTF-8?q?=20on=20now/next=3F"=20menus=20are=20now=20updated=20if=20a=20t?= =?UTF-8?q?imer=20=20=20is=20set=20or=20modified.=20-=20cTimer=20no=20long?= =?UTF-8?q?er=20has=20its=20own=20'schedule'=20member,=20it=20rather=20use?= =?UTF-8?q?s=20that=20of=20the=20=20=20event=20it=20has=20been=20set=20to.?= =?UTF-8?q?=20-=20The=20"Red"=20button=20in=20the=20"Schedule",=20"What's?= =?UTF-8?q?=20on=20now/next=3F"=20and=20"Event"=20menus=20=20=20now=20imme?= =?UTF-8?q?diately=20creates=20a=20timer=20for=20the=20selected=20event=20?= =?UTF-8?q?and=20marks=20it=20with=20'T'.=20=20=20If=20the=20event=20is=20?= =?UTF-8?q?already=20marked=20with=20'T',=20the=20"Red"=20button=20opens?= =?UTF-8?q?=20the=20"Edit=20=20=20timer"=20menu=20for=20that=20timer.=20-?= =?UTF-8?q?=20Removing=20deleted=20recordings=20is=20now=20done=20in=20a?= =?UTF-8?q?=20separate=20thread.=20-=20Dropped=20the=20unused=20"stop=20re?= =?UTF-8?q?cording=20on=20primary=20interface"=20stuff.=20-=20Converting?= =?UTF-8?q?=20a=20grabbed=20image=20to=20JPEG=20is=20now=20done=20with=20t?= =?UTF-8?q?he=20new=20function=20=20=20RgbToJpeg()=20(see=20tools.h).=20-?= =?UTF-8?q?=20The=20SVDRP=20command=20GRAB=20now=20determines=20the=20imag?= =?UTF-8?q?e=20type=20(JPEG=20or=20PNM)=20from=20the=20=20=20extension=20(?= =?UTF-8?q?".jpg",=20".jpeg"=20or=20".pnm")=20of=20the=20given=20file=20na?= =?UTF-8?q?me.=20The=20explicit=20=20=20'jpeg'=20or=20'pnm'=20parameter=20?= =?UTF-8?q?is=20still=20accepted=20for=20backward=20compatibility,=20but?= =?UTF-8?q?=20=20=20has=20no=20meaning=20any=20more.=20-=20The=20function?= =?UTF-8?q?=20cDevice::GrabImage()=20no=20longer=20writes=20the=20grabbed?= =?UTF-8?q?=20image=20to=20a=20=20=20file,=20but=20rather=20returns=20a=20?= =?UTF-8?q?pointer=20to=20the=20image=20in=20memory.=20The=20wrapper=20=20?= =?UTF-8?q?=20function=20cDevice::GrabImageFile()=20can=20be=20used=20to?= =?UTF-8?q?=20write=20the=20grabbed=20image=20=20=20directly=20to=20a=20fi?= =?UTF-8?q?le.=20Plugins=20that=20used=20the=20old=20version=20of=20cDevic?= =?UTF-8?q?e::GrabImage()=20=20=20need=20to=20be=20adapted=20to=20the=20ne?= =?UTF-8?q?w=20interface.=20-=20The=20new=20class=20cBase64Encoder=20(see?= =?UTF-8?q?=20tools.h)=20can=20be=20used=20to=20encode=20data=20in=20=20?= =?UTF-8?q?=20base64=20(thanks=20to=20Bob=20Withers=20for=20publishing=20h?= =?UTF-8?q?is=20Base64=20class).=20-=20The=20SVDRP=20command=20GRAB=20now?= =?UTF-8?q?=20writes=20the=20image=20data=20to=20the=20SVDRP=20connection?= =?UTF-8?q?=20=20=20(encoded=20in=20base64)=20if=20the=20given=20file=20na?= =?UTF-8?q?me=20consists=20of=20only=20the=20file=20=20=20extension=20(".j?= =?UTF-8?q?pg",=20".jpeg"=20or=20".pnm"),=20or=20if=20only=20"-"=20is=20gi?= =?UTF-8?q?ven=20as=20file=20=20=20name=20(based=20on=20a=20suggestion=20f?= =?UTF-8?q?rom=20Darren=20Salt).=20=20=20A=20simple=20way=20of=20viewing?= =?UTF-8?q?=20a=20grabbed=20image=20on=20a=20remote=20host=20is:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svdrpsend.pl -d 'grab -' | sed -n -e 's/^216-//p' -e '1ibegin-base64 644 -' -e '$a====' | uudecode | display - - The new command line option '-g' must be given if the SVDRP command GRAB shall be allowed to write image files to disk. The parameter to this option must be the full path name of an existing directory, without any "..", double '/' or symlinks. By default, or if "-g- is given, grabbing to files is not allowed any more because of potential security risks. - Modified the way the SVDRP command GRAB writes the grabbed image to a file to avoid a security hole (CAN-2005-0071, reported by Javier Fernández-Sanguino Peña): + The file handle is now opened in a way that it won't follow symbolic links (suggested by Darren Salt). + The given file name is now canonicalized, so that it won't contain any ".." or symlinks (suggested by Darren Salt). + Grabbing to files is limited to the directory given in the the command line option '-g'. By default grabbing to files is not allowed any more. - Updated the Greek OSD texts (thanks to Dimitrios Dimitrakos). - Changed all "illegal" to "invalid" in error messages (there's nothing "illegal" in VDR ;-). - When started as user 'root' VDR now switches to a lesser privileged user id, keeping the capability to set the system time (based on a patch from Ludwig Nussel). By default the user id 'vdr' is used, which can be changed through the new command line option '-u'. Note that for security reasons VDR will no longer run as user 'root' (unless you explicitly start it with '-u root', but this is not recommended!). The 'runvdr' script has been changed to use the '-u' option. - Changed the API of the functions cStatus::Recording() and cStatus::Replaying(), so that they can provide the full file name of the recording. Plugins that use these (or the related cStatus::Msg...() functions) need to be adapted (suggested by Andreas Brugger). - The DVB devices now retune (and, if applicable, resend the DiSEqC data) if the lock is lost (based on a patch from Reinhard Nissl). - Fixed handling multi byte key sequences in cKbdRemote (based on a patch from Jürgen Schneider). - Removed unused variables in skinclassic.c and skinsttng.c (thanks to Marco Schlüßler). - Made the static cControl functions thread safe (thanks to Patrick Fischer). - Fixed initializing pthread_mutexattr_t and pthread_rwlockattr_t to avoid warnings with g++ 4.1.0 (thanks to Ville Skyttä). - Fixed incrementing the 'state' variables in the repacker classes in remux.c to avoid warnings with g++ 4.1.0 (reported by Ville Skyttä). - The Makefile now reports a summary of failed plugins (thanks to Udo Richter). - The cTimer constructor can now take an optional cChannel (suggested by Patrick Fischer). - Fixed setting the main thread id if VDR is running as a daemon. - Fixed handling TS packets in cTS2PES (thanks to Reinhard Nissl). - Added cTimer::SetPriority() to set a timer's priority (suggested by Kendy Kutzner). - Added cMenuEditStrItem::InEditMode() (suggested by Christian Wieninger). - Now using FE_READ_STATUS to read the current frontend status (suggested by Holger Wächtler). - The "Menu" key now behaves consistently. If there is anything on the OSD, it is closed when the "Menu" key is pressed, and if there is nothing on the OSD, the "Menu" key opens the main menu (suggested by Luca Olivetti). - The new option "Setup/OSD/Timeout requested channel info" can be used to turn off the automatic timeout of the channel display in case it was invoked by a press of the "Ok" key (suggested by Thiemo Gehrke). - A message is now given when an instant recording is started (suggested by Helmut Auer). Actually the code was already there, just commented out - don't remember why it wasn't active... - Removed an obsolete "Summary" text from i18n.c and preceded all key definition texts with "Key$" to avoid duplicates (reported by Lucian Muresan). - Preceded all button texts with "Button$". - Removed obsolete "Eject", "Language" and "scanning recordings..." texts. - Added missing #include "thread.h" to dvbspu.c (reported by Gavin Hamill). - Disabled the use of "fadvise" in cUnbufferedFile because there have been several reports that it causes more problems than it solves (suggested by Petri Hintukainen). If you want to use "fadvise", you can activate the line //#define USE_FADVISE in tools.c. - Removed unused 'offset' member from cOsdItem. - In the "Channels" menu the numeric keys now position the cursor to the channel with the given number (see MANUAL, section "Remote Control Keys", note (3) for details). - The "Mark/Move" function in the "Channels" menu now also works in the non-numeric sort modes. - The default cOsdObject::Show() now automatically calls cOsdMenu::Display() if this is a menu. - The new "Info" key brings up information on the currently viewed programme or recording. For a live programme this is the same as "Schedule/Ok", i.e. the description of the current EPG event. For a recording this is the same as shown by the "Info" button in the "Recordings" menu. Plugins that implement players can overwrite their cControl::GetInfo() function to show their own info (see PLUGINS.html for details). Pressing the "Info" key again while the info is displayed will close the OSD. In order to assign this new key to an existing remote control setup, the remote.conf file needs to be deleted and VDR has to be restarted to go through the process of learning the remote control keys. - Any cReceivers still attached to a cDevice when that device switches to a different transponder are now automatically detached (suggested by Patrick Fischer). - The "flags" of a timer are now handled as an unsigned integer value. In order to do this, the interface of cMenuEditBitItem also had to be changed. - In string entry fields (like, e.g., the file name of a recording) the characters can now be entered by pressing the numeric keys, the same way as on a telephone keypad (based on the "Easy Input" patch from Marcel Schaeben). - Fixed the "Day" field of the "Edit timer" menu when pressing '0' to switch from "single shot" to "weekly", followed by the "Right" key (reported by Andreas Böttger). - The file 'ca.conf' is obsolete and has been removed. - Revised all descriptions regarding CICAM. - Adapted c(Dvb)Device::ProvidesCa() to the dynamic CA handling. - Added a mutex to synchronize cDevice::PlayPesPacket() and SetCurrentAudioTrack() (thanks to Reinhard Nissl). - Added a SleepMs() in cRecorder::Action() to avoid a busy loop (thanks to Ingo Schneider). - Cleaned up some trailing white space. --- remux.c | 105 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 32 deletions(-) (limited to 'remux.c') diff --git a/remux.c b/remux.c index e9997a5..c48e5f9 100644 --- a/remux.c +++ b/remux.c @@ -11,7 +11,7 @@ * The cRepacker family's code was originally written by Reinhard Nissl , * and adapted to the VDR coding style by Klaus.Schmidinger@cadsoft.de. * - * $Id: remux.c 1.47 2005/09/11 13:26:50 kls Exp $ + * $Id: remux.c 1.53 2006/01/08 11:40:16 kls Exp $ */ #include "remux.h" @@ -88,15 +88,21 @@ ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, // --- cRepacker ------------------------------------------------------------- +#define MIN_LOG_INTERVAL 10 // min. # of seconds between two consecutive log messages of a cRepacker +#define LOG(a...) (LogAllowed() && (esyslog(a), true)) + class cRepacker { protected: bool initiallySyncing; int maxPacketSize; uint8_t subStreamId; - static void DroppedData(const char *Reason, int Count) { esyslog("%s (dropped %d bytes)", Reason, Count); } + time_t lastLog; + int suppressedLogMessages; + bool LogAllowed(void); + void DroppedData(const char *Reason, int Count) { LOG("%s (dropped %d bytes)", Reason, Count); } public: static int Put(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count, int CapacityNeeded); - cRepacker(void) { initiallySyncing = true; maxPacketSize = 6 + 65535; subStreamId = 0; } + cRepacker(void); virtual ~cRepacker() {} virtual void Reset(void) { initiallySyncing = true; } virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count) = 0; @@ -106,6 +112,30 @@ public: void SetSubStreamId(uint8_t SubStreamId) { subStreamId = SubStreamId; } }; +cRepacker::cRepacker(void) +{ + initiallySyncing = true; + maxPacketSize = 6 + 65535; + subStreamId = 0; + suppressedLogMessages = 0;; + lastLog = 0; +} + +bool cRepacker::LogAllowed(void) +{ + bool Allowed = time(NULL) - lastLog >= MIN_LOG_INTERVAL; + lastLog = time(NULL); + if (Allowed) { + if (suppressedLogMessages) { + esyslog("%d cRepacker messages suppressed", suppressedLogMessages); + suppressedLogMessages = 0; + } + } + else + suppressedLogMessages++; + return Allowed; +} + int cRepacker::Put(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count, int CapacityNeeded) { if (CapacityNeeded >= Count && ResultBuffer->Free() < CapacityNeeded) { @@ -160,7 +190,7 @@ bool cCommonRepacker::PushOutPacket(cRingBufferLinear *ResultBuffer, const uchar // just skip packets with no payload int PesPayloadOffset = 0; if (AnalyzePesHeader(fragmentData, fragmentLen, PesPayloadOffset) <= phInvalid) - esyslog("cCommonRepacker: invalid PES packet encountered in fragment buffer!"); + LOG("cCommonRepacker: invalid PES packet encountered in fragment buffer!"); else if (6 + PacketLen <= PesPayloadOffset) { fragmentLen = 0; return true; // skip empty packet @@ -181,7 +211,7 @@ bool cCommonRepacker::PushOutPacket(cRingBufferLinear *ResultBuffer, const uchar // just skip packets with no payload int PesPayloadOffset = 0; if (AnalyzePesHeader(pesHeader, pesHeaderLen, PesPayloadOffset) <= phInvalid) - esyslog("cCommonRepacker: invalid PES packet encountered in header buffer!"); + LOG("cCommonRepacker: invalid PES packet encountered in header buffer!"); else if (6 + PacketLen <= PesPayloadOffset) { pesHeaderLen = 0; return true; // skip empty packet @@ -216,7 +246,8 @@ private: syncing, findPicture, scanPicture - } state; + }; + int state; public: cVideoRepacker(void); virtual void Reset(void); @@ -278,14 +309,14 @@ void cVideoRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, // which kind of start code have we got? switch (*data) { case 0xB9 ... 0xFF: // system start codes - esyslog("cVideoRepacker: found system start code: stream seems to be scrambled or not demultiplexed"); + LOG("cVideoRepacker: found system start code: stream seems to be scrambled or not demultiplexed"); break; case 0xB0 ... 0xB1: // reserved start codes case 0xB6: - esyslog("cVideoRepacker: found reserved start code: stream seems to be scrambled"); + LOG("cVideoRepacker: found reserved start code: stream seems to be scrambled"); break; case 0xB4: // sequence error code - isyslog("cVideoRepacker: found sequence error code: stream seems to be damaged"); + LOG("cVideoRepacker: found sequence error code: stream seems to be damaged"); case 0xB2: // user data start code case 0xB5: // extension start code break; @@ -307,7 +338,7 @@ void cVideoRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, if (initiallySyncing) // omit report for the typical initial case initiallySyncing = false; else if (skippedBytes > SkippedBytesLimit) // report that syncing dropped some bytes - esyslog("cVideoRepacker: skipped %d bytes to sync on next picture", skippedBytes - SkippedBytesLimit); + LOG("cVideoRepacker: skipped %d bytes to sync on next picture", skippedBytes - SkippedBytesLimit); skippedBytes = 0; // if there is a PES header available, then use it ... if (pesHeaderBackupLen > 0) { @@ -350,13 +381,13 @@ void cVideoRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, // maximum we can hold in one PES packet packetTodo = maxPacketSize - pesHeaderLen; // go on with finding the picture data - ((int &)state)++; + state++; } break; case 0x01 ... 0xAF: // slice start codes if (state == findPicture) { // go on with scanning the picture data - ((int &)state)++; + state++; } break; } @@ -465,7 +496,7 @@ void cVideoRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, // report that syncing dropped some bytes if (skippedBytes > SkippedBytesLimit) { if (!initiallySyncing) // omit report for the typical initial case - esyslog("cVideoRepacker: skipped %d bytes while syncing on next picture", skippedBytes - SkippedBytesLimit); + LOG("cVideoRepacker: skipped %d bytes while syncing on next picture", skippedBytes - SkippedBytesLimit); skippedBytes = SkippedBytesLimit; } } @@ -517,7 +548,8 @@ private: enum eState { syncing, scanFrame - } state; + }; + int state; int frameTodo; int frameSize; int cid; @@ -674,7 +706,7 @@ void cAudioRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, if (initiallySyncing) // omit report for the typical initial case initiallySyncing = false; else if (skippedBytes > SkippedBytesLimit) // report that syncing dropped some bytes - esyslog("cAudioRepacker(0x%02X): skipped %d bytes to sync on next audio frame", cid, skippedBytes - SkippedBytesLimit); + LOG("cAudioRepacker(0x%02X): skipped %d bytes to sync on next audio frame", cid, skippedBytes - SkippedBytesLimit); skippedBytes = 0; // if there is a PES header available, then use it ... if (pesHeaderBackupLen > 0) { @@ -714,10 +746,10 @@ void cAudioRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, payload = data; // maximum we can hold in one PES packet packetTodo = maxPacketSize - pesHeaderLen; - // expected remainder of audio frame: so far we have read 3 bytes from the frame header + // expected remainder of audio frame: so far we have read 3 bytes from the frame header frameTodo = frameSize - 3; // go on with collecting the frame's data - ((int &)state)++; + state++; } } } @@ -832,7 +864,7 @@ void cAudioRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, // report that syncing dropped some bytes if (skippedBytes > SkippedBytesLimit) { if (!initiallySyncing) // omit report for the typical initial case - esyslog("cAudioRepacker(0x%02X): skipped %d bytes while syncing on next audio frame", cid, skippedBytes - SkippedBytesLimit); + LOG("cAudioRepacker(0x%02X): skipped %d bytes while syncing on next audio frame", cid, skippedBytes - SkippedBytesLimit); skippedBytes = SkippedBytesLimit; } } @@ -898,14 +930,15 @@ private: uchar chk1; uchar chk2; int ac3todo; - enum { + enum eState { find_0b, find_77, store_chk1, store_chk2, get_length, output_packet - } state; + }; + int state; int skippedBytes; void ResetPesHeader(bool ContinuationFrame = false); void AppendSubStreamID(bool ContinuationFrame = false); @@ -1090,7 +1123,7 @@ void cDolbyRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, switch (state) { case find_0b: if (*data == 0x0B) { - ++(int &)state; + state++; // copy header information once for later use if (pesHeaderBackupLen > 0) { pesHeaderLen = pesHeaderBackupLen; @@ -1113,21 +1146,21 @@ void cDolbyRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, done++; todo--; skippedBytes++; // collect number of skipped bytes while syncing - ++(int &)state; + state++; continue; case store_chk1: chk1 = *data++; done++; todo--; skippedBytes++; // collect number of skipped bytes while syncing - ++(int &)state; + state++; continue; case store_chk2: chk2 = *data++; done++; todo--; skippedBytes++; // collect number of skipped bytes while syncing - ++(int &)state; + state++; continue; case get_length: ac3todo = 2 * frameSizes[*data]; @@ -1157,7 +1190,7 @@ void cDolbyRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, if (initiallySyncing) // omit report for the typical initial case initiallySyncing = false; else if (skippedBytes > SkippedBytesLimit) // report that syncing dropped some bytes - esyslog("cDolbyRepacker: skipped %d bytes to sync on next AC3 frame", skippedBytes - SkippedBytesLimit); + LOG("cDolbyRepacker: skipped %d bytes to sync on next AC3 frame", skippedBytes - SkippedBytesLimit); skippedBytes = 0; // append read data to header for common output processing pesHeader[pesHeaderLen++] = 0x0B; @@ -1165,7 +1198,7 @@ void cDolbyRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, pesHeader[pesHeaderLen++] = chk1; pesHeader[pesHeaderLen++] = chk2; ac3todo -= 4; - ++(int &)state; + state++; // fall through to output case output_packet: { int bite = 0; @@ -1188,7 +1221,7 @@ void cDolbyRepacker::Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, // report that syncing dropped some bytes if (skippedBytes > SkippedBytesLimit) { if (!initiallySyncing) // omit report for the typical initial case - esyslog("cDolbyRepacker: skipped %d bytes while syncing on next AC3 frame", skippedBytes - 4); + LOG("cDolbyRepacker: skipped %d bytes while syncing on next AC3 frame", skippedBytes - 4); skippedBytes = SkippedBytesLimit; } } @@ -1248,9 +1281,10 @@ int cDolbyRepacker::BreakAt(const uchar *Data, int Count) #define CONT_CNT_MASK 0x0F // Flags: +#define PAY_LOAD 0x10 +#define ADAPT_FIELD 0x20 #define PAY_START 0x40 #define TS_ERROR 0x80 -#define ADAPT_FIELD 0x20 #define MAX_PLENGTH 0xFFFF // the maximum PES packet length (theoretically) #define MMAX_PLENGTH (64*MAX_PLENGTH) // some stations send PES packets that are extremely large, e.g. DVB-T in Finland or HDTV 1920x1080 @@ -1635,7 +1669,11 @@ void cTS2PES::ts_to_pes(const uint8_t *Buf) // don't need count (=188) if (Buf[1] & TS_ERROR) tsErrors++; - if ((Buf[3] ^ ccCounter) & CONT_CNT_MASK) { + + if (!(Buf[3] & (ADAPT_FIELD | PAY_LOAD))) + return; // discard TS packet with adaption_field_control set to '00'. + + if ((Buf[3] & PAY_LOAD) && ((Buf[3] ^ ccCounter) & CONT_CNT_MASK)) { // This should check duplicates and packets which do not increase the counter. // But as the errors usually come in bursts this should be enough to // show you there is something wrong with signal quality. @@ -1650,12 +1688,14 @@ void cTS2PES::ts_to_pes(const uint8_t *Buf) // don't need count (=188) } if (Buf[1] & PAY_START) { - if (plength == MMAX_PLENGTH - 6 && found > 6) { + if (found > 6) { + if (plength != MMAX_PLENGTH - 6 && plength != found - 6) + dsyslog("PES packet shortened to %d bytes (expected: %d bytes)", found, plength + 6); plength = found - 6; - found = 0; send_ipack(); reset_ipack(); } + found = 0; } uint8_t off = 0; @@ -1666,7 +1706,8 @@ void cTS2PES::ts_to_pes(const uint8_t *Buf) // don't need count (=188) return; } - instant_repack(Buf + 4 + off, TS_SIZE - 4 - off); + if (Buf[3] & PAY_LOAD) + instant_repack(Buf + 4 + off, TS_SIZE - 4 - off); } // --- cRemux ---------------------------------------------------------------- -- cgit v1.2.3