File indexing completed on 2025-01-19 03:57:05

0001 /*********************************************************
0002  * Copyright (C) 2020, Val Doroshchuk <valbok@gmail.com> *
0003  *                                                       *
0004  * This file is part of QtAVPlayer.                      *
0005  * Free Qt Media Player based on FFmpeg.                 *
0006  *********************************************************/
0007 
0008 #ifndef QAVPLAYER_H
0009 #define QAVPLAYER_H
0010 
0011 #include <QtAVPlayer/qavvideoframe.h>
0012 #include <QtAVPlayer/qavaudioframe.h>
0013 #include <QtAVPlayer/qavsubtitleframe.h>
0014 #include <QtAVPlayer/qavstream.h>
0015 #include <QtAVPlayer/qtavplayerglobal.h>
0016 #include <QString>
0017 #include <memory>
0018 
0019 QT_BEGIN_NAMESPACE
0020 
0021 class QAVIODevice;
0022 class QAVPlayerPrivate;
0023 class QAVPlayer : public QObject
0024 {
0025     Q_OBJECT
0026     Q_ENUMS(State)
0027     Q_ENUMS(MediaStatus)
0028     Q_ENUMS(Error)
0029 
0030 public:
0031     enum State
0032     {
0033         StoppedState,
0034         PlayingState,
0035         PausedState
0036     };
0037 
0038     enum MediaStatus
0039     {
0040         NoMedia,
0041         LoadedMedia,
0042         EndOfMedia,
0043         InvalidMedia
0044     };
0045 
0046     enum Error
0047     {
0048         NoError,
0049         ResourceError,
0050         FilterError
0051     };
0052 
0053     QAVPlayer(QObject *parent = nullptr);
0054     ~QAVPlayer();
0055 
0056     void setSource(const QString &url, const QSharedPointer<QAVIODevice> &dev = {});
0057     QString source() const;
0058 
0059     QList<QAVStream> availableVideoStreams() const;
0060     QList<QAVStream> currentVideoStreams() const;
0061     void setVideoStream(const QAVStream &stream);
0062     void setVideoStreams(const QList<QAVStream> &streams);
0063 
0064     QList<QAVStream> availableAudioStreams() const;
0065     QList<QAVStream> currentAudioStreams() const;
0066     void setAudioStream(const QAVStream &stream);
0067     void setAudioStreams(const QList<QAVStream> &streams);
0068 
0069     QList<QAVStream> availableSubtitleStreams() const;
0070     QList<QAVStream> currentSubtitleStreams() const;
0071     void setSubtitleStream(const QAVStream &stream);
0072     void setSubtitleStreams(const QList<QAVStream> &streams);
0073 
0074     State state() const;
0075     MediaStatus mediaStatus() const;
0076     qint64 duration() const;
0077     qint64 position() const;
0078     qreal speed() const;
0079     double videoFrameRate() const;
0080 
0081     void setFilter(const QString &desc);
0082     void setFilters(const QList<QString> &filters);
0083     QList<QString> filters() const;
0084 
0085     void setBitstreamFilter(const QString &desc);
0086     QString bitstreamFilter() const;
0087 
0088     bool isSeekable() const;
0089 
0090     bool isSynced() const;
0091     void setSynced(bool sync);
0092 
0093     QString inputFormat() const;
0094     void setInputFormat(const QString &format);
0095 
0096     QString inputVideoCodec() const;
0097     void setInputVideoCodec(const QString &codec);
0098     static QStringList supportedVideoCodecs();
0099 
0100     QMap<QString, QString> inputOptions() const;
0101     void setInputOptions(const QMap<QString, QString> &opts);
0102 
0103     QAVStream::Progress progress(const QAVStream &stream) const;
0104 
0105 public Q_SLOTS:
0106     void play();
0107     void pause();
0108     void stop();
0109     void seek(qint64 position);
0110     void setSpeed(qreal rate);
0111     void stepForward();
0112     void stepBackward();
0113 
0114 Q_SIGNALS:
0115     void sourceChanged(const QString &url);
0116     void stateChanged(QAVPlayer::State newState);
0117     void mediaStatusChanged(QAVPlayer::MediaStatus status);
0118     void errorOccurred(QAVPlayer::Error, const QString &str);
0119     void durationChanged(qint64 duration);
0120     void seekableChanged(bool seekable);
0121     void speedChanged(qreal rate);
0122     void videoFrameRateChanged(double rate);
0123     void videoStreamsChanged(const QList<QAVStream> &streams);
0124     void audioStreamsChanged(const QList<QAVStream> &streams);
0125     void subtitleStreamsChanged(const QList<QAVStream> &streams);
0126     void played(qint64 pos);
0127     void paused(qint64 pos);
0128     void stopped(qint64 pos);
0129     void stepped(qint64 pos);
0130     void seeked(qint64 pos);
0131     void filtersChanged(const QList<QString> &filters);
0132     void bitstreamFilterChanged(const QString &desc);
0133     void syncedChanged(bool sync);
0134     void inputFormatChanged(const QString &format);
0135     void inputVideoCodecChanged(const QString &codec);
0136     void inputOptionsChanged(const QMap<QString, QString> &opts);
0137 
0138     void videoFrame(const QAVVideoFrame &frame);
0139     void audioFrame(const QAVAudioFrame &frame);
0140     void subtitleFrame(const QAVSubtitleFrame &frame);
0141 
0142 protected:
0143     std::unique_ptr<QAVPlayerPrivate> d_ptr;
0144 
0145 private:
0146     Q_DISABLE_COPY(QAVPlayer)
0147     Q_DECLARE_PRIVATE(QAVPlayer)
0148 };
0149 
0150 #ifndef QT_NO_DEBUG_STREAM
0151 QDebug operator<<(QDebug, QAVPlayer::State);
0152 QDebug operator<<(QDebug, QAVPlayer::MediaStatus);
0153 QDebug operator<<(QDebug, QAVPlayer::Error);
0154 #endif
0155 
0156 Q_DECLARE_METATYPE(QAVPlayer::State)
0157 Q_DECLARE_METATYPE(QAVPlayer::MediaStatus)
0158 Q_DECLARE_METATYPE(QAVPlayer::Error)
0159 
0160 QT_END_NAMESPACE
0161 
0162 #endif