File indexing completed on 2024-12-01 04:21:25

0001 /*
0002     Copyright (C) 2011 Harald Sitter <sitter@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef PHONON_VLC_MEDIA_H
0019 #define PHONON_VLC_MEDIA_H
0020 
0021 #include <QtCore/QObject>
0022 #include <QtCore/QStringBuilder>
0023 #include <QtCore/QVariant>
0024 
0025 #include <vlc/libvlc.h>
0026 #include <vlc/libvlc_version.h>
0027 #if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0))
0028 // Bit of a work around. media.h requires picture
0029 #include <vlc/libvlc_picture.h>
0030 #endif
0031 #include <vlc/libvlc_media.h>
0032 
0033 #define INTPTR_PTR(x) reinterpret_cast<intptr_t>(x)
0034 #define INTPTR_FUNC(x) reinterpret_cast<intptr_t>(&x)
0035 
0036 namespace Phonon {
0037 namespace VLC {
0038 
0039 class Media : public QObject
0040 {
0041     Q_OBJECT
0042 public:
0043     explicit Media(const QByteArray &mrl, QObject *parent = nullptr);
0044     ~Media();
0045 
0046     inline libvlc_media_t *libvlc_media() const { return m_media; }
0047     inline operator libvlc_media_t *() const { return m_media; }
0048 
0049     inline void addOption(const QString &option, const QVariant &argument)
0050     {
0051         addOption(option % argument.toString());
0052     }
0053 
0054     inline void addOption(const QString &option, intptr_t functionPtr)
0055     {
0056         QString optionWithPtr = option;
0057         optionWithPtr.append(QString::number(static_cast<qint64>(functionPtr)));
0058         addOption(optionWithPtr);
0059     }
0060 
0061     void addOption(const QString &option);
0062 
0063     QString meta(libvlc_meta_t meta);
0064 
0065     void setCdTrack(int track);
0066 
0067 Q_SIGNALS:
0068     void durationChanged(qint64 duration);
0069     void metaDataChanged();
0070 
0071 private:
0072     static void event_cb(const libvlc_event_t *event, void *opaque);
0073 
0074     libvlc_media_t *m_media;
0075     libvlc_state_t m_state;
0076     QByteArray m_mrl;
0077 };
0078 
0079 } // namespace VLC
0080 } // namespace Phonon
0081 
0082 #endif // PHONON_VLC_MEDIA_H