Merge lp:~ricmm/media-hub/keep-display-recording-1362658 into lp:media-hub

Proposed by Ricardo Mendoza
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 71
Merged at revision: 78
Proposed branch: lp:~ricmm/media-hub/keep-display-recording-1362658
Merge into: lp:media-hub
Diff against target: 107 lines (+56/-2)
2 files modified
debian/control (+1/-1)
src/core/media/service_implementation.cpp (+55/-1)
To merge this branch: bzr merge lp:~ricmm/media-hub/keep-display-recording-1362658
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Jim Hodapp (community) code Approve
Review via email: mp+238446@code.launchpad.net

Commit message

Make use of MediaRecorderObserver interface from hybris to register as listeners for recording operations, so that we can then decide whether to hold a screen lock or not.

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

Looks good, thanks man!

review: Approve (code)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

LGTM, works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-08-28 07:17:42 +0000
3+++ debian/control 2014-10-15 14:22:19 +0000
4@@ -22,7 +22,7 @@
5 libdbus-1-dev,
6 libdbus-cpp-dev (>= 4.0.0),
7 libgoogle-glog-dev,
8- libhybris-dev (>=0.1.0+git20131207+e452e83-0ubuntu13),
9+ libhybris-dev (>=0.1.0+git20131207+e452e83-0ubuntu28),
10 libprocess-cpp-dev,
11 libproperties-cpp-dev,
12 gstreamer1.0-libav,
13
14=== modified file 'src/core/media/service_implementation.cpp'
15--- src/core/media/service_implementation.cpp 2014-09-25 17:23:40 +0000
16+++ src/core/media/service_implementation.cpp 2014-10-15 14:22:19 +0000
17@@ -30,6 +30,10 @@
18 #include <memory>
19 #include <thread>
20
21+#include "util/timeout.h"
22+#include "unity_screen_service.h"
23+#include <hybris/media/media_recorder_layer.h>
24+
25 namespace media = core::ubuntu::media;
26
27 using namespace std;
28@@ -38,7 +42,8 @@
29 {
30 Private()
31 : resume_key(std::numeric_limits<std::uint32_t>::max()),
32- keep_alive(io_service)
33+ keep_alive(io_service),
34+ disp_cookie(0)
35 {
36 bus = std::shared_ptr<dbus::Bus>(new dbus::Bus(core::dbus::WellKnownBus::session));
37 bus->install_executor(dbus::asio::make_executor(bus, io_service));
38@@ -53,6 +58,16 @@
39 indicator_power_session = stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/indicator/power/Battery"));
40 power_level = indicator_power_session->get_property<core::IndicatorPower::PowerLevel>();
41 is_warning = indicator_power_session->get_property<core::IndicatorPower::IsWarning>();
42+
43+ // Obtain session with Unity.Screen so that we request state when doing recording
44+ auto bus = std::shared_ptr<dbus::Bus>(new dbus::Bus(core::dbus::WellKnownBus::system));
45+ bus->install_executor(dbus::asio::make_executor(bus));
46+
47+ auto uscreen_stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::UScreen>::interface_name());
48+ uscreen_session = uscreen_stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/Unity/Screen"));
49+
50+ observer = android_media_recorder_observer_new();
51+ android_media_recorder_observer_set_cb(observer, &Private::media_recording_started_callback, this);
52 }
53
54 ~Private()
55@@ -63,6 +78,42 @@
56 worker.join();
57 }
58
59+ void media_recording_started(bool started)
60+ {
61+ if (uscreen_session == nullptr)
62+ return;
63+
64+ if (started)
65+ {
66+ if (disp_cookie > 0)
67+ return;
68+
69+ auto result = uscreen_session->invoke_method_synchronously<core::UScreen::keepDisplayOn, int>();
70+ if (result.is_error())
71+ throw std::runtime_error(result.error().print());
72+ disp_cookie = result.value();
73+ }
74+ else
75+ {
76+ if (disp_cookie != -1)
77+ {
78+ timeout(4000, true, [this](){
79+ this->uscreen_session->invoke_method_synchronously<core::UScreen::removeDisplayOnRequest, void>(this->disp_cookie);
80+ this->disp_cookie = -1;
81+ });
82+ }
83+ }
84+ }
85+
86+ static void media_recording_started_callback(bool started, void *context)
87+ {
88+ if (context == nullptr)
89+ return;
90+
91+ auto p = static_cast<Private*>(context);
92+ p->media_recording_started(started);
93+ }
94+
95 // This holds the key of the multimedia role Player instance that was paused
96 // when the battery level reached 10% or 5%
97 media::Player::PlayerKey resume_key;
98@@ -73,6 +124,9 @@
99 std::shared_ptr<dbus::Object> indicator_power_session;
100 std::shared_ptr<core::dbus::Property<core::IndicatorPower::PowerLevel>> power_level;
101 std::shared_ptr<core::dbus::Property<core::IndicatorPower::IsWarning>> is_warning;
102+ int disp_cookie;
103+ std::shared_ptr<dbus::Object> uscreen_session;
104+ MediaRecorderObserver *observer;
105 };
106
107 media::ServiceImplementation::ServiceImplementation() : d(new Private())

Subscribers

People subscribed via source and target branches