MythTV  master
FrameAnalyzer.h
Go to the documentation of this file.
1 /*
2  * FrameAnalyzer
3  *
4  * Provide a generic interface for plugging in video frame analysis algorithms.
5  */
6 
7 #ifndef __FRAMEANALYZER_H__
8 #define __FRAMEANALYZER_H__
9 
10 /* Base class for commercial flagging video frame analyzers. */
11 
12 #include <climits>
13 #include <QMap>
14 #include "mythframe.h"
15 
16 /*
17  * At least FreeBSD doesn't define LONG_LONG_MAX, but it does define
18  * __LONG_LONG_MAX__. Who knows what other systems do the same?
19  */
20 #ifndef LONG_LONG_MAX
21 #define LONG_LONG_MAX __LONG_LONG_MAX__
22 #endif
23 
24 class MythPlayer;
25 
27 {
28 public:
29  virtual ~FrameAnalyzer(void) = default;
30 
31  virtual const char *name(void) const = 0;
32 
33  /* Analyze a video frame. */
35  ANALYZE_OK, /* Analysis OK */
36  ANALYZE_ERROR, /* Recoverable error */
37  ANALYZE_FINISHED, /* Analysis complete, don't need more frames. */
38  ANALYZE_FATAL, /* Don't use this analyzer anymore. */
39  };
40 
41 
42  /* 0-based frameno => nframes */
43  using FrameMap = QMap<long long, long long>;
44 
46  MythPlayer *player, long long nframes) {
47  (void)player;
48  (void)nframes;
49  return ANALYZE_OK;
50  };
51 
52  /*
53  * Populate *pNextFrame with the next frame number desired by this
54  * analyzer.
55  */
56  static const long long kAnyFrame = LLONG_MAX;
57  static const long long kNextFrame = -1;
58  virtual enum analyzeFrameResult analyzeFrame(const VideoFrame *frame,
59  long long frameno, long long *pNextFrame /* [out] */) = 0;
60 
61  virtual int finished(long long nframes, bool final) {
62  (void)nframes;
63  (void)final;
64  return 0;
65  }
66  virtual int reportTime(void) const { return 0; }
67 
68  virtual FrameMap GetMap(unsigned int) const = 0;
69 };
70 
71 namespace frameAnalyzer {
72 
73 bool rrccinrect(int rr, int cc, int rrow, int rcol, int rwidth, int rheight);
74 
76  float fps, const char *comment);
77 
79  float fps, const char *comment);
80 
81 long long frameAnalyzerMapSum(const FrameAnalyzer::FrameMap *frameMap);
82 
83 bool removeShortBreaks(FrameAnalyzer::FrameMap *breakMap, float fps,
84  int minbreaklen, bool verbose);
85 
86 bool removeShortSegments(FrameAnalyzer::FrameMap *breakMap, long long nframes,
87  float fps, int minseglen, bool verbose);
88 
89 FrameAnalyzer::FrameMap::const_iterator frameMapSearchForwards(
90  const FrameAnalyzer::FrameMap *frameMap, long long mark,
91  long long markend);
92 
93 FrameAnalyzer::FrameMap::const_iterator frameMapSearchBackwards(
94  const FrameAnalyzer::FrameMap *frameMap, long long markbegin,
95  long long mark);
96 
97 }; /* namespace */
98 
99 #endif /* !__FRAMEANALYZER_H__ */
100 
101 /* vim: set expandtab tabstop=4 shiftwidth=4: */
bool removeShortBreaks(FrameAnalyzer::FrameMap *breakMap, float fps, int minbreaklen, bool verbose)
bool rrccinrect(int rr, int cc, int rrow, int rcol, int rwidth, int rheight)
virtual int reportTime(void) const
Definition: FrameAnalyzer.h:66
Definition: cc.h:13
virtual const char * name(void) const =0
QMap< int, FrameList * > FrameMap
Definition: mpeg2fix.h:115
static const long long kNextFrame
Definition: FrameAnalyzer.h:57
Definition: lang.c:20
bool removeShortSegments(FrameAnalyzer::FrameMap *breakMap, long long nframes, float fps, int minseglen, bool verbose)
FrameAnalyzer::FrameMap::const_iterator frameMapSearchBackwards(const FrameAnalyzer::FrameMap *frameMap, long long markbegin, long long mark)
virtual ~FrameAnalyzer(void)=default
virtual enum analyzeFrameResult analyzeFrame(const VideoFrame *frame, long long frameno, long long *pNextFrame)=0
virtual FrameMap GetMap(unsigned int) const =0
static const long long kAnyFrame
Definition: FrameAnalyzer.h:56
void frameAnalyzerReportMap(const FrameAnalyzer::FrameMap *frameMap, float fps, const char *comment)
QMap< long long, long long > FrameMap
Definition: FrameAnalyzer.h:43
long long frameAnalyzerMapSum(const FrameAnalyzer::FrameMap *frameMap)
FrameAnalyzer::FrameMap::const_iterator frameMapSearchForwards(const FrameAnalyzer::FrameMap *frameMap, long long mark, long long markend)
virtual int finished(long long nframes, bool final)
Definition: FrameAnalyzer.h:61
virtual enum analyzeFrameResult MythPlayerInited(MythPlayer *player, long long nframes)
Definition: FrameAnalyzer.h:45
void frameAnalyzerReportMapms(const FrameAnalyzer::FrameMap *frameMap, float fps, const char *comment)