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