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
}
 
typedef enum PreviewGenerator::Mode Mode
 

Public Slots

void deleteLater ()
 

Public Member Functions

 PreviewGenerator (const ProgramInfo *pginfo, const QString &token, Mode mode=kLocal)
 Constructor. More...
 
void SetPreviewTime (long long time, bool in_seconds)
 
void SetPreviewTimeAsSeconds (long long seconds_in)
 
void SetPreviewTimeAsFrameNumber (long long frame_number)
 
void SetOutputFilename (const QString &)
 
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 *)
 
- 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 ()
 
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=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 (unsigned long time=ULONG_MAX)
 Wait for the MThread to exit, with a maximum timeout. More...
 

Protected Member Functions

virtual ~PreviewGenerator ()
 
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, long long seektime, bool time_in_secs, 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 sleep (unsigned long time)
 
static void msleep (unsigned long time)
 
static void usleep (unsigned long time)
 

Protected Attributes

QWaitCondition m_previewWaitCondition
 
QMutex m_previewLock
 
ProgramInfo m_programInfo
 
Mode m_mode
 
QObject * m_listener {nullptr}
 
QString m_pathname
 
bool m_timeInSeconds {true}
 tells us whether to use time as seconds or frame number More...
 
long long m_captureTime {-1}
 snapshot time in seconds or frame number, depending on timeInSeconds More...
 
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_prolog_executed {true}
 
bool m_epilog_executed {true}
 

Friends

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

Additional Inherited Members

- Static Public Member Functions inherited from MThread
static void ThreadSetup (const QString &)
 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)
 
- Static Public Attributes inherited from MThread
static const int kDefaultStartTimeout
 

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 Typedef Documentation

◆ Mode

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,
const 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 ( )
protectedvirtual

Definition at line 86 of file previewgenerator.cpp.

Member Function Documentation

◆ SetPreviewTime()

void PreviewGenerator::SetPreviewTime ( long long  time,
bool  in_seconds 
)
inline

Definition at line 54 of file previewgenerator.h.

Referenced by PreviewGeneratorQueue::GeneratePreviewImage().

◆ SetPreviewTimeAsSeconds()

void PreviewGenerator::SetPreviewTimeAsSeconds ( long long  seconds_in)
inline

Definition at line 56 of file previewgenerator.h.

Referenced by Content::GetPreviewImage(), and preview_helper().

◆ SetPreviewTimeAsFrameNumber()

void PreviewGenerator::SetPreviewTimeAsFrameNumber ( long long  frame_number)
inline

Definition at line 58 of file previewgenerator.h.

Referenced by preview_helper().

◆ SetOutputFilename()

void PreviewGenerator::SetOutputFilename ( const QString &  fileName)

◆ SetOutputSize()

void PreviewGenerator::SetOutputSize ( const QSize &  size)
inline

◆ GetToken()

QString PreviewGenerator::GetToken ( void  ) const
inline

Definition at line 63 of file previewgenerator.h.

◆ 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 349 of file previewgenerator.cpp.

◆ Run()

bool PreviewGenerator::Run ( void  )

◆ AttachSignals()

void PreviewGenerator::AttachSignals ( QObject *  obj)

Definition at line 114 of file previewgenerator.cpp.

◆ deleteLater

void PreviewGenerator::deleteLater ( void  )
slot

◆ 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 356 of file previewgenerator.cpp.

Referenced by Run(), and RunReal().

◆ LocalPreviewRun()

bool PreviewGenerator::LocalPreviewRun ( void  )
protected

Definition at line 624 of file previewgenerator.cpp.

Referenced by RunReal().

◆ IsLocal()

bool PreviewGenerator::IsLocal ( void  ) const
protected

Definition at line 752 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.

Referenced by preview_helper().

◆ GetScreenGrab()

char * PreviewGenerator::GetScreenGrab ( const ProgramInfo pginfo,
const QString &  filename,
long long  seektime,
bool  time_in_secs,
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 or frames into the video to seek before capturing a frame.
time_in_secsif true time is in seconds, otherwise it is in frames.
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 790 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 557 of file previewgenerator.cpp.

Referenced by LocalPreviewRun().

◆ CreateAccessibleFilename()

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

Definition at line 721 of file previewgenerator.cpp.

Referenced by LocalPreviewRun().

◆ event()

bool PreviewGenerator::event ( QEvent *  e)
overrideprotected

Definition at line 417 of file previewgenerator.cpp.

◆ SaveOutFile()

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

Definition at line 488 of file previewgenerator.cpp.

Referenced by event().

Friends And Related Function Documentation

◆ preview_helper

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

Definition at line 70 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_timeInSeconds

bool PreviewGenerator::m_timeInSeconds {true}
protected

tells us whether to use time as seconds or frame number

Definition at line 115 of file previewgenerator.h.

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

◆ m_captureTime

long long PreviewGenerator::m_captureTime {-1}
protected

snapshot time in seconds or frame number, depending on timeInSeconds

Definition at line 117 of file previewgenerator.h.

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

◆ m_outFileName

QString PreviewGenerator::m_outFileName
protected

◆ m_outSize

QSize PreviewGenerator::m_outSize {0,0}
protected

Definition at line 119 of file previewgenerator.h.

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

◆ m_outFormat

QString PreviewGenerator::m_outFormat {"PNG"}
protected

Definition at line 120 of file previewgenerator.h.

Referenced by LocalPreviewRun(), and SetOutputFilename().

◆ m_token

QString PreviewGenerator::m_token
protected

Definition at line 122 of file previewgenerator.h.

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

◆ m_gotReply

bool PreviewGenerator::m_gotReply {false}
protected

Definition at line 123 of file previewgenerator.h.

Referenced by event(), and RemotePreviewRun().

◆ m_pixmapOk

bool PreviewGenerator::m_pixmapOk {false}
protected

Definition at line 124 of file previewgenerator.h.

Referenced by event(), and RemotePreviewRun().


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