diff --git a/.github/workflows/L1-tests.yml b/.github/workflows/L1-tests.yml index 3d261109..9d741808 100755 --- a/.github/workflows/L1-tests.yml +++ b/.github/workflows/L1-tests.yml @@ -2,9 +2,9 @@ name: L1-tests on: push: - branches: [ main, develop, 'sprint/**', 'release/**' ] + branches: [ main, develop, 'sprint/**', 'release/**', 'topic/RDK*' ] pull_request: - branches: [ main, develop, 'sprint/**', 'release/**' ] + branches: [ main, develop, 'sprint/**', 'release/**', 'topic/RDK*' ] env: BUILD_TYPE: Debug @@ -208,6 +208,7 @@ jobs: headers/rdk/halif/ headers/rdk/halif/deepsleep-manager headers/ccec/drivers + headers/ccec/host headers/network headers/proc && @@ -216,6 +217,15 @@ jobs: touch audiocapturemgr/audiocapturemgr_iarm.h ccec/drivers/CecIARMBusMgr.h + ccec/FrameListener.hpp + ccec/Connection.hpp + ccec/Assert.hpp + ccec/Messages.hpp + ccec/MessageDecoder.hpp + ccec/MessageProcessor.hpp + ccec/CECFrame.hpp + ccec/MessageEncoder.hpp + ccec/host/RDK.hpp rdk/ds/audioOutputPort.hpp rdk/ds/compositeIn.hpp rdk/ds/dsDisplay.h @@ -249,6 +259,7 @@ jobs: libudev.h rfcapi.h rbus.h + dsRpc.h motionDetector.h telemetry_busmessage_sender.h maintenanceMGR.h @@ -270,6 +281,68 @@ jobs: if: ${{ matrix.compiler == 'gcc' && matrix.coverage == 'with-coverage' && !env.ACT }} run: echo "TOOLCHAIN_FILE=$GITHUB_WORKSPACE/entservices-testframework/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV + - name: Build mocks + run: > + cmake + -S "$GITHUB_WORKSPACE/entservices-testframework/Tests/mocks" + -B build/mocks + -DBUILD_SHARED_LIBS=ON + -DRDK_SERVICES_L1_TEST=ON + -DUSE_THUNDER_R4=ON + -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" + -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + -DCMAKE_CXX_FLAGS=" + -fprofile-arcs + -ftest-coverage + -DEXCEPTIONS_ENABLE=ON + -DUSE_THUNDER_R4=ON + -DTHUNDER_VERSION=4 + -DTHUNDER_VERSION_MAJOR=4 + -DTHUNDER_VERSION_MINOR=4 + -DRDK_SERVICES_L1_TEST + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/audiocapturemgr + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/ds + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmbus + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmmgrs-hal + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/ccec/drivers + -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/network + -I $GITHUB_WORKSPACE/entservices-testframework/Tests + -I $GITHUB_WORKSPACE/Thunder/Source + -I $GITHUB_WORKSPACE/Thunder/Source/core + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/devicesettings.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Iarm.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Rfc.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/RBus.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Telemetry.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Udev.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/maintenanceMGR.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/pkg.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/secure_wrappermock.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/wpa_ctrl_mock.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/readprocMockInterface.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/gdialservice.h + --coverage + -Wall -Wno-unused-result -Wno-deprecated-declarations -Wno-error=format= + -Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog -Wl,-wrap,v_secure_system -Wl,-wrap,v_secure_popen -Wl,-wrap,v_secure_pclose -Wl,-wrap,unlink -Wl,-wrap,v_secure_system -Wl,-wrap,pclose -Wl,-wrap,setmntent -Wl,-wrap,getmntent + -DENABLE_TELEMETRY_LOGGING + -DUSE_IARMBUS + -DENABLE_SYSTEM_GET_STORE_DEMO_LINK + -DENABLE_DEEP_SLEEP + -DENABLE_SET_WAKEUP_SRC_CONFIG + -DENABLE_THERMAL_PROTECTION + -DUSE_DRM_SCREENCAPTURE + -DHAS_API_SYSTEM + -DHAS_API_POWERSTATE + -DHAS_RBUS + -DENABLE_DEVICE_MANUFACTURER_INFO" + && + cmake --build build/mocks -j8 + && + cmake --install build/mocks + - name: Build entservices-inputoutput run: > cmake -G Ninja @@ -308,6 +381,7 @@ jobs: -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/wpa_ctrl_mock.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/readprocMockInterface.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/gdialservice.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/HdmiCec.h --coverage -Wall -Wno-unused-result -Wno-deprecated-declarations -Wno-error=format= -Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog -Wl,-wrap,v_secure_system -Wl,-wrap,v_secure_popen -Wl,-wrap,v_secure_pclose -Wl,-wrap,unlink @@ -328,11 +402,14 @@ jobs: -DCMAKE_DISABLE_FIND_PACKAGE_Udev=ON -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON -DCMAKE_DISABLE_FIND_PACKAGE_RBus=ON + -DCMAKE_DISABLE_FIND_PACKAGE_CEC=ON -DCMAKE_BUILD_TYPE=Debug -DDS_FOUND=ON -DHAS_FRONT_PANEL=ON -DRDK_SERVICES_L1_TEST=ON - -DPLUGIN_HDCPPROFILE=OFF + -DPLUGIN_HDCPPROFILE=ON + -DPLUGIN_HDMICECSOURCE=ON + -DPLUGIN_HDMICECSINK=ON -DUSE_THUNDER_R4=ON -DHIDE_NON_EXTERNAL_SYMBOLS=OFF && @@ -379,6 +456,7 @@ jobs: -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/wpa_ctrl_mock.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/readprocMockInterface.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/gdialservice.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/HdmiCec.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/thunder/Communicator.h --coverage -Wall -Wno-unused-result -Wno-deprecated-declarations -Wno-error=format= @@ -400,9 +478,12 @@ jobs: -DCMAKE_DISABLE_FIND_PACKAGE_Udev=ON -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON -DCMAKE_DISABLE_FIND_PACKAGE_RBus=ON + -DCMAKE_DISABLE_FIND_PACKAGE_CEC=ON -DCMAKE_BUILD_TYPE=Debug -DDS_FOUND=ON - -DPLUGIN_HDCPPROFILE=OFF + -DPLUGIN_HDCPPROFILE=ON + -DPLUGIN_HDMICECSOURCE=ON + -DPLUGIN_HDMICECSINK=ON -DRDK_SERVICES_L1_TEST=ON -DUSE_THUNDER_R4=ON -DHIDE_NON_EXTERNAL_SYMBOLS=OFF @@ -522,40 +603,39 @@ jobs: cp -rf $(pwd)/rdkL1TestResults.json $GITHUB_WORKSPACE/rdkL1TestResultsWithValgrind.json && rm -rf $(pwd)/rdkL1TestResults.json - # - name: Generate coverage - # if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} - # run: > - # cp $GITHUB_WORKSPACE/entservices-testframework/Tests/L1Tests/.lcovrc_l1 ~/.lcovrc - # && - # lcov -c - # -o coverage.info - # -d build/entservices-inputoutput - # && - # lcov - # -r coverage.info - # '/usr/include/*' - # '*/build/entservices-inputoutput/_deps/*' - # '*/install/usr/include/*' - # '*/Tests/headers/*' - # '*/Tests/mocks/*' - # '*/Tests/L1Tests/tests/*' - # '*/Thunder/*' - # -o filtered_coverage.info - # && - # genhtml - # -o coverage - # -t "entservices-inputoutput coverage" - # filtered_coverage.info - - # - name: Upload artifacts - # if: ${{ !env.ACT }} - # uses: actions/upload-artifact@v4 - # with: - # name: artifacts - # path: | - # coverage/ - # valgrind_log - # rdkL1TestResultsWithoutValgrind.json - # rdkL1TestResultsWithValgrind.json - # if-no-files-found: warn + - name: Generate coverage + if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} + run: > + cp $GITHUB_WORKSPACE/entservices-testframework/Tests/L1Tests/.lcovrc_l1 ~/.lcovrc + && + lcov -c + -o coverage.info + -d build/entservices-inputoutput + && + lcov + -r coverage.info + '/usr/include/*' + '*/build/entservices-inputoutput/_deps/*' + '*/install/usr/include/*' + '*/Tests/headers/*' + '*/Tests/mocks/*' + '*/Tests/L1Tests/tests/*' + '*/Thunder/*' + -o filtered_coverage.info + && + genhtml + -o coverage + -t "entservices-inputoutput coverage" + filtered_coverage.info + - name: Upload artifacts + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v4 + with: + name: artifacts + path: | + coverage/ + valgrind_log + rdkL1TestResultsWithoutValgrind.json + rdkL1TestResultsWithValgrind.json + if-no-files-found: warn diff --git a/.github/workflows/L2-tests.yml b/.github/workflows/L2-tests.yml index 8241453d..11cb4f3b 100755 --- a/.github/workflows/L2-tests.yml +++ b/.github/workflows/L2-tests.yml @@ -1,10 +1,8 @@ name: L2-tests +#enable the workflow incase of any plugin/testcase changes on: - push: - branches: [ main, develop, 'sprint/**', 'release/**' ] - pull_request: - branches: [ main, develop, 'sprint/**', 'release/**' ] + workflow_dispatch: env: BUILD_TYPE: Debug diff --git a/AVOutput/AVOutputTV.cpp b/AVOutput/AVOutputTV.cpp index e9bd4fb8..e95b81e7 100644 --- a/AVOutput/AVOutputTV.cpp +++ b/AVOutput/AVOutputTV.cpp @@ -270,73 +270,93 @@ namespace Plugin { LOGINFO("CTOR\n"); AVOutputTV::instance = this; - InitializeIARM(); - - registerMethod("getBacklight", &AVOutputTV::getBacklight, this); - registerMethod("setBacklight", &AVOutputTV::setBacklight, this); - registerMethod("resetBacklight", &AVOutputTV::resetBacklight, this); - registerMethod("getBacklightCaps", &AVOutputTV::getBacklightCaps, this); - registerMethod("getBrightnessCaps", &AVOutputTV::getBrightnessCaps, this); - registerMethod("getBrightness", &AVOutputTV::getBrightness, this); - registerMethod("setBrightness", &AVOutputTV::setBrightness, this); - registerMethod("resetBrightness", &AVOutputTV::resetBrightness, this); - registerMethod("getContrast", &AVOutputTV::getContrast, this); - registerMethod("setContrast", &AVOutputTV::setContrast, this); - registerMethod("resetContrast", &AVOutputTV::resetContrast, this); - registerMethod("getContrastCaps", &AVOutputTV::getContrastCaps, this); - registerMethod("getSharpness", &AVOutputTV::getSharpness, this); - registerMethod("setSharpness", &AVOutputTV::setSharpness, this); - registerMethod("resetSharpness", &AVOutputTV::resetSharpness, this); - registerMethod("getSharpnessCaps", &AVOutputTV::getSharpnessCaps, this); - registerMethod("getSaturation", &AVOutputTV::getSaturation, this); - registerMethod("setSaturation", &AVOutputTV::setSaturation, this); - registerMethod("resetSaturation", &AVOutputTV::resetSaturation, this); - registerMethod("getSaturationCaps", &AVOutputTV::getSaturationCaps, this); - registerMethod("getHue", &AVOutputTV::getHue, this); - registerMethod("setHue", &AVOutputTV::setHue, this); - registerMethod("resetHue", &AVOutputTV::resetHue, this); - registerMethod("getHueCaps", &AVOutputTV::getHueCaps, this); - registerMethod("getColorTemperature", &AVOutputTV::getColorTemperature, this); - registerMethod("setColorTemperature", &AVOutputTV::setColorTemperature, this); - registerMethod("resetColorTemperature", &AVOutputTV::resetColorTemperature, this); - registerMethod("getColorTemperatureCaps", &AVOutputTV::getColorTemperatureCaps, this); - - registerMethod("getBacklightDimmingMode", &AVOutputTV::getBacklightDimmingMode, this); - registerMethod("setBacklightDimmingMode", &AVOutputTV::setBacklightDimmingMode, this); - registerMethod("resetBacklightDimmingMode", &AVOutputTV::resetBacklightDimmingMode, this); - registerMethod("getBacklightDimmingModeCaps", &AVOutputTV::getBacklightDimmingModeCaps, this); - - registerMethod("getSupportedDolbyVisionModes", &AVOutputTV::getSupportedDolbyVisionModes, this); - registerMethod("getDolbyVisionMode", &AVOutputTV::getDolbyVisionMode, this); - registerMethod("setDolbyVisionMode", &AVOutputTV::setDolbyVisionMode, this); - registerMethod("resetDolbyVisionMode", &AVOutputTV::resetDolbyVisionMode, this); - registerMethod("getDolbyVisionModeCaps", &AVOutputTV::getDolbyVisionModeCaps, this); - registerMethod("getVideoFormat", &AVOutputTV::getVideoFormat, this); - registerMethod("getVideoSource", &AVOutputTV::getVideoSource, this); - registerMethod("getVideoFrameRate", &AVOutputTV::getVideoFrameRate, this); - registerMethod("getVideoResolution", &AVOutputTV::getVideoResolution, this); - registerMethod("getVideoContentType", &AVOutputTV::getVideoContentType, this); - - registerMethod("getZoomMode", &AVOutputTV::getZoomMode, this); - registerMethod("setZoomMode", &AVOutputTV::setZoomMode, this); - registerMethod("resetZoomMode", &AVOutputTV::resetZoomMode, this); - registerMethod("getZoomModeCaps", &AVOutputTV::getZoomModeCaps, this); - - registerMethod("getPictureMode", &AVOutputTV::getPictureMode, this); - registerMethod("setPictureMode", &AVOutputTV::setPictureMode, this); - registerMethod("signalFilmMakerMode", &AVOutputTV::signalFilmMakerMode, this); - registerMethod("resetPictureMode", &AVOutputTV::resetPictureMode, this); - registerMethod("getPictureModeCaps", &AVOutputTV::getPictureModeCaps, this); - registerMethod("getSupportedPictureModes", &AVOutputTV::getSupportedPictureModes, this); - registerMethod("getVideoSourceCaps", &AVOutputTV::getVideoSourceCaps, this); - registerMethod("getVideoFormatCaps", &AVOutputTV::getVideoFormatCaps, this); - registerMethod("getVideoFrameRateCaps", &AVOutputTV::getVideoFrameRateCaps, this); - registerMethod("getVideoResolutionCaps", &AVOutputTV::getVideoResolutionCaps, this); - - registerMethod("getLowLatencyState", &AVOutputTV::getLowLatencyState, this); - registerMethod("setLowLatencyState", &AVOutputTV::setLowLatencyState, this); - registerMethod("resetLowLatencyState", &AVOutputTV::resetLowLatencyState, this); - registerMethod("getLowLatencyStateCaps", &AVOutputTV::getLowLatencyStateCaps, this); + InitializeIARM(); + + registerMethod("getBacklight", &AVOutputTV::getBacklight, this); + registerMethod("setBacklight", &AVOutputTV::setBacklight, this); + registerMethod("resetBacklight", &AVOutputTV::resetBacklight, this); + registerMethod("getBacklightCaps", &AVOutputTV::getBacklightCaps, this); + registerMethod("getBrightnessCaps", &AVOutputTV::getBrightnessCaps, this); + registerMethod("getBrightness", &AVOutputTV::getBrightness, this); + registerMethod("setBrightness", &AVOutputTV::setBrightness, this); + registerMethod("resetBrightness", &AVOutputTV::resetBrightness, this); + registerMethod("getContrast", &AVOutputTV::getContrast, this); + registerMethod("setContrast", &AVOutputTV::setContrast, this); + registerMethod("resetContrast", &AVOutputTV::resetContrast, this); + registerMethod("getContrastCaps", &AVOutputTV::getContrastCaps, this); + registerMethod("getSharpness", &AVOutputTV::getSharpness, this); + registerMethod("setSharpness", &AVOutputTV::setSharpness, this); + registerMethod("resetSharpness", &AVOutputTV::resetSharpness, this); + registerMethod("getSharpnessCaps", &AVOutputTV::getSharpnessCaps, this); + registerMethod("getSaturation", &AVOutputTV::getSaturation, this); + registerMethod("setSaturation", &AVOutputTV::setSaturation, this); + registerMethod("resetSaturation", &AVOutputTV::resetSaturation, this); + registerMethod("getSaturationCaps", &AVOutputTV::getSaturationCaps, this); + registerMethod("getHue", &AVOutputTV::getHue, this); + registerMethod("setHue", &AVOutputTV::setHue, this); + registerMethod("resetHue", &AVOutputTV::resetHue, this); + registerMethod("getHueCaps", &AVOutputTV::getHueCaps, this); + registerMethod("getColorTemperature", &AVOutputTV::getColorTemperature, this); + registerMethod("setColorTemperature", &AVOutputTV::setColorTemperature, this); + registerMethod("resetColorTemperature", &AVOutputTV::resetColorTemperature, this); + registerMethod("getColorTemperatureCaps", &AVOutputTV::getColorTemperatureCaps, this); + + registerMethod("getBacklightDimmingMode", &AVOutputTV::getBacklightDimmingMode, this); + registerMethod("setBacklightDimmingMode", &AVOutputTV::setBacklightDimmingMode, this); + registerMethod("resetBacklightDimmingMode", &AVOutputTV::resetBacklightDimmingMode, this); + registerMethod("getBacklightDimmingModeCaps", &AVOutputTV::getBacklightDimmingModeCaps, this); + + registerMethod("getSupportedDolbyVisionModes", &AVOutputTV::getSupportedDolbyVisionModes, this); + registerMethod("getDolbyVisionMode", &AVOutputTV::getDolbyVisionMode, this); + registerMethod("setDolbyVisionMode", &AVOutputTV::setDolbyVisionMode, this); + registerMethod("resetDolbyVisionMode", &AVOutputTV::resetDolbyVisionMode, this); + registerMethod("getDolbyVisionModeCaps", &AVOutputTV::getDolbyVisionModeCaps, this); + registerMethod("getVideoFormat", &AVOutputTV::getVideoFormat, this); + registerMethod("getVideoSource", &AVOutputTV::getVideoSource, this); + registerMethod("getVideoFrameRate", &AVOutputTV::getVideoFrameRate, this); + registerMethod("getVideoResolution", &AVOutputTV::getVideoResolution, this); + registerMethod("getVideoContentType", &AVOutputTV::getVideoContentType, this); + + registerMethod("getZoomMode", &AVOutputTV::getZoomMode, this); + registerMethod("setZoomMode", &AVOutputTV::setZoomMode, this); + registerMethod("resetZoomMode", &AVOutputTV::resetZoomMode, this); + registerMethod("getZoomModeCaps", &AVOutputTV::getZoomModeCaps, this); + + registerMethod("getPictureMode", &AVOutputTV::getPictureMode, this); + registerMethod("setPictureMode", &AVOutputTV::setPictureMode, this); + registerMethod("signalFilmMakerMode", &AVOutputTV::signalFilmMakerMode, this); + registerMethod("resetPictureMode", &AVOutputTV::resetPictureMode, this); + registerMethod("getPictureModeCaps", &AVOutputTV::getPictureModeCaps, this); + registerMethod("getSupportedPictureModes", &AVOutputTV::getSupportedPictureModes, this); + registerMethod("getVideoSourceCaps", &AVOutputTV::getVideoSourceCaps, this); + registerMethod("getVideoFormatCaps", &AVOutputTV::getVideoFormatCaps, this); + registerMethod("getVideoFrameRateCaps", &AVOutputTV::getVideoFrameRateCaps, this); + registerMethod("getVideoResolutionCaps", &AVOutputTV::getVideoResolutionCaps, this); + + registerMethod("getLowLatencyState", &AVOutputTV::getLowLatencyState, this); + registerMethod("setLowLatencyState", &AVOutputTV::setLowLatencyState, this); + registerMethod("resetLowLatencyState", &AVOutputTV::resetLowLatencyState, this); + registerMethod("getLowLatencyStateCaps", &AVOutputTV::getLowLatencyStateCaps, this); + + registerMethod("getCMS", &AVOutputTV::getCMS, this); + registerMethod("setCMS", &AVOutputTV::setCMS, this); + registerMethod("resetCMS", &AVOutputTV::resetCMS, this); + registerMethod("getCMSCaps", &AVOutputTV::getCMSCaps, this); + + registerMethod("get2PointWB", &AVOutputTV::get2PointWB, this); + registerMethod("set2PointWB", &AVOutputTV::set2PointWB, this); + registerMethod("reset2PointWB", &AVOutputTV::reset2PointWB, this); + registerMethod("get2PointWBCaps", &AVOutputTV::get2PointWBCaps, this); + + registerMethod("getHDRMode", &AVOutputTV::getHDRMode, this); + registerMethod("setHDRMode", &AVOutputTV::setHDRMode, this); + registerMethod("resetHDRMode", &AVOutputTV::resetHDRMode, this); + registerMethod("getHDRModeCaps", &AVOutputTV::getHDRModeCaps, this); + + registerMethod("getAutoBacklightMode", &AVOutputTV::getAutoBacklightMode, this); + registerMethod("setAutoBacklightMode", &AVOutputTV::setAutoBacklightMode, this); + registerMethod("resetAutoBacklightMode", &AVOutputTV::resetAutoBacklightMode, this); + registerMethod("getAutoBacklightModeCaps", &AVOutputTV::getAutoBacklightModeCaps, this); LOGINFO("Exit\n"); } @@ -403,8 +423,8 @@ namespace Plugin { locatePQSettingsFile(); - // Get Index from PQ capabailites - if (getPqParamIndex() != 0) { + // Get Index from PQ capabailites + if (getPqParamIndex() != 0) { LOGWARN("Failed to get the supported index from capability \n"); } @@ -442,10 +462,7 @@ namespace Plugin { uint32_t AVOutputTV::getZoomModeCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -454,33 +471,33 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"AspectRatio"); + tvError_t ret = getParamsCaps("AspectRatio",info); if(ret != tvERROR_NONE) { returnResponse(false); } - else { - for (index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); - } + else { + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); + } response["options"]=rangeArray; - if (pqmode.front().compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if (info.pqmodeVector.front().compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -494,9 +511,7 @@ namespace Plugin { LOGINFO("Entry\n"); std::string value; tvDisplayMode_t mode = tvDisplayMode_16x9; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; value = parameters.HasLabel("zoomMode") ? parameters["zoomMode"].String() : ""; @@ -507,12 +522,12 @@ namespace Plugin { returnResponse(false); } - if (parsingSetInputArgument(parameters, "AspectRatio",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters,"AspectRatio",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "AspectRatio" )) { + if( !isCapablityCheckPassed( "AspectRatio",inputInfo )) { LOGERR("%s: CapablityCheck failed for AspectRatio\n", __FUNCTION__); returnResponse(false); } @@ -546,19 +561,17 @@ namespace Plugin { } else { //Save DisplayMode to localstore and ssm_data - int params[3]={0}; - params[0]=mode; - int retval=updateAVoutputTVParam("set","AspectRatio",pqmode,source,format,PQ_PARAM_ASPECT_RATIO,params); + int retval=updateAVoutputTVParam("set","AspectRatio",inputInfo,PQ_PARAM_ASPECT_RATIO,mode); if(retval != 0) { LOGERR("Failed to Save DisplayMode to ssm_data\n"); - returnResponse(false); + returnResponse(false); } tr181ErrorCode_t err = setLocalParam(rfc_caller_id, AVOUTPUT_ASPECTRATIO_RFC_PARAM, value.c_str()); if ( err != tr181Success ) { LOGERR("setLocalParam for %s Failed : %s\n", AVOUTPUT_ASPECTRATIO_RFC_PARAM, getTR181ErrorString(err)); - returnResponse(false); + returnResponse(false); } else { LOGINFO("setLocalParam for %s Successful, Value: %s\n", AVOUTPUT_ASPECTRATIO_RFC_PARAM, value.c_str()); @@ -623,17 +636,15 @@ namespace Plugin { uint32_t AVOutputTV::resetZoomMode(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry\n"); - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "AspectRatio",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "AspectRatio",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "AspectRatio" )) { + if( !isCapablityCheckPassed( "AspectRatio",inputInfo )) { LOGERR("%s: CapablityCheck failed for AspectRatio\n", __FUNCTION__); returnResponse(false); } @@ -644,9 +655,9 @@ namespace Plugin { ret = tvERROR_GENERAL; } else { - ret = setDefaultAspectRatio(pqmode,source,format); + ret = setDefaultAspectRatio(inputInfo.pqmode,inputInfo.source,inputInfo.format); } - if(ret != tvERROR_NONE) { + if(ret != tvERROR_NONE) { returnResponse(false); } else { @@ -707,29 +718,26 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; std::string key; - - int sourceIndex=0,pqIndex=0,formatIndex=0; + paramIndex_t indexInfo; int backlight = 0,err = 0; - if (parsingGetInputArgument(parameters, "Backlight",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Backlight",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } if (isPlatformSupport("Backlight") != 0) { - returnResponse(false); - } + returnResponse(false); + } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Backlight", inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - err = getLocalparam("Backlight",formatIndex,pqIndex,sourceIndex,backlight, PQ_PARAM_BACKLIGHT); + err = getLocalparam("Backlight",indexInfo,backlight, PQ_PARAM_BACKLIGHT); if( err == 0 ) { response["backlight"] = backlight; LOGINFO("Exit : Backlight Value: %d \n", backlight); @@ -745,9 +753,7 @@ namespace Plugin { LOGINFO("Entry\n"); std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int backlight = 0; tvError_t ret = tvERROR_NONE; @@ -760,21 +766,21 @@ namespace Plugin { returnResponse(false); } - if (parsingSetInputArgument(parameters, "Backlight",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters,"Backlight",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } if (isPlatformSupport("Backlight") != 0 ) { - returnResponse(false); - } + returnResponse(false); + } - if( !isCapablityCheckPassed( pqmode, source, format, "Backlight" )) { + if( !isCapablityCheckPassed( "Backlight" , inputInfo )) { LOGERR("%s: CapablityCheck failed for Backlight\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with setBacklight\n"); ret = SetBacklight(backlight); } @@ -784,9 +790,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=backlight; - int retval= updateAVoutputTVParam("set","Backlight",pqmode,source,format,PQ_PARAM_BACKLIGHT,params); + int retval= updateAVoutputTVParam("set","Backlight",inputInfo,PQ_PARAM_BACKLIGHT,backlight); if(retval != 0 ) { LOGERR("Failed to Save Backlight to ssm_data\n"); returnResponse(false); @@ -800,39 +804,39 @@ namespace Plugin { uint32_t AVOutputTV::resetBacklight(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,backlight=0; - int params[3]={0}; + capDetails_t inputInfo; + int backlight=0; + paramIndex_t indexInfo; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Backlight",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Backlight",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } if (isPlatformSupport("Backlight") != 0) { - returnResponse(false); - } + returnResponse(false); + } - if( !isCapablityCheckPassed( pqmode, source, format, "Backlight" )) { + if( !isCapablityCheckPassed( "Backlight",inputInfo )) { LOGERR("%s: CapablityCheck failed for Backlight\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Backlight",pqmode,source,format,PQ_PARAM_BACKLIGHT,params); + int retval= updateAVoutputTVParam("reset","Backlight",inputInfo,PQ_PARAM_BACKLIGHT,backlight); if(retval != 0 ) { LOGERR("Failed to reset Backlight\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Backlight",formatIndex,pqIndex,sourceIndex,backlight, PQ_PARAM_BACKLIGHT); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Backlight", inputInfo,indexInfo); + int err = getLocalparam("Backlight",indexInfo,backlight, PQ_PARAM_BACKLIGHT); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,backlight); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,backlight); ret = SetBacklight(backlight); } else { @@ -854,14 +858,7 @@ namespace Plugin { uint32_t AVOutputTV::getBacklightCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; - - std::string isPlatformSupport; - std::vector indexInfo; - + capVectors_t vectorInfo; JsonObject rangeObj; JsonArray pqmodeArray; JsonArray formatArray; @@ -869,33 +866,33 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Backlight", isPlatformSupport, indexInfo); + tvError_t ret = getParamsCaps("Backlight", vectorInfo ); if(ret != tvERROR_NONE) { returnResponse(false); } else { - response["platformSupport"] = (isPlatformSupport.compare("true") == 0) ? true : false; + response["platformSupport"] = (vectorInfo.isPlatformSupportVector[0].compare("true") == 0) ? true : false; - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = std::stoi(vectorInfo.rangeVector[0]); + rangeObj["to"] = std::stoi(vectorInfo.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((vectorInfo.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < vectorInfo.pqmodeVector.size(); index++) { + pqmodeArray.Add(vectorInfo.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((vectorInfo.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < vectorInfo.sourceVector.size(); index++) { + sourceArray.Add(vectorInfo.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((vectorInfo.formatVector.front()).compare("none") != 0) { + for (index = 0; index < vectorInfo.formatVector.size(); index++) { + formatArray.Add(vectorInfo.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -908,24 +905,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int brightness = 0; - if (parsingGetInputArgument(parameters, "Brightness",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Brightness",inputInfo) != 0) { LOGERR("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Brightness", inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("Brightness",formatIndex,pqIndex,sourceIndex,brightness, PQ_PARAM_BRIGHTNESS); + int err = getLocalparam("Brightness",indexInfo,brightness, PQ_PARAM_BRIGHTNESS); if( err == 0 ) { response["brightness"] = brightness; LOGINFO("Exit : Brightness Value: %d \n", brightness); @@ -941,9 +935,7 @@ namespace Plugin { LOGINFO("Entry\n"); std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int brightness = 0; tvError_t ret = tvERROR_NONE; @@ -956,17 +948,17 @@ namespace Plugin { returnResponse(false); } - if (parsingSetInputArgument(parameters, "Brightness",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Brightness",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Brightness" )) { + if( !isCapablityCheckPassed( "Brightness",inputInfo )) { LOGERR("%s: CapablityCheck failed for Brightness\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s \n",__FUNCTION__); ret = SetBrightness(brightness); } @@ -976,9 +968,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=brightness; - int retval= updateAVoutputTVParam("set","Brightness",pqmode,source,format,PQ_PARAM_BRIGHTNESS,params); + int retval= updateAVoutputTVParam("set","Brightness",inputInfo,PQ_PARAM_BRIGHTNESS,brightness); if(retval != 0 ) { LOGERR("Failed to Save Brightness to ssm_data\n"); returnResponse(false); @@ -996,34 +986,35 @@ namespace Plugin { LOGINFO("Entry\n"); std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,brightness=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int brightness=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Brightness",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Brightness",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Brightness" )) { + if( !isCapablityCheckPassed( "Brightness",inputInfo )) { LOGERR("%s: CapablityCheck failed for Brightness\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Brightness",pqmode,source,format,PQ_PARAM_BRIGHTNESS,params); + int retval= updateAVoutputTVParam("reset","Brightness",inputInfo,PQ_PARAM_BRIGHTNESS,brightness); if(retval != 0 ) { LOGWARN("Failed to reset Brightness\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Brightness",formatIndex,pqIndex,sourceIndex,brightness, PQ_PARAM_BRIGHTNESS); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Brightness", inputInfo,indexInfo); + int err = getLocalparam("Brightness",indexInfo,brightness, PQ_PARAM_BRIGHTNESS); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,brightness); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,brightness); ret = SetBrightness(brightness); } else { @@ -1046,10 +1037,7 @@ namespace Plugin { uint32_t AVOutputTV::getBrightnessCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray pqmodeArray; JsonArray formatArray; @@ -1058,31 +1046,31 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Brightness"); + tvError_t ret = getParamsCaps("Brightness",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = stoi(info.rangeVector[0]); + rangeObj["to"] = stoi(info.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -1095,24 +1083,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int contrast = 0; - if (parsingGetInputArgument(parameters, "Contrast",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Contrast",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Contrast",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("Contrast",formatIndex,pqIndex,sourceIndex,contrast, PQ_PARAM_CONTRAST); + int err = getLocalparam("Contrast",indexInfo,contrast, PQ_PARAM_CONTRAST); if( err == 0 ) { response["contrast"] = contrast; LOGINFO("Exit : Contrast Value: %d \n", contrast); @@ -1127,33 +1112,31 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int contrast = 0; tvError_t ret = tvERROR_NONE; + std::string value; value = parameters.HasLabel("contrast") ? parameters["contrast"].String() : ""; returnIfParamNotFound(parameters,"contrast"); - contrast = stoi(value); + contrast = std::stoi(value); if (validateIntegerInputParameter("Contrast", contrast) != 0) { LOGERR("Failed in contrast range validation:%s", __FUNCTION__); returnResponse(false); } - if (parsingSetInputArgument(parameters, "Contrast",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Contrast",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Contrast" )) { + if( !isCapablityCheckPassed( "Contrast" , inputInfo )) { LOGERR("%s: CapablityCheck failed for Contrast\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s \n",__FUNCTION__); ret = SetContrast(contrast); } @@ -1163,9 +1146,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=contrast; - int retval= updateAVoutputTVParam("set","Contrast",pqmode,source,format,PQ_PARAM_CONTRAST,params); + int retval= updateAVoutputTVParam("set","Contrast",inputInfo,PQ_PARAM_CONTRAST,contrast); if(retval != 0 ) { LOGERR("Failed to Save Contrast to ssm_data\n"); returnResponse(false); @@ -1181,36 +1162,36 @@ namespace Plugin { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,contrast=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int contrast=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Contrast",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Contrast",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Contrast" )) { + if( !isCapablityCheckPassed( "Contrast" , inputInfo )) { LOGERR("%s: CapablityCheck failed for Contrast\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Contrast",pqmode,source,format,PQ_PARAM_CONTRAST,params); + int retval= updateAVoutputTVParam("reset","Contrast",inputInfo,PQ_PARAM_CONTRAST,contrast); if(retval != 0 ) { LOGWARN("Failed to reset Contrast\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Contrast",formatIndex,pqIndex,sourceIndex,contrast, PQ_PARAM_CONTRAST); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Contrast", inputInfo,indexInfo); + int err = getLocalparam("Contrast",indexInfo,contrast, PQ_PARAM_CONTRAST); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,contrast); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,contrast); ret = SetContrast(contrast); } else { @@ -1233,10 +1214,7 @@ namespace Plugin { uint32_t AVOutputTV::getContrastCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -1246,31 +1224,31 @@ namespace Plugin { JsonObject rangeObj; unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Contrast"); + tvError_t ret = getParamsCaps("Contrast",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = stoi(info.rangeVector[0]); + rangeObj["to"] = stoi(info.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -1283,24 +1261,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int saturation = 0; - if (parsingGetInputArgument(parameters, "Saturation",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Saturation",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Saturation", inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("Saturation",formatIndex,pqIndex,sourceIndex,saturation, PQ_PARAM_SATURATION); + int err = getLocalparam("Saturation",indexInfo,saturation, PQ_PARAM_SATURATION); if( err == 0 ) { response["saturation"] = saturation; LOGINFO("Exit : Saturation Value: %d \n", saturation); @@ -1315,33 +1290,31 @@ namespace Plugin { { LOGINFO("Entry\n"); + capDetails_t inputInfo; std::string value; - std::string pqmode; - std::string source; - std::string format; int saturation = 0; tvError_t ret = tvERROR_NONE; value = parameters.HasLabel("saturation") ? parameters["saturation"].String() : ""; returnIfParamNotFound(parameters,"saturation"); - saturation = stoi(value); + saturation = std::stoi(value); if (validateIntegerInputParameter("Saturation",saturation) != 0) { LOGERR("Failed in saturation range validation:%s", __FUNCTION__); returnResponse(false); } - if (parsingSetInputArgument(parameters, "Saturation",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Saturation",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Saturation" )) { + if( !isCapablityCheckPassed( "Saturation" , inputInfo )) { LOGERR("%s: CapablityCheck failed for Saturation\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s\n",__FUNCTION__); ret = SetSaturation(saturation); } @@ -1351,9 +1324,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=saturation; - int retval= updateAVoutputTVParam("set","Saturation",pqmode,source,format,PQ_PARAM_SATURATION,params); + int retval= updateAVoutputTVParam("set","Saturation",inputInfo,PQ_PARAM_SATURATION,saturation); if(retval != 0 ) { LOGERR("Failed to Save Saturation to ssm_data\n"); returnResponse(false); @@ -1369,36 +1340,36 @@ namespace Plugin { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,saturation=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int saturation=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Saturation",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Saturation", inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Saturation" )) { + if( !isCapablityCheckPassed( "Saturation", inputInfo )) { LOGERR("%s: CapablityCheck failed for Saturation\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Saturation",pqmode,source,format,PQ_PARAM_SATURATION,params); + int retval= updateAVoutputTVParam("reset","Saturation",inputInfo,PQ_PARAM_SATURATION,saturation); if(retval != 0 ) { LOGERR("Failed to reset Saturation\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Saturation",formatIndex,pqIndex,sourceIndex, saturation, PQ_PARAM_SATURATION); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Saturation",inputInfo,indexInfo); + int err = getLocalparam("Saturation",indexInfo, saturation, PQ_PARAM_SATURATION); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,saturation); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,saturation); ret = SetSaturation(saturation); } else { @@ -1421,10 +1392,7 @@ namespace Plugin { uint32_t AVOutputTV::getSaturationCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -1434,32 +1402,32 @@ namespace Plugin { unsigned int index = 0; JsonObject rangeObj; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Saturation"); + tvError_t ret = getParamsCaps("Saturation",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = stoi(info.rangeVector[0]); + rangeObj["to"] = stoi(info.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -1472,24 +1440,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int sharpness = 0; - if (parsingGetInputArgument(parameters, "Sharpness",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Sharpness",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Sharpness",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("Sharpness",formatIndex,pqIndex,sourceIndex,sharpness, PQ_PARAM_SHARPNESS); + int err = getLocalparam("Sharpness",indexInfo,sharpness, PQ_PARAM_SHARPNESS); if( err == 0 ) { response["sharpness"] = sharpness; LOGINFO("Exit : Sharpness Value: %d \n", sharpness); @@ -1504,33 +1469,31 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int sharpness = 0; tvError_t ret = tvERROR_NONE; + std::string value; value = parameters.HasLabel("sharpness") ? parameters["sharpness"].String() : ""; returnIfParamNotFound(parameters,"sharpness"); - sharpness = stoi(value); + sharpness = std::stoi(value); if (validateIntegerInputParameter("Sharpness",sharpness) != 0) { LOGERR("Failed in sharpness range validation:%s", __FUNCTION__); returnResponse(false); } - if (parsingSetInputArgument(parameters, "Sharpness",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Sharpness", inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Sharpness" )) { + if( !isCapablityCheckPassed( "Sharpness", inputInfo )) { LOGERR("%s: CapablityCheck failed for Sharpness\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s\n",__FUNCTION__); ret = SetSharpness(sharpness); } @@ -1540,9 +1503,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=sharpness; - int retval= updateAVoutputTVParam("set","Sharpness",pqmode,source,format,PQ_PARAM_SHARPNESS,params); + int retval= updateAVoutputTVParam("set","Sharpness",inputInfo,PQ_PARAM_SHARPNESS,sharpness); if(retval != 0 ) { LOGERR("Failed to Save Sharpness to ssm_data\n"); returnResponse(false); @@ -1558,36 +1519,36 @@ namespace Plugin { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,sharpness=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int sharpness=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Sharpness",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Sharpness",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Sharpness" )) { + if( !isCapablityCheckPassed( "Sharpness" , inputInfo)) { LOGERR("%s: CapablityCheck failed for Sharpness\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Sharpness",pqmode,source,format,PQ_PARAM_SHARPNESS,params); + int retval= updateAVoutputTVParam("reset","Sharpness", inputInfo,PQ_PARAM_SHARPNESS,sharpness); if(retval != 0 ) { LOGERR("Failed to reset Sharpness\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Sharpness",formatIndex,pqIndex,sourceIndex, sharpness, PQ_PARAM_SHARPNESS); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Sharpness",inputInfo,indexInfo); + int err = getLocalparam("Sharpness",indexInfo, sharpness, PQ_PARAM_SHARPNESS); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,sharpness); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,sharpness); ret = SetSharpness(sharpness); } else { @@ -1610,10 +1571,7 @@ namespace Plugin { uint32_t AVOutputTV::getSharpnessCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -1623,31 +1581,31 @@ namespace Plugin { JsonObject rangeObj; unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Sharpness"); + tvError_t ret = getParamsCaps("Sharpness",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = stoi(info.rangeVector[0]); + rangeObj["to"] = stoi(info.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -1660,24 +1618,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int hue = 0; - if (parsingGetInputArgument(parameters, "Hue",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "Hue", inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("Hue",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("Hue",formatIndex,pqIndex,sourceIndex,hue, PQ_PARAM_HUE); + int err = getLocalparam("Hue",indexInfo,hue, PQ_PARAM_HUE); if( err == 0 ) { response["hue"] = hue; LOGINFO("Exit : Hue Value: %d \n", hue); @@ -1692,33 +1647,31 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int hue = 0; tvError_t ret = tvERROR_NONE; + std::string value; value = parameters.HasLabel("hue") ? parameters["hue"].String() : ""; returnIfParamNotFound(parameters,"hue"); - hue = stoi(value); + hue = std::stoi(value); if (validateIntegerInputParameter("Hue",hue) != 0) { LOGERR("Failed in hue range validation:%s", __FUNCTION__); returnResponse(false); } - if (parsingSetInputArgument(parameters, "Hue",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Hue",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Hue" )) { + if( !isCapablityCheckPassed( "Hue", inputInfo )) { LOGERR("%s: CapablityCheck failed for Hue\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s\n",__FUNCTION__); ret = SetHue(hue); } @@ -1728,9 +1681,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=hue; - int retval= updateAVoutputTVParam("set","Hue",pqmode,source,format,PQ_PARAM_HUE,params); + int retval= updateAVoutputTVParam("set","Hue",inputInfo,PQ_PARAM_HUE,hue); if(retval != 0 ) { LOGERR("Failed to Save Hue to ssm_data\n"); returnResponse(false); @@ -1746,36 +1697,36 @@ namespace Plugin { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,hue=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int hue=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "Hue",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "Hue",inputInfo)!= 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "Hue" )) { + if( !isCapablityCheckPassed( "Hue" , inputInfo )) { LOGERR("%s: CapablityCheck failed for Hue\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","Hue",pqmode,source,format,PQ_PARAM_HUE,params); + int retval= updateAVoutputTVParam("reset","Hue", inputInfo,PQ_PARAM_HUE,hue); if(retval != 0 ) { LOGERR("Failed to reset Hue\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("Hue",formatIndex,pqIndex,sourceIndex, hue, PQ_PARAM_HUE); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("Hue",inputInfo,indexInfo); + int err = getLocalparam("Hue",indexInfo, hue, PQ_PARAM_HUE); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex,hue); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex,hue); ret = SetHue(hue); } else { @@ -1798,10 +1749,7 @@ namespace Plugin { uint32_t AVOutputTV::getHueCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -1811,31 +1759,31 @@ namespace Plugin { JsonObject rangeObj; unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"Hue"); + tvError_t ret = getParamsCaps("Hue",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - rangeObj["from"] = stoi(range[0]); - rangeObj["to"] = stoi(range[1]); + rangeObj["from"] = stoi(info.rangeVector[0]); + rangeObj["to"] = stoi(info.rangeVector[1]); response["rangeInfo"]=rangeObj; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -1848,24 +1796,21 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int colortemp = 0; - if (parsingGetInputArgument(parameters, "ColorTemperature",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "ColorTemperature", inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("ColorTemperature",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("ColorTemp",formatIndex,pqIndex,sourceIndex,colortemp,PQ_PARAM_COLOR_TEMPERATURE); + int err = getLocalparam("ColorTemp",indexInfo,colortemp,PQ_PARAM_COLOR_TEMPERATURE); if( err == 0 ) { switch(colortemp) { case tvColorTemp_STANDARD: @@ -1885,7 +1830,7 @@ namespace Plugin { case tvColorTemp_USER: LOGINFO("Color Temp Value: User Defined\n"); - response["colorTemperature"] = "User Defined"; + response["colorTemperature"] = "UserDefined"; break; default: @@ -1905,10 +1850,8 @@ namespace Plugin { { LOGINFO("Entry\n"); + capDetails_t inputInfo; std::string value; - std::string pqmode; - std::string source; - std::string format; tvColorTemp_t colortemp = tvColorTemp_MAX; tvError_t ret = tvERROR_NONE; @@ -1923,24 +1866,24 @@ namespace Plugin { else if (!value.compare("Cold")) { colortemp = tvColorTemp_COLD; } - else if (!value.compare("User Defined")) { + else if (!value.compare("UserDefined")) { colortemp = tvColorTemp_USER; } else { returnResponse(false); } - if (parsingSetInputArgument(parameters, "ColorTemperature",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "ColorTemperature",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "ColorTemperature" )) { + if( !isCapablityCheckPassed( "ColorTemperature", inputInfo )) { LOGERR("%s: CapablityCheck failed for colorTemperature\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s\n",__FUNCTION__); ret = SetColorTemperature((tvColorTemp_t)colortemp); } @@ -1950,9 +1893,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=(int)colortemp; - int retval= updateAVoutputTVParam("set","ColorTemp",pqmode,source,format,PQ_PARAM_COLOR_TEMPERATURE,params); + int retval= updateAVoutputTVParam("set","ColorTemp", inputInfo,PQ_PARAM_COLOR_TEMPERATURE,(int)colortemp); if(retval != 0 ) { LOGERR("Failed to Save ColorTemperature to ssm_data\n"); returnResponse(false); @@ -1967,36 +1908,36 @@ namespace Plugin { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,colortemp=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int colortemp=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "ColorTemperature",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "ColorTemperature", inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "ColorTemperature" )) { + if( !isCapablityCheckPassed( "ColorTemperature", inputInfo )) { LOGERR("%s: CapablityCheck failed for colorTemperature\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","ColorTemp",pqmode,source,format,PQ_PARAM_COLOR_TEMPERATURE,params); + int retval= updateAVoutputTVParam("reset","ColorTemp", inputInfo,PQ_PARAM_COLOR_TEMPERATURE,colortemp); if(retval != 0 ) { LOGERR("Failed to reset ColorTemperature\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("ColorTemp",formatIndex,pqIndex,sourceIndex, colortemp, PQ_PARAM_COLOR_TEMPERATURE); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("ColorTemperature",inputInfo,indexInfo); + int err = getLocalparam("ColorTemp",indexInfo, colortemp, PQ_PARAM_COLOR_TEMPERATURE); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex, colortemp); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex, colortemp); ret = SetColorTemperature((tvColorTemp_t)colortemp); } else { @@ -2018,10 +1959,7 @@ namespace Plugin { uint32_t AVOutputTV::getColorTemperatureCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -2030,33 +1968,33 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"ColorTemperature"); + tvError_t ret = getParamsCaps("ColorTemperature",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - for (index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); - } + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); + } response["options"]=rangeArray; - if (((pqmode.front()).compare("none") != 0)) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if (((info.pqmodeVector.front()).compare("none") != 0)) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -2069,25 +2007,22 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int dimmingMode = 0; - if (parsingGetInputArgument(parameters, "DimmingMode",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "DimmingMode", inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("DimmingMode",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("DimmingMode",formatIndex,pqIndex,sourceIndex,dimmingMode, PQ_PARAM_DIMMINGMODE); + int err = getLocalparam("DimmingMode",indexInfo,dimmingMode, PQ_PARAM_DIMMINGMODE); if( err == 0 ) { switch(dimmingMode) { case tvDimmingMode_Fixed: @@ -2118,12 +2053,10 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; int dimmingMode = 0; tvError_t ret = tvERROR_NONE; + std::string value; value = parameters.HasLabel("DimmingMode") ? parameters["DimmingMode"].String() : ""; returnIfParamNotFound(parameters,"DimmingMode"); @@ -2134,17 +2067,17 @@ namespace Plugin { } dimmingMode = getDimmingModeIndex(value); - if (parsingSetInputArgument(parameters, "DimmingMode",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "DimmingMode",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "DimmingMode" )) { + if( !isCapablityCheckPassed( "DimmingMode" , inputInfo )) { LOGERR("%s: CapablityCheck failed for DimmingMode\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired(pqmode,source,format) ) { + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with %s\n",__FUNCTION__); ret = SetTVDimmingMode(value.c_str()); } @@ -2154,9 +2087,7 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=(int)dimmingMode; - int retval= updateAVoutputTVParam("set","DimmingMode",pqmode,source,format,PQ_PARAM_DIMMINGMODE,params); + int retval= updateAVoutputTVParam("set","DimmingMode",inputInfo,PQ_PARAM_DIMMINGMODE,(int)dimmingMode); if(retval != 0 ) { LOGERR("Failed to Save DimmingMode to ssm_data\n"); returnResponse(false); @@ -2171,25 +2102,23 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format;std::string dimmingMode; - int sourceIndex=0,pqIndex=0,formatIndex=0,dMode=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + std::string dimmingMode; + int dMode=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "DimmingMode",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "DimmingMode", inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "DimmingMode" )) { + if( !isCapablityCheckPassed( "DimmingMode" , inputInfo )) { LOGERR("%s: CapablityCheck failed for DimmingMode\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","DimmingMode",pqmode,source,format,PQ_PARAM_DIMMINGMODE,params); + int retval= updateAVoutputTVParam("reset","DimmingMode", inputInfo,PQ_PARAM_DIMMINGMODE,dMode); if(retval != 0 ) { LOGERR("Failed to reset ldim\n"); @@ -2197,11 +2126,14 @@ namespace Plugin { } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("DimmingMode",formatIndex,pqIndex,sourceIndex, dMode, PQ_PARAM_DIMMINGMODE); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("DimmingMode",inputInfo,indexInfo); + int err = getLocalparam("DimmingMode",indexInfo, dMode, PQ_PARAM_DIMMINGMODE); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex, dMode); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex, dMode); getDimmingModeStringFromEnum(dMode,dimmingMode); ret = SetTVDimmingMode(dimmingMode.c_str()); } @@ -2224,10 +2156,7 @@ namespace Plugin { uint32_t AVOutputTV::getBacklightDimmingModeCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector supportedDimmingMode; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray supportedDimmingModeArray; JsonArray pqmodeArray; @@ -2236,33 +2165,33 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(supportedDimmingMode,pqmode,source,format,"DimmingMode"); + tvError_t ret = getParamsCaps("DimmingMode",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - for (index = 0; index < supportedDimmingMode.size(); index++) { - supportedDimmingModeArray.Add(supportedDimmingMode[index]); + for (index = 0; index < info.rangeVector.size(); index++) { + supportedDimmingModeArray.Add(info.rangeVector[index]); } response["options"]=supportedDimmingModeArray; - if (((pqmode.front()).compare("none") != 0)) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if (((info.pqmodeVector.front()).compare("none") != 0)) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -2273,7 +2202,6 @@ namespace Plugin { uint32_t AVOutputTV::getSupportedDolbyVisionModes(const JsonObject& parameters, JsonObject& response) { - LOGINFO("Entry\n"); tvDolbyMode_t dvModes[tvMode_Max]; tvDolbyMode_t *dvModesPtr = dvModes; // Pointer to statically allocated tvDolbyMode_t array @@ -2297,21 +2225,18 @@ namespace Plugin { LOGINFO("Exit\n"); returnResponse(true); } - } + uint32_t AVOutputTV::getDolbyVisionMode(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; + capDetails_t inputInfo; + paramIndex_t indexInfo; int dolbyMode = 0; int err = 0; - int sourceIndex=0,pqIndex=0,formatIndex=0; - - if (parsingGetInputArgument(parameters, "DolbyVisionMode",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "DolbyVisionMode",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } @@ -2320,15 +2245,13 @@ namespace Plugin { returnResponse(false); } - // Since it is dolby vision mode, to should get only for dolby vision format - format = "DV"; - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("DolbyVisionMode",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - err = getLocalparam("DolbyVisionMode",formatIndex,pqIndex,sourceIndex,dolbyMode, PQ_PARAM_DOLBY_MODE); + err = getLocalparam("DolbyVisionMode",indexInfo,dolbyMode, PQ_PARAM_DOLBY_MODE); if( err == 0 ) { response["dolbyVisionMode"] = getDolbyModeStringFromEnum((tvDolbyMode_t)dolbyMode); LOGINFO("Exit : DolbyVisionMode Value: %d \n", dolbyMode); @@ -2344,35 +2267,33 @@ namespace Plugin { { LOGINFO("Entry\n"); + capDetails_t inputInfo; std::string value; - std::string pqmode; - std::string source; - std::string format; tvError_t ret = tvERROR_NONE; value = parameters.HasLabel("dolbyVisionMode") ? parameters["dolbyVisionMode"].String() : ""; returnIfParamNotFound(parameters,"dolbyVisionMode"); - if (parsingSetInputArgument(parameters, "DolbyVisionMode",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "DolbyVisionMode",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } if (isPlatformSupport("DolbyVisionMode") != 0) { - returnResponse(false); - } + returnResponse(false); + } if (validateInputParameter("DolbyVisionMode",value) != 0) { LOGERR("%s: Range validation failed for DolbyVisionMode\n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "DolbyVisionMode" )) { + if( !isCapablityCheckPassed( "DolbyVisionMode" , inputInfo )) { LOGERR("%s: CapablityCheck failed for DolbyVisionMode\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired("Current",source,"DV") ) { + if( isSetRequired("Current",inputInfo.source,"DV") ) { LOGINFO("Proceed with setDolbyVisionMode\n\n"); ret = SetTVDolbyVisionMode(GetDolbyVisionEnumFromModeString(value.c_str())); } @@ -2382,10 +2303,8 @@ namespace Plugin { returnResponse(false); } else { - int params[3]={0}; - params[0]=getDolbyModeIndex(value.c_str()); - format = "DV"; - int retval= updateAVoutputTVParam("set","DolbyVisionMode",pqmode,source,format,PQ_PARAM_DOLBY_MODE,params); + inputInfo.format = "DV"; //Update only for DV format + int retval= updateAVoutputTVParam("set","DolbyVisionMode",inputInfo,PQ_PARAM_DOLBY_MODE,getDolbyModeIndex(value.c_str())); if(retval != 0 ) { LOGERR("Failed to Save Dolbyvision mode\n"); returnResponse(false); @@ -2400,15 +2319,12 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,dolbyMode=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int dolbyMode=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "DolbyVisionMode",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "DolbyVisionMode",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } @@ -2417,24 +2333,26 @@ namespace Plugin { returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "DolbyVisionMode" )) { + if( !isCapablityCheckPassed( "DolbyVisionMode" , inputInfo )) { LOGERR("%s: CapablityCheck failed for DolbyVisionMode\n", __FUNCTION__); returnResponse(false); } - - format = "DV"; - int retval= updateAVoutputTVParam("reset","DolbyVisionMode",pqmode,source,format,PQ_PARAM_DOLBY_MODE,params); + inputInfo.format = "DV"; //Update only for DV format + int retval= updateAVoutputTVParam("reset","DolbyVisionMode",inputInfo,PQ_PARAM_DOLBY_MODE,dolbyMode); if(retval != 0 ) { LOGERR("Failed to reset DolbyVisionMode\n"); returnResponse(false); } else { - if (isSetRequired("Current",source,format)) { - getParamIndex("Current","Current", format,sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("DolbyVisionMode",formatIndex,pqIndex,sourceIndex, dolbyMode, PQ_PARAM_DOLBY_MODE); + if (isSetRequired("Current",inputInfo.source,inputInfo.format)) { + inputInfo.source = "Current"; + inputInfo.pqmode = "Current"; + inputInfo.format = "DV"; + getParamIndex("DolbyVisionMode",inputInfo,indexInfo); + int err = getLocalparam("DolbyVisionMode",indexInfo, dolbyMode, PQ_PARAM_DOLBY_MODE); if( err == 0 ) { - std::string dolbyModeValue = getDolbyModeStringFromEnum((tvDolbyMode_t)dolbyMode); - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d dolbyvalue : %s\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex, dolbyModeValue.c_str()); + + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d dolbyvalue : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex, dolbyMode); ret = SetTVDolbyVisionMode((tvDolbyMode_t)dolbyMode); } else { @@ -2456,12 +2374,7 @@ namespace Plugin { uint32_t AVOutputTV::getDolbyVisionModeCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; - std::string isPlatformSupport; - std::vector indexInfo; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -2470,35 +2383,35 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"DolbyVisionMode", isPlatformSupport, indexInfo); + tvError_t ret = getParamsCaps("DolbyVisionMode", info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - response["platformSupport"] = (isPlatformSupport.compare("true") == 0 ) ? true : false; + response["platformSupport"] = (info.isPlatformSupportVector[0].compare("true") == 0 ) ? true : false; - for (index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); } response["options"]=rangeArray; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -2553,20 +2466,17 @@ namespace Plugin { JsonArray rangeArray; - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"VideoFormat"); + tvError_t ret = getParamsCaps("VideoFormat",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - if ((range.front()).compare("none") != 0) { - for (unsigned int index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); + if ((info.rangeVector.front()).compare("none") != 0) { + for (unsigned int index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); } response["options"]=rangeArray; } @@ -2608,35 +2518,32 @@ namespace Plugin { JsonArray formatArray; JsonArray rangeArray; - std::vector range; - std::vector source; - std::vector pqmode; - std::vector format; + capVectors_t info; unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"PictureMode"); + tvError_t ret = getParamsCaps("PictureMode",info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - if ((range.front()).compare("none") != 0) { - for (index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); + if ((info.rangeVector.front()).compare("none") != 0) { + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); } response["options"]=rangeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -2648,29 +2555,24 @@ namespace Plugin { uint32_t AVOutputTV::getPictureMode(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry\n"); - std::string picturemode; - std::string source; - std::string format; - std::string dummyPqmode; - int current_source = 0; - int current_format = 0; - int pqIndex = 0; + capDetails_t inputInfo; + paramIndex_t indexInfo; std::string tr181_param_name; TR181_ParamData_t param = {0}; tr181ErrorCode_t err = tr181Success; - if (parsingGetInputArgument(parameters, "PictureMode",source, dummyPqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "PictureMode",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,dummyPqmode,format,current_source,pqIndex,current_format) == -1) { + if (getParamIndex("PictureMode",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM); - tr181_param_name += "." + convertSourceIndexToString(current_source) + "." + "Format."+convertVideoFormatToString(current_format)+"."+"PictureModeString"; + tr181_param_name += "." + convertSourceIndexToString(indexInfo.sourceIndex) + "." + "Format."+convertVideoFormatToString(indexInfo.formatIndex)+"."+"PictureModeString"; err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), ¶m); if ( tr181Success != err ) { @@ -2688,11 +2590,9 @@ namespace Plugin { uint32_t AVOutputTV::setPictureMode(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry\n"); - std::string value; - std::string source; - std::string format; - std::string dummyPqmode; + capDetails_t inputInfo; char prevmode[PIC_MODE_NAME_MAX]={0}; + std::string value; GetTVPictureMode(prevmode); tvError_t ret = tvERROR_NONE; @@ -2700,7 +2600,7 @@ namespace Plugin { returnIfParamNotFound(parameters,"pictureMode"); // As only source need to validate, so pqmode and formate passing as currrent - if (parsingSetInputArgument(parameters, "PictureMode",source, dummyPqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "PictureMode",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } @@ -2709,12 +2609,12 @@ namespace Plugin { LOGERR("%s: Range validation failed for PictureMode\n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( dummyPqmode, source,format, "PictureMode" )) { + if( !isCapablityCheckPassed( "PictureMode" , inputInfo )) { LOGERR("%s: CapablityCheck failed for PictureMode\n", __FUNCTION__); returnResponse(false); } - if( isSetRequired("Current",source,format) ) { + if( isSetRequired("Current",inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with SetTVPictureMode\n"); ret = SetTVPictureMode(value.c_str()); } @@ -2722,15 +2622,14 @@ namespace Plugin { returnResponse(false); } else { - std::vector pq_mode_vec; - std::vector source_vec; - std::vector format_vec; + valueVectors_t values; + inputInfo.pqmode = "Current"; - getSaveConfig("Current", source.c_str(), format.c_str(), source_vec, pq_mode_vec, format_vec); + getSaveConfig("PictureMode" ,inputInfo, values); - for (int sourceType : source_vec) { + for (int sourceType : values.sourceValues) { tvVideoSrcType_t source = (tvVideoSrcType_t)sourceType; - for (int formatType : format_vec) { + for (int formatType : values.formatValues) { tvVideoFormatType_t format = (tvVideoFormatType_t)formatType; std::string tr181_param_name = ""; tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM); @@ -2781,29 +2680,25 @@ namespace Plugin { tr181ErrorCode_t err = tr181Success; TR181_ParamData_t param = {0}; - std::vector pq_mode_vec; - std::vector source_vec; - std::vector format_vec; - std::string source; - std::string dummyPqmode; - std::string format; + valueVectors_t values; + capDetails_t inputInfo; // As only source need to validate, so pqmode and formate passing as currrent - if (parsingSetInputArgument(parameters, "PictureMode",source, dummyPqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "PictureMode",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( dummyPqmode, source,format, "PictureMode" )) { + if( !isCapablityCheckPassed( "PictureMode",inputInfo )) { LOGERR("%s: CapablityCheck failed for PictureMode\n", __FUNCTION__); returnResponse(false); } + inputInfo.pqmode = "Current"; + getSaveConfig("PictureMode", inputInfo, values); - getSaveConfig("Current", source, format, source_vec, pq_mode_vec, format_vec); - - for (int source : source_vec) { + for (int source : values.sourceValues) { tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source; - for (int format : format_vec) { + for (int format : values.formatValues) { tvVideoFormatType_t formatType = (tvVideoFormatType_t)format; std::string tr181_param_name = ""; tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM); @@ -2878,10 +2773,7 @@ namespace Plugin { LOGINFO("Entry\n"); std::string value; - std::string pqmode; - std::string source; - std::string format; - int params[3]={0}; + capDetails_t inputInfo; int lowLatencyIndex = 0,prevLowLatencyIndex = 0; tvError_t ret = tvERROR_NONE; @@ -2893,41 +2785,37 @@ namespace Plugin { value = parameters.HasLabel("LowLatencyState") ? parameters["LowLatencyState"].String() : ""; returnIfParamNotFound(parameters,"LowLatencyState"); - lowLatencyIndex = stoi(value); + lowLatencyIndex = std::stoi(value); if (validateIntegerInputParameter("LowLatencyState",lowLatencyIndex) != 0) { LOGERR("Failed in Brightness range validation:%s", __FUNCTION__); returnResponse(false); } - if (parsingSetInputArgument(parameters, "LowLatencyState",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "LowLatencyState",inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed(pqmode, source, format, "LowLatencyState" )) { + if( !isCapablityCheckPassed( "LowLatencyState" , inputInfo )) { LOGERR("%s: CapablityCheck failed for LowLatencyState\n", __FUNCTION__); returnResponse(false); } - params[0]=lowLatencyIndex; - int retval= updateAVoutputTVParam("set","LowLatencyState",pqmode,source,format,PQ_PARAM_LOWLATENCY_STATE,params); + int retval= updateAVoutputTVParam("set","LowLatencyState",inputInfo,PQ_PARAM_LOWLATENCY_STATE,lowLatencyIndex); if(retval != 0 ) { LOGERR("Failed to SaveLowLatency to ssm_data\n"); returnResponse(false); } else { - - if( isSetRequired(pqmode,source,format) ) { + + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { LOGINFO("Proceed with setLowLatencyState\n"); ret = SetLowLatencyState( lowLatencyIndex ); } if(ret != tvERROR_NONE) { - LOGERR("Failed to setLowLatency\n"); - params[0]=prevLowLatencyIndex; LOGERR("Failed to set low latency. Fallback to previous state %d\n", prevLowLatencyIndex); - - retval=updateAVoutputTVParam("set","LowLatencyState",pqmode,source,format,PQ_PARAM_LOWLATENCY_STATE,params); + retval=updateAVoutputTVParam("set","LowLatencyState",inputInfo,PQ_PARAM_LOWLATENCY_STATE,prevLowLatencyIndex); if(retval != 0 ){ LOGERR("Fallback to previous low latency state %d failed.\n", prevLowLatencyIndex); } @@ -2943,23 +2831,20 @@ namespace Plugin { { LOGINFO("Entry"); - std::string pqmode; - std::string source; - std::string format; - std::string key; - int sourceIndex=0,pqIndex=0,formatIndex=0; + capDetails_t inputInfo; + paramIndex_t indexInfo; int lowlatencystate = 0; - if (parsingGetInputArgument(parameters, "LowLatencyState",source, pqmode, format) != 0) { + if (parsingGetInputArgument(parameters, "LowLatencyState",inputInfo) != 0) { LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); returnResponse(false); } - if (getParamIndex(source,pqmode,format,sourceIndex,pqIndex,formatIndex) == -1) { + if (getParamIndex("LowLatencyState",inputInfo,indexInfo) == -1) { LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); returnResponse(false); } - int err = getLocalparam("LowLatencyState",formatIndex,pqIndex,sourceIndex,lowlatencystate, PQ_PARAM_LOWLATENCY_STATE); + int err = getLocalparam("LowLatencyState", indexInfo ,lowlatencystate, PQ_PARAM_LOWLATENCY_STATE); if( err == 0 ) { response["lowLatencyState"] = std::to_string(lowlatencystate); LOGINFO("Exit : LowLatencyState Value: %d \n", lowlatencystate); @@ -2974,35 +2859,35 @@ namespace Plugin { { LOGINFO("Entry\n"); - std::string value; - std::string pqmode; - std::string source; - std::string format; - int sourceIndex=0,pqIndex=0,formatIndex=0,lowlatencystate=0; - int params[3]={0}; + capDetails_t inputInfo; + paramIndex_t indexInfo; + int lowlatencystate=0; tvError_t ret = tvERROR_NONE; - if (parsingSetInputArgument(parameters, "LowLatencyState",source, pqmode, format) != 0) { + if (parsingSetInputArgument(parameters, "LowLatencyState", inputInfo) != 0) { LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); returnResponse(false); } - if( !isCapablityCheckPassed( pqmode, source, format, "LowLatencyState" )) { + if( !isCapablityCheckPassed( "LowLatencyState" , inputInfo )) { LOGERR("%s: CapablityCheck failed for LowLatencyState\n", __FUNCTION__); returnResponse(false); } - int retval= updateAVoutputTVParam("reset","LowLatencyState",pqmode,source,format,PQ_PARAM_LOWLATENCY_STATE,params); + int retval= updateAVoutputTVParam("reset","LowLatencyState", inputInfo,PQ_PARAM_LOWLATENCY_STATE,lowlatencystate); if(retval != 0 ) { LOGERR("Failed to clear Lowlatency from ssmdata and localstore\n"); returnResponse(false); } else { - if (isSetRequired(pqmode,source,format)) { - getParamIndex("Current","Current", "Current",sourceIndex,pqIndex,formatIndex); - int err = getLocalparam("LowLatencyState",formatIndex,pqIndex,sourceIndex, lowlatencystate, PQ_PARAM_LOWLATENCY_STATE); + if (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + inputInfo.pqmode = "Current"; + inputInfo.source = "Current"; + inputInfo.format = "Current"; + getParamIndex("LowLatencyState",inputInfo, indexInfo); + int err = getLocalparam("LowLatencyState",indexInfo, lowlatencystate, PQ_PARAM_LOWLATENCY_STATE); if( err == 0 ) { - LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,formatIndex, sourceIndex, pqIndex, lowlatencystate); + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d value : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex, lowlatencystate); ret = SetLowLatencyState(lowlatencystate); } else { @@ -3024,10 +2909,7 @@ namespace Plugin { uint32_t AVOutputTV::getLowLatencyStateCaps(const JsonObject& parameters, JsonObject& response) { LOGINFO("Entry"); - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; JsonArray rangeArray; JsonArray pqmodeArray; @@ -3036,32 +2918,32 @@ namespace Plugin { unsigned int index = 0; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"LowLatencyState"); + tvError_t ret = getParamsCaps("LowLatencyState", info); if(ret != tvERROR_NONE) { returnResponse(false); } else { - for (index = 0; index < range.size(); index++) { - rangeArray.Add(stoi(range[index])); + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(stoi(info.rangeVector[index])); } response["LowLatencyInfo"]=rangeArray; - if ((pqmode.front()).compare("none") != 0) { - for (index = 0; index < pqmode.size(); index++) { - pqmodeArray.Add(pqmode[index]); + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); } response["pictureModeInfo"]=pqmodeArray; } - if ((source.front()).compare("none") != 0) { - for (index = 0; index < source.size(); index++) { - sourceArray.Add(source[index]); + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); } response["videoSourceInfo"]=sourceArray; } - if ((format.front()).compare("none") != 0) { - for (index = 0; index < format.size(); index++) { - formatArray.Add(format[index]); + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); } response["videoFormatInfo"]=formatArray; } @@ -3070,6 +2952,972 @@ namespace Plugin { } } + uint32_t AVOutputTV::getCMS(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + + capDetails_t inputInfo; + paramIndex_t indexInfo; + int level = 0; + tvPQParameterIndex_t tvPQEnum; + + inputInfo.color = parameters.HasLabel("color") ? parameters["color"].String() : ""; + inputInfo.component = parameters.HasLabel("component") ? parameters["component"].String() : ""; + + if( inputInfo.color.empty() || inputInfo.component.empty() ) { + LOGERR("%s : Color/Component param not found!!!\n",__FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("CMS") != 0) { + returnResponse(false); + } + + + if (parsingGetInputArgument(parameters, "CMS", inputInfo) != 0) { + LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); + returnResponse(false); + } + + if (getParamIndex("CMS",inputInfo,indexInfo) == -1) { + LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); + returnResponse(false); + } + + if ( convertCMSParamToPQEnum(inputInfo.component,inputInfo.color,tvPQEnum) != 0 ) { + LOGINFO("%s: Component/Color Param Not Found \n",__FUNCTION__); + returnResponse(false); + } + + int err = getLocalparam("CMS",indexInfo,level,tvPQEnum); + if( err == 0 ) { + response["level"] = level; + LOGINFO("Exit : params Value: %d \n", level); + returnResponse(true); + } + else { + returnResponse(false); + } + } + + uint32_t AVOutputTV::setCMS(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + capDetails_t inputInfo; + int level = 0,retVal = 0; + tvPQParameterIndex_t tvPQEnum; + tvDataComponentColor_t colorEnum=tvDataColor_NONE; + std::string color,component; + tvError_t ret = tvERROR_NONE; + std::string value; + + inputInfo.color = parameters.HasLabel("color") ? parameters["color"].String() : ""; + inputInfo.component = parameters.HasLabel("component") ? parameters["component"].String() : ""; + + if( inputInfo.color.empty() || inputInfo.component.empty() ) { + LOGERR("%s : Color/Component param not found!!!\n",__FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("CMS") != 0) { + returnResponse(false); + } + + value = parameters.HasLabel("level") ? parameters["level"].String() : ""; + returnIfParamNotFound(parameters,"level"); + level = std::stoi(value); + + if (validateCMSParameter(inputInfo.component,level) != 0) { + LOGERR("%s: CMS Failed in range validation", __FUNCTION__); + returnResponse(false); + } + + if (parsingSetInputArgument(parameters,"CMS",inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "CMS",inputInfo )) { + LOGERR("%s: CapablityCheck failed for CMS\n", __FUNCTION__); + returnResponse(false); + } + + if ( convertCMSParamToPQEnum(inputInfo.component,inputInfo.color,tvPQEnum) != 0 ) { + LOGERR("%s: %s/%s Param Not Found \n",__FUNCTION__,inputInfo.component.c_str(),inputInfo.color.c_str()); + returnResponse(false); + } + + retVal = getCMSColorEnumFromString(inputInfo.color,colorEnum); + if( retVal == -1) { + LOGERR("%s: Invalid Color : %s\n",__FUNCTION__,inputInfo.color.c_str()); + returnResponse(false); + } + + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { + LOGINFO("Proceed with %s\n",__FUNCTION__); + tvError_t ret = SetCMSState(true); + if(ret != tvERROR_NONE) { + LOGWARN("CMS enable failed\n"); + returnResponse(false); + } + + if(inputInfo.component.compare("Saturation") == 0) + ret = SetCurrentComponentSaturation(colorEnum, level); + else if(inputInfo.component.compare("Hue") == 0 ) + ret = SetCurrentComponentHue(colorEnum,level); + else if( inputInfo.component.compare("Luma") == 0 ) + ret = SetCurrentComponentLuma(colorEnum,level); + + } + + if(ret != tvERROR_NONE) { + LOGERR("Failed to set CMS\n"); + returnResponse(false); + } + else { + std::string cmsParam; + cmsParam = inputInfo.color+"."+inputInfo.component; + + retVal= updateAVoutputTVParam("set","CMS",inputInfo,tvPQEnum,level); + if(retVal != 0 ) { + LOGERR("%s : Failed to Save CMS %s/%s(%s) to ssm_data\n",__FUNCTION__,inputInfo.component.c_str(),inputInfo.color.c_str(),cmsParam.c_str()); + returnResponse(false); + } + LOGINFO("Exit : setCMS %s/%s successful to value: %d\n", inputInfo.component.c_str(),inputInfo.color.c_str(),level); + returnResponse(true); + } + } + + uint32_t AVOutputTV::resetCMS(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + capDetails_t inputInfo; + int retVal = 0; + std::string color,component; + tvError_t ret = tvERROR_NONE; + JsonArray sourceArray; + JsonArray pqmodeArray; + JsonArray formatArray; + JsonArray colorArray; + JsonArray componentArray; + + if (isPlatformSupport("CMS") != 0) { + returnResponse(false); + } + + pqmodeArray = parameters.HasLabel("pictureMode") ? parameters["pictureMode"].Array() : JsonArray(); + for (int i = 0; i < pqmodeArray.Length(); ++i) { + inputInfo.pqmode += pqmodeArray[i].String(); + if (i != (pqmodeArray.Length() - 1) ) { + inputInfo.pqmode += ","; + } + } + + sourceArray = parameters.HasLabel("videoSource") ? parameters["videoSource"].Array() : JsonArray(); + for (int i = 0; i < sourceArray.Length(); ++i) { + inputInfo.source += sourceArray[i].String(); + if (i != (sourceArray.Length() - 1) ) { + inputInfo.source += ","; + } + } + + formatArray = parameters.HasLabel("videoFormat") ? parameters["videoFormat"].Array() : JsonArray(); + for (int i = 0; i < formatArray.Length(); ++i) { + inputInfo.format += formatArray[i].String(); + if (i != (formatArray.Length() - 1) ) { + inputInfo.format += ","; + } + } + colorArray = parameters.HasLabel("color") ? parameters["color"].Array() : JsonArray(); + for (int i = 0; i < colorArray.Length(); ++i) { + inputInfo.color += colorArray[i].String(); + if (i != (colorArray.Length() - 1) ) { + inputInfo.color += ","; + } + } + componentArray = parameters.HasLabel("component") ? parameters["component"].Array() : JsonArray(); + for (int i = 0; i < componentArray.Length(); ++i) { + inputInfo.component += componentArray[i].String(); + if (i != (componentArray.Length() - 1) ) { + inputInfo.component += ","; + } + } + if (inputInfo.source.empty()) { + inputInfo.source = "Global"; + } + if (inputInfo.pqmode.empty()) { + inputInfo.pqmode = "Global"; + } + if (inputInfo.format.empty()) { + inputInfo.format = "Global"; + } + if (inputInfo.color.empty()) { + inputInfo.color = "Global"; + } + if (inputInfo.component.empty()) { + inputInfo.component = "Global"; + } + + if (convertToValidInputParameter("CMS", inputInfo) != 0) { + LOGERR("%s: Failed to convert the input paramters. \n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "CMS" , inputInfo )) { + LOGERR("%s: CapablityCheck failed for CMS\n", __FUNCTION__); + returnResponse(false); + } + + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { + LOGINFO("Proceed with %s\n",__FUNCTION__); + tvError_t ret = SetCMSState(false); + if(ret != tvERROR_NONE) { + LOGWARN("CMS disable failed\n"); + returnResponse(false); + } + } + + if(ret != tvERROR_NONE) { + LOGERR("%s : Failed to setCMSState\n",__FUNCTION__); + returnResponse(false); + } + else { + int cms = 0; + retVal= updateAVoutputTVParam("reset","CMS",inputInfo,PQ_PARAM_CMS_SATURATION_RED,cms); + if(retVal != 0 ) { + LOGERR("%s : Failed to Save CMS %s/%s to ssm_data\n",__FUNCTION__,inputInfo.component.c_str(),inputInfo.color.c_str() ); + returnResponse(false); + } + returnResponse(true); + } + } + + uint32_t AVOutputTV::getCMSCaps(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + capVectors_t info; + + JsonArray rangeArray; + JsonArray pqmodeArray; + JsonArray formatArray; + JsonArray sourceArray; + JsonArray colorArray; + JsonArray componentArray; + + JsonObject componentSaturationRangeInfo; + JsonObject componentHueRangeInfo; + JsonObject componentLumaRangeInfo; + unsigned int index = 0; + + tvError_t ret = getParamsCaps("CMS",info); + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + + response["platformSupport"] = (info.isPlatformSupportVector[0].compare("true") == 0) ? true : false; + + componentSaturationRangeInfo["from"] = stoi(info.rangeVector[0]); + componentSaturationRangeInfo["to"] = stoi(info.rangeVector[1]); + response["componentSaturationRangeInfo"]=componentSaturationRangeInfo; + + componentHueRangeInfo["from"] = stoi(info.rangeVector[2]); + componentHueRangeInfo["to"] = stoi(info.rangeVector[3]); + response["componentHueRangeInfo"]=componentHueRangeInfo; + + componentLumaRangeInfo["from"] = stoi(info.rangeVector[4]); + componentLumaRangeInfo["to"] = stoi(info.rangeVector[5]); + response["componentLumaRangeInfo"]=componentLumaRangeInfo; + + + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); + } + response["pictureModeInfo"]=pqmodeArray; + } + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); + } + response["videoSourceInfo"]=sourceArray; + } + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); + } + response["videoFormatInfo"]=formatArray; + } + + if ((info.colorVector.front()).compare("none") != 0) { + for (index = 0; index < info.colorVector.size(); index++) { + colorArray.Add(info.colorVector[index]); + } + response["colorInfo"]=colorArray; + } + + if ((info.componentVector.front()).compare("none") != 0) { + for (index = 0; index < info.componentVector.size(); index++) { + componentArray.Add(info.componentVector[index]); + } + response["componentInfo"]=componentArray; + } + + LOGINFO("Exit\n"); + returnResponse(true); + } + } + + uint32_t AVOutputTV::getHDRMode(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + capDetails_t inputInfo; + int dolbyMode = 0; + int err = 0; + paramIndex_t indexInfo; + + if (parsingGetInputArgument(parameters, "HDRMode", inputInfo) != 0) { + LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("HDRMode") != 0) { + returnResponse(false); + } + + if (getParamIndex("HDRMode",inputInfo,indexInfo) == -1) { + LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); + returnResponse(false); + } + + err = getLocalparam("HDRMode", indexInfo,dolbyMode, PQ_PARAM_DOLBY_MODE); + if( err == 0 ) { + response["hdrMode"] = getDolbyModeStringFromEnum((tvDolbyMode_t)dolbyMode); + LOGINFO("Exit : hdrMode Value: %d \n", dolbyMode); + returnResponse(true); + } + else { + returnResponse(false); + } + + } + + uint32_t AVOutputTV::setHDRMode(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + tvDolbyMode_t index; + capDetails_t inputInfo; + tvError_t ret = tvERROR_NONE; + std::string value; + int retval = 0; + + value = parameters.HasLabel("HDRMode") ? parameters["HDRMode"].String() : ""; + returnIfParamNotFound(parameters,"HDRMode"); + + if (parsingSetInputArgument(parameters, "HDRMode", inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("HDRMode") != 0) { + returnResponse(false); + } + + if (validateInputParameter("HDRMode",value) != 0) { + LOGERR("%s: Range validation failed for hdrMode\n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "HDRMode", inputInfo )) { + LOGERR("%s: CapablityCheck failed for hdrMode\n", __FUNCTION__); + returnResponse(false); + } + + if( isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format) ) { + LOGINFO("Proceed with HDRMode\n\n"); + retval = getHDRModeIndex(value,inputInfo.format,index); + if( retval != 0 ) + { + LOGERR("Failed to getHDRMode index\n"); + returnResponse(false); + } + ret = SetTVDolbyVisionMode(index); + } + + if(ret != tvERROR_NONE) { + LOGERR("Failed to set HDRMode\n\n"); + returnResponse(false); + } + else { + retval= updateAVoutputTVParam("set","HDRMode",inputInfo,PQ_PARAM_DOLBY_MODE,(int)index); + if(retval != 0 ) { + LOGERR("Failed to Save hdrMode mode\n"); + returnResponse(false); + } + LOGINFO("Exit : hdrMode successful to value: %s\n", value.c_str()); + returnResponse(true); + } + + } + + uint32_t AVOutputTV::resetHDRMode(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + capDetails_t inputInfo; + paramIndex_t indexInfo; + int dolbyMode=0; + tvError_t ret = tvERROR_NONE; + + if (parsingSetInputArgument(parameters, "HDRMode", inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("HDRMode") != 0) { + returnResponse(false); + } + + if( !isCapablityCheckPassed( "HDRMode" , inputInfo )) { + LOGERR("%s: CapablityCheck failed for HDRMode\n", __FUNCTION__); + returnResponse(false); + } + + int retval= updateAVoutputTVParam("reset","HDRMode",inputInfo,PQ_PARAM_DOLBY_MODE,dolbyMode); + if(retval != 0 ) { + LOGERR("Failed to reset HDRMode\n"); + returnResponse(false); + } + else { + if (isSetRequired( inputInfo.pqmode,inputInfo.source,inputInfo.format)) { + getParamIndex( "HDRMode", inputInfo,indexInfo); + int err = getLocalparam("HDRMode", indexInfo, dolbyMode, PQ_PARAM_DOLBY_MODE); + if( err == 0 ) { + LOGINFO("%s : getLocalparam success format :%d source : %d format : %d dolbyvalue : %d\n",__FUNCTION__,indexInfo.formatIndex, indexInfo.sourceIndex, indexInfo.pqmodeIndex, dolbyMode); + ret = SetTVDolbyVisionMode((tvDolbyMode_t)dolbyMode); + } + else { + LOGERR("%s : GetLocalParam Failed \n",__FUNCTION__); + ret = tvERROR_GENERAL; + } + } + } + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + LOGINFO("Exit : resetHDRMode Successful to value : %d \n",dolbyMode); + returnResponse(true); + } + } + + uint32_t AVOutputTV::getHDRModeCaps(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + capVectors_t info; + + JsonArray rangeArray; + JsonArray pqmodeArray; + JsonArray formatArray; + JsonArray sourceArray; + + unsigned int index = 0; + + tvError_t ret = getParamsCaps("HDRMode", info); + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + + response["platformSupport"] = (info.isPlatformSupportVector[0].compare("true") == 0 ) ? true : false; + + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); + } + + response["options"]=rangeArray; + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); + } + response["pictureModeInfo"]=pqmodeArray; + } + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); + } + response["videoSourceInfo"]=sourceArray; + } + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); + } + response["videoFormatInfo"]=formatArray; + } + LOGINFO("Exit\n"); + returnResponse(true); + } + } + + uint32_t AVOutputTV::get2PointWB(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + + capDetails_t inputInfo; + paramIndex_t indexInfo; + int level = 0; + tvPQParameterIndex_t tvPQEnum; + + inputInfo.color = parameters.HasLabel("color") ? parameters["color"].String() : ""; + inputInfo.control = parameters.HasLabel("control") ? parameters["control"].String() : ""; + + if( inputInfo.color.empty() || inputInfo.control.empty() ) { + LOGERR("%s : Color/Control param not found!!!\n",__FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("WhiteBalance") != 0) { + returnResponse(false); + } + + if (parsingGetInputArgument(parameters, "WhiteBalance", inputInfo) != 0) { + LOGINFO("%s: Failed to parse argument\n", __FUNCTION__); + returnResponse(false); + } + + if (getParamIndex("WhiteBalance", inputInfo,indexInfo) == -1) { + LOGERR("%s: getParamIndex failed to get \n", __FUNCTION__); + returnResponse(false); + } + + if ( convertWBParamToPQEnum(inputInfo.control,inputInfo.color,tvPQEnum) != 0 ) { + LOGINFO("%s: Control/Color Param Not Found \n",__FUNCTION__); + returnResponse(false); + } + + int err = getLocalparam("WhiteBalance",indexInfo,level, tvPQEnum); + if( err == 0 ) { + response["level"] = level; + LOGINFO("Exit : params Value: %d \n", level); + returnResponse(true); + } + else { + returnResponse(false); + } + } + + uint32_t AVOutputTV::set2PointWB(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + capDetails_t inputInfo; + int level = 0; + tvPQParameterIndex_t tvPQEnum; + int retVal = 0; + std::string color,control,value; + tvError_t ret = tvERROR_NONE; + + inputInfo.color = parameters.HasLabel("color") ? parameters["color"].String() : ""; + inputInfo.control = parameters.HasLabel("control") ? parameters["control"].String() : ""; + + if (isPlatformSupport("WhiteBalance") != 0) { + returnResponse(false); + } + + if( inputInfo.color.empty() || inputInfo.control.empty() ) { + LOGERR("%s : Color/Control param not found!!!\n",__FUNCTION__); + returnResponse(false); + } + + value = parameters.HasLabel("level") ? parameters["level"].String() : ""; + returnIfParamNotFound(parameters,"level"); + level = std::stoi(value); + + if (validateWBParameter("WhiteBalance",inputInfo.control,level) != 0) { + LOGERR("%s: CMS Failed in range validation", __FUNCTION__); + returnResponse(false); + } + + if (parsingSetInputArgument(parameters,"WhiteBalance",inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "WhiteBalance",inputInfo )) { + LOGERR("%s: CapablityCheck failed for WhiteBalance\n", __FUNCTION__); + returnResponse(false); + } + + if ( convertWBParamToPQEnum(inputInfo.control,inputInfo.color,tvPQEnum) != 0 ) { + LOGERR("%s: %s/%s Param Not Found \n",__FUNCTION__,inputInfo.component.c_str(),inputInfo.color.c_str()); + returnResponse(false); + } + + if( (isSetRequired(inputInfo.pqmode,inputInfo.source,inputInfo.format))) { + LOGINFO("Proceed with %s\n",__FUNCTION__); + + tvVideoSrcType_t currentSource = VIDEO_SOURCE_IP; + tvError_t ret = GetCurrentVideoSource(¤tSource); + + if(ret != tvERROR_NONE) { + LOGWARN("%s: GetCurrentVideoSource( ) Failed \n",__FUNCTION__); + return -1; + } + + tvWBColor_t colorLevel; + if ( getWBColorEnumFromString(inputInfo.color,colorLevel ) == -1 ) { + LOGERR("%s : GetColorEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + tvWBControl_t controlLevel; + if ( getWBControlEnumFromString(inputInfo.control,controlLevel ) == -1 ) { + LOGERR("%s : GetComponentEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + ret = SetCustom2PointWhiteBalance(colorLevel,controlLevel,level); + } + + if(ret != tvERROR_NONE) { + LOGERR("%s: Failed to set WhiteBalance\n",__FUNCTION__); + returnResponse(false); + } + else { + retVal= updateAVoutputTVParam("set","WhiteBalance",inputInfo,tvPQEnum,level); + if(retVal != 0 ) { + LOGERR("%s : Failed to Save WB %s/%s : %d to ssm_data\n",__FUNCTION__,inputInfo.control.c_str(),inputInfo.color.c_str(),level); + returnResponse(false); + } + LOGINFO("Exit : set2PointWB %s/%s successful to value: %d\n", inputInfo.control.c_str(),inputInfo.color.c_str(),level); + returnResponse(true); + } + } + + uint32_t AVOutputTV::reset2PointWB(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + capDetails_t inputInfo; + tvPQParameterIndex_t tvPQEnum; + int retVal = 0; + int level = 0; + std::string color,control; + inputInfo.color = parameters.HasLabel("color") ? parameters["color"].String() : ""; + inputInfo.control = parameters.HasLabel("control") ? parameters["control"].String() : ""; + + if (isPlatformSupport("WhiteBalance") != 0) { + returnResponse(false); + } + + if (parsingSetInputArgument(parameters,"WhiteBalance",inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "WhiteBalance",inputInfo )) { + LOGERR("%s: CapablityCheck failed for WhiteBalance\n", __FUNCTION__); + returnResponse(false); + } + + for( int colorIndex= tvWB_COLOR_RED; colorIndex < tvWB_COLOR_MAX; colorIndex++) { + for(int controlIndex = tvWB_CONTROL_GAIN;controlIndex < tvWB_CONTROL_MAX;controlIndex++) { + inputInfo.control = getWBControlStringFromEnum((tvWBControl_t)controlIndex); + inputInfo.color = getWBColorStringFromEnum((tvWBColor_t)colorIndex); + if ( convertWBParamToPQEnum(inputInfo.control,inputInfo.color,tvPQEnum) != 0 ) { + LOGERR("%s: %s/%s Param Not Found \n",__FUNCTION__,inputInfo.control.c_str(),inputInfo.color.c_str()); + returnResponse(false); + } + + retVal |= updateAVoutputTVParam("reset","WhiteBalance",inputInfo,tvPQEnum,level); + } + } + + if( retVal != 0 ) { + LOGWARN("Failed to reset WhiteBalance\n"); + returnResponse(false); + } + else { + LOGINFO("Exit : reset2PointWB successful \n"); + returnResponse(true); + } + } + + uint32_t AVOutputTV::get2PointWBCaps(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + capVectors_t info; + + JsonArray rangeArray; + JsonArray pqmodeArray; + JsonArray formatArray; + JsonArray sourceArray; + JsonArray colorArray; + JsonArray controlArray; + + JsonObject gainInfo; + JsonObject offsetInfo; + + unsigned int index = 0; + + tvError_t ret = getParamsCaps("WhiteBalance",info); + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + response["platformSupport"] = (info.isPlatformSupportVector[0].compare("true") == 0) ? true : false; + + gainInfo["from"] = stoi(info.rangeVector[0]); + gainInfo["to"] = stoi(info.rangeVector[1]); + response["gainInfo"]=gainInfo; + + offsetInfo["from"] = stoi(info.rangeVector[0]); + offsetInfo["to"] = stoi(info.rangeVector[1]); + response["offsetInfo"]=offsetInfo; + + + + if ((info.pqmodeVector.front()).compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); + } + response["pictureModeInfo"]=pqmodeArray; + } + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); + } + response["videoSourceInfo"]=sourceArray; + } + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); + } + response["videoFormatInfo"]=formatArray; + } + + if ((info.colorVector.front()).compare("none") != 0) { + for (index = 0; index < info.colorVector.size(); index++) { + colorArray.Add(info.colorVector[index]); + } + response["colorInfo"]=colorArray; + } + + if ((info.controlVector.front()).compare("none") != 0) { + for (index = 0; index < info.controlVector.size(); index++) { + controlArray.Add(info.controlVector[index]); + } + response["controlInfo"]=controlArray; + } + + LOGINFO("Exit\n"); + returnResponse(true); + } + } + + uint32_t AVOutputTV::getAutoBacklightModeCaps(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry"); + capVectors_t info; + + JsonArray rangeArray; + JsonArray pqmodeArray; + JsonArray formatArray; + JsonArray sourceArray; + + unsigned int index = 0; + + tvError_t ret = getParamsCaps("AutoBacklightMode",info); + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + + response["platformSupport"] = (info.isPlatformSupportVector[0].compare("true") == 0 ) ? true : false; + + for (index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); + } + + response["options"]=rangeArray; + + if (info.pqmodeVector.front().compare("none") != 0) { + for (index = 0; index < info.pqmodeVector.size(); index++) { + pqmodeArray.Add(info.pqmodeVector[index]); + } + response["pictureModeInfo"]=pqmodeArray; + } + if ((info.sourceVector.front()).compare("none") != 0) { + for (index = 0; index < info.sourceVector.size(); index++) { + sourceArray.Add(info.sourceVector[index]); + } + response["videoSourceInfo"]=sourceArray; + } + if ((info.formatVector.front()).compare("none") != 0) { + for (index = 0; index < info.formatVector.size(); index++) { + formatArray.Add(info.formatVector[index]); + } + response["videoFormatInfo"]=formatArray; + } + LOGINFO("Exit\n"); + returnResponse(true); + } + } + + uint32_t AVOutputTV::setAutoBacklightMode(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + std::string value; + tvBacklightMode_t mode = tvBacklightMode_AMBIENT; + capDetails_t inputInfo; + + + value = parameters.HasLabel("mode") ? parameters["mode"].String() : ""; + returnIfParamNotFound(parameters,"mode"); + + if (validateInputParameter("AutoBacklightMode",value) != 0) { + LOGERR("%s: Range validation failed for AutoBacklightMode\n", __FUNCTION__); + returnResponse(false); + } + + if (isPlatformSupport("AutoBacklightMode") != 0) { + returnResponse(false); + } + + if (parsingSetInputArgument(parameters,"AutoBacklightMode",inputInfo) != 0) { + LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__); + returnResponse(false); + } + + if( !isCapablityCheckPassed( "AutoBacklightMode",inputInfo )) { + LOGERR("%s: CapablityCheck failed for AutoBacklightMode\n", __FUNCTION__); + returnResponse(false); + } + + if(!value.compare("Manual")) { + mode = tvBacklightMode_MANUAL; + } + else if (!value.compare("Ambient")) { + mode = tvBacklightMode_AMBIENT; + } + else { + returnResponse(false); + } + + tvError_t ret = SetCurrentBacklightMode (mode); + + if(ret != tvERROR_NONE) { + returnResponse(false); + } + else { + //Save AutoBacklightMode to localstore + + tr181ErrorCode_t err = setLocalParam(rfc_caller_id, AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, value.c_str()); + if ( err != tr181Success ) { + LOGERR("setLocalParam for %s Failed : %s\n", AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, getTR181ErrorString(err)); + returnResponse(false); + } + else { + LOGINFO("setLocalParam for %s Successful, Value: %s\n", AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, value.c_str()); + } + LOGINFO("Exit : SetAutoBacklightMode() value : %s\n",value.c_str()); + returnResponse(true); + } + } + + uint32_t AVOutputTV::getAutoBacklightMode(const JsonObject& parameters, JsonObject& response) + { + + TR181_ParamData_t param; + + if (isPlatformSupport("AutoBacklightMode") != 0) { + returnResponse(false); + } + + tr181ErrorCode_t err = getLocalParam(rfc_caller_id, AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, ¶m); + if (err!= tr181Success) { + returnResponse(false); + } + else { + std::string s; + s+=param.value; + response["mode"] = s; + LOGINFO("Exit getAutoBacklightMode(): %s\n",s.c_str()); + returnResponse(true); + } + + } + + uint32_t AVOutputTV::resetAutoBacklightMode(const JsonObject& parameters, JsonObject& response) + { + LOGINFO("Entry\n"); + + tvError_t ret = tvERROR_NONE; + + if (isPlatformSupport("AutoBacklightMode") != 0) { + returnResponse(false); + } + + tr181ErrorCode_t err = clearLocalParam(rfc_caller_id,AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM); + if ( err != tr181Success ) { + LOGWARN("clearLocalParam for %s Failed : %s\n", AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, getTR181ErrorString(err)); + ret = tvERROR_GENERAL; + } + else { + LOGINFO("clearLocalParam for %s Successful\n", AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM); + + TR181_ParamData_t param; + memset(¶m, 0, sizeof(param)); + + tr181ErrorCode_t err = getLocalParam(rfc_caller_id, AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM,¶m); + if ( err != tr181Success ) { + LOGWARN("getLocalParam for %s Failed : %s\n", AVOUTPUT_AUTO_BACKLIGHT_MODE_RFC_PARAM, getTR181ErrorString(err)); + ret = tvERROR_GENERAL; + } + else { + tvBacklightMode_t blMode = tvBacklightMode_NONE; + + if(!std::string(param.value).compare("none")) { + blMode = tvBacklightMode_NONE; + } + else if (!std::string(param.value).compare("Manual")){ + blMode = tvBacklightMode_MANUAL; + } + else if (!std::string(param.value).compare("Ambient")){ + blMode = tvBacklightMode_AMBIENT; + } + else if (!std::string(param.value).compare("Eco")){ + blMode = tvBacklightMode_ECO; + } + else { + blMode = tvBacklightMode_NONE; + } + ret = SetCurrentBacklightMode(blMode); + if(ret != tvERROR_NONE) { + LOGWARN("Autobacklight Mode set failed: %s\n",getErrorString(ret).c_str()); + } + else { + LOGINFO("Exit : Autobacklight Mode set successfully, value: %s\n", param.value); + } + } + } + if(ret != tvERROR_NONE) + { + returnResponse(false); + } + else + { + returnResponse(true); + } + } + uint32_t AVOutputTV::getVideoSource(const JsonObject& parameters,JsonObject& response) { LOGINFO("Entry\n"); diff --git a/AVOutput/AVOutputTV.h b/AVOutput/AVOutputTV.h index 0c390651..5e493068 100644 --- a/AVOutput/AVOutputTV.h +++ b/AVOutput/AVOutputTV.h @@ -68,6 +68,10 @@ #define STRING_FORMAT "Format." #define STRING_DEFAULT "Default" #define STRING_SOURCE "Source." +#define STRING_COMPONENT "Component." +#define STRING_COLOR "Color." +#define STRING_CONTROL "Control." +#define STRING_COLORTEMPERATURE "ColorTemperature." #define CREATE_DIRTY(__X__) (__X__+=STRING_DIRTY) #define CAPABLITY_FILE_NAME "pq_capabilities.ini" @@ -116,6 +120,61 @@ class CIniFile namespace WPEFramework { namespace Plugin { +typedef struct +{ + std::string range; + std::string pqmode; + std::string format; + std::string source; + std::string isPlatformSupport; + std::string index; + std::string color; + std::string component; + std::string colorTemperature; + std::string control; +}capDetails_t; + +typedef struct +{ + std::vector rangeVector; + std::vector pqmodeVector; + std::vector formatVector; + std::vector sourceVector; + std::vector isPlatformSupportVector; + std::vector indexVector; + std::vector colorVector; + std::vector componentVector; + std::vector colorTempVector; + std::vector controlVector; +}capVectors_t; + + +typedef struct +{ + std::vector rangeValues; + std::vector pqmodeValues; + std::vector formatValues; + std::vector sourceValues; + std::vector isPlatformSupportValues; + std::vector indexValues; + std::vector colorValues; + std::vector componentValues; + std::vector colorTempValues; + std::vector controlValues; +}valueVectors_t; + +typedef struct +{ + uint8_t sourceIndex; + uint8_t pqmodeIndex; + uint8_t formatIndex; + uint8_t colorIndex; + uint8_t componentIndex; + uint8_t colorTempIndex; + uint8_t controlIndex; +}paramIndex_t; + + //class AVOutputTV : public PluginHost::IPlugin, public PluginHost::JSONRPC { class AVOutputTV : public AVOutputBase { private: @@ -142,6 +201,10 @@ class AVOutputTV : public AVOutputBase { DECLARE_JSON_RPC_METHOD(getLowLatencyState) DECLARE_JSON_RPC_METHOD(getZoomMode) DECLARE_JSON_RPC_METHOD(getVideoContentType) + DECLARE_JSON_RPC_METHOD(getCMS) + DECLARE_JSON_RPC_METHOD(getHDRMode) + DECLARE_JSON_RPC_METHOD(get2PointWB) + DECLARE_JSON_RPC_METHOD(getAutoBacklightMode) /*Get Capability API's*/ @@ -161,6 +224,10 @@ class AVOutputTV : public AVOutputBase { DECLARE_JSON_RPC_METHOD(getVideoResolutionCaps) DECLARE_JSON_RPC_METHOD(getLowLatencyStateCaps) DECLARE_JSON_RPC_METHOD(getZoomModeCaps) + DECLARE_JSON_RPC_METHOD(getCMSCaps) + DECLARE_JSON_RPC_METHOD(get2PointWBCaps) + DECLARE_JSON_RPC_METHOD(getHDRModeCaps) + DECLARE_JSON_RPC_METHOD(getAutoBacklightModeCaps) /*Set API's*/ DECLARE_JSON_RPC_METHOD(setBacklight) @@ -176,7 +243,11 @@ class AVOutputTV : public AVOutputBase { DECLARE_JSON_RPC_METHOD(setLowLatencyState) DECLARE_JSON_RPC_METHOD(setZoomMode) DECLARE_JSON_RPC_METHOD(setWBCtrl ) - DECLARE_JSON_RPC_METHOD(signalFilmMakerMode) + DECLARE_JSON_RPC_METHOD(setHDRMode ) + DECLARE_JSON_RPC_METHOD(setCMS ) + DECLARE_JSON_RPC_METHOD(set2PointWB ) + DECLARE_JSON_RPC_METHOD(signalFilmMakerMode) + DECLARE_JSON_RPC_METHOD(setAutoBacklightMode) /*Reset API's*/ DECLARE_JSON_RPC_METHOD(resetBacklight) @@ -191,6 +262,10 @@ class AVOutputTV : public AVOutputBase { DECLARE_JSON_RPC_METHOD(resetPictureMode ) DECLARE_JSON_RPC_METHOD(resetLowLatencyState) DECLARE_JSON_RPC_METHOD(resetZoomMode) + DECLARE_JSON_RPC_METHOD(resetHDRMode) + DECLARE_JSON_RPC_METHOD(resetCMS) + DECLARE_JSON_RPC_METHOD(reset2PointWB) + DECLARE_JSON_RPC_METHOD(resetAutoBacklightMode) private: @@ -200,22 +275,26 @@ class AVOutputTV : public AVOutputBase { int getSourceIndex(std::string source); int getFormatIndex(std::string format); int getPqParamIndex(); - int getParamIndex(string source,string pqmode,string format,int& sourceIndex,int& pqmodeIndex,int& formatIndex); + int getParamIndex(std::string param, capDetails_t& paramInfo, paramIndex_t& indexInfo); int getDolbyModeIndex(const char * dolbyMode); + int getHDRModeIndex(const std::string HDRMode, const std::string format,tvDolbyMode_t &value); tvDimmingMode_t getDimmingModeIndex(string mode); bool isIncluded(const std::set set1,const std::set set2); bool isSetRequired(std::string pqmode,std::string source,std::string format); int isPlatformSupport(std::string pqparam); - void spliltCapablities( std::vector &range,std::vector &pqmode,std::vector &format,std::vector &source, std::vector &index,std::string rangeInfo, std::string pqmodeInfo, std::string formatInfo, std::string sourceInfo, std::string indexInfo); - bool isCapablityCheckPassed( std::string pqmodeInputInfo,std::string sourceInputInfo,std::string formatInputInfo,std::string param ); - int parsingSetInputArgument(const JsonObject& parameters, std::string pqparam,std::string & source, std::string & pqmode, std::string & format); - int parsingGetInputArgument(const JsonObject& parameters, std::string pqparam,std::string & source, std::string & pqmode, std::string & format); + + bool isCapablityCheckPassed( std::string param, capDetails_t inputInfo ); + int parsingSetInputArgument(const JsonObject& parameters, std::string pqparam,capDetails_t& paramInfo); + int parsingGetInputArgument(const JsonObject& parameters, std::string pqparam, capDetails_t& info); + void spliltCapablities( capVectors_t& vectorInfo, capDetails_t stringInfo); void spliltStringsAndConvertToSet( std::string pqmodeInfo,std::string formatInfo,std::string sourceInfo,std::set &pqmode, std::set &format, std::set &source); int validateIntegerInputParameter(std::string param, int inputValue); - int fetchCapablities(string pqparam, string & source, string & pqmode, string & format); + int fetchCapablities(string pqparam, capDetails_t& info); int validateInputParameter(std::string param, std::string inputValue); + int validateWBParameter(std::string param,std::string control,int inputValue); + int validateCMSParameter(std::string component,int inputValue); /* AVoutput ini file default entries */ void locatePQSettingsFile(void); @@ -225,7 +304,7 @@ class AVOutputTV : public AVOutputBase { std::string convertToString(std::vector vec_strings); void convertParamToLowerCase(std::string &source, std::string &pqmode, std::string &format); - int convertToValidInputParameter(std::string pqparam, std::string & source, std::string & pqmode, std::string & format); + int convertToValidInputParameter(std::string pqparam, capDetails_t& info); string convertSourceIndexToString(int source); string convertVideoFormatToString(int format); string convertPictureIndexToString(int pqmode); @@ -235,36 +314,37 @@ class AVOutputTV : public AVOutputBase { void convertUserScaleBacklightToDriverScale(int format,int * params); /* Update TR181 with new values when app calls set/reset calls */ - tvError_t updateAVoutputTVParamToHAL(std::string forParam, int source, int pqmode, int format, int value,bool setNotDelete); + tvError_t updateAVoutputTVParamToHAL(std::string forParam, paramIndex_t indexInfo, int value,bool setNotDelete); /* updatePQParamsToCache will call updatePQParamToLocalCache for writing to TR181. * it will call TVSettings HAL for setting/saving the value * Will be called whenever the application invokes set/reset call */ - int updateAVoutputTVParam( std::string action, std::string tr181ParamName, std::string pqmode, std::string source, std::string format, tvPQParameterIndex_t pqParamIndex, int params[] ); + int updateAVoutputTVParam( std::string action, std::string tr181ParamName, capDetails_t info, tvPQParameterIndex_t pqParamIndex, int level ); /* Every bootup this function is called to sync TR181 to TVSettings HAL for saving the value */ tvError_t syncAvoutputTVParamsToHAL(std::string pqmode, std::string source, std::string format); /* Every Bootup this function is called to sync TR181 to TVSettings HAL for saving the picture mode assiocation to source */ int syncAvoutputTVPQModeParamsToHAL(std::string pqmode, std::string source, std::string format); + void syncCMSParams( ); + void syncWBParams( ); - uint32_t generateStorageIdentifier(std::string &key, std::string forParam,int contentFormat, int pqmode, int source); + uint32_t generateStorageIdentifier(std::string &key, std::string forParam,paramIndex_t info); + uint32_t generateStorageIdentifierCMS(std::string &key, std::string forParam, paramIndex_t info); + uint32_t generateStorageIdentifierWB(std::string &key, std::string forParam, paramIndex_t info); uint32_t generateStorageIdentifierDirty(std::string &key, std::string forParam,uint32_t contentFormat, int pqmode); std::string getErrorString (tvError_t eReturn); /* Get function to query TR181 entries or pq capability.ini file*/ - int getSaveConfig(std::string pqmode, std::string source, std::string format,std::vector &sources,std::vector &picturemodes, std::vector &formats); - int getLocalparam(std::string forParam,int formatIndex,int pqIndex,int sourceIndex,int &value, - tvPQParameterIndex_t pqParamIndex ,bool cms=false,int tunnel_type=0); + int getSaveConfig(std::string param, capDetails_t capInfo, valueVectors_t &values); + int getLocalparam( std::string forParam,paramIndex_t indexInfo,int & value,tvPQParameterIndex_t pqParamIndex,bool sync=false); + tvDataComponentColor_t getComponentColorEnum(std::string colorName); int getDolbyParams(tvContentFormatType_t format, std::string &s, std::string source = ""); - tvError_t getParamsCaps(std::vector &range, std::vector &pqmode, std::vector &source, std::vector &format,std::string param ); - tvError_t getParamsCaps(std::vector &range, std::vector &pqmode, std::vector &source, - std::vector &format,std::string param , std::string & isPlatformSupport, - std::vector & index); + tvError_t getParamsCaps(std::string param, capVectors_t &vecInfo); int GetPanelID(char *panelid); int ConvertHDRFormatToContentFormat(tvhdr_type_t hdrFormat); - int ReadCapablitiesFromConf(std::string &rangeInfo,std::string &pqmodeInfo,std::string &formatInfo,std::string &sourceInfo,std::string param, std::string & isPlatformSupport, std::string & indexInfo); + int ReadCapablitiesFromConf(std::string param, capDetails_t& info); void getDimmingModeStringFromEnum(int value, std::string &toStore); void getColorTempStringFromEnum(int value, std::string &toStore); int getCurrentPictureMode(char *picMode); @@ -273,11 +353,26 @@ class AVOutputTV : public AVOutputBase { std::string getDolbyModeStringFromEnum( tvDolbyMode_t mode); JsonArray getSupportedVideoSource(void); int getAvailableCapabilityModesWrapper(std::string param, std::string & outparam); - int getAvailableCapabilityModes(std::string & source, std::string & pqmode, std::string & format); + int getAvailableCapabilityModes( capDetails_t& info ); int getCapabilitySource(JsonArray &rangeArray); int getRangeCapability(std::string param, std::vector & rangeInfo); void getDynamicAutoLatencyConfig(); tvError_t getUserSelectedAspectRatio (tvDisplayMode_t* mode); + std::string getColorTemperatureStringFromEnum(tvColorTemp_t value); + std::string getCMSColorStringFromEnum(tvDataComponentColor_t value); + std::string getCMSComponentStringFromEnum(tvComponentType_t value); + std::string getWBControlStringFromEnum(tvWBControl_t value); + int getCMSColorEnumFromString(std::string color,tvDataComponentColor_t &value); + int getCMSComponentEnumFromString(std::string component, tvComponentType_t& value); + std::string getWBColorStringFromEnum(tvWBColor_t value); + int getWBColorEnumFromString(std::string color,tvWBColor_t& value); + int getWBControlEnumFromString(std::string color,tvWBControl_t& value); + int getColorTempEnumFromString(std::string color, tvColorTemp_t& value); + + bool checkCMSColorAndComponentCapability(const std::string capValue, const std::string inputValue); + int convertCMSParamToPQEnum(const std::string component, const std::string color,tvPQParameterIndex_t& value); + int convertWBParamToPQEnum(const std::string control, const std::string color,tvPQParameterIndex_t& value); + int convertWBParamToRGBEnum(const std::string color,const std::string control,tvRGBType_t &value); void broadcastLowLatencyModeChangeEvent(bool lowLatencyMode); tvError_t setAspectRatioZoomSettings(tvDisplayMode_t mode); @@ -313,6 +408,7 @@ class AVOutputTV : public AVOutputBase { void DeinitializeIARM(); }; + }//namespace Plugin }//namespace WPEFramework #endif diff --git a/AVOutput/AVOutputTVHelper.cpp b/AVOutput/AVOutputTVHelper.cpp index d5536fbf..7e3b28c5 100644 --- a/AVOutput/AVOutputTVHelper.cpp +++ b/AVOutput/AVOutputTVHelper.cpp @@ -22,6 +22,8 @@ #include "UtilsIarm.h" #include "rfcapi.h" +#define CAPABLITY_FILE_NAME "pq_capabilities.ini" + static std::map supportedSourcemap; static std::map supportedPictureModemap; static std::map supportedFormatmap; @@ -104,19 +106,14 @@ namespace Plugin { int AVOutputTV::getPqParamIndex() { - std::vector localpq; - std::vector localformat; - std::vector localsource; - std::vector localrange; - std::string platformsupport; - std::vector index; - - tvError_t ret = getParamsCaps(localrange, localpq, localformat, localsource, - "VideoSource", platformsupport, index); + + capVectors_t info; + + tvError_t ret = getParamsCaps("VideoSource", info); if (ret == tvERROR_NONE) { - if (localrange.size() == index.size()) { - for (unsigned int i = 0; i< localrange.size(); i++) { - supportedSourcemap[localrange[i]] = stoi(index[i]); + if (info.rangeVector.size() == info.indexVector.size()) { + for (unsigned int i = 0; i< info.rangeVector.size(); i++) { + supportedSourcemap[info.rangeVector[i]] = stoi(info.indexVector[i]); } } } @@ -124,28 +121,18 @@ namespace Plugin { LOGERR("%s: Failed to fetch the source index \n", __FUNCTION__); return -1; } - if (!localpq.empty()) { - localpq.clear(); - } - if (!localformat.empty()) { - localformat.clear(); - } - if (!localsource.empty()) { - localsource.clear(); - } - if (!localrange.empty()) { - localrange.clear(); - } - if(!index.empty()) { - index.clear(); - } + + info.pqmodeVector.clear(); + info.sourceVector.clear(); + info.formatVector.clear(); + info.indexVector.clear(); + info.rangeVector.clear(); - ret = getParamsCaps(localrange, localpq, localformat, localsource, - "PictureMode", platformsupport, index); + ret = getParamsCaps("PictureMode", info); if (ret == tvERROR_NONE) { - if (localrange.size() == index.size()) { - for (unsigned int i = 0; i< localrange.size(); i++) { - supportedPictureModemap[localrange[i]] = stoi(index[i]); + if (info.rangeVector.size() == info.indexVector.size()) { + for (unsigned int i = 0; i< info.rangeVector.size(); i++) { + supportedPictureModemap[info.rangeVector[i]] = stoi(info.indexVector[i]); } } } @@ -153,28 +140,18 @@ namespace Plugin { LOGERR("%s: Failed to fetch the picture index \n", __FUNCTION__); return -1; } - if (!localpq.empty()) { - localpq.clear(); - } - if (!localformat.empty()) { - localformat.clear(); - } - if (!localsource.empty()) { - localsource.clear(); - } - if (!localrange.empty()) { - localrange.clear(); - } - if(!index.empty()) { - index.clear(); - } + + info.pqmodeVector.clear(); + info.sourceVector.clear(); + info.formatVector.clear(); + info.indexVector.clear(); + info.rangeVector.clear(); - ret = getParamsCaps(localrange, localpq, localformat, localsource, - "VideoFormat", platformsupport, index); + ret = getParamsCaps( "VideoFormat", info); if (ret == tvERROR_NONE) { - if (localrange.size() == index.size()) { - for (unsigned int i = 0; i< localrange.size(); i++) { - supportedFormatmap[localrange[i]] = stoi(index[i]); + if ( info.rangeVector.size() == info.indexVector.size()) { + for (unsigned int i = 0; i< info.rangeVector.size(); i++) { + supportedFormatmap[info.rangeVector[i]] = stoi(info.indexVector[i]); } } } @@ -186,50 +163,101 @@ namespace Plugin { return 0; } - int AVOutputTV::getParamIndex(string source,string pqmode,string format,int& sourceIndex,int& pqmodeIndex,int& formatIndex) + int AVOutputTV::getParamIndex(std::string param, capDetails_t& paramInfo, paramIndex_t& indexInfo) { - LOGINFO("Entry : %s pqmode : %s source :%s format :%s\n",__FUNCTION__,pqmode.c_str(),source.c_str(),format.c_str()); + LOGINFO("Entry : %s param : %s pqmode : %s source :%s format :%s\n",__FUNCTION__,param.c_str(),paramInfo.pqmode.c_str(),paramInfo.source.c_str(),paramInfo.format.c_str()); - if( source.compare("none") == 0 || source.compare("Current") == 0 ) { + if( paramInfo.source.compare("none") == 0 || paramInfo.source.compare("Current") == 0 ) { tvVideoSrcType_t currentSource = VIDEO_SOURCE_IP; GetCurrentVideoSource(¤tSource); - sourceIndex = (int)currentSource; + indexInfo.sourceIndex = (int)currentSource; } else { - sourceIndex = getSourceIndex(source); + indexInfo.sourceIndex = getSourceIndex(paramInfo.source); } - if( pqmode.compare("none") == 0 || pqmode.compare("Current") == 0) { + if( paramInfo.pqmode.compare("none") == 0 || paramInfo.pqmode.compare("Current") == 0) { char picMode[PIC_MODE_NAME_MAX]={0}; if(!getCurrentPictureMode(picMode)) { LOGERR("Failed to get the Current picture mode\n"); } else { std::string local = picMode; - pqmodeIndex = getPictureModeIndex(local); + indexInfo.pqmodeIndex = getPictureModeIndex(local); } } else { - pqmodeIndex = getPictureModeIndex(pqmode); + indexInfo.pqmodeIndex = getPictureModeIndex(paramInfo.pqmode); } - if( format.compare("none") == 0 || format.compare("Current") == 0) { + if( paramInfo.format.compare("none") == 0 || paramInfo.format.compare("Current") == 0) { tvVideoFormatType_t currentFormat = VIDEO_FORMAT_NONE; GetCurrentVideoFormat(¤tFormat); if( VIDEO_FORMAT_NONE == currentFormat ) { - formatIndex = VIDEO_FORMAT_SDR; + indexInfo.formatIndex = VIDEO_FORMAT_SDR; } else { - formatIndex = (int)currentFormat; + indexInfo.formatIndex = (int)currentFormat; } } else { - formatIndex = getFormatIndex(format); + indexInfo.formatIndex = getFormatIndex(paramInfo.format); } - if (sourceIndex == -1 || pqmodeIndex == -1 || formatIndex == -1) { - return -1; - } - LOGINFO("%s: Exit sourceIndex = %d pqmodeIndex = %d formatIndex = %d\n",__FUNCTION__,sourceIndex,pqmodeIndex,formatIndex); + if(param == "CMS") + { + tvDataComponentColor_t level = tvDataColor_NONE; + if ( getCMSColorEnumFromString(paramInfo.color,level ) == -1 ) { + LOGERR("%s : GetColorEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + indexInfo.colorIndex = level; + + tvComponentType_t componentLevel; + if ( getCMSComponentEnumFromString(paramInfo.component,componentLevel ) == -1 ) { + LOGERR("%s : GetComponentEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + indexInfo.componentIndex = componentLevel; + + LOGINFO("%s colorIndex : %d , componentIndex : %d\n",__FUNCTION__,indexInfo.colorIndex, indexInfo.componentIndex); + } + + if(param == "WhiteBalance") + { + tvWBColor_t level; + if ( getWBColorEnumFromString(paramInfo.color,level ) == -1 ) { + LOGERR("%s : GetColorEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + indexInfo.colorIndex = level; + + tvWBControl_t controlLevel; + if ( getWBControlEnumFromString(paramInfo.control,controlLevel ) == -1 ) { + LOGERR("%s : GetComponentEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + indexInfo.controlIndex = controlLevel; + + /*tvColorTemp_t colorTemp; + if ( getColorTempEnumFromString(paramInfo.colorTemperature,colorTemp ) == -1 ) { + LOGERR("%s : GetComponentEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + + indexInfo.colorTempIndex = colorTemp; */ + + LOGINFO("%s colorIndex : %d , controlIndex : %d \n",__FUNCTION__,indexInfo.colorIndex, indexInfo.controlIndex); + + } + + if (indexInfo.sourceIndex == -1 || indexInfo.pqmodeIndex == -1 || indexInfo.formatIndex == -1) { + return -1; + } + LOGINFO("%s: Exit sourceIndex = %d pqmodeIndex = %d formatIndex = %d\n",__FUNCTION__,indexInfo.sourceIndex,indexInfo.pqmodeIndex,indexInfo.formatIndex); return 0; } @@ -251,16 +279,44 @@ namespace Plugin { mode = dolbyModes[count]; break; } - } } else { mode = -1; printf("(%s):get supported mode is failed\n", __func__); } - return mode; } + int AVOutputTV::getHDRModeIndex(const std::string HDRMode, const std::string format,tvDolbyMode_t &value) { + // Create a map to associate format-mode pairs with enum values + int ret = 0; + static const std::unordered_map hdrModeIndexMap = { + {"DVDark", tvDolbyMode_Dark}, + {"DVBright", tvDolbyMode_Bright}, + {"DVGame", tvDolbyMode_Game}, + {"HDR10Dark", tvHDR10Mode_Dark}, + {"HDR10Bright", tvHDR10Mode_Bright}, + {"HDR10Game", tvHDR10Mode_Game}, + {"HLGDark", tvHLGMode_Dark}, + {"HLGBright", tvHLGMode_Bright}, + {"HLGGame", tvHLGMode_Game} + }; + + // Create the key by concatenating the format and HDRMode + std::string key = format+HDRMode; + + // Look up the key in the map + auto it = hdrModeIndexMap.find(key); + if (it != hdrModeIndexMap.end()) { + value = it->second; + ret = 0; + } else { + LOGERR("%s : Invalid format/mode\n",__FUNCTION__); + ret = -1; + } + return ret; + } + tvDimmingMode_t AVOutputTV::getDimmingModeIndex(std::string mode) { tvDimmingMode_t index = tvDimmingMode_MAX; @@ -337,21 +393,16 @@ namespace Plugin { int AVOutputTV::isPlatformSupport(std::string pqparam) { - std::vector range; - std::vector sourceVec; - std::vector pqmodeVec; - std::vector formatVec; - std::string isPlatformSupport; - std::vector index; + capVectors_t vectorInfo; - tvError_t ret = getParamsCaps(range, pqmodeVec, sourceVec, formatVec, pqparam, isPlatformSupport, index); + tvError_t ret = getParamsCaps(pqparam,vectorInfo); if (ret != tvERROR_NONE) { LOGINFO("%s: failed to get the capability \n", __FUNCTION__); return -1; } else { - if(isPlatformSupport.compare("true") != 0) { + if(vectorInfo.isPlatformSupportVector[0].compare("true") != 0) { LOGERR("%s: platform support not available\n", __FUNCTION__); return -1; } @@ -359,51 +410,37 @@ namespace Plugin { return 0; } - void AVOutputTV::spliltCapablities( std::vector &range,std::vector &pqmode,std::vector &format, - std::vector &source, std::vector &index, std::string rangeInfo, - std::string pqmodeInfo, std::string formatInfo, std::string sourceInfo, std::string indexInfo) + void AVOutputTV::spliltCapablities( capVectors_t& vectorInfo, capDetails_t stringInfo) { - std::string token; - std::stringstream rangeStream(rangeInfo); - std::stringstream pqmodeStream(pqmodeInfo); - std::stringstream formatStream(formatInfo); - std::stringstream sourceStream(sourceInfo); - std::stringstream indexStream(indexInfo); - - while( getline(rangeStream,token,',')) { - range.push_back(token ); - token.clear(); - } - - while( getline(pqmodeStream,token,',') ) { - pqmode.push_back(token ); - token.clear(); - } - - while( getline(formatStream,token,',')) { - format.push_back( token ); - token.clear(); - } - while( getline(sourceStream,token,',') ) { - source.push_back( token ); - token.clear(); - } - - while( getline(indexStream,token,',') ) { - index.push_back( token ); - token.clear(); + std::vector&>> streamVector; + + // Initializing the streamVector with stringstreams and corresponding vectors + streamVector.push_back({std::stringstream(stringInfo.range), vectorInfo.rangeVector}); + streamVector.push_back({std::stringstream(stringInfo.pqmode), vectorInfo.pqmodeVector}); + streamVector.push_back({std::stringstream(stringInfo.format), vectorInfo.formatVector}); + streamVector.push_back({std::stringstream(stringInfo.source), vectorInfo.sourceVector}); + streamVector.push_back({std::stringstream(stringInfo.isPlatformSupport), vectorInfo.isPlatformSupportVector}); + streamVector.push_back({std::stringstream(stringInfo.index), vectorInfo.indexVector}); + streamVector.push_back({std::stringstream(stringInfo.color), vectorInfo.colorVector}); + streamVector.push_back({std::stringstream(stringInfo.component), vectorInfo.componentVector}); + streamVector.push_back({std::stringstream(stringInfo.colorTemperature), vectorInfo.colorTempVector}); + streamVector.push_back({std::stringstream(stringInfo.control), vectorInfo.controlVector}); + + for (auto& pair : streamVector) { + std::stringstream& ss = pair.first; + std::vector& vec = pair.second; + + std::string token; + while (getline(ss, token, ',')) { + vec.push_back(token); + } } } - - bool AVOutputTV::isCapablityCheckPassed( std::string pqmodeInputInfo,std::string sourceInputInfo,std::string formatInputInfo,std::string param ) + + bool AVOutputTV::isCapablityCheckPassed( std::string param, capDetails_t inputInfo ) { - std::string rangeCapInfo; - std::string sourceCapInfo; - std::string formatCapInfo; - std::string pqmodeCapInfo; - std::string isPlatformSupport; - std::string indexInfo; + capDetails_t paramInfo; std::set pqmodeCapSet; std::set formatCapSet; @@ -412,17 +449,38 @@ namespace Plugin { std::set formatInputSet; std::set sourceInputSet; - if( ReadCapablitiesFromConf( rangeCapInfo, pqmodeCapInfo, formatCapInfo, sourceCapInfo,param, isPlatformSupport, indexInfo) ) { + + if( ReadCapablitiesFromConf( param, paramInfo ) != 0 ) { LOGINFO( "%s: readCapablitiesFromConf Failed !!!\n",__FUNCTION__); return false; } + + if( param == "CMS") + { + // Check color + if (! checkCMSColorAndComponentCapability(paramInfo.color, inputInfo.color)) { + LOGINFO( "%s:CMS color Capablity Failed CapColor : %s inputColor : %s!!!\n",__FUNCTION__,paramInfo.color.c_str(), inputInfo.color.c_str()); + return false; + } + + // Check component + if (! checkCMSColorAndComponentCapability(paramInfo.component, inputInfo.component)) { + LOGINFO( "%s:CMS component Capablity capComponent : %s inputComponent : %s Failed!!!.\n",__FUNCTION__,paramInfo.component.c_str(), inputInfo.component.c_str()); + return false; + } + } + else if( param == "WhiteBalance") + { + if ( ( paramInfo.color.find(inputInfo.color) == std::string::npos ) || ( paramInfo.control.find(inputInfo.control) == std::string::npos) ) + return false; + } //Compare capablityInfo with Input params //1.convertCapablity Info to set for comparison - spliltStringsAndConvertToSet( pqmodeCapInfo, formatCapInfo, sourceCapInfo, pqmodeCapSet, formatCapSet, sourceCapset); + spliltStringsAndConvertToSet( paramInfo.pqmode, paramInfo.format, paramInfo.source, pqmodeCapSet, formatCapSet, sourceCapset); //2.convert Application Input Info to set for comparison - spliltStringsAndConvertToSet( pqmodeInputInfo, formatInputInfo, sourceInputInfo, pqmodeInputSet, formatInputSet, sourceInputSet ); + spliltStringsAndConvertToSet( inputInfo.pqmode, inputInfo.format, inputInfo.source, pqmodeInputSet, formatInputSet, sourceInputSet ); //3.Compare Each pqmode/format/source InputInfo against CapablityInfo if ( isIncluded(pqmodeCapSet,pqmodeInputSet) && isIncluded(formatCapSet,formatInputSet) && isIncluded(sourceCapset,sourceInputSet) ) { @@ -435,8 +493,7 @@ namespace Plugin { } } - int AVOutputTV::parsingSetInputArgument(const JsonObject& parameters, std::string pqparam, std::string & source, - std::string & pqmode, std::string & format) { + int AVOutputTV::parsingSetInputArgument(const JsonObject& parameters, std::string pqparam,capDetails_t& paramInfo) { JsonArray sourceArray; JsonArray pqmodeArray; @@ -445,39 +502,60 @@ namespace Plugin { pqmodeArray = parameters.HasLabel("pictureMode") ? parameters["pictureMode"].Array() : JsonArray(); for (int i = 0; i < pqmodeArray.Length(); ++i) { - pqmode += pqmodeArray[i].String(); + paramInfo.pqmode += pqmodeArray[i].String(); if (i != (pqmodeArray.Length() - 1) ) { - pqmode += ","; + paramInfo.pqmode += ","; } } sourceArray = parameters.HasLabel("videoSource") ? parameters["videoSource"].Array() : JsonArray(); for (int i = 0; i < sourceArray.Length(); ++i) { - source += sourceArray[i].String(); + paramInfo.source += sourceArray[i].String(); if (i != (sourceArray.Length() - 1) ) { - source += ","; - } + paramInfo.source += ","; + } } formatArray = parameters.HasLabel("videoFormat") ? parameters["videoFormat"].Array() : JsonArray(); for (int i = 0; i < formatArray.Length(); ++i) { - format += formatArray[i].String(); + paramInfo.format += formatArray[i].String(); if (i != (formatArray.Length() - 1) ) { - format += ","; + paramInfo.format += ","; } } - if (source.empty()) { - source = "Global"; - } - if (pqmode.empty()) { - pqmode = "Global"; - } - if (format.empty()) { - format = "Global"; - } + if (paramInfo.source.empty()) { + paramInfo.source = "Global"; + } + if (paramInfo.pqmode.empty()) { + paramInfo.pqmode = "Global"; + } + if (paramInfo.format.empty()) { + paramInfo.format = "Global"; + } + + if( pqparam.compare("WhiteBalance") == 0 ) + { + if ( paramInfo.color.empty() ) + paramInfo.color = "Global"; + + if ( paramInfo.control.empty() ) + paramInfo.control = "Global"; + + if ( paramInfo.colorTemperature.empty() ) + paramInfo.colorTemperature = "Global"; + } + + if( pqparam.compare("CMS") == 0 ) + { + if ( paramInfo.color.empty() ) + paramInfo.color = "Global"; + + if ( paramInfo.component.empty() ) + paramInfo.component = "Global"; + } - if (convertToValidInputParameter(pqparam, source, pqmode, format) != 0) { + if (convertToValidInputParameter(pqparam, paramInfo) != 0) { LOGERR("%s: Failed to convert the input paramters. \n", __FUNCTION__); return -1; } @@ -485,30 +563,30 @@ namespace Plugin { return 0; } - int AVOutputTV::parsingGetInputArgument(const JsonObject& parameters, std::string pqparam, - std::string & source, std::string & pqmode, std::string & format) { - pqmode = parameters.HasLabel("pictureMode") ? parameters["pictureMode"].String() : ""; + int AVOutputTV::parsingGetInputArgument(const JsonObject& parameters, std::string pqparam, capDetails_t& info) + { + info.pqmode = parameters.HasLabel("pictureMode") ? parameters["pictureMode"].String() : ""; - source = parameters.HasLabel("videoSource") ? parameters["videoSource"].String() : ""; + info.source = parameters.HasLabel("videoSource") ? parameters["videoSource"].String() : ""; - format = parameters.HasLabel("videoFormat") ? parameters["videoFormat"].String() : ""; + info.format = parameters.HasLabel("videoFormat") ? parameters["videoFormat"].String() : ""; - if ( (source.compare("Global") == 0) || (pqmode.compare("Global") == 0) || (format.compare("Global") == 0) ) { + if ( (info.source.compare("Global") == 0) || (info.pqmode.compare("Global") == 0) || (info.format.compare("Global") == 0) ) { LOGERR("%s: get cannot fetch the Global inputs \n", __FUNCTION__); return -1; } - if (source.empty()) { - source = "Current"; - } - if (pqmode.empty()) { - pqmode = "Current"; - } - if (format.empty()) { - format = "Current"; - } + if (info.source.empty()) { + info.source = "Current"; + } + if (info.pqmode.empty()) { + info.pqmode = "Current"; + } + if (info.format.empty()) { + info.format = "Current"; + } - if (convertToValidInputParameter(pqparam,source, pqmode, format) != 0) { + if (convertToValidInputParameter(pqparam,info) != 0) { LOGERR("%s: Failed to convert the input paramters. \n", __FUNCTION__); return -1; } @@ -541,13 +619,8 @@ namespace Plugin { int AVOutputTV::validateIntegerInputParameter(std::string param, int inputValue) { - - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; - - tvError_t ret = getParamsCaps(range, pqmode, source, format, param); + capVectors_t info; + tvError_t ret = getParamsCaps(param, info); if (ret != tvERROR_NONE) { LOGERR("Failed to fetch the range capability[%s] \n", param.c_str()); @@ -557,9 +630,9 @@ namespace Plugin { if ( (param == "Brightness") || (param == "Contrast") || (param == "Sharpness") || (param == "Saturation") || (param == "Hue") || (param == "WhiteBalance") || - (param == "ComponentSaturation") || (param == "Backlight") || - (param == "ComponentHue") || (param == "ComponentLuma") || (param == "LowLatencyState") ) { - if (inputValue < stoi(range[0]) || inputValue > stoi(range[1])) { + (param == "CMS") || (param == "Backlight") || + (param == "WhiteBalance") || (param == "LowLatencyState") ) { + if (inputValue < stoi(info.rangeVector[0]) || inputValue > std::stoi(info.rangeVector[1])) { LOGERR("wrong Input value[%d]", inputValue); return -1; } @@ -567,32 +640,45 @@ namespace Plugin { return 0; } - int AVOutputTV::fetchCapablities(string pqparam, string & source, string & pqmode, string & format) { + int AVOutputTV::fetchCapablities(string pqparam, capDetails_t& info) { - std::vector range; - std::vector sourceVec; - std::vector pqmodeVec; - std::vector formatVec; + capVectors_t vectorInfo; tvError_t ret = tvERROR_NONE; - ret = getParamsCaps(range, pqmodeVec, sourceVec, formatVec, pqparam); + ret = getParamsCaps(pqparam, vectorInfo); if (ret != tvERROR_NONE) { LOGINFO("%s: failed to get the capability \n", __FUNCTION__); return -1; } - if (sourceVec.size() != 0) { - source = convertToString(sourceVec); + if (vectorInfo.sourceVector.size() != 0) { + info.source = convertToString(vectorInfo.sourceVector); + } + + if (vectorInfo.pqmodeVector.size() != 0) { + info.pqmode = convertToString(vectorInfo.pqmodeVector); + } + + if (vectorInfo.formatVector.size() != 0) { + info.format = convertToString(vectorInfo.formatVector); + } + + if (vectorInfo.colorVector.size() != 0) { + info.color = convertToString(vectorInfo.colorVector); + } + + if (vectorInfo.componentVector.size() != 0) { + info.component = convertToString(vectorInfo.componentVector); } - if (pqmodeVec.size() != 0) { - pqmode = convertToString(pqmodeVec); + if (vectorInfo.controlVector.size() != 0) { + info.control = convertToString(vectorInfo.controlVector); } - if (formatVec.size() != 0) { - format = convertToString(formatVec); + if (vectorInfo.colorTempVector.size() != 0) { + info.colorTemperature = convertToString(vectorInfo.colorTempVector); } return 0; @@ -601,12 +687,9 @@ namespace Plugin { int AVOutputTV::validateInputParameter(std::string param, std::string inputValue) { - std::vector range; - std::vector pqmode; - std::vector source; - std::vector format; + capVectors_t info; - tvError_t ret = getParamsCaps(range, pqmode, source, format, param); + tvError_t ret = getParamsCaps( param, info); if (ret != tvERROR_NONE) { LOGERR("Failed to fetch the range capability[%s] \n", param.c_str()); @@ -614,12 +697,12 @@ namespace Plugin { } if ( (param == "ColorTemperature") || - (param == "DimmingMode") || (param == "AutoBacklightControl") || + (param == "DimmingMode") || (param == "AutoBacklightMode") || (param == "DolbyVisionMode") || (param == "HDR10Mode") || - (param == "HLGMode") || (param == "AspectRatio") || (param == "PictureMode") ) { - auto iter = find(range.begin(), range.end(), inputValue); + (param == "HLGMode") || (param == "AspectRatio") || (param == "PictureMode") ) { + auto iter = find(info.rangeVector.begin(), info.rangeVector.end(), inputValue); - if (iter == range.end()) { + if (iter == info.rangeVector.end()) { LOGERR("Not a valid input value[%s].\n", inputValue.c_str()); return -1; } @@ -709,49 +792,36 @@ namespace Plugin { return result; } - int AVOutputTV::convertToValidInputParameter(std::string pqparam, std::string & source, std::string & pqmode, std::string & format) + int AVOutputTV::convertToValidInputParameter(std::string pqparam, capDetails_t& info) { - LOGINFO("Entry %s source %s pqmode %s format %s \n", __FUNCTION__, source.c_str(), pqmode.c_str(), format.c_str()); + LOGINFO("Entry %s source %s pqmode %s format %s \n", __FUNCTION__, info.source.c_str(), info.pqmode.c_str(), info.format.c_str()); + capDetails_t localInfo; + if (fetchCapablities(pqparam, localInfo) != 0) { + LOGINFO("%s, Failed to get capability fo %s\n", __FUNCTION__,pqparam.c_str()); + return -1; + } + // converting pq to valid paramter format - if (pqmode == "Global") { - std::string localSource; - std::string localPqmode; - std::string localFormat; - if (fetchCapablities(pqparam, localSource, localPqmode, localFormat) == 0) { - pqmode = localPqmode; - //if pqmode none from capabilty then lets keep pqmode as global to fail the capabilty - } - else { - LOGINFO("%s, Failed to get picturemode capability\n", __FUNCTION__); - return -1; - } + if (info.pqmode == "Global") { + info.pqmode = localInfo.pqmode; } - else if (pqmode == "Current") { + else if (info.pqmode == "Current") { char picMode[PIC_MODE_NAME_MAX]={0}; if(!getCurrentPictureMode(picMode)) { LOGINFO("Failed to get the Current picture mode\n"); return -1; } else { - pqmode = picMode; + info.pqmode = picMode; } } - if (source == "Global") { - std::string localSource; - std::string localPqmode; - std::string localFormat; - if (fetchCapablities(pqparam, localSource, localPqmode, localFormat) == 0) { - source = localSource; - } - else { - LOGINFO("%s, Failed to get source capability\n", __FUNCTION__); - return -1; - } + if (info.source == "Global") { + info.source = localInfo.source; } - else if (source == "Current") { + else if (info.source == "Current") { tvVideoSrcType_t currentSource = VIDEO_SOURCE_IP; tvError_t ret = GetCurrentVideoSource(¤tSource); @@ -759,32 +829,60 @@ namespace Plugin { LOGWARN("%s: GetCurrentVideoSource( ) Failed \n",__FUNCTION__); return -1; } - source = convertSourceIndexToString(currentSource); + info.source = convertSourceIndexToString(currentSource); } //convert format into valid parameter - if (format == "Global") { - std::string localSource; - std::string localPqmode; - std::string localFormat; - if (fetchCapablities(pqparam, localSource, localPqmode, localFormat) == 0) { - format = localFormat; - } - else { - LOGINFO("%s, Failed to get format capability\n", __FUNCTION__); - return -1; - } + if (info.format == "Global") { + info.format = localInfo.format; } - else if (format == "Current") { + else if (info.format == "Current") { tvVideoFormatType_t formatIndex = VIDEO_FORMAT_NONE; GetCurrentVideoFormat(&formatIndex); if ( formatIndex == VIDEO_FORMAT_NONE) { formatIndex = VIDEO_FORMAT_SDR; - } - format = convertVideoFormatToString(formatIndex); + } + info.format = convertVideoFormatToString(formatIndex); + } + + //convert WB and CMS params + if( pqparam.compare("WhiteBalance") == 0 ) + { + if( info.control.compare("Global") == 0 ) + { + info.control = localInfo.control; + } + + if( info.color.compare("Global") == 0 ) + { + info.color = localInfo.color; + } + + if( info.colorTemperature.compare("Global") == 0 ) + { + info.colorTemperature= localInfo.colorTemperature; + } + + LOGINFO("%s : control : %s color : %s colorTemp : %s \n",__FUNCTION__,info.control.c_str(),info.color.c_str(),info.colorTemperature.c_str()); + + } + + if( pqparam.compare("CMS") == 0 ) + { + if( info.component.compare("Global") == 0 ) + { + info.component = localInfo.component; + } + + if( info.color.compare("Global") == 0 ) + { + info.color = localInfo.color; + } + + LOGINFO("%s : component : %s color : %s \n",__FUNCTION__,info.component.c_str(),info.color.c_str()); } - LOGINFO("Exit %s source %s pqmode %s format %s \n", __FUNCTION__, source.c_str(), pqmode.c_str(), format.c_str()); + LOGINFO("Exit %s source %s pqmode %s format %s \n", __FUNCTION__, info.source.c_str(), info.pqmode.c_str(), info.format.c_str()); return 0; } @@ -847,12 +945,18 @@ namespace Plugin { return ret; } - tvError_t AVOutputTV::updateAVoutputTVParamToHAL(std::string forParam, int source, int pqmode, int format, int value,bool setNotDelete) + tvError_t AVOutputTV::updateAVoutputTVParamToHAL(std::string forParam, paramIndex_t indexInfo, int value,bool setNotDelete) { tvError_t ret = tvERROR_NONE; std::string key; - generateStorageIdentifier(key,forParam,format,pqmode,source); + if( forParam.compare("CMS") == 0 ) + generateStorageIdentifierCMS(key,forParam,indexInfo); + else if( forParam.compare("WhiteBalance") == 0 ) + generateStorageIdentifierWB(key,forParam,indexInfo); + else + generateStorageIdentifier(key,forParam,indexInfo); + if(key.empty()) { LOGERR("generateStorageIdentifierDirty failed\n"); ret = tvERROR_GENERAL; @@ -867,7 +971,7 @@ namespace Plugin { else if(forParam.compare("DimmingMode") == 0 ) { getDimmingModeStringFromEnum(value, toStore); } - else if (forParam.compare("DolbyVisionMode") == 0 ) { + else if (forParam.compare("DolbyVisionMode") == 0 || forParam.compare("HDRMode") == 0 ) { toStore = getDolbyModeStringFromEnum((tvDolbyMode_t)value); } err = setLocalParam(rfc_caller_id, key.c_str(),toStore.c_str()); @@ -885,9 +989,11 @@ namespace Plugin { return ret; } - int AVOutputTV::updateAVoutputTVParam( std::string action, std::string tr181ParamName, std::string pqmode, std::string source, std::string format, tvPQParameterIndex_t pqParamIndex, int params[] ) + int AVOutputTV::updateAVoutputTVParam( std::string action, std::string tr181ParamName, capDetails_t info, tvPQParameterIndex_t pqParamIndex, int level ) { LOGINFO("Entry : %s\n",__FUNCTION__); + valueVectors_t values; + paramIndex_t paramIndex; std::vector sources; std::vector pictureModes; std::vector formats; @@ -896,14 +1002,15 @@ namespace Plugin { bool reset = !(action.compare("reset")); bool set = !(action.compare("set")); - LOGINFO("%s: Entry param : %s Action : %s pqmode : %s source :%s format :%s\n",__FUNCTION__,tr181ParamName.c_str(),action.c_str(),pqmode.c_str(),source.c_str(),format.c_str() ); - ret = getSaveConfig(pqmode, source, format, sources, pictureModes, formats); + LOGINFO("%s: Entry param : %s Action : %s pqmode : %s source :%s format :%s color:%s component:%s control:%s\n",__FUNCTION__,tr181ParamName.c_str(),action.c_str(),info.pqmode.c_str(),info.source.c_str(),info.format.c_str(),info.color.c_str(),info.component.c_str(),info.control.c_str() ); + ret = getSaveConfig(tr181ParamName,info, values); if( 0 == ret ) { - for(int sourceType: sources) { - tvVideoSrcType_t source = (tvVideoSrcType_t)sourceType; - for(int mode : pictureModes) { - for(int formatType : formats) { - tvVideoFormatType_t format = (tvVideoFormatType_t)formatType; + for( int sourceType: values.sourceValues ) { + paramIndex.sourceIndex = sourceType; + for( int modeType : values.pqmodeValues ) { + paramIndex.pqmodeIndex = modeType; + for( int formatType : values.formatValues ) { + paramIndex.formatIndex = formatType; switch(pqParamIndex) { case PQ_PARAM_BRIGHTNESS: case PQ_PARAM_CONTRAST: @@ -916,17 +1023,17 @@ namespace Plugin { case PQ_PARAM_LOWLATENCY_STATE: case PQ_PARAM_DOLBY_MODE: if(reset) { - ret |= updateAVoutputTVParamToHAL(tr181ParamName,source, mode, format,0,false); - } + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,0,false); + } if(sync || reset) { int value=0; - if(getLocalparam(tr181ParamName,format,mode,source,value,pqParamIndex,sync)) { - continue; - } - params[0]=value; + if(getLocalparam(tr181ParamName,paramIndex,value,pqParamIndex,sync)) { + continue; + } + level=value; } if(set) { - ret |= updateAVoutputTVParamToHAL(tr181ParamName,source, mode, format, params[0],true); + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,level,true); } break; default: @@ -934,53 +1041,138 @@ namespace Plugin { } switch(pqParamIndex) { case PQ_PARAM_BRIGHTNESS: - ret |= SaveBrightness(source, mode,format,params[0]); + ret |= SaveBrightness((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_CONTRAST: - ret |= SaveContrast(source, mode,format,params[0]); + ret |= SaveContrast((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_SHARPNESS: - ret |= SaveSharpness(source, mode,format,params[0]); + ret |= SaveSharpness((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_HUE: - ret |= SaveHue(source, mode,format,params[0]); + ret |= SaveHue((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_SATURATION: - ret |= SaveSaturation(source, mode,format,params[0]); + ret |= SaveSaturation((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_COLOR_TEMPERATURE: - ret |= SaveColorTemperature(source, mode,format,(tvColorTemp_t)params[0]); + ret |= SaveColorTemperature((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvColorTemp_t)level); break; case PQ_PARAM_BACKLIGHT: - ret |= SaveBacklight(source, mode,format,params[0]); + ret |= SaveBacklight((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_DIMMINGMODE: - ret |= SaveTVDimmingMode(source,mode,format,(tvDimmingMode_t)params[0]); + ret |= SaveTVDimmingMode((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvDimmingMode_t)level); break; case PQ_PARAM_LOWLATENCY_STATE: - ret |= SaveLowLatencyState(source, mode,format,params[0]); + ret |= SaveLowLatencyState((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,level); break; case PQ_PARAM_DOLBY_MODE: - ret |= SaveTVDolbyVisionMode(source, mode,format,(tvDolbyMode_t)params[0]); + ret |= SaveTVDolbyVisionMode((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvDolbyMode_t)level); break; - case PQ_PARAM_ASPECT_RATIO: - ret |= SaveAspectRatio(source,mode,format,(tvDisplayMode_t)params[0]); + case PQ_PARAM_ASPECT_RATIO: + ret |= SaveAspectRatio((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvDisplayMode_t)level); break; - case PQ_PARAM_LOCALDIMMING_LEVEL: + + case PQ_PARAM_CMS_SATURATION_RED: + case PQ_PARAM_CMS_SATURATION_BLUE: + case PQ_PARAM_CMS_SATURATION_GREEN: + case PQ_PARAM_CMS_SATURATION_YELLOW: + case PQ_PARAM_CMS_SATURATION_CYAN: + case PQ_PARAM_CMS_SATURATION_MAGENTA: + case PQ_PARAM_CMS_HUE_RED: + case PQ_PARAM_CMS_HUE_BLUE: + case PQ_PARAM_CMS_HUE_GREEN: + case PQ_PARAM_CMS_HUE_YELLOW: + case PQ_PARAM_CMS_HUE_CYAN: + case PQ_PARAM_CMS_HUE_MAGENTA: + case PQ_PARAM_CMS_LUMA_RED: + case PQ_PARAM_CMS_LUMA_BLUE: + case PQ_PARAM_CMS_LUMA_GREEN: + case PQ_PARAM_CMS_LUMA_YELLOW: + case PQ_PARAM_CMS_LUMA_CYAN: + case PQ_PARAM_CMS_LUMA_MAGENTA: + { + for( int componentType : values.componentValues ) { + paramIndex.componentIndex = componentType; + for( int colorType : values.colorValues ) { + paramIndex.colorIndex = colorType; + if(reset) { + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,0,false); + } + if(sync || reset) { + int value=0; + tvPQParameterIndex_t pqIndex; + if ( convertCMSParamToPQEnum(getCMSComponentStringFromEnum((tvComponentType_t)paramIndex.componentIndex),getCMSColorStringFromEnum((tvDataComponentColor_t)paramIndex.colorIndex),pqIndex) != 0 ) + { + LOGERR("%s:convertCMSParamToPQEnum failed color : %d component : %d \n",__FUNCTION__,paramIndex.colorIndex,paramIndex.componentIndex); + return -1; + } + if(getLocalparam(tr181ParamName,paramIndex,value,pqIndex,sync)) { + continue; + } + level=value; + } + ret |= SaveCMS((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvComponentType_t)paramIndex.componentIndex,(tvDataComponentColor_t)paramIndex.colorIndex,level); + + if(set) { + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,level,true); + } + } + } + break; + } + case PQ_PARAM_WB_GAIN_RED: + case PQ_PARAM_WB_GAIN_GREEN: + case PQ_PARAM_WB_GAIN_BLUE: + case PQ_PARAM_WB_OFFSET_RED: + case PQ_PARAM_WB_OFFSET_GREEN: + case PQ_PARAM_WB_OFFSET_BLUE: + { + for( int colorType : values.colorValues ) { + paramIndex.colorIndex = colorType; + for( int controlType : values.controlValues ) { + paramIndex.controlIndex = controlType; + if(reset) { + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,0,false); + } + if(sync || reset) { + int value=0; + if(getLocalparam(tr181ParamName,paramIndex,value,pqParamIndex,sync)) { + continue; + } + level=value; + } + /* tvRGBType_t rgbIndex; + if ( convertWBParamToRGBEnum(getWBColorStringFromEnum((tvWBColor_t)(paramIndex.colorIndex)),getWBControlStringFromEnum((tvWBControl_t)(paramIndex.controlIndex)),rgbIndex) != 0 ) + { + LOGERR("%s:convertWBParamToRGBEnum failed Color : %d Control : %d \n",__FUNCTION__,paramIndex.colorIndex,paramIndex.controlIndex); + return -1; + }*/ + ret |= SaveCustom2PointWhiteBalance((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvWBColor_t)paramIndex.colorIndex,(tvWBControl_t)paramIndex.controlIndex,level); + + if(set) { + ret |= updateAVoutputTVParamToHAL(tr181ParamName,paramIndex,level,true); + } + } + } + break; + } + case PQ_PARAM_LOCALDIMMING_LEVEL: { - if(sync) { - int value=0; - getLocalparam(tr181ParamName,format,mode,source,value,pqParamIndex,sync); - params[0]=value; - } - ret |= SaveTVDimmingMode(source, mode,format,(tvDimmingMode_t)params[0]); - break; - } - case PQ_PARAM_CMS: - case PQ_PARAM_LDIM: - default: - break; + if(sync) { + int value=0; + getLocalparam(tr181ParamName,paramIndex,value,pqParamIndex,sync); + level=value; + } + ret |= SaveTVDimmingMode((tvVideoSrcType_t)paramIndex.sourceIndex, paramIndex.pqmodeIndex,(tvVideoFormatType_t)paramIndex.formatIndex,(tvDimmingMode_t)level); + break; + } + case PQ_PARAM_CMS: + case PQ_PARAM_LDIM: + default: + break; } } } @@ -992,72 +1184,88 @@ namespace Plugin { tvError_t AVOutputTV::syncAvoutputTVParamsToHAL(std::string pqmode,std::string source,std::string format) { - int params[3]={0}; + int level={0}; + capDetails_t info; + info.pqmode = pqmode; + info.source = source; + info.format = format; LOGINFO("Entry %s : pqmode : %s source : %s format : %s\n",__FUNCTION__,pqmode.c_str(),source.c_str(),format.c_str()); - if( !updateAVoutputTVParam("sync","Brightness",pqmode,source,format,PQ_PARAM_BRIGHTNESS,params)) { + if( !updateAVoutputTVParam("sync","Brightness",info,PQ_PARAM_BRIGHTNESS,level)) { LOGINFO("Brightness Successfully sync to Drive Cache\n"); - } + } else { LOGERR("Brightness Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","Contrast",pqmode,source,format,PQ_PARAM_CONTRAST,params)) { + if( !updateAVoutputTVParam("sync","Contrast",info,PQ_PARAM_CONTRAST,level)) { LOGINFO("Contrast Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("Contrast Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","Sharpness",pqmode,source,format,PQ_PARAM_SHARPNESS,params)) { + if( !updateAVoutputTVParam("sync","Sharpness",info,PQ_PARAM_SHARPNESS,level)) { LOGINFO("Sharpness Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("Sharpness Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","Saturation",pqmode,source,format,PQ_PARAM_SATURATION,params)) { + if( !updateAVoutputTVParam("sync","Saturation",info,PQ_PARAM_SATURATION,level)) { LOGINFO("Saturation Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("Saturation Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","Hue",pqmode,source,format,PQ_PARAM_HUE,params)) { + if( !updateAVoutputTVParam("sync","Hue",info,PQ_PARAM_HUE,level)) { LOGINFO("Hue Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("Hue Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","ColorTemp",pqmode,source,format,PQ_PARAM_COLOR_TEMPERATURE,params)) { + if( !updateAVoutputTVParam("sync","ColorTemp",info,PQ_PARAM_COLOR_TEMPERATURE,level)) { LOGINFO("ColorTemp Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("ColorTemp Sync to cache Failed !!!\n"); } - - if( !updateAVoutputTVParam("sync","DolbyVisionMode",pqmode,source,"DV",PQ_PARAM_DOLBY_MODE,params)) { - LOGINFO("dvmode Successfully Synced to Drive Cache\n"); - } + if( !updateAVoutputTVParam("sync","HDRMode",info,PQ_PARAM_DOLBY_MODE,level)) { + LOGINFO("HDRmode Successfully Synced to Drive Cache\n"); + } else { - LOGERR("dvmode Sync to cache Failed !!!\n"); - } + LOGERR("HDRmode Sync to cache Failed !!!\n"); + } - if( !updateAVoutputTVParam("sync","DimmingMode",pqmode,source,format,PQ_PARAM_DIMMINGMODE,params)) { + if( !updateAVoutputTVParam("sync","DimmingMode",info,PQ_PARAM_DIMMINGMODE,level)) { LOGINFO("dimmingmode Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("dimmingmode Sync to cache Failed !!!\n"); - } + } - if( !updateAVoutputTVParam("sync","Backlight",pqmode,source,format,PQ_PARAM_BACKLIGHT,params) ) { + if( !updateAVoutputTVParam("sync","Backlight",info,PQ_PARAM_BACKLIGHT,level) ) { LOGINFO("Backlight Successfully Synced to Drive Cache\n"); - } + } else { LOGERR("Backlight Sync to cache Failed !!!\n"); - } + } + + syncCMSParams(); //sync CMS + + syncWBParams(); + + info.format = "DV";//Sync only for Dolby + + if( !updateAVoutputTVParam("sync","DolbyVisionMode",info,PQ_PARAM_DOLBY_MODE,level)) { + LOGINFO("dvmode Successfully Synced to Drive Cache\n"); + } + else { + LOGERR("dvmode Sync to cache Failed !!!\n"); + } LOGINFO("Exit %s : pqmode : %s source : %s format : %s\n",__FUNCTION__,pqmode.c_str(),source.c_str(),format.c_str()); return tvERROR_NONE; @@ -1065,19 +1273,22 @@ namespace Plugin { int AVOutputTV::syncAvoutputTVPQModeParamsToHAL(std::string pqmode, std::string source, std::string format) { - std::vector sources; - std::vector pictureModes; - std::vector formats; + capDetails_t inputInfo; + valueVectors_t valueVectors; tr181ErrorCode_t err = tr181Success; TR181_ParamData_t param = {0}; int ret = 0; - ret = getSaveConfig(pqmode, source, format, sources, pictureModes, formats); + inputInfo.pqmode = pqmode; + inputInfo.source = source; + inputInfo.format = format; + + ret = getSaveConfig("PictureMode", inputInfo, valueVectors); if (ret == 0 ) { - for (int source : sources) { + for (int source : valueVectors.sourceValues ) { tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source; - for (int format : formats) { + for (int format : valueVectors.formatValues ) { tvVideoFormatType_t formatType = (tvVideoFormatType_t)format; std::string tr181_param_name = ""; tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM); @@ -1105,13 +1316,29 @@ namespace Plugin { return ret; } - uint32_t AVOutputTV::generateStorageIdentifier(std::string &key, std::string forParam,int contentFormat, int pqmode, int source) + uint32_t AVOutputTV::generateStorageIdentifier(std::string &key, std::string forParam, paramIndex_t info) + { + key+=std::string(AVOUTPUT_GENERIC_STRING_RFC_PARAM); + key+=STRING_SOURCE+convertSourceIndexToString(info.sourceIndex)+std::string(".")+STRING_PICMODE+convertPictureIndexToString(info.pqmodeIndex)+std::string(".")+std::string(STRING_FORMAT)+convertVideoFormatToString(info.formatIndex)+std::string(".")+forParam; + return tvERROR_NONE; + } + + uint32_t AVOutputTV::generateStorageIdentifierCMS(std::string &key, std::string forParam, paramIndex_t info) + { + key+=std::string(AVOUTPUT_GENERIC_STRING_RFC_PARAM); + key+=STRING_SOURCE+convertSourceIndexToString(info.sourceIndex)+std::string(".")+STRING_PICMODE+convertPictureIndexToString(info.pqmodeIndex)+std::string(".")+std::string(STRING_FORMAT)+convertVideoFormatToString(info.formatIndex)+std::string(".")+STRING_COLOR+getCMSColorStringFromEnum((tvDataComponentColor_t)info.colorIndex)+std::string(".")+STRING_COMPONENT+getCMSComponentStringFromEnum((tvComponentType_t)info.componentIndex)+std::string(".")+forParam; + return tvERROR_NONE; + } + + uint32_t AVOutputTV::generateStorageIdentifierWB(std::string &key, std::string forParam, paramIndex_t info) { key+=std::string(AVOUTPUT_GENERIC_STRING_RFC_PARAM); - key+=STRING_SOURCE+convertSourceIndexToString(source)+std::string(".")+STRING_PICMODE+convertPictureIndexToString(pqmode)+std::string(".")+std::string(STRING_FORMAT)+convertVideoFormatToString(contentFormat)+std::string(".")+forParam; + key+=STRING_SOURCE+convertSourceIndexToString(info.sourceIndex)+std::string(".")+STRING_PICMODE+convertPictureIndexToString(info.pqmodeIndex)+std::string(".")+std::string(STRING_FORMAT)+convertVideoFormatToString(info.formatIndex)+std::string(".")+STRING_COLOR+getWBColorStringFromEnum((tvWBColor_t)info.colorIndex)+std::string(".")+STRING_CONTROL+getWBControlStringFromEnum((tvWBControl_t)info.controlIndex)+std::string(".")+forParam; return tvERROR_NONE; } + + uint32_t AVOutputTV::generateStorageIdentifierDirty(std::string &key, std::string forParam,uint32_t contentFormat, int pqmode) { key+=std::string(AVOUTPUT_GENERIC_STRING_RFC_PARAM); @@ -1138,48 +1365,128 @@ namespace Plugin { return "UNKNOWN ERROR"; } - int AVOutputTV::getSaveConfig(std::string pqmode, std::string source, std::string format,std::vector &sources,std::vector &picturemodes, std::vector &formats) + int AVOutputTV::getSaveConfig(std::string param, capDetails_t capInfo, valueVectors_t &values) { - LOGINFO("Entry : %s pqmode : %s source :%s format :%s\n",__FUNCTION__,pqmode.c_str(),source.c_str(),format.c_str()); + LOGINFO("Entry : %s pqmode : %s source :%s format :%s component : %s color : %s control:%s\n",__FUNCTION__,capInfo.pqmode.c_str(),capInfo.source.c_str(),capInfo.format.c_str(),capInfo.component.c_str(),capInfo.color.c_str(),capInfo.control.c_str()); int ret = 0; - if (getAvailableCapabilityModes(source, pqmode, format) != 0) { + if (getAvailableCapabilityModes(capInfo) != 0) { LOGERR("%s: failed to get picture/source/format mode capability \n", __FUNCTION__); return -1; } //pqmode - char *modeString = strdup(pqmode.c_str()); + char *modeString = strdup(capInfo.pqmode.c_str()); char *token = NULL; while ((token = strtok_r(modeString,",",&modeString))) { std::string local = token; - picturemodes.push_back(getPictureModeIndex(local)); + values.pqmodeValues.push_back(getPictureModeIndex(local)); } //source - char *sourceString = strdup(source.c_str()); + char *sourceString = strdup(capInfo.source.c_str()); char *sourceToken = NULL; while ((sourceToken = strtok_r(sourceString,",",&sourceString))) { std::string local = sourceToken; - sources.push_back(getSourceIndex(local)); + if( local == "All") continue; + values.sourceValues.push_back(getSourceIndex(local)); } //3)check format - char *formatString = strdup(format.c_str()); + char *formatString = strdup(capInfo.format.c_str()); char *formatToken = NULL; while ((formatToken = strtok_r(formatString,",",&formatString))) { std::string local = formatToken; - formats.push_back(getFormatIndex(local)); + values.formatValues.push_back(getFormatIndex(local)); + } + + if( param.compare("CMS") == 0 ) + { + //Check Color + char *colorString = strdup(capInfo.color.c_str()); + char *colorToken = NULL; + while ((colorToken = strtok_r(colorString,",",&colorString))) { + std::string local = colorToken; + tvDataComponentColor_t level = tvDataColor_NONE; + if ( getCMSColorEnumFromString(local,level ) == -1 ) { + LOGERR("%s : GetColorEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + values.colorValues.push_back(level); + } + + //Check Component + char *componentString = strdup(capInfo.component.c_str()); + char *componentToken = NULL; + while ((componentToken = strtok_r(componentString,",",&componentString))) { + std::string local = componentToken; + tvComponentType_t level; + if ( getCMSComponentEnumFromString(local,level ) == -1 ) { + LOGERR("%s : GetComponentEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + values.componentValues.push_back(level); + } + } + + if( param.compare("WhiteBalance") == 0 ) + { + //Check Color + char *colorString = strdup(capInfo.color.c_str()); + char *colorToken = NULL; + while ((colorToken = strtok_r(colorString,",",&colorString))) { + std::string local = colorToken; + tvWBColor_t level=tvWB_COLOR_RED; + if ( getWBColorEnumFromString(local,level ) == -1 ) { + LOGERR("%s : GetWBColorEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + values.colorValues.push_back(level); + } + + //Check Control + char *controlString = strdup(capInfo.control.c_str()); + char *controlToken = NULL; + while ((controlToken = strtok_r(controlString,",",&controlString))) { + std::string local = controlToken; + tvWBControl_t level=tvWB_CONTROL_GAIN;; + if ( getWBControlEnumFromString(local,level ) == -1 ) { + LOGERR("%s : GetWBControlEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + values.controlValues.push_back(level); + } + + /* + //Check Color Temp + char *colorTempString = strdup(capInfo.colorTemperature.c_str()); + char *colorTempToken = NULL; + while ((colorTempToken = strtok_r(colorTempString,",",&colorTempString))) { + std::string local = colorTempToken; + tvColorTemp_t level; + if ( getColorTempEnumFromString(local,level ) == -1 ) { + LOGERR("%s : GetColorTempEnumFromString Failed!!! ",__FUNCTION__); + return -1; + } + values.colorTempValues.push_back(level); + }*/ } - LOGINFO("Exit : %s pqmode : %s source :%s format :%s ret:%d\n",__FUNCTION__,pqmode.c_str(),source.c_str(),format.c_str(), ret); + LOGINFO("Exit : %s pqmode : %s source :%s format :%s ret:%d\n",__FUNCTION__,capInfo.pqmode.c_str(),capInfo.source.c_str(),capInfo.format.c_str(), ret); return ret; } - int AVOutputTV::getLocalparam( std::string forParam,int formatIndex,int pqIndex,int sourceIndex,int & value, - tvPQParameterIndex_t pqParamIndex,bool sync,int color ) + int AVOutputTV::getLocalparam( std::string forParam,paramIndex_t indexInfo,int & value,tvPQParameterIndex_t pqParamIndex,bool sync) { string key; TR181_ParamData_t param={0}; - generateStorageIdentifier(key,forParam,formatIndex,pqIndex,sourceIndex); + + if( forParam.compare("CMS") == 0 ) { + generateStorageIdentifierCMS(key,forParam,indexInfo); + } else if( forParam.compare("WhiteBalance") == 0 ) { + generateStorageIdentifierWB(key,forParam,indexInfo); + } else { + generateStorageIdentifier(key,forParam,indexInfo); + } + if(key.empty()) { LOGERR("generateStorageIdentifier failed\n"); return -1; @@ -1191,31 +1498,31 @@ namespace Plugin { if( forParam.compare("ColorTemp") == 0 ) { if (strncmp(param.value, "Standard", strlen(param.value))==0) { value=tvColorTemp_STANDARD; - } + } else if (strncmp(param.value, "Warm", strlen(param.value))==0) { value=tvColorTemp_WARM; - } + } else if (strncmp(param.value, "Cold", strlen(param.value))==0) { value=tvColorTemp_COLD; - } - else if (strncmp(param.value, "User Defined", strlen(param.value))==0) { + } + else if (strncmp(param.value, "UserDefined", strlen(param.value))==0) { value=tvColorTemp_USER; - } + } else { value=tvColorTemp_STANDARD; - } + } return 0; - } + } else if( forParam.compare("DimmingMode") == 0 ) { if (strncmp(param.value, "fixed", strlen(param.value))==0) { value=tvDimmingMode_Fixed; - } + } else if (strncmp(param.value, "local", strlen(param.value))==0) { value=tvDimmingMode_Local; - } + } else if (strncmp(param.value, "global", strlen(param.value))==0) { value=tvDimmingMode_Global; - } + } return 0; } else if ( forParam.compare("DolbyVisionMode") == 0) { @@ -1229,17 +1536,41 @@ namespace Plugin { value = tvDolbyMode_Bright; } return 0; + } + else if ( forParam.compare("HDRMode") == 0) { + if (strncmp(param.value, "Dark", strlen(param.value)) == 0 && key.find("DV") != std::string::npos ) { + value = tvDolbyMode_Dark; + } + else if(strncmp(param.value, "Bright", strlen(param.value)) == 0 && key.find("DV") != std::string::npos ) { + value = tvDolbyMode_Game; + } + else if(strncmp(param.value, "Dark", strlen(param.value)) == 0 && key.find("HDR10") != std::string::npos ) { + value = tvHDR10Mode_Dark; + } + else if(strncmp(param.value, "Bright", strlen(param.value)) == 0 && key.find("HDR10") != std::string::npos ) { + value = tvHDR10Mode_Bright; + } + else if(strncmp(param.value, "Dark", strlen(param.value)) == 0 && key.find("HLG") != std::string::npos ) { + value = tvHLGMode_Dark; + } + else if(strncmp(param.value, "Bright", strlen(param.value)) == 0 && key.find("HLG") != std::string::npos ) { + value = tvHLGMode_Bright; + } + else { + value = tvDolbyMode_Game; + } + return 0; } else { value=std::stoi(param.value); - return 0; + return 0; } } else {// default value from DB if( sync ) { return 1; } - GetDefaultPQParams(pqIndex,(tvVideoSrcType_t)sourceIndex,(tvVideoFormatType_t)formatIndex,pqParamIndex,&value); + GetDefaultPQParams(indexInfo.pqmodeIndex,(tvVideoSrcType_t)indexInfo.sourceIndex,(tvVideoFormatType_t)indexInfo.formatIndex,pqParamIndex,&value); LOGINFO("Default value from DB : %s : %d \n",key.c_str(),value); return 0; } @@ -1273,102 +1604,20 @@ namespace Plugin { return CompColorEnum; } - int AVOutputTV::getDolbyParams(tvContentFormatType_t format, std::string &s, std::string source) - { - int ret = -1; - TR181_ParamData_t param; - std::string rfc_param = AVOUTPUT_HDR10MODE_RFC_PARAM; - int dolby_mode_value = 0; - tvVideoSrcType_t sourceIndex = VIDEO_SOURCE_IP; - /*Since dolby vision is source specific, we should for check for specific source*/ - if (!source.empty()) { - sourceIndex = (tvVideoSrcType_t)getSourceIndex(source); - } - else { - GetCurrentVideoSource(&sourceIndex); - } - - char picMode[PIC_MODE_NAME_MAX]={0}; - int pqmodeIndex = 0; - if(!getCurrentPictureMode(picMode)) { - LOGERR("Failed to get the Current picture mode\n"); - } - else { - std::string local = picMode; - pqmodeIndex = getPictureModeIndex(local); - } - memset(¶m, 0, sizeof(param)); - if (format == tvContentFormatType_HLG ) { - rfc_param = AVOUTPUT_HLGMODE_RFC_PARAM; - } - else if (format == tvContentFormatType_DOVI) { - rfc_param = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM + std::to_string(sourceIndex) + "."+"DolbyVisionMode"; - } - - tr181ErrorCode_t err = getLocalParam(rfc_caller_id, rfc_param.c_str(), ¶m); - if ( tr181Success != err) { - tvError_t retVal = GetDefaultPQParams(pqmodeIndex,(tvVideoSrcType_t)sourceIndex, - (tvVideoFormatType_t)ConvertHDRFormatToContentFormat((tvhdr_type_t)format), - PQ_PARAM_DOLBY_MODE,&dolby_mode_value); - if( retVal != tvERROR_NONE ) { - LOGERR("%s : failed\n",__FUNCTION__); - return ret; - } - s = getDolbyModeStringFromEnum((tvDolbyMode_t)dolby_mode_value); - ret = 0; - } - else { - s += param.value; - ret = 0; - } - return ret; - } - - tvError_t AVOutputTV::getParamsCaps(std::vector &range - , std::vector &pqmode, std::vector &source, std::vector &format,std::string param ) + tvError_t AVOutputTV::getParamsCaps(std::string param, capVectors_t &vecInfo) { tvError_t ret = tvERROR_NONE; - - std::string rangeInfo; - std::string sourceInfo; - std::string formatInfo; - std::string pqmodeInfo; - - std::string platformsupport; - std::string indexInfo; - std::vector localIndex; - - if( ReadCapablitiesFromConf( rangeInfo, pqmodeInfo, formatInfo ,sourceInfo,param, platformsupport, indexInfo)) { - LOGERR( "%s: ReadCapablitiesFromConf Failed !!!\n",__FUNCTION__); - return tvERROR_GENERAL; - } - else { - spliltCapablities( range, pqmode, format, source, localIndex,rangeInfo, pqmodeInfo, formatInfo, sourceInfo , indexInfo); - } - - return ret; - } - - tvError_t AVOutputTV::getParamsCaps(std::vector &range - , std::vector &pqmode, std::vector &source, std::vector &format,std::string param, - std::string & isPlatformSupport, std::vector & index) - { - tvError_t ret = tvERROR_NONE; - - std::string rangeInfo; - std::string sourceInfo; - std::string formatInfo; - std::string pqmodeInfo; - std::string indexInfo; - - if( ReadCapablitiesFromConf( rangeInfo, pqmodeInfo, formatInfo ,sourceInfo,param, isPlatformSupport, indexInfo)) { + capDetails_t stringInfo; + + if( ReadCapablitiesFromConf( param, stringInfo) != 0 ) + { LOGERR( "%s: ReadCapablitiesFromConf Failed !!!\n",__FUNCTION__); return tvERROR_GENERAL; } - else { - spliltCapablities( range, pqmode, format, source, index,rangeInfo, pqmodeInfo, formatInfo, sourceInfo, indexInfo); + else + { + spliltCapablities( vecInfo, stringInfo); } - return ret; } @@ -1431,60 +1680,6 @@ namespace Plugin { return ret; } - - int AVOutputTV::ReadCapablitiesFromConf(std::string &rangeInfo,std::string &pqmodeInfo,std::string &formatInfo,std::string &sourceInfo, - std::string param, std::string & isPlatformSupport, std::string & indexInfo) - { - int ret = 0; - - try { - CIniFile inFile(CAPABLITY_FILE_NAME); - std::string configString; - if ((param == "DolbyVisionMode") || (param == "Backlight") ) { - configString = param + ".platformsupport"; - isPlatformSupport = inFile.Get(configString); - printf(" platfromsupport : %s\n",isPlatformSupport.c_str() ); - } - - if ( (param == "ColorTemperature") || (param == "DimmingMode") || - ( param == "AutoBacklightControl") || (param == "DolbyVisionMode") || - (param == "HDR10Mode") || (param == "HLGMode") || (param == "AspectRatio") || - (param == "PictureMode") || (param == "VideoSource") || (param == "VideoFormat") || - (param == "VideoFrameRate") ) { - configString = param + ".range"; - rangeInfo = inFile.Get(configString); - printf(" String Range info : %s\n",rangeInfo.c_str() ); - } else { - configString = param + ".range_from"; - rangeInfo = inFile.Get(configString); - configString = param + ".range_to"; - rangeInfo += ","+inFile.Get(configString); - printf(" Integer Range Info : %s\n",rangeInfo.c_str() ); - } - - if ((param == "VideoSource") || (param == "PictureMode") || (param == "VideoFormat") ) { - configString.clear(); - configString = param + ".index"; - indexInfo = inFile.Get(configString); - printf("Index value %s\n", indexInfo.c_str()); - } - - configString.clear(); - configString = param + ".pqmode"; - pqmodeInfo = inFile.Get(configString); - configString = param + ".format"; - formatInfo = inFile.Get(configString); - configString = param + ".source"; - sourceInfo = inFile.Get(configString); - ret = 0; - } - catch(const boost::property_tree::ptree_error &e) { - printf("%s: error %s::config table entry not found in ini file\n",__FUNCTION__,e.what()); - ret = -1; - } - return ret; - } - void AVOutputTV::getDimmingModeStringFromEnum(int value, std::string &toStore) { const char *color_temp_string[] = { @@ -1502,7 +1697,7 @@ namespace Plugin { [tvColorTemp_STANDARD] = "Standard", [tvColorTemp_WARM] = "Warm", [tvColorTemp_COLD] = "Cold", - [tvColorTemp_USER] = "User Defined" + [tvColorTemp_USER] = "UserDefined" }; toStore.clear(); toStore+=color_temp_string[value]; @@ -1540,44 +1735,11 @@ namespace Plugin { return 1; } else { - LOGERR("getLocalParam failed"); + LOGERR("getLocalParam failed %s\n",tr181_param_name.c_str()); return 0; } } - - int AVOutputTV::getDolbyParamToSync(int sourceIndex, int formatIndex, int& value) - { - int ret=0; - TR181_ParamData_t param; - int pqmodeIndex = 0; - char picMode[PIC_MODE_NAME_MAX]={0}; - if(!getCurrentPictureMode(picMode)) { - LOGERR("Failed to get the Current picture mode\n"); - } - else { - std::string local = picMode; - pqmodeIndex = getPictureModeIndex(local); - } - std ::string rfc_param = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM + std::to_string(sourceIndex) + "."+"DolbyVisionMode"; - memset(¶m, 0, sizeof(param)); - tr181ErrorCode_t err = getLocalParam(rfc_caller_id, rfc_param.c_str(), ¶m); - - if ( tr181Success != err) { - tvError_t retVal = GetDefaultPQParams(pqmodeIndex,(tvVideoSrcType_t)sourceIndex, (tvVideoFormatType_t)formatIndex, - PQ_PARAM_DOLBY_MODE, &value); - if( retVal != tvERROR_NONE ) { - LOGERR("%s : failed\n",__FUNCTION__); - return -1; - } - ret = 0; - } - else { - value=getDolbyModeIndex(param.value); - ret = 0; - } - - return ret; - } + tvDolbyMode_t AVOutputTV::GetDolbyVisionEnumFromModeString(const char* modeString) { if (strcmp(modeString, "Invalid") == 0) { @@ -1588,45 +1750,31 @@ namespace Plugin { return tvDolbyMode_Bright; } else if (strcmp(modeString, "Game") == 0) { return tvDolbyMode_Game; - } else if (strcmp(modeString, "HDR10 Dark") == 0) { - return tvHDR10Mode_Dark; - } else if (strcmp(modeString, "HDR10 Bright") == 0) { - return tvHDR10Mode_Bright; - } else if (strcmp(modeString, "HDR10 Game") == 0) { - return tvHDR10Mode_Game; - } else if (strcmp(modeString, "HLG Dark") == 0) { - return tvHLGMode_Dark; - } else if (strcmp(modeString, "HLG Bright") == 0) { - return tvHLGMode_Bright; - } else if (strcmp(modeString, "HLG Game") == 0) { - return tvHLGMode_Game; } - return tvDolbyMode_Invalid; // Default case for invalid input } std::string AVOutputTV::getDolbyModeStringFromEnum( tvDolbyMode_t mode) - { std::string value; switch(mode) { case tvDolbyMode_Dark: case tvHDR10Mode_Dark: case tvHLGMode_Dark: - value = "Dark"; - break; + value = "Dark"; + break; case tvDolbyMode_Bright: case tvHDR10Mode_Bright: case tvHLGMode_Bright: - value = "Bright"; - break; - case tvDolbyMode_Game: + value = "Bright"; + break; + case tvDolbyMode_Game: case tvHDR10Mode_Game: case tvHLGMode_Game: value = "Game"; break; default: - break; + break; } return value; @@ -1635,39 +1783,36 @@ namespace Plugin { int AVOutputTV::getAvailableCapabilityModesWrapper(std::string param, std::string & outparam) { tvError_t err = tvERROR_NONE; - std::vector range; - std::vector picmodeVec; - std::vector sourceVec; - std::vector formatVec; + capVectors_t info; - err = getParamsCaps(range,picmodeVec,sourceVec,formatVec, param); + err = getParamsCaps(param,info); if (err != tvERROR_NONE) { LOGERR("%s: failed to get [%s] capability \n", __FUNCTION__, param.c_str()); return -1; } - outparam = convertToString(range); + outparam = convertToString(info.rangeVector); return 0; } - int AVOutputTV::getAvailableCapabilityModes(std::string & source, std::string & pqmode, std::string & format) + int AVOutputTV::getAvailableCapabilityModes( capDetails_t &info) { - if ((pqmode.compare("none") == 0 )) { - if (getAvailableCapabilityModesWrapper("PictureMode", pqmode) != 0) { + if ((info.pqmode.compare("none") == 0 )) { + if (getAvailableCapabilityModesWrapper("PictureMode", info.pqmode) != 0) { LOGERR("%s: failed to get picture mode capability \n", __FUNCTION__); return -1; } } - if( (source.compare("none") == 0)) { - if (getAvailableCapabilityModesWrapper("VideoSource",source) != 0) { + if( (info.source.compare("none") == 0)) { + if (getAvailableCapabilityModesWrapper("VideoSource",info.source) != 0) { LOGERR("%s: failed to get source capability \n", __FUNCTION__); return -1; } } - if( (format.compare("none") == 0) ) { - if (getAvailableCapabilityModesWrapper("VideoFormat",format) != 0) { + if( (info.format.compare("none") == 0) ) { + if (getAvailableCapabilityModesWrapper("VideoFormat",info.format) != 0) { LOGERR("%s: failed to get format capability \n", __FUNCTION__); return -1; } @@ -1677,17 +1822,17 @@ namespace Plugin { int AVOutputTV::getCapabilitySource(JsonArray & rangeArray) { - std::vector range,pqmode,source,format; + capVectors_t info; - tvError_t ret = getParamsCaps(range,pqmode,source,format,"VideoSource"); + tvError_t ret = getParamsCaps("VideoSource",info); if(ret != tvERROR_NONE) { return -1; } else { - if ((range.front()).compare("none") != 0) { - for (unsigned int index = 0; index < range.size(); index++) { - rangeArray.Add(range[index]); + if ((info.rangeVector.front()).compare("none") != 0) { + for (unsigned int index = 0; index < info.rangeVector.size(); index++) { + rangeArray.Add(info.rangeVector[index]); } } } @@ -1696,16 +1841,16 @@ namespace Plugin { int AVOutputTV::getRangeCapability(std::string param, std::vector & rangeInfo) { - std::vector range,pqmode,source,format; + capVectors_t info; - tvError_t ret = getParamsCaps(range,pqmode,source,format, param); + tvError_t ret = getParamsCaps(param,info); if(ret != tvERROR_NONE) { return -1; } else { - if ((range.front()).compare("none") != 0) { - rangeInfo = range; + if ((info.rangeVector.front()).compare("none") != 0) { + rangeInfo = info.rangeVector; } } return 0; @@ -1783,6 +1928,11 @@ namespace Plugin { tvDisplayMode_t mode = tvDisplayMode_MAX; TR181_ParamData_t param; tvError_t ret = tvERROR_NONE; + capDetails_t inputInfo; + + inputInfo.pqmode = pqmode; + inputInfo.source = source; + inputInfo.format = format; memset(¶m, 0, sizeof(param)); tr181ErrorCode_t err = getLocalParam(rfc_caller_id, AVOUTPUT_ASPECTRATIO_RFC_PARAM, ¶m); @@ -1829,9 +1979,7 @@ namespace Plugin { } else { //Save DisplayMode to ssm_data - int params[3]={0}; - params[0]=mode; - int retval=updateAVoutputTVParam("set","AspectRatio",pqmode,source,format,PQ_PARAM_ASPECT_RATIO,params); + int retval=updateAVoutputTVParam("set","ZoomMode",inputInfo,PQ_PARAM_ASPECT_RATIO,mode); if(retval != 0) { LOGERR("Failed to Save DisplayMode to ssm_data\n"); @@ -1848,5 +1996,473 @@ namespace Plugin { return ret; } + int AVOutputTV::getCMSComponentEnumFromString(std::string component, tvComponentType_t& value) + { + int ret = 0; + + if( component.compare("Luma") == 0 ) + value = COMP_LUMA; + else if( component.compare("Saturation") == 0 ) + value = COMP_SATURATION; + else if( component.compare("Hue") == 0 ) + value = COMP_HUE; + else + ret = -1; + + return ret; + } + + int AVOutputTV::getCMSColorEnumFromString(std::string color,tvDataComponentColor_t& value) + { + int ret = 0; + + if( color.compare("Red") == 0 ) + value = tvDataColor_RED; + else if( color.compare("Green") == 0 ) + value = tvDataColor_GREEN; + else if( color.compare("Blue") == 0 ) + value = tvDataColor_BLUE; + else if( color.compare("Yellow") == 0) + value = tvDataColor_YELLOW; + else if( color.compare("Cyan") == 0) + value = tvDataColor_CYAN; + else if( color.compare("Magenta") == 0) + value = tvDataColor_MAGENTA; + else + ret = -1; + + return ret; + } + + int AVOutputTV::getColorTempEnumFromString(std::string color, tvColorTemp_t& value) + { + int ret = 0; + + if( color.compare("Standard") == 0 ) + value = tvColorTemp_STANDARD; + else if( color.compare("Warm") == 0 ) + value = tvColorTemp_WARM; + else if( color.compare("Cold") == 0 ) + value = tvColorTemp_COLD; + else if( color.compare("UserDefined") == 0 ) + value =tvColorTemp_USER; + else + ret = -1; + return ret; + } + + void AVOutputTV::syncCMSParams( ) + { + int level = 0; + std::string cmsParam; + tvPQParameterIndex_t tvPQEnum; + capDetails_t inputInfo; + tvDataComponentColor_t colors[] = {tvDataColor_RED,tvDataColor_GREEN,tvDataColor_BLUE,tvDataColor_YELLOW,tvDataColor_CYAN,tvDataColor_MAGENTA}; + + inputInfo.pqmode = "none"; + inputInfo.source = "none"; + inputInfo.format = "none"; + + for ( int component = COMP_HUE; component < COMP_MAX;component++) { + for(int count = 0;count < (int)(sizeof(colors)/sizeof(colors[0])); ++count) { + tvDataComponentColor_t color = colors[count]; + std::string componentString = getCMSComponentStringFromEnum((tvComponentType_t)component); + std::string colorString = getCMSColorStringFromEnum((tvDataComponentColor_t)color); + cmsParam = componentString+"."+colorString; + + if ( convertCMSParamToPQEnum(componentString,colorString,tvPQEnum) != 0 ) { + LOGINFO("%s: %s/%s Param Not Found \n",__FUNCTION__,componentString.c_str(),componentString.c_str()); + continue; + } + + inputInfo.color = colorString; + inputInfo.component = componentString; + if( !updateAVoutputTVParam("sync","CMS", inputInfo,tvPQEnum,level)) + LOGINFO("CMS Successfully Synced to Drive Cache\n"); + else + LOGERR("CMS Sync to cache Failed !!!\n"); + } + } + } + + void AVOutputTV::syncWBParams( ) + { + int level = 0; + tvPQParameterIndex_t tvPQEnum; + capDetails_t inputInfo; + + inputInfo.pqmode = "none"; + inputInfo.source = "none"; + inputInfo.format = "none"; + + for( int colorIndex= tvWB_COLOR_RED; colorIndex < tvWB_COLOR_MAX; colorIndex++) { + for(int controlIndex = tvWB_CONTROL_GAIN;controlIndex < tvWB_CONTROL_MAX;controlIndex++) { + inputInfo.control = getWBControlStringFromEnum((tvWBControl_t)controlIndex); + inputInfo.color = getWBColorStringFromEnum((tvWBColor_t)colorIndex); + + if ( convertWBParamToPQEnum(inputInfo.control,inputInfo.color,tvPQEnum) != 0 ) { + LOGERR("%s: %s/%s Param Not Found \n",__FUNCTION__,inputInfo.control.c_str(),inputInfo.color.c_str()); + } + updateAVoutputTVParam("sync","WhiteBalance",inputInfo,tvPQEnum,level); + } + } + } + + + int AVOutputTV:: convertCMSParamToPQEnum(const std::string component, const std::string color,tvPQParameterIndex_t& value) { + // Create a map to associate color-component pairs with enum values + int ret = 0; + static const std::unordered_map colorComponentMap = { + {"SaturationRed", PQ_PARAM_CMS_SATURATION_RED}, + {"SaturationGreen", PQ_PARAM_CMS_SATURATION_GREEN}, + {"SaturationBlue", PQ_PARAM_CMS_SATURATION_BLUE}, + {"SaturationCyan", PQ_PARAM_CMS_SATURATION_CYAN}, + {"SaturationMagenta", PQ_PARAM_CMS_SATURATION_MAGENTA}, + {"SaturationYellow", PQ_PARAM_CMS_SATURATION_YELLOW}, + {"HueRed", PQ_PARAM_CMS_HUE_RED}, + {"HueGreen", PQ_PARAM_CMS_HUE_GREEN}, + {"HueBlue", PQ_PARAM_CMS_HUE_BLUE}, + {"HueCyan", PQ_PARAM_CMS_HUE_CYAN}, + {"HueMagenta", PQ_PARAM_CMS_HUE_MAGENTA}, + {"HueYellow", PQ_PARAM_CMS_HUE_YELLOW}, + {"LumaRed", PQ_PARAM_CMS_LUMA_RED}, + {"LumaGreen", PQ_PARAM_CMS_LUMA_GREEN}, + {"LumaBlue", PQ_PARAM_CMS_LUMA_BLUE}, + {"LumaCyan", PQ_PARAM_CMS_LUMA_CYAN}, + {"LumaMagenta", PQ_PARAM_CMS_LUMA_MAGENTA}, + {"LumaYellow", PQ_PARAM_CMS_LUMA_YELLOW} + }; + + // Create the key by concatenating the component and color + std::string key = component + color; + + // Look up the key in the map + auto it = colorComponentMap.find(key); + if (it != colorComponentMap.end()) { + value = it->second; + ret = 0; + } else { + LOGERR("%s : Invalid color/component\n",__FUNCTION__); + ret = -1; + } + return ret; + } + + int AVOutputTV:: convertWBParamToRGBEnum(const std::string color,std::string control,tvRGBType_t &value) + { + // Create a map to associate color-ntrol pairs with enum values + int ret = 0; + static const std::unordered_map colorControlMap = { + {"RedGain", R_GAIN}, + {"GreenGain", G_GAIN}, + {"BlueGain", B_GAIN}, + {"RedOffset", R_POST_OFFSET}, + {"GreenOffset", G_POST_OFFSET}, + {"BlueOffset", B_POST_OFFSET} + }; + + // Create the key by concatenating the color and control + std::string key = color + control; + + // Look up the key in the map + auto it = colorControlMap.find(key); + if (it != colorControlMap.end()) { + value = it->second; + ret = 0; + } else { + LOGERR("%s : Invalid color/control\n",__FUNCTION__); + ret = -1; + } + return ret; + } + + int AVOutputTV:: convertWBParamToPQEnum(const std::string control, const std::string color,tvPQParameterIndex_t& value) { + // Create a map to associate color-component pairs with enum values + int ret = 0; + static const std::unordered_map colorControlMap = { + {"RedGain", PQ_PARAM_WB_GAIN_RED}, + {"RedOffset", PQ_PARAM_WB_OFFSET_RED}, + {"GreenGain", PQ_PARAM_WB_GAIN_GREEN}, + {"GreenOffset", PQ_PARAM_WB_OFFSET_GREEN}, + {"BlueGain", PQ_PARAM_WB_GAIN_BLUE}, + {"BlueOffset", PQ_PARAM_WB_OFFSET_BLUE}, + }; + + // Create the key by concatenating the component and color + std::string key = color+control; + + // Look up the key in the map + auto it = colorControlMap.find(key); + if (it != colorControlMap.end()) { + value = it->second; + ret = 0; + } else { + LOGERR("%s : Invalid color/control\n",__FUNCTION__); + ret = -1; + } + return ret; + } + + std::string AVOutputTV::getCMSColorStringFromEnum(tvDataComponentColor_t value) + { + switch(value) + { + case tvDataColor_RED: return "Red"; + case tvDataColor_GREEN: return "Green"; + case tvDataColor_BLUE: return "Blue"; + case tvDataColor_YELLOW: return "Yellow"; + case tvDataColor_CYAN: return "Cyan"; + case tvDataColor_MAGENTA: return "Magenta"; + default : return "Max"; + } + } + + std::string AVOutputTV::getCMSComponentStringFromEnum(tvComponentType_t value) { + switch(value) { + case COMP_HUE: return "Hue"; + case COMP_SATURATION: return "Saturation"; + case COMP_LUMA: return "Luma"; + default : return "Max"; + } + } + + std::string AVOutputTV::getWBColorStringFromEnum(tvWBColor_t value) { + switch(value) { + case tvWB_COLOR_RED: return "Red"; + case tvWB_COLOR_GREEN: return "Green"; + case tvWB_COLOR_BLUE: return "Blue"; + default : return "Max"; + } + } + + std::string AVOutputTV::getWBControlStringFromEnum(tvWBControl_t value) { + switch(value) + { + case tvWB_CONTROL_GAIN: return "Gain"; + case tvWB_CONTROL_OFFSET: return "Offset"; + default: return "Max"; + } + } + + int AVOutputTV::getWBColorEnumFromString(std::string color,tvWBColor_t& value) { + int ret = 0; + + if( color.compare("Red") == 0 ) + value = tvWB_COLOR_RED; + else if( color.compare("Green") == 0 ) + value = tvWB_COLOR_GREEN; + else if( color.compare("Blue") == 0 ) + value = tvWB_COLOR_BLUE; + else + ret = -1; + + return ret; + } + + int AVOutputTV::getWBControlEnumFromString(std::string color,tvWBControl_t& value) { + int ret = 0; + + if( color.compare("Gain") == 0 ) + value = tvWB_CONTROL_GAIN; + else if( color.compare("Offset") == 0 ) + value = tvWB_CONTROL_OFFSET; + else + ret = -1; + + return ret; + } + + std::string AVOutputTV::getColorTemperatureStringFromEnum(tvColorTemp_t value) { + switch(value) { + case tvColorTemp_STANDARD: return "Standard"; + case tvColorTemp_WARM: return "Warm"; + case tvColorTemp_COLD: return "Cold"; + case tvColorTemp_USER : return "UserDefined"; + default : return "Max"; + } + } + + int AVOutputTV:: validateCMSParameter(std::string component,int inputValue) + { + capVectors_t info; + tvError_t ret = getParamsCaps("CMS", info); + + LOGINFO("%s : component : %s inputValue : %d\n",__FUNCTION__,component.c_str(),inputValue); + + if (ret != tvERROR_NONE) { + LOGERR("Failed to fetch the range capability \n"); + return -1; + } + + if( component == "Saturation" ) { + if (inputValue < stoi(info.rangeVector[0]) || inputValue > std::stoi(info.rangeVector[1])) { + LOGERR("wrong Input value[%d] for %s\n", inputValue,component.c_str()); + return -1; + } + } else if ( component == "Hue" ) { + if (inputValue < stoi(info.rangeVector[2]) || inputValue > std::stoi(info.rangeVector[3])) { + LOGERR("wrong Input value[%d] for %s\n", inputValue,component.c_str()); + return -1; + } + } else if ( component == "Luma" ) { + if (inputValue < stoi(info.rangeVector[4]) || inputValue > std::stoi(info.rangeVector[5])) { + LOGERR("wrong Input value[%d] for %s\n", inputValue,component.c_str()); + return -1; + } + } + return 0; + } + + int AVOutputTV:: validateWBParameter(std::string param,std::string control,int inputValue) + { + capVectors_t info; + tvError_t ret = getParamsCaps(param, info); + + if (ret != tvERROR_NONE) { + LOGERR("Failed to fetch the range capability[%s] \n", param.c_str()); + return -1; + } + + if( control == "Gain" ) { + if (inputValue < stoi(info.rangeVector[0]) || inputValue > std::stoi(info.rangeVector[1])) { + LOGERR("wrong Input value[%d] for %s\n", inputValue,control.c_str()); + return -1; + } + } else if ( control == "Offset" ) { + if (inputValue < stoi(info.rangeVector[2]) || inputValue > std::stoi(info.rangeVector[3])) { + LOGERR("wrong Input value[%d] for %s\n", inputValue,control.c_str()); + return -1; + } + } + return 0; + } + + int AVOutputTV::ReadCapablitiesFromConf(std::string param, capDetails_t& info) + { + int ret = 0; + + /*Consider User WhiteBalance as CustomWhiteBalance + To avoid clash with Factory WhiteBalance Calibration capablities*/ + + if ( param == "WhiteBalance") { + param = "CustomWhiteBalance"; + } else if ( param == "AutoBacklightMode") { + param = "BacklightControl"; + } + + try { + CIniFile inFile(CAPABLITY_FILE_NAME); + std::string configString; + + if(param == "CMS") + { + configString = param + ".color"; + info.color = inFile.Get(configString); + + configString = param + ".component"; + info.component = inFile.Get(configString); + } + + if(param == "CustomWhiteBalance") + { + configString = param + ".color"; + info.color = inFile.Get(configString); + + configString = param + ".control"; + info.control = inFile.Get(configString); + + } + + if ((param == "DolbyVisionMode") || (param == "Backlight") || (param == "CMS") || (param == "CustomWhiteBalance") || (param == "HDRMode") || (param == "BacklightControl")) { + configString = param + ".platformsupport"; + info.isPlatformSupport = inFile.Get(configString); + printf(" platformsupport : %s\n",info.isPlatformSupport.c_str() ); + } + + if ( (param == "ColorTemperature") || (param == "DimmingMode") || + ( param == "BacklightControl") || (param == "DolbyVisionMode") || + (param == "HDR10Mode") || (param == "HLGMode") || (param == "AspectRatio") || + (param == "PictureMode") || (param == "VideoSource") || (param == "VideoFormat") || + (param == "VideoFrameRate") || (param == "HDRMode") ) { + configString = param + ".range"; + info.range = inFile.Get(configString); + printf(" String Range info : %s\n",info.range.c_str() ); + } else if ( (param == "CMS" )) { + configString.clear(); + configString = param + ".range_Saturation_from"; + info.range = inFile.Get(configString); + configString = param + ".range_Saturation_to"; + info.range += ","+inFile.Get(configString); + + configString = param + ".range_Hue_from"; + info.range += ","+inFile.Get(configString); + configString = param + ".range_Hue_to"; + info.range += ","+inFile.Get(configString); + + configString = param + ".range_Luma_from"; + info.range += ","+inFile.Get(configString); + configString = param + ".range_Luma_to"; + info.range += ","+inFile.Get(configString); + } else if ( (param == "CustomWhiteBalance")) { + configString = param + ".range_Gain_from"; + info.range = inFile.Get(configString); + configString = param + ".range_Gain_to"; + info.range += ","+inFile.Get(configString); + + configString = param + ".range_Offset_from"; + info.range += ","+inFile.Get(configString); + configString = param + ".range_Offset_to"; + info.range += ","+inFile.Get(configString); + } else { + configString = param + ".range_from"; + info.range = inFile.Get(configString); + configString = param + ".range_to"; + info.range += ","+inFile.Get(configString); + printf(" Integer Range Info : %s\n",info.range.c_str() ); + } + + if ((param == "VideoSource") || (param == "PictureMode") || (param == "VideoFormat") ) { + configString.clear(); + configString = param + ".index"; + info.index = inFile.Get(configString); + printf("Index value %s\n", info.index.c_str()); + } + + configString.clear(); + configString = param + ".pqmode"; + info.pqmode = inFile.Get(configString); + configString = param + ".format"; + info.format = inFile.Get(configString); + configString = param + ".source"; + info.source = inFile.Get(configString); + ret = 0; + } + catch(const boost::property_tree::ptree_error &e) { + printf("%s: error %s::config table entry not found in ini file\n",__FUNCTION__,e.what()); + ret = -1; + } + return ret; + } + + bool AVOutputTV::checkCMSColorAndComponentCapability(const std::string capValue, const std::string inputValue) { + // Parse capValue into a set + std::set capSet; + std::istringstream capStream(capValue); + std::string token; + + while (std::getline(capStream, token, ',')) { + capSet.insert(token); + } + + // Parse inputValue and check if each item exists in the set + std::istringstream inputStream(inputValue); + while (std::getline(inputStream, token, ',')) { + if (capSet.find(token) == capSet.end()) { + return false; + } + } + return true; + } + } //namespace Plugin } //namespace WPEFramework diff --git a/AVOutput/CHANGELOG.md b/AVOutput/CHANGELOG.md index d9497c1c..a3afa122 100644 --- a/AVOutput/CHANGELOG.md +++ b/AVOutput/CHANGELOG.md @@ -14,6 +14,10 @@ All notable changes to this RDK Service will be documented in this file. * Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. +## [1.1.0] - 2025-03-14 +### Added +- Add additional features on AVOutput + ## [1.0.10] - 2025-02-17 ### Fixed ODM API removal changes phase 1 and Fixed PQ Mode Camel Case issue diff --git a/CHANGELOG.md b/CHANGELOG.md index 503eccde..73149475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,27 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.1.0](https://github.com/rdkcentral/entservices-inputoutput/compare/1.0.12...1.1.0) + +- RDK-52028 : Add CMS,WB,ALS to AVOutput (#6139) [`#23`](https://github.com/rdkcentral/entservices-inputoutput/pull/23) +- [RDKEMW-2711] RDKEMW-4232: Moving the L2 Test files to entservices-inputoutput [`#107`](https://github.com/rdkcentral/entservices-inputoutput/pull/107) +- [RDKEMW-2711] RDKEMW-3851: L1 - Move plugins Unit test to inputoutput repo [`#92`](https://github.com/rdkcentral/entservices-inputoutput/pull/92) +- RDKEMW-4155: Fix L1-test for HdcpProfile [`#111`](https://github.com/rdkcentral/entservices-inputoutput/pull/111) +- RDKEMW-4155 : Fix L1/L2 tests for HdcpProfile plugin [`#102`](https://github.com/rdkcentral/entservices-inputoutput/pull/102) +- RDK-55554 : Gtest for HdmiCecSource and sink [`#78`](https://github.com/rdkcentral/entservices-inputoutput/pull/78) +- RDK-55373:[RDKServices] Coverity integration with middleware componen… [`#96`](https://github.com/rdkcentral/entservices-inputoutput/pull/96) +- RDK-55373:[RDKServices] Coverity integration with middleware component workflow [`#94`](https://github.com/rdkcentral/entservices-inputoutput/pull/94) +- Merge tag '1.0.12' into develop [`2019c9f`](https://github.com/rdkcentral/entservices-inputoutput/commit/2019c9f8d72eba911fe9030cf4476ce99c2127de) + #### [1.0.12](https://github.com/rdkcentral/entservices-inputoutput/compare/1.0.11...1.0.12) +> 1 May 2025 + - RDKEMW-1014 : Add COM-RPC support to HdcpProfile plugin [`#72`](https://github.com/rdkcentral/entservices-inputoutput/pull/72) - RDK-55373:[RDKServices] Coverity integration with middleware component workflow [`#80`](https://github.com/rdkcentral/entservices-inputoutput/pull/80) - [RDKEMW-2711] RDKEMW-2748 : Update the Test Coverage [`#75`](https://github.com/rdkcentral/entservices-inputoutput/pull/75) - Update Utils.py [`#73`](https://github.com/rdkcentral/entservices-inputoutput/pull/73) +- RDKEMW-1014 - Changelog updates for 1.0.12 [`5f66dc2`](https://github.com/rdkcentral/entservices-inputoutput/commit/5f66dc28ba8ce5a57ba6dddd587db529110298e7) - Merge tag '1.0.11' into develop [`c86b827`](https://github.com/rdkcentral/entservices-inputoutput/commit/c86b82721e32a4bbc828003d0fd5cf76c77d8cca) #### [1.0.11](https://github.com/rdkcentral/entservices-inputoutput/compare/1.0.10...1.0.11) diff --git a/CMakeLists.txt b/CMakeLists.txt index d474ddb0..a3036b26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,14 @@ string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY) # for writing pc and config files include(CmakeHelperFunctions) +if(RDK_SERVICE_L2_TEST) + add_subdirectory(Tests/L2Tests) +endif() + +if(RDK_SERVICES_L1_TEST) + add_subdirectory(Tests/L1Tests) +endif() + if(PLUGIN_AVINPUT) add_subdirectory(AVInput) endif() diff --git a/HdcpProfile/HdcpProfile.cpp b/HdcpProfile/HdcpProfile.cpp index 4b24b151..bcfa8f63 100644 --- a/HdcpProfile/HdcpProfile.cpp +++ b/HdcpProfile/HdcpProfile.cpp @@ -84,6 +84,7 @@ namespace WPEFramework { message = _T("HdcpProfile could not be configured"); } + configure->Release(); } else { @@ -126,7 +127,6 @@ namespace WPEFramework _hdcpProfile->Unregister(&_hdcpProfileNotification); Exchange::JHdcpProfile::Unregister(*this); - // Stop processing: RPC::IRemoteConnection *connection = service->RemoteConnection(_connectionId); VARIABLE_IS_NOT_USED uint32_t result = _hdcpProfile->Release(); diff --git a/HdcpProfile/HdcpProfileImplementation.cpp b/HdcpProfile/HdcpProfileImplementation.cpp index 83456c9e..69b55a21 100644 --- a/HdcpProfile/HdcpProfileImplementation.cpp +++ b/HdcpProfile/HdcpProfileImplementation.cpp @@ -61,6 +61,14 @@ HdcpProfileImplementation::~HdcpProfileImplementation() { LOGINFO("Call HdcpProfileImplementation destructor\n"); + if (_powerManagerPlugin) { + _powerManagerPlugin.Reset(); + } + if(_service != nullptr) + { + _service->Release(); + } + DeinitializeIARM(); HdcpProfileImplementation::_instance = nullptr; mShell = nullptr; } diff --git a/Tests/.clang-format b/Tests/.clang-format new file mode 100755 index 00000000..423360be --- /dev/null +++ b/Tests/.clang-format @@ -0,0 +1,108 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^"config\.h"' + Priority: -1 + # The main header for a source file automatically gets category 0 + - Regex: '.*' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/Tests/L1Tests/.lcovrc_l1 b/Tests/L1Tests/.lcovrc_l1 new file mode 100644 index 00000000..879fe2ce --- /dev/null +++ b/Tests/L1Tests/.lcovrc_l1 @@ -0,0 +1,181 @@ +# +# /etc/lcovrc - system-wide defaults for LCOV +# +# To change settings for a single user, place a customized copy of this file +# at location ~/.lcovrc +# + +# Specify an external style sheet file (same as --css-file option of genhtml) +#genhtml_css_file = gcov.css + +# Specify coverage rate limits (in %) for classifying file entries +# HI: hi_limit <= rate <= 100 graph color: green +# MED: med_limit <= rate < hi_limit graph color: orange +# LO: 0 <= rate < med_limit graph color: red +genhtml_hi_limit = 75 +genhtml_med_limit = 50 + +# Width of line coverage field in source code view +genhtml_line_field_width = 12 + +# Width of branch coverage field in source code view +genhtml_branch_field_width = 16 + +# Width of overview image (used by --frames option of genhtml) +genhtml_overview_width = 80 + +# Resolution of overview navigation: this number specifies the maximum +# difference in lines between the position a user selected from the overview +# and the position the source code window is scrolled to (used by --frames +# option of genhtml) +genhtml_nav_resolution = 4 + +# Clicking a line in the overview image should show the source code view at +# a position a bit further up so that the requested line is not the first +# line in the window. This number specifies that offset in lines (used by +# --frames option of genhtml) +genhtml_nav_offset = 10 + +# Do not remove unused test descriptions if non-zero (same as +# --keep-descriptions option of genhtml) +genhtml_keep_descriptions = 0 + +# Do not remove prefix from directory names if non-zero (same as --no-prefix +# option of genhtml) +genhtml_no_prefix = 0 + +# Do not create source code view if non-zero (same as --no-source option of +# genhtml) +genhtml_no_source = 0 + +# Replace tabs with number of spaces in source view (same as --num-spaces +# option of genhtml) +genhtml_num_spaces = 8 + +# Highlight lines with converted-only data if non-zero (same as --highlight +# option of genhtml) +genhtml_highlight = 0 + +# Include color legend in HTML output if non-zero (same as --legend option of +# genhtml) +genhtml_legend = 0 + +# Use FILE as HTML prolog for generated pages (same as --html-prolog option of +# genhtml) +#genhtml_html_prolog = FILE + +# Use FILE as HTML epilog for generated pages (same as --html-epilog option of +# genhtml) +#genhtml_html_epilog = FILE + +# Use custom filename extension for pages (same as --html-extension option of +# genhtml) +#genhtml_html_extension = html + +# Compress all generated html files with gzip. +#genhtml_html_gzip = 1 + +# Include sorted overview pages (can be disabled by the --no-sort option of +# genhtml) +genhtml_sort = 1 + +# Include function coverage data display (can be disabled by the +# --no-func-coverage option of genhtml) +#genhtml_function_coverage = 1 + +# Include branch coverage data display (can be disabled by the +# --no-branch-coverage option of genhtml) +#genhtml_branch_coverage = 1 + +# Specify the character set of all generated HTML pages +genhtml_charset=UTF-8 + +# Allow HTML markup in test case description text if non-zero +genhtml_desc_html=0 + +# Specify the precision for coverage rates +#genhtml_precision=1 + +# Show missed counts instead of hit counts +#genhtml_missed=1 + +# Demangle C++ symbols +#genhtml_demangle_cpp=1 + +# Name of the tool used for demangling C++ function names +#genhtml_demangle_cpp_tool = c++filt + +# Specify extra parameters to be passed to the demangling tool +#genhtml_demangle_cpp_params = "" + +# Location of the gcov tool (same as --gcov-info option of geninfo) +#geninfo_gcov_tool = gcov + +# Adjust test names to include operating system information if non-zero +#geninfo_adjust_testname = 0 + +# Calculate checksum for each source code line if non-zero (same as --checksum +# option of geninfo if non-zero, same as --no-checksum if zero) +#geninfo_checksum = 1 + +# Specify whether to capture coverage data for external source files (can +# be overridden by the --external and --no-external options of geninfo/lcov) +#geninfo_external = 1 + +# Enable libtool compatibility mode if non-zero (same as --compat-libtool option +# of geninfo if non-zero, same as --no-compat-libtool if zero) +#geninfo_compat_libtool = 0 + +# Use gcov's --all-blocks option if non-zero +#geninfo_gcov_all_blocks = 1 + +# Specify compatiblity modes (same as --compat option of geninfo). +#geninfo_compat = libtool=on, hammer=auto, split_crc=auto + +# Adjust path to source files by removing or changing path components that +# match the specified pattern (Perl regular expression format) +#geninfo_adjust_src_path = /tmp/build => /usr/src + +# Specify if geninfo should try to automatically determine the base-directory +# when collecting coverage data. +geninfo_auto_base = 1 + +# Use gcov intermediate format? Valid values are 0, 1, auto +geninfo_intermediate = auto + +# Specify if exception branches should be excluded from branch coverage. +geninfo_no_exception_branch = 0 + +# Directory containing gcov kernel files +# lcov_gcov_dir = /proc/gcov + +# Location of the insmod tool +lcov_insmod_tool = /sbin/insmod + +# Location of the modprobe tool +lcov_modprobe_tool = /sbin/modprobe + +# Location of the rmmod tool +lcov_rmmod_tool = /sbin/rmmod + +# Location for temporary directories +lcov_tmp_dir = /tmp + +# Show full paths during list operation if non-zero (same as --list-full-path +# option of lcov) +lcov_list_full_path = 0 + +# Specify the maximum width for list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_width = 80 + +# Specify the maximum percentage of file names which may be truncated when +# choosing a directory prefix in list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_truncate_max = 20 + +# Specify if function coverage data should be collected and processed. +lcov_function_coverage = 1 + +# Specify if branch coverage data should be collected and processed. +lcov_branch_coverage = 0 diff --git a/Tests/L1Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt new file mode 100755 index 00000000..33773882 --- /dev/null +++ b/Tests/L1Tests/CMakeLists.txt @@ -0,0 +1,168 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 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. + +cmake_minimum_required(VERSION 3.8) +set(PLUGIN_NAME L1TestsIO) +set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) + +set(CMAKE_CXX_STANDARD 11) + +find_package(${NAMESPACE}Plugins REQUIRED) + +set (TEST_SRC + tests/test_UtilsFile.cpp +) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/e39786088138f2749d64e9e90e0f9902daa77c40.zip +) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +FetchContent_MakeAvailable(googletest) + +set (TEST_LIB + gmock_main + ${NAMESPACE}Plugins::${NAMESPACE}Plugins +) + +set (TEST_INC ../../helpers) + +######################################################################################### +# add_plugin_test_ex: Macro to add plugin tests, it will append to TEST_SRC, TEST_INC, +# and TEST_LIB. Args are positional. +# arg1: test file list as **string** +# arg2: include dir list as **string** +# arg3: plugin libs to link list as **string** +# +# sample invocation : +# add_plugin_test_ex(PLUGIN_NAME +# "test/file1.cpp;test/file2.cpp" +# "../../inc_dir1;../../inc_dir2" +# "${NAMESPACE}PluginName;${NAMESPACE}PluginNameImplementation") +# ----------------------------------------- OR ------------------------------------------ +# list(APPEND PLUGIN_NAME_SRC test/file1.cpp) +# list(APPEND PLUGIN_NAME_SRC test/file2.cpp) +# +# list(APPEND PLUGIN_NAME_INC ../../inc_dir1) +# list(APPEND PLUGIN_NAME_INC ../../inc_dir2) +# +# list(APPEND PLUGIN_NAME_LIB ${NAMESPACE}PluginName) +# list(APPEND PLUGIN_NAME_LIB ${NAMESPACE}PluginNameImplementation) +# +# add_plugin_test_ex(PLUGIN_NAME +# "${PLUGIN_NAME_SRC}" +# "${PLUGIN_NAME_INC}" +# "${PLUGIN_NAME_LIB}") +# +# NOTE: Alternatively test can choose to update `TEST_SRC`, `TEST_INC` & `TEST_LIB` +# directly (like in the case of Miracast) +######################################################################################### +macro(add_plugin_test_ex plugin_opt plugin_test_sources_str plugin_includes_str plugin_libs_str) + # Check if the plugin option is enabled + if(${plugin_opt}) + message(STATUS "${plugin_opt}=ON") + + string(REPLACE ";" ";" srclist "${plugin_test_sources_str}") + string(REPLACE ";" ";" inclist "${plugin_includes_str}") + string(REPLACE ";" ";" liblist "${plugin_libs_str}") + + foreach(item IN LISTS srclist) + # Add each test source file + list(APPEND TEST_SRC ${item}) + endforeach() + + foreach(item IN LISTS inclist) + # Add each include directory + list(APPEND TEST_INC ${item}) + endforeach() + + foreach(item IN LISTS liblist) + # Add each libraries to link + list(APPEND TEST_LIB ${item}) + endforeach() + else() + message(STATUS "${plugin_opt}=OFF") + endif() +endmacro() + +# helper to add plugin test +macro(add_plugin_test plugin_name test_files) + # Convert plugin name to uppercase for the option variable + string(TOUPPER "${plugin_name}" plugin_option) + set(plugin_opt "PLUGIN_${plugin_option}") + + add_plugin_test_ex(${plugin_opt} "${test_files}" "../../${plugin_name}" "${NAMESPACE}${plugin_name}") +endmacro() + +# PLUGIN_HDCPPROFILE +set (HDCPPROFILE_INC ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/HdcpProfile ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/helpers) +set (HDCPPROFILE_LIBS ${NAMESPACE}HdcpProfile ${NAMESPACE}HdcpProfileImplementation) +add_plugin_test_ex(PLUGIN_HDCPPROFILE tests/test_HdcpProfile.cpp "${HDCPPROFILE_INC}" "${HDCPPROFILE_LIBS}") + +# PLUGIN_HDMIINPUT +set (HDMIINPUT_INC ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/HdmiInput ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/helpers) +add_plugin_test_ex(PLUGIN_HDMIINPUT tests/test_HdmiInput.cpp "${HDMIINPUT_INC}" "${NAMESPACE}HdmiInput") + +# PLUGIN_HDMICEC2 +add_plugin_test_ex(PLUGIN_HDMICEC2 tests/test_HdmiCec2.cpp "../../HdmiCec_2" "${NAMESPACE}HdmiCec_2") + +# PLUGIN_HDMICECSINK +set (HDMICECSINK_INC ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/HdmiCecSink ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/helpers) +add_plugin_test_ex(PLUGIN_HDMICECSINK tests/test_HdmiCecSink.cpp "${HDMICECSINK_INC}" "${NAMESPACE}HdmiCecSink") + +# PLUGIN_HDMICECSOURCE +set (HDMICECSOURCE_INC ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/HdmiCecSource ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/helpers) +set (HDMICECSOURCE_LIBS ${NAMESPACE}HdmiCecSource ${NAMESPACE}HdmiCecSourceImplementation) +add_plugin_test_ex(PLUGIN_HDMICECSOURCE tests/test_HdmiCecSource.cpp "${HDMICECSOURCE_INC}" "${HDMICECSOURCE_LIBS}") + +# PLUGIN_AVINPUT +set (AVINPUT_INC ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/AVInput ${CMAKE_SOURCE_DIR}/../entservices-inputoutput/helpers) +add_plugin_test_ex(PLUGIN_AVINPUT tests/test_AVInput.cpp "${AVINPUT_INC}" "${NAMESPACE}AVInput") + +add_library(${MODULE_NAME} SHARED ${TEST_SRC}) + +if (RDK_SERVICES_L1_TEST) + find_library(TESTMOCKLIB_LIBRARIES NAMES L1TestMocklib) + if (TESTMOCKLIB_LIBRARIES) + message ("Found mock libraries ${TESTMOCKLIB_LIBRARIES} library") + target_link_libraries(${MODULE_NAME} ${TESTMOCKLIB_LIBRARIES}) + else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") + endif (TESTMOCKLIB_LIBRARIES) +endif (RDK_SERVICES_L1_TEST) + +include_directories(${TEST_INC}) + +target_link_directories(${MODULE_NAME} PUBLIC ${CMAKE_INSTALL_PREFIX}/lib/wpeframework/plugins) + +target_link_libraries(${MODULE_NAME} ${TEST_LIB}) + +target_include_directories(${MODULE_NAME} + PUBLIC + $ + $ + ${CMAKE_SOURCE_DIR}/../entservices-testframework/Tests/mocks + ${CMAKE_SOURCE_DIR}/../entservices-testframework/Tests/mocks/devicesettings + ${CMAKE_SOURCE_DIR}/../entservices-testframework/Tests/mocks/thunder + ${CMAKE_SOURCE_DIR}/../Thunder/Source/plugins + ) + +install(TARGETS ${MODULE_NAME} DESTINATION lib) +write_config(${PLUGIN_NAME}) + + diff --git a/Tests/L1Tests/tests/test_AVInput.cpp b/Tests/L1Tests/tests/test_AVInput.cpp new file mode 100644 index 00000000..fae90a90 --- /dev/null +++ b/Tests/L1Tests/tests/test_AVInput.cpp @@ -0,0 +1,113 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2024 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. +**/ + +#include + +#include "AVInput.h" + +#include "HdmiInputMock.h" +#include "ThunderPortability.h" + +using namespace WPEFramework; + +using ::testing::NiceMock; + +class AVInputTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + string response; + + AVInputTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + { + } + virtual ~AVInputTest() = default; +}; + +class AVInputDsTest : public AVInputTest { +protected: + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; + + AVInputDsTest() + : AVInputTest() + { + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); + } + virtual ~AVInputDsTest() override + { + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } + } +}; + +TEST_F(AVInputTest, RegisteredMethods) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("numberOfInputs"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("currentVideoMode"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("contentProtected"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEdid2AllmSupport"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getEdid2AllmSupport"))); +} + +TEST_F(AVInputTest, contentProtected) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("contentProtected"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"isContentProtected\":true,\"success\":true}")); +} + +TEST_F(AVInputDsTest, numberOfInputs) +{ + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) + .WillByDefault(::testing::Return(1)); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("numberOfInputs"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"numberOfInputs\":1,\"success\":true}")); +} + +TEST_F(AVInputDsTest, currentVideoMode) +{ + ON_CALL(*p_hdmiInputImplMock, getCurrentVideoMode()) + .WillByDefault(::testing::Return(string("unknown"))); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("currentVideoMode"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"currentVideoMode\":\"unknown\",\"success\":true}")); +} + +TEST_F(AVInputDsTest, getEdid2AllmSupport) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getEdid2AllmSupport"), _T("{\"portId\": \"0\",\"allmSupport\":true}"), response)); + EXPECT_EQ(response, string("{\"allmSupport\":true,\"success\":true}")); +} + + +TEST_F(AVInputDsTest, setEdid2AllmSupport) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEdid2AllmSupport"), _T("{\"portId\": \"0\",\"allmSupport\":true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + diff --git a/Tests/L1Tests/tests/test_HdcpProfile.cpp b/Tests/L1Tests/tests/test_HdcpProfile.cpp new file mode 100755 index 00000000..dbcd5562 --- /dev/null +++ b/Tests/L1Tests/tests/test_HdcpProfile.cpp @@ -0,0 +1,527 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2024 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. +**/ + +#include + +#include "HdcpProfile.h" + +#include "FactoriesImplementation.h" +#include "HostMock.h" +#include "ManagerMock.h" +#include "VideoOutputPortConfigMock.h" +#include "VideoOutputPortMock.h" +#include "IarmBusMock.h" +#include "ServiceMock.h" +#include "dsMgr.h" +#include "dsDisplay.h" +#include "ThunderPortability.h" +#include "pwrMgr.h" +#include "PowerManagerMock.h" + +#include +#include +#include +#include +#include "COMLinkMock.h" +#include "WrapsMock.h" +#include "IarmBusMock.h" +#include "WorkerPoolImplementation.h" +#include "HdcpProfileImplementation.h" + +using namespace WPEFramework; + +using ::testing::NiceMock; + +class HDCPProfileTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + Core::JSONRPC::Message message; + string response; + + WrapsImplMock *p_wrapsImplMock = nullptr; + IarmBusImplMock *p_iarmBusImplMock = nullptr; + Core::ProxyType hdcpProfileImpl; + + NiceMock comLinkMock; + NiceMock service; + PLUGINHOST_DISPATCHER* dispatcher; + Core::ProxyType workerPool; + + NiceMock factoriesImplementation; + + HDCPProfileTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + , workerPool(Core::ProxyType::Create(2, Core::Thread::DefaultStackSize(), 16)) + { + p_wrapsImplMock = new NiceMock; + printf("Pass created wrapsImplMock: %p ", p_wrapsImplMock); + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + + ON_CALL(service, COMLink()) + .WillByDefault(::testing::Invoke( + [this]() { + TEST_LOG("Pass created comLinkMock: %p ", &comLinkMock); + return &comLinkMock; + })); + + + #ifdef USE_THUNDER_R4 + ON_CALL(comLinkMock, Instantiate(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const RPC::Object& object, const uint32_t waitTime, uint32_t& connectionId) { + hdcpProfileImpl = Core::ProxyType::Create(); + TEST_LOG("Pass created hdcpProfileImpl: %p ", &hdcpProfileImpl); + return &hdcpProfileImpl; + })); + #else + ON_CALL(comLinkMock, Instantiate(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(hdcpProfileImpl)); + #endif /*USE_THUNDER_R4 */ + + PluginHost::IFactories::Assign(&factoriesImplementation); + + Core::IWorkerPool::Assign(&(*workerPool)); + workerPool->Run(); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + + EXPECT_EQ(string(""), plugin->Initialize(&service)); + + } + virtual ~HDCPProfileTest() override + { + TEST_LOG("HdcpProfileTest Destructor"); + + plugin->Deinitialize(&service); + + dispatcher->Deactivate(); + dispatcher->Release(); + + Core::IWorkerPool::Assign(nullptr); + workerPool.Release(); + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + PluginHost::IFactories::Assign(nullptr); + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + + } +}; + +class HDCPProfileDsTest : public HDCPProfileTest { +protected: + HostImplMock *p_hostImplMock = nullptr ; + VideoOutputPortConfigImplMock *p_videoOutputPortConfigImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; + + HDCPProfileDsTest() + : HDCPProfileTest() + { + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + p_videoOutputPortConfigImplMock = new NiceMock ; + device::VideoOutputPortConfig::setImpl(p_videoOutputPortConfigImplMock); + p_videoOutputPortMock = new NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); + } + virtual ~HDCPProfileDsTest() override + { + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::VideoOutputPortConfig::setImpl(nullptr); + if (p_videoOutputPortConfigImplMock != nullptr) + { + delete p_videoOutputPortConfigImplMock; + p_videoOutputPortConfigImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } + } +}; + +class HDCPProfileEventTest : public HDCPProfileDsTest { +protected: + NiceMock service; + NiceMock factoriesImplementation; + PLUGINHOST_DISPATCHER* dispatcher; + Core::JSONRPC::Message message; + + HDCPProfileEventTest() + : HDCPProfileDsTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + } + + virtual ~HDCPProfileEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + + PluginHost::IFactories::Assign(nullptr); + } +}; + +class HDCPProfileEventIarmTest : public HDCPProfileEventTest { +protected: + ManagerImplMock *p_managerImplMock = nullptr ; + IARM_EventHandler_t dsHdmiEventHandler; + + HDCPProfileEventIarmTest() + : HDCPProfileEventTest() + { + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + EXPECT_CALL(*p_managerImplMock, Initialize()) + .Times(::testing::AnyNumber()) + .WillRepeatedly(::testing::Return()); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG)) { + dsHdmiEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDCP_STATUS)) { + dsHdmiEventHandler = handler; + } + return IARM_RESULT_SUCCESS; + })); + + EXPECT_EQ(string(""), plugin->Initialize(&service)); + } + + virtual ~HDCPProfileEventIarmTest() override + { + plugin->Deinitialize(&service); + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } + } +}; + +TEST_F(HDCPProfileTest, RegisteredMethods) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getHDCPStatus"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSettopHDCPSupport"))); +} + +TEST_F(HDCPProfileDsTest, getHDCPStatus_isConnected_false) +{ + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(false)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) + .WillByDefault(::testing::Return(dsHDCP_STATUS_UNPOWERED)); + ON_CALL(*p_videoOutputPortMock, isContentProtected()) + .WillByDefault(::testing::Return(0)); + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_MAX)); + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_MAX)); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDCPStatus"), _T(""), response)); + EXPECT_THAT(response, ::testing::MatchesRegex(_T("\\{" + "\"HDCPStatus\":" + "\\{" + "\"isConnected\":false," + "\"isHDCPCompliant\":false," + "\"isHDCPEnabled\":false," + "\"hdcpReason\":0," + "\"supportedHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"receiverHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"currentHDCPVersion\":\"[1-2]+.[1-4]\"" + "\\}," + "\"success\":true" + "\\}"))); +} + +TEST_F(HDCPProfileDsTest, getHDCPStatus_isConnected_true) +{ + NiceMock videoOutputPortMock; + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) + .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); + ON_CALL(*p_videoOutputPortMock, isContentProtected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDCPStatus"), _T(""), response)); + EXPECT_THAT(response, ::testing::MatchesRegex(_T("\\{" + "\"HDCPStatus\":" + "\\{" + "\"isConnected\":true," + "\"isHDCPCompliant\":true," + "\"isHDCPEnabled\":true," + "\"hdcpReason\":2," + "\"supportedHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"receiverHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"currentHDCPVersion\":\"[1-2]+.[1-4]\"" + "\\}," + "\"success\":true" + "\\}"))); +} + +TEST_F(HDCPProfileDsTest, getSettopHDCPSupport_Hdcp_v1x) +{ + NiceMock videoOutputPortMock; + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_1X)); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSettopHDCPSupport"), _T(""), response)); + EXPECT_THAT(response, ::testing::MatchesRegex(_T("\\{" + "\"supportedHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"isHDCPSupported\":true," + "\"success\":true" + "\\}"))); +} + +TEST_F(HDCPProfileDsTest, getSettopHDCPSupport_Hdcp_v2x) +{ + NiceMock videoOutputPortMock; + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSettopHDCPSupport"), _T(""), response)); + EXPECT_THAT(response, ::testing::MatchesRegex(_T("\\{" + "\"supportedHDCPVersion\":\"[1-2]+.[1-4]\"," + "\"isHDCPSupported\":true," + "\"success\":true" + "\\}"))); +} + +TEST_F(HDCPProfileEventIarmTest, onDisplayConnectionChanged) +{ + ASSERT_TRUE(dsHdmiEventHandler != nullptr); + + Core::Event onDisplayConnectionChanged(false, true); + + NiceMock videoOutputPortMock; + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) + .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); + ON_CALL(*p_videoOutputPortMock, isContentProtected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + + //EXPECT_EQ(text, string(_T(""))); + EXPECT_THAT(text, ::testing::MatchesRegex(_T("\\{" + "\"jsonrpc\":\"2.0\"," + "\"method\":\"client.events.onDisplayConnectionChanged\"," + "\"params\":" + "\\{\"HDCPStatus\":" + "\\{" + "\"isConnected\":true," + "\"isHDCPCompliant\":true," + "\"isHDCPEnabled\":true," + "\"hdcpReason\":2," + "\"supportedHDCPVersion\":\"2.2\"," + "\"receiverHDCPVersion\":\"2.2\"," + "\"currentHDCPVersion\":\"2.2\"" + "\\}" + "\\}" + "\\}"))); + + onDisplayConnectionChanged.SetEvent(); + + return Core::ERROR_NONE; + })); + + EVENT_SUBSCRIBE(0, _T("onDisplayConnectionChanged"), _T("client.events"), message); + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_hpd.event = dsDISPLAY_EVENT_CONNECTED; + dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG, &eventData, 0); + + EXPECT_EQ(Core::ERROR_NONE, onDisplayConnectionChanged.Lock()); + + EVENT_UNSUBSCRIBE(0, _T("onDisplayConnectionChanged"), _T("client.events"), message); +} + +TEST_F(HDCPProfileEventIarmTest, onHdmiOutputHDCPStatusEvent) +{ + ASSERT_TRUE(dsHdmiEventHandler != nullptr); + + Core::Event onDisplayConnectionChanged(false, true); + + NiceMock videoOutputPortMock; + device::VideoOutputPort videoOutputPort; + + string videoPort(_T("HDMI0")); + + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .WillByDefault(::testing::Return(videoPort)); + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(videoOutputPort)); + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) + .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); + ON_CALL(*p_videoOutputPortMock, isContentProtected()) + .WillByDefault(::testing::Return(true)); + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) + .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); + + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + + EXPECT_THAT(text, ::testing::MatchesRegex(_T("\\{" + "\"jsonrpc\":\"2.0\"," + "\"method\":\"client.events.onDisplayConnectionChanged\"," + "\"params\":" + "\\{\"HDCPStatus\":" + "\\{" + "\"isConnected\":true," + "\"isHDCPCompliant\":true," + "\"isHDCPEnabled\":true," + "\"hdcpReason\":2," + "\"supportedHDCPVersion\":\"2.2\"," + "\"receiverHDCPVersion\":\"2.2\"," + "\"currentHDCPVersion\":\"2.2\"" + "\\}" + "\\}" + "\\}"))); + + onDisplayConnectionChanged.SetEvent(); + + return Core::ERROR_NONE; + })); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .WillByDefault( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { + auto* param = static_cast(arg); + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + } + return IARM_RESULT_SUCCESS; + }); + + EVENT_SUBSCRIBE(0, _T("onDisplayConnectionChanged"), _T("client.events"), message); + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_hdcp.hdcpStatus = dsDISPLAY_HDCPPROTOCOL_CHANGE; + dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDCP_STATUS, &eventData, 0); + + EXPECT_EQ(Core::ERROR_NONE, onDisplayConnectionChanged.Lock()); + + EVENT_UNSUBSCRIBE(0, _T("onDisplayConnectionChanged"), _T("client.events"), message); +} diff --git a/Tests/L1Tests/tests/test_HdmiCec2.cpp b/Tests/L1Tests/tests/test_HdmiCec2.cpp new file mode 100644 index 00000000..0ba40518 --- /dev/null +++ b/Tests/L1Tests/tests/test_HdmiCec2.cpp @@ -0,0 +1,644 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 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. + */ + +#include + +#include "HdmiCec.h" +#include "HdmiCec_2.h" + +#include "FactoriesImplementation.h" + + +#include "IarmBusMock.h" +#include "ServiceMock.h" +#include "devicesettings.h" +#include "HdmiCecMock.h" +#include "DisplayMock.h" +#include "VideoOutputPortMock.h" +#include "HostMock.h" +#include "ManagerMock.h" +#include "PowerManagerMock.h" +#include "ThunderPortability.h" + +using namespace WPEFramework; + +class HdmiCec_2Test : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + string response; + + HdmiCec_2Test() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + { + } + virtual ~HdmiCec_2Test() = default; +}; +class HdmiCec_2DsTest : public HdmiCec_2Test { +protected: + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + HdmiCec_2DsTest() + : HdmiCec_2Test() + { + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + } + virtual ~HdmiCec_2DsTest() override + { + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + } +}; + +class HdmiCec_2InitializedTest : public HdmiCec_2Test { +protected: + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; + HostImplMock *p_hostImplMock = nullptr ; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; + MessageEncoderMock *p_messageEncoderMock = nullptr ; + + IARM_EventHandler_t cecMgrEventHandler; + IARM_EventHandler_t dsHdmiEventHandler; + IARM_EventHandler_t pwrMgrEventHandler; + + DisplayMock *p_displayMock = nullptr ; + + HdmiCec_2InitializedTest() + : HdmiCec_2Test() + { + p_iarmBusImplMock = new testing::NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_hostImplMock = new testing::NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_managerImplMock = new testing::NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_videoOutputPortMock = new testing::NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); + + p_displayMock = new testing::NiceMock ; + device::Display::setImpl(p_displayMock); + + //OnCall required for intialize to run properly + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(device::VideoOutputPort::getInstance())); + + ON_CALL(*p_videoOutputPortMock, getDisplay()) + .WillByDefault(::testing::ReturnRef(device::Display::getInstance())); + + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(true)); + + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); + + ON_CALL(*p_displayMock, getEDIDBytes(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](std::vector &edidVec2) { + edidVec2 = std::vector({ 't', 'e', 's', 't' }); + })); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED)) { + EXPECT_TRUE(handler != nullptr); + cecMgrEventHandler = handler; + } + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { + EXPECT_TRUE(handler != nullptr); + cecMgrEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiEventHandler = handler; + } + if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { + EXPECT_TRUE(handler != nullptr); + pwrMgrEventHandler = handler; + } + + return IARM_RESULT_SUCCESS; + })); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .WillByDefault( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { + auto* param = static_cast(arg); + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + } + return IARM_RESULT_SUCCESS; + }); + + + EXPECT_EQ(string(""), plugin->Initialize(nullptr)); + //Set enabled needs to be + ON_CALL(*p_libCCECImplMock, getLogicalAddress(::testing::_)) + .WillByDefault(::testing::Return(1)); + ON_CALL(*p_connectionImplMock, open()) + .WillByDefault(::testing::Return()); + ON_CALL(*p_connectionImplMock, addFrameListener(::testing::_)) + .WillByDefault(::testing::Return()); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + } + virtual ~HdmiCec_2InitializedTest() override + { + int lCounter = 0; + while ((Plugin::HdmiCec_2::_instance->deviceList[0].m_isOSDNameUpdated) && (lCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + lCounter ++; + } + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": false}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + plugin->Deinitialize(nullptr); + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Display::setImpl(nullptr); + if (p_displayMock != nullptr) + { + delete p_displayMock; + p_displayMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } + + } +}; +class HdmiCec_2InitializedEventTest : public HdmiCec_2InitializedTest { +protected: + testing::NiceMock service; + FactoriesImplementation factoriesImplementation; + PLUGINHOST_DISPATCHER* dispatcher; + Core::JSONRPC::Message message; + + HdmiCec_2InitializedEventTest() + : HdmiCec_2InitializedTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + } + + virtual ~HdmiCec_2InitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + +TEST_F(HdmiCec_2Test, RegisteredMethods) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getActiveSourceStatus"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getDeviceList"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getOSDName"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getOTPEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getVendorId"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("performOTPAction"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendKeyPressEvent"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendStandbyMessage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOSDName"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOTPEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVendorId"))); + +} + +TEST_F(HdmiCec_2DsTest, getEnabledFalse) +{ + //Without setting cecEnable to true. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getEnabled"), _T(""), response)); + EXPECT_EQ(response, string("{\"enabled\":false,\"success\":true}")); +} + + +TEST_F(HdmiCec_2InitializedTest, getEnabledTrue) +{ + //Get enabled just checks if CEC is on, which is a global variable. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getEnabled"), _T(""), response)); + EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); + +} + +TEST_F(HdmiCec_2InitializedTest, getActiveSourceStatusTrue) +{ + //SetsOTP to on. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + //Sets Activesource to true + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getActiveSourceStatus"), _T(""), response)); + EXPECT_EQ(response, string("{\"status\":true,\"success\":true}")); + + +} +TEST_F(HdmiCec_2InitializedTest, getActiveSourceStatusFalse) +{ + //ActiveSource is a local variable, no mocked functions to check. + //Active source is false by default. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getActiveSourceStatus"), _T(""), response)); + EXPECT_EQ(response, string("{\"status\":false,\"success\":true}")); +} + + +TEST_F(HdmiCec_2InitializedTest, getDeviceList) +{ + int iCounter = 0; + //Checking to see if one of the values has been filled in (as the rest get filled in at the same time, and waiting if its not. + while ((!Plugin::HdmiCec_2::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + const char* val = "TEST"; + OSDName name = OSDName(val); + SetOSDName osdName = SetOSDName(name); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + VendorID vendor(1,2,3); + DeviceVendorID vendorid(vendor); + + Plugin::HdmiCec_2Processor proc(Connection::getInstance()); + + proc.process(osdName, header); //calls the process that sets osdName for LogicalAddress = 1 + proc.process(vendorid, header); //calls the process that sets vendorID for LogicalAddress = 1 + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"osdName\":\"TEST\",\"vendorID\":\"123\"},{\"logicalAddress\":2,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":3,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":4,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":5,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":6,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":7,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":8,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":9,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":10,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":11,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":12,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":13,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":14,\"osdName\":\"NA\",\"vendorID\":\"000\"}],\"success\":true}"))); + +} + +TEST_F(HdmiCec_2InitializedTest, getOTPEnabled) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOTPEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); + +} + +TEST_F(HdmiCec_2InitializedTest, sendStandbyMessage) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendStandbyMessage"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(HdmiCec_2InitializedTest, setOSDName) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOSDName"), _T("{\"name\": \"CUSTOM8 Tv\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOSDName"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"name\":\"CUSTOM8 Tv\",\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, setVendorId) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVendorId"), _T("{\"vendorid\": \"0x0019FB\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getVendorId"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"vendorid\":\"019fb\",\"success\":true}")); + + +} +TEST_F(HdmiCec_2InitializedTest, setOTPEnabled) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": false}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEventUp) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_UP ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 65}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent2) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_DOWN ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 66}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent3) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_MUTE ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 67}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent4) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_UP ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 1}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent5) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_DOWN ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 2}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent6) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_LEFT ); + return CECFrame::getInstance(); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 3}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent7) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_RIGHT ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 4}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent8) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_SELECT ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 0}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent9) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_HOME ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 9}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent10) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_BACK ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 13}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent11) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_0 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 32}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent12) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_1 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 33}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent13) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_2 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 34}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent14) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_3 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 35}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent15) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_4 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 36}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent16) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_5 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 37}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent17) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_6 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 38}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent18) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_7 ); + return CECFrame::getInstance(); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 39}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent19) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_8 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 40}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent20) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_9 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 41}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + diff --git a/Tests/L1Tests/tests/test_HdmiCecSink.cpp b/Tests/L1Tests/tests/test_HdmiCecSink.cpp new file mode 100755 index 00000000..2f570df1 --- /dev/null +++ b/Tests/L1Tests/tests/test_HdmiCecSink.cpp @@ -0,0 +1,502 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2024 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. +**/ + +#include +#include +#include +#include + +#include "HdmiCecSink.h" +#include "FactoriesImplementation.h" +#include "IarmBusMock.h" +#include "ServiceMock.h" +#include "devicesettings.h" +#include "HdmiCec.h" +#include "HdmiCecMock.h" +#include "WrapsMock.h" +#include "RfcApiMock.h" +#include "ThunderPortability.h" +#include "PowerManagerMock.h" + +using namespace WPEFramework; +using ::testing::NiceMock; + +namespace +{ + static void removeFile(const char* fileName) + { + if (std::remove(fileName) != 0) + { + printf("File %s failed to remove\n", fileName); + perror("Error deleting file"); + } + else + { + printf("File %s successfully deleted\n", fileName); + } + } + + static void createFile(const char* fileName, const char* fileContent) + { + removeFile(fileName); + + std::ofstream fileContentStream(fileName); + fileContentStream << fileContent; + fileContentStream << "\n"; + fileContentStream.close(); + } +} + +class HdmiCecSinkWOInitializeTest : public ::testing::Test { +protected: + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + MessageEncoderMock *p_messageEncoderMock = nullptr ; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; + WrapsImplMock *p_wrapsImplMock = nullptr ; + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + NiceMock rfcApiImplMock; + NiceMock wrapsImplMock; + IARM_EventHandler_t dsHdmiEventHandler; + string response; + + HdmiCecSinkWOInitializeTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + { + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_rfcApiImplMock = new testing::NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + p_wrapsImplMock = new testing::NiceMock ; + Wraps::setImpl(p_wrapsImplMock); /*Set up mock for fopen; + to use the mock implementation/the default behavior of the fopen function from Wraps class.*/ + + ON_CALL(*p_connectionImplMock, poll(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const LogicalAddress &from, const Throw_e &doThrow) { + throw CECNoAckException(); + })); + + EXPECT_CALL(*p_libCCECImplMock, getPhysicalAddress(::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](uint32_t *physAddress) { + *physAddress = (uint32_t)0x12345678; + })); + + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiEventHandler = handler; + } + return IARM_RESULT_SUCCESS; + })); + + ON_CALL(*p_connectionImplMock, open()) + .WillByDefault(::testing::Return()); + + } + + virtual ~HdmiCecSinkWOInitializeTest() override + { + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } + + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + } +}; + +class HdmiCecSinkTest : public HdmiCecSinkWOInitializeTest { +protected: + //Exchange::IPowerManager::IModeChangedNotification* _notification = nullptr; + + HdmiCecSinkTest() + : HdmiCecSinkWOInitializeTest() + { + removeFile("/etc/device.properties"); + createFile("/etc/device.properties", "RDK_PROFILE=TV"); + //EXPECT_CALL(PowerManagerMock::Mock(), Register(Exchange::IPowerManager::IModeChangedNotification* notification)) + // .WillOnce( + // [this](Exchange::IPowerManager::IModeChangedNotification* notification) -> uint32_t { + // _notification = notification; + // return Core::ERROR_NONE; + // }); + EXPECT_EQ(string(""), plugin->Initialize(nullptr)); + } + + virtual ~HdmiCecSinkTest() override + { + plugin->Deinitialize(nullptr); + removeFile("/etc/device.properties"); + } +}; + +class HdmiCecSinkDsTest : public HdmiCecSinkTest { +protected: + string response; + + HdmiCecSinkDsTest(): HdmiCecSinkTest() + { + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .WillByDefault( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { + auto* param = static_cast(arg); + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + } + if (strcmp(methodName, IARM_BUS_DSMGR_API_dsHdmiInGetNumberOfInputs) == 0) { + auto* param = static_cast(arg); + param->result = dsERR_NONE; + param->numHdmiInputs = 3; + } + if (strcmp(methodName, IARM_BUS_DSMGR_API_dsHdmiInGetStatus) == 0) { + auto* param = static_cast(arg); + param->result = dsERR_NONE; + param->status.isPortConnected[1] = 1; + } + if (strcmp(methodName, IARM_BUS_DSMGR_API_dsGetHDMIARCPortId) == 0) { + auto* param = static_cast(arg); + param->portId = 1; + } + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + } + virtual ~HdmiCecSinkDsTest() override { + } +}; + +class HdmiCecSinkInitializedEventTest : public HdmiCecSinkDsTest { +protected: + NiceMock service; + NiceMock factoriesImplementation; + PLUGINHOST_DISPATCHER* dispatcher; + Core::JSONRPC::Message message; + + HdmiCecSinkInitializedEventTest(): HdmiCecSinkDsTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + } + virtual ~HdmiCecSinkInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + } +}; + +class HdmiCecSinkInitializedEventDsTest : public HdmiCecSinkInitializedEventTest { +protected: + HdmiCecSinkInitializedEventDsTest(): HdmiCecSinkInitializedEventTest() + { + } + virtual ~HdmiCecSinkInitializedEventDsTest() override + { + } +}; + +TEST_F(HdmiCecSinkWOInitializeTest, NotSupportPlugin) +{ + removeFile("/etc/device.properties"); + EXPECT_EQ(string("Not supported"), plugin->Initialize(nullptr)); + createFile("/etc/device.properties", "RDK_PROFILE=STB"); + EXPECT_EQ(string("Not supported"), plugin->Initialize(nullptr)); + removeFile("/etc/device.properties"); + createFile("/etc/device.properties", "RDK_PROFILE=TV"); + EXPECT_EQ(string(""), plugin->Initialize(nullptr)); + plugin->Deinitialize(nullptr); + removeFile("/etc/device.properties"); + +} + +TEST_F(HdmiCecSinkTest, RegisteredMethods) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOSDName"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVendorId"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getVendorId"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setActivePath"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setRoutingChange"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getDeviceList"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getActiveSource"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setActiveSource"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getActiveRoute"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setMenuLanguage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("requestActiveSource"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setupARCRouting"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("requestShortAudioDescriptor"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendStandbyMessage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendAudioDevicePowerOnMessage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendKeyPressEvent"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendGetAudioStatusMessage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getAudioDeviceConnectedStatus"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("requestAudioDevicePowerStatus"))); + +} + +TEST_F(HdmiCecSinkDsTest, setOSDNameParamMissing) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setOSDName"), _T("{}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, getOSDName) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOSDName"), _T("{\"name\":\"CECTEST\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOSDName"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"name\":\"CECTEST\",\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, setVendorIdParamMissing) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setVendorId"), _T("{}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, getVendorId) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVendorId"), _T("{\"vendorid\":\"0x0019FF\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getVendorId"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"vendorid\":\"019ff\",\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, setActivePathMissingParam) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setActivePath"), _T("{}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, setActivePath) +{ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { + EXPECT_EQ(to.toInt(), LogicalAddress::BROADCAST); + EXPECT_GT(timeout, 0); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setActivePath"), _T("{\"activePath\":\"2.0.0.0\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, setRoutingChangeInvalidParam) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setRoutingChange"), _T("{\"oldPort\":\"HDMI0\"}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, setRoutingChange) +{ + + std::this_thread::sleep_for(std::chrono::seconds(30)); + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { + EXPECT_EQ(to.toInt(), LogicalAddress::BROADCAST); + EXPECT_GT(timeout, 0); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setRoutingChange"), _T("{\"oldPort\":\"HDMI0\",\"newPort\":\"TV\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, setMenuLanguageInvalidParam) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setMenuLanguage"), _T("{\"language\":""}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, setMenuLanguage) +{ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { + EXPECT_LE(to.toInt(), LogicalAddress::BROADCAST); + EXPECT_GT(timeout, 0); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setMenuLanguage"), _T("{\"language\":\"english\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, setupARCRoutingInvalidParam) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setupARCRouting"), _T("{}"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, setupARCRouting) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setupARCRouting"), _T("{\"enabled\":\"true\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCecSinkDsTest, sendKeyPressEventMissingParam) +{ + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": }"), response)); + EXPECT_EQ(response, string("")); + +} + +TEST_F(HdmiCecSinkDsTest, sendKeyPressEvent) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 65}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +TEST_F(HdmiCecSinkInitializedEventDsTest, onHdmiOutputHDCPStatusEvent) +{ + + ASSERT_TRUE(dsHdmiEventHandler != nullptr); + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_connect.port =dsHDMI_IN_PORT_1; + eventData.data.hdmi_in_connect.isPortConnected = true; + + EVENT_SUBSCRIBE(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); + + dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); + +} + +TEST_F(HdmiCecSinkInitializedEventDsTest, powerModeChange) +{ + // ASSERT_TRUE(pwrMgrModeChangeEventHandler != nullptr); + + IARM_Bus_PWRMgr_EventData_t eventData; + eventData.data.state.newState =IARM_BUS_PWRMGR_POWERSTATE_ON; + eventData.data.state.curState =IARM_BUS_PWRMGR_POWERSTATE_STANDBY; + + (void) eventData; + + // pwrMgrModeChangeEventHandler(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_MODECHANGED, &eventData , 0); +} + +TEST_F(HdmiCecSinkTest, DISABLED_getCecVersion) +{ + /*EXPECT_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { + EXPECT_EQ(string(pcCallerID), string("HdmiCecSink")); + EXPECT_EQ(string(pcParameterName), string("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.HdmiCecSink.CECVersion")); + strncpy(pstParamData->value, "1.4", sizeof(pstParamData->value)); + return WDMP_SUCCESS; + }));*/ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCecVersion"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"CECVersion\":\"1.4\",\"success\":true}")); + +} diff --git a/Tests/L1Tests/tests/test_HdmiCecSource.cpp b/Tests/L1Tests/tests/test_HdmiCecSource.cpp new file mode 100755 index 00000000..9a08cadb --- /dev/null +++ b/Tests/L1Tests/tests/test_HdmiCecSource.cpp @@ -0,0 +1,1452 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 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. + */ + +#include +#include +#include +#include +#include + +#include "HdmiCecSourceImplementation.h" +#include "HdmiCec.h" +#include "HdmiCecSource.h" +#include "pwrMgr.h" +#include "PowerManagerMock.h" +#include "FactoriesImplementation.h" +#include "IarmBusMock.h" +#include "ServiceMock.h" +#include "devicesettings.h" +#include "HdmiCecMock.h" +#include "DisplayMock.h" +#include "VideoOutputPortMock.h" +#include "HostMock.h" +#include "ManagerMock.h" +#include "ThunderPortability.h" +#include "COMLinkMock.h" +#include "HdmiCecSourceMock.h" +#include "WorkerPoolImplementation.h" +#include "WrapsMock.h" + +#define JSON_TIMEOUT (1000) + +using namespace WPEFramework; +using ::testing::NiceMock; + +namespace +{ + static void removeFile(const char* fileName) + { + if (std::remove(fileName) != 0) + { + printf("File %s failed to remove\n", fileName); + perror("Error deleting file"); + } + else + { + printf("File %s successfully deleted\n", fileName); + } + } + + static void createFile(const char* fileName, const char* fileContent) + { + removeFile(fileName); + + std::ofstream fileContentStream(fileName); + fileContentStream << fileContent; + fileContentStream << "\n"; + fileContentStream.close(); + } +} + +typedef enum : uint32_t { + HdmiCecSource_OnDeviceAdded = 0x00000001, + HdmiCecSource_OnDeviceRemoved = 0x00000002, + HdmiCecSource_OnDeviceInfoUpdated = 0x00000004, + HdmiCecSource_OnActiveSourceStatusUpdated = 0x00000008, + HdmiCecSource_StandbyMessageReceived = 0x00000010, + HdmiCecSource_OnKeyReleaseEvent = 0x00000020, + HdmiCecSource_OnKeyPressEvent = 0x00000040, +} HdmiCecSourceEventType_t; + + +class NotificationHandler : public Exchange::IHdmiCecSource::INotification { + private: + /** @brief Mutex */ + std::mutex m_mutex; + + /** @brief Condition variable */ + std::condition_variable m_condition_variable; + + /** @brief Event signalled flag */ + uint32_t m_event_signalled; + bool m_OnDeviceAdded_signalled =false; + bool m_onDeviceRemoved_signalled =false; + bool m_OnDeviceInfoUpdated_signalled =false; + bool m_OnActiveSourceStatusUpdated_signalled = false; + bool m_StandbyMessageReceived_signalled = false; + bool m_OnKeyReleaseEvent=false; + bool m_OnKeyPressEvent=false; + + + BEGIN_INTERFACE_MAP(Notification) + INTERFACE_ENTRY(Exchange::IHdmiCecSource::INotification) + END_INTERFACE_MAP + + public: + NotificationHandler(){} + ~NotificationHandler(){} + + void OnDeviceAdded(const int logicalAddress) override + { + TEST_LOG("OnDeviceAdded event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + m_event_signalled |= HdmiCecSource_OnDeviceAdded; + m_OnDeviceAdded_signalled = true; + m_condition_variable.notify_one(); + + + } + void OnDeviceRemoved(const int logicalAddress) override + { + TEST_LOG("OnDeviceRemoved event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + m_event_signalled |= HdmiCecSource_OnDeviceRemoved; + m_onDeviceRemoved_signalled = true; + m_condition_variable.notify_one(); + } + void OnDeviceInfoUpdated(const int logicalAddress) override + { + TEST_LOG("OnDeviceInfoUpdated event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + m_event_signalled |= HdmiCecSource_OnDeviceInfoUpdated; + m_OnDeviceInfoUpdated_signalled = true; + m_condition_variable.notify_one(); + } + void OnActiveSourceStatusUpdated(const bool status) override + { + TEST_LOG("OnActiveSourceStatusUpdated event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("status: %d\n", status); + m_event_signalled |= HdmiCecSource_OnActiveSourceStatusUpdated; + m_OnActiveSourceStatusUpdated_signalled = true; + m_condition_variable.notify_one(); + } + void StandbyMessageReceived(const int logicalAddress) override + { + TEST_LOG("StandbyMessageReceived event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + m_event_signalled |= HdmiCecSource_StandbyMessageReceived; + m_StandbyMessageReceived_signalled = true; + m_condition_variable.notify_one(); + } + void OnKeyReleaseEvent(const int logicalAddress) override + { + TEST_LOG("OnKeyReleaseEvent event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + m_event_signalled |= HdmiCecSource_OnKeyReleaseEvent; + m_OnKeyReleaseEvent = true; + m_condition_variable.notify_one(); + } + void OnKeyPressEvent(const int logicalAddress, const int keyCode) override + { + TEST_LOG("OnKeyPressEvent event trigger ***\n"); + std::unique_lock lock(m_mutex); + + TEST_LOG("LogicalAddress: %d\n", logicalAddress); + TEST_LOG("KeyCode: %d\n", keyCode); + m_event_signalled |= HdmiCecSource_OnKeyPressEvent; + m_OnKeyPressEvent = true; + m_condition_variable.notify_one(); + } + + bool WaitForRequestStatus(uint32_t timeout_ms, HdmiCecSourceEventType_t expected_status) + { + std::unique_lock lock(m_mutex); + auto now = std::chrono::system_clock::now(); + std::chrono::milliseconds timeout(timeout_ms); + bool signalled = false; + + while (!(expected_status & m_event_signalled)) + { + if (m_condition_variable.wait_until(lock, now + timeout) == std::cv_status::timeout) + { + TEST_LOG("Timeout waiting for request status event"); + break; + } + } + + switch(m_event_signalled) + { + case HdmiCecSource_OnDeviceAdded: + signalled = m_OnDeviceAdded_signalled; + break; + case HdmiCecSource_OnDeviceRemoved: + signalled = m_onDeviceRemoved_signalled; + break; + case HdmiCecSource_OnDeviceInfoUpdated: + signalled = m_OnDeviceInfoUpdated_signalled; + break; + case HdmiCecSource_OnActiveSourceStatusUpdated: + signalled = m_OnActiveSourceStatusUpdated_signalled; + break; + case HdmiCecSource_StandbyMessageReceived: + signalled = m_StandbyMessageReceived_signalled; + break; + case HdmiCecSource_OnKeyReleaseEvent: + signalled = m_OnKeyReleaseEvent; + break; + case HdmiCecSource_OnKeyPressEvent: + signalled = m_OnKeyPressEvent; + break; + default: + signalled = false; + break; + } + + + signalled = m_event_signalled; + return signalled; + } + }; + + +class HdmiCecSourceTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + DECL_CORE_JSONRPC_CONX connection; + string response; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + IARM_EventHandler_t cecMgrEventHandler; + IARM_EventHandler_t dsHdmiEventHandler; + IARM_EventHandler_t pwrMgrEventHandler; + ManagerImplMock *p_managerImplMock = nullptr ; + HostImplMock *p_hostImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; + DisplayMock *p_displayMock = nullptr ; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + MessageEncoderMock *p_messageEncoderMock = nullptr ; + WrapsImplMock *p_wrapsImplMock = nullptr; + ServiceMock *p_serviceMock = nullptr; + HdmiCecSourceMock *p_hdmiCecSourceMock = nullptr; + testing::NiceMock comLinkMock; + testing::NiceMock service; + Core::ProxyType workerPool; + Core::ProxyType HdmiCecSourceImplementationImpl; + Exchange::IHdmiCecSource::INotification *HdmiCecSourceNotification = nullptr; + + HdmiCecSourceTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , INIT_CONX(1, 0) + , workerPool(Core::ProxyType::Create( + 2, Core::Thread::DefaultStackSize(), 16)) + { + p_iarmBusImplMock = new testing::NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_managerImplMock = new testing::NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + p_hostImplMock = new testing::NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_videoOutputPortMock = new testing::NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); + + p_displayMock = new testing::NiceMock ; + device::Display::setImpl(p_displayMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_serviceMock = new testing::NiceMock ; + + p_hdmiCecSourceMock = new NiceMock ; + + p_wrapsImplMock = new NiceMock ; + + Wraps::setImpl(p_wrapsImplMock); + + ON_CALL(*p_hdmiCecSourceMock, Register(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](Exchange::IHdmiCecSource::INotification *notification){ + HdmiCecSourceNotification = notification; + return Core::ERROR_NONE;; + })); + + + ON_CALL(service, COMLink()) + .WillByDefault(::testing::Invoke( + [this]() { + TEST_LOG("Pass created comLinkMock: %p ", &comLinkMock); + return &comLinkMock; + })); + + //OnCall required for intialize to run properly + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); + + ON_CALL(*p_videoOutputPortMock, getDisplay()) + .WillByDefault(::testing::ReturnRef(device::Display::getInstance())); + + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) + .WillByDefault(::testing::Return(true)); + + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) + .WillByDefault(::testing::ReturnRef(device::VideoOutputPort::getInstance())); + + ON_CALL(*p_displayMock, getEDIDBytes(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](std::vector &edidVec2) { + edidVec2 = std::vector({ 't', 'e', 's', 't' }); + })); + //Set enabled needs to be + ON_CALL(*p_libCCECImplMock, getLogicalAddress(::testing::_)) + .WillByDefault(::testing::Return(0)); + + ON_CALL(*p_connectionImplMock, open()) + .WillByDefault(::testing::Return()); + ON_CALL(*p_connectionImplMock, addFrameListener(::testing::_)) + .WillByDefault(::testing::Return()); + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED)) { + EXPECT_TRUE(handler != nullptr); + cecMgrEventHandler = handler; + } + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { + EXPECT_TRUE(handler != nullptr); + cecMgrEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiEventHandler = handler; + } + if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { + EXPECT_TRUE(handler != nullptr); + pwrMgrEventHandler = handler; + } + + return IARM_RESULT_SUCCESS; + })); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .WillByDefault( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { + auto* param = static_cast(arg); + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + } + return IARM_RESULT_SUCCESS; + }); + + } + virtual ~HdmiCecSourceTest() override + { + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::Display::setImpl(nullptr); + if (p_displayMock != nullptr) + { + delete p_displayMock; + p_displayMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } + + Core::IWorkerPool::Assign(nullptr); + workerPool.Release(); + + if (p_serviceMock != nullptr) + { + delete p_serviceMock; + p_serviceMock = nullptr; + } + + if (p_hdmiCecSourceMock != nullptr) + { + delete p_hdmiCecSourceMock; + p_hdmiCecSourceMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + } +}; + +class HdmiCecSourceInitializedTest : public HdmiCecSourceTest { +protected: + HdmiCecSourceInitializedTest() + : HdmiCecSourceTest() + { + system("ls -lh /etc/"); + removeFile("/etc/device.properties"); + system("ls -lh /etc/"); + createFile("/etc/device.properties", "RDK_PROFILE=STB"); + system("ls -lh /etc/"); + EXPECT_EQ(string(""), plugin->Initialize(&service)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + } + virtual ~HdmiCecSourceInitializedTest() override + { + int lCounter = 0; + while ((Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (lCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + lCounter ++; + } + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": false}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + plugin->Deinitialize(&service); + removeFile("/etc/device.properties"); + + } +}; +class HdmiCecSourceInitializedEventTest : public HdmiCecSourceInitializedTest { +protected: + + FactoriesImplementation factoriesImplementation; + PLUGINHOST_DISPATCHER* dispatcher; + Core::JSONRPC::Message message; + + HdmiCecSourceInitializedEventTest() + : HdmiCecSourceInitializedTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + } + + virtual ~HdmiCecSourceInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + +TEST_F(HdmiCecSourceInitializedTest, RegisteredMethods) +{ + + removeFile("/etc/device.properties"); + createFile("/etc/device.properties", "RDK_PROFILE=STB"); + + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getActiveSourceStatus"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getDeviceList"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getOSDName"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getOTPEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getVendorId"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("performOTPAction"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendKeyPressEvent"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendStandbyMessage"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOSDName"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOTPEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVendorId"))); + + removeFile("/etc/device.properties"); + +} + +TEST_F(HdmiCecSourceInitializedTest, getEnabledTrue) +{ + //Get enabled just checks if CEC is on, which is a global variable. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getEnabled"), _T(""), response)); + EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); + +} + +TEST_F(HdmiCecSourceInitializedTest, getActiveSourceStatusTrue) +{ + //SetsOTP to on. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + //Sets Activesource to true + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getActiveSourceStatus"), _T(""), response)); + EXPECT_EQ(response, string("{\"status\":true,\"success\":true}")); + + +} +TEST_F(HdmiCecSourceInitializedTest, getActiveSourceStatusFalse) +{ + //ActiveSource is a local variable, no mocked functions to check. + //Active source is false by default. + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getActiveSourceStatus"), _T(""), response)); + EXPECT_EQ(response, string("{\"status\":false,\"success\":true}")); +} + + +TEST_F(HdmiCecSourceInitializedTest, getDeviceList) +{ + int iCounter = 0; + //Checking to see if one of the values has been filled in (as the rest get filled in at the same time, and waiting if its not. + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + const char* val = "TEST"; + OSDName name = OSDName(val); + SetOSDName osdName = SetOSDName(name); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + VendorID vendor(1,2,3); + DeviceVendorID vendorid(vendor); + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + + proc.process(osdName, header); //calls the process that sets osdName for LogicalAddress = 1 + proc.process(vendorid, header); //calls the process that sets vendorID for LogicalAddress = 1 + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"123\",\"osdName\":\"TEST\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + + +} + + +TEST_F(HdmiCecSourceInitializedTest, getOTPEnabled) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOTPEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); + +} + +TEST_F(HdmiCecSourceInitializedTest, sendStandbyMessage) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendStandbyMessage"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(HdmiCecSourceInitializedTest, setOSDName) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOSDName"), _T("{\"name\": \"CUSTOM8 Tv\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOSDName"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"name\":\"CUSTOM8 Tv\",\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, setVendorId) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVendorId"), _T("{\"vendorid\": \"0x0019FB\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getVendorId"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"vendorid\":\"019fb\",\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, setOTPEnabled) +{ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": false}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + + +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEventUp) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_UP ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 65}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent2) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_DOWN ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 66}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent3) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_MUTE ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 67}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent4) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_UP ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 1}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent5) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_DOWN ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 2}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent6) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_LEFT ); + return CECFrame::getInstance(); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 3}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent7) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_RIGHT ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 4}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent8) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_SELECT ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 0}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent9) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_HOME ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 9}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent10) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_BACK ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 13}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent11) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_0 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 32}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent12) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_1 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 33}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent13) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_2 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 34}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent14) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_3 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 35}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent15) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_4 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 36}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent16) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_5 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 37}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent17) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_6 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 38}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent18) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_7 ); + return CECFrame::getInstance(); + })); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 39}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent19) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_8 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 40}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} +TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent20) +{ + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) + .WillByDefault(::testing::Invoke( + [](const UserControlPressed& m) -> CECFrame& { + EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_9 ); + return CECFrame::getInstance(); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 41}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + +} + +//Failing to remove file when triggered on github. There might be some kind of permission issue. +TEST_F(HdmiCecSourceTest, DISABLED_NotSupportedPlugin) +{ + system("ls -lh /etc/"); + removeFile("/etc/device.properties"); + system("ls -lh /etc/"); + EXPECT_EQ(string("Not supported"), plugin->Initialize(&service)); + createFile("/etc/device.properties", "RDK_PROFILE=TV"); + system("ls -lh /etc/"); + EXPECT_EQ(string("Not supported"), plugin->Initialize(&service)); + removeFile("/etc/device.properties"); + system("ls -lh /etc/"); + createFile("/etc/device.properties", "RDK_PROFILE=STB"); + system("ls -lh /etc/"); + EXPECT_EQ(string(""), plugin->Initialize(&service)); + plugin->Deinitialize(&service); + removeFile("/etc/device.properties"); + system("ls -lh /etc/"); +} + +TEST_F(HdmiCecSourceInitializedTest, GetInformation) +{ + EXPECT_EQ("This HdmiCecSource PLugin Facilitates the HDMI CEC Source Control", plugin->Information()); +} + +TEST_F(HdmiCecSourceInitializedTest, activeSourceProcess) +{ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; +} + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + PhysicalAddress physicalAddress(0x0F,0x0F,0x0F,0x0F); + PhysicalAddress physicalAddress2(1,2,3,4); + ActiveSource activeSource(physicalAddress); + ActiveSource activeSource2(physicalAddress2); + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(activeSource2, header); + proc.process(activeSource, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + + +} + +TEST_F(HdmiCecSourceInitializedTest, imageViewOnProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; +} + + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + ImageViewOn imageViewOn; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(imageViewOn, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, textViewOnProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; +} + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + TextViewOn textViewOn; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(textViewOn, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, requestActiveSourceProccess){ + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + //Sets Activesource to true + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 15); + })); + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + RequestActiveSource requestActiveSource; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(requestActiveSource, header); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, standyProcess){ + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + Standby standby; + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(standby, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_StandbyMessageReceived); + + EXPECT_TRUE(signalled); +} + + +TEST_F(HdmiCecSourceInitializedEventTest, requestGetCECVersionProcess){ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 1); + })); + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + GetCECVersion getCecVersion; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(getCecVersion, header); + +} + + +TEST_F(HdmiCecSourceInitializedEventTest, CecVersionProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; +} + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + CECVersion cecVersion(Version::V_1_4); + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(cecVersion, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, giveOSDNameProcess){ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 1); + })); + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + GiveOSDName giveOSDName; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(giveOSDName, header); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, givePhysicalAddressProcess){ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 15); + })); + + + Header header; + header.from = LogicalAddress(15); //specifies with logicalAddress in the deviceList we're using + + GivePhysicalAddress givePhysicalAddress; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(givePhysicalAddress, header); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, giveDeviceVendorIdProcess){ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 15); + })); + + + Header header; + header.from = LogicalAddress(15); //specifies with logicalAddress in the deviceList we're using + + GiveDeviceVendorID giveDeviceVendorID; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(giveDeviceVendorID, header); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, setOSDNameProcess){ + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + OSDName osdName("Test"); + + SetOSDName setOSDName(osdName); + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(setOSDName, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnDeviceInfoUpdated); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, routingChangeProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + PhysicalAddress physicalAddress(0x0F,0x0F,0x0F,0x0F); + PhysicalAddress physicalAddress2(1,2,3,4); + + RoutingChange routingChange(physicalAddress,physicalAddress2); + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(routingChange, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnActiveSourceStatusUpdated); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, routingInformationProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + RoutingInformation routingInformation; + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(routingInformation, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnActiveSourceStatusUpdated); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, setStreamPathProcess){ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + PhysicalAddress physicalAddress(0x0F,0x0F,0x0F,0x0F); + + SetStreamPath setStreamPath(physicalAddress); + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(setStreamPath, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnActiveSourceStatusUpdated); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, reportPhysicalAddressProcess){ + + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + PhysicalAddress physicalAddress(0x0F,0x0F,0x0F,0x0F); + DeviceType deviceType(1); + + ReportPhysicalAddress reportPhysicalAddress(physicalAddress, deviceType); + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(reportPhysicalAddress, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + + +} + + +TEST_F(HdmiCecSourceInitializedEventTest, deviceVendorIDProcess){ + + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + + VendorID vendorID(1,2,3); + + DeviceVendorID deviceVendorID(vendorID); + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(deviceVendorID, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnDeviceInfoUpdated); + + EXPECT_TRUE(signalled); +} + + +TEST_F(HdmiCecSourceInitializedEventTest, GiveDevicePowerStatusProcess){ + + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](const LogicalAddress &to, const CECFrame &frame) { + EXPECT_EQ(to.toInt(), 1); + })); + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + GiveDevicePowerStatus deviceDevicePowerStatus; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(deviceDevicePowerStatus, header); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, reportPowerStatusProcess){ + + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + PowerStatus powerStatus(0); + + ReportPowerStatus reportPowerStatus(powerStatus); + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(reportPowerStatus, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + + +} + +TEST_F(HdmiCecSourceInitializedEventTest, userControlPressedProcess){ + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + UserControlPressed userControlPressed(UICommand::UI_COMMAND_VOLUME_UP); + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(userControlPressed, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnKeyPressEvent); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, userControlReleasedrocess){ + Core::Sink notification; + uint32_t signalled = false; + p_hdmiCecSourceMock->AddRef(); + p_hdmiCecSourceMock->Register(¬ification); + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + UserControlReleased userControlReleased; + + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(userControlReleased, header); + + signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, HdmiCecSource_OnKeyReleaseEvent); + + EXPECT_TRUE(signalled); +} + +TEST_F(HdmiCecSourceInitializedEventTest, abortProcess){ + + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + + Header header; + header.from = LogicalAddress(1); //specifies with logicalAddress in the deviceList we're using + + Abort abort; + + + Plugin::HdmiCecSourceProcessor proc(Connection::getInstance()); + proc.process(abort, header); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); + + EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":2,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":3,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":4,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":5,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":6,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":7,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":8,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":9,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":10,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":11,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":12,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":13,\"vendorID\":\"000\",\"osdName\":\"NA\"},{\"logicalAddress\":14,\"vendorID\":\"000\",\"osdName\":\"NA\"}],\"success\":true}"))); + +} + +TEST_F(HdmiCecSourceInitializedEventTest, hdmiEventHandler) +{ + int iCounter = 0; + while ((!Plugin::HdmiCecSourceImplementation::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } + + ASSERT_TRUE(dsHdmiEventHandler != nullptr); + EXPECT_CALL(*p_hostImplMock, getDefaultVideoPortName()) + .Times(1) + .WillOnce(::testing::Return("TEST")); + + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_hpd.event = 0; + + EVENT_SUBSCRIBE(0, _T("onHdmiHotPlug"), _T("client.events.onHdmiHotPlug"), message); + + dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onHdmiHotPlug"), _T("client.events.onHdmiHotPlug"), message); +} + + +TEST_F(HdmiCecSourceInitializedEventTest, powerModeChanged) +{ + EXPECT_CALL(*p_libCCECImplMock, getLogicalAddress(::testing::_)) + .WillRepeatedly(::testing::Invoke( + [&](int devType) { + EXPECT_EQ(devType, 1); + return 0; + })); + + Plugin::HdmiCecSourceImplementation::_instance->onPowerModeChanged(WPEFramework::Exchange::IPowerManager::POWER_STATE_OFF, WPEFramework::Exchange::IPowerManager::POWER_STATE_ON); + + +} + diff --git a/Tests/L1Tests/tests/test_HdmiInput.cpp b/Tests/L1Tests/tests/test_HdmiInput.cpp new file mode 100644 index 00000000..9b0b1f66 --- /dev/null +++ b/Tests/L1Tests/tests/test_HdmiInput.cpp @@ -0,0 +1,861 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2024 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. +**/ + +#include + +#include "HdmiInput.h" + +#include "FactoriesImplementation.h" + +#include "HdmiInputMock.h" +#include "IarmBusMock.h" +#include "ServiceMock.h" + +#include "dsMgr.h" +#include "ThunderPortability.h" + +using namespace WPEFramework; + +using ::testing::NiceMock; + +class HdmiInputTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + Core::JSONRPC::Handler& handlerV2; + DECL_CORE_JSONRPC_CONX connection; + string response; + + HdmiInputTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , handlerV2(*(plugin->GetHandler(2))) + , INIT_CONX(1, 0) + { + } + virtual ~HdmiInputTest() = default; +}; + +class HdmiInputDsTest : public HdmiInputTest { +protected: + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; + + HdmiInputDsTest() + : HdmiInputTest() + { + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); + } + virtual ~HdmiInputDsTest() override + { + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } + } +}; + +class HdmiInputInitializedTest : public HdmiInputTest { +protected: + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + IARM_EventHandler_t dsHdmiEventHandler; + IARM_EventHandler_t dsHdmiStatusEventHandler; + IARM_EventHandler_t dsHdmiSignalStatusEventHandler; + IARM_EventHandler_t dsHdmiVideoModeEventHandler; + IARM_EventHandler_t dsHdmiGameFeatureStatusEventHandler; + + // NiceMock service; + ServiceMock service; + + HdmiInputInitializedTest() + : HdmiInputTest() + { + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_)) + .Times(::testing::AnyNumber()) + .WillRepeatedly(::testing::Invoke( + [&](const uint32_t, const string& name) -> void* { + return nullptr; + })); + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiStatusEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiSignalStatusEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiVideoModeEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_ALLM_STATUS)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiGameFeatureStatusEventHandler = handler; + } + return IARM_RESULT_SUCCESS; + })); + + EXPECT_EQ(string(""), plugin->Initialize(&service)); + } + virtual ~HdmiInputInitializedTest() override + { + plugin->Deinitialize(&service); + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } +}; + + +class HdmiInputInitializedEventTest : public HdmiInputInitializedTest { +protected: + NiceMock service; + NiceMock factoriesImplementation; + PLUGINHOST_DISPATCHER* dispatcher; + Core::JSONRPC::Message message; + + HdmiInputInitializedEventTest() + : HdmiInputInitializedTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PLUGINHOST_DISPATCHER_ID)); + dispatcher->Activate(&service); + } + + virtual ~HdmiInputInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + + PluginHost::IFactories::Assign(nullptr); + } +}; + +class HdmiInputInitializedEventDsTest : public HdmiInputInitializedEventTest { +protected: + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; + + HdmiInputInitializedEventDsTest() + : HdmiInputInitializedEventTest() + { + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); + } + + virtual ~HdmiInputInitializedEventDsTest() override + { + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } + } +}; + +TEST_F(HdmiInputTest, RegisteredMethods) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getHDMIInputDevices"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("writeEDID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("readEDID"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getRawHDMISPD"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getHDMISPD"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("setEdidVersion"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getEdidVersion"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startHdmiInput"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopHdmiInput"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVideoRectangle"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSupportedGameFeatures"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getHdmiGameFeatureStatus"))); + + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getHDMIInputDevices"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("writeEDID"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("readEDID"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("startHdmiInput"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("stopHdmiInput"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("setVideoRectangle"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getSupportedGameFeatures"))); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Exists(_T("getHdmiGameFeatureStatus"))); +} + +TEST_F(HdmiInputDsTest, getHDMIInputDevices) +{ + + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) + .WillByDefault(::testing::Return(1)); + ON_CALL(*p_hdmiInputImplMock, isPortConnected(::testing::_)) + .WillByDefault(::testing::Return(true)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDMIInputDevices"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":\"true\"}],\"success\":true}")); +} + + +TEST_F(HdmiInputDsTest, writeEDIDEmpty) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("writeEDID"), _T("{\"message\": \"message\"}"), response)); + EXPECT_EQ(response, string("")); +} + + +TEST_F(HdmiInputDsTest, writeEDID) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("writeEDID"), _T("{\"deviceId\": 0, \"message\": \"message\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(HdmiInputDsTest, writeEDIDInvalid) +{ + ON_CALL(*p_hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector &edidVec2) { + edidVec2 = std::vector({ 't', 'e', 's', 't' }); + })); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("readEDID"), _T("{\"deviceId\": \"b\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, readEDID) +{ + ON_CALL(*p_hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector &edidVec2) { + edidVec2 = std::vector({ 't', 'e', 's', 't' }); + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("readEDID"), _T("{\"deviceId\": 0}"), response)); + EXPECT_EQ(response, string("{\"EDID\":\"dGVzdA==\",\"success\":true}")); +} + +TEST_F(HdmiInputDsTest, getRawHDMISPD) +{ + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector& edidVec2) { + edidVec2 = { 't', 'e', 's', 't' }; + })); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getRawHDMISPD"), _T("{\"portId\":0}"), response)); + EXPECT_EQ(response, string("{\"HDMISPD\":\"dGVzdA\",\"success\":true}")); +} +TEST_F(HdmiInputDsTest, getRawHDMISPDInvalid) +{ + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector& edidVec2) { + edidVec2 = { 't', 'e', 's', 't' }; + })); + EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("getRawHDMISPD"), _T("{\"portId\":\"b\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, getHDMISPD) +{ + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector& edidVec2) { + edidVec2 = {'0','1','2','n', 'p', '1','2','3','4','5','6','7',0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',0,'q','r'}; + })); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getHDMISPD"), _T("{\"portId\":0}"), response)); + EXPECT_EQ(response, string("{\"HDMISPD\":\"Packet Type:30,Version:49,Length:50,vendor name:1234567,product des:abcdefghijklmno,source info:71\",\"success\":true}")); +} +TEST_F(HdmiInputDsTest, getHDMISPDInvalid) +{ + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, std::vector& edidVec2) { + edidVec2 = {'0','1','2','n', 'p', '0'}; + })); + EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("getHDMISPD"), _T("{\"portId\":\"b\"}"), response)); + EXPECT_EQ(response, string("")); +} + + +TEST_F(HdmiInputDsTest, setEdidVersionInvalid) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("setEdidVersion"), _T("{\"portId\": \"b\", \"edidVersion\":\"HDMI1.4\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, setEdidVersion14) +{ + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("setEdidVersion"), _T("{\"portId\": \"0\", \"edidVersion\":\"HDMI1.4\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(HdmiInputDsTest, setEdidVersion20) +{ + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("setEdidVersion"), _T("{\"portId\": \"0\", \"edidVersion\":\"HDMI2.0\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} +TEST_F(HdmiInputDsTest, setEdidVersionEmpty) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("setEdidVersion"), _T("{\"portId\": \"0\", \"edidVersion\":\"\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, getEdidVersionInvalid) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("getEdidVersion"), _T("{\"portId\": \"b\", \"edidVersion\":\"HDMI1.4\"}"), response)); + EXPECT_EQ(response, string("")); +} +TEST_F(HdmiInputDsTest, getEdidVersionVer14) +{ + ON_CALL(*p_hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iPort, int *edidVersion) { + *edidVersion = 0; + })); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getEdidVersion"), _T("{\"portId\": \"0\"}"), response)); + EXPECT_EQ(response, string("{\"edidVersion\":\"HDMI1.4\",\"success\":true}")); +} +TEST_F(HdmiInputDsTest, getEdidVersionVer20) +{ + ON_CALL(*p_hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iPort, int *edidVersion) { + *edidVersion = 1; + })); + EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getEdidVersion"), _T("{\"portId\": \"0\"}"), response)); + EXPECT_EQ(response, string("{\"edidVersion\":\"HDMI2.0\",\"success\":true}")); +} + +TEST_F(HdmiInputDsTest, startHdmiInputInvalid) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("startHdmiInput"), _T("{\"portId\": \"b\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, startHdmiInput) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startHdmiInput"), _T("{\"portId\": \"0\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + + +TEST_F(HdmiInputDsTest, stopHdmiInput) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopHdmiInput"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(HdmiInputDsTest, setVideoRectangleInvalid) +{ + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setVideoRectangle"), _T("{\"x\": \"b\",\"y\": 0,\"w\": 1920,\"h\": 1080}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, setVideoRectangle) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVideoRectangle"), _T("{\"x\": 0,\"y\": 0,\"w\": 1920,\"h\": 1080}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + + +TEST_F(HdmiInputDsTest, getSupportedGameFeatures) +{ + ON_CALL(*p_hdmiInputImplMock, getSupportedGameFeatures(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](std::vector &supportedFeatures) { + supportedFeatures = {"ALLM"}; + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSupportedGameFeatures"), _T("{\"supportedGameFeatures\": \"ALLM\"}"), response)); + EXPECT_EQ(response, string("{\"supportedGameFeatures\":[\"ALLM\"],\"success\":true}")); +} + + +TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatusInvalidPort) +{ + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, bool *allm) { + *allm = true; + })); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getHdmiGameFeatureStatus"), _T("{\"portId\": \"b\",\"gameFeature\": \"ALLM\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatus) +{ + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, bool *allm) { + *allm = true; + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHdmiGameFeatureStatus"), _T("{\"portId\": \"0\",\"gameFeature\": \"ALLM\"}"), response)); + EXPECT_EQ(response, string("{\"mode\":true,\"success\":true}")); +} +TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatusInvalidFeature) +{ + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + .WillByDefault(::testing::Invoke( + [&](int iport, bool *allm) { + *allm = true; + })); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getHdmiGameFeatureStatus"), _T("{\"portId\": \"0\",\"gameFeature\": \"Invalid\"}"), response)); + EXPECT_EQ(response, string("")); +} + +TEST_F(HdmiInputInitializedEventDsTest, onDevicesChanged) +{ + ASSERT_TRUE(dsHdmiEventHandler != nullptr); + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) + .WillByDefault(::testing::Return(1)); + ON_CALL(*p_hdmiInputImplMock, isPortConnected(::testing::_)) + .WillByDefault(::testing::Return(true)); + + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onDevicesChanged.onDevicesChanged\",\"params\":{\"devices\":[{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":\"true\"}]}}"))); + + return Core::ERROR_NONE; + })); + + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_connect.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_connect.isPortConnected = true; + + EVENT_SUBSCRIBE(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); + + dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); +} + +TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOn) +{ + ASSERT_TRUE(dsHdmiStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onInputStatusChanged.onInputStatusChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"status\":\"started\",\"plane\":0}}"))); + return Core::ERROR_NONE; + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startHdmiInput"), _T("{\"portId\": \"0\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_status.isPresented = true; + + EVENT_SUBSCRIBE(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); + + dsHdmiStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOff) +{ + ASSERT_TRUE(dsHdmiStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onInputStatusChanged.onInputStatusChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"status\":\"stopped\",\"plane\":-1}}"))); + return Core::ERROR_NONE; + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopHdmiInput"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_status.isPresented = false; + + EVENT_SUBSCRIBE(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); + + dsHdmiStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedStable) +{ + ASSERT_TRUE(dsHdmiSignalStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onSignalChanged.onSignalChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"signalStatus\":\"stableSignal\"}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_STABLE; + + EVENT_SUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + + dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNoSignal) +{ + ASSERT_TRUE(dsHdmiSignalStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onSignalChanged.onSignalChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"signalStatus\":\"noSignal\"}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOSIGNAL; + + EVENT_SUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + + dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedUnstable) +{ + ASSERT_TRUE(dsHdmiSignalStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onSignalChanged.onSignalChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"signalStatus\":\"unstableSignal\"}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_UNSTABLE; + + EVENT_SUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + + dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNotSupported) +{ + ASSERT_TRUE(dsHdmiSignalStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onSignalChanged.onSignalChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"signalStatus\":\"notSupportedSignal\"}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOTSUPPORTED; + + EVENT_SUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + + dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + +} +TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedDefault) +{ + ASSERT_TRUE(dsHdmiSignalStatusEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onSignalChanged.onSignalChanged\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"signalStatus\":\"none\"}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_MAX; + + EVENT_SUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + + dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); +} + +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate1) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":1920,\"height\":1080,\"progressive\":false,\"frameRateN\":60000,\"frameRateD\":1001}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1920x1080; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_59dot94; + + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate2) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":720,\"height\":480,\"progressive\":false,\"frameRateN\":24000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x480; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_24; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate3) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":720,\"height\":576,\"progressive\":false,\"frameRateN\":25000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x576; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_25; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate4) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":3840,\"height\":2160,\"progressive\":false,\"frameRateN\":30000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_3840x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_30; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate5) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":4096,\"height\":2160,\"progressive\":false,\"frameRateN\":50000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_50; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate6) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":4096,\"height\":2160,\"progressive\":false,\"frameRateN\":60000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_60; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate7) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":4096,\"height\":2160,\"progressive\":false,\"frameRateN\":24000,\"frameRateD\":1001}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_23dot98; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate8) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":4096,\"height\":2160,\"progressive\":false,\"frameRateN\":30000,\"frameRateD\":1001}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate9) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":1280,\"height\":720,\"progressive\":false,\"frameRateN\":30000,\"frameRateD\":1001}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1280x720; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdateDefault) +{ + ASSERT_TRUE(dsHdmiVideoModeEventHandler != nullptr); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.videoStreamInfoUpdate.videoStreamInfoUpdate\",\"params\":{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"width\":1920,\"height\":1080,\"progressive\":false,\"frameRateN\":60000,\"frameRateD\":1000}}"))); + return Core::ERROR_NONE; + })); + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_MAX; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate= dsVIDEO_FRAMERATE_MAX; + EVENT_SUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); + EVENT_UNSUBSCRIBE(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); +} +TEST_F(HdmiInputInitializedEventDsTest, hdmiGameFeatureStatusUpdate) +{ + ASSERT_TRUE(dsHdmiGameFeatureStatusEventHandler != nullptr); + + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.hdmiGameFeatureStatusUpdate.hdmiGameFeatureStatusUpdate\",\"params\":{\"id\":0,\"gameFeature\":\"ALLM\",\"mode\":true}}"))); + + return Core::ERROR_NONE; + })); + + + IARM_Bus_DSMgr_EventData_t eventData; + eventData.data.hdmi_in_allm_mode.port =dsHDMI_IN_PORT_0; + eventData.data.hdmi_in_allm_mode.allm_mode = true; + EVENT_SUBSCRIBE(0, _T("hdmiGameFeatureStatusUpdate"), _T("client.events.hdmiGameFeatureStatusUpdate"), message); + + dsHdmiGameFeatureStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_ALLM_STATUS, &eventData , 0); + + EVENT_UNSUBSCRIBE(0, _T("hdmiGameFeatureStatusUpdate"), _T("client.events.hdmiGameFeatureStatusUpdate"), message); +} diff --git a/Tests/L1Tests/tests/test_UtilsFile.cpp b/Tests/L1Tests/tests/test_UtilsFile.cpp new file mode 100644 index 00000000..ed41f3ad --- /dev/null +++ b/Tests/L1Tests/tests/test_UtilsFile.cpp @@ -0,0 +1,64 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 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. + */ + +#include + +#include "Module.h" + +#include "UtilsFile.h" + +namespace { +const uint8_t bytes[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0xFE, 0x03, 0x20, 0x04, 0x00, 0x01 }; +} +#include "ThunderPortability.h" + +using namespace WPEFramework; + +TEST(UtilsFileTest, createFolder_createFile_moveFile_verifyFile) +{ + Core::Directory dir(_T("/tmp/UtilsFileTest")); + +#ifdef USE_THUNDER_R4 + EXPECT_TRUE(dir.Destroy()); +#else + EXPECT_TRUE(dir.Destroy(false)); +#endif /*USE_THUNDER_R4 */ + ASSERT_TRUE(dir.CreatePath()); + + Core::File file(string(_T("/tmp/UtilsFileTest/file"))); + + EXPECT_FALSE(file.Exists()); + EXPECT_TRUE(file.Create()); + EXPECT_EQ(sizeof(bytes), file.Write(bytes, sizeof(bytes))); + + Core::File file2(string(_T("/tmp/UtilsFileTest/destination/for/new/file"))); + + EXPECT_FALSE(file2.Exists()); + EXPECT_TRUE(Utils::MoveFile(file.Name(), file2.Name())); + file.LoadFileInfo(); + file2.LoadFileInfo(); + EXPECT_FALSE(file.Exists()); + EXPECT_TRUE(file2.Exists()); + EXPECT_TRUE(file2.Open(true)); + + uint8_t buffer[2 * sizeof(bytes)]; + + EXPECT_EQ(sizeof(bytes), file2.Read(buffer, 2 * sizeof(bytes))); + EXPECT_EQ(0, memcmp(buffer, bytes, sizeof(bytes))); +} diff --git a/Tests/L2Tests/CMakeLists.txt b/Tests/L2Tests/CMakeLists.txt new file mode 100755 index 00000000..7e852330 --- /dev/null +++ b/Tests/L2Tests/CMakeLists.txt @@ -0,0 +1,85 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 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. + + +set(PLUGIN_NAME L2TestsIO) +set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) +set(THUNDER_PORT 9998) +#set(CMAKE_CXX_STANDARD 11) +find_package(${NAMESPACE}Plugins REQUIRED) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/e39786088138f2749d64e9e90e0f9902daa77c40.zip +) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +FetchContent_MakeAvailable(googletest) + +if(PLUGIN_AVOUTPUT) + set(SRC_FILES ${SRC_FILES} tests/AVOutputTV_L2Test.cpp) +endif() + +add_library(${MODULE_NAME} SHARED ${SRC_FILES}) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_compile_definitions(${MODULE_NAME} + PRIVATE + MODULE_NAME=Plugin_${PLUGIN_NAME} + THUNDER_PORT="${THUNDER_PORT}") + +target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) +target_link_libraries(${MODULE_NAME} PRIVATE gmock_main ${NAMESPACE}Plugins::${NAMESPACE}Plugins) + +if (NOT L2_TEST_OOP_RPC) + find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib) + if (TESTMOCKLIB_LIBRARIES) + message ("Found mock library - ${TESTMOCKLIB_LIBRARIES}") + target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES}) + else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") + endif (TESTMOCKLIB_LIBRARIES) +endif (NOT L2_TEST_OOP_RPC) + +find_library(MOCKACCESSOR_LIBRARIES NAMES MockAccessor) +if (MOCKACCESSOR_LIBRARIES) + message ("Found MockAccessor library - ${MOCKACCESSOR_LIBRARIES}") + target_link_libraries(${MODULE_NAME} PRIVATE ${MOCKACCESSOR_LIBRARIES}) +else (MOCKACCESSOR_LIBRARIES) + message ("Require ${MOCKACCESSOR_LIBRARIES} library") +endif (MOCKACCESSOR_LIBRARIES) + +target_include_directories( + ${MODULE_NAME} PRIVATE ./ + ../../helpers + ../../../entservices-testframework/Tests/mocks + ../../../entservices-testframework/Tests/mocks/thunder + ../../../entservices-testframework/Tests/mocks/devicesettings + ../../../entservices-testframework/Tests/mocks/MockPlugin + ../../../entservices-testframework/Tests/L2Tests/L2TestsPlugin + ${CMAKE_INSTALL_PREFIX}/include + ) + +install(TARGETS ${MODULE_NAME} DESTINATION lib) + +write_config(${PLUGIN_NAME}) + + + diff --git a/Tests/L2Tests/tests/AVOutputTV_L2Test.cpp b/Tests/L2Tests/tests/AVOutputTV_L2Test.cpp new file mode 100755 index 00000000..e7e3b47d --- /dev/null +++ b/Tests/L2Tests/tests/AVOutputTV_L2Test.cpp @@ -0,0 +1,201 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2024 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. +**/ + +#include +#include +#include "L2Tests.h" +#include "L2TestsMock.h" +#include +#include +#include + +#define JSON_TIMEOUT (1000) +#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); +#define AVOUTPUT_CALLSIGN _T("org.rdk.AVOutput.1") +#define AVOUTPUT_CALLSIGNL2TEST_CALLSIGN _T("L2tests.1") + +using ::testing::NiceMock; +using namespace WPEFramework; +using testing::StrictMock; + +/** +* @brief Internal test mock class +* +* Note that this is for internal test use only and doesn't mock any actual +* concrete interface. +*/ + +/* AVOutput L2 test class declaration */ +class AVOutput_L2test : public L2TestMocks { +protected: + Core::JSONRPC::Message message; + string response; + IARM_EventHandler_t dsHdmiStatusEventHandler; + IARM_EventHandler_t dsHdmiVideoModeEventHandler; + + virtual ~AVOutput_L2test() override; + + public: + AVOutput_L2test(); +}; + +/** +* @brief Constructor for AVOutput L2 test class +*/ +AVOutput_L2test::AVOutput_L2test() + : L2TestMocks() +{ + printf("AVOutput Constructor\n"); + uint32_t status = Core::ERROR_GENERAL; + + std::ofstream devicePropFileStream("/etc/device.properties"); + devicePropFileStream << "RDK_PROFILE=TV"; + devicePropFileStream << "\n"; + devicePropFileStream.close(); + + EXPECT_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { + EXPECT_EQ(string(pcCallerID), string("AVOutput")); + EXPECT_EQ(string(pcParameterName), string("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AVOutput.DynamicAutoLatency")); + strncpy(pstParamData->value, "true", sizeof(pstParamData->value)); + return WDMP_SUCCESS; + })); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiStatusEventHandler = handler; + } + if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE)) { + EXPECT_TRUE(handler != nullptr); + dsHdmiVideoModeEventHandler = handler; + } + return IARM_RESULT_SUCCESS; + })); + + ON_CALL(*p_hdmiInputImplMock, getCurrentVideoModeObj(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](dsVideoPortResolution_t& resolution) { + resolution.pixelResolution = dsVIDEO_PIXELRES_1920x1080; + return tvERROR_NONE; + })); + + ON_CALL(*p_tvSettingsImplMock, TvInit()) + .WillByDefault(::testing::Return(tvERROR_NONE)); + + ON_CALL(*p_tvSettingsImplMock, RegisterVideoFormatChangeCB(testing::_)) + .WillByDefault(testing::Return(tvERROR_NONE)); + ON_CALL(*p_tvSettingsImplMock, RegisterVideoContentChangeCB(testing::_)) + .WillByDefault(testing::Return(tvERROR_NONE)); + ON_CALL(*p_tvSettingsImplMock, RegisterVideoResolutionChangeCB(testing::_)) + .WillByDefault(testing::Return(tvERROR_NONE)); + ON_CALL(*p_tvSettingsImplMock, RegisterVideoFrameRateChangeCB(testing::_)) + .WillByDefault(testing::Return(tvERROR_NONE)); + + EXPECT_CALL(*p_tr181ApiImplMock, getLocalParam(::testing::_, ::testing::_, ::testing::_)) + .Times(2) + .WillOnce(::testing::Invoke( + [&](char *pcCallerID, const char* pcParameterName, TR181_ParamData_t *pstParamData) { + EXPECT_EQ(string(pcCallerID), string("AVOutput")); + strncpy(pstParamData->value, "Normal", sizeof(pstParamData->value)); + + return tr181Success; + })) + .WillOnce(::testing::Invoke( + [&](char *pcCallerID, const char* pcParameterName, TR181_ParamData_t *pstParamData) { + EXPECT_EQ(string(pcCallerID), string("AVOutput")); + strncpy(pstParamData->value, "Normal", sizeof(pstParamData->value)); + + return tr181Success; + })); + + ON_CALL(*p_tvSettingsImplMock, SetAspectRatio(testing::_)) + .WillByDefault(testing::Invoke( + [&](tvDisplayMode_t dispMode) { + EXPECT_EQ(dispMode, tvDisplayMode_NORMAL); + return tvERROR_NONE; + })); + + ON_CALL(*p_tvSettingsImplMock, GetCurrentSource(testing::_)) + .WillByDefault(testing::Invoke( + [&](tvVideoSrcType_t *currentSource) { + EXPECT_EQ(*currentSource, VIDEO_SOURCE_IP); + return tvERROR_NONE; + })); + + ON_CALL(*p_tvSettingsImplMock, GetCurrentVideoFormat(testing::_)) + .WillByDefault(testing::Invoke( + [&](tvVideoFormatType_t* videoFormat) { + EXPECT_EQ(*videoFormat, VIDEO_FORMAT_NONE); + return tvERROR_NONE; // Return an appropriate error code + })); + + ON_CALL(*p_tvSettingsImplMock, SetTVPictureMode(testing::_)) + .WillByDefault(testing::Invoke( + [&](const char * pictureMode) { + EXPECT_EQ(string(pictureMode), string("normal")); + return tvERROR_NONE; + })); + + /* Activate plugin in constructor */ + status = ActivateService("org.rdk.AVOutput"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +/** +* @brief Destructor for AVInput L2 test class +*/ +AVOutput_L2test::~AVOutput_L2test() +{ + printf("AVOutput Destructor\n"); + uint32_t status = Core::ERROR_GENERAL; + + ON_CALL(*p_tvSettingsImplMock, TvTerm()) + .WillByDefault(::testing::Return(tvERROR_NONE)); + + status = DeactivateService("org.rdk.AVOutput"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +TEST_F(AVOutput_L2test, AVOUTPUT_GETINPUTDEVICE_Test) +{ + JSONRPC::LinkType jsonrpc(AVOUTPUT_CALLSIGN, AVOUTPUT_CALLSIGNL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject result, params; + + ON_CALL(*p_tvSettingsImplMock, ReadCapablitiesFromConfODM(testing::_, testing::_, testing::_, testing::_, testing::_, testing::_, testing::_)) + .WillByDefault([](std::string& rangeInfo, std::string& pqmodeInfo, std::string& formatInfo, std::string& sourceInfo, std::string param, std::string& platformsupport, std::string& index) { + printf("ReadCapablitiesFromConfODM\n"); + rangeInfo = "\"Standard\",\"Vivid\",\"EnergySaving\",\"Custom\",\"Theater\",\"Game\""; + pqmodeInfo = ""; + formatInfo = "\"SDR\""; + sourceInfo = "\"HDMI\",\"HDMI2\""; + platformsupport = ""; + index = "0"; + + return tvERROR_NONE; + }); + + status = InvokeServiceMethod("org.rdk.AVOutput.1", "getPictureModeCaps", params, result); + +} diff --git a/Tests/README.md b/Tests/README.md new file mode 100644 index 00000000..4b6eb4ac --- /dev/null +++ b/Tests/README.md @@ -0,0 +1,54 @@ +As part of rdkservices open source activity and logical grouping of services into various entservices-* repos, the below listed change to L1 and L2 Test are effective hence forth. + +# Changes Done: +Since the mock part is common across various plugins/repos and common for L1, L2 & etc, the gtest and gmock related stubs (including platform interface mocks) are moved to a new repo called "entservices-testframework" and L1 & L2 test files of each plugin moved to corresponding repos, you can find them inside Tests directory of each entservices-*. +Hence, any modifications/additions related to mocks should be commited to entservices-testframework repo @ rdkcentral and any modifications/additions related to test case should be commited to Test directory of corresponding entservices repo. + +# Individual Repo Handling +Each individual entservices-* repo was added with a .yml file to trigger L1, L2, L2-OOP test job in github workflow. This yml file triggers below mentioned build jobs in addition to regular build jobs (thunder, thunder tools & etc,). + +a/ Build mocks => To create TestMock Lib from all required mock relates stubs and copy to install/usr/lib path. +b/ Build entservices- => To create Test Lib of .so type from all applicable test files which are enabled for plugin test. +c/ Build entservices-testframework => To create L1/L2 executable by linking the plugins/test .so files. + +This ensures everything in-tact in repo level across multiple related plugins when there is a new change comes in. + +# testframework Repo Handling +The entservices-testframework repo contains yml files corresponds to L1, L2 & L2-OOP to trigger test job in github workflow. + +This yml file triggers below mentioned build jobs in addition to regular build jobs (thunder, thunder tools & etc,). + +a/ Build mocks => To create TestMock Lib from all required mock relates stubs and copy to install/usr/lib path. +b/ Build entservices-* => Jobs to checkout/build all individual repo's plugin & test files which are enabled for plugin test and copy all required libs to install/usr/lib path. +c/ Build entservices-testframework => To create L1/L2 executable by linking the plugins/test .so files. + +This ensures everything in-tact across multiple repos when there is a new change comes either in mocks or test case or plugins. + +##### Steps to run L1, L2, L2-OOP test locally ##### +1. checkout the entservices- to your working directory in your build machine. +example: git clone https://github.com/rdkcentral/entservices-testframework.git + +2. switch to entservices- directory +example: cd entservices-testframework + +3. check and ensure current working branch points to develop +example: git branch + +4. Run below curl command to download act executable to your repo. +example: curl -SL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash + +5. 5a/to run L1 test +example: ./bin/act -W .github/workflows/L1-tests.yml -s GITHUB_TOKEN= + +5. 5b/to run L2 test +example: ./bin/act -W .github/workflows/L2-tests.yml -s GITHUB_TOKEN= + +5. 5c/to run L2 test OOP +example: ./bin/act -W .github/workflows/L2-tests-oop.yml -s GITHUB_TOKEN= + +NOTES: +a/ If you face any secret token related error while run your yml, pls comment the below mentioned line +#token: ${{ secrets.RDKE_GITHUB_TOKEN }} +b/ Coverage Report of both L1 and L2 test are uploaded to artifacts server. +c/ For the case, which has modification in plugin and/or test files as well in entservices-testframework mock files, change the ref key of checkout job to point your own branch instead of develop, in both entservices-testframework and entservices-* repo and ensure L1, L2, L2-OOP test jobs are passing for your PR. +example: ref: feature/L1-test diff --git a/Tests/clang.cmake b/Tests/clang.cmake new file mode 100755 index 00000000..e4d5ac4a --- /dev/null +++ b/Tests/clang.cmake @@ -0,0 +1,31 @@ +### +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2024 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. +### + +set(CMAKE_C_COMPILER "/usr/bin/clang") +set(CMAKE_CXX_COMPILER "/usr/bin/clang++") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=missing-braces") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=dangling-gsl") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-const-variable") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=inconsistent-missing-override") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-parameter") + +# clang Valgrind: debuginfo reader: ensure_valid failed +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4") diff --git a/Tests/gcc-with-coverage.cmake b/Tests/gcc-with-coverage.cmake new file mode 100755 index 00000000..6a2b449a --- /dev/null +++ b/Tests/gcc-with-coverage.cmake @@ -0,0 +1,20 @@ +### +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2024 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. +### + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") diff --git a/build_dependencies.sh b/build_dependencies.sh index 3f56b49d..d03a3082 100644 --- a/build_dependencies.sh +++ b/build_dependencies.sh @@ -1,6 +1,6 @@ - #!/bin/bash set -x +set -e ############################## GITHUB_WORKSPACE="${PWD}" ls -la ${GITHUB_WORKSPACE} diff --git a/cov_build.sh b/cov_build.sh index 4e3a28c8..d3915245 100644 --- a/cov_build.sh +++ b/cov_build.sh @@ -1,5 +1,6 @@ #!/bin/bash set -x +set -e ############################## GITHUB_WORKSPACE="${PWD}" ls -la ${GITHUB_WORKSPACE} @@ -17,11 +18,11 @@ cmake -G Ninja -S "$GITHUB_WORKSPACE" -B build/entservices-inputoutput \ -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON \ -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON \ -DCMAKE_DISABLE_FIND_PACKAGE_DS=ON \ +-DCMAKE_DISABLE_FIND_PACKAGE_CEC=ON \ -DCOMCAST_CONFIG=OFF \ -DRDK_SERVICES_COVERITY=ON \ -DRDK_SERVICES_L1_TEST=ON \ -DDS_FOUND=ON \ --DPLUGIN_HDMICECSINK=ON \ -DPLUGIN_HDMICECSOURCE=ON \ -DPLUGIN_HDCPPROFILE=ON \ -DCMAKE_CXX_FLAGS="-DEXCEPTIONS_ENABLE=ON \