Files

121 lines
3.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.
*/
#ifndef BINDER_SERVER_H
#define BINDER_SERVER_H
#include <binder/Binder.h>
#include <binder/Parcel.h>
#include "MesonVideoCompositor.h"
using namespace android;
typedef struct pairDisplayLayer {
int32_t displayId;
int32_t layerId;
} pairDisplayLayert;
class BinderServer : public BBinder {
public:
BinderServer();
void run(std::shared_ptr<BinderServer> server);
void setMesonCompositor(std::shared_ptr<mesonVideoCompositor>& c);
private:
class compositorClient {
public:
compositorClient(std::shared_ptr<mesonVideoCompositor> cp)
: mCp(cp) { }
~compositorClient() {
if (mCp.get()) {
for (auto it = mInfos.begin(); it != mInfos.end(); it++)
mCp->destroyLayer(it->second.displayId, it->second.layerId);
}
}
void addDisplay(int32_t displayId, int32_t layerId) {
std::string key = std::to_string(10 * layerId + displayId);
pairDisplayLayert info = {
.displayId = displayId,
.layerId = layerId
};
mInfos.emplace(key, info);
}
void removeDisplay(int32_t displayId, int32_t layerId) {
std::string key = std::to_string(10 * layerId + displayId);
mInfos.erase(key);
}
private:
std::shared_ptr<mesonVideoCompositor> mCp;
std::map<std::string, pairDisplayLayert> mInfos;
};
class ServiceDeathRecipient;
typedef std::pair<std::shared_ptr<compositorClient>, sp<ServiceDeathRecipient>> clientInfo;
class ServerCallback {
public:
ServerCallback() { }
int registerCallback(const Parcel& data, Parcel* reply);
int createLayer(const Parcel& data, Parcel* reply);
int destroyLayer(const Parcel& data, Parcel* reply);
int setTunnelId(const Parcel& data, Parcel* reply);
int setLayerIndex(const Parcel& data, Parcel* reply);
int setLayerZorder(const Parcel& data, Parcel* reply);
int setSourceCrop(const Parcel& data, Parcel* reply);
int setDisplayFrame(const Parcel& data, Parcel* reply);
int getDelayLatency(const Parcel& data, Parcel* reply);
int setToMainPlane(const Parcel& data, Parcel* reply);
int getUiSize(const Parcel& data, Parcel* reply);
void setMesonCompositor(std::shared_ptr<mesonVideoCompositor>& c);
void removeClient(int clientId);
private:
std::shared_ptr<mesonVideoCompositor> mMesonCompositor;
std::map<int, clientInfo> mClients;
std::map<int, sp<IBinder>> mBinders;
};
class ServiceDeathRecipient : public IBinder::DeathRecipient {
public:
ServiceDeathRecipient(ServerCallback *callbck, int id)
: mCb(callbck),
mClientId(id) { }
virtual void binderDied(const wp<IBinder>& who);
private:
ServerCallback *mCb;
int mClientId;
};
virtual status_t onTransact(uint32_t code,
const Parcel& data, Parcel* reply,
uint32_t flags = 0);
typedef int (ServerCallback::*func)(const Parcel&, Parcel*);
private:
std::shared_ptr<ServerCallback> mSCallback;
std::map<uint32_t, func> mServerFunc;
};
#endif