26 #include <boost/asio.hpp>
35 #include <hybris/media/media_recorder_layer.h>
37 namespace media = core::ubuntu::media;
44 : resume_key(std::numeric_limits<std::uint32_t>::max()),
45 keep_alive(io_service),
48 bus = std::shared_ptr<dbus::Bus>(
new dbus::Bus(core::dbus::WellKnownBus::session));
49 bus->install_executor(dbus::asio::make_executor(bus, io_service));
50 worker = std::move(std::thread([
this]()
57 auto stub_service = dbus::Service::use_service(bus,
"com.canonical.indicator.power");
58 indicator_power_session = stub_service->object_for_path(dbus::types::ObjectPath(
"/com/canonical/indicator/power/Battery"));
63 auto bus = std::shared_ptr<dbus::Bus>(
new dbus::Bus(core::dbus::WellKnownBus::system));
64 bus->install_executor(dbus::asio::make_executor(bus));
66 auto uscreen_stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::UScreen>::interface_name());
67 uscreen_session = uscreen_stub_service->object_for_path(dbus::types::ObjectPath(
"/com/canonical/Unity/Screen"));
69 observer = android_media_recorder_observer_new();
70 android_media_recorder_observer_set_cb(observer, &Private::media_recording_started_callback,
this);
77 if (worker.joinable())
83 if (uscreen_session ==
nullptr)
92 if (result.is_error())
93 throw std::runtime_error(result.error().print());
94 disp_cookie = result.value();
98 if (disp_cookie != -1)
100 timeout(4000,
true, [
this](){
102 this->disp_cookie = -1;
110 if (context ==
nullptr)
113 auto p =
static_cast<Private*
>(context);
125 std::shared_ptr<core::dbus::Property<core::IndicatorPower::PowerLevel>>
power_level;
126 std::shared_ptr<core::dbus::Property<core::IndicatorPower::IsWarning>>
is_warning;
134 cout << __PRETTY_FUNCTION__ << endl;
140 if (level ==
"low" || level ==
"very_low")
141 pause_all_multimedia_sessions();
149 resume_multimedia_session();
158 const media::Player::Configuration& conf)
160 auto player = std::make_shared<media::PlayerImplementation>(
161 conf.identity, conf.bus, conf.session, shared_from_this(), conf.key);
164 player->on_client_disconnected().connect([
this, key]()
171 d->io_service.post([
this, key]()
184 cerr <<
"Could not find Player by key: " << key << endl;
206 cout <<
"Pausing Player with key: " << other_key << endl;
207 other_player->pause();
212 void media::ServiceImplementation::pause_all_multimedia_sessions()
220 cout <<
"Will resume playback of Player with key: " << d->resume_key << endl;
226 void media::ServiceImplementation::resume_multimedia_session()
235 cout <<
"Resuming playback of Player with key: " << d->resume_key << endl;
237 d->resume_key = std::numeric_limits<std::uint32_t>::max();