Merge lp:~thomas-voss/media-hub/introduce-client-death-observer-interface into lp:media-hub

Proposed by Thomas Voß
Status: Merged
Approved by: Ricardo Mendoza
Approved revision: 108
Merged at revision: 116
Proposed branch: lp:~thomas-voss/media-hub/introduce-client-death-observer-interface
Merge into: lp:media-hub
Prerequisite: lp:~thomas-voss/media-hub/make-video-size-a-proper-type
Diff against target: 376 lines (+266/-24)
8 files modified
src/core/media/CMakeLists.txt (+2/-0)
src/core/media/client_death_observer.cpp (+42/-0)
src/core/media/client_death_observer.h (+62/-0)
src/core/media/hybris_client_death_observer.cpp (+84/-0)
src/core/media/hybris_client_death_observer.h (+64/-0)
src/core/media/player_implementation.cpp (+11/-11)
src/core/media/player_stub.cpp (+0/-4)
tests/unit-tests/CMakeLists.txt (+1/-9)
To merge this branch: bzr merge lp:~thomas-voss/media-hub/introduce-client-death-observer-interface
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Jim Hodapp (community) code Approve
Review via email: mp+242884@code.launchpad.net

Commit message

Add an interface media::ClientDeathObserver that abstracts away receiving key-based death notifications for clients associated to media::Player instances server-side
Provide an implementation media::HybrisClientDeathObserver that relies on hybris and ultimately on Android's onBinderDied to receive death notifications.
Adjust media::PlayerStub and media::PlayerImplementation to account for the new interface.
Adjust the CMake setup for tests to link media-hub-service instead of recompiling large parts of the implementation classes.

Description of the change

Add an interface media::ClientDeathObserver that abstracts away receiving key-based death notifications for clients associated to media::Player instances server-side
Provide an implementation media::HybrisClientDeathObserver that relies on hybris and ultimately on Android's onBinderDied to receive death notifications.
Adjust media::PlayerStub and media::PlayerImplementation to account for the new interface.
Adjust the CMake setup for tests to link media-hub-service instead of recompiling large parts of the implementation classes.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
102. By Thomas Voß

Remerge prereq branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good, 4 minor comments inline below.

review: Needs Fixing (code)
103. By Thomas Voß

[ Jim Hodapp ]
* Resubmitting with prerequisite branch (LP: #1331041)
[ Justin McPherson ]
* Resubmitting with prerequisite branch (LP: #1331041)

104. By Thomas Voß

Address reviewer comments.

Revision history for this message
Thomas Voß (thomas-voss) :
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good.

review: Approve (code)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
105. By Thomas Voß

[ Jim Hodapp ]
* Error reporting all the way up to the app level from the playbin
  pipeline.
[ Ubuntu daily release ]
* New rebuild forced
[ Jim Hodapp ]
* Don't auto-resume playback of videos after a phone call ends. (LP:
  #1411273)
[ Ubuntu daily release ]
* New rebuild forced
[ Ricardo Salveti de Araujo ]
* service_implementation: adding debug for call started/ended signals.
  Make sure account and connection are available when setting up
  account manager (patch from Gustavo Boiko). call_monitor: don't
  check caps when hooking up on/off signals, until bug 1409125 is
  fixed. Enable parallel building . (LP: #1409125)
[ Jim Hodapp ]
* Pause playback when recording begins. (LP: #1398047)
[ Ricardo Salveti de Araujo ]
* call_monitor.cpp: waiting for bridge to be up, and also protecting
  the on_change call (LP: #1408137)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
106. By Thomas Voß

Merge prereq branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
107. By Thomas Voß

Merge prereq branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
108. By Thomas Voß

* debian/control:
  - Removing pre-depends that are not required
  - Bumping standards-version to 3.9.6
[ Ricardo Salveti de Araujo ]
* Migrating tests to use ogg instead of mp3/avi removed:
  tests/h264.avi tests/test.mp3 added: tests/test-audio-1.ogg
  tests/test-video.ogg tests/test.mp3 renamed: tests/test.ogg =>
  tests/test-audio.ogg

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/media/CMakeLists.txt'
2--- src/core/media/CMakeLists.txt 2015-03-12 11:40:36 +0000
3+++ src/core/media/CMakeLists.txt 2015-03-12 11:40:36 +0000
4@@ -86,6 +86,8 @@
5 ${MEDIA_HUB_HEADERS}
6 ${MPRIS_HEADERS}
7
8+ client_death_observer.cpp
9+ hybris_client_death_observer.cpp
10 cover_art_resolver.cpp
11 engine.cpp
12 gstreamer/engine.cpp
13
14=== added file 'src/core/media/client_death_observer.cpp'
15--- src/core/media/client_death_observer.cpp 1970-01-01 00:00:00 +0000
16+++ src/core/media/client_death_observer.cpp 2015-03-12 11:40:36 +0000
17@@ -0,0 +1,42 @@
18+/*
19+ * Copyright © 2014 Canonical Ltd.
20+ *
21+ * This program is free software: you can redistribute it and/or modify it
22+ * under the terms of the GNU Lesser General Public License version 3,
23+ * as published by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU Lesser General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU Lesser General Public License
31+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32+ *
33+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
34+ */
35+
36+#include <core/media/client_death_observer.h>
37+
38+namespace media = core::ubuntu::media;
39+
40+#if defined(MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER)
41+#include <core/media/hybris_client_death_observer.h>
42+
43+// Accesses the default client death observer implementation for the platform.
44+media::ClientDeathObserver::Ptr media::platform_default_client_death_observer()
45+{
46+ return media::HybrisClientDeathObserver::create();
47+}
48+#else // MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER
49+// Just throws a std::logic_error as we have not yet defined a default way to
50+// identify client death changes. One possible way of implementing the interface
51+// would be to listen to dbus name changes and react accordingly.
52+media::ClientDeathObserver::Ptr media::platform_default_client_death_observer()
53+{
54+ throw std::logic_error
55+ {
56+ "No platform-specific death observer implementation known."
57+ };
58+}
59+#endif // MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER
60
61=== added file 'src/core/media/client_death_observer.h'
62--- src/core/media/client_death_observer.h 1970-01-01 00:00:00 +0000
63+++ src/core/media/client_death_observer.h 2015-03-12 11:40:36 +0000
64@@ -0,0 +1,62 @@
65+/*
66+ * Copyright © 2014 Canonical Ltd.
67+ *
68+ * This program is free software: you can redistribute it and/or modify it
69+ * under the terms of the GNU Lesser General Public License version 3,
70+ * as published by the Free Software Foundation.
71+ *
72+ * This program is distributed in the hope that it will be useful,
73+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
74+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75+ * GNU Lesser General Public License for more details.
76+ *
77+ * You should have received a copy of the GNU Lesser General Public License
78+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
79+ *
80+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
81+ */
82+
83+#ifndef CORE_UBUNTU_MEDIA_CLIENT_DEATH_OBSERVER_H_
84+#define CORE_UBUNTU_MEDIA_CLIENT_DEATH_OBSERVER_H_
85+
86+#include <core/media/player.h>
87+
88+#include <core/signal.h>
89+
90+#include <memory>
91+
92+namespace core
93+{
94+namespace ubuntu
95+{
96+namespace media
97+{
98+// Models functionality to be notified whenever a client
99+// of the service goes away, and thus allows us to clean
100+// up in that case.
101+struct ClientDeathObserver
102+{
103+ // To save us some typing.
104+ typedef std::shared_ptr<ClientDeathObserver> Ptr;
105+
106+ ClientDeathObserver() = default;
107+ ClientDeathObserver(const ClientDeathObserver&) = delete;
108+ virtual ~ClientDeathObserver() = default;
109+
110+ ClientDeathObserver& operator=(const ClientDeathObserver&) = delete;
111+
112+ // Registers the client with the given key for death notifications.
113+ virtual void register_for_death_notifications_with_key(const Player::PlayerKey&) = 0;
114+
115+ // Emitted whenever a client dies, reporting the key under which the
116+ // respective client was known.
117+ virtual const core::Signal<Player::PlayerKey>& on_client_with_key_died() const = 0;
118+};
119+
120+// Accesses the default client death observer implementation for the platform.
121+ClientDeathObserver::Ptr platform_default_client_death_observer();
122+}
123+}
124+}
125+
126+#endif // CORE_UBUNTU_MEDIA_CLIENT_DEATH_OBSERVER_H_
127
128=== added file 'src/core/media/hybris_client_death_observer.cpp'
129--- src/core/media/hybris_client_death_observer.cpp 1970-01-01 00:00:00 +0000
130+++ src/core/media/hybris_client_death_observer.cpp 2015-03-12 11:40:36 +0000
131@@ -0,0 +1,84 @@
132+/*
133+ * Copyright © 2014 Canonical Ltd.
134+ *
135+ * This program is free software: you can redistribute it and/or modify it
136+ * under the terms of the GNU Lesser General Public License version 3,
137+ * as published by the Free Software Foundation.
138+ *
139+ * This program is distributed in the hope that it will be useful,
140+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
141+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142+ * GNU Lesser General Public License for more details.
143+ *
144+ * You should have received a copy of the GNU Lesser General Public License
145+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
146+ *
147+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
148+ */
149+
150+#include <core/media/hybris_client_death_observer.h>
151+
152+namespace media = core::ubuntu::media;
153+
154+#if defined(MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER)
155+#include <hybris/media/media_codec_layer.h>
156+
157+namespace
158+{
159+typedef std::pair<media::Player::PlayerKey, std::weak_ptr<media::HybrisClientDeathObserver>> Holder;
160+}
161+
162+void media::HybrisClientDeathObserver::on_client_died_cb(void* context)
163+{
164+ auto holder = static_cast<Holder*>(context);
165+
166+ if (not holder)
167+ return;
168+
169+ // We check if we are still alive or if we already got killed.
170+ if (auto sp = holder->second.lock())
171+ {
172+ sp->client_with_key_died(holder->first);
173+ }
174+
175+ // And with that, we have reached end of life for our holder object.
176+ delete holder;
177+}
178+
179+// Creates an instance of the HybrisClientDeathObserver or throws
180+// if the underlying platform does not support it.
181+media::ClientDeathObserver::Ptr media::HybrisClientDeathObserver::create()
182+{
183+ return media::ClientDeathObserver::Ptr{new media::HybrisClientDeathObserver{}};
184+}
185+
186+media::HybrisClientDeathObserver::HybrisClientDeathObserver()
187+{
188+}
189+
190+media::HybrisClientDeathObserver::~HybrisClientDeathObserver()
191+{
192+}
193+
194+void media::HybrisClientDeathObserver::register_for_death_notifications_with_key(const media::Player::PlayerKey& key)
195+{
196+ decoding_service_set_client_death_cb(&media::HybrisClientDeathObserver::on_client_died_cb, key, new Holder{key, shared_from_this()});
197+}
198+
199+const core::Signal<media::Player::PlayerKey>& media::HybrisClientDeathObserver::on_client_with_key_died() const
200+{
201+ return client_with_key_died;
202+}
203+#else // MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER
204+// Creates an instance of the HybrisClientDeathObserver or throws
205+// if the underlying platform does not support it.
206+media::ClientDeathObserver::Ptr media::HybrisClientDeathObserver::create()
207+{
208+ throw std::logic_error
209+ {
210+ "Hybris-based death observer implementation not supported on this platform."
211+ };
212+}
213+#endif // MEDIA_HUB_HAVE_HYBRIS_MEDIA_COMPAT_LAYER
214+
215+
216
217=== added file 'src/core/media/hybris_client_death_observer.h'
218--- src/core/media/hybris_client_death_observer.h 1970-01-01 00:00:00 +0000
219+++ src/core/media/hybris_client_death_observer.h 2015-03-12 11:40:36 +0000
220@@ -0,0 +1,64 @@
221+/*
222+ * Copyright © 2014 Canonical Ltd.
223+ *
224+ * This program is free software: you can redistribute it and/or modify it
225+ * under the terms of the GNU Lesser General Public License version 3,
226+ * as published by the Free Software Foundation.
227+ *
228+ * This program is distributed in the hope that it will be useful,
229+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
230+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231+ * GNU Lesser General Public License for more details.
232+ *
233+ * You should have received a copy of the GNU Lesser General Public License
234+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
235+ *
236+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
237+ */
238+
239+#ifndef CORE_UBUNTU_MEDIA_HYBRIS_CLIENT_DEATH_OBSERVER_H_
240+#define CORE_UBUNTU_MEDIA_HYBRIS_CLIENT_DEATH_OBSERVER_H_
241+
242+#include <core/media/client_death_observer.h>
243+
244+namespace core
245+{
246+namespace ubuntu
247+{
248+namespace media
249+{
250+// Models functionality to be notified whenever a client
251+// of the service goes away, and thus allows us to clean
252+// up in that case.
253+// Specific implementation for a hybris-based platform.
254+class HybrisClientDeathObserver : public ClientDeathObserver,
255+ public std::enable_shared_from_this<HybrisClientDeathObserver>
256+{
257+public:
258+ // Our static callback that we inject to the hybris world.
259+ static void on_client_died_cb(void* context);
260+
261+ // Creates an instance of the HybrisClientDeathObserver or throws
262+ // if the underlying platform does not support it.
263+ static ClientDeathObserver::Ptr create();
264+
265+ // Make std::unique_ptr happy for forward declared Private internals.
266+ ~HybrisClientDeathObserver();
267+
268+ // Registers the client with the given key for death notifications.
269+ void register_for_death_notifications_with_key(const Player::PlayerKey&) override;
270+
271+ // Emitted whenever a client dies, reporting the key under which the
272+ // respective client was known.
273+ const core::Signal<Player::PlayerKey>& on_client_with_key_died() const override;
274+
275+private:
276+ HybrisClientDeathObserver();
277+
278+ core::Signal<media::Player::PlayerKey> client_with_key_died;
279+};
280+}
281+}
282+}
283+
284+#endif // CORE_UBUNTU_MEDIA_HYBRIS_CLIENT_DEATH_OBSERVER_H_
285
286=== modified file 'src/core/media/player_implementation.cpp'
287--- src/core/media/player_implementation.cpp 2015-03-12 11:40:36 +0000
288+++ src/core/media/player_implementation.cpp 2015-03-12 11:40:36 +0000
289@@ -21,10 +21,10 @@
290
291 #include <unistd.h>
292
293+#include "client_death_observer.h"
294 #include "engine.h"
295 #include "track_list_implementation.h"
296
297-#include <hybris/media/media_codec_layer.h>
298 #include "powerd_service.h"
299 #include "unity_screen_service.h"
300 #include "gstreamer/engine.h"
301@@ -81,7 +81,16 @@
302 auto uscreen_stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::UScreen>::interface_name());
303 uscreen_session = uscreen_stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/Unity/Screen"));
304
305- decoding_service_set_client_death_cb(&Private::on_client_died_cb, key, static_cast<void*>(this));
306+ auto client_death_observer = media::platform_default_client_death_observer();
307+
308+ client_death_observer->register_for_death_notifications_with_key(key);
309+ client_death_observer->on_client_with_key_died().connect([this](const media::Player::PlayerKey& died)
310+ {
311+ if (died != this->key)
312+ return;
313+
314+ on_client_died();
315+ });
316 }
317
318 ~Private()
319@@ -261,15 +270,6 @@
320 };
321 }
322
323- static void on_client_died_cb(void *context)
324- {
325- if (context)
326- {
327- Private *p = static_cast<Private*>(context);
328- p->on_client_died();
329- }
330- }
331-
332 void on_client_died()
333 {
334 engine->reset();
335
336=== modified file 'src/core/media/player_stub.cpp'
337--- src/core/media/player_stub.cpp 2015-03-12 11:40:36 +0000
338+++ src/core/media/player_stub.cpp 2015-03-12 11:40:36 +0000
339@@ -33,10 +33,6 @@
340 #include <core/dbus/property.h>
341 #include <core/dbus/types/object_path.h>
342
343-// Hybris
344-#include <hybris/media/media_codec_layer.h>
345-#include <hybris/media/surface_texture_client_hybris.h>
346-
347 #include <limits>
348
349 #define UNUSED __attribute__((unused))
350
351=== modified file 'tests/unit-tests/CMakeLists.txt'
352--- tests/unit-tests/CMakeLists.txt 2014-11-18 20:29:26 +0000
353+++ tests/unit-tests/CMakeLists.txt 2015-03-12 11:40:36 +0000
354@@ -13,15 +13,6 @@
355 test-gstreamer-engine
356
357 libmedia-mock.cpp
358- ${CMAKE_SOURCE_DIR}/src/core/media/cover_art_resolver.cpp
359- ${CMAKE_SOURCE_DIR}/src/core/media/engine.cpp
360- ${CMAKE_SOURCE_DIR}/src/core/media/gstreamer/engine.cpp
361- ${CMAKE_SOURCE_DIR}/src/core/media/player_skeleton.cpp
362- ${CMAKE_SOURCE_DIR}/src/core/media/player_implementation.cpp
363- ${CMAKE_SOURCE_DIR}/src/core/media/service_skeleton.cpp
364- ${CMAKE_SOURCE_DIR}/src/core/media/service_implementation.cpp
365- ${CMAKE_SOURCE_DIR}/src/core/media/track_list_skeleton.cpp
366- ${CMAKE_SOURCE_DIR}/src/core/media/track_list_implementation.cpp
367 test-gstreamer-engine.cpp
368 )
369
370@@ -30,6 +21,7 @@
371
372 media-hub-common
373 media-hub-client
374+ media-hub-service
375 call-monitor
376 media-hub-test-framework
377

Subscribers

People subscribed via source and target branches