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