Sayonara Player
PlaybackEngine.h
1 /* PlaybackEngine.h */
2 
3 /* Copyright (C) 2011-2017 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 "Components/Engine/AbstractEngine.h"
25 
26 #include <glib.h>
27 #include <gst/gstbuffer.h>
28 
29 #include <QList>
30 #include <QtGlobal>
31 
32 class QTimer;
33 class QString;
34 class PlaybackPipeline;
35 class StreamRecorder;
36 class SpectrumReceiver;
37 class LevelReceiver;
38 
43 enum class GaplessState : quint8
44 {
45  NoGapless=0, // no gapless enabled at all
46  AboutToFinish, // the phase when the new track is already displayed but not played yet
47  TrackFetched, // track is requested, but no yet there
48  Playing // currently playing
49 };
50 
56  public Engine
57 {
58  Q_OBJECT
59 
60 signals:
61  void sig_data(const uchar* data, quint64 n_bytes);
62 
63 public:
64  explicit PlaybackEngine(QObject* parent=nullptr);
65  ~PlaybackEngine();
66 
67  bool init() override;
68  void init_other_pipeline();
69 
70  void set_track_finished(GstElement* src) override;
71 
72  void update_bitrate(quint32 br, GstElement* src) override;
73  void update_duration(GstElement* src) override;
74  void set_about_to_finish(qint64 time2go) override;
75  void set_cur_position_ms(qint64 pos_ms) override;
76 
77  void set_streamrecorder_recording(bool b);
78 
79  int get_spectrum_bins() const;
80  void set_spectrum(const QList<float>& vals);
81  void add_spectrum_receiver(SpectrumReceiver* receiver);
82 
83  void set_level(float left, float right);
84  void add_level_receiver(LevelReceiver* receiver);
85 
86  void set_n_sound_receiver(int num_sound_receiver);
87 
88  void set_equalizer(int band, int value);
89 
90  void emit_buffer(float inv_array_elements, float scale);
91 
92 public slots:
93 
94  void play() override;
95  void stop() override;
96  void pause() override;
97 
98  void jump_abs_ms(quint64 pos_ms) override;
99  void jump_rel_ms(quint64 pos_ms) override;
100  void jump_rel(double percent) override;
101  void update_md(const MetaData& md, GstElement* src) override;
102  void update_cover(const QImage& img, GstElement* src) override;
103  void change_track(const MetaData& md) override;
104  void change_track(const QString& filepath) override;
105 
106  void set_track_ready(GstElement* src) override;
107  void set_buffer_state(int progress, GstElement* src) override;
108 
109  void gapless_timed_out();
110 
111 
112 private:
113  PlaybackPipeline* _pipeline=nullptr;
114  PlaybackPipeline* _other_pipeline=nullptr;
115 
116  QList<LevelReceiver*> _level_receiver;
117  QList<SpectrumReceiver*> _spectrum_receiver;
118 
119  QTimer* _gapless_timer=nullptr;
120  GaplessState _gapless_state;
121 
122  bool _sr_active;
123 
124  StreamRecorder* _stream_recorder=nullptr;
125 
126 private:
127  bool set_uri(const QString& filepath);
128  void change_track_gapless(const MetaData& md);
129  void change_gapless_state(GaplessState state);
130 
131 
132 private slots:
133  void _playlist_mode_changed();
134  void _streamrecorder_active_changed();
135 };
136 
137 #endif /* GSTENGINE_H_ */
The LevelReceiver class.
Definition: SoundOutReceiver.h:30
The MetaData class MetaDataHelper.
Definition: MetaData.h:55
The Engine class.
Definition: AbstractEngine.h:49
The StreamRecorder class.
Definition: StreamRecorder.h:36
GaplessState
The GaplessState enum.
Definition: PlaybackEngine.h:43
The PlaybackEngine class.
Definition: PlaybackEngine.h:55
The PlaybackPipeline class.
Definition: PlaybackPipeline.h:37
The SpectrumReceiver class.
Definition: SoundOutReceiver.h:43