Skip to content

Commit c83c7cf

Browse files
slkanthiarjunbinu
authored andcommitted
Implement syncAvoutputTVPQModeParamsToHALV2
1 parent cb8be79 commit c83c7cf

File tree

3 files changed

+178
-91
lines changed

3 files changed

+178
-91
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,50 +3823,45 @@ namespace Plugin {
38233823
returnResponse(success);
38243824
}
38253825
}
3826-
38273826
bool AVOutputTV::resetPictureModeV2(const JsonObject& parameters)
38283827
{
38293828
LOGINFO("Entry %s\n", __FUNCTION__);
38303829

3831-
// Extract videoSource (default: "Global" if not provided)
3832-
std::vector<std::string> sources;
3833-
if (parameters.HasLabel("videoSource")) {
3834-
const JsonArray& sourceParam = parameters["videoSource"].Array();
3835-
for (uint32_t i = 0; i < sourceParam.Length(); ++i)
3836-
sources.push_back(sourceParam[i].Value());
3837-
} else {
3838-
sources.push_back("Global");
3839-
}
3830+
auto extractList = [](const JsonObject& params, const std::string& key) -> std::vector<std::string> {
3831+
std::vector<std::string> result;
3832+
if (params.HasLabel(key.c_str())) {
3833+
const JsonArray& array = params[key.c_str()].Array();
3834+
for (uint32_t i = 0; i < array.Length(); ++i) {
3835+
result.push_back(array[i].Value());
3836+
}
3837+
} else {
3838+
result.push_back("Global");
3839+
}
3840+
return result;
3841+
};
38403842

3841-
// Extract videoFormat (default: "Global" if not provided)
3842-
std::vector<std::string> formats;
3843-
if (parameters.HasLabel("videoFormat")) {
3844-
const JsonArray& formatParam = parameters["videoFormat"].Array();
3845-
for (uint32_t i = 0; i < formatParam.Length(); ++i)
3846-
formats.push_back(formatParam[i].Value());
3847-
} else {
3848-
formats.push_back("Global");
3849-
}
3843+
std::vector<std::string> sources = extractList(parameters, "videoSource");
3844+
std::vector<std::string> formats = extractList(parameters, "videoFormat");
38503845

3851-
// Expand Global sources if "Global" is set in the parameters
3852-
if (std::find(sources.begin(), sources.end(), "Global") != sources.end()) {
3853-
std::unordered_set<std::string> sourceSet;
3854-
for (size_t j = 0; j < m_pictureModeCaps->num_contexts; ++j) {
3855-
sourceSet.insert(convertSourceIndexToStringV2(m_pictureModeCaps->contexts[j].videoSrcType));
3846+
auto expandGlobal = [](std::vector<std::string>& vec, const std::unordered_set<std::string>& fullSet) {
3847+
if (std::find(vec.begin(), vec.end(), "Global") != vec.end()) {
3848+
vec.erase(std::remove(vec.begin(), vec.end(), "Global"), vec.end());
3849+
vec.insert(vec.end(), fullSet.begin(), fullSet.end());
38563850
}
3857-
sources.insert(sources.end(), sourceSet.begin(), sourceSet.end());
3858-
}
3851+
std::unordered_set<std::string> unique(vec.begin(), vec.end());
3852+
vec.assign(unique.begin(), unique.end());
3853+
};
38593854

3860-
// Expand Global formats if "Global" is set in the parameters
3861-
if (std::find(formats.begin(), formats.end(), "Global") != formats.end()) {
3862-
std::unordered_set<std::string> formatSet;
3863-
for (size_t j = 0; j < m_pictureModeCaps->num_contexts; ++j) {
3864-
formatSet.insert(convertVideoFormatToStringV2(m_pictureModeCaps->contexts[j].videoFormatType));
3865-
}
3866-
formats.insert(formats.end(), formatSet.begin(), formatSet.end());
3855+
// Expand "Global" values
3856+
std::unordered_set<std::string> allSources, allFormats;
3857+
for (size_t j = 0; j < m_pictureModeCaps->num_contexts; ++j) {
3858+
allSources.insert(convertSourceIndexToStringV2(m_pictureModeCaps->contexts[j].videoSrcType));
3859+
allFormats.insert(convertVideoFormatToStringV2(m_pictureModeCaps->contexts[j].videoFormatType));
38673860
}
3861+
expandGlobal(sources, allSources);
3862+
expandGlobal(formats, allFormats);
38683863

3869-
// Get current context
3864+
// Get current source & format
38703865
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
38713866
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
38723867
GetCurrentVideoSource(&currentSrc);
@@ -3876,46 +3871,63 @@ namespace Plugin {
38763871

38773872
bool contextHandled = false;
38783873

3879-
// Iterate through contexts and apply picture mode reset based on the video source and format
38803874
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
38813875
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
38823876

3883-
// Validate by source and format
3884-
if (!isValidSource(sources, ctx.videoSrcType))
3877+
if (!isValidSource(sources, ctx.videoSrcType) || !isValidFormat(formats, ctx.videoFormatType))
38853878
continue;
3886-
if (!isValidFormat(formats, ctx.videoFormatType))
3887-
continue;
3888-
3889-
// Apply reset to hardware if the current context matches
3890-
if (ctx.videoSrcType == currentSrc && ctx.videoFormatType == currentFmt) {
3891-
LOGINFO("Applying resetPictureMode to hardware for current context.\n");
3892-
if (SetTVPictureMode("") != tvERROR_NONE) { // Reset to default mode (empty string or default value)
3893-
LOGERR("resetPictureMode failed for %s\n", convertSourceIndexToStringV2(ctx.videoSrcType).c_str());
3894-
continue; // Skip TR181 write if hardware apply fails
3895-
}
3896-
}
38973879

3898-
// Update TR181 to reflect reset, even if HAL apply fails
38993880
std::string tr181Param = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + "." +
39003881
convertSourceIndexToString(ctx.videoSrcType) + ".Format." +
39013882
convertVideoFormatToString(ctx.videoFormatType) + ".PictureModeString";
39023883

3903-
tr181ErrorCode_t err = setLocalParam(rfc_caller_id, tr181Param.c_str(), ""); // Reset mode to default (empty string)
3884+
// Clear override
3885+
tr181ErrorCode_t err = clearLocalParam(rfc_caller_id, tr181Param.c_str());
39043886
if (err != tr181Success) {
3905-
LOGERR("setLocalParam failed for %s: %s", tr181Param.c_str(), getTR181ErrorString(err));
3887+
LOGERR("clearLocalParam failed for %s: %s", tr181Param.c_str(), getTR181ErrorString(err));
3888+
continue;
3889+
}
3890+
3891+
// Read saved TR-181 value
3892+
TR181_ParamData_t param = {0};
3893+
err = getLocalParam(rfc_caller_id, tr181Param.c_str(), &param);
3894+
if (err != tr181Success || strlen(param.value) == 0) {
3895+
LOGWARN("getLocalParam failed or empty for %s", tr181Param.c_str());
39063896
continue;
39073897
}
39083898

3899+
// Apply to hardware if current context matches
3900+
if (ctx.videoSrcType == currentSrc && ctx.videoFormatType == currentFmt) {
3901+
LOGINFO("resetPictureModeV2: Applying PictureMode %s for current Src=%s Format=%s",
3902+
param.value,
3903+
convertSourceIndexToString(currentSrc).c_str(),
3904+
convertVideoFormatToString(currentFmt).c_str());
3905+
3906+
tvError_t ret = SetTVPictureMode(param.value);
3907+
if (ret != tvERROR_NONE) {
3908+
LOGERR("SetTVPictureMode failed for %s", param.value);
3909+
continue;
3910+
}
3911+
}
3912+
3913+
// Save to internal config
3914+
int pqmodeIndex = static_cast<int>(getPictureModeIndex(param.value));
3915+
SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, pqmodeIndex);
3916+
3917+
LOGINFO("resetPictureModeV2: Reset done for Src=%s Format=%s\n",
3918+
convertSourceIndexToString(ctx.videoSrcType).c_str(),
3919+
convertVideoFormatToString(ctx.videoFormatType).c_str());
3920+
39093921
contextHandled = true;
39103922
}
39113923

39123924

39133925
if (!contextHandled) {
3914-
LOGERR("No matching context found to reset pictureMode.\n");
3926+
LOGERR("No valid pictureMode context matched to reset.\n");
39153927
return false;
39163928
}
39173929

3918-
LOGINFO("Exit: PictureMode reset successfully.\n");
3930+
LOGINFO("resetPictureModeV2: Exit - PictureMode reset successfully.\n");
39193931
return true;
39203932
}
39213933

AVOutput/AVOutputTV.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class AVOutputTV : public AVOutputBase {
504504
bool isValidFormat(const std::vector<std::string>& formatArray, tvVideoFormatType_t formatIndex);
505505
tvError_t updateAVoutputTVParamToHALV2(std::string forParam, paramIndex_t indexInfo, int value, bool setNotDelete);
506506
bool resetPictureModeV2(const JsonObject& parameters);
507-
507+
int syncAvoutputTVPQModeParamsToHALV2(std::string pqmode, std::string source, std::string format);
508508

509509
public:
510510
int m_currentHdmiInResoluton;

AVOutput/AVOutputTVHelper.cpp

Lines changed: 112 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,54 +1365,129 @@ namespace Plugin {
13651365
LOGINFO("Exit %s : pqmode : %s source : %s format : %s\n", __FUNCTION__, pqmode.c_str(), source.c_str(), format.c_str());
13661366
return tvERROR_NONE;
13671367
}
1368-
1369-
int AVOutputTV::syncAvoutputTVPQModeParamsToHAL(std::string pqmode, std::string source, std::string format)
1368+
int AVOutputTV::syncAvoutputTVPQModeParamsToHALV2(std::string pqmode, std::string source, std::string format)
13701369
{
1371-
capDetails_t inputInfo;
1372-
valueVectors_t valueVectors;
13731370
tr181ErrorCode_t err = tr181Success;
13741371
TR181_ParamData_t param = {0};
1375-
int ret = 0;
1372+
bool contextSynced = false;
13761373

1377-
inputInfo.pqmode = pqmode;
1378-
inputInfo.source = source;
1379-
inputInfo.format = format;
1374+
// Treat "none" as "Global"
1375+
if (source == "none")
1376+
source = "Global";
1377+
if (format == "none")
1378+
format = "Global";
1379+
1380+
// Handle "Current" source/format substitution
1381+
if (source == "Current" || format == "Current") {
1382+
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
1383+
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
1384+
GetCurrentVideoSource(&currentSrc);
1385+
GetCurrentVideoFormat(&currentFmt);
1386+
if (currentFmt == VIDEO_FORMAT_NONE)
1387+
currentFmt = VIDEO_FORMAT_SDR;
1388+
1389+
if (source == "Current")
1390+
source = convertSourceIndexToString(currentSrc);
1391+
if (format == "Current")
1392+
format = convertVideoFormatToString(currentFmt);
1393+
}
13801394

1381-
ret = getSaveConfig("PictureMode", inputInfo, valueVectors);
1382-
1383-
if (ret == 0 ) {
1384-
for (int source : valueVectors.sourceValues ) {
1385-
tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source;
1386-
for (int format : valueVectors.formatValues ) {
1387-
tvVideoFormatType_t formatType = (tvVideoFormatType_t)format;
1388-
std::string tr181_param_name = "";
1389-
tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
1390-
tr181_param_name += "."+convertSourceIndexToString(sourceType)+"."+"Format."+
1391-
convertVideoFormatToString(formatType)+"."+"PictureModeString";
1392-
1393-
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
1394-
1395-
if ( tr181Success == err ) {
1396-
std::string local = param.value;
1397-
if (local == "Dark" || local == "Bright" || local == "IQ" || local =="AI PQ"){
1398-
local = "EnergySaving";
1399-
}
1400-
int pqmodeindex = (int)getPictureModeIndex(local);
1401-
1402-
tvError_t tv_err = SaveSourcePictureMode(sourceType, formatType, pqmodeindex);
1403-
if (tv_err != tvERROR_NONE) {
1404-
LOGWARN("failed to SaveSourcePictureMode \n");
1395+
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
1396+
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
1397+
1398+
std::string sourceStr = convertSourceIndexToString(ctx.videoSrcType);
1399+
std::string formatStr = convertVideoFormatToString(ctx.videoFormatType);
1400+
1401+
// Filter by provided source/format
1402+
if (source != "Global" && source != sourceStr)
1403+
continue;
1404+
if (format != "Global" && format != formatStr)
1405+
continue;
1406+
1407+
std::string tr181Param = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) +
1408+
"." + sourceStr + ".Format." + formatStr + ".PictureModeString";
1409+
1410+
err = getLocalParam(rfc_caller_id, tr181Param.c_str(), &param);
1411+
if (err != tr181Success) {
1412+
LOGWARN("Failed to getLocalParam for %s\n", tr181Param.c_str());
1413+
continue;
1414+
}
1415+
1416+
std::string modeStr = param.value;
1417+
int modeIndex = static_cast<int>(getPictureModeIndex(modeStr));
1418+
if (modeIndex == -1) {
1419+
LOGWARN("Invalid pictureMode from TR181: %s\n", modeStr.c_str());
1420+
continue;
1421+
}
1422+
1423+
tvError_t tv_err = SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, modeIndex);
1424+
if (tv_err != tvERROR_NONE) {
1425+
LOGWARN("Failed SaveSourcePictureMode for %s / %s\n", sourceStr.c_str(), formatStr.c_str());
1426+
continue;
1427+
}
1428+
1429+
contextSynced = true;
1430+
}
1431+
1432+
if (!contextSynced) {
1433+
LOGWARN("No matching context synced for pqmode=%s source=%s format=%s\n",
1434+
pqmode.c_str(), source.c_str(), format.c_str());
1435+
return -1;
1436+
}
1437+
return 0;
1438+
}
1439+
1440+
int AVOutputTV::syncAvoutputTVPQModeParamsToHAL(std::string pqmode, std::string source, std::string format)
1441+
{
1442+
if (m_pictureModeStatus == tvERROR_OPERATION_NOT_SUPPORTED)
1443+
{
1444+
capDetails_t inputInfo;
1445+
valueVectors_t valueVectors;
1446+
tr181ErrorCode_t err = tr181Success;
1447+
TR181_ParamData_t param = {0};
1448+
int ret = 0;
1449+
1450+
inputInfo.pqmode = pqmode;
1451+
inputInfo.source = source;
1452+
inputInfo.format = format;
1453+
1454+
ret = getSaveConfig("PictureMode", inputInfo, valueVectors);
1455+
1456+
if (ret == 0 ) {
1457+
for (int source : valueVectors.sourceValues ) {
1458+
tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source;
1459+
for (int format : valueVectors.formatValues ) {
1460+
tvVideoFormatType_t formatType = (tvVideoFormatType_t)format;
1461+
std::string tr181_param_name = "";
1462+
tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
1463+
tr181_param_name += "."+convertSourceIndexToString(sourceType)+"."+"Format."+
1464+
convertVideoFormatToString(formatType)+"."+"PictureModeString";
1465+
1466+
1467+
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
1468+
if ( tr181Success == err ) {
1469+
std::string local = param.value;
1470+
int pqmodeindex = (int)getPictureModeIndex(local);
1471+
1472+
tvError_t tv_err = SaveSourcePictureMode(sourceType, formatType, pqmodeindex);
1473+
if (tv_err != tvERROR_NONE) {
1474+
LOGWARN("failed to SaveSourcePictureMode \n");
1475+
return -1;
1476+
}
1477+
}
1478+
else {
1479+
LOGWARN("Failed to get the getLocalParam \n");
14051480
return -1;
14061481
}
14071482
}
1408-
else {
1409-
LOGWARN("Failed to get the getLocalParam \n");
1410-
return -1;
1411-
}
14121483
}
14131484
}
1485+
return ret;
1486+
}
1487+
else
1488+
{
1489+
return syncAvoutputTVPQModeParamsToHALV2(pqmode,source,format);
14141490
}
1415-
return ret;
14161491
}
14171492

14181493
uint32_t AVOutputTV::generateStorageIdentifier(std::string &key, std::string forParam, paramIndex_t info)

0 commit comments

Comments
 (0)