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