19 #ifndef GSTREAMER_PLAYBIN_H_
20 #define GSTREAMER_PLAYBIN_H_
23 #include "../mpris/player.h"
25 #include <hybris/media/surface_texture_client_hybris.h>
26 #include <hybris/media/media_codec_layer.h>
62 static const std::string s{
"playbin"};
69 auto thiz =
static_cast<Playbin*
>(user_data);
85 std::placeholders::_1))),
89 throw std::runtime_error(
"Could not create pipeline for playbin.");
111 std::cout <<
"Client died, resetting pipeline" << std::endl;
122 std::cout << __PRETTY_FUNCTION__ << std::endl;
123 auto ret = gst_element_set_state(
pipeline, GST_STATE_NULL);
126 case GST_STATE_CHANGE_FAILURE:
127 std::cout <<
"Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;
129 case GST_STATE_CHANGE_NO_PREROLL:
130 case GST_STATE_CHANGE_SUCCESS:
131 case GST_STATE_CHANGE_ASYNC:
134 std::cout <<
"Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;
143 case GST_MESSAGE_ERROR:
146 case GST_MESSAGE_WARNING:
149 case GST_MESSAGE_INFO:
152 case GST_MESSAGE_TAG:
155 if (gst_tag_list_get_string(message.
detail.
tag.
tag_list,
"image-orientation", &orientation))
159 g_free (orientation);
165 case GST_MESSAGE_STATE_CHANGED:
168 case GST_MESSAGE_ASYNC_DONE:
176 case GST_MESSAGE_EOS:
191 g_object_get (
pipeline,
"flags", &flags,
nullptr);
195 g_object_set (
pipeline,
"flags", flags,
nullptr);
197 if (::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME") !=
nullptr)
199 auto audio_sink = gst_element_factory_make (
200 ::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"),
203 std::cout <<
"audio_sink: " << ::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME") << std::endl;
212 if (::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") !=
nullptr)
215 ::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
218 std::cout <<
"video_sink: " << ::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") << std::endl;
230 std::cout <<
"Creating video sink for texture_id: " << texture_id << std::endl;
232 if (::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") !=
nullptr)
238 IGBPWrapperHybris igbp = decoding_service_get_igraphicbufferproducer();
239 SurfaceTextureClientHybris stc = surface_texture_client_create_by_igbp(igbp);
241 surface_texture_client_set_hardware_rendering (stc, TRUE);
242 g_object_set (G_OBJECT (
video_sink),
"surface", static_cast<gpointer>(stc), static_cast<char*>(NULL));
248 g_object_set (
pipeline,
"volume", new_volume, NULL);
256 case media::Player::AudioStreamRole::alarm:
259 case media::Player::AudioStreamRole::alert:
262 case media::Player::AudioStreamRole::multimedia:
265 case media::Player::AudioStreamRole::phone:
276 if (g_strcmp0(orientation,
"rotate-0") == 0)
277 return media::Player::Orientation::rotate0;
278 else if (g_strcmp0(orientation,
"rotate-90") == 0)
279 return media::Player::Orientation::rotate90;
280 else if (g_strcmp0(orientation,
"rotate-180") == 0)
281 return media::Player::Orientation::rotate180;
282 else if (g_strcmp0(orientation,
"rotate-270") == 0)
283 return media::Player::Orientation::rotate270;
285 return media::Player::Orientation::rotate0;
291 GstElement *audio_sink = NULL;
292 g_object_get (
pipeline,
"audio-sink", &audio_sink, NULL);
295 std::cout <<
"Audio stream role: " << role_str << std::endl;
297 GstStructure *props = gst_structure_from_string (role_str.c_str(), NULL);
298 if (audio_sink !=
nullptr && props !=
nullptr)
299 g_object_set (audio_sink,
"stream-properties", props, NULL);
303 "Warning: couldn't set audio stream role - couldn't get audio_sink from pipeline" <<
307 gst_structure_free (props);
313 gst_element_query_position (
pipeline, GST_FORMAT_TIME, &pos);
316 return static_cast<uint64_t
>(pos);
322 gst_element_query_duration (
pipeline, GST_FORMAT_TIME, &dur);
325 return static_cast<uint64_t
>(dur);
330 g_object_set(
pipeline,
"uri", uri.c_str(), NULL);
339 gchar* data =
nullptr;
340 g_object_get(
pipeline,
"current-uri", &data,
nullptr);
342 std::string result((data ==
nullptr ?
"" : data));
350 static const std::chrono::nanoseconds state_change_timeout
355 std::chrono::milliseconds{5000}
358 auto ret = gst_element_set_state(
pipeline, new_state);
359 bool result =
false; GstState current, pending;
362 case GST_STATE_CHANGE_FAILURE:
363 result =
false;
break;
364 case GST_STATE_CHANGE_NO_PREROLL:
365 case GST_STATE_CHANGE_SUCCESS:
366 result =
true;
break;
367 case GST_STATE_CHANGE_ASYNC:
368 result = GST_STATE_CHANGE_SUCCESS == gst_element_get_state(
372 state_change_timeout.count());
374 if (new_state == GST_STATE_PLAYING)
378 #ifdef DEBUG_GST_PIPELINE
379 std::cout <<
"Dumping pipeline dot file" << std::endl;
380 GST_DEBUG_BIN_TO_DOT_FILE((GstBin*)
pipeline, GST_DEBUG_GRAPH_SHOW_ALL,
"pipeline");
389 bool seek(
const std::chrono::microseconds& ms)
392 return gst_element_seek_simple(
395 (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT),
401 if (
video_sink !=
nullptr && g_strcmp0(::getenv(
"CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
"mirsink") == 0)
409 std::cerr <<
"Could not get the height/width of each video frame" << std::endl;
425 return std::string();
427 std::string filename(uri);
428 std::cout <<
"filename: " << filename << std::endl;
429 size_t pos = uri.find(
"file://");
430 if (pos != std::string::npos)
431 filename = uri.substr(pos + 7, std::string::npos);
436 return std::string(
"audio/video/");
439 GError *error =
nullptr;
440 std::unique_ptr<GFile, void(*)(void *)> file(
441 g_file_new_for_path(filename.c_str()), g_object_unref);
442 std::unique_ptr<GFileInfo, void(*)(void *)> info(
444 file.get(), G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE
","
445 G_FILE_ATTRIBUTE_ETAG_VALUE, G_FILE_QUERY_INFO_NONE,
450 std::string error_str(error->message);
453 std::cout <<
"Failed to query the URI for the presence of video content: "
454 << error_str << std::endl;
455 return std::string();
458 std::string content_type(g_file_info_get_attribute_string(
459 info.get(), G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE));
471 std::cout <<
"Found audio content" << std::endl;
485 std::cout <<
"Found video content" << std::endl;
509 core::Signal<Bus::Message::Detail::ErrorWarningInfo>
on_error;
510 core::Signal<Bus::Message::Detail::ErrorWarningInfo>
on_warning;
511 core::Signal<Bus::Message::Detail::ErrorWarningInfo>
on_info;
524 #endif // GSTREAMER_PLAYBIN_H_
core::Signal< Bus::Message::Detail::StateChanged > on_state_changed
core::Signal< Message > on_new_message
core::Signal< Bus::Message::Detail::Tag > on_tag_available
bool set_state_and_wait(GstState new_state)
void get_video_dimensions()
void set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)
bool seek(const std::chrono::microseconds &ms)
static void about_to_finish(GstElement *, gpointer user_data)
uint64_t duration() const
core::Signal< void > about_to_finish
int get_video_width() const
core::Signal< Bus::Message::Detail::ErrorWarningInfo > on_warning
core::Connection on_new_message_connection
int get_video_height() const
core::Signal< uint64_t > on_seeked_to
void on_new_message(const Bus::Message &message)
core::Signal< media::Player::Orientation > on_orientation_changed
media::Player::Orientation orientation_lut(const gchar *orientation)
SurfaceTextureClientHybris stc_hybris
MediaFileType media_file_type() const
void setup_pipeline_for_audio_video()
union gstreamer::Bus::Message::Detail detail
static std::string get_audio_role_str(media::Player::AudioStreamRole audio_role)
core::Signal< Bus::Message::Detail::ErrorWarningInfo > on_info
core::Signal< media::Player::PlaybackStatus > on_playback_status_changed
core::Signal< void > on_end_of_stream
std::string get_file_content_type(const std::string &uri) const
struct gstreamer::Playbin::@11 signals
void set_uri(const std::string &uri)
struct gstreamer::Bus::Message::Detail::Tag tag
bool is_audio_file(const std::string &uri) const
bool is_video_file(const std::string &uri) const
struct gstreamer::Bus::Message::Detail::ErrorWarningInfo error_warning_info
core::Signal< uint32_t, uint32_t > on_add_frame_dimension
void set_volume(double new_volume)
core::Signal< Bus::Message::Detail::ErrorWarningInfo > on_error
void create_video_sink(uint32_t texture_id)
core::Signal< void > client_disconnected
uint64_t position() const
static const std::string & pipeline_name()
gstreamer::Bus & message_bus()
struct gstreamer::Bus::Message::Detail::StateChanged state_changed