183 lines
4.8 KiB
C++
183 lines
4.8 KiB
C++
/*
|
|
* Copyright (C) 2024 Amlogic Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <VscalerEvent.h>
|
|
|
|
std::mutex VscalerEvent::sLock;
|
|
VscalerEvent * VscalerEvent::sInstance(nullptr);
|
|
|
|
VscalerEvent::VscalerEvent() {
|
|
initialize();
|
|
for (int i = 0; i < VT_SCALER_MAX; i++) {
|
|
std::deque<VscEventType> deqEvent;
|
|
mVscEvents.emplace(i, deqEvent);
|
|
}
|
|
}
|
|
|
|
VscalerEvent::~VscalerEvent() {
|
|
initialize();
|
|
}
|
|
|
|
VscalerEvent &VscalerEvent::getInstance() {
|
|
std::lock_guard<std::mutex> lock(sLock);
|
|
VscalerEvent *instance = sInstance;
|
|
if (instance == nullptr) {
|
|
instance = new VscalerEvent();
|
|
sInstance = instance;
|
|
}
|
|
|
|
return *instance;
|
|
}
|
|
|
|
void VscalerEvent::setBinder(std::shared_ptr<BinderServer> server)
|
|
{
|
|
mServer = server;
|
|
}
|
|
|
|
void VscalerEvent::addEventToQueue(VscEventType event) {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
if (mServer.get() != NULL) {
|
|
for (int i = VT_SCALER_0; i < VT_SCALER_MAX; i++) {
|
|
mServer->broadcastEvent(i, event);
|
|
}
|
|
return;
|
|
}
|
|
for (auto it = mVscEvents.begin(); it != mVscEvents.end(); it++) {
|
|
it->second.push_back(event);
|
|
}
|
|
mVscEvent.push_back(event);
|
|
}
|
|
|
|
void VscalerEvent::addEventToQueue(uint32_t id, VscEventType event) {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
if (mServer.get() != NULL) {
|
|
mServer->broadcastEvent(id, event);
|
|
return;
|
|
}
|
|
|
|
auto it = mVscEvents.find(id);
|
|
if (it != mVscEvents.end()) {
|
|
it->second.push_back(event);
|
|
}
|
|
mVscEvent.push_back(event);
|
|
}
|
|
|
|
VscEventType VscalerEvent::getEvent() {
|
|
VscEventType event = {0};
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
event.eventId = 0;
|
|
if (mVscEvent.size() > 0) {
|
|
event = mVscEvent[0];
|
|
mVscEvent.pop_front();
|
|
}
|
|
mVscEvents.clear();
|
|
return event;
|
|
}
|
|
|
|
VscEventType VscalerEvent::getEvent(uint32_t id) {
|
|
VscEventType event = {0};
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
event.eventId = 0;
|
|
if (mVscEvents.size() > 0) {
|
|
auto it = mVscEvents.find(id);
|
|
if (it != mVscEvents.end() && it->second.size() > 0) {
|
|
event = it->second[0];
|
|
it->second.pop_front();
|
|
}
|
|
}
|
|
mVscEvent.clear();
|
|
return event;
|
|
}
|
|
|
|
int32_t VscalerEvent::initialize() {
|
|
mVscEvent.clear();
|
|
mVscEvents.clear();
|
|
return 0;
|
|
}
|
|
|
|
bool VscalerEvent::getEventState() {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
return mVscEvent.size() > 0;
|
|
}
|
|
|
|
bool VscalerEvent::getEventState(uint32_t id) {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
auto it = mVscEvents.find(id);
|
|
if (it != mVscEvents.end())
|
|
return it->second.size() > 0;
|
|
return false;
|
|
}
|
|
|
|
VscEventType VscalerEvent::makeEventData(int displayId,
|
|
int scalerId, uint32_t eventId, uint8_t* data, int len) {
|
|
VscEventType event = { 0 };
|
|
event.displayId = displayId;
|
|
event.scalerId = scalerId;
|
|
event.eventId = eventId;
|
|
if (data) {
|
|
if (len >= (int)sizeof(event.data))
|
|
len = sizeof(event.data) - 1;
|
|
memcpy(event.data, data, len);
|
|
}
|
|
return event;
|
|
}
|
|
|
|
VscEventType VscalerEvent::makeEventData(int displayId,
|
|
uint32_t eventId, uint8_t* data, int len) {
|
|
VscEventType event = {0};
|
|
event.displayId = displayId;
|
|
event.scalerId = INVALID_ID;
|
|
event.eventId = eventId;
|
|
if (data) {
|
|
if (len >= (int)sizeof(event.data))
|
|
len = sizeof(event.data) - 1;
|
|
memcpy(event.data, data, len);
|
|
}
|
|
return event;
|
|
}
|
|
|
|
void VscalerEvent::makeEventNoData(int scalerId, uint32_t eventId) {
|
|
VscEventType event = { 0 };
|
|
event.displayId = INVALID_ID;
|
|
event.scalerId = scalerId;
|
|
event.eventId = eventId;
|
|
addEventToQueue(scalerId, event);
|
|
}
|
|
|
|
void VscalerEvent::makeBspError(const char* data) {
|
|
if (!data)
|
|
return;
|
|
|
|
VscEventType event = { 0 };
|
|
int len = strlen(data);
|
|
event.displayId = INVALID_ID;
|
|
event.scalerId = INVALID_ID;
|
|
event.eventId = V4L2_CID_EXT_VSC_SUBSCRIBE_BSP_ERROR;
|
|
if (len >= (int)sizeof(event.data))
|
|
len = sizeof(event.data) - 1;
|
|
memcpy(event.data, data, len);
|
|
addEventToQueue(event);
|
|
}
|
|
|
|
void VscalerEvent::makeMuteOff(int sclarId) {
|
|
VscEventType event = { 0 };
|
|
event.displayId = INVALID_ID;
|
|
event.scalerId = sclarId;
|
|
event.eventId = V4L2_CID_EXT_VSC_SUBSCRIBE_MUTE_OFF;
|
|
addEventToQueue(sclarId, event);
|
|
}
|