00001
00002 #ifndef PREVIEW_GENERATOR_H_
00003 #define PREVIEW_GENERATOR_H_
00004
00005 #include <pthread.h>
00006
00007 #include <qstring.h>
00008 #include <qmutex.h>
00009
00010 #include "programinfo.h"
00011 #include "util.h"
00012
00013 class MythSocket;
00014
00015 class MPUBLIC PreviewGenerator : public QObject
00016 {
00017 friend int preview_helper(const QString &chanid,
00018 const QString &starttime,
00019 long long previewFrameNumber,
00020 long long previewSeconds,
00021 const QSize &previewSize,
00022 const QString &infile,
00023 const QString &outfile);
00024
00025 Q_OBJECT
00026 public:
00027 PreviewGenerator(const ProgramInfo *pginfo, bool local_only = true);
00028
00029 void SetPreviewTime(long long time, bool in_seconds)
00030 { captureTime = time; timeInSeconds = in_seconds; }
00031 void SetPreviewTimeAsSeconds(long long seconds_in)
00032 { SetPreviewTime(seconds_in, true); }
00033 void SetPreviewTimeAsFrameNumber(long long frame_number)
00034 { SetPreviewTime(frame_number, false); }
00035 void SetOutputFilename(const QString&);
00036 void SetOutputSize(const QSize &size) { outSize = size; }
00037
00038 void Start(void);
00039 bool Run(void);
00040
00041 void AttachSignals(QObject*);
00042 void disconnectSafe(void);
00043
00044 static const char *kInUseID;
00045 signals:
00046 void previewThreadDone(const QString&, bool&);
00047 void previewReady(const ProgramInfo*);
00048
00049 public slots:
00050 void deleteLater();
00051
00052 protected:
00053 virtual ~PreviewGenerator();
00054 void TeardownAll(void);
00055
00056 bool RemotePreviewSetup(void);
00057 bool RemotePreviewRun(void);
00058 void RemotePreviewTeardown(void);
00059
00060 bool LocalPreviewRun(void);
00061 bool IsLocal(void) const;
00062
00063 bool RunReal(void);
00064
00065 static void *PreviewRun(void*);
00066
00067 static char *GetScreenGrab(const ProgramInfo *pginfo,
00068 const QString &filename,
00069 long long seektime,
00070 bool time_in_secs,
00071 int &bufferlen,
00072 int &video_width,
00073 int &video_height,
00074 float &video_aspect);
00075
00076 static bool SavePreview(QString filename,
00077 const unsigned char *data,
00078 uint width, uint height, float aspect,
00079 int desired_width, int desired_height);
00080
00081
00082 static QString CreateAccessibleFilename(
00083 const QString &pathname, const QString &outFileName);
00084
00085 protected:
00086 QMutex previewLock;
00087 pthread_t previewThread;
00088 ProgramInfo programInfo;
00089
00090 bool localOnly;
00091 bool isConnected;
00092 bool createSockets;
00093 MythSocket *serverSock;
00094 QString pathname;
00095
00097 bool timeInSeconds;
00099 long long captureTime;
00100 QString outFileName;
00101 QSize outSize;
00102 };
00103
00104 #endif // PREVIEW_GENERATOR_H_