Sayonara Player
Engine.h
1 /* PlaybackEngine.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef GSTPLAYBACKENGINE_H_
22 #define GSTPLAYBACKENGINE_H_
23 
24 #include "Utils/Pimpl.h"
25 #include "Interfaces/Engine/AudioDataReceiverInterface.h"
26 #include <QObject>
27 #include <gst/gst.h>
28 
29 #include <QImage>
30 
31 namespace StreamRecorder
32 {
33  class StreamRecorder;
34 }
35 
36 namespace Engine
37 {
38  class SpectrumReceiver;
39  class LevelReceiver;
40 
41  class Pipeline;
42  using PipelinePtr=std::shared_ptr<Pipeline>;
47  class Engine :
48  public QObject
49  {
50 
51  Q_OBJECT
52  PIMPL(Engine)
53 
54  private:
59  enum class GaplessState : uint8_t
60  {
61  NoGapless=0, // no gapless enabled at all
62  AboutToFinish, // the phase when the new track is already displayed but not played yet
63  TrackFetched, // track is requested, but no yet there
64  Playing, // currently playing
65  Stopped
66  };
67 
68  signals:
69  void sigDataAvailable(const QByteArray& data);
70  void sigSpectrumChanged();
71  void sigLevelChanged();
72 
73  void sigMetadataChanged(const MetaData& md);
74  void sigDurationChanged(const MetaData& md);
75  void sigBitrateChanged(const MetaData& md);
76  void sigCoverDataAvailable(const QByteArray& data, const QString& mimetype);
77 
78  void sigCurrentPositionChanged(MilliSeconds ms);
79  void sigBuffering(int progress);
80  void sigTrackFinished();
81  void sigTrackReady();
82  void sigError(const QString& error_message);
83 
84  public:
85  explicit Engine(QObject* parent=nullptr);
86  ~Engine();
87 
88  void updateBitrate(Bitrate br, GstElement* src);
89  void updateDuration(GstElement* src);
90 
91  void setTrackReady(GstElement* src);
92  void setTrackAlmostFinished(MilliSeconds time2go);
93  void setTrackFinished(GstElement* src);
94 
95  bool isStreamRecorderRecording() const;
96  void setStreamRecorderRecording(bool b);
97 
98  void setSpectrum(const SpectrumList& vals);
99  SpectrumList spectrum() const;
100 
101  void setLevel(float left, float right);
102  QPair<float, float> level() const;
103 
104  void setVisualizerEnabled(bool levelEnabled, bool spectrumEnabled);
105  void setBroadcastEnabled(bool b);
106  void setEqualizer(int band, int value);
107 
108  MetaData currentTrack() const;
109 
110  public slots:
111  void play();
112  void stop();
113  void pause();
114 
115  void jumpAbsMs(MilliSeconds pos_ms);
116  void jumpRelMs(MilliSeconds pos_ms);
117  void jumpRel(double percent);
118  void updateMetadata(const MetaData& md, GstElement* src);
119  void updateCover(GstElement* src, const QByteArray& data, const QString& mimedata);
120 
121  bool changeTrack(const MetaData& md);
122 
123  void setBufferState(int progress, GstElement* src);
124  void error(const QString& error, const QString& elementName);
125 
126  private:
127  PipelinePtr initPipeline(const QString& name);
128  bool changeMetadata(const MetaData& md);
129 
130  void swapPipelines();
131  bool changeTrackCrossfading(const MetaData& md);
132  bool changeTrackGapless(const MetaData& md);
133  bool changeTrackImmediatly(const MetaData& md);
134 
135  void setCurrentPositionMs(MilliSeconds pos_ms);
136 
137  private slots:
138  void gaplessChanged();
139  void streamrecorderActiveChanged();
140  void currentPositionChanged(MilliSeconds pos_ms);
141  };
142 }
143 
144 #endif /* GSTENGINE_H_ */
QPair
Definition: typedefs.h:32
MetaData
The MetaData class.
Definition: MetaData.h:47
Engine::Engine
The PlaybackEngine class.
Definition: Engine.h:49