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 
66  void update_bitrate(quint32 br, GstElement* src) override;
67  void update_duration(GstElement* src) override;
68  void set_about_to_finish(qint64 time2go) override;
69  void set_cur_position_ms(qint64 pos_ms) override;
70 
71  void set_streamrecorder_recording(bool b);
72 
73  void set_spectrum(const QList<float>& vals);
74  void add_spectrum_receiver(SpectrumReceiver* receiver);
75 
76  void set_level(float left, float right);
77  void add_level_receiver(LevelReceiver* receiver);
78 
79  void set_n_sound_receiver(int num_sound_receiver);
80 
81  void set_equalizer(int band, int value);
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 
105 
106 private:
107 
108  PlaybackPipeline* _pipeline=nullptr;
109  PlaybackPipeline* _other_pipeline=nullptr;
110 
111  QList<LevelReceiver*> _level_receiver;
112  QList<SpectrumReceiver*> _spectrum_receiver;
113 
114  QTimer* _gapless_timer=nullptr;
115  GaplessState _gapless_state;
116 
117  bool _sr_active;
118 
119  StreamRecorder* _stream_recorder=nullptr;
120 
121 private:
122 
123  bool set_uri(const QString& filepath);
124  void change_track_gapless(const MetaData& md);
125  void change_gapless_state(GaplessState state);
126 
127 
128 private slots:
129  void _playlist_mode_changed();
130  void _streamrecorder_active_changed();
131 
132 };
133 
134 
135 #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:37
Definition: SoundOutReceiver.h:33