27 #include <hybris/media/media_codec_layer.h>
37 #define UNUSED __attribute__((unused))
45 public std::enable_shared_from_this<Private>
49 WAKELOCK_CLEAR_INACTIVE,
50 WAKELOCK_CLEAR_DISPLAY,
51 WAKELOCK_CLEAR_SYSTEM,
52 WAKELOCK_CLEAR_INVALID
56 const dbus::types::ObjectPath& session_path,
57 const std::shared_ptr<media::Service>& service,
58 PlayerImplementation::PlayerKey key)
62 session_path(session_path),
64 new
media::TrackListImplementation(
65 session_path.as_string() +
"/TrackList",
66 engine->meta_data_extractor())),
67 sys_lock_name(
"media-hub-music-playback"),
69 system_wakelock_count(0),
70 display_wakelock_count(0),
71 previous_state(Engine::State::stopped),
73 engine_state_change_connection(engine->state().changed().connect(make_state_change_handler()))
75 auto bus = std::shared_ptr<dbus::Bus>(
new dbus::Bus(core::dbus::WellKnownBus::system));
76 bus->install_executor(dbus::asio::make_executor(bus));
78 auto stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::Powerd>::interface_name());
79 powerd_session = stub_service->object_for_path(dbus::types::ObjectPath(
"/com/canonical/powerd"));
81 auto uscreen_stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::UScreen>::interface_name());
82 uscreen_session = uscreen_stub_service->object_for_path(dbus::types::ObjectPath(
"/com/canonical/Unity/Screen"));
84 decoding_service_set_client_death_cb(&Private::on_client_died_cb, key, static_cast<void*>(
this));
96 engine_state_change_connection.disconnect();
106 return [
this](
const Engine::State& state)
110 case Engine::State::ready:
113 if (previous_state == Engine::State::playing)
115 timeout(4000,
true, make_clear_wakelock_functor());
119 case Engine::State::playing:
123 parent->meta_data_for_current_track().set(std::get<1>(engine->track_meta_data().get()));
126 request_power_state();
129 case Engine::State::stopped:
132 if (previous_state == Engine::State::playing)
134 timeout(4000,
true, make_clear_wakelock_functor());
138 case Engine::State::paused:
141 if (previous_state == Engine::State::playing)
143 timeout(4000,
true, make_clear_wakelock_functor());
152 previous_state = state;
160 if (parent->is_video_source())
162 if (++display_wakelock_count == 1)
165 if (result.is_error())
166 throw std::runtime_error(result.error().print());
167 disp_cookie = result.value();
168 cout <<
"Requested new display wakelock" << endl;
173 if (++system_wakelock_count == 1)
176 if (result.is_error())
177 throw std::runtime_error(result.error().print());
178 sys_cookie = result.value();
179 cout <<
"Requested new system wakelock" << endl;
183 catch(
const std::exception& e)
185 std::cerr <<
"Warning: failed to request power state: ";
186 std::cerr << e.what() << std::endl;
192 cout << __PRETTY_FUNCTION__ << endl;
197 case wakelock_clear_t::WAKELOCK_CLEAR_INACTIVE:
199 case wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM:
201 if (--system_wakelock_count == 0)
203 cout <<
"Clearing system wakelock" << endl;
208 case wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY:
210 if (--display_wakelock_count == 0)
212 cout <<
"Clearing display wakelock" << endl;
217 case wakelock_clear_t::WAKELOCK_CLEAR_INVALID:
219 cerr <<
"Can't clear invalid wakelock type" << endl;
222 catch(
const std::exception& e)
224 std::cerr <<
"Warning: failed to clear power state: ";
225 std::cerr << e.what() << std::endl;
231 return (parent->is_video_source()) ?
232 wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY : wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM;
238 if (system_wakelock_count.load() > 0)
240 system_wakelock_count = 1;
241 clear_wakelock(wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM);
243 if (display_wakelock_count.load() > 0)
245 display_wakelock_count = 1;
246 clear_wakelock(wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY);
256 std::weak_ptr<Private> weak_self{shared_from_this()};
257 auto wakelock_type = current_wakelock_type();
258 return [weak_self, wakelock_type] {
259 if (
auto self = weak_self.lock())
260 self->clear_wakelock(wakelock_type);
291 PlayerImplementation::PlayerKey
key;
297 const std::string& identity,
298 const std::shared_ptr<core::dbus::Bus>& bus,
299 const std::shared_ptr<core::dbus::Object>& session,
300 const std::shared_ptr<Service>& service,
302 :
media::PlayerSkeleton
304 media::PlayerSkeleton::Configuration
311 d(make_shared<Private>(
332 d->engine->audio_stream_role().set(Player::AudioStreamRole::multimedia);
334 lifetime().set(Player::Lifetime::normal);
335 d->engine->lifetime().set(Player::Lifetime::normal);
339 std::function<uint64_t()> position_getter = [
this]()
341 return d->engine->position().get();
343 position().install(position_getter);
347 std::function<uint64_t()> duration_getter = [
this]()
349 return d->engine->duration().get();
351 duration().install(duration_getter);
353 std::function<bool()> video_type_getter = [
this]()
355 return d->engine->is_video_source().get();
359 std::function<bool()> audio_type_getter = [
this]()
361 return d->engine->is_audio_source().get();
369 d->engine->audio_stream_role().set(new_role);
381 d->engine->lifetime().set(lifetime);
384 d->engine->about_to_finish_signal().connect([
this]()
386 if (d->track_list->has_next())
388 Track::UriType uri = d->track_list->query_uri_for_track(d->track_list->next());
390 d->parent->open_uri(uri);
394 d->engine->client_disconnected_signal().connect([
this]()
398 d->clear_wakelocks();
400 d->on_client_disconnected();
403 d->engine->seeked_to_signal().connect([
this](uint64_t value)
408 d->engine->end_of_stream_signal().connect([
this]()
418 d->engine->video_dimension_changed_signal().connect([
this](uint32_t height, uint32_t width)
422 mask = (
static_cast<uint64_t
>(height) << 32) |
static_cast<uint64_t
>(width);
432 std::function<uint64_t()> position_getter = [
this]()
434 return static_cast<uint64_t
>(0);
436 position().install(position_getter);
438 std::function<uint64_t()> duration_getter = [
this]()
440 return static_cast<uint64_t
>(0);
442 duration().install(duration_getter);
444 std::function<bool()> video_type_getter = [
this]()
450 std::function<bool()> audio_type_getter = [
this]()
459 return d->track_list;
470 return d->engine->open_resource_for_uri(uri);
475 return d->engine->open_resource_for_uri(uri, headers);
480 d->engine->create_video_sink(texture_id);
509 std::cout << __PRETTY_FUNCTION__ << std::endl;
527 d->engine->seek_to(ms);
532 return d->on_client_disconnected;