Skip to content

Commit 9093339

Browse files
committed
RDKEMW-5197 : Handle the logic for setSDRGamma to set correct enum value
1 parent 7f6c201 commit 9093339

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,11 +1648,11 @@ namespace Plugin {
16481648
}
16491649

16501650
uint32_t AVOutputTV::setContextPQParam(const JsonObject& parameters, JsonObject& response,
1651-
const std::string& inputParamName,
1652-
const std::string& tr181ParamName,
1653-
int maxAllowedValue,
1654-
tvPQParameterIndex_t pqParamType,
1655-
std::function<tvError_t(tvVideoSrcType_t, tvPQModeIndex_t, tvVideoFormatType_t, int)> halSetter)
1651+
const std::string& inputParamName,
1652+
const std::string& tr181ParamName,
1653+
int maxAllowedValue,
1654+
tvPQParameterIndex_t pqParamType,
1655+
std::function<tvError_t(tvVideoSrcType_t, tvPQModeIndex_t, tvVideoFormatType_t, int)> halSetter)
16561656
{
16571657
LOGINFO("Entry");
16581658

@@ -1662,11 +1662,30 @@ namespace Plugin {
16621662
}
16631663

16641664
std::string valueStr = parameters[inputParamName.c_str()].String();
1665-
int value = std::stoi(valueStr);
1665+
int enumValue = -1;
16661666

1667-
if (value < 0 || value > maxAllowedValue) {
1668-
LOGERR("Input value %d is out of range for %s", value, inputParamName.c_str());
1669-
returnResponse(false);
1667+
// Handle special map-based params
1668+
if (pqParamType == PQ_PARAM_SDR_GAMMA) {
1669+
auto it = sdrGammaMap.find(valueStr);
1670+
if (it == sdrGammaMap.end()) {
1671+
LOGERR("Invalid SDRGamma value: %s", valueStr.c_str());
1672+
returnResponse(false);
1673+
}
1674+
enumValue = it->second;
1675+
}
1676+
else {
1677+
// default: numeric parsing
1678+
try {
1679+
enumValue = std::stoi(valueStr);
1680+
} catch (const std::exception& e) {
1681+
LOGERR("Failed to parse %s as integer: %s", inputParamName.c_str(), e.what());
1682+
returnResponse(false);
1683+
}
1684+
1685+
if (enumValue < 0 || enumValue > maxAllowedValue) {
1686+
LOGERR("Input value %d is out of range for %s", enumValue, inputParamName.c_str());
1687+
returnResponse(false);
1688+
}
16701689
}
16711690

16721691
// Get current context
@@ -1680,41 +1699,36 @@ namespace Plugin {
16801699
currentFmt = VIDEO_FORMAT_SDR;
16811700

16821701
char picMode[PIC_MODE_NAME_MAX] = {0};
1683-
if (getCurrentPictureMode(picMode))
1684-
{
1702+
if (getCurrentPictureMode(picMode)) {
16851703
auto it = pqModeReverseMap.find(picMode);
1686-
if (it != pqModeReverseMap.end())
1687-
{
1704+
if (it != pqModeReverseMap.end()) {
16881705
currentPQMode = static_cast<tvPQModeIndex_t>(it->second);
1689-
}
1690-
else
1691-
{
1706+
} else {
16921707
LOGERR("Unknown picture mode");
16931708
}
1694-
}
1695-
else
1696-
{
1709+
} else {
16971710
LOGERR("Failed to get current picture mode");
16981711
}
16991712

17001713
LOGINFO("currentPQMode: %d, currentFmt: %d, currentSrc: %d", currentPQMode, currentFmt, currentSrc);
17011714

1715+
// Call HAL if required
17021716
if (isSetRequiredForParam(parameters, tr181ParamName)) {
1703-
tvError_t ret = halSetter(currentSrc, currentPQMode, currentFmt, value);
1717+
tvError_t ret = halSetter(currentSrc, currentPQMode, currentFmt, enumValue);
17041718
if (ret != tvERROR_NONE) {
17051719
LOGERR("HAL setter failed for %s", inputParamName.c_str());
17061720
returnResponse(false);
17071721
}
17081722
}
17091723

1710-
// Persist
1711-
int retval = updateAVoutputTVParamV2("set", tr181ParamName, parameters, pqParamType, value);
1724+
// Persist enum/int
1725+
int retval = updateAVoutputTVParamV2("set", tr181ParamName, parameters, pqParamType, enumValue);
17121726
if (retval != 0) {
1713-
LOGERR("Failed to save %s to ssm_data", inputParamName.c_str());
1727+
LOGERR("Failed to save %s to driver", inputParamName.c_str());
17141728
returnResponse(false);
17151729
}
17161730

1717-
LOGINFO("Exit: %s set successfully to %d", inputParamName.c_str(), value);
1731+
LOGINFO("Exit: %s set successfully to %d", inputParamName.c_str(), enumValue);
17181732
returnResponse(true);
17191733
}
17201734

@@ -3776,7 +3790,7 @@ namespace Plugin {
37763790
return setContextPQParam(
37773791
parameters, response,
37783792
"sdrGamma", "SDRGamma",
3779-
tvSdrGamma_MAX,
3793+
tvSdrGamma_MAX-1,
37803794
PQ_PARAM_SDR_GAMMA,
37813795
[](tvVideoSrcType_t src, tvPQModeIndex_t mode, tvVideoFormatType_t /*fmt*/, int val) {
37823796
return SetSdrGamma(src, mode, static_cast<tvSdrGamma_t>(val));

0 commit comments

Comments
 (0)