/* * Copyright (c) 2019 Amlogic, Inc. All rights reserved. * * This source code is subject to the terms and conditions defined in the * file 'LICENSE' which is part of this source code package. * * Description: */ #define LOG_MODULE_TAG "TV" #define LOG_CLASS_TAG "TvClientWrapper" #include "TvClientWrapper.h" #include "CTvLog.h" #include "TvClient.h" #include #include #include #ifdef __cplusplus extern "C" { #endif typedef void (*TvClientEventCallbackFunc)(event_type_t eventType, void *eventData); class TvClientWrapper : public TvClient::TvClientIObserver { public: TvClientWrapper() { mpTvClient = TvClient::GetInstance(); mpTvClient->setTvClientObserver(this); mEventCallbackFunc = NULL; } ~TvClientWrapper() { LOGD("%s.\n", __FUNCTION__); if (mpTvClient != NULL) { mpTvClient->Release(); mpTvClient = NULL; } if (mEventCallbackFunc != NULL) { mEventCallbackFunc = NULL; } } int RegisterCallback(TvClientEventCallbackFunc eventCallbackFunc) { if (eventCallbackFunc == NULL) { LOGD("eventCallbackFunc is NULL.\n"); return -1; } else { mEventCallbackFunc = eventCallbackFunc; return 0; } } int StartTv(tv_source_input_t source) { return mpTvClient->StartTv(source); } int StopTv(tv_source_input_t source) { return mpTvClient->StopTv(source); } int SwitchSource(tv_source_input_t source) { return mpTvClient->SwitchSource(source); } tv_source_input_t GetCurrentSource() { return mpTvClient->GetCurrentSource(); } int SetEdidVersion(tv_source_input_t source, int edidVer) { return mpTvClient->SetEdidVersion(source, edidVer); } int GetEdidVersion(tv_source_input_t source) { return mpTvClient->GetEdidVersion(source); } int SetEdidData(tv_source_input_t source, char *dataBuf) { return mpTvClient->SetEdidData(source, dataBuf); } int GetEdidData(tv_source_input_t source, char *dataBuf) { LOGD("%s\n", __FUNCTION__); char buf[512] = {0}; int ret = mpTvClient->GetEdidData(source, buf); if (ret < 0) { LOGD("%s failed.\n", __FUNCTION__); } else { memcpy(dataBuf, buf, sizeof(buf)); } return ret; } int SetVdinWorkMode(vdin_work_mode_t vdinWorkMode) { return mpTvClient->SetVdinWorkMode(vdinWorkMode); } int GetHdmiSPDInfo(tv_source_input_t source, char *data, size_t datalen) { return mpTvClient->GetHdmiSPDInfo(source, data, datalen); } int GetCurrentSourceFrameHeight() { return mpTvClient->GetCurrentSourceFrameHeight(); } int GetCurrentSourceFrameWidth() { return mpTvClient->GetCurrentSourceFrameWidth(); } int GetCurrentSourceFrameFps() { return mpTvClient->GetCurrentSourceFrameFps(); } int GetCurrentSourceColorDepth() { return mpTvClient->GetCurrentSourceColorDepth(); } tvin_aspect_ratio_t GetCurrentSourceAspectRatio() { return mpTvClient->GetCurrentSourceAspectRatio(); } tvin_color_fmt_t GetCurrentSourceColorFormat() { return mpTvClient->GetCurrentSourceColorFormat(); } tvin_color_range_t GetCurrentSourceColorRange() { return mpTvClient->GetCurrentSourceColorRange(); } tvin_line_scan_mode_t GetCurrentSourceLineScanMode() { return mpTvClient->GetCurrentSourceLineScanMode(); } int GetSourceConnectStatus(tv_source_input_t source) { return mpTvClient->GetSourceConnectStatus(source); } int SetEdidBoostOn(int bBoostOn) { return mpTvClient->SetEdidBoostOn(bBoostOn); } int GetCurrentSourceAllmInfo(tvin_latency_s *info) { return mpTvClient->GetCurrentSourceAllmInfo(info); } int SetHdmiAllmEnabled(bool enable) { return mpTvClient->SetHdmiAllmEnabled(enable); } bool GetHdmiAllmEnabled() { return mpTvClient->GetHdmiAllmEnabled(); } bool GetHdmiVrrSupport() { return mpTvClient->GetHdmiVrrSupport(); } int SetHdmiVrrEnabled(bool enable) { return mpTvClient->SetHdmiVrrEnabled(enable); } bool GetHdmiVrrEnabled() { return mpTvClient->GetHdmiVrrEnabled(); } vdin_vrr_mode_t GetHdmiVrrMode() { return mpTvClient->GetHdmiVrrMode(); } bool GetHdmiQmsSupport() { return mpTvClient->GetHdmiQmsSupport(); } int SetHdmiQmsEnabled(bool enable) { return mpTvClient->SetHdmiQmsEnabled(enable); } bool GetHdmiQmsEnabled() { return mpTvClient->GetHdmiQmsEnabled(); } int GetCurrentStdInfo(tvin_std_s *info) { return mpTvClient->GetCurrentStdInfo(info); } int SetAudioDecoderId(int channel, int id) { return mpTvClient->SetAudioDecoderId(channel, id); } int SetAvAudioModeEnabled(bool enable) { return mpTvClient->SetAvAudioModeEnabled(enable); } int StartTvInPIP(tv_source_input_t source) { return mpTvClient->StartTvInPIP(source); } int StopTvInPIP(tv_source_input_t source) { return mpTvClient->StopTvInPIP(source); } int SetHdmiDlgEnabled(bool enable) { return mpTvClient->SetHdmiDlgEnabled(enable); } bool GetHdmiDlgEnabled() { return mpTvClient->GetHdmiDlgEnabled(); } bool GetHdmiDlgSupport(void) { return mpTvClient->GetHdmiDlgSupport(); } void onTvClientEvent(CTvEvent &event) { int eventType = event.getEventType(); LOGD("%s: eventType: %d.\n", __FUNCTION__, eventType); switch (eventType) { case CTvEvent::TV_EVENT_SIGNAL_DETECT: { LOGD("%s: signal event.\n", __FUNCTION__); TvEvent::SignalDetectEvent *signalDetectEvent = (TvEvent::SignalDetectEvent *)(&event); SignalDetectCallback_t SignalDetectCallback; SignalDetectCallback.SourceInput = (tv_source_input_t)signalDetectEvent->mSourceInput; SignalDetectCallback.SignalFmt = (tvin_sig_fmt_t)signalDetectEvent->mFmt; SignalDetectCallback.TransFmt = (tvin_trans_fmt_t)signalDetectEvent->mTrans_fmt; SignalDetectCallback.SignalStatus = (tvin_sig_status_t)signalDetectEvent->mStatus; SignalDetectCallback.isDviSignal = signalDetectEvent->mDviFlag; SignalDetectCallback.Hdrinfo = signalDetectEvent->mhdr_info; mEventCallbackFunc(TV_EVENT_TYPE_SIGNAL_DETECT, &SignalDetectCallback); break; } case CTvEvent::TV_EVENT_SOURCE_CONNECT: { LOGD("%s: connect event.\n", __FUNCTION__); TvEvent::SourceConnectEvent *sourceConnectEvent = (TvEvent::SourceConnectEvent *)(&event); SourceConnectCallback_t SourceConnectCallback; SourceConnectCallback.SourceInput = (tv_source_input_t)sourceConnectEvent->mSourceInput; SourceConnectCallback.ConnectionState = sourceConnectEvent->connectionState; mEventCallbackFunc(TV_EVENT_TYPE_SOURCE_CONNECT, &SourceConnectCallback); break; } case CTvEvent::TV_EVENT_SIG_DV_ALLM: { LOGD("%s: allm event.\n", __FUNCTION__); TvEvent::SignalDvAllmEvent *signalDvAllmEvent = (TvEvent::SignalDvAllmEvent *)(&event); SignalDvAllmCallback_t SignalDvAllmCallback; SignalDvAllmCallback.allm_mode = signalDvAllmEvent->allm_mode; SignalDvAllmCallback.it_content = signalDvAllmEvent->it_content; SignalDvAllmCallback.cn_type = (tvin_cn_type_t)signalDvAllmEvent->cn_type; mEventCallbackFunc(TV_EVENT_TYPE_SIG_DV_ALLM, &SignalDvAllmCallback); break; } case CTvEvent::TV_EVENT_PIP_SIGNAL_DETECT: { LOGD("%s: pip signal event.\n", __FUNCTION__); TvEvent::PipSignalDetectEvent *pipDetectEvent = (TvEvent::PipSignalDetectEvent *)(&event); PipSignalDetectCallback_t PipSignalDetectCallback; PipSignalDetectCallback.SourceInput = (tv_source_input_t)pipDetectEvent->mSourceInput; PipSignalDetectCallback.SignalFmt = (tvin_sig_fmt_t)pipDetectEvent->mFmt; PipSignalDetectCallback.TransFmt = (tvin_trans_fmt_t)pipDetectEvent->mTrans_fmt; PipSignalDetectCallback.SignalStatus = (tvin_sig_status_t)pipDetectEvent->mStatus; PipSignalDetectCallback.isDviSignal = pipDetectEvent->mDviFlag; PipSignalDetectCallback.Hdrinfo = pipDetectEvent->mhdr_info; mEventCallbackFunc(TV_EVENT_TYPE_PIP_SIGNAL_DETECT, &PipSignalDetectCallback); break; } default: LOGD("%s: invalid event!\n", __FUNCTION__); break; } return; } TvClient *mpTvClient; TvClientEventCallbackFunc mEventCallbackFunc; }; static void HandleTvClientEvent(event_type_t eventType, void *eventData) { if (eventType == TV_EVENT_TYPE_SIGNAL_DETECT) { SignalDetectCallback_t *SignalDetectCallback = (SignalDetectCallback_t *)(eventData); LOGD("%s: source: %d, signalFmt: %d, transFmt: %d, status: %d, isDVI: %d, " "Hdrinfo: %ud\n", __FUNCTION__, SignalDetectCallback->SourceInput, SignalDetectCallback->SignalFmt, SignalDetectCallback->TransFmt, SignalDetectCallback->SignalStatus, SignalDetectCallback->isDviSignal, SignalDetectCallback->Hdrinfo); } else if (eventType == TV_EVENT_TYPE_SOURCE_CONNECT) { SourceConnectCallback_t *SourceConnectCallback = (SourceConnectCallback_t *)eventData; LOGD("%s: source: %d, connectStatus: %d\n", __FUNCTION__, SourceConnectCallback->SourceInput, SourceConnectCallback->ConnectionState); } else if (eventType == TV_EVENT_TYPE_SIG_DV_ALLM) { SignalDvAllmCallback_t *SignalDvAllmCallback = (SignalDvAllmCallback_t *)eventData; LOGD("%s: allm_mode: %d, it_content: %d, cn_type: %d\n", __FUNCTION__, SignalDvAllmCallback->allm_mode, SignalDvAllmCallback->it_content, SignalDvAllmCallback->cn_type); } else if (eventType == TV_EVENT_TYPE_PIP_SIGNAL_DETECT) { PipSignalDetectCallback_t *PipSignalDetectCallback = (PipSignalDetectCallback_t *)eventData; LOGD("%s: pip source: %d, signalFmt: %d, transFmt: %d, status: %d, isDVI: " "%d, Hdrinfo: %ud\n", __FUNCTION__, PipSignalDetectCallback->SourceInput, PipSignalDetectCallback->SignalFmt, PipSignalDetectCallback->TransFmt, PipSignalDetectCallback->SignalStatus, PipSignalDetectCallback->isDviSignal, PipSignalDetectCallback->Hdrinfo); } else { LOGD("%s: invalid event.\n", __FUNCTION__); } mEventCallback(eventType, eventData); } /**************************************wrapper * api*******************************************/ static std::shared_ptr instance_ = nullptr; static std::shared_ptr GetInstance(void) { if (!instance_) { instance_ = std::shared_ptr(new TvClientWrapper()); GetInstance()->RegisterCallback(HandleTvClientEvent); LOGD("%s: start GetInstance.\n", __FUNCTION__); } return instance_; } int StartTv(tv_source_input_t source) { return GetInstance()->StartTv(source); } int StopTv(tv_source_input_t source) { return GetInstance()->StopTv(source); } int SwitchSource(tv_source_input_t source) { return GetInstance()->SwitchSource(source); } tv_source_input_t GetCurrentSource() { return GetInstance()->GetCurrentSource(); } int SetEdidVersion(tv_source_input_t source, int edidVer) { return GetInstance()->SetEdidVersion(source, edidVer); } int GetEdidVersion(tv_source_input_t source) { return GetInstance()->GetEdidVersion(source); } int SetEdidData(tv_source_input_t source, char *dataBuf) { return GetInstance()->SetEdidData(source, dataBuf); } int GetEdidData(tv_source_input_t source, char *dataBuf) { return GetInstance()->GetEdidData(source, dataBuf); } int GetHdmiSPDInfo(tv_source_input_t source, char *data, size_t datalen) { return GetInstance()->GetHdmiSPDInfo(source, data, datalen); } int setTvEventCallback(EventCallback Callback) { if (Callback == NULL) { LOGD("%s: Callback is NULL.\n", __FUNCTION__); } else { mEventCallback = Callback; } return 0; } int SetVdinWorkMode(vdin_work_mode_t vdinWorkMode) { return GetInstance()->SetVdinWorkMode(vdinWorkMode); } int GetCurrentSourceFrameHeight() { return GetInstance()->GetCurrentSourceFrameHeight(); } int GetCurrentSourceFrameWidth() { return GetInstance()->GetCurrentSourceFrameWidth(); } int GetCurrentSourceFrameFps() { return GetInstance()->GetCurrentSourceFrameFps(); } int GetCurrentSourceColorDepth() { return GetInstance()->GetCurrentSourceColorDepth(); } tvin_aspect_ratio_t GetCurrentSourceAspectRatio() { return GetInstance()->GetCurrentSourceAspectRatio(); } tvin_color_fmt_t GetCurrentSourceColorFormat() { return GetInstance()->GetCurrentSourceColorFormat(); } tvin_color_range_t GetCurrentSourceColorRange() { return GetInstance()->GetCurrentSourceColorRange(); } tvin_line_scan_mode_t GetCurrentSourceLineScanMode() { return GetInstance()->GetCurrentSourceLineScanMode(); } int GetSourceConnectStatus(tv_source_input_t source) { return GetInstance()->GetSourceConnectStatus(source); } int SetEdidBoostOn(int bBoostOn) { return GetInstance()->SetEdidBoostOn(bBoostOn); } int GetCurrentStdInfo(tvin_std_s *info) { return GetInstance()->GetCurrentStdInfo(info); } int GetCurrentSourceAllmInfo(tvin_latency_s *info) { return GetInstance()->GetCurrentSourceAllmInfo(info); } int SetHdmiAllmEnabled(bool enable) { return GetInstance()->SetHdmiAllmEnabled(enable); } bool GetHdmiAllmEnabled() { return GetInstance()->GetHdmiAllmEnabled(); } bool GetHdmiVrrSupport() { return GetInstance()->GetHdmiVrrSupport(); } int SetHdmiVrrEnabled(bool enable) { return GetInstance()->SetHdmiVrrEnabled(enable); } bool GetHdmiVrrEnabled() { return GetInstance()->GetHdmiVrrEnabled(); } vdin_vrr_mode_t GetHdmiVrrMode() { return GetInstance()->GetHdmiVrrMode(); } bool GetHdmiQmsSupport() { return GetInstance()->GetHdmiQmsSupport(); } int SetHdmiQmsEnabled(bool enable) { return GetInstance()->SetHdmiQmsEnabled(enable); } bool GetHdmiQmsEnabled() { return GetInstance()->GetHdmiQmsEnabled(); } int SetAudioDecoderId(int channel, int id) {return GetInstance()->SetAudioDecoderId(channel, id); } int SetAvAudioModeEnabled(bool enable) {return GetInstance()->SetAvAudioModeEnabled(enable); } int StartTvInPIP(tv_source_input_t source) { return GetInstance()->StartTvInPIP(source); } int StopTvInPIP(tv_source_input_t source) { return GetInstance()->StopTvInPIP(source); } int SetHdmiDlgEnabled(bool enable) { return GetInstance()->SetHdmiDlgEnabled(enable);} bool GetHdmiDlgEnabled() { return GetInstance()->GetHdmiDlgEnabled(); } bool GetHdmiDlgSupport(void) { return GetInstance()->GetHdmiDlgSupport(); } #ifdef __cplusplus }; #endif