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