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 "Utils/Settings/SayonaraClass.h"
25 #include "Utils/Pimpl.h"
26 
27 #include <gst/gst.h>
28 #include <gst/gstbuffer.h>
29 
30 #include <memory>
31 
32 #include <QTimer>
33 
34 namespace Engine
35 {
36  class Base;
37 }
38 
39 namespace Pipeline
40 {
45  enum class GSTFileMode : uint8_t
46  {
47  File,
48  Http
49  };
50 
51  bool
52  test_and_error(void* element, const QString& errorstr);
53 
54  bool
55  test_and_error_bool(bool b, const QString& errorstr);
56 
61  class Base :
62  public QObject,
63  public SayonaraClass
64  {
65  Q_OBJECT
66  PIMPL(Base)
67 
68  signals:
69  void sig_duration_changed();
70 
71  protected:
72 
73  bool _about_to_finish;
74  QString _name;
75 
76  GstBus* _bus=nullptr;
77  GstElement* _pipeline=nullptr;
78  gchar* _uri=nullptr;
79 
80  int64_t _duration_ms;
81  int64_t _position_source_ms;
82  int64_t _position_pipeline_ms;
83 
84  bool tee_connect(GstElement* tee,
85  GstPadTemplate* tee_src_pad_template,
86  GstElement* queue,
87  const QString& queue_name
88  );
89  bool create_element(GstElement** elem, const gchar* elem_name, const gchar* name="");
90 
91  virtual bool create_elements()=0;
92  virtual bool add_and_link_elements()=0;
93  virtual bool configure_elements()=0;
94 
95  virtual uint64_t get_about_to_finish_time() const;
96 
97  signals:
98  void sig_finished();
99  void sig_about_to_finish(int64_t);
100  void sig_pos_changed_ms(int64_t);
101  void sig_data(uchar*, uint64_t);
102 
103 
104  public slots:
105  virtual void play();
106  virtual void pause();
107  virtual void stop();
108 
109 
110  public:
111  Base(QString name, Engine::Base* engine, QObject* parent=nullptr);
112  virtual ~Base();
113 
114  virtual GstElement* get_source() const=0;
115  virtual bool init(GstState state=GST_STATE_READY);
116  virtual GstElement* get_pipeline() const;
117  virtual GstState get_state();
118  virtual void refresh_position();
119 
120  virtual void finished();
121  virtual void check_about_to_finish();
122  virtual int64_t get_time_to_go() const;
123  virtual void set_data(uchar* data, uint64_t size);
124 
125  virtual bool set_uri(gchar* uri);
126 
127  void update_duration_ms(int64_t duration_ms, GstElement* src);
128  virtual int64_t get_duration_ms() const final ;
129  virtual int64_t get_source_position_ms() const final;
130  virtual int64_t get_pipeline_position_ms() const final;
131 
132  bool has_element(GstElement* e) const;
133  };
134 }
135 
136 #endif // GSTPIPELINE_H
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
Definition: AbstractEngine.h:33
The AbstractPipeline class.
Definition: AbstractPipeline.h:61
The Engine class.
Definition: AbstractEngine.h:51
GSTFileMode
The GSTFileMode enum.
Definition: AbstractPipeline.h:45
Definition: AbstractPipeline.h:39