MythTV  master
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
PreviewGenerator Class Reference

This class creates a preview image of a recording. More...

#include <previewgenerator.h>

Inheritance diagram for PreviewGenerator:
Inheritance graph
[legend]
Collaboration diagram for PreviewGenerator:
Collaboration graph
[legend]

Public Types

enum  Mode {
  kNone = 0x0, kLocal = 0x1, kRemote = 0x2, kLocalAndRemote = 0x3,
  kForceLocal = 0x5, kModeMask = 0x7
}
 

Public Slots

void deleteLater ()
 

Public Member Functions

 PreviewGenerator (const ProgramInfo *pginfo, QString token, Mode mode=kLocal)
 Constructor. More...
 
void SetPreviewTime (std::chrono::seconds time, long long frame)
 
void SetPreviewTimeAsSeconds (std::chrono::seconds seconds)
 
void SetPreviewTimeAsFrameNumber (long long frame_number)
 
void SetOutputFilename (const QString &fileName)
 
void SetOutputSize (const QSize size)
 
QString GetToken (void) const
 
void run (void) override
 Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead. More...
 
bool Run (void)
 
void AttachSignals (QObject *obj)
 
- Public Member Functions inherited from MThread
 MThread (const QString &objectName)
 Standard constructor. More...
 
 MThread (const QString &objectName, QRunnable *runnable)
 Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More...
 
virtual ~MThread ()
 
 MThread (const MThread &)=delete
 
MThreadoperator= (const MThread &)=delete
 
void RunProlog (void)
 Sets up a thread, call this if you reimplement run(). More...
 
void RunEpilog (void)
 Cleans up a thread's resources, call this if you reimplement run(). More...
 
QThread * qthread (void)
 Returns the thread, this will always return the same pointer no matter how often you restart the thread. More...
 
void setObjectName (const QString &name)
 
QString objectName (void) const
 
void setPriority (QThread::Priority priority)
 
QThread::Priority priority (void) const
 
bool isFinished (void) const
 
bool isRunning (void) const
 
void setStackSize (uint stackSize)
 
uint stackSize (void) const
 
void exit (int retcode=0)
 Use this to exit from the thread if you are using a Qt event loop. More...
 
void start (QThread::Priority p=QThread::InheritPriority)
 Tell MThread to start running the thread in the near future. More...
 
void terminate (void)
 Kill a thread unsafely. More...
 
void quit (void)
 calls exit(0) More...
 
bool wait (std::chrono::milliseconds time=std::chrono::milliseconds::max())
 Wait for the MThread to exit, with a maximum timeout. More...
 

Protected Member Functions

 ~PreviewGenerator () override
 
void TeardownAll (void)
 
bool RemotePreviewRun (void)
 
bool LocalPreviewRun (void)
 
bool IsLocal (void) const
 
bool RunReal (void)
 This call creates a preview without starting a new thread. More...
 
bool event (QEvent *e) override
 
bool SaveOutFile (const QByteArray &data, const QDateTime &dt)
 
- Protected Member Functions inherited from MThread
int exec (void)
 Enters the qt event loop. call exit or quit to exit thread. More...
 

Static Protected Member Functions

static char * GetScreenGrab (const ProgramInfo &pginfo, const QString &filename, std::chrono::seconds seektime, long long seekframe, int &bufferlen, int &video_width, int &video_height, float &video_aspect)
 Returns a AV_PIX_FMT_RGBA32 buffer containg a frame from the video. More...
 
static bool SavePreview (const QString &filename, const unsigned char *data, uint width, uint height, float aspect, int desired_width, int desired_height, const QString &format)
 
static QString CreateAccessibleFilename (const QString &pathname, const QString &outFileName)
 
- Static Protected Member Functions inherited from MThread
static void setTerminationEnabled (bool enabled=true)
 
static void usleep (std::chrono::microseconds time)
 
template<typename R , typename P >
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > usleep (std::chrono::duration< R, P > time)
 

Protected Attributes

QWaitCondition m_previewWaitCondition
 
QMutex m_previewLock
 
ProgramInfo m_programInfo
 
Mode m_mode
 
QObject * m_listener {nullptr}
 
QString m_pathname
 
std::chrono::seconds m_captureTime {-1s}
 snapshot time in seconds or frame number (seconds has priority) More...
 
long long m_captureFrame {-1}
 
QString m_outFileName
 
QSize m_outSize {0,0}
 
QString m_outFormat {"PNG"}
 
QString m_token
 
bool m_gotReply {false}
 
bool m_pixmapOk {false}
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 

Friends

int preview_helper (uint chanid, QDateTime starttime, long long previewFrameNumber, std::chrono::seconds previewSeconds, QSize previewSize, const QString &infile, const QString &outfile)
 

Additional Inherited Members

- Static Public Member Functions inherited from MThread
static void ThreadSetup (const QString &name)
 This is to be called on startup in those few threads that haven't been ported to MThread. More...
 
static void ThreadCleanup (void)
 This is to be called on exit in those few threads that haven't been ported to MThread. More...
 
static void Cleanup (void)
 This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More...
 
static void GetAllThreadNames (QStringList &list)
 
static void GetAllRunningThreadNames (QStringList &list)
 

Detailed Description

This class creates a preview image of a recording.

The usage is simple: First, pass a ProgramInfo whose pathname points to a local or remote recording to the constructor. Then call either start(void) or Run(void) to generate the preview.

start(void) will create a thread that processes the request.

Run(void) will block until the preview completes.

The PreviewGenerator will send a PREVIEW_SUCCESS or a PREVIEW_FAILED event when the preview completes or fails.

Definition at line 26 of file previewgenerator.h.

Member Enumeration Documentation

◆ Mode

Enumerator
kNone 
kLocal 
kRemote 
kLocalAndRemote 
kForceLocal 
kModeMask 

Definition at line 39 of file previewgenerator.h.

Constructor & Destructor Documentation

◆ PreviewGenerator()

PreviewGenerator::PreviewGenerator ( const ProgramInfo pginfo,
QString  token,
PreviewGenerator::Mode  mode = kLocal 
)

Constructor.

ProgramInfo::pathname must include recording prefix, so that the file can be found on the file system for local preview generation. When called by the backend 'mode' should be set to kLocal, otherwise the backend may deadlock if the PreviewGenerator cannot find the file.

Parameters
pginfoProgramInfo for the recording we want a preview of.
tokenA token value used to match up this request with the response from the backend. If a token isn't provided, the code will generate one.
modeSpecify the location where the file must exist in order to be processed.

Definition at line 72 of file previewgenerator.cpp.

◆ ~PreviewGenerator()

PreviewGenerator::~PreviewGenerator ( )
overrideprotected

Definition at line 86 of file previewgenerator.cpp.

Member Function Documentation

◆ SetPreviewTime()

void PreviewGenerator::SetPreviewTime ( std::chrono::seconds  time,
long long  frame 
)
inline

Definition at line 54 of file previewgenerator.h.

◆ SetPreviewTimeAsSeconds()

void PreviewGenerator::SetPreviewTimeAsSeconds ( std::chrono::seconds  seconds)
inline

Definition at line 56 of file previewgenerator.h.

◆ SetPreviewTimeAsFrameNumber()

void PreviewGenerator::SetPreviewTimeAsFrameNumber ( long long  frame_number)
inline

Definition at line 58 of file previewgenerator.h.

◆ SetOutputFilename()

void PreviewGenerator::SetOutputFilename ( const QString &  fileName)

Definition at line 92 of file previewgenerator.cpp.

Referenced by SaveOutFile().

◆ SetOutputSize()

void PreviewGenerator::SetOutputSize ( const QSize  size)
inline

Definition at line 61 of file previewgenerator.h.

◆ GetToken()

QString PreviewGenerator::GetToken ( void  ) const
inline

Definition at line 63 of file previewgenerator.h.

Referenced by PreviewGeneratorQueue::SetPreviewGenerator().

◆ run()

void PreviewGenerator::run ( void  )
overridevirtual

Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.

Note
If you override this method you must call RunProlog before you do any work and RunEpilog before you exit the run method.

Reimplemented from MThread.

Definition at line 347 of file previewgenerator.cpp.

◆ Run()

bool PreviewGenerator::Run ( void  )

Definition at line 207 of file previewgenerator.cpp.

Referenced by run().

◆ AttachSignals()

void PreviewGenerator::AttachSignals ( QObject *  obj)

Definition at line 114 of file previewgenerator.cpp.

Referenced by PreviewGeneratorQueue::SetPreviewGenerator().

◆ deleteLater

void PreviewGenerator::deleteLater ( )
slot

Definition at line 108 of file previewgenerator.cpp.

Referenced by PreviewGeneratorQueue::SetPreviewGenerator().

◆ TeardownAll()

void PreviewGenerator::TeardownAll ( void  )
protected

Definition at line 101 of file previewgenerator.cpp.

Referenced by deleteLater(), and ~PreviewGenerator().

◆ RemotePreviewRun()

bool PreviewGenerator::RemotePreviewRun ( void  )
protected

Definition at line 354 of file previewgenerator.cpp.

Referenced by Run(), and RunReal().

◆ LocalPreviewRun()

bool PreviewGenerator::LocalPreviewRun ( void  )
protected

Definition at line 633 of file previewgenerator.cpp.

Referenced by RunReal().

◆ IsLocal()

bool PreviewGenerator::IsLocal ( void  ) const
protected

Definition at line 756 of file previewgenerator.cpp.

Referenced by Run(), and RunReal().

◆ RunReal()

bool PreviewGenerator::RunReal ( void  )
protected

This call creates a preview without starting a new thread.

Definition at line 123 of file previewgenerator.cpp.

◆ GetScreenGrab()

char * PreviewGenerator::GetScreenGrab ( const ProgramInfo pginfo,
const QString &  filename,
std::chrono::seconds  seektime,
long long  seekframe,
int &  bufferlen,
int &  video_width,
int &  video_height,
float &  video_aspect 
)
staticprotected

Returns a AV_PIX_FMT_RGBA32 buffer containg a frame from the video.

Parameters
pginfoRecording to grab from.
filenameFile containing recording.
seektimeSeconds into the video to seek before capturing a frame. This field has priority. If it is set to -1s then seekframe will be used.
seekframeFrames into the video to seek before capturing a frame.
bufferlenReturns size of buffer returned (in bytes).
video_widthReturns width of frame grabbed.
video_heightReturns height of frame grabbed.
video_aspectReturns aspect ratio of frame grabbed.
Returns
Buffer allocated with new containing frame in RGBA32 format if successful, nullptr otherwise.

Definition at line 795 of file previewgenerator.cpp.

Referenced by LocalPreviewRun().

◆ SavePreview()

bool PreviewGenerator::SavePreview ( const QString &  filename,
const unsigned char *  data,
uint  width,
uint  height,
float  aspect,
int  desired_width,
int  desired_height,
const QString &  format 
)
staticprotected

Definition at line 566 of file previewgenerator.cpp.

Referenced by LocalPreviewRun().

◆ CreateAccessibleFilename()

QString PreviewGenerator::CreateAccessibleFilename ( const QString &  pathname,
const QString &  outFileName 
)
staticprotected

Definition at line 725 of file previewgenerator.cpp.

Referenced by LocalPreviewRun().

◆ event()

bool PreviewGenerator::event ( QEvent *  e)
overrideprotected

Definition at line 423 of file previewgenerator.cpp.

◆ SaveOutFile()

bool PreviewGenerator::SaveOutFile ( const QByteArray &  data,
const QDateTime &  dt 
)
protected

Definition at line 501 of file previewgenerator.cpp.

Referenced by event().

Friends And Related Function Documentation

◆ preview_helper

int preview_helper ( uint  chanid,
QDateTime  starttime,
long long  previewFrameNumber,
std::chrono::seconds  previewSeconds,
QSize  previewSize,
const QString &  infile,
const QString &  outfile 
)
friend

Definition at line 68 of file mythtv/programs/mythpreviewgen/main.cpp.

Member Data Documentation

◆ m_previewWaitCondition

QWaitCondition PreviewGenerator::m_previewWaitCondition
protected

Definition at line 106 of file previewgenerator.h.

Referenced by event(), RemotePreviewRun(), and TeardownAll().

◆ m_previewLock

QMutex PreviewGenerator::m_previewLock
protected

Definition at line 107 of file previewgenerator.h.

Referenced by AttachSignals(), event(), RemotePreviewRun(), Run(), RunReal(), and TeardownAll().

◆ m_programInfo

ProgramInfo PreviewGenerator::m_programInfo
protected

Definition at line 108 of file previewgenerator.h.

Referenced by LocalPreviewRun(), RemotePreviewRun(), Run(), RunReal(), and SaveOutFile().

◆ m_mode

Mode PreviewGenerator::m_mode
protected

Definition at line 110 of file previewgenerator.h.

Referenced by Run(), and RunReal().

◆ m_listener

QObject* PreviewGenerator::m_listener {nullptr}
protected

Definition at line 111 of file previewgenerator.h.

Referenced by AttachSignals(), Run(), RunReal(), and TeardownAll().

◆ m_pathname

QString PreviewGenerator::m_pathname
protected

Definition at line 112 of file previewgenerator.h.

Referenced by IsLocal(), LocalPreviewRun(), Run(), and RunReal().

◆ m_captureTime

std::chrono::seconds PreviewGenerator::m_captureTime {-1s}
protected

snapshot time in seconds or frame number (seconds has priority)

Definition at line 115 of file previewgenerator.h.

Referenced by LocalPreviewRun(), RemotePreviewRun(), and Run().

◆ m_captureFrame

long long PreviewGenerator::m_captureFrame {-1}
protected

Definition at line 116 of file previewgenerator.h.

Referenced by RemotePreviewRun(), and Run().

◆ m_outFileName

QString PreviewGenerator::m_outFileName
protected

◆ m_outSize

QSize PreviewGenerator::m_outSize {0,0}
protected

Definition at line 118 of file previewgenerator.h.

Referenced by LocalPreviewRun(), RemotePreviewRun(), and Run().

◆ m_outFormat

QString PreviewGenerator::m_outFormat {"PNG"}
protected

Definition at line 119 of file previewgenerator.h.

Referenced by LocalPreviewRun(), and SetOutputFilename().

◆ m_token

QString PreviewGenerator::m_token
protected

Definition at line 121 of file previewgenerator.h.

Referenced by event(), RemotePreviewRun(), Run(), and RunReal().

◆ m_gotReply

bool PreviewGenerator::m_gotReply {false}
protected

Definition at line 122 of file previewgenerator.h.

Referenced by event(), and RemotePreviewRun().

◆ m_pixmapOk

bool PreviewGenerator::m_pixmapOk {false}
protected

Definition at line 123 of file previewgenerator.h.

Referenced by event(), and RemotePreviewRun().


The documentation for this class was generated from the following files: