Sayonara Player
AbstractPipeline.h
1 /* GSTPipeline.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 
23 #ifndef GSTPIPELINE_H
24 #define GSTPIPELINE_H
25 
26 #include "Helper/Settings/SayonaraClass.h"
27 
28 #include <QTimer>
29 #include <gst/gst.h>
30 #include <gst/gstbuffer.h>
31 #include <QTimer>
32 
33 
34 enum class GSTFileMode : quint8 {
35  File,
36  Http
37 };
38 
39 bool
40 _test_and_error(void* element, QString errorstr);
41 
42 bool
43 _test_and_error_bool(bool b, QString errorstr);
44 
45 class Engine;
47  public QObject,
48  protected SayonaraClass
49 {
50 
51  Q_OBJECT
52 
53  signals:
54  void sig_duration_changed();
55 
56  private:
57  bool _about_to_finish;
58  bool _initialized;
59  Engine* _engine=nullptr;
60  QTimer* _progress_timer=nullptr;
61 
62  protected:
63 
64  QString _name;
65 
66  GstBus* _bus=nullptr;
67  GstElement* _pipeline=nullptr;
68  gchar* _uri=nullptr;
69 
70  qint64 _duration_ms;
71  qint64 _position_ms;
72 
73  bool tee_connect(GstElement* tee,
74  GstPadTemplate* tee_src_pad_template,
75  GstElement* queue,
76  const QString& queue_name
77  );
78  bool create_element(GstElement** elem, const gchar* elem_name, const gchar* name="");
79 
80  virtual bool create_elements()=0;
81  virtual bool add_and_link_elements()=0;
82  virtual bool configure_elements()=0;
83 
84  virtual quint64 get_about_to_finish_time() const;
85 
86  signals:
87  void sig_finished();
88  void sig_about_to_finish(qint64);
89  void sig_pos_changed_ms(qint64);
90  void sig_data(uchar*, quint64);
91 
92 
93  public slots:
94  virtual void play()=0;
95  virtual void pause()=0;
96  virtual void stop()=0;
97 
98 
99 
100  public:
101  AbstractPipeline(QString name, Engine* engine, QObject* parent=nullptr);
102  virtual ~AbstractPipeline();
103 
104  virtual GstElement* get_source() const=0;
105  virtual bool init(GstState state=GST_STATE_READY);
106  virtual GstElement* get_pipeline() const;
107  virtual GstBus* get_bus();
108  virtual GstState get_state();
109  virtual void refresh_position();
110  virtual void refresh_duration();
111  virtual void finished();
112  virtual void check_about_to_finish();
113  virtual qint64 get_time_to_go() const;
114  virtual void set_data(uchar* data, quint64 size);
115 
116  virtual bool set_uri(gchar* uri);
117  virtual gchar* get_uri();
118 
119  virtual qint64 get_duration_ms() final;
120  virtual qint64 get_position_ms() final;
121 
122  bool has_element(GstElement* e) const;
123 };
124 
125 
126 #endif // GSTPIPELINE_H
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: AbstractEngine.h:40
Definition: AbstractPipeline.h:46