File indexing completed on 2024-06-16 04:38:29

0001 /*
0002     SPDX-FileCopyrightText: 2003 Fabrice Bellard
0003     SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef FFPLAYER_H
0009 #define FFPLAYER_H
0010 
0011 #include "videoplayer/backend/decoder.h"
0012 #include "videoplayer/backend/audiodecoder.h"
0013 #include "videoplayer/backend/videodecoder.h"
0014 #include "videoplayer/backend/subtitledecoder.h"
0015 #include "videoplayer/backend/framequeue.h"
0016 #include "videoplayer/backend/packetqueue.h"
0017 #include "videoplayer/backend/clock.h"
0018 #include "videoplayer/backend/streamdemuxer.h"
0019 #include "videoplayer/backend/videostate.h"
0020 
0021 #include <QtGlobal>
0022 #include <QObject>
0023 #include <QTimer>
0024 
0025 extern "C" {
0026 #include "libavformat/avformat.h"
0027 }
0028 
0029 
0030 QT_FORWARD_DECLARE_CLASS(QThread)
0031 QT_FORWARD_DECLARE_CLASS(QWaitCondition)
0032 
0033 namespace SubtitleComposer {
0034 class VideoPlayer;
0035 class GLRenderer;
0036 
0037 class FFPlayer : public QObject {
0038     Q_OBJECT
0039 
0040 public:
0041     FFPlayer(QObject *parent=nullptr);
0042     virtual ~FFPlayer();
0043 
0044     static uint8_t *flushPkt();
0045 
0046     bool open(const char *filename);
0047     void close();
0048 
0049     inline double position() { return m_vs == nullptr ? 0.0 : m_vs->position(); }
0050 
0051     void pauseToggle();
0052     bool paused();
0053     void stepFrame(int frameCnt);
0054 
0055     void seek(double seconds);
0056 
0057     bool muted() { return m_muted; }
0058     void setMuted(bool mute);
0059     double volume() { return m_volume; }
0060     void setVolume(double volume);
0061 
0062     void setSpeed(double speed);
0063 
0064     quint32 videoWidth();
0065     quint32 videoHeight();
0066     qreal videoSAR();
0067     qreal videoFPS();
0068 
0069     int activeVideoStream();
0070     int activeAudioStream();
0071     void activeAudioStream(int streamIndex);
0072     int activeSubtitleStream();
0073 
0074     enum State { Stopped, Playing, Paused };
0075     Q_ENUM(FFPlayer::State)
0076 
0077     inline GLRenderer * renderer() const { return m_renderer; }
0078 
0079 signals:
0080     void mediaLoaded();
0081     void stateChanged(FFPlayer::State state);
0082 
0083     void positionChanged(double pos);
0084     void durationChanged(double duration);
0085     void speedChanged(double speed);
0086 
0087     void volumeChanged(double volume);
0088     void muteChanged(bool muted);
0089 
0090     void videoStreamsChanged(const QStringList &streams);
0091     void audioStreamsChanged(const QStringList &streams);
0092     void subtitleStreamsChanged(const QStringList &streams);
0093 
0094 private:
0095     bool m_muted;
0096     double m_volume;
0097 
0098     QTimer m_positionTimer;
0099     qint32 m_postitionLast;
0100     VideoState *m_vs;
0101     GLRenderer *m_renderer;
0102 };
0103 }
0104 
0105 Q_DECLARE_METATYPE(SubtitleComposer::FFPlayer::State)
0106 
0107 #endif // FFPLAYER_H