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