diff --git a/ds/audioOutputPortConfig.cpp b/ds/audioOutputPortConfig.cpp index c3ab1cc6..2b1664fd 100644 --- a/ds/audioOutputPortConfig.cpp +++ b/ds/audioOutputPortConfig.cpp @@ -34,6 +34,9 @@ #include "dsUtl.h" #include "stdlib.h" #include "dslogger.h" +#include +#include "manager.hpp" + namespace device { @@ -108,68 +111,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() @@ -187,8 +277,5 @@ 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/include/videoDevice.hpp b/ds/include/videoDevice.hpp index 61ec375d..331105fb 100644 --- a/ds/include/videoDevice.hpp +++ b/ds/include/videoDevice.hpp @@ -33,6 +33,7 @@ #include "dsConstant.hpp" #include "videoDFC.hpp" #include "videoResolution.hpp" +#include "videoOutputPortConfig.hpp" #include "list.hpp" #include #include 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/videoDevice.cpp b/ds/videoDevice.cpp index 37452a0c..040e8b3a 100644 --- a/ds/videoDevice.cpp +++ b/ds/videoDevice.cpp @@ -33,6 +33,7 @@ #include "illegalArgumentException.hpp" #include "exception.hpp" #include "videoDeviceConfig.hpp" +#include "videoOutputPortConfig.hpp" #include "dsVideoResolutionSettings.h" #include "host.hpp" @@ -258,16 +259,17 @@ void VideoDevice::getHDRCapabilities(int *capabilities) dsGetHDRCapabilities(_handle, capabilities); } + void VideoDevice::getSettopSupportedResolutions(std::list& stbSupportedResoltuions) { - size_t numResolutions = dsUTL_DIM(kResolutions); - for (size_t i = 0; i < numResolutions; i++) - { - dsVideoPortResolution_t *resolution = &kResolutions[i]; - stbSupportedResoltuions.push_back(std::string(resolution->name)); + stbSupportedResoltuions.clear(); + + // Get cached supported resolutions directly from _supportedResolutions + const std::vector& resolutions = VideoOutputPortConfig::getInstance()._supportedResolutions; + + for (const VideoResolution& resolution : resolutions) { + stbSupportedResoltuions.push_back(resolution.getName()); } - - return; } unsigned int VideoDevice::getSupportedVideoCodingFormats() const 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..d5394c64 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 @@ -216,20 +217,17 @@ List VideoOutputPortConfig::getSupportedResolutions(bool isIgn //If isIgnoreEdid is true isDynamicList is zero. Edid logic is skipped. if (0 == isDynamicList ) { - size_t numResolutions = dsUTL_DIM(kResolutions); - for (size_t i = 0; i < numResolutions; i++) - { - dsVideoPortResolution_t *resolution = &kResolutions[i]; - tmpsupportedResolutions.push_back( - VideoResolution( - i, /* id */ - std::string(resolution->name), - resolution->pixelResolution, - resolution->aspectRatio, - resolution->stereoScopicMode, - resolution->frameRate, - resolution->interlaced)); - } + cout << "[DsMgr] Copying _supportedResolutions to tmpsupportedResolutions, size: " << _supportedResolutions.size() << endl; + for (size_t idx = 0; idx < _supportedResolutions.size(); idx++) { + const VideoResolution& res = _supportedResolutions[idx]; + cout << "[DsMgr] [" << idx << "] " << res.getName() + << " pixelRes=" << res.getPixelResolution().getId() + << " aspectRatio=" << res.getAspectRatio().getId() + << " frameRate=" << res.getFrameRate().getId() << endl; + } + for (const VideoResolution& resolution : _supportedResolutions) { + tmpsupportedResolutions.push_back(resolution); + } } if (!isIgnoreEdid) { try { @@ -259,88 +257,207 @@ List VideoOutputPortConfig::getSupportedResolutions(bool isIgn for (VideoResolution resolution : tmpsupportedResolutions){ _supportedResolutions.push_back(resolution); } + cout << "[DsMgr] _supportedResolutions cache after update, size: " << _supportedResolutions.size() << endl; + for (size_t idx = 0; idx < _supportedResolutions.size(); idx++) { + const VideoResolution& res = _supportedResolutions[idx]; + cout << "[DsMgr] [" << idx << "] " << res.getName() + << " pixelRes=" << res.getPixelResolution().getId() + << " aspectRatio=" << res.getAspectRatio().getId() + << " frameRate=" << res.getFrameRate().getId() << endl; + } } return supportedResolutions; } - -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 { @@ -49,7 +55,6 @@ class VideoOutputPortConfig { std::vector _vPixelResolutions; std::vector _vAspectRatios; std::vector _vStereoScopieModes; - std::vector _supportedResolutions; std::vector _vFrameRates; std::vector _vPortTypes; std::vector _vPorts; @@ -59,6 +64,7 @@ class VideoOutputPortConfig { ~VideoOutputPortConfig(); public: + std::vector _supportedResolutions; static VideoOutputPortConfig & getInstance(); const PixelResolution &getPixelResolution(int id) const; @@ -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/rpc/include/dsAudioConfig.h b/rpc/include/dsAudioConfig.h new file mode 100644 index 00000000..427d20a1 --- /dev/null +++ b/rpc/include/dsAudioConfig.h @@ -0,0 +1,75 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#ifndef _DS_AUDIO_CONFIG_H_ +#define _DS_AUDIO_CONFIG_H_ + +#include "dsTypes.h" +//#include "dsAudioSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct audioConfigs +{ + const dsAudioTypeConfig_t *pKAudioConfigs; + const dsAudioPortConfig_t *pKAudioPorts; + int *pKConfigSize; + int *pKPortSize; +}audioConfigs_t; + +/** + * @brief Load audio output port configuration + * + * @param[in] dynamicAudioConfigs Pointer to dynamic audio configuration, or NULL for static config + */ +void dsLoadAudioOutputPortConfig(const audioConfigs_t* dynamicAudioConfigs); + +/** + * @brief Get audio type configurations + * + * @param[out] outConfigSize Pointer to store the number of audio type configs, or NULL + * @param[out] outConfigs Pointer to store the audio type configs array, or NULL + */ +void dsGetAudioTypeConfigs(int* outConfigSize, const dsAudioTypeConfig_t** outConfigs); + +/** + * @brief Get audio port configurations + * + * @param[out] outPortSize Pointer to store the number of audio port configs, or NULL + * @param[out] outPorts Pointer to store the audio port configs array, or NULL + */ +void dsGetAudioPortConfigs(int* outPortSize, const dsAudioPortConfig_t** outPorts); + +#ifdef __cplusplus +} +#endif + +#endif /* _DS_AUDIO_CONFIG_H_ */ + +/** @} */ +/** @} */ diff --git a/rpc/include/dsConfigs.h b/rpc/include/dsConfigs.h new file mode 100644 index 00000000..b7e2fb7a --- /dev/null +++ b/rpc/include/dsConfigs.h @@ -0,0 +1,78 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#ifndef _DS_CONFIGS_H_ +#define _DS_CONFIGS_H_ + +#include "dsTypes.h" +//#include "dsAudioSettings.h" +//#include "dsVideoPortSettings.h" +//#include "dsVideoDeviceSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct audioConfigs +{ + const dsAudioTypeConfig_t *pKAudioConfigs; + const dsAudioPortConfig_t *pKAudioPorts; + int *pKConfigSize; + int *pKPortSize; +}audioConfigs_t; + +typedef struct videoPortConfigs +{ + const dsVideoPortTypeConfig_t *pKVideoPortConfigs; + int *pKVideoPortConfigs_size; + const dsVideoPortPortConfig_t *pKVideoPortPorts; + int *pKVideoPortPorts_size; + dsVideoPortResolution_t *pKVideoPortResolutionsSettings; + int *pKResolutionsSettings_size; + int *pKDefaultResIndex; +}videoPortConfigs_t; + +typedef struct videoDeviceConfig +{ + dsVideoConfig_t *pKVideoDeviceConfigs; + int *pKVideoDeviceConfigs_size; +}videoDeviceConfig_t; + +/** + * @brief Load all device settings configurations + * + * Loads audio, video port, and video device configurations from HAL library + */ +void dsLoadConfigs(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _DS_CONFIGS_H_ */ + +/** @} */ +/** @} */ diff --git a/rpc/include/dsVideoDeviceConfig.h b/rpc/include/dsVideoDeviceConfig.h new file mode 100644 index 00000000..d35c2664 --- /dev/null +++ b/rpc/include/dsVideoDeviceConfig.h @@ -0,0 +1,65 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#ifndef _DS_VIDEO_DEVICE_CONFIG_H_ +#define _DS_VIDEO_DEVICE_CONFIG_H_ + +#include "dsTypes.h" +//#include "dsVideoDeviceSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct videoDeviceConfig +{ + dsVideoConfig_t *pKVideoDeviceConfigs; + int *pKVideoDeviceConfigs_size; +}videoDeviceConfig_t; + +/** + * @brief Load video device configuration + * + * @param[in] dynamicVideoDeviceConfigs Pointer to dynamic video device configuration, or NULL for static config + */ +void dsLoadVideoDeviceConfig(const videoDeviceConfig_t* dynamicVideoDeviceConfigs); + +/** + * @brief Get video device configurations + * + * @param[out] outConfigSize Pointer to store the number of video device configs, or NULL + * @param[out] outConfigs Pointer to store the video device configs array, or NULL + */ +void dsGetVideoDeviceConfigs(int* outConfigSize, dsVideoConfig_t** outConfigs); + +#ifdef __cplusplus +} +#endif + +#endif /* _DS_VIDEO_DEVICE_CONFIG_H_ */ + +/** @} */ +/** @} */ diff --git a/rpc/include/dsVideoPortConfig.h b/rpc/include/dsVideoPortConfig.h new file mode 100644 index 00000000..17de96dd --- /dev/null +++ b/rpc/include/dsVideoPortConfig.h @@ -0,0 +1,93 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#ifndef _DS_VIDEO_PORT_CONFIG_H_ +#define _DS_VIDEO_PORT_CONFIG_H_ + +#include "dsTypes.h" +//#include "dsVideoPortSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct videoPortConfigs +{ + const dsVideoPortTypeConfig_t *pKVideoPortConfigs; + int *pKVideoPortConfigs_size; + const dsVideoPortPortConfig_t *pKVideoPortPorts; + int *pKVideoPortPorts_size; + dsVideoPortResolution_t *pKVideoPortResolutionsSettings; + int *pKResolutionsSettings_size; + int *pKDefaultResIndex; +}videoPortConfigs_t; + +/** + * @brief Load video output port configuration + * + * @param[in] dynamicVideoPortConfigs Pointer to dynamic video port configuration, or NULL for static config + */ +void dsLoadVideoOutputPortConfig(const videoPortConfigs_t* dynamicVideoPortConfigs); + +/** + * @brief Get video port type configurations + * + * @param[out] outConfigSize Pointer to store the number of video port type configs, or NULL + * @param[out] outConfigs Pointer to store the video port type configs array, or NULL + */ +void dsGetVideoPortTypeConfigs(int* outConfigSize, const dsVideoPortTypeConfig_t** outConfigs); + +/** + * @brief Get video port port configurations + * + * @param[out] outPortSize Pointer to store the number of video port port configs, or NULL + * @param[out] outPorts Pointer to store the video port port configs array, or NULL + */ +void dsGetVideoPortPortConfigs(int* outPortSize, const dsVideoPortPortConfig_t** outPorts); + +/** + * @brief Get video port resolutions + * + * @param[out] outResolutionSize Pointer to store the number of video port resolutions, or NULL + * @param[out] outResolutions Pointer to store the video port resolutions array, or NULL + */ +void dsGetVideoPortResolutions(int* outResolutionSize, dsVideoPortResolution_t** outResolutions); + +/** + * @brief Get default resolution index + * + * @param[out] outDefaultIndex Pointer to store the default resolution index, or NULL + */ +void dsGetDefaultResolutionIndex(int* outDefaultIndex); + +#ifdef __cplusplus +} +#endif + +#endif /* _DS_VIDEO_PORT_CONFIG_H_ */ + +/** @} */ +/** @} */ diff --git a/rpc/srv/dsAudio.c b/rpc/srv/dsAudio.c index 7d085ffd..8ec09aee 100755 --- a/rpc/srv/dsAudio.c +++ b/rpc/srv/dsAudio.c @@ -49,7 +49,8 @@ #include "dsMgr.h" #include "hostPersistence.hpp" #include "dsserverlogger.h" -#include "dsAudioSettings.h" +//#include "dsAudioSettings.h" +#include "dsAudioConfig.h" #include "safec_lib.h" @@ -3777,17 +3778,20 @@ IARM_Result_t _dsGetEncoding(void *arg) static dsAudioPortType_t _GetAudioPortType(intptr_t handle) { - int numPorts,i; + int numPorts = 0; + int i; intptr_t halhandle = 0; + const dsAudioPortConfig_t *kAudioPorts = NULL; - numPorts = dsUTL_DIM(kSupportedPortTypes); + // Get audio port configurations from AudioOutputPortConfig + dsGetAudioPortConfigs(&numPorts, &kAudioPorts); for(i=0; i< numPorts; i++) { - if(dsGetAudioPort (kPorts[i].id.type, kPorts[i].id.index, &halhandle) == dsERR_NONE) { + if(dsGetAudioPort (kAudioPorts[i].id.type, kAudioPorts[i].id.index, &halhandle) == dsERR_NONE) { if (handle == halhandle) { - return kPorts[i].id.type; + return kAudioPorts[i].id.type; } } } diff --git a/rpc/srv/dsAudioConfig.c b/rpc/srv/dsAudioConfig.c new file mode 100644 index 00000000..caefb12a --- /dev/null +++ b/rpc/srv/dsAudioConfig.c @@ -0,0 +1,230 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#include +#include +#include +#include "dsserverlogger.h" +#include "dsTypes.h" +#include "dsAudioSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct audioConfigs +{ + dsAudioTypeConfig_t *pKAudioConfigs; + dsAudioPortConfig_t *pKAudioPorts; + int *pKConfigSize; + int *pKPortSize; +}audioConfigs_t; + +static audioConfigs_t audioConfiguration; + +void audioDumpconfig(audioConfigs_t *config) +{ + 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( NULL != config->pKAudioConfigs ) + { + configSize = (config->pKConfigSize) ? *(config->pKConfigSize) : -1; + + for (int i = 0; i < configSize; i++) { + const dsAudioTypeConfig_t *typeCfg = &(config->pKAudioConfigs[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( NULL != config->pKAudioPorts ) + { + portSize = (config->pKPortSize) ? *(config->pKPortSize) : -1; + for (int i = 0; i < portSize; i++) { + const dsAudioPortConfig_t *portCfg = &(config->pKAudioPorts[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"); +} + +static int allocateAndCopyAudioConfigs(const dsAudioTypeConfig_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s config numElements: %d\n", configType, numElements); + return -1; + } + + audioConfiguration.pKAudioConfigs = (dsAudioTypeConfig_t*)malloc(numElements * sizeof(dsAudioTypeConfig_t)); + if (audioConfiguration.pKAudioConfigs == NULL) { + INT_ERROR("Failed to allocate memory for %s audio configs\n", configType); + return -1; + } + + memcpy(audioConfiguration.pKAudioConfigs, source, numElements * sizeof(dsAudioTypeConfig_t)); + INT_INFO("Allocated and copied %d audio configs (%s)", numElements, configType); + return numElements; +} + +static int allocateAndCopyAudioPorts(const dsAudioPortConfig_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s port numElements: %d\n", configType, numElements); + return -1; + } + + audioConfiguration.pKAudioPorts = (dsAudioPortConfig_t*)malloc(numElements * sizeof(dsAudioPortConfig_t)); + if (audioConfiguration.pKAudioPorts == NULL) { + INT_ERROR("Failed to allocate memory for %s audio ports\n", configType); + return -1; + } + + memcpy(audioConfiguration.pKAudioPorts, source, numElements * sizeof(dsAudioPortConfig_t)); + INT_INFO("Allocated and copied %d audio ports (%s)", numElements, configType); + return numElements; +} + +void dsLoadAudioOutputPortConfig(const audioConfigs_t* dynamicAudioConfigs) +{ + int configSize = -1, portSize = -1; + int ret = -1; + + INT_INFO("Using '%s' config", dynamicAudioConfigs ? "dynamic" : "static"); + + if (NULL != dynamicAudioConfigs) + { + // Reading Audio type configs + configSize = (dynamicAudioConfigs->pKConfigSize) ? *(dynamicAudioConfigs->pKConfigSize) : -1; + ret = allocateAndCopyAudioConfigs(dynamicAudioConfigs->pKAudioConfigs, configSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + // Reading Audio port configs + portSize = (dynamicAudioConfigs->pKPortSize) ? *(dynamicAudioConfigs->pKPortSize) : -1; + ret = allocateAndCopyAudioPorts(dynamicAudioConfigs->pKAudioPorts, portSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + } + else { + // Using static configuration + configSize = dsUTL_DIM(kConfigs); + ret = allocateAndCopyAudioConfigs(kConfigs, configSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + portSize = dsUTL_DIM(kPorts); + ret = allocateAndCopyAudioPorts(kPorts, portSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + } + + INT_INFO("Store sizes configSize =%d, portSize =%d\n", configSize, portSize); + audioConfiguration.pKConfigSize = (int*)malloc(sizeof(int)); + if (audioConfiguration.pKConfigSize == NULL) { + INT_ERROR("Failed to allocate memory for pKConfigSize\n"); + } + else { + *(audioConfiguration.pKConfigSize) = configSize; + INT_INFO("Store sizes *(audioConfiguration.pKConfigSize) =%d\n", *(audioConfiguration.pKConfigSize)); + } + audioConfiguration.pKPortSize = (int*)malloc(sizeof(int)); + if (audioConfiguration.pKPortSize == NULL) { + INT_ERROR("Failed to allocate memory for pKPortSize\n"); + } + else { + *(audioConfiguration.pKPortSize) = configSize; + INT_INFO("Store sizes *(audioConfiguration.pKPortSize) =%d\n", *(audioConfiguration.pKPortSize)); + } + + INT_INFO("Audio Config[%p] ConfigSize[%d] Ports[%p] PortSize[%d]", + audioConfiguration.pKAudioConfigs ? audioConfiguration.pKAudioConfigs : NULL, + audioConfiguration.pKConfigSize ? *(audioConfiguration.pKConfigSize) : -1, + audioConfiguration.pKAudioPorts? audioConfiguration.pKAudioPorts : NULL, + audioConfiguration.pKPortSize ? *(audioConfiguration.pKPortSize) : -1); + audioDumpconfig(&audioConfiguration); +} + +// Getter functions for use across srv code +void dsGetAudioTypeConfigs(int* outConfigSize, const dsAudioTypeConfig_t** outConfigs) +{ + if (outConfigSize != NULL) { + *outConfigSize = *(audioConfiguration.pKConfigSize); + } + if (outConfigs != NULL) { + *outConfigs = audioConfiguration.pKAudioConfigs; + } +} + +void dsGetAudioPortConfigs(int* outPortSize, const dsAudioPortConfig_t** outPorts) +{ + if (outPortSize != NULL) { + *outPortSize = *(audioConfiguration.pKPortSize); + } + if (outPorts != NULL) { + *outPorts = audioConfiguration.pKAudioPorts; + } +} + +#ifdef __cplusplus +} +#endif + +/** @} */ +/** @} */ diff --git a/rpc/srv/dsConfigs.c b/rpc/srv/dsConfigs.c new file mode 100644 index 00000000..6aedbd61 --- /dev/null +++ b/rpc/srv/dsConfigs.c @@ -0,0 +1,176 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#include +#include +#include +#include +#include "dsserverlogger.h" +#include "dsAudioConfig.h" +#include "dsVideoPortConfig.h" +#include "dsVideoDeviceConfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef RDK_DSHAL_NAME +#define RDK_DSHAL_NAME "libdshal.so" +#endif + +#define DEVICE_CAPABILITY_VIDEO_PORT 0x01 +#define DEVICE_CAPABILITY_AUDIO_PORT 0x02 +#define DEVICE_CAPABILITY_VIDEO_DEVICE 0x04 +#define DEVICE_CAPABILITY_FRONT_PANEL 0x08 + +typedef struct { + const char* name; + void** dataptr; +} dlSymbolLookup_t; + + +static int LoadDLSymbols(void* pDLHandle, const dlSymbolLookup_t* symbols, int numberOfSymbols) +{ + int currentSymbols = 0; + int isAllSymbolsLoaded = 0; + + if ((NULL == pDLHandle) || (NULL == symbols)) { + INT_ERROR("Invalid DL Handle or symbolsPtr"); + return 0; + } + + INT_INFO("numberOfSymbols = %d", numberOfSymbols); + for (int i = 0; i < numberOfSymbols; i++) { + if ((NULL == symbols[i].dataptr) || (NULL == symbols[i].name)) { + INT_ERROR("Invalid symbol entry at index [%d]", i); + continue; + } + *(symbols[i].dataptr) = dlsym(pDLHandle, symbols[i].name); + if (NULL == *(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) : 0; + return isAllSymbolsLoaded; +} + +static void loadDeviceCapabilities(unsigned int capabilityType) +{ + void* pDLHandle = NULL; + int isSymbolsLoaded = 0; + + INT_INFO("Entering capabilityType = 0x%08X", capabilityType); + dlerror(); /* clear old error */ + pDLHandle = dlopen(RDK_DSHAL_NAME, RTLD_LAZY); + INT_INFO("DL Instance '%s'", (NULL == pDLHandle ? "NULL" : "Valid")); + + /* Audio Port Config */ + if (DEVICE_CAPABILITY_AUDIO_PORT & capabilityType) { + audioConfigs_t dynamicAudioConfigs; + memset(&dynamicAudioConfigs, 0, sizeof(audioConfigs_t)); + + dlSymbolLookup_t audioConfigSymbols[] = { + {"kAudioConfigs", (void**)&dynamicAudioConfigs.pKAudioConfigs}, + {"kAudioPorts", (void**)&dynamicAudioConfigs.pKAudioPorts}, + {"kAudioConfigs_size", (void**)&dynamicAudioConfigs.pKConfigSize}, + {"kAudioPorts_size", (void**)&dynamicAudioConfigs.pKPortSize} + }; + + isSymbolsLoaded = 0; + if (NULL != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, audioConfigSymbols, + sizeof(audioConfigSymbols)/sizeof(dlSymbolLookup_t)); + } + dsLoadAudioOutputPortConfig(isSymbolsLoaded ? &dynamicAudioConfigs : NULL); + } + + /* Video Port Config */ + if (DEVICE_CAPABILITY_VIDEO_PORT & capabilityType) { + videoPortConfigs_t dynamicVideoPortConfigs; + memset(&dynamicVideoPortConfigs, 0, sizeof(videoPortConfigs_t)); + + dlSymbolLookup_t videoPortConfigSymbols[] = { + {"kVideoPortConfigs", (void**)&dynamicVideoPortConfigs.pKVideoPortConfigs}, + {"kVideoPortConfigs_size", (void**)&dynamicVideoPortConfigs.pKVideoPortConfigs_size}, + {"kVideoPortPorts", (void**)&dynamicVideoPortConfigs.pKVideoPortPorts}, + {"kVideoPortPorts_size", (void**)&dynamicVideoPortConfigs.pKVideoPortPorts_size}, + {"kResolutionsSettings", (void**)&dynamicVideoPortConfigs.pKVideoPortResolutionsSettings}, + {"kResolutionsSettings_size", (void**)&dynamicVideoPortConfigs.pKResolutionsSettings_size}, + {"kDefaultResIndex", (void**)&dynamicVideoPortConfigs.pKDefaultResIndex} + }; + + isSymbolsLoaded = 0; + if (NULL != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, videoPortConfigSymbols, + sizeof(videoPortConfigSymbols)/sizeof(dlSymbolLookup_t)); + } + dsLoadVideoOutputPortConfig(isSymbolsLoaded ? &dynamicVideoPortConfigs : NULL); + } + + /* Video Device Config */ + if (DEVICE_CAPABILITY_VIDEO_DEVICE & capabilityType) { + videoDeviceConfig_t dynamicVideoDeviceConfigs; + memset(&dynamicVideoDeviceConfigs, 0, sizeof(videoDeviceConfig_t)); + + dlSymbolLookup_t videoDeviceConfigSymbols[] = { + {"kVideoDeviceConfigs", (void**)&dynamicVideoDeviceConfigs.pKVideoDeviceConfigs}, + {"kVideoDeviceConfigs_size", (void**)&dynamicVideoDeviceConfigs.pKVideoDeviceConfigs_size} + }; + + isSymbolsLoaded = 0; + if (NULL != pDLHandle) { + isSymbolsLoaded = LoadDLSymbols(pDLHandle, videoDeviceConfigSymbols, + sizeof(videoDeviceConfigSymbols)/sizeof(dlSymbolLookup_t)); + } + dsLoadVideoDeviceConfig(isSymbolsLoaded ? &dynamicVideoDeviceConfigs : NULL); + } + + if (NULL != pDLHandle) { + dlclose(pDLHandle); + pDLHandle = NULL; + } + INT_INFO("Exiting ..."); +} + +void dsLoadConfigs(void) +{ + INT_INFO("Enter function"); + loadDeviceCapabilities(DEVICE_CAPABILITY_VIDEO_PORT | + DEVICE_CAPABILITY_AUDIO_PORT | + DEVICE_CAPABILITY_VIDEO_DEVICE); + INT_INFO("Exit function"); +} + +#ifdef __cplusplus +} +#endif + +/** @} */ +/** @} */ diff --git a/rpc/srv/dsDisplay.c b/rpc/srv/dsDisplay.c index 982a8b57..91a89dc4 100644 --- a/rpc/srv/dsDisplay.c +++ b/rpc/srv/dsDisplay.c @@ -46,8 +46,10 @@ #include "dsMgr.h" #include "dsserverlogger.h" #include "dsVideoPort.h" -#include "dsVideoPortSettings.h" -#include "dsVideoResolutionSettings.h" +//#include "dsVideoPortSettings.h" +//#include "dsVideoResolutionSettings.h" +#include "dsVideoPortConfig.h" +//#include "dsConfigs.h" #include "dsInternal.h" #include "safec_lib.h" @@ -578,7 +580,7 @@ static void filterEDIDResolution(intptr_t handle, dsDisplayEDID_t *edid) { errno_t rc = -1; dsVideoPortResolution_t *edidResn = NULL; - dsVideoPortResolution_t *presolution = NULL; + dsVideoPortResolution_t *presolution = NULL, *kVidoeResolutionsSettings = NULL; dsDisplayEDID_t *edidData = (dsDisplayEDID_t*)malloc(sizeof(dsDisplayEDID_t)); dsVideoPortType_t _VPortType = _GetDisplayPortType(handle); if (edid == NULL) { @@ -590,7 +592,21 @@ static void filterEDIDResolution(intptr_t handle, dsDisplayEDID_t *edid) if(_VPortType == dsVIDEOPORT_TYPE_HDMI) { INT_DEBUG("EDID for HDMI Port\r\n"); - size_t iCount = dsUTL_DIM(kResolutions); + //size_t iCount = dsUTL_DIM(kResolutions); + int iCount = 0; + //Get details from libds + dsGetVideoPortResolutions(&iCount, &kVidoeResolutionsSettings); + + // Print kVidoeResolutionsSettings array + INT_INFO("[DsMgr] ========== Dumping kVidoeResolutionsSettings Array ==========\r\n"); + INT_INFO("[DsMgr] Total resolutions retrieved: %d\r\n", iCount); + for (int k = 0; k < iCount; k++) { + dsVideoPortResolution_t *res = &kVidoeResolutionsSettings[k]; + INT_INFO("[DsMgr] [%d] name=%s, pixelRes=%d, aspectRatio=%d, stereoMode=%d, frameRate=%d, interlaced=%d\r\n", + k, res->name, res->pixelResolution, res->aspectRatio, + res->stereoScopicMode, res->frameRate, res->interlaced); + } + INT_INFO("[DsMgr] ========== End of kVidoeResolutionsSettings Dump ==========\r\n"); /*Initialize the struct*/ memset(edidData,0,sizeof(*edidData)); @@ -604,14 +620,14 @@ static void filterEDIDResolution(intptr_t handle, dsDisplayEDID_t *edid) edid->numOfSupportedResolution = 0; for (size_t i = 0; i < iCount; i++) { - presolution = &kResolutions[i]; + presolution = &kVidoeResolutionsSettings[i]; for (size_t j = 0; j < edidData->numOfSupportedResolution; j++) { edidResn = &(edidData->suppResolutionList[j]); if (0 == (strcmp(presolution->name,edidResn->name))) { - edid->suppResolutionList[edid->numOfSupportedResolution] = kResolutions[i]; + edid->suppResolutionList[edid->numOfSupportedResolution] = kVidoeResolutionsSettings[i]; edid->numOfSupportedResolution++; numOfSupportedResolution++; INT_DEBUG("[DsMgr] presolution->name : %s, resolution count : %d\r\n",presolution->name,numOfSupportedResolution); @@ -646,14 +662,29 @@ static dsVideoPortType_t _GetDisplayPortType(intptr_t handle) { int numPorts,i; intptr_t halhandle = 0; + const dsVideoPortPortConfig_t *kVideoPortPorts = NULL; + + //numPorts = dsUTL_DIM(kSupportedPortTypes); + dsGetVideoPortPortConfigs(&numPorts, &kVideoPortPorts); + + // Print kVideoPortPorts array + INT_INFO("[DsMgr] ========== Dumping kVideoPortPorts Array ==========\r\n"); + INT_INFO("[DsMgr] Total ports retrieved: %d\r\n", numPorts); + for (int k = 0; k < numPorts; k++) { + const dsVideoPortPortConfig_t *port = &kVideoPortPorts[k]; + INT_INFO("[DsMgr] [%d] type=%d, index=%d, connectedAOP_type=%d, connectedAOP_index=%d, defaultResolution=%s\r\n", + k, port->id.type, port->id.index, + port->connectedAOP.type, port->connectedAOP.index, + port->defaultResolution); + } + INT_INFO("[DsMgr] ========== End of kVideoPortPorts Dump ==========\r\n"); - numPorts = dsUTL_DIM(kSupportedPortTypes); for(i=0; i< numPorts; i++) { - dsGetDisplay(kPorts[i].id.type, kPorts[i].id.index, &halhandle); + dsGetDisplay(kVideoPortPorts[i].id.type, kVideoPortPorts[i].id.index, &halhandle); if (handle == halhandle) { - return kPorts[i].id.type; + return kVideoPortPorts[i].id.type; } } INT_INFO("Error: The Requested Display is not part of Platform Port Configuration \r\n"); diff --git a/rpc/srv/dsMgr.c b/rpc/srv/dsMgr.c index 9de34e5a..b4217861 100755 --- a/rpc/srv/dsMgr.c +++ b/rpc/srv/dsMgr.c @@ -41,6 +41,7 @@ #include "hostPersistence.hpp" #include "dsInternal.h" +#include "dsConfigs.h" profile_t profileType = PROFILE_INVALID; @@ -113,7 +114,9 @@ IARM_Result_t dsMgr_init() profileType = searchRdkProfile(); INT_INFO("[%s]: profileType=%d\r\n", __FUNCTION__, profileType); - device::HostPersistence::getInstance().load(); + INT_INFO("[%s]: Loading device configurations\r\n", __FUNCTION__); + dsLoadConfigs(); + device::HostPersistence::getInstance().load(); dsServer_Rdklogger_Init(); dsHostInit(); dsDisplayMgr_init(); @@ -124,6 +127,7 @@ IARM_Result_t dsMgr_init() dsHostMgr_init(); dsHdmiInMgr_init(); dsCompositeInMgr_init(); + return ret; } diff --git a/rpc/srv/dsVideoDeviceConfig.c b/rpc/srv/dsVideoDeviceConfig.c new file mode 100644 index 00000000..ea5199b4 --- /dev/null +++ b/rpc/srv/dsVideoDeviceConfig.c @@ -0,0 +1,158 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#include +#include +#include +#include "dsserverlogger.h" +#include "dsTypes.h" +#include "dsVideoDeviceSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct videoDeviceConfig +{ + dsVideoConfig_t *pKVideoDeviceConfigs; + int *pKVideoDeviceConfigs_size; +}videoDeviceConfig_t; + +static videoDeviceConfig_t videoDeviceConfiguration; + +void videoDeviceDumpconfig(videoDeviceConfig_t *config) +{ + if (NULL == 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( NULL != 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"); +} + +static int allocateAndCopyVideoDeviceConfigs(const dsVideoConfig_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s video device config numElements: %d\n", configType, numElements); + return -1; + } + + videoDeviceConfiguration.pKVideoDeviceConfigs = (dsVideoConfig_t*)malloc(numElements * sizeof(dsVideoConfig_t)); + if (videoDeviceConfiguration.pKVideoDeviceConfigs == NULL) { + INT_ERROR("Failed to allocate memory for %s video device configs\n", configType); + return -1; + } + + memcpy(videoDeviceConfiguration.pKVideoDeviceConfigs, source, numElements * sizeof(dsVideoConfig_t)); + INT_INFO("Allocated and copied %d video device configs (%s)", numElements, configType); + return numElements; +} + +void dsLoadVideoDeviceConfig(const videoDeviceConfig_t* dynamicVideoDeviceConfigs) +{ + int configSize = -1, ret = -1; + + INT_INFO("Using '%s' config", dynamicVideoDeviceConfigs ? "dynamic" : "static"); + + if (NULL != dynamicVideoDeviceConfigs) + { + // Reading Video Device configs + configSize = (dynamicVideoDeviceConfigs->pKVideoDeviceConfigs_size) ? *(dynamicVideoDeviceConfigs->pKVideoDeviceConfigs_size) : -1; + ret = allocateAndCopyVideoDeviceConfigs(dynamicVideoDeviceConfigs->pKVideoDeviceConfigs, configSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + } + else { + // Using static configuration + configSize = dsUTL_DIM(kConfigs); + ret = allocateAndCopyVideoDeviceConfigs(kConfigs, configSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + } + + INT_INFO("Store sizes configSize =%d\n", configSize); + videoDeviceConfiguration.pKVideoDeviceConfigs_size = (int*)malloc(sizeof(int)); + if (videoDeviceConfiguration.pKVideoDeviceConfigs_size == NULL) { + INT_ERROR("Failed to allocate memory for pKConfigSize\n"); + } + else { + *(videoDeviceConfiguration.pKVideoDeviceConfigs_size) = configSize; + INT_INFO("Store sizes *(videoDeviceConfiguration.pKVideoDeviceConfigs_size) =%d\n", *(videoDeviceConfiguration.pKVideoDeviceConfigs_size)); + } + + INT_INFO("VideoDevice Config[%p] ConfigSize[%d]", + videoDeviceConfiguration.pKVideoDeviceConfigs, + *(videoDeviceConfiguration.pKVideoDeviceConfigs_size)); + videoDeviceDumpconfig(&videoDeviceConfiguration); +} + +// Getter functions for use across srv code +void dsGetVideoDeviceConfigs(int* outConfigSize, dsVideoConfig_t** outConfigs) +{ + if (outConfigSize != NULL) { + *outConfigSize = *(videoDeviceConfiguration.pKVideoDeviceConfigs_size); + } + if (outConfigs != NULL) { + *outConfigs = videoDeviceConfiguration.pKVideoDeviceConfigs; + } +} + +#ifdef __cplusplus +} +#endif + +/** @} */ +/** @} */ diff --git a/rpc/srv/dsVideoPort.c b/rpc/srv/dsVideoPort.c index 21ffdcd2..0aa50bc9 100644 --- a/rpc/srv/dsVideoPort.c +++ b/rpc/srv/dsVideoPort.c @@ -51,7 +51,9 @@ #include "hostPersistence.hpp" #include "dsserverlogger.h" #include "dsTypes.h" -#include "dsVideoPortSettings.h" +//#include "dsVideoPortSettings.h" +#include "dsVideoPortConfig.h" +//#include "dsConfigs.h" #include "dsInternal.h" #include "safec_lib.h" #include @@ -1701,16 +1703,30 @@ IARM_Result_t _dsSupportedTvResolutions(void *arg) static dsVideoPortType_t _GetVideoPortType(intptr_t handle) { - int numPorts,i; + int numPorts = 0, i; intptr_t halhandle = 0; + const dsVideoPortPortConfig_t *kVideoPortPorts = NULL; + + dsGetVideoPortPortConfigs(&numPorts, &kVideoPortPorts); + + // Print kVideoPortPorts array + INT_INFO("[DsMgr] ========== Dumping kVideoPortPorts Array in _GetVideoPortType ==========\r\n"); + INT_INFO("[DsMgr] Total ports retrieved: %d\r\n", numPorts); + for (int k = 0; k < numPorts; k++) { + const dsVideoPortPortConfig_t *port = &kVideoPortPorts[k]; + INT_INFO("[DsMgr] [%d] type=%d, index=%d, connectedAOP_type=%d, connectedAOP_index=%d, defaultResolution=%s\r\n", + k, port->id.type, port->id.index, + port->connectedAOP.type, port->connectedAOP.index, + port->defaultResolution ? port->defaultResolution : "NULL"); + } + INT_INFO("[DsMgr] ========== End of kVideoPortPorts Dump ==========\r\n"); - numPorts = dsUTL_DIM(kSupportedPortTypes); for(i=0; i< numPorts; i++) { - dsGetVideoPort(kPorts[i].id.type, kPorts[i].id.index, &halhandle); + dsGetVideoPort(kVideoPortPorts[i].id.type, kVideoPortPorts[i].id.index, &halhandle); if (handle == halhandle) { - return kPorts[i].id.type; + return kVideoPortPorts[i].id.type; } } INT_ERROR("Error: The Requested Video Port is not part of Platform Port Configuration \r\n"); @@ -1894,7 +1910,16 @@ static std::string getCompatibleResolution(dsVideoPortResolution_t *SrcResn) case dsVIDEO_PIXELRES_4096x2160: case dsVIDEO_PIXELRES_MAX: default: - return resolution.assign(kResolutions[kDefaultResIndex].name); + { + int numResolutions = 0; + dsVideoPortResolution_t* resolutions = NULL; + int defaultIndex = 0; + dsGetVideoPortResolutions(&numResolutions, &resolutions); + dsGetDefaultResolutionIndex(&defaultIndex); + if (resolutions && defaultIndex >= 0 && defaultIndex < numResolutions) { + return resolution.assign(resolutions[defaultIndex].name); + } + } break; } } @@ -1916,11 +1941,26 @@ static bool IsCompatibleResolution(dsVideoResolution_t pixelResolution1,dsVideo static dsVideoResolution_t getPixelResolution(std::string &resolution ) { - dsVideoPortResolution_t *Resn = &kResolutions[kDefaultResIndex]; + dsVideoPortResolution_t *kVidoeResolutionsSettings = NULL; + int iCount = 0; + dsGetVideoPortResolutions(&iCount, &kVidoeResolutionsSettings); + + // Print kVidoeResolutionsSettings array + INT_INFO("[DsMgr] ========== Dumping kVidoeResolutionsSettings Array in getPixelResolution ==========\r\n"); + INT_INFO("[DsMgr] Total resolutions retrieved: %d\r\n", iCount); + for (int k = 0; k < iCount; k++) { + dsVideoPortResolution_t *res = &kVidoeResolutionsSettings[k]; + INT_INFO("[DsMgr] [%d] name=%s, pixelRes=%d, aspectRatio=%d, stereoMode=%d, frameRate=%d, interlaced=%d\r\n", + k, res->name, res->pixelResolution, res->aspectRatio, + res->stereoScopicMode, res->frameRate, res->interlaced); + } + INT_INFO("[DsMgr] ========== End of kVidoeResolutionsSettings Dump ==========\r\n"); - for (unsigned int i = 0; i < dsUTL_DIM(kResolutions); i++) + dsVideoPortResolution_t *Resn = &kVidoeResolutionsSettings[0]; + + for (int i = 0; i < iCount; i++) { - Resn = &kResolutions[i]; + Resn = &kVidoeResolutionsSettings[i]; if (resolution.compare(Resn->name) == 0 ) { break; @@ -2251,17 +2291,21 @@ static dsError_t _dsVideoFormatUpdateRegisterCB (dsVideoFormatUpdateCB_t cbFun) return eRet; } +//This funcation does not have any caller. bool isComponentPortPresent() { bool componentPortPresent = false; - int numPorts,i; - - numPorts = dsUTL_DIM(kSupportedPortTypes); - for(i=0; i< numPorts; i++) - { - if (kSupportedPortTypes[i] == dsVIDEOPORT_TYPE_COMPONENT) + int numTypeConfigs = 0; + const dsVideoPortTypeConfig_t* typeConfigs = NULL; + + dsGetVideoPortTypeConfigs(&numTypeConfigs, &typeConfigs); + if (typeConfigs) { + for(int i=0; i< numTypeConfigs; i++) { - componentPortPresent = true;; + if (typeConfigs[i].typeId == dsVIDEOPORT_TYPE_COMPONENT) + { + componentPortPresent = true; + } } } INT_INFO(" componentPortPresent :%d\n",componentPortPresent); @@ -2385,14 +2429,29 @@ void _dsSyncHdmiStatus(const std::string& key, int val) { intptr_t dsGetDefaultPortHandle() { - int numPorts,i; + int numPorts = 0, i; intptr_t halhandle = 0; - numPorts = dsUTL_DIM(kSupportedPortTypes); + const dsVideoPortPortConfig_t *kVideoPortPorts = NULL; + + dsGetVideoPortPortConfigs(&numPorts, &kVideoPortPorts); + + // Print kVideoPortPorts array + INT_INFO("[DsMgr] ========== Dumping kVideoPortPorts Array in dsGetDefaultPortHandle ==========\r\n"); + INT_INFO("[DsMgr] Total ports retrieved: %d\r\n", numPorts); + for (int k = 0; k < numPorts; k++) { + const dsVideoPortPortConfig_t *port = &kVideoPortPorts[k]; + INT_INFO("[DsMgr] [%d] type=%d, index=%d, connectedAOP_type=%d, connectedAOP_index=%d, defaultResolution=%s\r\n", + k, port->id.type, port->id.index, + port->connectedAOP.type, port->connectedAOP.index, + port->defaultResolution ? port->defaultResolution : "NULL"); + } + INT_INFO("[DsMgr] ========== End of kVideoPortPorts Dump ==========\r\n"); + for(i=0; i< numPorts; i++) { - dsGetVideoPort(kPorts[i].id.type, kPorts[i].id.index, &halhandle); - if (dsVIDEOPORT_TYPE_HDMI == kPorts[i].id.type || - dsVIDEOPORT_TYPE_INTERNAL == kPorts[i].id.type) + dsGetVideoPort(kVideoPortPorts[i].id.type, kVideoPortPorts[i].id.index, &halhandle); + if (dsVIDEOPORT_TYPE_HDMI == kVideoPortPorts[i].id.type || + dsVIDEOPORT_TYPE_INTERNAL == kVideoPortPorts[i].id.type) { return halhandle; } diff --git a/rpc/srv/dsVideoPortConfig.c b/rpc/srv/dsVideoPortConfig.c new file mode 100644 index 00000000..8153fcf6 --- /dev/null +++ b/rpc/srv/dsVideoPortConfig.c @@ -0,0 +1,355 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ + +/** +* @defgroup devicesettings +* @{ +* @defgroup rpc +* @{ +**/ + +#include +#include +#include +#include "dsserverlogger.h" +#include "dsTypes.h" +#include "dsVideoPortSettings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct videoPortConfigs +{ + dsVideoPortTypeConfig_t *pKVideoPortConfigs; + int *pKVideoPortConfigs_size; + dsVideoPortPortConfig_t *pKVideoPortPorts; + int *pKVideoPortPorts_size; + dsVideoPortResolution_t *pKVideoPortResolutionsSettings; + int *pKResolutionsSettings_size; + int *pKDefaultResIndex; +}videoPortConfigs_t; + +static videoPortConfigs_t videoPortConfiguration; + +void videoPortDumpconfig(videoPortConfigs_t *config) +{ + if (NULL == 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 (( NULL != config->pKVideoPortConfigs ) && ( NULL != config->pKVideoPortPorts ) && ( nullptr != config->pKVideoPortResolutionsSettings )) + { + 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("pKVideoPortConfigs = %p", config->pKVideoPortConfigs); + INT_INFO("pKConfigSize pointer %p = %d", config->pKVideoPortConfigs_size, configSize); + INT_INFO("pKVideoPortPorts = %p", config->pKVideoPortPorts); + INT_INFO("pKPortSize pointer %p = %d", config->pKVideoPortPorts_size, portSize); + INT_INFO("pKResolutionsSettings = %p", config->pKVideoPortResolutionsSettings); + 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->pKVideoPortResolutionsSettings[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->pKVideoPortConfigs[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->pKVideoPortPorts[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"); +} + +static int allocateAndCopyVideoPortConfigs(const dsVideoPortTypeConfig_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s video port config numElements: %d\n", configType, numElements); + return -1; + } + + videoPortConfiguration.pKVideoPortConfigs = (dsVideoPortTypeConfig_t*)malloc(numElements * sizeof(dsVideoPortTypeConfig_t)); + if (videoPortConfiguration.pKVideoPortConfigs == NULL) { + INT_ERROR("Failed to allocate memory for %s video port configs\n", configType); + return -1; + } + + memcpy(videoPortConfiguration.pKVideoPortConfigs, source, numElements * sizeof(dsVideoPortTypeConfig_t)); + INT_INFO("Allocated and copied %d video port configs (%s)", numElements, configType); + return numElements; +} + +static int allocateAndCopyVideoPortPorts(const dsVideoPortPortConfig_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s video port port numElements: %d\n", configType, numElements); + return -1; + } + + videoPortConfiguration.pKVideoPortPorts = (dsVideoPortPortConfig_t*)malloc(numElements * sizeof(dsVideoPortPortConfig_t)); + if (videoPortConfiguration.pKVideoPortPorts == NULL) { + INT_ERROR("Failed to allocate memory for %s video port ports\n", configType); + return -1; + } + + memcpy(videoPortConfiguration.pKVideoPortPorts, source, numElements * sizeof(dsVideoPortPortConfig_t)); + INT_INFO("Allocated and copied %d video port ports (%s)", numElements, configType); + return numElements; +} + +static int allocateAndCopyVideoPortResolutions(const dsVideoPortResolution_t* source, int numElements, bool isDynamic) +{ + const char* configType = isDynamic ? "dynamic" : "static"; + + if (numElements <= 0) { + INT_ERROR("Invalid %s video port resolution numElements: %d\n", configType, numElements); + return -1; + } + + videoPortConfiguration.pKVideoPortResolutionsSettings = (dsVideoPortResolution_t*)malloc(numElements * sizeof(dsVideoPortResolution_t)); + if (videoPortConfiguration.pKVideoPortResolutionsSettings == NULL) { + INT_ERROR("Failed to allocate memory for %s video port resolutions\n", configType); + return -1; + } + + memcpy(videoPortConfiguration.pKVideoPortResolutionsSettings, source, numElements * sizeof(dsVideoPortResolution_t)); + INT_INFO("Allocated and copied %d video port resolutions (%s)", numElements, configType); + return numElements; +} + +void dsLoadVideoOutputPortConfig(const videoPortConfigs_t* dynamicVideoPortConfigs) +{ + int configSize = -1, portSize = -1, resolutionSize = -1, ret = -1; + + INT_INFO("Using '%s' config", dynamicVideoPortConfigs ? "dynamic" : "static"); + + if (NULL != dynamicVideoPortConfigs) + { + // Reading Video Port Type configs + configSize = (dynamicVideoPortConfigs->pKVideoPortConfigs_size) ? *(dynamicVideoPortConfigs->pKVideoPortConfigs_size) : -1; + ret = allocateAndCopyVideoPortConfigs(dynamicVideoPortConfigs->pKVideoPortConfigs, configSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + // Reading Video Port Port configs + portSize = (dynamicVideoPortConfigs->pKVideoPortPorts_size) ? *(dynamicVideoPortConfigs->pKVideoPortPorts_size) : -1; + ret = allocateAndCopyVideoPortPorts(dynamicVideoPortConfigs->pKVideoPortPorts, portSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + // Reading Video Port Resolutions + resolutionSize = (dynamicVideoPortConfigs->pKResolutionsSettings_size) ? *(dynamicVideoPortConfigs->pKResolutionsSettings_size) : -1; + ret = allocateAndCopyVideoPortResolutions(dynamicVideoPortConfigs->pKVideoPortResolutionsSettings, resolutionSize, true); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + // Reading Default Resolution Index + if (dynamicVideoPortConfigs->pKDefaultResIndex != NULL) { + INT_INFO("Store sizes configSize =%d, portSize =%d, resolutionSize = %d\n", configSize, portSize, resolutionSize); + videoPortConfiguration.pKDefaultResIndex = (int*)malloc(sizeof(int)); + if (videoPortConfiguration.pKDefaultResIndex == NULL) { + INT_ERROR("Failed to allocate memory for pKConfigSize\n"); + } + else + { + *(videoPortConfiguration.pKDefaultResIndex) = *(dynamicVideoPortConfigs->pKDefaultResIndex); + INT_INFO("Store sizes *(videoPortConfiguration.pKDefaultResIndex) =%d (dynamic)\n", *(videoPortConfiguration.pKDefaultResIndex)); + } + } else { + INT_INFO("Default pKDefaultResIndex not available in dynamic config"); + } + } + else { + // Using static configuration + configSize = dsUTL_DIM(kConfigs); + ret = allocateAndCopyVideoPortConfigs(kConfigs, configSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + portSize = dsUTL_DIM(kPorts); + ret = allocateAndCopyVideoPortPorts(kPorts, portSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + resolutionSize = dsUTL_DIM(kResolutions); + ret = allocateAndCopyVideoPortResolutions(kResolutions, resolutionSize, false); + if(ret == -1) + { + INT_ERROR("failed to create dynamic memory\n"); + } + + // Using static default resolution index + if (dynamicVideoPortConfigs->pKDefaultResIndex != NULL) { + INT_INFO("Store sizes configSize =%d, portSize =%d, resolutionSize = %d\n", configSize, portSize, resolutionSize); + videoPortConfiguration.pKDefaultResIndex = (int*)malloc(sizeof(int)); + if (videoPortConfiguration.pKDefaultResIndex == NULL) { + INT_ERROR("Failed to allocate memory for pKConfigSize\n"); + } + else + { + *(videoPortConfiguration.pKDefaultResIndex) = kDefaultResIndex; + INT_INFO("Store sizes *(videoPortConfiguration.pKDefaultResIndex) =%d (static)\n", *(videoPortConfiguration.pKDefaultResIndex)); + } + } + } + + INT_INFO("Store sizes configSize =%d, portSize =%d, resolutionSize = %d\n", configSize, portSize, resolutionSize); + videoPortConfiguration.pKVideoPortConfigs_size = (int*)malloc(sizeof(int)); + if (videoPortConfiguration.pKVideoPortConfigs_size == NULL) { + INT_ERROR("Failed to allocate memory for pKConfigSize\n"); + } + else + { + *(videoPortConfiguration.pKVideoPortConfigs_size) = configSize; + INT_INFO("Store sizes *(videoPortConfiguration.pKVideoPortConfigs_size) =%d\n", *(videoPortConfiguration.pKVideoPortConfigs_size)); + } + videoPortConfiguration.pKVideoPortPorts_size = (int*)malloc(sizeof(int)); + if (videoPortConfiguration.pKVideoPortPorts_size == NULL) { + INT_ERROR("Failed to allocate memory for pKPortSize\n"); + } + else + { + *(videoPortConfiguration.pKVideoPortPorts_size) = portSize; + INT_INFO("Store sizes *(videoPortConfiguration.pKVideoPortPorts_size) =%d\n", *(videoPortConfiguration.pKVideoPortPorts_size)); + } + videoPortConfiguration.pKResolutionsSettings_size = (int*)malloc(sizeof(int)); + if (videoPortConfiguration.pKResolutionsSettings_size == NULL) { + INT_ERROR("Failed to allocate memory for pKPortSize\n"); + } + else + { + *(videoPortConfiguration.pKResolutionsSettings_size) = resolutionSize; + INT_INFO("Store sizes *(videoPortConfiguration.pKResolutionsSettings_size) =%d\n", *(videoPortConfiguration.pKResolutionsSettings_size)); + } + + INT_INFO("VideoPort Config[%p] ConfigSize[%d] Ports[%p] PortSize[%d] Resolutions[%p] ResolutionSize[%d] DefaultResIndex[%d]", + videoPortConfiguration.pKVideoPortConfigs, + *(videoPortConfiguration.pKVideoPortConfigs_size), + videoPortConfiguration.pKVideoPortPorts, + *(videoPortConfiguration.pKVideoPortPorts_size), + videoPortConfiguration.pKVideoPortResolutionsSettings, + *(videoPortConfiguration.pKResolutionsSettings_size), + *(videoPortConfiguration.pKDefaultResIndex)); + videoPortDumpconfig(&videoPortConfiguration); +} + +// Getter functions for use across srv code +void dsGetVideoPortTypeConfigs(int* outConfigSize, const dsVideoPortTypeConfig_t** outConfigs) +{ + if (outConfigSize != NULL) { + *outConfigSize = *(videoPortConfiguration.pKVideoPortConfigs_size); + } + if (outConfigs != NULL) { + *outConfigs = videoPortConfiguration.pKVideoPortConfigs; + } +} + +void dsGetVideoPortPortConfigs(int* outPortSize, const dsVideoPortPortConfig_t** outPorts) +{ + if (outPortSize != NULL) { + *outPortSize = *(videoPortConfiguration.pKVideoPortPorts_size); + } + if (outPorts != NULL) { + *outPorts = videoPortConfiguration.pKVideoPortPorts; + } +} + +void dsGetVideoPortResolutions(int* outResolutionSize, dsVideoPortResolution_t** outResolutions) +{ + if (outResolutionSize != NULL) { + *outResolutionSize = *(videoPortConfiguration.pKResolutionsSettings_size); + } + if (outResolutions != NULL) { + *outResolutions = videoPortConfiguration.pKVideoPortResolutionsSettings; + } +} + +void dsGetDefaultResolutionIndex(int* outDefaultIndex) +{ + if (outDefaultIndex != NULL) { + *outDefaultIndex = *(videoPortConfiguration.pKDefaultResIndex); + } +} + +#ifdef __cplusplus +} +#endif + +/** @} */ +/** @} */