Merge lp:~alfonsosanchezbeato/media-hub/get-selected-streams into lp:media-hub/stable

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Jim Hodapp
Approved revision: 149
Merged at revision: 153
Proposed branch: lp:~alfonsosanchezbeato/media-hub/get-selected-streams
Merge into: lp:media-hub/stable
Diff against target: 282 lines (+116/-12)
6 files modified
debian/changelog (+12/-5)
debian/control (+1/-0)
src/core/media/CMakeLists.txt (+2/-0)
src/core/media/gstreamer/engine.cpp (+22/-5)
src/core/media/gstreamer/playbin.cpp (+72/-2)
src/core/media/gstreamer/playbin.h (+7/-0)
To merge this branch: bzr merge lp:~alfonsosanchezbeato/media-hub/get-selected-streams
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Disapprove
Jim Hodapp (community) code Approve
Review via email: mp+267514@code.launchpad.net

Commit message

Gather information about missing codecs and selected streams from gstreamer so we have more information on whether we should play the video or not.

Description of the change

Gather information about missing codecs and selected streams from gstreamer so we have more information on whether we should play the video or not.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good, thanks.

review: Approve (code)
Revision history for this message
Robert Bruce Park (robru) wrote :
review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-07-10 18:12:22 +0000
3+++ debian/changelog 2015-08-10 13:10:12 +0000
4@@ -1,4 +1,11 @@
5-media-hub (3.1.0+15.10.20150710-0ubuntu1) wily; urgency=medium
6+media-hub (3.1.0+15.04.20150810-0ubuntu1) UNRELEASED; urgency=medium
7+
8+ * Gather information about missing codecs and selected streams from gstreamer
9+ so we have more information on whether we should play the video or not.
10+
11+ -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Mon, 10 Aug 2015 15:04:18 +0200
12+
13+media-hub (3.1.0+15.04.20150710-0ubuntu1) vivid; urgency=medium
14
15 [ CI Train Bot ]
16 * New rebuild forced.
17@@ -9,7 +16,7 @@
18
19 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 10 Jul 2015 18:12:21 +0000
20
21-media-hub (3.1.0+15.10.20150604-0ubuntu1) wily; urgency=medium
22+media-hub (3.1.0+15.04.20150604-0ubuntu1) vivid; urgency=medium
23
24 [ CI Train Bot ]
25 * New rebuild forced.
26@@ -20,7 +27,7 @@
27
28 -- CI Train Bot <ci-train-bot@canonical.com> Thu, 04 Jun 2015 14:18:22 +0000
29
30-media-hub (3.1.0+15.10.20150601-0ubuntu1) wily; urgency=medium
31+media-hub (3.1.0+15.04.20150601-0ubuntu1) vivid; urgency=medium
32
33 [ CI Train Bot ]
34 * New rebuild forced.
35@@ -31,7 +38,7 @@
36
37 -- CI Train Bot <ci-train-bot@canonical.com> Mon, 01 Jun 2015 16:31:53 +0000
38
39-media-hub (3.1.0+15.10.20150527.1-0ubuntu1) wily; urgency=medium
40+media-hub (3.1.0+15.04.20150527.1-0ubuntu1) vivid; urgency=medium
41
42 [ CI Train Bot ]
43 * New rebuild forced.
44@@ -42,7 +49,7 @@
45
46 -- CI Train Bot <ci-train-bot@canonical.com> Wed, 27 May 2015 18:38:16 +0000
47
48-media-hub (3.1.0+15.10.20150522-0ubuntu1) wily; urgency=medium
49+media-hub (3.1.0+15.04.20150522-0ubuntu1) vivid; urgency=medium
50
51 [ Jim Hodapp ]
52 * Fix issues with not reporting failed decoding error to the client.
53
54=== modified file 'debian/control'
55--- debian/control 2015-03-12 11:38:32 +0000
56+++ debian/control 2015-08-10 13:10:12 +0000
57@@ -25,6 +25,7 @@
58 libprocess-cpp-dev,
59 libproperties-cpp-dev,
60 libgstreamer1.0-dev,
61+ libgstreamer-plugins-base1.0-dev,
62 pkg-config,
63 libpulse-dev,
64 qtbase5-dev,
65
66=== modified file 'src/core/media/CMakeLists.txt'
67--- src/core/media/CMakeLists.txt 2015-02-24 15:22:19 +0000
68+++ src/core/media/CMakeLists.txt 2015-08-10 13:10:12 +0000
69@@ -1,4 +1,5 @@
70 pkg_check_modules(PC_GSTREAMER_1_0 REQUIRED gstreamer-1.0)
71+pkg_check_modules(PC_GSTREAMER_PBUTILS_1_0 REQUIRED gstreamer-pbutils-1.0)
72 pkg_check_modules(PC_PULSE_AUDIO REQUIRED libpulse)
73 include_directories(${PC_GSTREAMER_1_0_INCLUDE_DIRS} ${HYBRIS_MEDIA_CFLAGS} ${PC_PULSE_AUDIO_INCLUDE_DIRS})
74
75@@ -126,6 +127,7 @@
76 ${DBUS_CPP_LDFLAGS}
77 ${GLog_LIBRARY}
78 ${PC_GSTREAMER_1_0_LIBRARIES}
79+ ${PC_GSTREAMER_PBUTILS_1_0_LIBRARIES}
80 ${PROCESS_CPP_LDFLAGS}
81 ${GIO_LIBRARIES}
82 ${HYBRIS_MEDIA_LIBRARIES}
83
84=== modified file 'src/core/media/gstreamer/engine.cpp'
85--- src/core/media/gstreamer/engine.cpp 2015-06-01 16:30:59 +0000
86+++ src/core/media/gstreamer/engine.cpp 2015-08-10 13:10:12 +0000
87@@ -67,8 +67,22 @@
88 {
89 if (p.second == "playbin")
90 {
91- std::cout << "State changed on playbin: " << p.first.new_state << std::endl;
92- playback_status_changed(gst_state_to_player_status(p.first));
93+ std::cout << "State changed on playbin: "
94+ << gst_element_state_get_name(p.first.new_state) << std::endl;
95+ const auto status = gst_state_to_player_status(p.first);
96+ /*
97+ * When state moves to "paused" the pipeline is already set. We check that we
98+ * have streams to play.
99+ */
100+ if (status == media::Player::PlaybackStatus::paused &&
101+ !playbin.can_play_streams()) {
102+ std::cerr << "** Cannot play: some codecs are missing" << std::endl;
103+ playbin.reset();
104+ const media::Player::Error e = media::Player::Error::format_error;
105+ error(e);
106+ } else {
107+ playback_status_changed(status);
108+ }
109 }
110 }
111
112@@ -149,7 +163,8 @@
113 break;
114 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
115 std::cerr << "** Encountered a GST_STREAM_ERROR_CODEC_NOT_FOUND" << std::endl;
116- ret_error = media::Player::Error::format_error;
117+ // Missing codecs are handled later, when state switches to "paused"
118+ ret_error = media::Player::Error::no_error;
119 break;
120 case GST_STREAM_ERROR_DECODE:
121 std::cerr << "** Encountered a GST_STREAM_ERROR_DECODE" << std::endl;
122@@ -163,8 +178,10 @@
123 }
124 }
125
126- std::cout << "Resetting playbin pipeline after unrecoverable error" << std::endl;
127- playbin.reset();
128+ if (ret_error != media::Player::Error::no_error) {
129+ std::cerr << "Resetting playbin pipeline after unrecoverable error" << std::endl;
130+ playbin.reset();
131+ }
132 return ret_error;
133 }
134
135
136=== modified file 'src/core/media/gstreamer/playbin.cpp'
137--- src/core/media/gstreamer/playbin.cpp 2015-06-12 18:14:05 +0000
138+++ src/core/media/gstreamer/playbin.cpp 2015-08-10 13:10:12 +0000
139@@ -1,5 +1,5 @@
140 /*
141- * Copyright © 2013 Canonical Ltd.
142+ * Copyright © 2013-2015 Canonical Ltd.
143 *
144 * This program is free software: you can redistribute it and/or modify it
145 * under the terms of the GNU Lesser General Public License version 3,
146@@ -20,6 +20,8 @@
147
148 #include <core/media/gstreamer/engine.h>
149
150+#include <gst/pbutils/missing-plugins.h>
151+
152 #if defined(MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER)
153 #include <hybris/media/surface_texture_client_hybris.h>
154 #include <hybris/media/media_codec_layer.h>
155@@ -105,7 +107,11 @@
156 core::ubuntu::media::video::Width{0}},
157 player_lifetime(media::Player::Lifetime::normal),
158 about_to_finish_handler_id(0),
159- source_setup_handler_id(0)
160+ source_setup_handler_id(0),
161+ is_missing_audio_codec(false),
162+ is_missing_video_codec(false),
163+ audio_stream_id(-1),
164+ video_stream_id(-1)
165 {
166 if (!pipeline)
167 throw std::runtime_error("Could not create pipeline for playbin.");
168@@ -170,6 +176,44 @@
169 std::cout << "Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;
170 }
171 file_type = MEDIA_FILE_TYPE_NONE;
172+ is_missing_audio_codec = false;
173+ is_missing_video_codec = false;
174+ audio_stream_id = -1;
175+ video_stream_id = -1;
176+}
177+
178+void gstreamer::Playbin::process_message_element(GstMessage *message)
179+{
180+ if (!gst_is_missing_plugin_message(message))
181+ return;
182+
183+ gchar *desc = gst_missing_plugin_message_get_description(message);
184+ std::cerr << "Missing plugin: " << desc << std::endl;
185+ g_free(desc);
186+
187+ const GstStructure *msg_data = gst_message_get_structure(message);
188+ if (g_strcmp0("decoder", gst_structure_get_string(msg_data, "type")) != 0)
189+ return;
190+
191+ GstCaps *caps;
192+ if (!gst_structure_get(msg_data, "detail", GST_TYPE_CAPS, &caps, NULL)) {
193+ std::cerr << __PRETTY_FUNCTION__ << ": No detail" << std::endl;
194+ return;
195+ }
196+
197+ GstStructure *caps_data = gst_caps_get_structure(caps, 0);
198+ if (!caps_data) {
199+ std::cerr << __PRETTY_FUNCTION__ << ": No caps data" << std::endl;
200+ return;
201+ }
202+
203+ const gchar *mime = gst_structure_get_name(caps_data);
204+ if (strstr(mime, "audio"))
205+ is_missing_audio_codec = true;
206+ else if (strstr(mime, "video"))
207+ is_missing_video_codec = true;
208+
209+ std::cerr << "Missing decoder for " << mime << std::endl;
210 }
211
212 void gstreamer::Playbin::on_new_message_async(const Bus::Message& message)
213@@ -186,8 +230,15 @@
214 signals.on_info(message.detail.error_warning_info);
215 break;
216 case GST_MESSAGE_STATE_CHANGED:
217+ if (message.source == "playbin") {
218+ g_object_get(G_OBJECT(pipeline), "current-audio", &audio_stream_id, NULL);
219+ g_object_get(G_OBJECT(pipeline), "current-video", &video_stream_id, NULL);
220+ }
221 signals.on_state_changed(std::make_pair(message.detail.state_changed, message.source));
222 break;
223+ case GST_MESSAGE_ELEMENT:
224+ process_message_element(message.message);
225+ break;
226 case GST_MESSAGE_TAG:
227 {
228 gchar *orientation;
229@@ -591,3 +642,22 @@
230 {
231 return file_type;
232 }
233+
234+bool gstreamer::Playbin::can_play_streams() const
235+{
236+ /*
237+ * We do not consider that we can play the video when
238+ * 1. No audio stream selected due to missing decoder
239+ * 2. No video stream selected due to missing decoder
240+ * 3. No stream selected at all
241+ * Note that if there are several, say, audio streams, we will play the file
242+ * provided that we can decode just one of them, even if there are missing
243+ * audio codecs. We will also play files with only one type of stream.
244+ */
245+ if ((is_missing_audio_codec && audio_stream_id == -1) ||
246+ (is_missing_video_codec && video_stream_id == -1) ||
247+ (audio_stream_id == -1 && video_stream_id == -1))
248+ return false;
249+ else
250+ return true;
251+}
252
253=== modified file 'src/core/media/gstreamer/playbin.h'
254--- src/core/media/gstreamer/playbin.h 2015-06-12 18:14:05 +0000
255+++ src/core/media/gstreamer/playbin.h 2015-08-10 13:10:12 +0000
256@@ -72,6 +72,7 @@
257
258 void on_new_message(const Bus::Message& message);
259 void on_new_message_async(const Bus::Message& message);
260+ void process_message_element(GstMessage *message);
261
262 gstreamer::Bus& message_bus();
263
264@@ -110,6 +111,8 @@
265
266 MediaFileType media_file_type() const;
267
268+ bool can_play_streams() const;
269+
270 GstElement* pipeline;
271 gstreamer::Bus bus;
272 MediaFileType file_type;
273@@ -137,6 +140,10 @@
274 core::Signal<core::ubuntu::media::video::Dimensions> on_video_dimensions_changed;
275 core::Signal<void> client_disconnected;
276 } signals;
277+ bool is_missing_audio_codec;
278+ bool is_missing_video_codec;
279+ gint audio_stream_id;
280+ gint video_stream_id;
281 };
282 }
283

Subscribers

People subscribed via source and target branches