MythTV  master
ClassicCommDetector.h
Go to the documentation of this file.
1 #ifndef CLASSIC_COMMDETECTOR_H
2 #define CLASSIC_COMMDETECTOR_H
3 
4 // C++ headers
5 #include <cstdint>
6 
7 // Qt headers
8 #include <QObject>
9 #include <QMap>
10 #include <QDateTime>
11 
12 // MythTV headers
14 #include "libmythtv/mythframe.h"
15 
16 // Commercial Flagging headers
17 #include "CommDetectorBase.h"
18 
19 class MythCommFlagPlayer;
20 class LogoDetectorBase;
22 
25  COMM_FRAME_BLANK = 0x0002,
30 };
31 
33 {
34  public:
39  int aspect;
40  int format;
41  int flagMask;
42  static QString GetHeader(void);
43  QString toString(uint64_t frame, bool verbose) const;
44 };
45 
47 {
48  Q_OBJECT
49 
50  public:
51  ClassicCommDetector(SkipType commDetectMethod, bool showProgress,
52  bool fullSpeed, MythCommFlagPlayer* player,
53  QDateTime startedAt_in,
54  QDateTime stopsAt_in,
55  QDateTime recordingStartedAt_in,
56  QDateTime recordingStopsAt_in);
57  virtual void deleteLater(void);
58 
59  bool go() override; // CommDetectorBase
60  void GetCommercialBreakList(frm_dir_map_t &marks) override; // CommDetectorBase
61  void recordingFinished(long long totalFileSize) override; // CommDetectorBase
62  void requestCommBreakMapUpdate(void) override; // CommDetectorBase
63 
64  void PrintFullMap(
65  std::ostream &out, const frm_dir_map_t *comm_breaks,
66  bool verbose) const override; // CommDetectorBase
67 
68  void logoDetectorBreathe();
69 
70  friend class ClassicLogoDetector;
71 
72  protected:
73  ~ClassicCommDetector() override = default;
74 
75  private:
76  struct FrameBlock
77  {
78  long start;
79  long end;
80  long frames;
81  double length;
82  int bfCount;
83  int logoCount;
85  int scCount;
86  double scRate;
89  int score;
90  };
91 
92  template <typename T>
93  QString FormatMsg(T first, const FrameBlock *fbp)
94  {
95  QString msgformat("%1 %2:%3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15");
96  return msgformat.arg(first, 5)
97  .arg((int)(fbp->start / m_fps) / 60, 3)
98  .arg((int)((fbp->start / m_fps )) % 60, 2, 10, QChar('0'))
99  .arg(fbp->start, 6)
100  .arg(fbp->end, 6)
101  .arg(fbp->frames, 6)
102  .arg(fbp->length, 7, 'f', 2)
103  .arg(fbp->bfCount, 3)
104  .arg(fbp->logoCount, 6)
105  .arg(fbp->ratingCount, 6)
106  .arg(fbp->scCount, 6)
107  .arg(fbp->scRate, 5, 'f', 2)
108  .arg(fbp->formatMatch, 6)
109  .arg(fbp->aspectMatch, 6)
110  .arg(fbp->score, 5);
111  }
112 
113  void ClearAllMaps(void);
114  void GetBlankCommMap(frm_dir_map_t &comms);
115  void GetBlankCommBreakMap(frm_dir_map_t &comms);
116  void GetSceneChangeMap(frm_dir_map_t &scenes,
117  int64_t start_frame);
119  const frm_dir_map_t &a, const frm_dir_map_t &b) const;
120  static void UpdateFrameBlock(FrameBlock *fbp, const FrameInfoEntry& finfo,
121  int format, int aspect);
122  void BuildAllMethodsCommList(void);
123  void BuildBlankFrameCommList(void);
124  void BuildSceneChangeCommList(void);
125  void BuildLogoCommList();
126  void MergeBlankCommList(void);
127  bool FrameIsInBreakMap(uint64_t f, const frm_dir_map_t &breakMap) const;
128  void DumpMap(frm_dir_map_t &map) const;
129  static void CondenseMarkMap(show_map_t &map, int spacing, int length);
130  static void ConvertShowMapToCommMap(
131  frm_dir_map_t &out, const show_map_t &in);
132  void CleanupFrameInfo(void);
133  void GetLogoCommBreakMap(show_map_t &map);
134 
139 
151 
152  bool m_verboseDebugging {false};
153 
154  long long m_lastFrameNumber {0};
155  long long m_curFrameNumber {0};
156 
157  int m_width {0};
158  int m_height {0};
159  int m_horizSpacing {0};
160  int m_vertSpacing {0};
161  bool m_blankFramesOnly {false};
164 
165 
167 
168  bool m_logoInfoAvailable {false};
170 
178 
179  bool m_frameIsBlank {false};
180  bool m_stationLogoPresent {false};
181 
183 
185 
186 protected:
188  QDateTime m_startedAt;
189  QDateTime m_stopsAt;
192  bool m_aggressiveDetection {false};
193  bool m_stillRecording {false};
194  bool m_fullSpeed {false};
195  bool m_showProgress {false};
196  double m_fps {0.0};
197  uint64_t m_framesProcessed {0};
198  long long m_preRoll {0};
199  long long m_postRoll {0};
200 
201 
202  void Init();
203  void SetVideoParams(float aspect);
204  void ProcessFrame(MythVideoFrame *frame, long long frame_number);
205  QMap<long long, FrameInfoEntry> m_frameInfo;
206 
207 public slots:
208  void sceneChangeDetectorHasNewInformation(unsigned int framenum, bool isSceneChange,float debugValue);
209 };
210 
211 #endif // CLASSIC_COMMDETECTOR_H
212 
213 /* vim: set expandtab tabstop=4 shiftwidth=4: */
COMM_FRAME_SCENE_CHANGE
@ COMM_FRAME_SCENE_CHANGE
Definition: ClassicCommDetector.h:26
ClassicCommDetector::m_lastFrameNumber
long long m_lastFrameNumber
Definition: ClassicCommDetector.h:154
ClassicCommDetector::deleteLater
virtual void deleteLater(void)
Definition: ClassicCommDetector.cpp:270
FrameInfoEntry::sceneChangePercent
int sceneChangePercent
Definition: ClassicCommDetector.h:38
CommDetectorBase
Abstract base class for all CommDetectors. Please use the CommDetectFactory to make actual instances.
Definition: CommDetectorBase.h:26
COMM_FRAME_ASPECT_CHANGE
@ COMM_FRAME_ASPECT_CHANGE
Definition: ClassicCommDetector.h:28
show_map_t
QMap< uint64_t, CommMapValue > show_map_t
Definition: CommDetectorBase.h:19
ClassicCommDetector::m_logoCommBreakMap
frm_dir_map_t m_logoCommBreakMap
Definition: ClassicCommDetector.h:177
FrameInfoEntry::maxBrightness
int maxBrightness
Definition: ClassicCommDetector.h:36
FrameInfoEntry::avgBrightness
int avgBrightness
Definition: ClassicCommDetector.h:37
ClassicCommDetector::m_recordingStartedAt
QDateTime m_recordingStartedAt
Definition: ClassicCommDetector.h:190
ClassicCommDetector::m_width
int m_width
Definition: ClassicCommDetector.h:157
ClassicCommDetector::ClassicCommDetector
ClassicCommDetector(SkipType commDetectMethod, bool showProgress, bool fullSpeed, MythCommFlagPlayer *player, QDateTime startedAt_in, QDateTime stopsAt_in, QDateTime recordingStartedAt_in, QDateTime recordingStopsAt_in)
Definition: ClassicCommDetector.cpp:120
ClassicCommDetector::FrameBlock::aspectMatch
int aspectMatch
Definition: ClassicCommDetector.h:88
ClassicCommDetector::m_recordingStopsAt
QDateTime m_recordingStopsAt
Definition: ClassicCommDetector.h:191
ClassicCommDetector::m_commDetectBorder
int m_commDetectBorder
Definition: ClassicCommDetector.h:140
ClassicCommDetector::BuildLogoCommList
void BuildLogoCommList()
Definition: ClassicCommDetector.cpp:2129
ClassicCommDetector::m_stationLogoPresent
bool m_stationLogoPresent
Definition: ClassicCommDetector.h:180
ClassicCommDetector::ProcessFrame
void ProcessFrame(MythVideoFrame *frame, long long frame_number)
Definition: ClassicCommDetector.cpp:745
ClassicCommDetector::m_commBreakMap
frm_dir_map_t m_commBreakMap
Definition: ClassicCommDetector.h:176
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:119
ClassicCommDetector::UpdateFrameBlock
static void UpdateFrameBlock(FrameBlock *fbp, const FrameInfoEntry &finfo, int format, int aspect)
Definition: ClassicCommDetector.cpp:1143
ClassicCommDetector::logoDetectorBreathe
void logoDetectorBreathe()
Definition: ClassicCommDetector.cpp:2483
ClassicCommDetector::m_sceneChangeDetector
SceneChangeDetectorBase * m_sceneChangeDetector
Definition: ClassicCommDetector.h:184
ClassicCommDetector::m_commDetectMinCommBreakLength
int m_commDetectMinCommBreakLength
Definition: ClassicCommDetector.h:147
ClassicCommDetector::m_sceneMap
frm_dir_map_t m_sceneMap
Definition: ClassicCommDetector.h:174
ClassicCommDetector::FrameBlock::end
long end
Definition: ClassicCommDetector.h:79
ClassicCommDetector::m_commDetectDimBrightness
int m_commDetectDimBrightness
Definition: ClassicCommDetector.h:143
ClassicCommDetector::FrameBlock::logoCount
int logoCount
Definition: ClassicCommDetector.h:83
mythframe.h
ClassicCommDetector::requestCommBreakMapUpdate
void requestCommBreakMapUpdate(void) override
Definition: ClassicCommDetector.cpp:701
ClassicCommDetector::m_currentAspect
int m_currentAspect
Definition: ClassicCommDetector.h:163
ClassicCommDetector::m_commDetectMethod
SkipType m_commDetectMethod
Definition: ClassicCommDetector.h:135
ClassicCommDetector::Combine2Maps
frm_dir_map_t Combine2Maps(const frm_dir_map_t &a, const frm_dir_map_t &b) const
Definition: ClassicCommDetector.cpp:1044
COMM_FRAME_BLANK
@ COMM_FRAME_BLANK
Definition: ClassicCommDetector.h:25
FrameInfoEntry::minBrightness
int minBrightness
Definition: ClassicCommDetector.h:35
ClassicCommDetector::Init
void Init()
Definition: ClassicCommDetector.cpp:163
FrameInfoEntry::flagMask
int flagMask
Definition: ClassicCommDetector.h:41
COMM_FRAME_RATING_SYMBOL
@ COMM_FRAME_RATING_SYMBOL
Definition: ClassicCommDetector.h:29
ClassicCommDetector::GetBlankCommMap
void GetBlankCommMap(frm_dir_map_t &comms)
Definition: ClassicCommDetector.cpp:1009
ClassicCommDetector::FormatMsg
QString FormatMsg(T first, const FrameBlock *fbp)
Definition: ClassicCommDetector.h:93
ClassicCommDetector::PrintFullMap
void PrintFullMap(std::ostream &out, const frm_dir_map_t *comm_breaks, bool verbose) const override
Definition: ClassicCommDetector.cpp:2488
ClassicCommDetector::FrameBlock::ratingCount
int ratingCount
Definition: ClassicCommDetector.h:84
ClassicCommDetector::GetSceneChangeMap
void GetSceneChangeMap(frm_dir_map_t &scenes, int64_t start_frame)
Definition: ClassicCommDetector.cpp:1029
ClassicCommDetector::m_stillRecording
bool m_stillRecording
Definition: ClassicCommDetector.h:193
ClassicCommDetector::FrameBlock::scRate
double scRate
Definition: ClassicCommDetector.h:86
ClassicCommDetector::BuildSceneChangeCommList
void BuildSceneChangeCommList(void)
Definition: ClassicCommDetector.cpp:2028
frameMaskValues
frameMaskValues
Definition: ClassicCommDetector.h:23
programinfo.h
ClassicCommDetector::BuildBlankFrameCommList
void BuildBlankFrameCommList(void)
Definition: ClassicCommDetector.cpp:1868
FrameInfoEntry::GetHeader
static QString GetHeader(void)
Definition: ClassicCommDetector.cpp:101
ClassicCommDetector::m_blankCommMap
frm_dir_map_t m_blankCommMap
Definition: ClassicCommDetector.h:172
ClassicCommDetector::m_lastSentCommBreakMap
frm_dir_map_t m_lastSentCommBreakMap
Definition: ClassicCommDetector.h:136
ClassicCommDetector::FrameBlock
Definition: ClassicCommDetector.h:76
ClassicCommDetector::m_horizSpacing
int m_horizSpacing
Definition: ClassicCommDetector.h:159
ClassicCommDetector::FrameBlock::formatMatch
int formatMatch
Definition: ClassicCommDetector.h:87
ClassicCommDetector::FrameIsInBreakMap
bool FrameIsInBreakMap(uint64_t f, const frm_dir_map_t &breakMap) const
Definition: ClassicCommDetector.cpp:2208
COMM_FRAME_SKIPPED
@ COMM_FRAME_SKIPPED
Definition: ClassicCommDetector.h:24
ClassicCommDetector::m_frameInfo
QMap< long long, FrameInfoEntry > m_frameInfo
Definition: ClassicCommDetector.h:205
ClassicCommDetector::m_blankCommBreakMap
frm_dir_map_t m_blankCommBreakMap
Definition: ClassicCommDetector.h:173
ClassicCommDetector::m_verboseDebugging
bool m_verboseDebugging
Definition: ClassicCommDetector.h:152
ClassicCommDetector::m_commDetectBoxBrightness
int m_commDetectBoxBrightness
Definition: ClassicCommDetector.h:144
FrameInfoEntry
Definition: ClassicCommDetector.h:32
ClassicCommDetector::GetLogoCommBreakMap
void GetLogoCommBreakMap(show_map_t &map)
Definition: ClassicCommDetector.cpp:2461
ClassicCommDetector::m_preRoll
long long m_preRoll
Definition: ClassicCommDetector.h:198
MythCommFlagPlayer
Definition: mythcommflagplayer.h:25
ClassicCommDetector::m_fullSpeed
bool m_fullSpeed
Definition: ClassicCommDetector.h:194
ClassicCommDetector::FrameBlock::frames
long frames
Definition: ClassicCommDetector.h:80
ClassicCommDetector::m_commDetectMaxCommBreakLength
int m_commDetectMaxCommBreakLength
Definition: ClassicCommDetector.h:146
ClassicCommDetector::m_stopsAt
QDateTime m_stopsAt
Definition: ClassicCommDetector.h:189
ClassicCommDetector
Definition: ClassicCommDetector.h:46
ClassicCommDetector::ClearAllMaps
void ClearAllMaps(void)
Definition: ClassicCommDetector.cpp:996
ClassicCommDetector::m_blankFrameCount
int m_blankFrameCount
Definition: ClassicCommDetector.h:162
ClassicCommDetector::sceneChangeDetectorHasNewInformation
void sceneChangeDetectorHasNewInformation(unsigned int framenum, bool isSceneChange, float debugValue)
Definition: ClassicCommDetector.cpp:607
ClassicCommDetector::SetVideoParams
void SetVideoParams(float aspect)
Definition: ClassicCommDetector.cpp:707
ClassicCommDetector::m_framesProcessed
uint64_t m_framesProcessed
Definition: ClassicCommDetector.h:197
SceneChangeDetectorBase
Definition: SceneChangeDetectorBase.h:7
LogoDetectorBase
Definition: LogoDetectorBase.h:9
ClassicCommDetector::~ClassicCommDetector
~ClassicCommDetector() override=default
ClassicCommDetector::m_vertSpacing
int m_vertSpacing
Definition: ClassicCommDetector.h:160
ClassicCommDetector::DumpMap
void DumpMap(frm_dir_map_t &map) const
Definition: ClassicCommDetector.cpp:2240
ClassicCommDetector::m_decoderFoundAspectChanges
bool m_decoderFoundAspectChanges
Definition: ClassicCommDetector.h:182
ClassicCommDetector::m_commDetectMinShowLength
int m_commDetectMinShowLength
Definition: ClassicCommDetector.h:148
ClassicCommDetector::m_curFrameNumber
long long m_curFrameNumber
Definition: ClassicCommDetector.h:155
ClassicCommDetector::m_commDetectDimAverage
int m_commDetectDimAverage
Definition: ClassicCommDetector.h:145
ClassicCommDetector::GetBlankCommBreakMap
void GetBlankCommBreakMap(frm_dir_map_t &comms)
Definition: ClassicCommDetector.cpp:1019
ClassicCommDetector::FrameBlock::score
int score
Definition: ClassicCommDetector.h:89
ClassicCommDetector::m_fps
double m_fps
Definition: ClassicCommDetector.h:196
ClassicCommDetector::m_blankFramesOnly
bool m_blankFramesOnly
Definition: ClassicCommDetector.h:161
ClassicCommDetector::CondenseMarkMap
static void CondenseMarkMap(show_map_t &map, int spacing, int length)
Definition: ClassicCommDetector.cpp:2267
ClassicCommDetector::GetCommercialBreakList
void GetCommercialBreakList(frm_dir_map_t &marks) override
Definition: ClassicCommDetector.cpp:624
ClassicCommDetector::m_logoDetector
LogoDetectorBase * m_logoDetector
Definition: ClassicCommDetector.h:169
ClassicCommDetector::m_sendCommBreakMapUpdates
bool m_sendCommBreakMapUpdates
Definition: ClassicCommDetector.h:138
FrameInfoEntry::toString
QString toString(uint64_t frame, bool verbose) const
Definition: ClassicCommDetector.cpp:106
ClassicCommDetector::MergeBlankCommList
void MergeBlankCommList(void)
Definition: ClassicCommDetector.cpp:2143
ClassicCommDetector::BuildAllMethodsCommList
void BuildAllMethodsCommList(void)
Definition: ClassicCommDetector.cpp:1167
ClassicCommDetector::go
bool go() override
Definition: ClassicCommDetector.cpp:281
ClassicCommDetector::m_sceneCommBreakMap
frm_dir_map_t m_sceneCommBreakMap
Definition: ClassicCommDetector.h:175
ClassicCommDetector::m_frameIsBlank
bool m_frameIsBlank
Definition: ClassicCommDetector.h:179
ClassicLogoDetector
Definition: ClassicLogoDetector.h:9
ClassicCommDetector::m_totalMinBrightness
int m_totalMinBrightness
Definition: ClassicCommDetector.h:166
ClassicCommDetector::m_logoInfoAvailable
bool m_logoInfoAvailable
Definition: ClassicCommDetector.h:168
ClassicCommDetector::m_aggressiveDetection
bool m_aggressiveDetection
Definition: ClassicCommDetector.h:192
marks
static const std::array< const mark, 16 > marks
Definition: lang.cpp:23
ClassicCommDetector::m_commDetectBlankFrameMaxDiff
int m_commDetectBlankFrameMaxDiff
Definition: ClassicCommDetector.h:141
ClassicCommDetector::FrameBlock::length
double length
Definition: ClassicCommDetector.h:81
SkipType
SkipType
This is used as a bitmask.
Definition: programtypes.h:129
ClassicCommDetector::m_commDetectMaxCommLength
int m_commDetectMaxCommLength
Definition: ClassicCommDetector.h:149
hardwareprofile.distros.mythtv_data.makeopts.verbose
verbose
Definition: makeopts.py:60
FrameInfoEntry::format
int format
Definition: ClassicCommDetector.h:40
ClassicCommDetector::FrameBlock::start
long start
Definition: ClassicCommDetector.h:78
MythVideoFrame
Definition: mythframe.h:88
ClassicCommDetector::m_commBreakMapUpdateRequested
bool m_commBreakMapUpdateRequested
Definition: ClassicCommDetector.h:137
ClassicCommDetector::m_commDetectDarkBrightness
int m_commDetectDarkBrightness
Definition: ClassicCommDetector.h:142
ClassicCommDetector::m_blankFrameMap
frm_dir_map_t m_blankFrameMap
Definition: ClassicCommDetector.h:171
ClassicCommDetector::CleanupFrameInfo
void CleanupFrameInfo(void)
Definition: ClassicCommDetector.cpp:2373
CommDetectorBase.h
ClassicCommDetector::m_commDetectBlankCanHaveLogo
bool m_commDetectBlankCanHaveLogo
Definition: ClassicCommDetector.h:150
ClassicCommDetector::FrameBlock::scCount
int scCount
Definition: ClassicCommDetector.h:85
ClassicCommDetector::m_postRoll
long long m_postRoll
Definition: ClassicCommDetector.h:199
ClassicCommDetector::recordingFinished
void recordingFinished(long long totalFileSize) override
Definition: ClassicCommDetector.cpp:696
ClassicCommDetector::FrameBlock::bfCount
int bfCount
Definition: ClassicCommDetector.h:82
COMM_FRAME_LOGO_PRESENT
@ COMM_FRAME_LOGO_PRESENT
Definition: ClassicCommDetector.h:27
ClassicCommDetector::m_showProgress
bool m_showProgress
Definition: ClassicCommDetector.h:195
ClassicCommDetector::m_height
int m_height
Definition: ClassicCommDetector.h:158
FrameInfoEntry::aspect
int aspect
Definition: ClassicCommDetector.h:39
ClassicCommDetector::ConvertShowMapToCommMap
static void ConvertShowMapToCommMap(frm_dir_map_t &out, const show_map_t &in)
Definition: ClassicCommDetector.cpp:2332
ClassicCommDetector::m_startedAt
QDateTime m_startedAt
Definition: ClassicCommDetector.h:188
ClassicCommDetector::m_player
MythCommFlagPlayer * m_player
Definition: ClassicCommDetector.h:187