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/AudioDataReceiver.h"
26 
27 #include <QObject>
28 #include <QImage>
29 
30 #include <gst/gst.h>
31 
32 #include <vector>
33 
34 namespace StreamRecorder
35 {
36  class StreamRecorder;
37 }
38 
39 class PlayManager;
40 
41 namespace Engine
42 {
43  class SpectrumDataReceiver;
44  class LevelDataReceiver;
45 
46  class Pipeline;
47  using PipelinePtr=std::shared_ptr<Pipeline>;
52  class Engine :
53  public QObject
54  {
55 
56  Q_OBJECT
57  PIMPL(Engine)
58 
59  private:
64  enum class GaplessState : uint8_t
65  {
66  NoGapless=0, // no gapless enabled at all
67  AboutToFinish, // the phase when the new track is already displayed but not played yet
68  TrackFetched, // track is requested, but no yet there
69  Playing, // currently playing
70  Stopped
71  };
72 
73  signals:
74  void sigDataAvailable(const QByteArray& data);
75  void sigSpectrumChanged();
76  void sigLevelChanged();
77 
78  void sigMetadataChanged(const MetaData& md);
79  void sigDurationChanged(const MetaData& md);
80  void sigBitrateChanged(const MetaData& md);
81  void sigCoverDataAvailable(const QByteArray& data, const QString& mimetype);
82 
83  void sigCurrentPositionChanged(MilliSeconds ms);
84  void sigBuffering(int progress);
85  void sigTrackFinished();
86  void sigTrackReady();
87  void sigError(const QString& error_message);
88 
89  public:
90  explicit Engine(PlayManager* playManager, QObject* parent=nullptr);
91  ~Engine();
92 
93  void updateBitrate(Bitrate br, GstElement* src);
94  void updateDuration(GstElement* src);
95 
96  void setTrackReady(GstElement* src);
97  void setTrackAlmostFinished(MilliSeconds time2go);
98  void setTrackFinished(GstElement* src);
99 
100  bool isStreamRecorderRecording() const;
101  void setStreamRecorderRecording(bool b);
102 
103  void setSpectrum(const std::vector<float>& spectrum);
104  const std::vector<float>& spectrum() const;
105 
106  void setLevel(float left, float right);
107  QPair<float, float> level() const;
108 
109  void setVisualizerEnabled(bool levelEnabled, bool spectrumEnabled);
110  void setBroadcastEnabled(bool b);
111  void setEqualizer(int band, int value);
112 
113  MetaData currentTrack() const;
114 
115  public slots:
116  void play();
117  void stop();
118  void pause();
119 
120  void jumpAbsMs(MilliSeconds pos_ms);
121  void jumpRelMs(MilliSeconds pos_ms);
122  void jumpRel(double percent);
123  void updateMetadata(const MetaData& track, GstElement* src);
124  void updateCover(GstElement* src, const QByteArray& data, const QString& mimedata);
125 
126  bool changeTrack(const MetaData& track);
127 
128  void setBufferState(int progress, GstElement* src);
129  void error(const QString& error, const QString& elementName);
130 
131  private:
132  PipelinePtr initPipeline(const QString& name);
133  bool changeMetadata(const MetaData& track);
134 
135  void swapPipelines();
136  bool changeTrackCrossfading(const MetaData& track);
137  bool changeTrackGapless(const MetaData& track);
138  bool changeTrackImmediatly(const MetaData& track);
139 
140  void setCurrentPositionMs(MilliSeconds pos_ms);
141 
142  private slots:
143  void gaplessChanged();
144  void streamrecorderActiveChanged();
145  void currentPositionChanged(MilliSeconds pos_ms);
146  };
147 }
148 
149 #endif /* GSTENGINE_H_ */
The PlaybackEngine class.
Definition: Engine.h:54
The MetaData class.
Definition: MetaData.h:47
Global handler for current playback state (Singleton)
Definition: PlayManager.h:36
Definition: typedefs.h:33