Music Hub ..
A session-wide music playback service
Loading...
Searching...
No Matches
playbin.h
Go to the documentation of this file.
1/*
2 * Copyright © 2013 Canonical Ltd.
3 * Copyright © 2022 UBports Foundation.
4 *
5 * Contact: Alberto Mardegan <mardy@users.sourceforge.net>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License version 3,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Authored by: Thomas Voß <thomas.voss@canonical.com>
20 */
21
22#ifndef GSTREAMER_PLAYBIN_H
23#define GSTREAMER_PLAYBIN_H
24
25#include "bus.h"
26#include "player.h"
27
28#include <QObject>
29#include <QString>
30#include <QUrl>
31
32#include <gio/gio.h>
33#include <gst/gst.h>
34
35#include <chrono>
36#include <string>
37
38// Uncomment to generate a dot file at the time that the pipeline
39// goes to the PLAYING state. Make sure to export GST_DEBUG_DUMP_DOT_DIR
40// before starting media-hub-server. To convert the dot file to some
41// other image format, use: dot pipeline.dot -Tpng -o pipeline.png
42//#define DEBUG_GST_PIPELINE
43
44namespace gstreamer
45{
46class Playbin: public QObject
47{
48 Q_OBJECT
49
50public:
52 {
56 };
57
64
66
67 static const std::string& pipeline_name();
68
69 static void about_to_finish(GstElement*, gpointer user_data);
70
71 static void source_setup(GstElement*,
72 GstElement *source,
73 gpointer user_data);
74 static void streams_changed(GstElement*, gpointer user_data);
75
77 ~Playbin();
78
79 void reset();
80 void reset_pipeline();
81
82 void on_new_message(const Bus::Message& message);
84 void process_message_element(GstMessage *message);
85
87
89
90 void create_video_sink(uint32_t texture_id);
91
92 void set_volume(double new_volume);
93
96
99
101 uint64_t position() const;
103 uint64_t duration() const;
104
105 void set_uri(const QUrl &uri, const lomiri::MediaHubService::Player::HeadersType& headers, bool do_pipeline_reset = true);
106 QUrl uri() const;
107
108 void setup_source(GstElement *source);
109 void updateMediaFileType();
110
111 // Sets the pipeline's state (stopped, playing, paused, etc).
112 bool set_state(GstState new_state);
113 bool seek(const std::chrono::microseconds& ms);
114
115 QSize get_video_dimensions() const;
116
117 QString file_info_from_uri(const QUrl &uri) const;
118 QString get_file_content_type(const QUrl &uri) const;
119
120 bool is_audio_file(const QUrl &uri) const;
121 bool is_video_file(const QUrl &uri) const;
122
123 MediaFileType mediaFileType() const;
124
125 bool can_play_streams() const;
126
127 GstElement* pipeline;
130 GstElement* video_sink;
131 GstElement* audio_sink;
133 mutable uint64_t previous_position;
145
146Q_SIGNALS:
150
152 void seekedTo(uint64_t offset);
154 const QByteArray &source);
158 void videoDimensionChanged(const QSize &size);
159 void bufferingChanged(int progress);
162
163protected:
164 void setMediaFileType(MediaFileType fileType);
165
166private:
167 void setup_video_sink_for_buffer_streaming(void);
168 bool is_supported_video_sink(void) const;
169 bool connect_to_consumer(void);
170 void send_buffer_data(int fd, void *data, size_t len);
171 void send_frame_ready(void);
172 void process_missing_plugin_message(GstMessage *message);
173
176 std::string video_sink_name;
177 int sock_consumer;
178};
179}
180
181#endif // GSTREAMER_PLAYBIN_H
QString file_info_from_uri(const QUrl &uri) const
Definition playbin.cpp:755
void stateChanged(const Bus::Message::Detail::StateChanged &state, const QByteArray &source)
void setup_pipeline_for_audio_video()
Definition playbin.cpp:437
static const std::string & pipeline_name()
Definition playbin.cpp:105
uint64_t duration() const
Definition playbin.cpp:576
lomiri::MediaHubService::Player::Orientation orientation_lut(const gchar *orientation)
Definition playbin.cpp:518
QString get_file_content_type(const QUrl &uri) const
Definition playbin.cpp:761
void tagAvailable(Bus::Message::Detail::Tag tag)
bool is_missing_audio_codec
Definition playbin.h:140
bool can_play_streams() const
Definition playbin.cpp:817
GstElement * pipeline
Definition playbin.h:127
void bufferingChanged(int progress)
MediaFileType m_fileType
Definition playbin.h:129
gulong source_setup_handler_id
Definition playbin.h:137
MediaFileType mediaFileType() const
Definition playbin.cpp:812
void set_audio_stream_role(lomiri::MediaHubService::Player::AudioStreamRole new_audio_role)
Definition playbin.cpp:533
bool is_missing_video_codec
Definition playbin.h:141
Playbin(const lomiri::MediaHubService::Player::PlayerKey key)
Definition playbin.cpp:137
static std::string get_audio_role_str(lomiri::MediaHubService::Player::AudioStreamRole audio_role)
Definition playbin.cpp:496
void orientationChanged(lomiri::MediaHubService::Player::Orientation o)
uint64_t position() const
Definition playbin.cpp:556
void set_volume(double new_volume)
Definition playbin.cpp:490
void videoDimensionChanged(const QSize &size)
void process_message_element(GstMessage *message)
Definition playbin.cpp:326
void setup_source(GstElement *source)
Definition playbin.cpp:618
void setMediaFileType(MediaFileType fileType)
Definition playbin.cpp:927
void warningOccurred(const Bus::Message::Detail::ErrorWarningInfo &)
bool set_state(GstState new_state)
Definition playbin.cpp:690
void errorOccurred(const Bus::Message::Detail::ErrorWarningInfo &)
QSize get_video_dimensions() const
Definition playbin.cpp:720
static void streams_changed(GstElement *, gpointer user_data)
Definition playbin.cpp:127
static void about_to_finish(GstElement *, gpointer user_data)
Definition playbin.cpp:111
lomiri::MediaHubService::Player::Lifetime player_lifetime
Definition playbin.h:135
void set_lifetime(lomiri::MediaHubService::Player::Lifetime)
Definition playbin.cpp:551
gulong m_videoChangedHandlerId
Definition playbin.h:139
void updateMediaFileType()
Definition playbin.cpp:665
gulong m_audioChangedHandlerId
Definition playbin.h:138
QUrl uri() const
Definition playbin.cpp:679
void processVideoSinkStateChanged(const Bus::Message::Detail::StateChanged &state)
Definition playbin.cpp:304
gstreamer::Bus bus
Definition playbin.h:128
void mediaFileTypeChanged()
uint64_t previous_position
Definition playbin.h:133
void seekedTo(uint64_t offset)
void set_uri(const QUrl &uri, const lomiri::MediaHubService::Player::HeadersType &headers, bool do_pipeline_reset=true)
Definition playbin.cpp:585
bool seek(const std::chrono::microseconds &ms)
Definition playbin.cpp:710
void infoOccurred(const Bus::Message::Detail::ErrorWarningInfo &)
GstElement * audio_sink
Definition playbin.h:131
void create_video_sink(uint32_t texture_id)
Definition playbin.cpp:480
lomiri::MediaHubService::Player::HeadersType request_headers
Definition playbin.h:134
GstElement * video_sink
Definition playbin.h:130
GstState current_new_state
Definition playbin.h:144
void on_new_message(const Bus::Message &message)
Definition playbin.cpp:364
gstreamer::Bus & message_bus()
Definition playbin.cpp:432
bool is_video_file(const QUrl &uri) const
Definition playbin.cpp:798
bool is_audio_file(const QUrl &uri) const
Definition playbin.cpp:784
gulong about_to_finish_handler_id
Definition playbin.h:136
static void source_setup(GstElement *, GstElement *source, gpointer user_data)
Definition playbin.cpp:117
QMap< QString, QString > HeadersType
Definition player.h:57