123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- #include <hyperion/ComponentRegister.h>
- #include <iostream>
- #include <hyperion/Hyperion.h>
- #include <hyperion/GrabberWrapper.h>
- using namespace hyperion;
- ComponentRegister::ComponentRegister(Hyperion* hyperion)
- : _hyperion(hyperion)
- , _log(nullptr)
- {
- QString subComponent = hyperion->property("instance").toString();
- _log= Logger::getInstance("COMPONENTREG", subComponent);
- // init all comps to false
- QVector<hyperion::Components> vect;
- vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE;
- bool areScreenGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
- bool areVideoGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
- bool areAudioGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::AUDIO).isEmpty();
- bool flatBufServerAvailable { false };
- bool protoBufServerAvailable{ false };
- #if defined(ENABLE_FLATBUF_SERVER)
- flatBufServerAvailable = true;
- #endif
- #if defined(ENABLE_PROTOBUF_SERVER)
- protoBufServerAvailable = true;
- #endif
- if (areScreenGrabberAvailable)
- {
- vect << COMP_GRABBER;
- }
- if (areAudioGrabberAvailable)
- {
- vect << COMP_AUDIO;
- }
- if (areVideoGrabberAvailable)
- {
- vect << COMP_V4L;
- }
- if (areScreenGrabberAvailable || areVideoGrabberAvailable || flatBufServerAvailable || protoBufServerAvailable)
- {
- vect << COMP_BLACKBORDER;
- }
- #if defined(ENABLE_BOBLIGHT_SERVER)
- vect << COMP_BOBLIGHTSERVER;
- #endif
- #if defined(ENABLE_FORWARDER)
- vect << COMP_FORWARDER;
- #endif
- for(auto e : std::as_const(vect))
- {
- _componentStates.emplace(e, (e == COMP_ALL));
- }
- connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
- connect(_hyperion, &Hyperion::compStateChangeRequestAll, this, &ComponentRegister::handleCompStateChangeRequestAll);
- }
- ComponentRegister::~ComponentRegister()
- {
- }
- int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
- {
- return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
- }
- void ComponentRegister::setNewComponentState(hyperion::Components comp, bool isActive)
- {
- if (_componentStates.count(comp) > 0)
- {
- if (_componentStates[comp] != isActive)
- {
- Debug(_log, "%s: %s", componentToString(comp), (isActive ? "enabled" : "disabled"));
- _componentStates[comp] = isActive;
- // emit component has changed state
- emit updatedComponentState(comp, isActive);
- }
- }
- }
- void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool isActive)
- {
- if(comps == COMP_ALL )
- {
- handleCompStateChangeRequestAll(isActive,{});
- }
- }
- void ComponentRegister::handleCompStateChangeRequestAll(bool isActive, const ComponentList& excludeList)
- {
- if (!_inProgress)
- {
- _inProgress = true;
- if(!isActive)
- {
- if (excludeList.isEmpty())
- {
- Debug(_log,"Disable Hyperion instance, store current components' state");
- }
- else
- {
- Debug(_log,"Disable selected Hyperion components, store their current state");
- }
- for(const auto &comp : _componentStates)
- {
- if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
- {
- // save state
- _prevComponentStates.emplace(comp.first, comp.second);
- // disable if enabled
- if(comp.second)
- {
- emit _hyperion->compStateChangeRequest(comp.first, false);
- }
- }
- }
- if (excludeList.isEmpty())
- {
- setNewComponentState(COMP_ALL, false);
- }
- }
- else
- {
- if(isActive && !_prevComponentStates.empty())
- {
- if (excludeList.isEmpty())
- {
- Debug(_log,"Enable Hyperion instance, restore components' previous state");
- }
- else
- {
- Debug(_log,"Enable selected Hyperion components, restore their previous state");
- }
- for(const auto &comp : _prevComponentStates)
- {
- if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
- {
- // if comp was enabled, enable again
- if(comp.second)
- {
- emit _hyperion->compStateChangeRequest(comp.first, true);
- }
- }
- }
- _prevComponentStates.clear();
- if (excludeList.isEmpty())
- {
- setNewComponentState(COMP_ALL, true);
- }
- }
- }
- _inProgress = false;
- }
- }
|