Sayonara Player
Engine.h
1 /* PlaybackEngine.h */
2 
3 /* Copyright (C) 2011-2019 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 "SoundOutReceiver.h"
26 #include <QObject>
27 #include <gst/gst.h>
28 
29 #include <QImage>
30 
31 class SpectrumReceiver;
32 class LevelReceiver;
33 
34 namespace StreamRecorder
35 {
36  class StreamRecorder;
37 }
38 
39 namespace Engine
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 sig_data(const unsigned char* data, uint64_t n_bytes);
70  void sig_spectrum_changed();
71  void sig_level_changed();
72 
73  void sig_metadata_changed(const MetaData& md);
74  void sig_duration_changed(const MetaData& md);
75  void sig_bitrate_changed(const MetaData& md);
76  void sig_cover_data(const QByteArray& data, const QString& mimetype);
77 
78  void sig_current_position_changed(MilliSeconds ms);
79  void sig_buffering(int progress);
80  void sig_track_finished();
81  void sig_track_ready();
82  void sig_error(const QString& error_message);
83 
84  public:
85  explicit Engine(QObject* parent=nullptr);
86  ~Engine();
87 
88  void update_bitrate(Bitrate br, GstElement* src);
89  void update_duration(GstElement* src);
90 
91  void set_track_ready(GstElement* src);
92  void set_track_almost_finished(MilliSeconds time2go);
93  void set_track_finished(GstElement* src);
94 
95  bool is_streamrecroder_recording() const;
96  void set_streamrecorder_recording(bool b);
97 
98  void set_spectrum(const SpectrumList& vals);
99  SpectrumList spectrum() const;
100 
101  void set_level(float left, float right);
102  QPair<float, float> level() const;
103 
104  void set_broadcast_enabled(bool b);
105  void set_equalizer(int band, int value);
106 
107  MetaData current_track() const;
108 
109 
110  public slots:
111  void play();
112  void stop();
113  void pause();
114 
115  void jump_abs_ms(MilliSeconds pos_ms);
116  void jump_rel_ms(MilliSeconds pos_ms);
117  void jump_rel(double percent);
118  void update_metadata(const MetaData& md, GstElement* src);
119  void update_cover(GstElement* src, const QByteArray& data, const QString& mimedata);
120 
121  bool change_track(const MetaData& md);
122 
123  void set_buffer_state(int progress, GstElement* src);
124  void error(const QString& error);
125 
126  private:
127  PipelinePtr init_pipeline(const QString& name);
128  bool change_metadata(const MetaData& md);
129 
130  bool change_track_crossfading(const MetaData& md);
131  bool change_track_gapless(const MetaData& md);
132  bool change_track_immediatly(const MetaData& md);
133 
134  void set_current_position_ms(MilliSeconds pos_ms);
135 
136  private slots:
137  void s_gapless_changed();
138  void s_streamrecorder_active_changed();
139 
140  void cur_pos_ms_changed(MilliSeconds pos_ms);
141  };
142 }
143 
144 #endif /* GSTENGINE_H_ */
QPair
Definition: typedefs.h:32
SpectrumReceiver
The SpectrumReceiver class.
Definition: SoundOutReceiver.h:46
LevelReceiver
The LevelReceiver class.
Definition: SoundOutReceiver.h:32
MetaData
The MetaData class.
Definition: MetaData.h:44
Engine::Engine
The PlaybackEngine class.
Definition: Engine.h:47