00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __output_h
00009 #define __output_h
00010
00011 class OutputListeners;
00012 class OutputEvent;
00013
00014 #include <vector>
00015 using namespace std;
00016
00017 #include <QMutex>
00018 #include <QList>
00019
00020 #include "mythobservable.h"
00021 #include "mythexp.h"
00022
00023 class QObject;
00024 class Buffer;
00025
00026 namespace MythTV {
00027 class Visual;
00028 }
00029
00030 class MPUBLIC OutputEvent : public MythEvent
00031 {
00032 public:
00033 OutputEvent(Type t) :
00034 MythEvent(t), error_msg(NULL), elasped_seconds(0), written_bytes(0),
00035 brate(0), freq(0), prec(0), chan(0)
00036 { ; }
00037
00038 OutputEvent(long s, unsigned long w, int b, int f, int p, int c) :
00039 MythEvent(Info), error_msg(NULL), elasped_seconds(s), written_bytes(w),
00040 brate(b), freq(f), prec(p), chan(c)
00041 { ; }
00042
00043 OutputEvent(const QString &e) :
00044 MythEvent(Error), elasped_seconds(0), written_bytes(0),
00045 brate(0), freq(0), prec(0), chan(0)
00046 {
00047 QByteArray tmp = e.toUtf8();
00048 error_msg = new QString(tmp.constData());
00049 }
00050
00051 ~OutputEvent()
00052 {
00053 delete error_msg;
00054 }
00055
00056 const QString *errorMessage() const { return error_msg; }
00057
00058 const long &elapsedSeconds() const { return elasped_seconds; }
00059 const unsigned long &writtenBytes() const { return written_bytes; }
00060 const int &bitrate() const { return brate; }
00061 const int &frequency() const { return freq; }
00062 const int &precision() const { return prec; }
00063 const int &channels() const { return chan; }
00064
00065 virtual MythEvent *clone(void) const { return new OutputEvent(*this); }
00066
00067 static Type Playing;
00068 static Type Buffering;
00069 static Type Info;
00070 static Type Paused;
00071 static Type Stopped;
00072 static Type Error;
00073
00074 private:
00075 OutputEvent(const OutputEvent &o) : MythEvent(o),
00076 error_msg(NULL),
00077 elasped_seconds(o.elasped_seconds),
00078 written_bytes(o.written_bytes),
00079 brate(o.brate), freq(o.freq), prec(o.prec), chan(o.chan)
00080 {
00081 if (o.error_msg)
00082 {
00083 error_msg = new QString(*o.error_msg);
00084 error_msg->detach();
00085 }
00086 }
00087 OutputEvent &operator=(const OutputEvent&);
00088
00089 private:
00090 QString *error_msg;
00091
00092 long elasped_seconds;
00093 unsigned long written_bytes;
00094 int brate, freq, prec, chan;
00095 };
00096
00097 typedef vector<MythTV::Visual*> Visuals;
00098
00099 class MPUBLIC OutputListeners : public MythObservable
00100 {
00101 public:
00102 OutputListeners();
00103 virtual ~OutputListeners();
00104
00105 bool hasVisual(void) { return visuals.size(); }
00106 void addVisual(MythTV::Visual *);
00107 void removeVisual(MythTV::Visual *);
00108
00109 QMutex *mutex() { return &mtx; }
00110
00111 void setBufferSize(unsigned int sz) { bufsize = sz; }
00112 unsigned int bufferSize() const { return bufsize; }
00113
00114 protected:
00115 void error(const QString &e);
00116 void dispatchVisual(uchar *b, unsigned long b_len,
00117 unsigned long written, int chan, int prec);
00118 void prepareVisuals();
00119
00120 private:
00121 QMutex mtx;
00122 Visuals visuals;
00123
00124 unsigned int bufsize;
00125 };
00126
00127
00128 #endif // __output_h