MythTV  master
mythmedia.h
Go to the documentation of this file.
1 #ifndef MYTH_MEDIA_H
2 #define MYTH_MEDIA_H
3 
4 #include <QObject>
5 #include <QMap>
6 #include <QString>
7 #include <QEvent>
8 #include <QPointer>
9 
10 #include "mythbaseexp.h"
11 
12 enum MythMediaStatus : std::uint8_t {
22 };
23 
26  MEDIATYPE_DATA = 0x0002,
27  MEDIATYPE_MIXED = 0x0004,
28  MEDIATYPE_AUDIO = 0x0008,
29  MEDIATYPE_DVD = 0x0010,
30  MEDIATYPE_VCD = 0x0020,
31  MEDIATYPE_MMUSIC = 0x0040,
32  MEDIATYPE_MVIDEO = 0x0080,
34  MEDIATYPE_BD = 0x0200,
35  MEDIATYPE_END = 0x0400,
36 };
37 // MediaType conflicts with a definition within OSX Quicktime Libraries.
38 
39 enum MythMediaError : std::uint8_t {
43 };
44 
45 using ext_cnt_t = QMap<QString,uint>;
46 using ext_to_media_t = QMap<QString,uint>;
47 
48 class MBASE_PUBLIC MythMediaDevice : public QObject
49 {
50  Q_OBJECT
51  friend class MediaMonitorDarwin; // So these can call setStatus(),
52  friend class MonitorThreadDarwin; // and trigger posting of MythMediaEvents
53 
54  public:
55  MythMediaDevice(QObject* par, QString DevicePath, bool SuperMount,
56  bool AllowEject);
57 
58  const QString& getMountPath() const { return m_mountPath; }
59  void setMountPath(const char *path) { m_mountPath = path; }
60 
61  const QString& getDevicePath() const { return m_devicePath; }
62 
63  const QString& getRealDevice() const
64  { return !m_realDevice.isEmpty() ? m_realDevice : m_devicePath; }
65 
66 
67  const QString& getDeviceModel() const { return m_deviceModel; }
68  void setDeviceModel(const char *model) { m_deviceModel = model; }
69 
70  MythMediaStatus getStatus() const { return m_status; }
71 
72  const QString& getVolumeID() const { return m_volumeID; }
73  void setVolumeID(const char *vol) { m_volumeID = vol; }
74 
75  const QString& getKeyID() const { return m_keyID; }
76 
77  bool getAllowEject() const { return m_allowEject; }
78 
79  bool getLocked() const { return m_locked; }
80 
81  bool isDeviceOpen() const;
82 
84  bool isUsable() const
85  {
86  return m_status == MEDIASTAT_USEABLE
87  || m_status == MEDIASTAT_MOUNTED
88  || m_status == MEDIASTAT_NOTMOUNTED;
89  }
90 
91  MythMediaType getMediaType() const { return m_mediaType; }
92 
93  bool isSuperMount() const { return m_superMount; }
94 
96  virtual bool openDevice();
97  virtual bool closeDevice();
98  virtual bool isSameDevice(const QString &path);
99  virtual void setSpeed(int speed);
100  virtual void setDeviceSpeed(const char * /*devicePath*/, int /*speed*/) { }
101  virtual MythMediaStatus checkMedia() = 0;// Derived classes MUST implement this.
102  virtual MythMediaError eject(bool open_close = true);
103  virtual MythMediaError lock();
104  virtual MythMediaError unlock();
105  virtual bool performMountCmd( bool DoMount );
106 
107  bool mount() { return performMountCmd(true); }
108  bool unmount() { return performMountCmd(false); }
109 
110  bool isMounted(bool bVerify = true);
111  bool findMountPath();
112 
113  static void RegisterMediaExtensions(uint mediatype,
114  const QString& extensions);
115 
116 
117  static const std::array<const QString,9> kMediaStatusStrings;
118  static const std::array<const QString,3> kMediaErrorStrings;
119 
120  void clearData();
121 
122  QString MediaTypeString();
123 
124  static QString MediaTypeString(uint type);
125 
126  signals:
127  void statusChanged(MythMediaStatus oldStatus, MythMediaDevice* pMedia);
128 
129  protected:
130  ~MythMediaDevice() override = default; // use deleteLater...
131 
133  virtual void onDeviceMounted(void)
134  {
135  MythMediaType type = DetectMediaType();
136  if (type != MEDIATYPE_UNKNOWN)
137  m_mediaType = type;
138  }
139 
141  virtual void onDeviceUnmounted() {};
142 
143  MythMediaType DetectMediaType(void);
144  bool ScanMediaType(const QString &directory, ext_cnt_t &cnt);
145 
146  MythMediaStatus setStatus(MythMediaStatus newStat, bool CloseIt=false);
147 
148  QString m_deviceModel;
149  QString m_devicePath;
150  QString m_keyID;
152  QString m_mountPath;
154  QString m_realDevice;
156  QString m_volumeID;
158 
164 
166  bool m_locked {false};
167 
169 
174 
175  int m_deviceHandle {-1};
176  private:
181 };
182 
183 class MBASE_PUBLIC MythMediaEvent : public QEvent
184 {
185  public:
187  QEvent(kEventType), m_oldStatus(oldStatus), m_device(pDevice) {}
188  ~MythMediaEvent() override;
189 
190  MythMediaStatus getOldStatus(void) const { return m_oldStatus; }
191  MythMediaDevice* getDevice(void) { return m_device.isNull() ? nullptr : m_device.data(); }
192 
193  static const Type kEventType;
194 
195  protected:
197  QPointer<MythMediaDevice> m_device;
198 };
199 
200 #endif
MythMediaDevice::isUsable
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
MythMediaDevice::getMountPath
const QString & getMountPath() const
Definition: mythmedia.h:58
MythMediaEvent::getOldStatus
MythMediaStatus getOldStatus(void) const
Definition: mythmedia.h:190
MEDIASTAT_ERROR
@ MEDIASTAT_ERROR
Unable to mount, but could be usable.
Definition: mythmedia.h:13
MythMediaDevice::m_superMount
bool m_superMount
Is this a supermount device?.
Definition: mythmedia.h:168
MEDIATYPE_DVD
@ MEDIATYPE_DVD
Definition: mythmedia.h:29
MEDIASTAT_OPEN
@ MEDIASTAT_OPEN
CD/DVD tray open (meaningless for non-CDs?)
Definition: mythmedia.h:16
MythMediaDevice::mount
bool mount()
Definition: mythmedia.h:107
MythMediaDevice::getAllowEject
bool getAllowEject() const
Definition: mythmedia.h:77
MythMediaDevice::m_deviceModel
QString m_deviceModel
The device Manufacturer/Model. Read/write.
Definition: mythmedia.h:148
MythMediaDevice::setDeviceSpeed
virtual void setDeviceSpeed(const char *, int)
Definition: mythmedia.h:100
MythMediaDevice::setVolumeID
void setVolumeID(const char *vol)
Definition: mythmedia.h:73
MythMediaEvent::getDevice
MythMediaDevice * getDevice(void)
Definition: mythmedia.h:191
MythMediaDevice::testMedia
virtual MythMediaError testMedia()
Definition: mythmedia.h:95
MEDIATYPE_UNKNOWN
@ MEDIATYPE_UNKNOWN
Definition: mythmedia.h:25
mythburn.mediatype
int mediatype
Definition: mythburn.py:208
mythbaseexp.h
MythMediaEvent::m_device
QPointer< MythMediaDevice > m_device
Definition: mythmedia.h:197
MEDIASTAT_USEABLE
@ MEDIASTAT_USEABLE
Definition: mythmedia.h:19
MEDIATYPE_MIXED
@ MEDIATYPE_MIXED
Definition: mythmedia.h:27
MythMediaEvent::m_oldStatus
MythMediaStatus m_oldStatus
Definition: mythmedia.h:196
ext_to_media_t
QMap< QString, uint > ext_to_media_t
Definition: mythmedia.h:46
MythMediaDevice::getDevicePath
const QString & getDevicePath() const
Definition: mythmedia.h:61
MythMediaEvent::kEventType
static const Type kEventType
Definition: mythmedia.h:193
MythMediaDevice::getStatus
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
MythMediaDevice::getKeyID
const QString & getKeyID() const
Definition: mythmedia.h:75
MythMediaDevice::onDeviceUnmounted
virtual void onDeviceUnmounted()
Override this to perform any post unmount logic.
Definition: mythmedia.h:141
MythMediaDevice::s_ext_to_media
static ext_to_media_t s_ext_to_media
Map of extension to media type.
Definition: mythmedia.h:180
MythMediaDevice::getDeviceModel
const QString & getDeviceModel() const
Definition: mythmedia.h:67
MythMediaType
MythMediaType
Definition: mythmedia.h:24
MythMediaEvent::MythMediaEvent
MythMediaEvent(MythMediaStatus oldStatus, MythMediaDevice *pDevice)
Definition: mythmedia.h:186
MEDIASTAT_UNPLUGGED
@ MEDIASTAT_UNPLUGGED
Definition: mythmedia.h:15
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MEDIAERR_UNSUPPORTED
@ MEDIAERR_UNSUPPORTED
Definition: mythmedia.h:42
MythMediaDevice::getRealDevice
const QString & getRealDevice() const
Definition: mythmedia.h:63
MythMediaDevice::setDeviceModel
void setDeviceModel(const char *model)
Definition: mythmedia.h:68
MythMediaStatus
MythMediaStatus
Definition: mythmedia.h:12
MythMediaEvent
Definition: mythmedia.h:183
MEDIATYPE_MVIDEO
@ MEDIATYPE_MVIDEO
Definition: mythmedia.h:32
MythMediaDevice::unmount
bool unmount()
Definition: mythmedia.h:108
MythMediaDevice::onDeviceMounted
virtual void onDeviceMounted(void)
Override this to perform any post mount logic.
Definition: mythmedia.h:133
MythMediaDevice::isSuperMount
bool isSuperMount() const
Definition: mythmedia.h:93
MEDIASTAT_MOUNTED
@ MEDIASTAT_MOUNTED
Definition: mythmedia.h:21
MythMediaDevice::setMountPath
void setMountPath(const char *path)
Definition: mythmedia.h:59
MythMediaDevice::kMediaErrorStrings
static const std::array< const QString, 3 > kMediaErrorStrings
Definition: mythmedia.h:118
MEDIAERR_OK
@ MEDIAERR_OK
Definition: mythmedia.h:40
MEDIATYPE_MMUSIC
@ MEDIATYPE_MMUSIC
Definition: mythmedia.h:31
MEDIATYPE_VCD
@ MEDIATYPE_VCD
Definition: mythmedia.h:30
MediaMonitorDarwin
Definition: mediamonitor-darwin.h:21
MEDIATYPE_END
@ MEDIATYPE_END
Definition: mythmedia.h:35
MEDIATYPE_AUDIO
@ MEDIATYPE_AUDIO
Definition: mythmedia.h:28
MonitorThreadDarwin
Definition: mediamonitor-darwin.h:7
MEDIASTAT_UNFORMATTED
@ MEDIASTAT_UNFORMATTED
For devices/media a plugin might erase/format.
Definition: mythmedia.h:18
MythMediaDevice::m_devicePath
QString m_devicePath
The path to this media's device.
Definition: mythmedia.h:149
MEDIATYPE_BD
@ MEDIATYPE_BD
Definition: mythmedia.h:34
MythMediaDevice::m_allowEject
bool m_allowEject
Allow the user to eject the media?. Read only.
Definition: mythmedia.h:165
MythMediaDevice::kMediaStatusStrings
static const std::array< const QString, 9 > kMediaStatusStrings
Definition: mythmedia.h:117
MythMediaDevice::getLocked
bool getLocked() const
Definition: mythmedia.h:79
MEDIATYPE_MGALLERY
@ MEDIATYPE_MGALLERY
Definition: mythmedia.h:33
MEDIATYPE_DATA
@ MEDIATYPE_DATA
Definition: mythmedia.h:26
MythMediaDevice::getMediaType
MythMediaType getMediaType() const
Definition: mythmedia.h:91
MythMediaError
MythMediaError
Definition: mythmedia.h:39
MEDIASTAT_UNKNOWN
@ MEDIASTAT_UNKNOWN
Definition: mythmedia.h:14
MythMediaDevice
Definition: mythmedia.h:48
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
MEDIAERR_FAILED
@ MEDIAERR_FAILED
Definition: mythmedia.h:41
MEDIASTAT_NODISK
@ MEDIASTAT_NODISK
CD/DVD tray closed but empty, device unusable.
Definition: mythmedia.h:17
MythMediaDevice::getVolumeID
const QString & getVolumeID() const
Definition: mythmedia.h:72
ext_cnt_t
QMap< QString, uint > ext_cnt_t
Definition: mythmedia.h:45
uint
unsigned int uint
Definition: freesurround.h:24
MEDIASTAT_NOTMOUNTED
@ MEDIASTAT_NOTMOUNTED
Definition: mythmedia.h:20