Skip to content

Commit 88ffda0

Browse files
committed
Added dumping findings to a file, standardizing PTS
1 parent 5749b62 commit 88ffda0

File tree

10 files changed

+205
-29
lines changed

10 files changed

+205
-29
lines changed

mythtv/programs/mythgpucommflag/audioconsumer.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <strings.h>
2+
13
#include "mythlogging.h"
24
#include "packetqueue.h"
35
#include "resultslist.h"
@@ -41,6 +43,12 @@ void AudioConsumer::ProcessPacket(Packet *packet)
4143
m_codec = avcodec_find_decoder(curstream->codec->codec_id);
4244
if (avcodec_open(m_context, m_codec) < 0)
4345
return;
46+
47+
m_stream = curstream;
48+
49+
memcpy(&m_timebase, &curstream->time_base, sizeof(m_timebase));
50+
LOG(VB_GENERAL, LOG_NOTICE, QString("Audio: num = %1, den = %2")
51+
.arg(m_timebase.num) .arg(m_timebase.den));
4452
m_opened = true;
4553
}
4654

@@ -109,7 +117,7 @@ void AudioConsumer::ProcessFrame(int16_t *samples, int size, int frames,
109117
LOG(VB_GENERAL, LOG_INFO, QString("Audio Frame: %1 samples (%2 size)")
110118
.arg(frames).arg(size));
111119

112-
uint64_t duration = (uint64_t)((double)(frames * 1000) / rate);
120+
int duration = (int)((double)(frames * 1000000) / (rate * 1.0));
113121
AudioPacket *audioPacket = NULL;
114122

115123
// Push PCM frame to GPU/CPU Processing memory
@@ -132,9 +140,12 @@ void AudioConsumer::ProcessFrame(int16_t *samples, int size, int frames,
132140
// Toss the results onto the results list
133141
if (result)
134142
{
143+
static AVRational realTimeBase = { 1, 1000 };
135144
LOG(VB_GENERAL, LOG_INFO, "Audio Finding found");
136-
result->m_pts = pts;
145+
pts = av_rescale_q(pts, realTimeBase, m_timebase);
146+
result->m_timestamp = NormalizeTimecode(pts);;
137147
result->m_duration = duration;
148+
LOG(VB_GENERAL, LOG_INFO, result->toString());
138149
m_outL->append(result);
139150
}
140151
}
@@ -146,6 +157,7 @@ void AudioConsumer::ProcessFrame(int16_t *samples, int size, int frames,
146157
}
147158
}
148159

160+
149161
/*
150162
* vim:ts=4:sw=4:ai:et:si:sts=4
151163
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef _FINDINGDEFS_H
2+
#define _FINDINGDEFS_H
3+
4+
#undef FINDINGS_PREAMBLE
5+
#undef FINDINGS_POSTAMBLE
6+
#undef FINDINGS_MAP
7+
8+
// names are expected to start with kFinding
9+
// value is the enumerated value (0-xxxxx)
10+
// desc is descriptive text used for dumping results
11+
12+
#ifdef _IMPLEMENT_FINDINGS
13+
14+
// This actually will implement the mapping in resultslist.cpp
15+
#define FINDINGS_PREAMBLE
16+
#define FINDINGS_POSTAMBLE
17+
#define FINDINGS_MAP(name,value,desc) \
18+
findingsAdd((int)value,QString(desc));
19+
20+
#else
21+
22+
// This is used to define the enumerated type (used by all files)
23+
24+
#define FINDINGS_PREAMBLE \
25+
typedef enum {
26+
#define FINDINGS_POSTAMBLE \
27+
kFindingsLastItem \
28+
} FlagFindingsType;
29+
#define FINDINGS_MAP(name,value,desc) \
30+
name = (int)(value),
31+
32+
#endif
33+
34+
FINDINGS_PREAMBLE
35+
FINDINGS_MAP(kFindingAudioHigh, 0, "Audio more than 6dB above average")
36+
FINDINGS_MAP(kFindingAudioLow, 1, "Audio more than 12dB below average")
37+
FINDINGS_MAP(kFindingVideoBlankFrame, 2, "Blank video frame")
38+
FINDINGS_MAP(kFindingVideoSceneChange, 3, "Video scene change")
39+
FINDINGS_MAP(kFindingVideoAspectChange, 4, "Video aspect ratio change")
40+
FINDINGS_MAP(kFindingVideoLogoChange, 5, "Video logo presence change")
41+
FINDINGS_POSTAMBLE
42+
43+
#endif
44+
45+
/*
46+
* vim:ts=4:sw=4:ai:et:si:sts=4
47+
*/
48+

mythtv/programs/mythgpucommflag/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using namespace std;
44
#include <QApplication>
55
#include <QDesktopWidget>
66
#include <QX11Info>
7+
#include <QFile>
78

89
#include "exitcodes.h"
910
#include "mythcontext.h"
@@ -307,6 +308,9 @@ int main(int argc, char **argv)
307308
ResultsList audioMarks;
308309
ResultsList videoMarks;
309310

311+
// Initialize the findings map
312+
FindingsInitialize();
313+
310314
// Create consumer threads
311315
AudioConsumer *audioThread = new AudioConsumer(&audioQ, &audioMarks,
312316
devices[1]);
@@ -338,6 +342,15 @@ int main(int argc, char **argv)
338342
LOG(VB_GENERAL, LOG_INFO, QString("audioMarks: %1, videoMarks: %2")
339343
.arg(audioMarks.size()) .arg(videoMarks.size()));
340344

345+
// Dump results to an output file
346+
QFile dump("out/results");
347+
dump.open(QIODevice::WriteOnly);
348+
QString audioDump = audioMarks.toString("Audio markings");
349+
QString videoDump = videoMarks.toString("Video markings");
350+
dump.write(audioDump.toAscii());
351+
dump.write(videoDump.toAscii());
352+
dump.close();
353+
341354
// Loop:
342355
// Summarize the various criteria to get commercial flag map
343356

mythtv/programs/mythgpucommflag/mythgpucommflag.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LIBS += -lOpenCL -lglut -lGLEW
3131
HEADERS += commandlineparser.h
3232
HEADERS += openclinterface.h openglsupport.h
3333
HEADERS += packetqueue.h
34-
HEADERS += resultslist.h
34+
HEADERS += resultslist.h findingdefs.h
3535
HEADERS += gpuplayer.h
3636
HEADERS += queueconsumer.h audioconsumer.h videoconsumer.h
3737
HEADERS += audioprocessor.h videoprocessor.h
@@ -40,7 +40,7 @@ HEADERS += videodecoder.h vdpauvideodecoder.h ffmpegvideodecoder.h
4040

4141
SOURCES += main.cpp commandlineparser.cpp
4242
SOURCES += openclinterface.cpp
43-
SOURCES += packetqueue.cpp
43+
SOURCES += packetqueue.cpp resultslist.cpp
4444
SOURCES += gpuplayer.cpp
4545
SOURCES += queueconsumer.cpp audioconsumer.cpp videoconsumer.cpp
4646
SOURCES += audioprocessor.cpp videoprocessor.cpp

mythtv/programs/mythgpucommflag/openclvideoprocessor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,6 @@ FlagResults *OpenCLSceneChangeDetect(OpenCLDevice *dev, AVFrame *frame,
21002100

21012101
if (found)
21022102
{
2103-
#define DEBUG_VIDEO
21042103
#ifdef DEBUG_VIDEO
21052104
videoPacket->m_prevFrameRGB->Dump("rgb", frameNum-1, 1);
21062105
videoPacket->m_croppedRGB->Dump("rgb", frameNum, 1);

mythtv/programs/mythgpucommflag/queueconsumer.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ void QueueConsumer::run(void)
3636
}
3737

3838

39+
int64_t QueueConsumer::NormalizeTimecode(int64_t timecode)
40+
{
41+
int64_t start_pts = 0;
42+
43+
if (m_stream->start_time != (int64_t)AV_NOPTS_VALUE)
44+
start_pts = m_stream->start_time;
45+
46+
int64_t pts = timecode - start_pts;
47+
48+
pts = av_rescale(pts, 1000000 * m_timebase.num, m_timebase.den);
49+
50+
#ifdef DEBUG_TIMESTAMP
51+
LOG(VB_GENERAL, LOG_INFO, QString("Timecode %1, Start %2, Normalized %3 us")
52+
.arg(timecode) .arg(start_pts) .arg(pts));
53+
#endif
54+
return pts;
55+
}
56+
57+
int64_t QueueConsumer::NormalizeDuration(int64_t duration)
58+
{
59+
int64_t retval;
60+
61+
retval = av_rescale(duration, m_timebase.num * 1000000, m_timebase.den);
62+
63+
#ifdef DEBUG_TIMESTAMP
64+
LOG(VB_GENERAL, LOG_INFO, QString("Duration %1, Normalized %2 us")
65+
.arg(duration) .arg(retval));
66+
#endif
67+
return retval;
68+
}
69+
70+
3971
/*
4072
* vim:ts=4:sw=4:ai:et:si:sts=4
4173
*/

mythtv/programs/mythgpucommflag/queueconsumer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ class QueueConsumer : public MThread
1212
QueueConsumer(PacketQueue *inQ, ResultsList *outL, OpenCLDevice *dev,
1313
QString name) :
1414
MThread(name), m_name(name), m_inQ(inQ), m_outL(outL), m_done(false),
15-
m_dev(dev), m_context(NULL), m_codec(NULL), m_opened(false) {};
15+
m_dev(dev), m_context(NULL), m_codec(NULL), m_stream(NULL),
16+
m_opened(false) {};
1617
~QueueConsumer() {};
1718
virtual bool Initialize(void) = 0;
1819
virtual void ProcessPacket(Packet *packet) = 0;
20+
int64_t NormalizeTimecode(int64_t timecode);
21+
int64_t NormalizeDuration(int64_t duration);
1922

2023
void run(void);
2124
void done(void) { m_done = true; m_inQ->stop(); }
@@ -27,6 +30,8 @@ class QueueConsumer : public MThread
2730
OpenCLDevice *m_dev;
2831
AVCodecContext *m_context;
2932
AVCodec *m_codec;
33+
AVStream *m_stream;
34+
AVRational m_timebase;
3035
bool m_opened;
3136
};
3237

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <QList>
2+
#include <QMap>
3+
#include <QString>
4+
5+
#include "resultslist.h"
6+
#include "mythlogging.h"
7+
8+
FlagFindingsMap findingsMap;
9+
10+
void findingsAdd(int value, QString description);
11+
12+
void FindingsInitialize(void)
13+
{
14+
#undef _FINDINGDEFS_H
15+
#define _IMPLEMENT_FINDINGS
16+
#include "findingdefs.h"
17+
}
18+
19+
void findingsAdd(int value, QString description)
20+
{
21+
LOG(VB_GENERAL, LOG_DEBUG, QString("FindingsMap: Inserting %1:%2")
22+
.arg(value) .arg(description));
23+
findingsMap.insert(value, description);
24+
}
25+
26+
QString FlagFindings::toString(void)
27+
{
28+
QString finding = QString("Unknown finding (%1)").arg(m_type);
29+
if (findingsMap.contains((int)m_type))
30+
finding = findingsMap.value((int)m_type);
31+
32+
QString str = QString("%1: %2").arg(finding).arg(m_value);
33+
return str;
34+
}
35+
36+
QString FlagResults::toString(void)
37+
{
38+
FlagFindingsList::iterator it;
39+
40+
QString str = QString("Findings at PTS: %1, Duration: %2\n")
41+
.arg(m_timestamp) .arg(m_duration);
42+
43+
for (it = m_findings->begin(); it != m_findings->end(); ++it)
44+
{
45+
FlagFindings *finding = *it;
46+
str += QString(" %1\n").arg(finding->toString());
47+
}
48+
str += QString("\n");
49+
return str;
50+
}
51+
52+
QString ResultsList::toString(QString title)
53+
{
54+
ResultsList::iterator it;
55+
QString str = QString("-----------------------------\n%1\n\n").arg(title);
56+
57+
for (it = begin(); it != end(); ++it)
58+
{
59+
FlagResults *results = *it;
60+
str += results->toString();
61+
}
62+
return str;
63+
}
64+
65+
/*
66+
* vim:ts=4:sw=4:ai:et:si:sts=4
67+
*/

mythtv/programs/mythgpucommflag/resultslist.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
#define _RESULTSLIST_H
33

44
#include <QList>
5+
#include <QMap>
56

67
extern "C" {
78
#include "libavcodec/avcodec.h"
89
}
910

10-
typedef enum {
11-
kFindingAudioHigh,
12-
kFindingAudioLow,
13-
kFindingVideoBlankFrame,
14-
kFindingVideoSceneChange,
15-
kFindingVideoAspectChange,
16-
kFindingVideoLogoChange
17-
} FlagFindingsType;
11+
#include "findingdefs.h"
1812

1913
class FlagFindings
2014
{
2115
public:
2216
FlagFindings(int type, int64_t value) : m_type(type), m_value(value) {};
2317
~FlagFindings() {};
18+
QString toString(void);
2419

2520
int m_type;
2621
int64_t m_value;
@@ -34,28 +29,28 @@ class FlagResults
3429
FlagResults(AVPacket *pkt, FlagFindingsList *list) : m_findings(list)
3530
{
3631
m_valid = (pkt != NULL);
37-
if (m_valid)
38-
{
39-
m_pts = pkt->pts;
40-
m_dts = pkt->dts;
41-
m_duration = pkt->duration;
42-
m_pos = pkt->pos;
43-
}
4432
}
4533

4634
FlagResults(FlagFindingsList *list) : m_findings(list) {};
4735
~FlagResults() { delete m_findings; };
36+
QString toString(void);
4837

4938
bool m_valid;
50-
int64_t m_pts;
51-
int64_t m_dts;
39+
int64_t m_timestamp;
5240
int m_duration;
53-
int64_t m_pos;
5441

5542
FlagFindingsList *m_findings;
5643
};
5744

58-
typedef QList<FlagResults *> ResultsList;
45+
class ResultsList : public QList<FlagResults *>
46+
{
47+
public:
48+
QString toString(QString title);
49+
};
50+
51+
typedef QMap<int, QString> FlagFindingsMap;
52+
53+
void FindingsInitialize(void);
5954

6055
#endif
6156

0 commit comments

Comments
 (0)