36 #define UNUSED __attribute__((unused))
43 template<
typename Parent>
45 public std::enable_shared_from_this<Private>
49 WAKELOCK_CLEAR_INACTIVE,
50 WAKELOCK_CLEAR_DISPLAY,
51 WAKELOCK_CLEAR_SYSTEM,
52 WAKELOCK_CLEAR_INVALID
58 display_state_lock(config.power_state_controller->display_state_lock()),
59 system_state_lock(config.power_state_controller->system_state_lock()),
61 track_list(
std::make_shared<NullTrackList>()),
62 system_wakelock_count(0),
63 display_wakelock_count(0),
64 previous_state(Engine::State::stopped),
65 engine_state_change_connection(engine->state().changed().connect(make_state_change_handler())),
66 engine_playback_status_change_connection(engine->playback_status_changed_signal().connect(make_playback_status_change_handler()))
68 std::cout <<
"Private parent instance: " << parent << std::endl;
72 std::cout <<
"Acquired new display state: " << state << std::endl;
77 std::cout <<
"Released display state: " << state << std::endl;
82 std::cout <<
"Acquired new system state: " << state << std::endl;
87 std::cout <<
"Released system state: " << state << std::endl;
100 engine_state_change_connection.disconnect();
102 std::cout <<
"** Disconnecting playback_status_changed_signal connection";
106 engine_playback_status_change_connection.disconnect();
116 return [
this](
const Engine::State& state)
118 std::cout <<
"Setting state for parent: " << parent << std::endl;
121 case Engine::State::ready:
124 if (previous_state == Engine::State::playing)
126 timeout(4000,
true, make_clear_wakelock_functor());
130 case Engine::State::playing:
134 parent->meta_data_for_current_track().set(std::get<1>(engine->track_meta_data().get()));
137 std::cout <<
"Requesting power state" << std::endl;
138 request_power_state();
141 case Engine::State::stopped:
144 if (previous_state == Engine::State::playing)
146 timeout(4000,
true, make_clear_wakelock_functor());
150 case Engine::State::paused:
153 if (previous_state == Engine::State::playing)
155 timeout(4000,
true, make_clear_wakelock_functor());
164 previous_state = state;
172 std::cout <<
"Emiting playback_status_changed for parent: " << parent << std::endl;
173 parent->emit_playback_status_changed(status);
179 std::cout << __PRETTY_FUNCTION__ << std::endl;
182 if (parent->is_video_source())
184 if (++display_wakelock_count == 1)
186 std::cout <<
"Requesting new display wakelock." << std::endl;
187 display_state_lock->request_acquire(media::power::DisplayState::on);
188 std::cout <<
"Requested new display wakelock." << std::endl;
193 if (++system_wakelock_count == 1)
195 std::cout <<
"Requesting new system wakelock." << std::endl;
196 system_state_lock->request_acquire(media::power::SystemState::active);
197 std::cout <<
"Requested new system wakelock." << std::endl;
201 catch(
const std::exception& e)
203 std::cerr <<
"Warning: failed to request power state: ";
204 std::cerr << e.what() << std::endl;
210 cout << __PRETTY_FUNCTION__ << endl;
215 case wakelock_clear_t::WAKELOCK_CLEAR_INACTIVE:
217 case wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM:
219 if (--system_wakelock_count == 0)
221 std::cout <<
"Clearing system wakelock." << std::endl;
222 system_state_lock->request_release(media::power::SystemState::active);
225 case wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY:
227 if (--display_wakelock_count == 0)
229 std::cout <<
"Clearing display wakelock." << std::endl;
230 display_state_lock->request_release(media::power::DisplayState::on);
233 case wakelock_clear_t::WAKELOCK_CLEAR_INVALID:
235 cerr <<
"Can't clear invalid wakelock type" << endl;
238 catch(
const std::exception& e)
240 std::cerr <<
"Warning: failed to clear power state: ";
241 std::cerr << e.what() << std::endl;
247 return (parent->is_video_source()) ?
248 wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY : wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM;
254 if (system_wakelock_count.load() > 0)
256 system_wakelock_count = 1;
257 clear_wakelock(wakelock_clear_t::WAKELOCK_CLEAR_SYSTEM);
259 if (display_wakelock_count.load() > 0)
261 display_wakelock_count = 1;
262 clear_wakelock(wakelock_clear_t::WAKELOCK_CLEAR_DISPLAY);
272 std::weak_ptr<Private> weak_self{this->shared_from_this()};
273 auto wakelock_type = current_wakelock_type();
274 return [weak_self, wakelock_type] {
275 if (
auto self = weak_self.lock())
276 self->clear_wakelock(wakelock_type);
302 template<
typename Parent>
305 d{std::make_shared<Private>(
this, config)}
308 Parent::can_play().set(
true);
309 Parent::can_pause().set(
true);
310 Parent::can_seek().set(
true);
311 Parent::can_go_previous().set(
true);
312 Parent::can_go_next().set(
true);
313 Parent::is_video_source().set(
false);
314 Parent::is_audio_source().set(
false);
315 Parent::is_shuffle().set(
true);
316 Parent::playback_rate().set(1.f);
317 Parent::playback_status().set(Player::PlaybackStatus::null);
318 Parent::loop_status().set(Player::LoopStatus::none);
319 Parent::position().set(0);
320 Parent::duration().set(0);
321 Parent::audio_stream_role().set(Player::AudioStreamRole::multimedia);
322 d->engine->audio_stream_role().set(Player::AudioStreamRole::multimedia);
323 Parent::orientation().set(Player::Orientation::rotate0);
324 Parent::lifetime().set(Player::Lifetime::normal);
325 d->engine->lifetime().set(Player::Lifetime::normal);
329 std::function<uint64_t()> position_getter = [
this]()
331 return d->engine->position().get();
333 Parent::position().install(position_getter);
337 std::function<uint64_t()> duration_getter = [
this]()
339 return d->engine->duration().get();
341 Parent::duration().install(duration_getter);
343 std::function<bool()> video_type_getter = [
this]()
345 return d->engine->is_video_source().get();
347 Parent::is_video_source().install(video_type_getter);
349 std::function<bool()> audio_type_getter = [
this]()
351 return d->engine->is_audio_source().get();
353 Parent::is_audio_source().install(audio_type_getter);
359 d->engine->audio_stream_role().set(new_role);
366 Parent::orientation().set(o);
371 d->engine->lifetime().set(lifetime);
374 d->engine->about_to_finish_signal().connect([
this]()
376 Parent::about_to_finish()();
378 if (d->track_list->has_next())
380 Track::UriType uri = d->track_list->query_uri_for_track(d->track_list->next());
382 d->parent->open_uri(uri);
386 d->engine->client_disconnected_signal().connect([
this]()
390 d->clear_wakelocks();
392 d->on_client_disconnected();
395 d->engine->seeked_to_signal().connect([
this](uint64_t value)
397 Parent::seeked_to()(value);
400 d->engine->end_of_stream_signal().connect([
this]()
402 Parent::end_of_stream()();
407 Parent::video_dimension_changed()(dimensions);
410 d->engine->error_signal().connect([
this](
const Player::Error& e)
416 std::weak_ptr<Private> wp{d};
418 d->config.client_death_observer->register_for_death_notifications_with_key(config.key);
421 if (
auto sp = wp.lock())
423 if (died != sp->config.key)
426 static const std::chrono::milliseconds timeout{1000};
429 if (
auto sp = wp.lock())
430 sp->on_client_died();
436 template<
typename Parent>
442 std::function<uint64_t()> position_getter = [
this]()
444 return static_cast<uint64_t
>(0);
446 Parent::position().install(position_getter);
448 std::function<uint64_t()> duration_getter = [
this]()
450 return static_cast<uint64_t
>(0);
452 Parent::duration().install(duration_getter);
454 std::function<bool()> video_type_getter = [
this]()
458 Parent::is_video_source().install(video_type_getter);
460 std::function<bool()> audio_type_getter = [
this]()
464 Parent::is_audio_source().install(audio_type_getter);
467 template<
typename Parent>
470 return d->track_list;
474 template<
typename Parent>
477 return d->config.key;
480 template<
typename Parent>
483 d->engine->create_video_sink(texture_id);
484 return media::video::Sink::Ptr{};
487 template<
typename Parent>
490 return d->engine->open_resource_for_uri(uri);
493 template<
typename Parent>
496 return d->engine->open_resource_for_uri(uri, headers);
499 template<
typename Parent>
504 template<
typename Parent>
509 template<
typename Parent>
515 template<
typename Parent>
521 template<
typename Parent>
524 std::cout << __PRETTY_FUNCTION__ << std::endl;
528 template<
typename Parent>
531 d->engine->seek_to(ms);
534 template<
typename Parent>
537 return d->on_client_disconnected;
540 template<
typename Parent>
543 Parent::playback_status_changed()(status);