diff --git a/ds/audioOutputPortConfig.cpp b/ds/audioOutputPortConfig.cpp index c3ab1cc6..aab6d682 100644 --- a/ds/audioOutputPortConfig.cpp +++ b/ds/audioOutputPortConfig.cpp @@ -34,6 +34,8 @@ #include "dsUtl.h" #include "stdlib.h" #include "dslogger.h" +#include +#include "manager.hpp" namespace device { @@ -108,68 +110,155 @@ List AudioOutputPortConfig::getSupportedTypes() return supportedTypes; } -void AudioOutputPortConfig::load() +void dumpconfig(audioConfigs_t *config) { - try { - /* - * Load Constants First. - */ - for (int i = 0; i < dsAUDIO_ENC_MAX; i++) { - _aEncodings.push_back(AudioEncoding(i)); - } - - for (int i = 0; i < dsAUDIO_CMP_MAX; i++) { - _aCompressions.push_back(AudioCompression(i)); - - } - - for (int i = 0; i < dsAUDIO_STEREO_MAX; i++) { - _aStereoModes.push_back(AudioStereoMode(i)); - - } - - for (int i = 0; i < dsAUDIOPORT_TYPE_MAX; i++) { - _aPortTypes.push_back(AudioOutputPortType(i)); - - } - - /* - * Initialize Audio portTypes (encodings, compressions etc.) - * and its port instances (db, level etc) - */ - for (size_t i = 0; i < dsUTL_DIM(kConfigs); i++) { - const dsAudioTypeConfig_t *typeCfg = &kConfigs[i]; - AudioOutputPortType &aPortType = AudioOutputPortType::getInstance(typeCfg->typeId); - aPortType.enable(); - for (size_t j = 0; j < typeCfg->numSupportedEncodings; j++) { - aPortType.addEncoding(AudioEncoding::getInstance(typeCfg->encodings[j])); - _aEncodings.at(typeCfg->encodings[j]).enable(); - } - for (size_t j = 0; j < typeCfg->numSupportedCompressions; j++) { - aPortType.addCompression(typeCfg->compressions[j]); - _aCompressions.at(typeCfg->compressions[j]).enable(); - - } - for (size_t j = 0; j < typeCfg->numSupportedStereoModes; j++) { - aPortType.addStereoMode(typeCfg->stereoModes[j]); - _aStereoModes.at(typeCfg->stereoModes[j]).enable(); - - } - } - - /* - * set up ports based on kPorts[] - */ - for (size_t i = 0; i < dsUTL_DIM(kPorts); i++) { - const dsAudioPortConfig_t *port = &kPorts[i]; - _aPorts.push_back(AudioOutputPort((port->id.type), port->id.index, i)); - _aPortTypes.at(port->id.type).addPort(_aPorts.at(i)); - } + if (nullptr == config) { + INT_ERROR("Audio config is NULL"); + return; + } + if ( -1 == access("/opt/dsMgrDumpDeviceConfigs", F_OK) ) { + INT_INFO("Dumping of Device configs is disabled"); + return; + } + + int configSize = -1, portSize = -1; + INT_INFO("\n=============== Starting to Dump Audio Configs ===============\n"); + if( nullptr != config->pKConfigs ) + { + configSize = (config->pKConfigSize) ? *(config->pKConfigSize) : -1; + + for (int i = 0; i < configSize; i++) { + const dsAudioTypeConfig_t *typeCfg = &(config->pKConfigs[i]); + INT_INFO("typeCfg->typeId = %d", typeCfg->typeId); + INT_INFO("typeCfg->name = %s", typeCfg->name); + INT_INFO("typeCfg->numSupportedEncodings = %zu", typeCfg->numSupportedEncodings); + INT_INFO("typeCfg->numSupportedCompressions = %zu", typeCfg->numSupportedCompressions); + INT_INFO("typeCfg->numSupportedStereoModes = %zu", typeCfg->numSupportedStereoModes); + } + } + else + { + INT_ERROR("kAudioConfigs is NULL"); + } + + if( nullptr != config->pKPorts ) + { + portSize = (config->pKPortSize) ? *(config->pKPortSize) : -1; + for (int i = 0; i < portSize; i++) { + const dsAudioPortConfig_t *portCfg = &(config->pKPorts[i]); + INT_INFO("portCfg->id.type = %d", portCfg->id.type); + INT_INFO("portCfg->id.index = %d", portCfg->id.index); + } + } + else + { + INT_ERROR("kAudioPorts is NULL"); + } + + INT_INFO("\n=============== Dump Audio Configs done ===============\n"); +} - } - catch(const Exception &e) { - throw e; - } +void AudioOutputPortConfig::load(audioConfigs_t* dynamicAudioConfigs) +{ + int configSize = -1, portSize = -1; + audioConfigs_t configuration = {0}; + + INT_INFO("Enter function"); + try { + /* + * Load Constants First. + */ + for (int i = 0; i < dsAUDIO_ENC_MAX; i++) { + _aEncodings.push_back(AudioEncoding(i)); + } + + for (int i = 0; i < dsAUDIO_CMP_MAX; i++) { + _aCompressions.push_back(AudioCompression(i)); + + } + + for (int i = 0; i < dsAUDIO_STEREO_MAX; i++) { + _aStereoModes.push_back(AudioStereoMode(i)); + + } + + for (int i = 0; i < dsAUDIOPORT_TYPE_MAX; i++) { + _aPortTypes.push_back(AudioOutputPortType(i)); + + } + + INT_INFO("Using '%s' config", dynamicAudioConfigs ? "dynamic" : "static"); + if ( nullptr != dynamicAudioConfigs ) + { + configuration = *dynamicAudioConfigs; + configSize = (configuration.pKConfigSize) ? *(configuration.pKConfigSize) : -1; + portSize = (configuration.pKPortSize) ? *(configuration.pKPortSize) : -1; + } + else { + configuration.pKConfigs = kConfigs; + configSize = dsUTL_DIM(kConfigs); + configuration.pKConfigSize = &configSize; + configuration.pKPorts = kPorts; + portSize = dsUTL_DIM(kPorts); + configuration.pKPortSize = &portSize; + } + + INT_INFO("Audio Config[%p] ConfigSize[%d] Ports[%p] PortSize[%d]", + configuration.pKConfigs, + configSize, + configuration.pKPorts, + portSize); + + dumpconfig(&configuration); + + /* + * Check if configs are loaded properly + */ + if (( nullptr != configuration.pKConfigs ) && ( nullptr != configuration.pKPorts )) + { + /* + * Initialize Audio portTypes (encodings, compressions etc.) + * and its port instances (db, level etc) + */ + for (int i = 0; i < configSize; i++) { + const dsAudioTypeConfig_t *typeCfg = &(configuration.pKConfigs[i]); + AudioOutputPortType &aPortType = AudioOutputPortType::getInstance(typeCfg->typeId); + aPortType.enable(); + for (int j = 0; j < typeCfg->numSupportedEncodings; j++) { + const dsAudioEncoding_t* encoding = &typeCfg->encodings[j]; + aPortType.addEncoding(AudioEncoding::getInstance(*encoding)); + _aEncodings.at(*encoding).enable(); + } + for (int j = 0; j < typeCfg->numSupportedCompressions; j++) { + const dsAudioCompression_t* compression = &typeCfg->compressions[j]; + aPortType.addCompression(*compression); + _aCompressions.at(*compression).enable(); + } + for (int j = 0; j < typeCfg->numSupportedStereoModes; j++) { + const dsAudioStereoMode_t *stereoMode = &typeCfg->stereoModes[j]; + aPortType.addStereoMode(*stereoMode); + _aStereoModes.at(*stereoMode).enable(); + } + } + + /* + * set up ports based on kPorts[] + */ + for (int i = 0; i < portSize; i++) { + const dsAudioPortConfig_t *portCfg = &configuration.pKPorts[i]; + _aPorts.push_back(AudioOutputPort((portCfg->id.type), portCfg->id.index, i)); + _aPortTypes.at(portCfg->id.type).addPort(_aPorts.at(i)); + } + INT_INFO("Audio Configs loaded successfully"); + } + else { + INT_ERROR("Audio Configs loading failed"); + } + } + catch(const Exception &e) { + throw e; + } + INT_INFO("Exit function"); } void AudioOutputPortConfig::release() diff --git a/ds/audioOutputPortConfig.hpp b/ds/audioOutputPortConfig.hpp index 90526b99..54db385a 100644 --- a/ds/audioOutputPortConfig.hpp +++ b/ds/audioOutputPortConfig.hpp @@ -38,6 +38,14 @@ #include #include +typedef struct audioConfigs +{ + const dsAudioTypeConfig_t *pKConfigs; + const dsAudioPortConfig_t *pKPorts; + int *pKConfigSize; + int *pKPortSize; +}audioConfigs_t; + namespace device { class AudioOutputPortConfig { @@ -66,7 +74,7 @@ class AudioOutputPortConfig { List getPorts(); List getSupportedTypes(); - void load(); + void load(audioConfigs_t* dynamicAudioConfigs); void release(); }; diff --git a/ds/dslogger.cpp b/ds/dslogger.cpp index 2fd2f81e..9cdb7322 100644 --- a/ds/dslogger.cpp +++ b/ds/dslogger.cpp @@ -30,8 +30,12 @@ #include "dslogger.h" +#include // for SYS_gettid +#include // for syscall + #define unlikely(x) (__builtin_expect(!!(x), 0)) -#define MAX_LOG_BUFF 512 +#define MAX_LOG_BUFF 1024 +#define kFormatMessageSize (MAX_LOG_BUFF - 128) DS_LogCb logCb = NULL; @@ -40,29 +44,34 @@ void DS_RegisterForLog(DS_LogCb cb) logCb = cb; } -int ds_log(int priority, const char* fileName, int lineNum, const char *format, ...) +int ds_log(LogLevel priority, const char* fileName, int lineNum, const char *func, const char *format, ...) { - char tmp_buff[MAX_LOG_BUFF] = {'\0'}; - - int offset = snprintf(tmp_buff, MAX_LOG_BUFF, "[%s:%d] ", fileName, lineNum); + char formatted[MAX_LOG_BUFF] = {'\0'}; + enum LogLevel {INFO_LEVEL = 0, WARN_LEVEL, ERROR_LEVEL, DEBUG_LEVEL, TRACE_LEVEL}; + const char *levelMap[] = { "INFO", "WARN", "ERROR", "DEBUG", "TRACE"}; - // formatting error - if (unlikely(offset < 0)) { - offset = 0; - tmp_buff[0] = '\0'; // Ensure buffer is null-terminated if snprintf fails + if (!func || !fileName || !format) + { + return -1; } - va_list args; - va_start(args, format); - vsnprintf(tmp_buff + offset, MAX_LOG_BUFF - offset, format, args); - va_end(args); + va_list argptr; + va_start(argptr, format); + vsnprintf(formatted, kFormatMessageSize, format, argptr); + va_end(argptr); if (nullptr != logCb) { - logCb(priority, tmp_buff); + logCb(priority, formatted); } else { - return printf("%s\n", tmp_buff); + fprintf(stderr, "[DS][%d] %s [%s:%d] %s: %s \n", + (int)syscall(SYS_gettid), + levelMap[static_cast(priority)], + fileName, + lineNum, + func, + formatted); + fflush(stderr); } - return 0; } diff --git a/ds/frontPanelConfig.cpp b/ds/frontPanelConfig.cpp index e8c932b2..5d4d1030 100644 --- a/ds/frontPanelConfig.cpp +++ b/ds/frontPanelConfig.cpp @@ -41,6 +41,7 @@ #include "frontPanelSettings.hpp" #include "illegalArgumentException.hpp" #include "dslogger.h" +#include "manager.hpp" using namespace std; @@ -56,6 +57,7 @@ namespace device { FrontPanelConfig::FrontPanelConfig() { m_isFPInitialized = false; + m_isFPConfigLoaded = false; } @@ -69,6 +71,7 @@ FrontPanelConfig::~FrontPanelConfig() { //dsFPTerm(); m_isFPInitialized = false; + m_isFPConfigLoaded = false; } @@ -92,7 +95,6 @@ FrontPanelConfig & FrontPanelConfig::getInstance() errorCode = dsFPInit(); if (dsERR_NONE == errorCode) { - _singleton.load(); _singleton.m_isFPInitialized = true; INT_INFO("dsFPInit success\n"); } @@ -337,6 +339,64 @@ List FrontPanelConfig::getTextDisplays() return rTexts; } +void dumpconfig(fpdConfigs_t *configuration) +{ + if (nullptr == configuration) { + INT_ERROR("configuration is NULL"); + return; + } + if ( -1 == access("/opt/dsMgrDumpDeviceConfigs", F_OK) ) { + INT_INFO("Dumping of Device configs is disabled"); + return; + } + int indicatorSize = -1; + int indicatorColorSize = -1; + + // Dump the configuration details + INT_INFO("\n=============== Starting to Dump FrontPanel Configs ===============\n"); + + if (( nullptr != configuration->pKFPDIndicatorColors) && ( nullptr != configuration->pKIndicators)) + { + int indicatorSize = (configuration->pKIndicators_size) ? *(configuration->pKIndicators_size) : -1; + int indicatorColorSize = (configuration->pKFPDIndicatorColors_size) ? *(configuration->pKFPDIndicatorColors_size) : -1; + + for (int i = 0; i < indicatorColorSize; i++) { + const dsFPDColorConfig_t* fpdColorCfg = &configuration->pKFPDIndicatorColors[i]; + INT_INFO(" Color ID: %d, color: %d", fpdColorCfg->id, fpdColorCfg->color); + } + INT_INFO("Indicators:"); + for (int i = 0; i < indicatorSize; i++) { + const dsFPDIndicatorConfig_t* fpdIndicatorCfg = &configuration->pKIndicators[i]; + INT_INFO(" Indicator ID: %d, Max Brightness: %d, Max Cycle Rate: %d, Levels: %d, Color Mode: %d", + fpdIndicatorCfg->id, + fpdIndicatorCfg->maxBrightness, + fpdIndicatorCfg->maxCycleRate, + fpdIndicatorCfg->levels, + fpdIndicatorCfg->colorMode); + } + } + + if ( nullptr != configuration->pKTextDisplays) { + int textDisplaySize = (configuration->pKTextDisplays_size) ? *(configuration->pKTextDisplays_size) : -1; + INT_INFO("Text Displays: textDisplaySize =%d", textDisplaySize); + for (int i = 0; i < textDisplaySize; i++) { + const dsFPDTextDisplayConfig_t* fpdTextDisplayCfg = &configuration->pKTextDisplays[i]; + INT_INFO(" Text Display ID: %d, Max Brightness: %d, Max Cycle Rate: %d, Levels: %d, Max Horizontal Iterations: %d, Max Vertical Iterations: %d, Supported Characters: %s, Color Mode: %d", + fpdTextDisplayCfg->id, + fpdTextDisplayCfg->maxBrightness, + fpdTextDisplayCfg->maxCycleRate, + fpdTextDisplayCfg->levels, + fpdTextDisplayCfg->maxHorizontalIterations, + fpdTextDisplayCfg->maxVerticalIterations, + (fpdTextDisplayCfg->supportedCharacters) ? fpdTextDisplayCfg->supportedCharacters : DEFAULT_FPD_TEXT_DISPLAY_SUPPORTED_CHARACTERS, + fpdTextDisplayCfg->colorMode); + } + } + else { + INT_INFO(" No Text Displays configured."); + } + INT_INFO("\n=============== Dump FrontPanel Configs done ===============\n"); +} /** * @fn FrontPanelConfig::load() @@ -345,51 +405,106 @@ List FrontPanelConfig::getTextDisplays() * * @return None */ -void FrontPanelConfig::load() +void FrontPanelConfig::load(fpdConfigs_t* dynamicFPDConfigs) { - /* - * Create Indicators - * 1. Create Supported Colors. - * 2. Create Indicators. - */ - { - for (size_t i = 0; i < dsUTL_DIM(kIndicatorColors); i++) { - _colors.push_back(FrontPanelIndicator::Color(kIndicatorColors[i].id)); - } + /* + * Create Indicators + * 1. Create Supported Colors. + * 2. Create Indicators. + */ + int indicatorSize, indicatorColorSize, textDisplaySize; + fpdConfigs_t configuration = {0}; + INT_INFO("Enter function"); + if (( false == m_isFPInitialized) || (true == m_isFPConfigLoaded)) { + INT_ERROR("'%s'", (!m_isFPInitialized) ? "Front Panel not initialized" : "Front Panel Config already loaded"); + return; + } - for (size_t i = 0; i < dsUTL_DIM(kIndicators); i++) { - /* All indicators support a same set of colors */ - _indicators.push_back(FrontPanelIndicator(kIndicators[i].id, - kIndicators[i].maxBrightness, - kIndicators[i].maxCycleRate, - kIndicators[i].levels, - kIndicators[i].colorMode)); - } + INT_INFO("Using '%s' config", dynamicFPDConfigs ? "dynamic" : "static"); + if ( nullptr != dynamicFPDConfigs ) + { + configuration = *dynamicFPDConfigs; + indicatorSize = (configuration.pKIndicators_size) ? *(configuration.pKIndicators_size) : -1; + indicatorColorSize = (configuration.pKFPDIndicatorColors_size) ? *(configuration.pKFPDIndicatorColors_size) : -1; + textDisplaySize = (configuration.pKTextDisplays_size) ? *(configuration.pKTextDisplays_size) : -1; + } + else { + configuration.pKFPDIndicatorColors = kIndicatorColors; + indicatorColorSize = dsUTL_DIM(kIndicatorColors); + configuration.pKFPDIndicatorColors_size = &indicatorColorSize; + configuration.pKIndicators = kIndicators; + indicatorSize = dsUTL_DIM(kIndicators); + configuration.pKIndicators_size = &indicatorSize; + configuration.pKTextDisplays = kTextDisplays; + textDisplaySize = dsUTL_DIM(kTextDisplays); + configuration.pKTextDisplays_size = &textDisplaySize; + } - } + INT_INFO("FPD IndicatorColors[%p] IndicatorColors_size[%d] Indicators[%p] Indicators_size[%d] TextDisplays[%p] TextDisplays_size[%d]", + configuration.pKFPDIndicatorColors, + indicatorColorSize, + configuration.pKIndicators, + indicatorSize, + configuration.pKTextDisplays, + textDisplaySize); - { - /* - * Create TextDisplays - * 1. Use Supported Colors created for indicators. - * 2. Create Text Displays. - */ - for (size_t i = 0; i < dsUTL_DIM(kTextDisplays); i++) { - _textDisplays.push_back( - FrontPanelTextDisplay(kTextDisplays[i].id, - kTextDisplays[i].maxBrightness, - kTextDisplays[i].maxCycleRate, - kTextDisplays[i].levels, - kTextDisplays[i].maxHorizontalIterations, - kTextDisplays[i].maxVerticalIterations, - kTextDisplays[i].supportedCharacters, - kTextDisplays[i].colorMode)); - } - } -} + dumpconfig(&configuration); + if (( nullptr != configuration.pKFPDIndicatorColors ) && ( nullptr != configuration.pKIndicators)) + { + for (int i = 0; i < indicatorColorSize; i++) { + const dsFPDColorConfig_t* fpdColorCfg = &configuration.pKFPDIndicatorColors[i]; + _colors.push_back(FrontPanelIndicator::Color(fpdColorCfg->id)); + } + + for (int i = 0; i < indicatorSize; i++) { + const dsFPDIndicatorConfig_t* fpdIndicatorCfg = &configuration.pKIndicators[i]; + /* All indicators support a same set of colors */ + _indicators.push_back(FrontPanelIndicator(fpdIndicatorCfg->id, + fpdIndicatorCfg->maxBrightness, + fpdIndicatorCfg->maxCycleRate, + fpdIndicatorCfg->levels, + fpdIndicatorCfg->colorMode)); + } + } + else { + INT_ERROR("No valid indicator configuration found\n"); + } + + if ( nullptr != configuration.pKTextDisplays ) + { + /* + * Create TextDisplays + * 1. Use Supported Colors created for indicators. + * 2. Create Text Displays. + */ + INT_DEBUG("Text Displays \n"); + for (int i = 0; i < textDisplaySize; i++) { + const dsFPDTextDisplayConfig_t* fpdTextDisplayCfg = &configuration.pKTextDisplays[i]; + if (nullptr == fpdTextDisplayCfg->supportedCharacters) { + INT_ERROR("supportedCharacters is NULL at %d, using '%s' string...", i, DEFAULT_FPD_TEXT_DISPLAY_SUPPORTED_CHARACTERS); + } + _textDisplays.push_back( + FrontPanelTextDisplay(fpdTextDisplayCfg->id, + fpdTextDisplayCfg->maxBrightness, + fpdTextDisplayCfg->maxCycleRate, + fpdTextDisplayCfg->levels, + fpdTextDisplayCfg->maxHorizontalIterations, + fpdTextDisplayCfg->maxVerticalIterations, + (fpdTextDisplayCfg->supportedCharacters) ? std::string(fpdTextDisplayCfg->supportedCharacters) : std::string(DEFAULT_FPD_TEXT_DISPLAY_SUPPORTED_CHARACTERS), + fpdTextDisplayCfg->colorMode)); + } + } + else + { + INT_ERROR("No valid text display configuration found\n"); + } + m_isFPConfigLoaded = true; + INT_INFO("Exit function"); + return; } +} /** @} */ /** @} */ diff --git a/ds/frontPanelIndicator.cpp b/ds/frontPanelIndicator.cpp index 7a4d0202..68bae9a9 100644 --- a/ds/frontPanelIndicator.cpp +++ b/ds/frontPanelIndicator.cpp @@ -67,7 +67,6 @@ int stringToNumber (std::string text) return number; } - namespace { const char *_colorNames[] = { "Blue", @@ -100,7 +99,6 @@ namespace { }; - inline bool isIndicatorValid(int id) { return dsFPDIndicator_isValid(id); } diff --git a/ds/hdmiIn.cpp b/ds/hdmiIn.cpp index 514cff14..2e518a14 100755 --- a/ds/hdmiIn.cpp +++ b/ds/hdmiIn.cpp @@ -341,7 +341,7 @@ static std::string getResolutionStr (dsVideoResolution_t resolution) break; } - printf ("%s:%d - ResolutionStr: %s\n", __PRETTY_FUNCTION__,__LINE__, resolutionStr.c_str()); + INT_INFO("ResolutionStr: %s", resolutionStr.c_str()); return resolutionStr; } @@ -412,20 +412,20 @@ static std::string getFrameRateStr (dsVideoFrameRate_t frameRate) break; } - printf ("%s:%d - FrameRateStr: %s\n", __PRETTY_FUNCTION__,__LINE__, FrameRateStr.c_str()); + INT_INFO("FrameRateStr: %s", FrameRateStr.c_str()); return FrameRateStr; } static std::string getInterlacedStr (bool interlaced) { std::string InterlacedStr = (interlaced) ? "i" : "p"; - printf ("%s:%d - InterlacedStr: %s\n", __PRETTY_FUNCTION__,__LINE__, InterlacedStr.c_str()); + INT_INFO("InterlacedStr: %s", InterlacedStr.c_str()); return InterlacedStr; } static std::string CreateResolutionStr (const dsVideoPortResolution_t &resolution) { - printf("%s ---> \n", __PRETTY_FUNCTION__); + INT_INFO("--->"); std::string resolutionStr = getResolutionStr(resolution.pixelResolution); if(resolutionStr.compare("unknown") != 0){ @@ -433,7 +433,7 @@ static std::string CreateResolutionStr (const dsVideoPortResolution_t &resolutio getInterlacedStr(resolution.interlaced) + getFrameRateStr(resolution.frameRate); } - printf ("%s <--- %s\n", __PRETTY_FUNCTION__, resolutionStr.c_str()); + INT_INFO("<--- %s", resolutionStr.c_str()); return resolutionStr; } @@ -461,7 +461,7 @@ std::string HdmiInput::getCurrentVideoMode () const } std::string resolutionStr = CreateResolutionStr (resolution); - printf("%s:%d - Resolution =%s\n", __PRETTY_FUNCTION__,__LINE__, resolutionStr.c_str()); + INT_INFO("Resolution =%s", resolutionStr.c_str()); return resolutionStr; } @@ -478,13 +478,13 @@ void HdmiInput::getCurrentVideoModeObj (dsVideoPortResolution_t& resolution) throw Exception(eError); } - printf("%s:%d - pixelResolution =%d interlaced:%d frameRate:%d\n", __PRETTY_FUNCTION__, __LINE__, resolution.pixelResolution, resolution.interlaced, resolution.frameRate); + INT_INFO("pixelResolution =%d interlaced:%d frameRate:%d", resolution.pixelResolution, resolution.interlaced, resolution.frameRate); } void HdmiInput::getEDIDBytesInfo (int iHdmiPort, std::vector &edidArg) const { - printf("HdmiInput::getEDIDBytesInfo \r\n"); + INT_INFO("HdmiInput::getEDIDBytesInfo"); dsError_t ret = dsERR_NONE; int length = 0; @@ -493,10 +493,10 @@ void HdmiInput::getEDIDBytesInfo (int iHdmiPort, std::vector &edidArg) const char* exceptionstr = ""; ret = dsGetEDIDBytesInfo (static_cast(iHdmiPort), edid, &length); - printf("HdmiInput::getEDIDBytesInfo has ret %d\r\n", ret); + INT_INFO("HdmiInput::getEDIDBytesInfo has ret %d", ret); if (ret == dsERR_NONE) { if (length <= MAX_EDID_BYTES_LEN) { - printf("HdmiInput::getEDIDBytesInfo has %d bytes\r\n", length); + INT_INFO("HdmiInput::getEDIDBytesInfo has %d bytes", length); if (edid_parser::EDID_STATUS_OK == edid_parser::EDID_Verify(edid, length)) { edidArg.clear(); edidArg.insert(edidArg.begin(), edid, edid + length); @@ -518,17 +518,17 @@ void HdmiInput::getEDIDBytesInfo (int iHdmiPort, std::vector &edidArg) } void HdmiInput::getHDMISPDInfo (int iHdmiPort, std::vector &data) { - printf("HdmiInput::getHDMISPDInfo \r\n"); + INT_INFO("HdmiInput::getHDMISPDInfo"); unsigned char spdinfo[sizeof(struct dsSpd_infoframe_st)] = {0}; const char* exceptionstr = ""; dsError_t ret = dsGetHDMISPDInfo (static_cast(iHdmiPort), spdinfo); - printf("HdmiInput::getHDMISPDInfo has ret %d\r\n", ret); + INT_INFO("HdmiInput::getHDMISPDInfo has ret %d", ret); data.clear(); if (ret == dsERR_NONE) { if (sizeof(spdinfo) <= sizeof(struct dsSpd_infoframe_st)) { - printf("HdmiInput::getHDMISPDInfo has %d bytes\r\n", sizeof(spdinfo)); + INT_INFO("HdmiInput::getHDMISPDInfo has %d bytes", sizeof(spdinfo)); data.insert(data.begin(), spdinfo, spdinfo + sizeof(struct dsSpd_infoframe_st)); } else { ret = dsERR_OPERATION_NOT_SUPPORTED; @@ -537,11 +537,11 @@ void HdmiInput::getHDMISPDInfo (int iHdmiPort, std::vector &data) { } else { exceptionstr = "getHDMISPDInfo failed"; } - printf("HdmiInput::getHDMISPDInfo data: \r\n"); + INT_INFO("HdmiInput::getHDMISPDInfo data:"); for (int itr = 0; itr < data.size(); itr++) { printf("%02X ", data[itr]); } - printf("\n"); + INT_INFO(""); if (ret != dsERR_NONE) { throw Exception(ret, exceptionstr); @@ -550,17 +550,17 @@ void HdmiInput::getHDMISPDInfo (int iHdmiPort, std::vector &data) { } void HdmiInput::setEdidVersion (int iHdmiPort, int iEdidVersion) { - printf ("HdmiInput::setEdidVersion \r\n"); + INT_INFO("HdmiInput::setEdidVersion"); dsError_t ret = dsSetEdidVersion (static_cast(iHdmiPort), static_cast(iEdidVersion)); if (ret != dsERR_NONE) { throw Exception(ret); } - printf ("%s:%d - Set EDID Version = %d\n", __PRETTY_FUNCTION__, __LINE__, iEdidVersion); + INT_INFO("Set EDID Version = %d", iEdidVersion); } void HdmiInput::getEdidVersion (int iHdmiPort, int *iEdidVersion) { - printf ("HdmiInput::getEdidVersion \r\n"); + INT_INFO("HdmiInput::getEdidVersion"); tv_hdmi_edid_version_t EdidVersion; dsError_t ret = dsGetEdidVersion (static_cast(iHdmiPort), &EdidVersion); if (ret != dsERR_NONE) @@ -569,7 +569,7 @@ void HdmiInput::getEdidVersion (int iHdmiPort, int *iEdidVersion) { } int tmp = static_cast(EdidVersion); *iEdidVersion = tmp; - printf ("%s:%d - EDID Version = %d\n", __PRETTY_FUNCTION__, __LINE__, *iEdidVersion); + INT_INFO("EDID Version = %d", *iEdidVersion); } void HdmiInput::setVRRSupport(int iHdmiPort, bool vrrSupport) @@ -579,7 +579,7 @@ void HdmiInput::setVRRSupport(int iHdmiPort, bool vrrSupport) { throw Exception(ret); } - printf ("%s:%d - Set VRR Support = %d\n", __PRETTY_FUNCTION__, __LINE__, vrrSupport); + INT_INFO("Set VRR Support = %d", vrrSupport); } void HdmiInput::getVRRSupport (int iHdmiPort, bool *vrrSupport) { @@ -588,7 +588,7 @@ void HdmiInput::getVRRSupport (int iHdmiPort, bool *vrrSupport) { { throw Exception(ret); } - printf ("%s:%d - EDID VRR Support = %d\n", __PRETTY_FUNCTION__, __LINE__, *vrrSupport); + INT_INFO("EDID VRR Support = %d", *vrrSupport); } void HdmiInput::getVRRStatus (int iHdmiPort, dsHdmiInVrrStatus_t *vrrStatus) { @@ -597,17 +597,17 @@ void HdmiInput::getVRRStatus (int iHdmiPort, dsHdmiInVrrStatus_t *vrrStatus) { { throw Exception(ret); } - printf ("%s:%d - VRR Type = %d , VRR FrameRate = %f\n", __FUNCTION__, __LINE__, vrrStatus->vrrType,vrrStatus->vrrAmdfreesyncFramerate_Hz); + INT_INFO("VRR Type = %d , VRR FrameRate = %f", vrrStatus->vrrType,vrrStatus->vrrAmdfreesyncFramerate_Hz); } void HdmiInput::getHdmiALLMStatus (int iHdmiPort, bool *allmStatus) { - printf ("HdmiInput::getHdmiALLMStatus \r\n"); + INT_INFO("HdmiInput::getHdmiALLMStatus"); dsError_t ret = dsGetAllmStatus (static_cast(iHdmiPort), allmStatus); if (ret != dsERR_NONE) { throw Exception(ret); } - printf ("%s:%d - ALLM Status = %d\n", __FUNCTION__, __LINE__, *allmStatus); + INT_INFO("ALLM Status = %d", *allmStatus); } void HdmiInput::getSupportedGameFeatures (std::vector &featureList) { @@ -629,7 +629,7 @@ void HdmiInput::getSupportedGameFeatures (std::vector &featureList) } if(featureList.size() != feList.gameFeatureCount){ - printf ("%s:%d - Number of Supported Game Features in list doesn't match with count from HAL", __FUNCTION__, __LINE__); + INT_ERROR("Number of Supported Game Features in list doesn't match with count from HAL"); throw Exception(dsERR_GENERAL); } } @@ -637,7 +637,7 @@ void HdmiInput::getSupportedGameFeatures (std::vector &featureList) void HdmiInput::getAVLatency (int *audio_output_delay,int *video_latency) { dsError_t ret = dsGetAVLatency (audio_output_delay,video_latency); - printf ("HdmiInput::getHdmiDAL_ - VideoLatency: %d , Audio Latency: %d \r\n",*video_latency,*audio_output_delay); + INT_INFO("VideoLatency: %d , Audio Latency: %d",*video_latency,*audio_output_delay); if (ret != dsERR_NONE) { throw Exception(ret); @@ -646,24 +646,24 @@ void HdmiInput::getAVLatency (int *audio_output_delay,int *video_latency) { void HdmiInput::setEdid2AllmSupport(int iHdmiPort,bool allmSupport) { - printf ("HdmiInput::setEdid2AllmSupport \r\n"); + INT_INFO("HdmiInput::setEdid2AllmSupport"); dsError_t ret = dsSetEdid2AllmSupport (static_cast(iHdmiPort), allmSupport); if (ret != dsERR_NONE) { throw Exception(ret); } - printf ("%s:%d - Set EDID Allm Support = %d\n", __PRETTY_FUNCTION__, __LINE__, allmSupport); + INT_INFO("Set EDID Allm Support = %d", allmSupport); } void HdmiInput::getEdid2AllmSupport (int iHdmiPort, bool *allmSupport) { - printf ("HdmiInput::getEdid2AllmSupport \r\n"); + INT_INFO("HdmiInput::getEdid2AllmSupport"); dsError_t ret = dsGetEdid2AllmSupport (static_cast(iHdmiPort), allmSupport); if (ret != dsERR_NONE) { throw Exception(ret); } - printf ("%s:%d - EDID allm Support = %d\n", __PRETTY_FUNCTION__, __LINE__, *allmSupport); + INT_INFO("EDID allm Support = %d", *allmSupport); } void HdmiInput::getHdmiVersion (int iHdmiPort, dsHdmiMaxCapabilityVersion_t *capversion) { @@ -675,7 +675,7 @@ void HdmiInput::getHdmiVersion (int iHdmiPort, dsHdmiMaxCapabilityVersion_t *cap throw Exception(ret); } - printf ("%s:%d - HDMI Compatibility Version = %d\n", __PRETTY_FUNCTION__, __LINE__, *capversion); + INT_INFO("HDMI Compatibility Version = %d", *capversion); } dsError_t HdmiInput::getHDMIARCPortId(int &portId) { diff --git a/ds/host.cpp b/ds/host.cpp index e2475e14..98d0a071 100644 --- a/ds/host.cpp +++ b/ds/host.cpp @@ -758,7 +758,7 @@ Host::~Host() { throw Exception(ret); } - printf ("%s:%d - Set Audio Mixer levels for audio input: %d with volume = %d\n", __PRETTY_FUNCTION__, __LINE__,aInput, volume); + INT_INFO("Set Audio Mixer levels for audio input: %d with volume = %d",aInput, volume); } DefaultImpl& Host::impl() diff --git a/ds/include/dslogger.h b/ds/include/dslogger.h index e356979d..de8fb822 100644 --- a/ds/include/dslogger.h +++ b/ds/include/dslogger.h @@ -33,12 +33,9 @@ #include "dsregisterlog.h" -int ds_log(int priority, const char* fileName, int lineNum, const char *format, ...); +enum LogLevel {INFO_LEVEL = 0, WARN_LEVEL, ERROR_LEVEL, DEBUG_LEVEL, TRACE_LEVEL}; -#define INFO_LEVEL 0 -#define WARN_LEVEL 1 -#define ERROR_LEVEL 2 -#define DEBUG_LEVEL 3 +int ds_log(LogLevel level, const char* fileName, int lineNum, const char *func, const char *format, ...); // Helper to extract filename from full path // E.g. "/path/to/file.cpp" -> "file.cpp" @@ -52,13 +49,13 @@ static inline const char* fileName(const char* path) { #define DS_LOG_LEVEL ERROR_LEVEL #endif -#define INT_INFO(FORMAT, ...) ds_log(INFO_LEVEL, fileName(__FILE__), __LINE__, FORMAT, ##__VA_ARGS__ ) -#define INT_WARN(FORMAT, ...) ds_log(WARN_LEVEL, fileName(__FILE__), __LINE__, FORMAT, ##__VA_ARGS__ ) -#define INT_ERROR(FORMAT, ...) ds_log(ERROR_LEVEL, fileName(__FILE__), __LINE__, FORMAT, ##__VA_ARGS__ ) +#define INT_INFO(FORMAT, ...) ds_log(INFO_LEVEL, fileName(__FILE__), __LINE__, __FUNCTION__, FORMAT, ##__VA_ARGS__ ) +#define INT_WARN(FORMAT, ...) ds_log(WARN_LEVEL, fileName(__FILE__), __LINE__, __FUNCTION__, FORMAT, ##__VA_ARGS__ ) +#define INT_ERROR(FORMAT, ...) ds_log(ERROR_LEVEL, fileName(__FILE__), __LINE__, __FUNCTION__, FORMAT, ##__VA_ARGS__ ) // conditionally enable debug logs, based on DS_LOG_LEVEL #if DS_LOG_LEVEL >= DEBUG_LEVEL -#define INT_DEBUG(FORMAT, ...) ds_log(DEBUG_LEVEL, fileName(__FILE__), __LINE__, FORMAT, ##__VA_ARGS__ ) +#define INT_DEBUG(FORMAT, ...) ds_log(DEBUG_LEVEL, fileName(__FILE__), __LINE__, __FUNCTION__, FORMAT, ##__VA_ARGS__ ) #else #define INT_DEBUG(FORMAT, ...) ((void)0) #endif diff --git a/ds/include/frontPanelConfig.hpp b/ds/include/frontPanelConfig.hpp index 77c243ba..a85d4c0f 100644 --- a/ds/include/frontPanelConfig.hpp +++ b/ds/include/frontPanelConfig.hpp @@ -44,6 +44,18 @@ */ using namespace std; +typedef struct fpdConfigs +{ + const dsFPDColorConfig_t *pKFPDIndicatorColors; + const dsFPDIndicatorConfig_t *pKIndicators; + const dsFPDTextDisplayConfig_t *pKTextDisplays; + int *pKFPDIndicatorColors_size; + int *pKIndicators_size; + int *pKTextDisplays_size; +}fpdConfigs_t; + +#define DEFAULT_FPD_TEXT_DISPLAY_SUPPORTED_CHARACTERS "ABCEDFG" + namespace device { @@ -59,12 +71,11 @@ class FrontPanelConfig { std::vector _textDisplays; //!< Container to hold all the FrontPanelTextDisplay instances. std::vector _colors; //!< Container to hold all the Color instances. bool m_isFPInitialized; + bool m_isFPConfigLoaded; FrontPanelConfig(); virtual ~FrontPanelConfig(); - void load(); - public: static FrontPanelConfig & getInstance(); @@ -80,11 +91,12 @@ class FrontPanelConfig { List getIndicators(); List getTextDisplays(); - /* Initialize Front Panel */ - void fPInit(); - /* Terminate Front Panel */ - void fPTerm(); + /* Initialize Front Panel */ + void fPInit(); + /* Terminate Front Panel */ + void fPTerm(); + void load(fpdConfigs_t* dynamicFPDConfigs); }; } diff --git a/ds/include/manager.hpp b/ds/include/manager.hpp index 2539569a..bcf53014 100644 --- a/ds/include/manager.hpp +++ b/ds/include/manager.hpp @@ -149,6 +149,10 @@ #ifndef _DS_MANAGER_HPP_ #define _DS_MANAGER_HPP_ +#include +#include // for access API + +using namespace std; /** * @file manager.hpp @@ -156,6 +160,24 @@ */ namespace device { +typedef enum DeviceCapabilityTypes { + DEVICE_CAPABILITY_INVALID = 0x00000000, + DEVICE_CAPABILITY_AUDIO_PORT = 0x00000001, + DEVICE_CAPABILITY_VIDEO_PORT = 0x00000002, + DEVICE_CAPABILITY_VIDEO_DEVICE = 0x00000004, + DEVICE_CAPABILITY_FRONT_PANEL = 0x00000008, + DEVICE_CAPABILITY_MAX = 0xFFFFFFFF +} +DeviceCapabilityTypes; + +typedef struct dlSymbolLookup { + const char* name; + void** dataptr; +} +dlSymbolLookup; + +bool LoadDLSymbols(void* pDLHandle, const dlSymbolLookup* symbols, int numberOfSymbols); +void loadDeviceCapabilities(unsigned int capabilityType); /** * @class Manager @@ -169,7 +191,7 @@ class Manager { static void Initialize(); static void DeInitialize(); static void load(); //!< This function is being used for loading configure in-process DSMgr. - static int IsInitialized; //!< Indicates the application has initialized with devicettings modules. + static int IsInitialized; //!< Indicates the application has initialized with devicettings modules. }; } diff --git a/ds/manager.cpp b/ds/manager.cpp index eedcd8b2..a5ac1216 100644 --- a/ds/manager.cpp +++ b/ds/manager.cpp @@ -43,6 +43,13 @@ #include "exception.hpp" #include #include +#include +#include +#include "dsHALConfig.h" +#include "frontPanelConfig.hpp" + +//static pthread_mutex_t dsLock = PTHREAD_MUTEX_INITIALIZER; + /** * @file manager.cpp @@ -63,6 +70,119 @@ namespace device { int Manager::IsInitialized = 0; //!< Indicates the application has initialized with devicettings modules. static std::mutex gManagerInitMutex; +bool LoadDLSymbols(void* pDLHandle, const dlSymbolLookup* symbols, int numberOfSymbols) +{ + int currentSymbols = 0; + bool isAllSymbolsLoaded = false; + if ((nullptr == pDLHandle) || (nullptr == symbols)) { + INT_ERROR("Invalid DL Handle or symbolsPtr"); + } + else { + INT_INFO("numberOfSymbols = %d",numberOfSymbols); + for (int i = 0; i < numberOfSymbols; i++) { + if (( nullptr == symbols[i].dataptr) || ( nullptr == symbols[i].name)) { + INT_ERROR("Invalid symbol entry at index [%d]", i); + continue; + } + *(symbols[i].dataptr) = dlsym(pDLHandle, symbols[i].name); + if (nullptr == *(symbols[i].dataptr)) { + INT_ERROR("[%s] is not defined", symbols[i].name); + } + else { + currentSymbols++; + INT_INFO("[%s] is defined and loaded, data[%p]", symbols[i].name, *(symbols[i].dataptr)); + } + } + isAllSymbolsLoaded = (numberOfSymbols) ? (currentSymbols == numberOfSymbols) : false; + } + return isAllSymbolsLoaded; +} + +void loadDeviceCapabilities(unsigned int capabilityType) +{ + void* pDLHandle = nullptr; + bool isSymbolsLoaded = false; + + INT_INFO("Entering capabilityType = 0x%08X", capabilityType); + dlerror(); // clear old error + pDLHandle = dlopen(RDK_DSHAL_NAME, RTLD_LAZY); + INT_INFO("DL Instance '%s'", (nullptr == pDLHandle ? "NULL" : "Valid")); + + // Audio Port Config + if (DEVICE_CAPABILITY_AUDIO_PORT & capabilityType) { + audioConfigs_t dynamicAudioConfigs = {0 }; + dlSymbolLookup audioConfigSymbols[] = { + {"kAudioConfigs", (void**)&dynamicAudioConfigs.pKConfigs}, + {"kAudioPorts", (void**)&dynamicAudioConfigs.pKPorts}, + {"kAudioConfigs_size", (void**)&dynamicAudioConfigs.pKConfigSize}, + {"kAudioPorts_size", (void**)&dynamicAudioConfigs.pKPortSize} + }; + + isSymbolsLoaded = false; + if (nullptr != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, audioConfigSymbols, sizeof(audioConfigSymbols)/sizeof(dlSymbolLookup)); + } + AudioOutputPortConfig::getInstance().load(isSymbolsLoaded ? &dynamicAudioConfigs : nullptr); + } + + // Video Port Config + if (DEVICE_CAPABILITY_VIDEO_PORT & capabilityType) { + videoPortConfigs_t dynamicVideoPortConfigs = {0}; + dlSymbolLookup videoPortConfigSymbols[] = { + {"kVideoPortConfigs", (void**)&dynamicVideoPortConfigs.pKConfigs}, + {"kVideoPortConfigs_size", (void**)&dynamicVideoPortConfigs.pKVideoPortConfigs_size}, + {"kVideoPortPorts", (void**)&dynamicVideoPortConfigs.pKPorts}, + {"kVideoPortPorts_size", (void**)&dynamicVideoPortConfigs.pKVideoPortPorts_size}, + {"kResolutionsSettings", (void**)&dynamicVideoPortConfigs.pKResolutionsSettings}, + {"kResolutionsSettings_size", (void**)&dynamicVideoPortConfigs.pKResolutionsSettings_size} + }; + + isSymbolsLoaded = false; + if (nullptr != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, videoPortConfigSymbols, sizeof(videoPortConfigSymbols)/sizeof(dlSymbolLookup)); + } + VideoOutputPortConfig::getInstance().load(isSymbolsLoaded ? &dynamicVideoPortConfigs : nullptr); + } + + // Video Device Config + if (DEVICE_CAPABILITY_VIDEO_DEVICE & capabilityType) { + videoDeviceConfig_t dynamicVideoDeviceConfigs = {0}; + dlSymbolLookup videoDeviceConfigSymbols[] = { + {"kVideoDeviceConfigs", (void**)&dynamicVideoDeviceConfigs.pKVideoDeviceConfigs}, + {"kVideoDeviceConfigs_size", (void**)&dynamicVideoDeviceConfigs.pKVideoDeviceConfigs_size} + }; + isSymbolsLoaded = false; + if (nullptr != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, videoDeviceConfigSymbols, sizeof(videoDeviceConfigSymbols)/sizeof(dlSymbolLookup)); + } + VideoDeviceConfig::getInstance().load(isSymbolsLoaded ? &dynamicVideoDeviceConfigs : nullptr); + } + + // Front Panel Config + if (DEVICE_CAPABILITY_FRONT_PANEL & capabilityType) { + fpdConfigs_t dynamicFPDConfigs = {0}; + dlSymbolLookup fpdConfigSymbols[] = { + {"kFPDIndicatorColors", (void**)&dynamicFPDConfigs.pKFPDIndicatorColors}, + {"kFPDIndicatorColors_size", (void**)&dynamicFPDConfigs.pKFPDIndicatorColors_size}, + {"kIndicators", (void**)&dynamicFPDConfigs.pKIndicators}, + {"kIndicators_size", (void**)&dynamicFPDConfigs.pKIndicators_size}, + {"kFPDTextDisplays", (void**)&dynamicFPDConfigs.pKTextDisplays}, + {"kFPDTextDisplays_size", (void**)&dynamicFPDConfigs.pKTextDisplays_size} + }; + isSymbolsLoaded = false; + if (nullptr != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, fpdConfigSymbols, sizeof(fpdConfigSymbols)/sizeof(dlSymbolLookup)); + } + FrontPanelConfig::getInstance().load(isSymbolsLoaded ? &dynamicFPDConfigs : nullptr); + } + + if (nullptr != pDLHandle) { + dlclose(pDLHandle); + pDLHandle = nullptr; + } + INT_INFO("Exiting ..."); +} + Manager::Manager() { // TODO Auto-generated constructor stub @@ -106,7 +226,8 @@ Manager::~Manager() { void Manager::Initialize() { {std::lock_guard lock(gManagerInitMutex); - printf("Entering %s count %d with thread id %lu\n",__FUNCTION__,IsInitialized,pthread_self()); + + INT_INFO("Entering ... count %d with thread id %lu\n",IsInitialized,pthread_self()); try { if (0 == IsInitialized) { @@ -120,7 +241,7 @@ void Manager::Initialize() // That's why the retry logic is applied only for dsDisplayInit. do { err = dsDisplayInit(); - printf ("Manager::Initialize: result :%d retryCount :%d\n", err, retryCount); + INT_INFO("dsDisplayInit returned %d, retryCount %d", err, retryCount); if (dsERR_NONE == err) break; usleep(100000); } while(( dsERR_INVALID_STATE == err) && (retryCount++ < 25)); @@ -131,9 +252,11 @@ void Manager::Initialize() CHECK_RET_VAL(err); err = dsVideoDeviceInit(); CHECK_RET_VAL(err); - AudioOutputPortConfig::getInstance().load(); - VideoOutputPortConfig::getInstance().load(); - VideoDeviceConfig::getInstance().load(); + + loadDeviceCapabilities(device::DEVICE_CAPABILITY_VIDEO_PORT | + device::DEVICE_CAPABILITY_AUDIO_PORT | + device::DEVICE_CAPABILITY_VIDEO_DEVICE | + device::DEVICE_CAPABILITY_FRONT_PANEL); } IsInitialized++; } @@ -142,16 +265,16 @@ void Manager::Initialize() throw e; } } - printf("Exiting %s with thread %lu\n",__FUNCTION__,pthread_self()); + INT_INFO("Exiting ... with thread id %lu",pthread_self()); } void Manager::load() { - printf("%d:%s load start\n", __LINE__, __FUNCTION__); - device::AudioOutputPortConfig::getInstance().load(); - device::VideoOutputPortConfig::getInstance().load(); - device::VideoDeviceConfig::getInstance().load(); - printf("%d:%s load completed\n", __LINE__, __FUNCTION__); + INT_INFO("Enter function"); + loadDeviceCapabilities( device::DEVICE_CAPABILITY_VIDEO_PORT | + device::DEVICE_CAPABILITY_AUDIO_PORT | + device::DEVICE_CAPABILITY_VIDEO_DEVICE); + INT_INFO("Exit function"); } /** @@ -176,7 +299,7 @@ void Manager::load() void Manager::DeInitialize() { {std::lock_guard lock(gManagerInitMutex); - printf("Entering %s count %d with thread id: %lu\n",__FUNCTION__,IsInitialized,pthread_self()); + INT_INFO("Entering ... count %d with thread id %lu",IsInitialized,pthread_self()); if(IsInitialized>0)IsInitialized--; if (0 == IsInitialized) { @@ -190,8 +313,7 @@ void Manager::DeInitialize() dsDisplayTerm(); } } - printf("Exiting %s with thread %lu\n",__FUNCTION__,pthread_self()); - + INT_INFO("Exiting ... with thread %lu",pthread_self()); } } diff --git a/ds/videoDeviceConfig.cpp b/ds/videoDeviceConfig.cpp index 0a25b478..fab33f59 100644 --- a/ds/videoDeviceConfig.cpp +++ b/ds/videoDeviceConfig.cpp @@ -33,7 +33,9 @@ #include "videoDFC.hpp" #include #include "dslogger.h" +#include "manager.hpp" +#define DEBUG 1 // Using for dumpconfig namespace device { @@ -86,8 +88,46 @@ VideoDFC & VideoDeviceConfig::getDefaultDFC() return _vDFCs.back(); } -void VideoDeviceConfig::load() +void dumpconfig(videoDeviceConfig_t *config) { + if (nullptr == config) { + INT_ERROR("Video config is NULL"); + return; + } + if ( -1 == access("/opt/dsMgrDumpDeviceConfigs", F_OK) ) { + INT_INFO("Dumping of Device configs is disabled"); + return; + } + + INT_INFO("\n=============== Starting to Dump VideoDevice Configs ===============\n"); + + if( nullptr != config->pKVideoDeviceConfigs ) + { + int configSize = (config->pKVideoDeviceConfigs_size) ? *(config->pKVideoDeviceConfigs_size) : -1; + INT_INFO("pKVideoDeviceConfigs = %p", config->pKVideoDeviceConfigs); + INT_INFO("videoDeviceConfigs_size = %d", configSize); + for (int i = 0; i < configSize; i++) { + dsVideoConfig_t* videoDeviceConfig = &config->pKVideoDeviceConfigs[i]; + INT_INFO("pKVideoDeviceConfigs[%d].numSupportedDFCs = %lu ", i, videoDeviceConfig->numSupportedDFCs); + for (int j = 0; j < videoDeviceConfig->numSupportedDFCs; j++) { + INT_INFO(" Address of pKVideoDeviceConfigs[%d].supportedDFCs[%d] = %d", i, j, videoDeviceConfig->supportedDFCs[j]); + } + } + } + else + { + INT_ERROR(" kVideoDeviceConfigs is NULL"); + } + + INT_INFO("\n=============== Dump VideoDevice Configs done ===============\n"); +} + +void VideoDeviceConfig::load(videoDeviceConfig_t* dynamicVideoDeviceConfigs) +{ + int configSize = -1; + videoDeviceConfig_t configuration = {0}; + + INT_INFO("Enter function"); /* * Load Constants First. */ @@ -95,16 +135,41 @@ void VideoDeviceConfig::load() _vDFCs.push_back(VideoDFC(i)); } + INT_INFO("Using '%s' config", dynamicVideoDeviceConfigs ? "dynamic" : "static"); + if ( nullptr != dynamicVideoDeviceConfigs ) + { + configuration = *dynamicVideoDeviceConfigs; + configSize = (configuration.pKVideoDeviceConfigs_size) ? *(configuration.pKVideoDeviceConfigs_size) : -1; + } + else { + configuration.pKVideoDeviceConfigs = (dsVideoConfig_t *)kConfigs; + configSize = dsUTL_DIM(kConfigs); + configuration.pKVideoDeviceConfigs_size = &configSize; + } + + INT_INFO("VideoDevice Config[%p] ConfigSize[%d]", configuration.pKVideoDeviceConfigs, configSize); + + dumpconfig(&configuration); + /* * Initialize Video Devices (supported DFCs etc.) */ - for (size_t i = 0; i < dsUTL_DIM(kConfigs); i++) { - _vDevices.push_back(VideoDevice(i)); - - for (size_t j = 0; j < kConfigs[i].numSupportedDFCs; j++) { - _vDevices.at(i).addDFC(VideoDFC::getInstance(kConfigs[i].supportedDFCs[j])); + if ( nullptr != configuration.pKVideoDeviceConfigs ) + { + for (int i = 0; i < configSize; i++) { + dsVideoConfig_t* videoDeviceCfg = &configuration.pKVideoDeviceConfigs[i]; + _vDevices.push_back(VideoDevice(i)); + + for (int j = 0; j < videoDeviceCfg->numSupportedDFCs; j++) { + _vDevices.at(i).addDFC(VideoDFC::getInstance(videoDeviceCfg->supportedDFCs[j])); + } } } + else + { + INT_ERROR(" Configs are NULL and config size are -1"); + } + INT_INFO("Exit function"); } void VideoDeviceConfig::release() diff --git a/ds/videoDeviceConfig.hpp b/ds/videoDeviceConfig.hpp index 65fcf791..c6b0659d 100644 --- a/ds/videoDeviceConfig.hpp +++ b/ds/videoDeviceConfig.hpp @@ -35,6 +35,12 @@ #include "videoDevice.hpp" #include +typedef struct videoDeviceConfig +{ + dsVideoConfig_t *pKVideoDeviceConfigs; + int *pKVideoDeviceConfigs_size; +}videoDeviceConfig_t; + namespace device { class VideoDeviceConfig { @@ -55,7 +61,7 @@ class VideoDeviceConfig { VideoDFC & getDFC(int id); VideoDFC & getDefaultDFC(); - void load(); + void load(videoDeviceConfig_t* dynamicVideoDeviceConfigs); void release(); }; diff --git a/ds/videoOutputPort.cpp b/ds/videoOutputPort.cpp index c77aa5c4..a5b29674 100644 --- a/ds/videoOutputPort.cpp +++ b/ds/videoOutputPort.cpp @@ -128,7 +128,7 @@ VideoOutputPort::VideoOutputPort(const int type, const int index, const int id, _resolution(resolution), _display(*this) { - dsError_t ret = dsGetVideoPort((dsVideoPortType_t)_type, _index, &_handle); + dsError_t ret = dsGetVideoPort((dsVideoPortType_t)_type, _index, &_handle); { std::stringstream out; @@ -138,25 +138,25 @@ VideoOutputPort::VideoOutputPort(const int type, const int index, const int id, if (ret == dsERR_NONE) { bool enabled = false; - ret = dsIsVideoPortEnabled(_handle, &enabled); + ret = dsIsVideoPortEnabled(_handle, &enabled); if (ret == dsERR_NONE) { _enabled = enabled; _contentProtected = false; bool connected = false; - ret = dsIsDisplayConnected(_handle, &connected); + ret = dsIsDisplayConnected(_handle, &connected); if (ret == dsERR_NONE) { - _displayConnected = connected; + _displayConnected = connected; } else { - throw IllegalArgumentException(); + throw IllegalArgumentException(); } } else { } } else { - throw IllegalArgumentException(); + throw IllegalArgumentException(); } } @@ -465,7 +465,7 @@ bool VideoOutputPort::isDynamicResolutionSupported() const */ void VideoOutputPort::setResolution(const std::string &resolutionName, bool persist/* = true*/, bool isIgnoreEdid/* = false*/) { - printf("ResOverride VideoOutputPort::setResolution resolutionName:%s persist:%d isIgnoreEdid:%d line:%d\r\n", resolutionName.c_str(), persist, isIgnoreEdid, __LINE__); + INT_INFO("ResOverride VideoOutputPort::setResolution resolutionName:%s persist:%d isIgnoreEdid:%d", resolutionName.c_str(), persist, isIgnoreEdid); if (0 && resolutionName.compare(_resolution) == 0) { return; } diff --git a/ds/videoOutputPortConfig.cpp b/ds/videoOutputPortConfig.cpp index 8f1e475c..64759527 100644 --- a/ds/videoOutputPortConfig.cpp +++ b/ds/videoOutputPortConfig.cpp @@ -42,6 +42,7 @@ #include "videoResolution.hpp" #include "dslogger.h" #include "host.hpp" +#include "manager.hpp" #include @@ -264,83 +265,194 @@ List VideoOutputPortConfig::getSupportedResolutions(bool isIgn } - -void VideoOutputPortConfig::load() +void dumpconfig(videoPortConfigs_t *config) { - try { - /* - * Load Constants First. - */ - for (size_t i = 0; i < dsVIDEO_PIXELRES_MAX; i++) { - _vPixelResolutions.push_back(PixelResolution(i)); - } - for (size_t i = 0; i < dsVIDEO_ASPECT_RATIO_MAX; i++) { - _vAspectRatios.push_back(AspectRatio(i)); - } - for (size_t i = 0; i < dsVIDEO_SSMODE_MAX; i++) { - _vStereoScopieModes.push_back(StereoScopicMode(i)); - } - for (size_t i = 0; i < dsVIDEO_FRAMERATE_MAX; i++) { - _vFrameRates.push_back(FrameRate((int)i)); - } - - for (size_t i = 0; i < dsVIDEOPORT_TYPE_MAX; i++) { - _vPortTypes.push_back(VideoOutputPortType((int)i)); - } - - /* Initialize a set of supported resolutions - * - */ - size_t numResolutions = dsUTL_DIM(kResolutions); - for (size_t i = 0; i < numResolutions; i++) { - dsVideoPortResolution_t *resolution = &kResolutions[i]; - {std::lock_guard lock(gSupportedResolutionsMutex); - _supportedResolutions.push_back( - VideoResolution( - i, /* id */ - std::string(resolution->name), - resolution->pixelResolution, - resolution->aspectRatio, - resolution->stereoScopicMode, - resolution->frameRate, - resolution->interlaced)); - } - } - - - /* - * Initialize Video portTypes (Only Enable POrts) - * and its port instances (curr resolution) - */ - for (size_t i = 0; i < dsUTL_DIM(kConfigs); i++) - { - const dsVideoPortTypeConfig_t *typeCfg = &kConfigs[i]; - VideoOutputPortType &vPortType = VideoOutputPortType::getInstance(typeCfg->typeId); - vPortType.enable(); - vPortType.setRestrictedResolution(typeCfg->restrictedResollution); - } - - /* - * set up ports based on kPorts[] - */ - for (size_t i = 0; i < dsUTL_DIM(kPorts); i++) { - const dsVideoPortPortConfig_t *port = &kPorts[i]; - - _vPorts.push_back( - VideoOutputPort((port->id.type), port->id.index, i, - AudioOutputPortType::getInstance(kPorts[i].connectedAOP.type).getPort(kPorts[i].connectedAOP.index).getId(), - std::string(port->defaultResolution))); - - _vPortTypes.at(port->id.type).addPort(_vPorts.at(i)); - - } + if (nullptr == config) { + INT_ERROR("Video config is NULL"); + return; + } + if ( -1 == access("/opt/dsMgrDumpDeviceConfigs", F_OK) ) { + INT_INFO("Dumping of Device configs is disabled"); + return; + } + INT_INFO("\n=============== Starting to Dump VideoPort Configs ===============\n"); + + int configSize = -1, portSize = -1, resolutionSize = -1; + if (( nullptr != config->pKConfigs ) && ( nullptr != config->pKPorts ) && ( nullptr != config->pKResolutionsSettings )) + { + configSize = (config->pKVideoPortConfigs_size) ? *(config->pKVideoPortConfigs_size) : -1; + portSize = (config->pKVideoPortPorts_size) ? *(config->pKVideoPortPorts_size) : -1; + resolutionSize = (config->pKResolutionsSettings_size) ? *(config->pKResolutionsSettings_size) : -1; + INT_INFO("pKConfigs = %p", config->pKConfigs); + INT_INFO("pKConfigSize pointer %p = %d", config->pKVideoPortConfigs_size, configSize); + INT_INFO("pKPorts = %p", config->pKPorts); + INT_INFO("pKPortSize pointer %p = %d", config->pKVideoPortPorts_size, portSize); + INT_INFO("pKResolutionsSettings = %p", config->pKResolutionsSettings); + INT_INFO("pKResolutionsSettingsSize pointer %p = %d", config->pKResolutionsSettings_size, resolutionSize); + + INT_INFO("\n\n############### Dumping Video Resolutions Settings ############### \n\n"); + + for (int i = 0; i < resolutionSize; i++) { + dsVideoPortResolution_t *resolution = &(config->pKResolutionsSettings[i]); + INT_INFO("resolution->name = %s", resolution->name); + INT_INFO("resolution->pixelResolution= %d", resolution->pixelResolution); + INT_INFO("resolution->aspectRatio= %d", resolution->aspectRatio); + INT_INFO("resolution->stereoScopicMode= %d", resolution->stereoScopicMode); + INT_INFO("resolution->frameRate= %d", resolution->frameRate); + INT_INFO("resolution->interlaced= %d", resolution->interlaced); + } + + INT_INFO("\n ############### Dumping Video Port Configurations ############### \n"); + + for (int i = 0; i < configSize; i++) + { + const dsVideoPortTypeConfig_t *typeCfg = &(config->pKConfigs[i]); + INT_INFO("typeCfg->typeId = %d", typeCfg->typeId); + INT_INFO("typeCfg->name = %s", (typeCfg->name) ? typeCfg->name : "NULL"); + INT_INFO("typeCfg->dtcpSupported= %d", typeCfg->dtcpSupported); + INT_INFO("typeCfg->hdcpSupported = %d", typeCfg->hdcpSupported); + INT_INFO("typeCfg->restrictedResollution = %d", typeCfg->restrictedResollution); + INT_INFO("typeCfg->numSupportedResolutions= %lu", typeCfg->numSupportedResolutions); + + INT_INFO("typeCfg->supportedResolutions = %p", typeCfg->supportedResolutions); + INT_INFO("typeCfg->supportedResolutions->name = %s", (typeCfg->supportedResolutions->name) ? typeCfg->supportedResolutions->name : "NULL"); + INT_INFO("typeCfg->supportedResolutions->pixelResolution= %d", typeCfg->supportedResolutions->pixelResolution); + INT_INFO("typeCfg->supportedResolutions->aspectRatio= %d", typeCfg->supportedResolutions->aspectRatio); + INT_INFO("typeCfg->supportedResolutions->stereoScopicMode= %d", typeCfg->supportedResolutions->stereoScopicMode); + INT_INFO("typeCfg->supportedResolutions->frameRate= %d", typeCfg->supportedResolutions->frameRate); + INT_INFO("typeCfg->supportedResolutions->interlaced= %d", typeCfg->supportedResolutions->interlaced); + } + INT_INFO("\n############### Dumping Video Port Connections ###############\n"); + + for (int i = 0; i < portSize; i++) { + const dsVideoPortPortConfig_t *portCfg = &(config->pKPorts[i]); + INT_INFO("portCfg->id.type = %d", portCfg->id.type); + INT_INFO("portCfg->id.index = %d", portCfg->id.index); + INT_INFO("portCfg->connectedAOP.type = %d", portCfg->connectedAOP.type); + INT_INFO("portCfg->connectedAOP.index = %d", portCfg->connectedAOP.index); + INT_INFO("portCfg->defaultResolution = %s", (portCfg->defaultResolution) ? portCfg->defaultResolution : "NULL"); + } + } + else + { + INT_ERROR("pKConfigs or pKPorts or pKResolutionsSettings is NULL"); + } + INT_INFO("\n=============== Dump VideoPort Configs done ===============\n"); + INT_INFO("Exit function"); +} - } - catch (...) { - cout << "VIdeo Outport Exception Thrown. ..."< lock(gSupportedResolutionsMutex); + _supportedResolutions.push_back( + VideoResolution( + i, /* id */ + std::string(resolution->name), + resolution->pixelResolution, + resolution->aspectRatio, + resolution->stereoScopicMode, + resolution->frameRate, + resolution->interlaced)); + } + } + + /* + * Initialize Video portTypes (Only Enable POrts) + * and its port instances (curr resolution) + */ + for (int i = 0; i < configSize; i++) + { + const dsVideoPortTypeConfig_t *typeCfg = &(configuration.pKConfigs[i]); + VideoOutputPortType &vPortType = VideoOutputPortType::getInstance(typeCfg->typeId); + vPortType.enable(); + vPortType.setRestrictedResolution(typeCfg->restrictedResollution); + } + + /* + * set up ports based on kPorts[] + */ + for (int i = 0; i < portSize; i++) { + const dsVideoPortPortConfig_t *portCfg = &(configuration.pKPorts[i]); + if (nullptr == portCfg->defaultResolution) { + INT_ERROR("defaultResolution is NULL at %d, using empty string...", i); + } + _vPorts.push_back( + VideoOutputPort((portCfg->id.type), portCfg->id.index, i, + AudioOutputPortType::getInstance(portCfg->connectedAOP.type).getPort(portCfg->connectedAOP.index).getId(), + (portCfg->defaultResolution) ? std::string(portCfg->defaultResolution) : std::string(""))); + _vPortTypes.at(portCfg->id.type).addPort(_vPorts.at(i)); + } + } + else + { + cout << "Video Outport Configs or Ports or Resolutions is NULL. ..."< #include +typedef struct videoPortConfigs +{ + const dsVideoPortTypeConfig_t *pKConfigs; + int *pKVideoPortConfigs_size; + const dsVideoPortPortConfig_t *pKPorts; + int *pKVideoPortPorts_size; + dsVideoPortResolution_t *pKResolutionsSettings; + int *pKResolutionsSettings_size; +}videoPortConfigs_t; + namespace device { class VideoOutputPortConfig { @@ -74,7 +80,7 @@ class VideoOutputPortConfig { List getSupportedTypes(); List getSupportedResolutions(bool isIgnoreEdid=false); - void load(); + void load(videoPortConfigs_t* dynamicVideoPortConfigs); void release(); }; diff --git a/ds/videoOutputPortType.cpp b/ds/videoOutputPortType.cpp index 87ebbaa6..2e112058 100644 --- a/ds/videoOutputPortType.cpp +++ b/ds/videoOutputPortType.cpp @@ -36,7 +36,7 @@ #include "illegalArgumentException.hpp" #include "videoOutputPortConfig.hpp" #include "dslogger.h" - +#include "dsVideoPort.h" #include @@ -209,19 +209,26 @@ void VideoOutputPortType::enabledDTCP() */ void VideoOutputPortType::enabledHDCP(bool contentProtect , char *hdcpKey , size_t keySize ) { - dsError_t ret = dsERR_NONE; - if (device::Host::getInstance().isHDMIOutPortPresent()){ - ret = dsEnableHDCP(dsVIDEOPORT_TYPE_HDMI, contentProtect, hdcpKey, keySize); + dsError_t ret = dsERR_NONE; + intptr_t handle = -1; + + // Assuming isHDMIOutPortPresent() will only be 'true' for Source devices + dsVideoPortType_t portType = device::Host::getInstance().isHDMIOutPortPresent() + ? dsVIDEOPORT_TYPE_HDMI + : dsVIDEOPORT_TYPE_INTERNAL; + ret = dsGetVideoPort(portType, 0, &handle); + if ((ret == dsERR_NONE) && (handle != -1)) { + ret = dsEnableHDCP(handle, contentProtect, hdcpKey, keySize); + } else { + INT_ERROR("VideoOutputPortType::enabledHDCP: Error type %d, handle=%p, error code=%d", portType, (void *)handle, ret); + // Set ret to an error code on dsGetVideoPort failure or invalid handle to ensure exception is thrown + ret = dsERR_GENERAL; } - else{ - ret = dsEnableHDCP(dsVIDEOPORT_TYPE_INTERNAL , contentProtect, hdcpKey, keySize); + + if (ret != dsERR_NONE) { + throw IllegalArgumentException(); } - - if (ret != dsERR_NONE) - { - throw IllegalArgumentException(); - } - _hdcpSupported = true; + _hdcpSupported = true; }