diff options
author | Jochen Dolze <vdr@dolze.de> | 2010-10-07 20:27:51 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2010-10-07 20:27:51 +0200 |
commit | c84d6dba338bc863f0cb64f13b08ef87b65eba65 (patch) | |
tree | 808806f210823da5e3a5dc0d9584681670c85b02 | |
parent | 8cf797691409510a1957156d9d2c9cfa104ef6b4 (diff) | |
download | vdr-plugin-markad-c84d6dba338bc863f0cb64f13b08ef87b65eba65.tar.gz vdr-plugin-markad-c84d6dba338bc863f0cb64f13b08ef87b65eba65.tar.bz2 |
Added support for totally broken info files
Code cleanups
-rw-r--r-- | command/audio.cpp | 46 | ||||
-rw-r--r-- | command/audio.h | 5 | ||||
-rw-r--r-- | command/global.h | 30 | ||||
-rw-r--r-- | command/markad-standalone.cpp | 77 | ||||
-rw-r--r-- | command/markad-standalone.h | 3 |
5 files changed, 64 insertions, 97 deletions
diff --git a/command/audio.cpp b/command/audio.cpp index f46d006..448d1e9 100644 --- a/command/audio.cpp +++ b/command/audio.cpp @@ -68,49 +68,6 @@ bool cMarkAdAudio::AddMark(int Type, int Position, const char *Comment) return true; } -bool cMarkAdAudio::SilenceDetection(int FrameNumber) -{ - // function taken from noad - if (!FrameNumber) return false; - if (!macontext->Audio.Data.Valid) return false; - if (lastframe_silence==FrameNumber) return false; // we already detected silence for this frame - if (lastframe_silence==-1) - { - // ignore first detection - lastframe_silence=FrameNumber; - return false; - } - int samples=macontext->Audio.Data.SampleBufLen/ - sizeof(*macontext->Audio.Data.SampleBuf)/ - macontext->Audio.Info.Channels; - - short left,right; - int lowvalcount=0; - for (int i=0; i<samples; i++) - { - left=macontext->Audio.Data.SampleBuf[0+(i*2)]; - right=macontext->Audio.Data.SampleBuf[1+(i*2)]; - - if ((abs(left)+abs(right))<CUT_VAL) - { - lowvalcount++; - if (lowvalcount>MIN_LOWVALS) - { - lastframe_silence=FrameNumber; - } - } - else - { - if (lastframe_silence==FrameNumber) - { - return true; - } - lowvalcount=0; - } - } - return false; -} - bool cMarkAdAudio::AnalyzeGain(int FrameNumber) { if (!macontext->Audio.Data.Valid) return false; @@ -155,7 +112,6 @@ void cMarkAdAudio::Clear() { channels=0; lastframe_gain=-1; - lastframe_silence=-1; if (result.CommentBefore) free(result.CommentBefore); if (result.CommentAfter) free(result.CommentAfter); memset(&result,0,sizeof(result)); @@ -172,7 +128,7 @@ MarkAdPos *cMarkAdAudio::Process2ndPass(int FrameNumber) { if (!FrameNumber) return NULL; #if 0 - if (SilenceDetection(FrameNumber)) + if (AnalyzeGain(FrameNumber)) { if (result.CommentBefore) free(result.CommentBefore); if (asprintf(&result.CommentBefore,"audio silence detection (%i)",FrameNumber)==-1) diff --git a/command/audio.h b/command/audio.h index 56901a2..651d056 100644 --- a/command/audio.h +++ b/command/audio.h @@ -22,11 +22,6 @@ private: void ResetMark(); bool AddMark(int Type, int Position, const char *Comment); -#define CUT_VAL 4 -#define MIN_LOWVALS 25 - bool SilenceDetection(int FrameNumber); - int lastframe_silence; - int lastframe_gain; double lastgain; cMarkAdAudioGainAnalysis audiogain; diff --git a/command/global.h b/command/global.h index 71016e0..8062cf9 100644 --- a/command/global.h +++ b/command/global.h @@ -30,23 +30,27 @@ typedef unsigned char uchar; #define MT_COMMONSTART 0x11 #define MT_COMMONSTOP 0x12 -#define MT_ASPECTCHANGE 0x20 -#define MT_ASPECTSTART 0x21 -#define MT_ASPECTSTOP 0x22 +#define MT_ASSUMED 0x20 +#define MT_ASSUMEDSTART 0x21 +#define MT_ASSUMEDSTOP 0x22 -#define MT_CHANNELCHANGE 0x30 -#define MT_CHANNELSTART 0x31 -#define MT_CHANNELSTOP 0x32 +#define MT_ASPECTCHANGE 0x30 +#define MT_ASPECTSTART 0x31 +#define MT_ASPECTSTOP 0x32 -#define MT_LOGOCHANGE 0x40 -#define MT_LOGOSTART 0x41 -#define MT_LOGOSTOP 0x42 +#define MT_CHANNELCHANGE 0x40 +#define MT_CHANNELSTART 0x41 +#define MT_CHANNELSTOP 0x42 -#define MT_BORDERCHANGE 0x50 -#define MT_BORDERSTART 0x51 -#define MT_BORDERSTOP 0x52 +#define MT_LOGOCHANGE 0x50 +#define MT_LOGOSTART 0x51 +#define MT_LOGOSTOP 0x52 -#define MT_SILENCECHANGE 0x60 +#define MT_BORDERCHANGE 0x60 +#define MT_BORDERSTART 0x61 +#define MT_BORDERSTOP 0x62 + +#define MT_SILENCECHANGE 0x90 #define MT_MOVED 0xE0 #define MT_ALL 0xFF diff --git a/command/markad-standalone.cpp b/command/markad-standalone.cpp index 1fe0d86..4686df8 100644 --- a/command/markad-standalone.cpp +++ b/command/markad-standalone.cpp @@ -157,10 +157,23 @@ int cOSDMessage::Send(const char *format, ...) void cMarkAdStandalone::CalculateStopPosition(int startframe, int delta) { - int len_in_frames=macontext.Info.Length*macontext.Video.Info.FramesPerSecond; - iStop=-(startframe+len_in_frames); - chkLEFT=startframe+delta+macontext.Video.Info.FramesPerSecond; - chkRIGHT=startframe+(len_in_frames*2/3); + chkLEFT=0xFFFFFFF; + chkRIGHT=0xFFFFFFF; + if (!macontext.Info.Length) return; + if (!macontext.Video.Info.FramesPerSecond) return; + + if (startframe) + { + int len_in_frames=macontext.Info.Length*macontext.Video.Info.FramesPerSecond; + iStop=-(startframe+len_in_frames); + chkLEFT=startframe+delta+macontext.Video.Info.FramesPerSecond; + chkRIGHT=startframe+(len_in_frames*2/3); + } + else + { + chkLEFT=(int) ((macontext.Video.Info.FramesPerSecond*macontext.Info.Length)/3); + chkRIGHT=(int) ((macontext.Video.Info.FramesPerSecond*macontext.Info.Length)*2/3); + } } void cMarkAdStandalone::AddStartMark() @@ -168,22 +181,16 @@ void cMarkAdStandalone::AddStartMark() char *buf; if (asprintf(&buf,"start of recording (0)")!=-1) { - marks.Add(MT_COMMON,0,buf); + marks.Add(MT_COMMONSTART,0,buf); isyslog("%s",buf); free(buf); } - if (macontext.Info.Length) + if (tStart) { - chkLEFT=(int) ((macontext.Video.Info.FramesPerSecond*macontext.Info.Length)/3); - chkRIGHT=(int) ((macontext.Video.Info.FramesPerSecond*macontext.Info.Length)*2/3); - - if (tStart) - { - iStart=-(tStart*macontext.Video.Info.FramesPerSecond); - CalculateStopPosition(-iStart,macontext.Video.Info.FramesPerSecond*MAXRANGE); - } + iStart=-(tStart*macontext.Video.Info.FramesPerSecond); } + CalculateStopPosition(-iStart,macontext.Video.Info.FramesPerSecond*MAXRANGE); } void cMarkAdStandalone::CheckStartStop(int frame, bool checkend) @@ -293,7 +300,7 @@ void cMarkAdStandalone::CheckStartStop(int frame, bool checkend) iStart=frame; if (asprintf(&buf,"assumed start of broadcast (%i)",iStart)!=-1) { - mark.Type=MT_COMMONSTART; + mark.Type=MT_ASSUMEDSTART; mark.Position=iStart; mark.Comment=buf; AddMark(&mark); @@ -314,7 +321,7 @@ void cMarkAdStandalone::CheckStartStop(int frame, bool checkend) iStop=frame; if (asprintf(&buf,"assumed stop of broadcast (%i)",iStop)!=-1) { - mark.Type=MT_COMMONSTOP; + mark.Type=MT_ASSUMEDSTOP; mark.Position=iStop; mark.Comment=buf; AddMark(&mark); @@ -450,6 +457,12 @@ void cMarkAdStandalone::CheckInfoAspectRatio() { if (aspectChecked) return; + if (bIgnoreVideoInfo) + { + aspectChecked=true; + return; + } + dsyslog("checking aspectratio"); bool aSet=false; @@ -519,8 +532,8 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) clMark *prev=marks.GetLast(); if ((prev) && ((prev->type & 0xF)==MT_STOP)) { - int MINMARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*15); - if ((Mark->Position-prev->position)<MINMARKDIFF) + int MARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*15); + if ((Mark->Position-prev->position)<MARKDIFF) { if (Mark->Comment) isyslog("%s",Mark->Comment); isyslog("double stop mark in short distance, deleting this mark (%i)",prev->position); @@ -536,8 +549,8 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) clMark *prev=marks.GetLast(); if ((prev) && (prev->type==MT_CHANNELSTOP)) { - int MINMARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*15); - if ((Mark->Position-prev->position)<MINMARKDIFF) + int MARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*15); + if ((Mark->Position-prev->position)<MARKDIFF) { if (Mark->Comment) isyslog("%s",Mark->Comment); isyslog("audiochannel change in short distance, using this mark (%i->%i)",Mark->Position,prev->position); @@ -548,8 +561,8 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) prev=marks.GetPrev(Mark->Position,MT_LOGOSTART); if (prev) { - int MINMARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*240); - if ((Mark->Position-prev->position)<MINMARKDIFF) + int MARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*240); + if ((Mark->Position-prev->position)<MARKDIFF) { if (Mark->Comment) isyslog("%s",Mark->Comment); double distance=(Mark->Position-prev->position)/macontext.Video.Info.FramesPerSecond; @@ -569,8 +582,8 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) { if ((prev->type & 0xF0)==MT_ASPECTCHANGE) { - int MINMARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*5); - if ((Mark->Position-prev->position)<MINMARKDIFF) + int MARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*5); + if ((Mark->Position-prev->position)<MARKDIFF) { if (Mark->Comment) isyslog("%s",Mark->Comment); isyslog("aspectratio change in short distance, deleting this mark (%i)",Mark->Position); @@ -580,8 +593,8 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) if (prev->type==MT_CHANNELSTART) { - int MINMARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*5); - if ((Mark->Position-prev->position)<MINMARKDIFF) + int MARKDIFF=(int) (macontext.Video.Info.FramesPerSecond*5); + if ((Mark->Position-prev->position)<MARKDIFF) { if (Mark->Comment) isyslog("%s",Mark->Comment); isyslog("audiochannel change in short distance, deleting this mark (%i)",Mark->Position); @@ -754,7 +767,7 @@ void cMarkAdStandalone::ChangeMarks(clMark **Mark1, clMark **Mark2, MarkAdPos *N if ((*Mark1)->position!=NewPos->FrameNumberBefore) { marks.Del(*Mark1); - *Mark1=marks.Add(MT_COMMON,NewPos->FrameNumberBefore,NewPos->CommentBefore); + *Mark1=marks.Add(MT_MOVED,NewPos->FrameNumberBefore,NewPos->CommentBefore); save=true; } if (NewPos->CommentBefore) isyslog("%s",NewPos->CommentBefore); @@ -762,7 +775,7 @@ void cMarkAdStandalone::ChangeMarks(clMark **Mark1, clMark **Mark2, MarkAdPos *N if (Mark2 && (*Mark2) && (*Mark2)->position!=NewPos->FrameNumberAfter) { marks.Del(*Mark2); - *Mark2=marks.Add(MT_COMMON,NewPos->FrameNumberAfter,NewPos->CommentAfter); + *Mark2=marks.Add(MT_MOVED,NewPos->FrameNumberAfter,NewPos->CommentAfter); if (NewPos->CommentAfter) isyslog("%s",NewPos->CommentAfter); save=true; } @@ -919,7 +932,7 @@ bool cMarkAdStandalone::ProcessFile2ndPass(clMark **Mark1, clMark **Mark2,int Nu } } } - +#if 0 if ((mp2_demux) && (audio) && (pn!=3)) { uchar *tspkt = data; @@ -953,7 +966,7 @@ bool cMarkAdStandalone::ProcessFile2ndPass(clMark **Mark1, clMark **Mark2,int Nu } } } - +#endif if (abort) { close(f); @@ -1351,7 +1364,7 @@ void cMarkAdStandalone::ProcessFile() { char *buf; MarkAdMark tempmark; - tempmark.Type=MT_COMMON; + tempmark.Type=MT_COMMONSTOP; tempmark.Position=lastiframe; if (asprintf(&buf,"stop of recording (%i)",lastiframe)!=-1) @@ -1417,7 +1430,7 @@ void cMarkAdStandalone::Process() ((isTS) || ((macontext.Info.VPid.Type== MARKAD_PIDTYPE_VIDEO_H264) && (!isTS))) ? ", sorry you're lost" : - ", please run genindex"); + ", please recreate index"); } } } diff --git a/command/markad-standalone.h b/command/markad-standalone.h index 6cf09b2..b4e2359 100644 --- a/command/markad-standalone.h +++ b/command/markad-standalone.h @@ -23,7 +23,7 @@ #define DELTATIME 20000 /* equals to 222ms (base is 90kHz PTS) */ -#define MAXRANGE 360 /* range to search for start/stop marks in [s] */ +#define MAXRANGE 420 /* range to search for start/stop marks in seconds */ class cOSDMessage { @@ -220,7 +220,6 @@ unsigned Descriptor_Length: int nextPictType; int chkLEFT; - int chkLEFT2; int chkRIGHT; void CheckBroadcastLength(); |