137 lines
4.5 KiB
C++
137 lines
4.5 KiB
C++
/*
|
|||
|
|
* Copyright (C) 2014-2025 Amlogic, Inc. All rights reserved.
|
||
|
|
*
|
||
|
|
* All information contained herein is Amlogic confidential.
|
||
|
|
*
|
||
|
|
* This software is provided to you pursuant to Software License Agreement
|
||
|
|
* (SLA) with Amlogic Inc ("Amlogic"). This software may be used
|
||
|
|
* only in accordance with the terms of this agreement.
|
||
|
|
*
|
||
|
|
* Redistribution and use in source and binary forms, with or without
|
||
|
|
* modification is strictly prohibited without prior written permission from
|
||
|
|
* Amlogic.
|
||
|
|
*
|
||
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <utils/CallStack.h>
|
||
|
|
#include <utils/Mutex.h>
|
||
|
|
|
||
|
|
#include <list>
|
||
|
|
#include <thread>
|
||
|
|
|
||
|
|
#include "ParserEventNotifier.h"
|
||
|
|
|
||
|
|
// #include <android/hidl/allocator/1.0/IAllocator.h>
|
||
|
|
#include <binder/IMemory.h>
|
||
|
|
// #include <hidlmemory/mapping.h>
|
||
|
|
// SubtitleType.h
|
||
|
|
// #include <vendor/amlogic/hardware/subtitleserver/1.0/types.h>
|
||
|
|
#include <IpcSocket.h>
|
||
|
|
#include <RemoteData.h>
|
||
|
|
#include <SubtitleType.h>
|
||
|
|
#include <utils/Looper.h>
|
||
|
|
using namespace android;
|
||
|
|
|
||
|
|
// using ::android::CallStack;
|
||
|
|
// using ::android::hardware::HidlMemory;
|
||
|
|
// using ::android::hardware::hidl_memory;
|
||
|
|
// using ::android::hardware::mapMemory;
|
||
|
|
// using ::android::hardware::Return;
|
||
|
|
// using ::android::hidl::memory::V1_0::IMemory;
|
||
|
|
// using ::android::hidl::allocator::V1_0::IAllocator;
|
||
|
|
|
||
|
|
// using ::vendor::amlogic::hardware::subtitleserver::V1_0::SubtitleHidlParcel;
|
||
|
|
|
||
|
|
enum port_id {
|
||
|
|
MIPC_SUBTITLE_PORTID = 100,
|
||
|
|
};
|
||
|
|
|
||
|
|
namespace amlogic {
|
||
|
|
|
||
|
|
class AndroidCallbackHandler : public android::RefBase {
|
||
|
|
public:
|
||
|
|
virtual ~AndroidCallbackHandler() {};
|
||
|
|
virtual bool onSubtitleDisplayNotify(SubtitleHidlParcel& event) = 0;
|
||
|
|
|
||
|
|
virtual bool onSubtitleEventNotify(SubtitleHidlParcel& event) = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
class AndroidCallbackMessageQueue : public ParserEventNotifier, public android::MessageHandler {
|
||
|
|
public:
|
||
|
|
static sp<AndroidCallbackMessageQueue> Instance();
|
||
|
|
|
||
|
|
AndroidCallbackMessageQueue() = delete;
|
||
|
|
AndroidCallbackMessageQueue(sp<AndroidCallbackHandler> proxy);
|
||
|
|
~AndroidCallbackMessageQueue();
|
||
|
|
|
||
|
|
bool postDisplayData(const char* data, int type, int x, int y, int width, int height,
|
||
|
|
int videoWidth, int videoHeight, int size, int cmd, int objectSegmentId);
|
||
|
|
|
||
|
|
virtual void onSubtitleDataEvent(int event, int id) override;
|
||
|
|
virtual void onSubtitleDimension(int width, int height) override;
|
||
|
|
// report available state, may error
|
||
|
|
virtual void onSubtitleAvailable(int available) override;
|
||
|
|
|
||
|
|
virtual void onVideoAfdChange(int afd, int playerid) override;
|
||
|
|
|
||
|
|
// for ttx page pip
|
||
|
|
virtual void onMixVideoEvent(int val) override;
|
||
|
|
|
||
|
|
virtual void onSubtitleLanguage(char* lang) override;
|
||
|
|
|
||
|
|
// what: info type, extra: value, for info extension
|
||
|
|
virtual void onSubtitleInfo(int what, int extra) override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
struct SubtitleData {
|
||
|
|
IMemory* mem;
|
||
|
|
int type;
|
||
|
|
int x;
|
||
|
|
int y;
|
||
|
|
int width;
|
||
|
|
int height;
|
||
|
|
int videoWidth;
|
||
|
|
int videoHeight;
|
||
|
|
int size;
|
||
|
|
bool isShow;
|
||
|
|
int objectSegmentId; // objectSegmentId: the current number object segment object.
|
||
|
|
int shmid;
|
||
|
|
char* lang;
|
||
|
|
};
|
||
|
|
|
||
|
|
void handleMessage(const android::Message& message);
|
||
|
|
void looperLoop();
|
||
|
|
int copyShareMemory(const char* data, int size);
|
||
|
|
void initSender();
|
||
|
|
void deInitSender();
|
||
|
|
int handleReceivedReadyData(int fd);
|
||
|
|
void sendData(std::shared_ptr<RemoteData> remoteData);
|
||
|
|
std::thread mCallbackLooperThread;
|
||
|
|
sp<android::Looper> mLooper;
|
||
|
|
std::list<std::unique_ptr<SubtitleData>> mSubtitleData;
|
||
|
|
|
||
|
|
// we transfer to proxy to do the real work.
|
||
|
|
sp<AndroidCallbackHandler> mProxyHandler;
|
||
|
|
|
||
|
|
mutable android::Mutex mLock;
|
||
|
|
bool mStopped;
|
||
|
|
static sp<AndroidCallbackMessageQueue> sInstance;
|
||
|
|
std::shared_ptr<IpcSocket> mDataSender;
|
||
|
|
std::vector<int> mSendFds;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace amlogic
|