MythTV master
PGMConverter.cpp
Go to the documentation of this file.
1// Qt headers
2#include <QSize>
3
4// MythTV headers
7#include "libmythtv/mythframe.h" /* VideoFrame */
9
10// Commercial Flagging headers
11#include "CommDetector2.h"
12#include "PGMConverter.h"
13#include "pgm.h"
14
15extern "C" {
16#include "libavutil/imgutils.h"
17}
18
19using namespace commDetector2;
20
22{
23 m_width = -1;
24#ifdef PGM_CONVERT_GREYSCALE
25 av_freep(reinterpret_cast<void*>(&m_pgm.data[0]));
26 memset(&m_pgm, 0, sizeof(m_pgm));
27 delete m_copy;
28#endif /* PGM_CONVERT_GREYSCALE */
29}
30
31int
33{
34#ifdef PGM_CONVERT_GREYSCALE
35 m_timeReported = false;
36 memset(&m_convertTime, 0, sizeof(m_convertTime));
37#endif /* PGM_CONVERT_GREYSCALE */
38
39 if (m_width != -1)
40 return 0;
41
42 QSize buf_dim = player->GetVideoBufferSize();
43 m_width = buf_dim.width();
44 m_height = buf_dim.height();
45
46#ifdef PGM_CONVERT_GREYSCALE
47 if (av_image_alloc(m_pgm.data, m_pgm.linesize,
48 m_width, m_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
49 {
50 LOG(VB_COMMFLAG, LOG_ERR, QString("PGMConverter::MythPlayerInited "
51 "av_image_alloc m_pgm (%1x%2) failed")
52 .arg(m_width).arg(m_height));
53 return -1;
54 }
55
56 delete m_copy;
57 m_copy = new MythAVCopy;
58 LOG(VB_COMMFLAG, LOG_INFO, QString("PGMConverter::MythPlayerInited "
59 "using true greyscale conversion"));
60#else /* !PGM_CONVERT_GREYSCALE */
61 LOG(VB_COMMFLAG, LOG_INFO, QString("PGMConverter::MythPlayerInited "
62 "(YUV shortcut)"));
63#endif /* !PGM_CONVERT_GREYSCALE */
64
65 return 0;
66}
67
68const AVFrame *
69PGMConverter::getImage(const MythVideoFrame *frame, long long _frameno,
70 int *pwidth, int *pheight)
71{
72 if (m_frameNo != _frameno)
73 {
74 if (!frame->m_buffer)
75 {
76 LOG(VB_COMMFLAG, LOG_ERR, "PGMConverter::getImage no buf");
77 return nullptr;
78 }
79
80#ifdef PGM_CONVERT_GREYSCALE
81 auto start = nowAsDuration<std::chrono::microseconds>();
82 if (m_copy->Copy(&m_pgm, frame, m_pgm.data[0], AV_PIX_FMT_GRAY8) < 0)
83 return nullptr;
84 auto end = nowAsDuration<std::chrono::microseconds>();
85 m_convertTime += (end - start);
86#else /* !PGM_CONVERT_GREYSCALE */
87 if (av_image_fill_arrays(m_pgm.data, m_pgm.linesize,
88 frame->m_buffer, AV_PIX_FMT_GRAY8, m_width, m_height,IMAGE_ALIGN) < 0)
89 {
90 LOG(VB_COMMFLAG, LOG_ERR,
91 QString("PGMConverter::getImage error at frame %1 (%2x%3)")
92 .arg(_frameno).arg(m_width).arg(m_height));
93 return nullptr;
94 }
95#endif /* !PGM_CONVERT_GREYSCALE */
96
97 m_frameNo = _frameno;
98 }
99
100 *pwidth = m_width;
101 *pheight = m_height;
102 return &m_pgm;
103}
104
105int
107{
108#ifdef PGM_CONVERT_GREYSCALE
109 if (!m_timeReported)
110 {
111 LOG(VB_COMMFLAG, LOG_INFO, QString("PGM Time: convert=%1s")
113 m_timeReported = true;
114 }
115#endif /* PGM_CONVERT_GREYSCALE */
116 return 0;
117}
118
119/* vim: set expandtab tabstop=4 shiftwidth=4: */
AVFrame AVFrame
int Copy(AVFrame *To, const MythVideoFrame *From, unsigned char *Buffer, AVPixelFormat Fmt=AV_PIX_FMT_YUV420P)
Initialise AVFrame and copy contents of VideoFrame frame into it, performing any required conversion.
Definition: mythavutil.cpp:267
QSize GetVideoBufferSize(void) const
Definition: mythplayer.h:130
uint8_t * m_buffer
Definition: mythframe.h:119
AVFrame m_pgm
Definition: PGMConverter.h:46
int MythPlayerInited(const MythPlayer *player)
const AVFrame * getImage(const MythVideoFrame *frame, long long frameno, int *pwidth, int *pheight)
int reportTime(void)
MythAVCopy * m_copy
Definition: PGMConverter.h:50
bool m_timeReported
Definition: PGMConverter.h:49
std::chrono::microseconds m_convertTime
Definition: PGMConverter.h:48
long long m_frameNo
Definition: PGMConverter.h:43
~PGMConverter(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QString strftimeval(std::chrono::microseconds usecs)