summaryrefslogtreecommitdiff
path: root/command
diff options
context:
space:
mode:
Diffstat (limited to 'command')
-rw-r--r--command/demux.cpp36
-rw-r--r--command/demux.h1
-rw-r--r--command/markad-standalone.cpp85
-rw-r--r--command/markad-standalone.h3
-rw-r--r--command/pes2es.cpp14
-rw-r--r--command/queue.h2
-rw-r--r--command/ts2pkt.cpp3
-rw-r--r--command/video.cpp2
8 files changed, 67 insertions, 79 deletions
diff --git a/command/demux.cpp b/command/demux.cpp
index 752b300..a5b4ed7 100644
--- a/command/demux.cpp
+++ b/command/demux.cpp
@@ -41,36 +41,6 @@ void cMarkAdDemux::Clear()
skip=0;
}
-void cMarkAdDemux::GetVideoPTS(uchar *Data, int Count, unsigned int *Timestamp)
-{
- if (!Data) return;
- if (Count<=0) return;
- if (!Timestamp) return;
- struct PESHDR *peshdr=(struct PESHDR *) Data;
-
- if ((peshdr->Sync1!=0) && (peshdr->Sync2!=0) && (peshdr->Sync3!=1)) return;
- if ((peshdr->StreamID & 0xF0)!=0xE0) return;
-
- struct PESHDROPT *peshdropt=(struct PESHDROPT *) &Data[sizeof(struct PESHDR)];
- if (peshdropt->MarkerBits!=0x2) return;
-
- if (peshdropt->PTSDTS<2) return;
-
- struct PESHDROPTPTS *peshdroptpts=(struct PESHDROPTPTS *) &Data[sizeof(struct PESHDR)+
- sizeof(struct PESHDROPT)];
-
- if (peshdroptpts->Marker1 && peshdroptpts->Marker2 &&
- peshdroptpts->Marker3)
-{
- unsigned int pts=0;
- pts|=((peshdroptpts->PTS29_15_H<<7|peshdroptpts->PTS29_15_L)<<15);
- pts|=(peshdroptpts->PTS14_0_H<<7|peshdroptpts->PTS14_0_L);
- pts|=(peshdroptpts->PTS32_30<<30);
- *Timestamp=pts;
- }
- return;
-}
-
void cMarkAdDemux::ProcessVDR(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket *Pkt)
{
if (!Pkt) return;
@@ -149,7 +119,6 @@ void cMarkAdDemux::ProcessTS(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket
if ((Pid.Type==MARKAD_PIDTYPE_VIDEO_H262) || (Pid.Type==MARKAD_PIDTYPE_VIDEO_H264))
{
- GetVideoPTS(pkt.Data,pkt.Length,&Pkt->Timestamp);
if ((pkt.Data) && ((pkt.Data[3] & 0xF0)==0xE0) && (pkt.Data[4]!=0) && (pkt.Data[5]!=0))
{
ts2pkt->InjectVideoPES(pkt.Data,pkt.Length);
@@ -158,6 +127,7 @@ void cMarkAdDemux::ProcessTS(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket
}
Pkt->Data=pkt.Data;
Pkt->Length=pkt.Length;
+ Pkt->Skipped=pkt.Skipped;
}
return;
}
@@ -207,6 +177,8 @@ int cMarkAdDemux::GetMinNeeded(MarkAdPid Pid, uchar *Data, int Count, bool *Offc
}
else
{
+ queue->Clear();
+ if (Offcnt) *Offcnt=true;
return -1; // skip one byte (maybe we get another header!)
}
}
@@ -223,6 +195,7 @@ int cMarkAdDemux::Process(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket *P
{
Pkt->Data=NULL;
Pkt->Length=0;
+ Pkt->Skipped=0;
Pkt->Offcnt=false;
if (!min_needed)
@@ -247,6 +220,7 @@ int cMarkAdDemux::Process(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket *P
skip=-t_min_needed-Count;
return Count;
}
+ if (t_min_needed==-1) Pkt->Skipped++;
return -t_min_needed;
}
min_needed=t_min_needed;
diff --git a/command/demux.h b/command/demux.h
index 489528b..9313912 100644
--- a/command/demux.h
+++ b/command/demux.h
@@ -32,7 +32,6 @@ private:
int min_needed;
int skip;
- void GetVideoPTS(uchar *Data, int Count, unsigned int *Timestamp);
int GetMinNeeded(MarkAdPid Pid, uchar *Data, int Count, bool *Offcnt);
void ProcessTS(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket *pkt);
void ProcessVDR(MarkAdPid Pid, uchar *Data, int Count, MarkAdPacket *pkt);
diff --git a/command/markad-standalone.cpp b/command/markad-standalone.cpp
index e361306..43ea333 100644
--- a/command/markad-standalone.cpp
+++ b/command/markad-standalone.cpp
@@ -33,6 +33,7 @@
extern int sys_ioprio_set(int which, int who, int ioprio);
bool SYSLOG=false;
+bool LOG2REC=false;
cMarkAdStandalone *cmasta=NULL;
int SysLogLevel=2;
@@ -59,7 +60,7 @@ static inline int ioprio_set(int which, int who, int ioprio)
void syslog_with_tid(int priority, const char *format, ...)
{
va_list ap;
- if (SYSLOG)
+ if ((SYSLOG) && (!LOG2REC))
{
char fmt[255];
snprintf(fmt, sizeof(fmt), "[%d] %s", getpid(), format);
@@ -1334,6 +1335,10 @@ bool cMarkAdStandalone::ProcessFile(int Number)
}
}
}
+ if (vpkt.Skipped)
+ {
+ errcnt+=vpkt.Skipped;
+ }
tspkt+=len;
tslen-=len;
if (!vpkt.Offcnt)
@@ -1589,6 +1594,17 @@ void cMarkAdStandalone::Process()
if (macontext.Config->GenIndex) marks.RemoveGeneratedIndex(directory,isTS);
}
+bool cMarkAdStandalone::SetFileUID(char *File)
+{
+ if (!File) return false;
+ struct stat statbuf;
+ if (!stat(directory,&statbuf))
+ {
+ if (chown(File,statbuf.st_uid, statbuf.st_gid)==-1) return false;
+ }
+ return true;
+}
+
bool cMarkAdStandalone::SaveInfo()
{
if ((!setVideo43) && (!setVideo169) && (!setAudio20) && (!setAudio51) && (!setVideo43LB) &&
@@ -1772,21 +1788,7 @@ bool cMarkAdStandalone::SaveInfo()
oldtimes.actime=statbuf_r.st_atime;
oldtimes.modtime=statbuf_r.st_mtime;
if (utime(src,&oldtimes)) {};
- }
- }
-
- if ((getuid()==0 || geteuid()!=0) && (!err))
- {
- // if we are root, set fileowner to owner of 001.vdr/00001.ts file
- char *spath=NULL;
- if (asprintf(&spath,"%s/%s",directory,isTS ? "00001.ts" : "001.vdr")!=-1)
- {
- struct stat statbuf;
- if (!stat(spath,&statbuf))
- {
- if (chown(src,statbuf.st_uid, statbuf.st_gid)) {};
- }
- free(spath);
+ SetFileUID(src);
}
}
@@ -2324,15 +2326,7 @@ bool cMarkAdStandalone::CreatePidfile()
FILE *pidfile=fopen(buf,"w+");
- if (getuid()==0 || geteuid()!=0)
- {
- // if we are root, set fileowner to owner of directory
- struct stat statbuf;
- if (!stat(directory,&statbuf))
- {
- if (chown(buf,statbuf.st_uid, statbuf.st_gid)) {};
- }
- }
+ SetFileUID(buf);
free(buf);
if (!pidfile) return false;
@@ -2390,6 +2384,8 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, const MarkAdConfig *
noticeHEADER=false;
noticeFILLER=false;
+ errcnt=0;
+
sleepcnt=0;
waittime=iwaittime=0;
duplicate=false;
@@ -2604,6 +2600,11 @@ cMarkAdStandalone::~cMarkAdStandalone()
{
if ((!abort) && (!duplicate))
{
+ if (errcnt>20)
+ {
+ isyslog("skipped %i bytes in video stream",errcnt);
+ }
+
gettimeofday(&tv2,&tz);
time_t sec;
suseconds_t usec;
@@ -2706,6 +2707,8 @@ int usage(int svdrpport)
" [height] range from 20 to %3i, default %3i\n"
"-O --OSD\n"
" markad sends an OSD-Message for start and end\n"
+ "-R --log2rec\n"
+ " write logfiles into recording directory\n"
"-T --threads=<number>\n"
" number of threads used for decoding, max. 16\n"
" (default is the number of cpus)\n"
@@ -2866,6 +2869,7 @@ int main(int argc, char *argv[])
{"genindex",0, 0, 'G'},
{"extractlogo", 1, 0, 'L'},
{"OSD",0,0,'O' },
+ {"log2rec",0,0,'R'},
{"savelogo", 0, 0, 'S'},
{"threads", 1, 0, 'T'},
{"version", 0, 0, 'V'},
@@ -2873,7 +2877,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, "abcd:i:jl:nop:r:s:vBCGL:OST:V",
+ c = getopt_long (argc, argv, "abcd:i:jl:nop:r:s:vBCGL:ORST:V",
long_options, &option_index);
if (c == -1)
break;
@@ -3050,6 +3054,11 @@ int main(int argc, char *argv[])
config.OSD=true;
break;
+ case 'R':
+ // --log2rec
+ LOG2REC=true;
+ break;
+
case 'S':
// --savelogo
break;
@@ -3208,18 +3217,15 @@ int main(int argc, char *argv[])
{
char *err=strerror(errno);
fprintf(stderr, "%s\n",err);
- esyslog("fork ERROR: %s",err);
return 2;
}
if (pid != 0)
{
- tsyslog("forked to pid %d",pid);
return 0; // initial program immediately returns
}
}
if ( bFork )
{
- tsyslog("(forked) pid %d", getpid());
if (chdir("/")==-1)
{
perror("chdir");
@@ -3286,11 +3292,11 @@ int main(int argc, char *argv[])
{
if (setpriority(PRIO_PROCESS,0,niceLevel)==-1)
{
- esyslog("failed to set nice to %d",niceLevel);
+ fprintf(stderr,"failed to set nice to %d",niceLevel);
}
if (ioprio_set(1,getpid(),ioprio | ioprio_class << 13)==-1)
{
- esyslog("failed to set ioprio to %i,%i",ioprio_class,ioprio);
+ fprintf(stderr,"failed to set ioprio to %i,%i",ioprio_class,ioprio);
}
}
@@ -3308,6 +3314,12 @@ int main(int argc, char *argv[])
return -1;
}
+ if (access(recDir,W_OK|R_OK)==-1)
+ {
+ fprintf(stderr,"cannot access %s\n",recDir);
+ return -1;
+ }
+
// ignore some signals
signal(SIGHUP, SIG_IGN);
@@ -3320,6 +3332,17 @@ int main(int argc, char *argv[])
signal(SIGTSTP, signal_handler);
signal(SIGCONT, signal_handler);
+ if (LOG2REC)
+ {
+ char *fbuf;
+ if (asprintf(&fbuf,"%s/markad.log",recDir)!=-1)
+ {
+ if (freopen(fbuf,"w+",stdout)) {};
+ if (chown(fbuf,statbuf.st_uid, statbuf.st_gid)) {};
+ free(fbuf);
+ }
+ }
+
cmasta = new cMarkAdStandalone(recDir,&config);
if (!cmasta) return -1;
diff --git a/command/markad-standalone.h b/command/markad-standalone.h
index 25d19bb..412530a 100644
--- a/command/markad-standalone.h
+++ b/command/markad-standalone.h
@@ -214,6 +214,8 @@ unsigned Descriptor_Length:
int iStop; // posttimer as index value
int iStopCheck; // check position for iStop
+ int errcnt; // Skipped bytes in stream
+
bool setAudio51; // set audio to 5.1 in info
bool setAudio20; // set audio to 2.0 in info
bool setVideo43; // set video to 4:3 in info
@@ -255,6 +257,7 @@ unsigned Descriptor_Length:
bool CheckTS();
bool LoadInfo();
bool SaveInfo();
+ bool SetFileUID(char *File);
bool RegenerateIndex();
bool ProcessFile2ndPass(clMark **Mark1, clMark **Mark2, int Number, off_t Offset, int Frame, int Frames);
bool ProcessFile(int Number);
diff --git a/command/pes2es.cpp b/command/pes2es.cpp
index 4c74e5f..c78afd6 100644
--- a/command/pes2es.cpp
+++ b/command/pes2es.cpp
@@ -88,20 +88,6 @@ void cMarkAdPES2ES::Process(MarkAdPid Pid, uchar *PESData, int PESSize, MarkAdPa
peshdropt->Length;
buf=&PESData[bpos];
buflen=PESSize-bpos;
- if (peshdropt->PTSDTS>1)
- {
- struct PESHDROPTPTS *peshdroptpts=(struct PESHDROPTPTS *) &PESData[sizeof(struct PESHDR)+
- sizeof(struct PESHDROPT)];
-
- if (peshdroptpts->Marker1 && peshdroptpts->Marker2 && peshdroptpts->Marker3)
- {
- unsigned int pts=0;
- pts|=((peshdroptpts->PTS29_15_H<<7|peshdroptpts->PTS29_15_L)<<15);
- pts|=(peshdroptpts->PTS14_0_H<<7|peshdroptpts->PTS14_0_L);
- pts|=(peshdroptpts->PTS32_30<<30);
- ESPkt->Timestamp=pts;
- }
- }
}
else
{
diff --git a/command/queue.h b/command/queue.h
index 855355b..4efd197 100644
--- a/command/queue.h
+++ b/command/queue.h
@@ -18,7 +18,7 @@ typedef struct MarkAdPacket
{
uchar *Data;
int Length;
- unsigned int Timestamp;
+ int Skipped;
bool Offcnt;
} MarkAdPacket;
diff --git a/command/ts2pkt.cpp b/command/ts2pkt.cpp
index 3fbfa75..c3bbd15 100644
--- a/command/ts2pkt.cpp
+++ b/command/ts2pkt.cpp
@@ -128,6 +128,7 @@ bool cMarkAdTS2Pkt::Process(MarkAdPid Pid, uchar *TSData, int TSSize, MarkAdPack
{
if (counter==(int) tshdr->Counter)
{
+ Pkt->Skipped+=TS_SIZE;
return true; // duplicate paket -> just ignore
}
// sequence error
@@ -142,6 +143,7 @@ bool cMarkAdTS2Pkt::Process(MarkAdPid Pid, uchar *TSData, int TSSize, MarkAdPack
}
if (!sync)
{
+ Pkt->Skipped+=TS_SIZE;
return false; // not synced
}
@@ -195,6 +197,7 @@ bool cMarkAdTS2Pkt::Process(MarkAdPid Pid, uchar *TSData, int TSSize, MarkAdPack
{
if ((buf[0]!=0) && (buf[1]!=0))
{
+ Pkt->Skipped+=TS_SIZE;
sync=false;
if (buflen<7) return false;
// add a pseudo padding stream
diff --git a/command/video.cpp b/command/video.cpp
index 8dc509c..6f683bf 100644
--- a/command/video.cpp
+++ b/command/video.cpp
@@ -714,7 +714,7 @@ MarkAdPos *cMarkAdOverlap::Process(int FrameNumber, int Frames, bool BeforeAd)
{
if ((lastframenumber>0) && (!similarMaxCnt))
{
- similarCutOff=50000;
+ similarCutOff=60000;
similarMaxCnt=4;
}