MythTV  master
decoderhandler.h
Go to the documentation of this file.
1 #ifndef DECODERHANDLER_H_
2 #define DECODERHANDLER_H_
3 
4 // c++
5 #include <iostream>
6 
7 // qt
8 #include <QObject>
9 #include <QIODevice>
10 #include <QFile>
11 #include <QUrl>
12 #include <QMutex>
13 
14 // mythtv
15 #include <mythobservable.h>
16 #include <musicmetadata.h>
17 
18 // mythmusic
19 
20 #include "pls.h"
21 
22 class Decoder;
23 
27 {
28  public:
29  explicit DecoderHandlerEvent(Type type)
30  : MythEvent(type) {}
31 
32  DecoderHandlerEvent(Type type, QString *e)
33  : MythEvent(type), m_msg(e) {}
34 
35  DecoderHandlerEvent(Type type, int available, int maxSize)
36  : MythEvent(type), m_available(available), m_maxSize(maxSize) {}
37 
38  DecoderHandlerEvent(Type type, const MusicMetadata &m);
40 
41  QString *getMessage(void) const { return m_msg; }
42  MusicMetadata *getMetadata(void) const { return m_meta; }
43  void getBufferStatus(int *available, int *maxSize) const;
44 
45  MythEvent *clone(void) const override; // MythEvent
46 
47  static Type Ready;
48  static Type Meta;
49  static Type BufferStatus;
50  static Type OperationStart;
51  static Type OperationStop;
52  static Type Error;
53 
54  private:
55  QString *m_msg {nullptr};
56  MusicMetadata *m_meta {nullptr};
57  int m_available {0};
58  int m_maxSize {0};
59 };
60 
70 class DecoderHandler : public QObject, public MythObservable
71 {
72  Q_OBJECT
73 
74  public:
75  typedef enum
76  {
80  } State;
81 
82  DecoderHandler(void) = default;
83  virtual ~DecoderHandler(void);
84 
85  Decoder *getDecoder(void) { return m_decoder; }
86 
87  void start(MusicMetadata *mdata);
88 
89  void stop(void);
90  void customEvent(QEvent *e) override; // QObject
91  bool done(void);
92  bool next(void);
93  void error(const QString &e);
94 
96 
97  QUrl& getUrl() { return m_url; }
98  void setUrl (const QUrl &url) { m_url = url; }
99 
100  protected:
101  void doOperationStart(const QString &name);
102  void doOperationStop(void);
103  void doConnectDecoder(const QUrl &url, const QString &format);
104  void doFailed(const QUrl &url, const QString &message);
105  void doStart(bool result);
106 
107  private:
108  void createPlaylist(const QUrl &url);
109  void createPlaylistForSingleFile(const QUrl &url);
110  void createPlaylistFromFile(const QUrl &url);
111  void createPlaylistFromRemoteUrl(const QUrl &url);
112 
114  int m_playlist_pos {0};
116  Decoder *m_decoder {nullptr};
118  QUrl m_url;
119  bool m_op {false};
121 
122  static const uint MaxRedirects = 3;
123 };
124 
125 #endif /* DECODERHANDLER_H_ */
void createPlaylistForSingleFile(const QUrl &url)
Decoder * getDecoder(void)
void setUrl(const QUrl &url)
DecoderHandlerEvent(Type type, int available, int maxSize)
MusicMetadata * getMetadata(void) const
MusicMetadata & getMetadata()
DecoderHandler(void)=default
unsigned int uint
Definition: compat.h:140
MusicMetadata m_meta
Events sent by the DecoderHandler and it's helper classes.
Superclass for making an object have a set of listeners.
void doOperationStop(void)
virtual ~DecoderHandler(void)
MusicMetadata * m_meta
DecoderHandlerEvent(Type type, QString *e)
This class is used as a container for messages.
Definition: mythevent.h:16
QString * getMessage(void) const
void doOperationStart(const QString &name)
static Type OperationStart
Class for containing the info of a pls or m3u file.
Definition: pls.h:41
static const uint MaxRedirects
void createPlaylistFromFile(const QUrl &url)
const char * name
Definition: ParseText.cpp:328
void createPlaylistFromRemoteUrl(const QUrl &url)
void error(const QString &e)
void doFailed(const QUrl &url, const QString &message)
void doStart(bool result)
MythEvent * clone(void) const override
void doConnectDecoder(const QUrl &url, const QString &format)
void customEvent(QEvent *e) override
static Type BufferStatus
void getBufferStatus(int *available, int *maxSize) const
Class for starting stream decoding.
static Type OperationStop
PlayListFile m_playlist
Decoder * m_decoder
DecoderHandlerEvent(Type type)
void createPlaylist(const QUrl &url)
void start(MusicMetadata *mdata)