Skip to content

Commit cb8be79

Browse files
slkanthiarjunbinu
authored andcommitted
- Optimized loop in setPictureModeV2 to iterate only over incoming PQMode context.
- getPictureModeV2 will fetch the actual persisted value for the source-format combination. Don’t rely on m_pictureModeCaps->contexts - Moved pictureMode halsetter logic before update function call in set/reset methods.
1 parent db3cb5a commit cb8be79

File tree

2 files changed

+192
-152
lines changed

2 files changed

+192
-152
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 157 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,41 +3502,55 @@ namespace Plugin {
35023502

35033503
bool AVOutputTV::getPictureModeV2(const JsonObject& parameters, std::string& outMode)
35043504
{
3505-
tvConfigContext_t validContext = getValidContextFromGetParameters(parameters, "PictureMode");
3506-
if ((validContext.videoSrcType == VIDEO_SOURCE_ALL &&
3507-
validContext.videoFormatType == VIDEO_FORMAT_NONE &&
3508-
validContext.pq_mode == PQ_MODE_INVALID))
3509-
{
3510-
LOGWARN("No Valid context for get PictureMode");
3511-
return false;
3505+
LOGINFO("Entry");
3506+
3507+
tvVideoSrcType_t source = VIDEO_SOURCE_IP;
3508+
tvVideoFormatType_t format = VIDEO_FORMAT_SDR;
3509+
3510+
// Parse videoSource
3511+
if (!parameters.HasLabel("videoSource") || parameters["videoSource"].String() == "Current") {
3512+
GetCurrentVideoSource(&source);
3513+
} else {
3514+
std::string srcStr = parameters["videoSource"].String();
3515+
if (videoSrcReverseMap.count(srcStr)) {
3516+
source = static_cast<tvVideoSrcType_t>(videoSrcReverseMap.at(srcStr));
3517+
} else {
3518+
LOGERR("Invalid videoSource: %s", srcStr.c_str());
3519+
return false;
3520+
}
35123521
}
35133522

3514-
paramIndex_t indexInfo {
3515-
.sourceIndex = static_cast<uint8_t>(validContext.videoSrcType),
3516-
.pqmodeIndex = static_cast<uint8_t>(validContext.pq_mode),
3517-
.formatIndex = static_cast<uint8_t>(validContext.videoFormatType)
3518-
};
3523+
// Parse videoFormat
3524+
if (!parameters.HasLabel("videoFormat") || parameters["videoFormat"].String() == "Current") {
3525+
GetCurrentVideoFormat(&format);
3526+
if (format == VIDEO_FORMAT_NONE) format = VIDEO_FORMAT_SDR;
3527+
} else {
3528+
std::string fmtStr = parameters["videoFormat"].String();
3529+
if (videoFormatReverseMap.count(fmtStr)) {
3530+
format = static_cast<tvVideoFormatType_t>(videoFormatReverseMap.at(fmtStr));
3531+
} else {
3532+
LOGERR("Invalid videoFormat: %s", fmtStr.c_str());
3533+
return false;
3534+
}
3535+
}
35193536

3537+
// Directly use TR-181 to fetch active picture mode
35203538
std::string tr181_param_name = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) +
3521-
"." + convertSourceIndexToString(indexInfo.sourceIndex) +
3522-
".Format." + convertVideoFormatToString(indexInfo.formatIndex) +
3539+
"." + convertSourceIndexToString(source) +
3540+
".Format." + convertVideoFormatToString(format) +
35233541
".PictureModeString";
35243542

3525-
LOGINFO("Context: Source=%s, Format=%s",
3526-
convertSourceIndexToString(indexInfo.sourceIndex).c_str(),
3527-
convertVideoFormatToString(indexInfo.formatIndex).c_str());
3528-
35293543
LOGINFO("TR181 Param Name = %s", tr181_param_name.c_str());
35303544

35313545
TR181_ParamData_t param = {0};
35323546
tr181ErrorCode_t err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
3533-
35343547
if (err != tr181Success) {
35353548
LOGERR("getLocalParam failed: %d", err);
35363549
return false;
35373550
}
35383551

35393552
outMode = param.value;
3553+
LOGINFO("Exit: PictureMode = %s", outMode.c_str());
35403554
return true;
35413555
}
35423556

@@ -3587,43 +3601,80 @@ namespace Plugin {
35873601
{
35883602
LOGINFO("Entry %s\n", __FUNCTION__);
35893603

3590-
// Validate pictureMode
35913604
if (!parameters.HasLabel("pictureMode")) {
35923605
LOGERR("Missing 'pictureMode' in parameters.\n");
35933606
return false;
35943607
}
35953608

35963609
std::string mode = parameters["pictureMode"].String();
3597-
std::vector<std::string> validOptions;
3598-
for (size_t i = 0; i < m_numPictureModes; ++i)
3599-
validOptions.emplace_back(pqModeMap.at(m_pictureModes[i]));
36003610

3601-
if (std::find(validOptions.begin(), validOptions.end(), mode) == validOptions.end()) {
3611+
// Validate against m_pictureModes
3612+
int modeIndex = -1;
3613+
for (size_t i = 0; i < m_numPictureModes; ++i) {
3614+
if (pqModeMap.at(m_pictureModes[i]) == mode) {
3615+
modeIndex = static_cast<int>(i);
3616+
break;
3617+
}
3618+
}
3619+
3620+
if (modeIndex == -1) {
36023621
LOGERR("Invalid pictureMode: %s", mode.c_str());
36033622
return false;
36043623
}
36053624

3606-
// Extract and normalize videoSource array
3625+
// Extract videoSource array (default: Global if not provided)
36073626
std::vector<std::string> sources;
36083627
if (parameters.HasLabel("videoSource")) {
36093628
const JsonArray& sourceParam = parameters["videoSource"].Array();
3610-
for (uint32_t i = 0; i < sourceParam.Length(); ++i)
3611-
sources.push_back(sourceParam[i].Value());
3629+
for (uint32_t i = 0; i < sourceParam.Length(); ++i) {
3630+
std::string source = sourceParam[i].Value();
3631+
if (!source.empty()) {
3632+
sources.push_back(source); // Only add non-empty sources
3633+
}
3634+
}
36123635
} else {
36133636
sources.push_back("Global");
36143637
}
36153638

3616-
// Extract and normalize videoFormat array
3639+
// Extract videoFormat array (default: Global if not provided)
36173640
std::vector<std::string> formats;
36183641
if (parameters.HasLabel("videoFormat")) {
36193642
const JsonArray& formatParam = parameters["videoFormat"].Array();
3620-
for (uint32_t i = 0; i < formatParam.Length(); ++i)
3621-
formats.push_back(formatParam[i].Value());
3643+
for (uint32_t i = 0; i < formatParam.Length(); ++i) {
3644+
std::string format = formatParam[i].Value();
3645+
if (!format.empty()) {
3646+
formats.push_back(format); // Only add non-empty formats
3647+
}
3648+
}
36223649
} else {
36233650
formats.push_back("Global");
36243651
}
36253652

3626-
// Get current source/format
3653+
// Expand Global sources and formats if "Global" is set
3654+
if (std::find(sources.begin(), sources.end(), "Global") != sources.end()) {
3655+
// Extract sources from context
3656+
std::unordered_set<std::string> sourceSet;
3657+
for (size_t j = 0; j < m_pictureModeCaps->num_contexts; ++j) {
3658+
if (m_pictureModeCaps->contexts[j].pq_mode == m_pictureModes[modeIndex]) {
3659+
sourceSet.insert(convertSourceIndexToStringV2(m_pictureModeCaps->contexts[j].videoSrcType));
3660+
}
3661+
}
3662+
sources.insert(sources.end(), sourceSet.begin(), sourceSet.end());
3663+
}
3664+
3665+
// Expand Global formats if "Global" is set
3666+
if (std::find(formats.begin(), formats.end(), "Global") != formats.end()) {
3667+
// Extract formats from context
3668+
std::unordered_set<std::string> formatSet;
3669+
for (size_t j = 0; j < m_pictureModeCaps->num_contexts; ++j) {
3670+
if (m_pictureModeCaps->contexts[j].pq_mode == m_pictureModes[modeIndex]) {
3671+
formatSet.insert(convertVideoFormatToStringV2(m_pictureModeCaps->contexts[j].videoFormatType));
3672+
}
3673+
}
3674+
formats.insert(formats.end(), formatSet.begin(), formatSet.end());
3675+
}
3676+
3677+
// Get current context
36273678
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
36283679
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
36293680
GetCurrentVideoSource(&currentSrc);
@@ -3633,17 +3684,29 @@ namespace Plugin {
36333684

36343685
bool contextHandled = false;
36353686

3687+
// Iterate through contexts and apply picture mode based on the video source and format
36363688
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
36373689
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
36383690

3639-
// Match source
3640-
if (!isValidSource(sources, ctx.videoSrcType))
3691+
// Only process contexts with matching picture mode
3692+
if (ctx.pq_mode != m_pictureModes[modeIndex])
36413693
continue;
36423694

3643-
// Match format
3695+
// Validate by source and format
3696+
if (!isValidSource(sources, ctx.videoSrcType))
3697+
continue;
36443698
if (!isValidFormat(formats, ctx.videoFormatType))
36453699
continue;
36463700

3701+
// Apply to hardware
3702+
if (ctx.videoSrcType == currentSrc && ctx.videoFormatType == currentFmt) {
3703+
LOGINFO("Applying SetTVPictureMode to hardware for current context.\n");
3704+
if (SetTVPictureMode(mode.c_str()) != tvERROR_NONE) {
3705+
LOGERR("SetTVPictureMode failed: %s\n", mode.c_str());
3706+
continue; // Skip TR181 write if hardware apply fails
3707+
}
3708+
}
3709+
// Update TR181 after successful HAL application
36473710
std::string tr181Param = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + "." +
36483711
convertSourceIndexToString(ctx.videoSrcType) + ".Format." +
36493712
convertVideoFormatToString(ctx.videoFormatType) + ".PictureModeString";
@@ -3654,17 +3717,6 @@ namespace Plugin {
36543717
continue;
36553718
}
36563719

3657-
int modeIndex = getPictureModeIndex(mode);
3658-
SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, modeIndex);
3659-
3660-
if (ctx.videoSrcType == currentSrc && ctx.videoFormatType == currentFmt) {
3661-
LOGINFO("Applying SetTVPictureMode to hardware for current context.\n");
3662-
if (SetTVPictureMode(mode.c_str()) != tvERROR_NONE) {
3663-
LOGERR("SetTVPictureMode failed: %s\n", mode.c_str());
3664-
continue;
3665-
}
3666-
}
3667-
36683720
contextHandled = true;
36693721
}
36703722

@@ -3774,113 +3826,96 @@ namespace Plugin {
37743826

37753827
bool AVOutputTV::resetPictureModeV2(const JsonObject& parameters)
37763828
{
3777-
LOGINFO("Entry\n");
3778-
3779-
tr181ErrorCode_t err = tr181Success;
3780-
TR181_ParamData_t param = {0};
3781-
3782-
auto isExplicitGlobal = [](const JsonArray& arr) {
3783-
return arr.Length() == 1 && arr[0].Value() == "Global";
3784-
};
3785-
3786-
bool hasSource = parameters.HasLabel("videoSource");
3787-
bool hasFormat = parameters.HasLabel("videoFormat");
3829+
LOGINFO("Entry %s\n", __FUNCTION__);
37883830

3789-
std::vector<std::string> sourceArray;
3790-
if (hasSource) {
3831+
// Extract videoSource (default: "Global" if not provided)
3832+
std::vector<std::string> sources;
3833+
if (parameters.HasLabel("videoSource")) {
37913834
const JsonArray& sourceParam = parameters["videoSource"].Array();
3792-
3793-
if (isExplicitGlobal(sourceParam)) {
3794-
hasSource = false; // Treat as global
3795-
} else {
3796-
for (uint32_t i = 0; i < sourceParam.Length(); ++i) {
3797-
std::string val = sourceParam[i].Value();
3798-
if (val == "Global") {
3799-
LOGWARN("Invalid videoSource array: 'Global' cannot be combined with other values.\n");
3800-
return false;
3801-
}
3802-
sourceArray.push_back(val);
3803-
}
3804-
}
3835+
for (uint32_t i = 0; i < sourceParam.Length(); ++i)
3836+
sources.push_back(sourceParam[i].Value());
3837+
} else {
3838+
sources.push_back("Global");
38053839
}
38063840

3807-
std::vector<std::string> formatArray;
3808-
if (hasFormat) {
3841+
// Extract videoFormat (default: "Global" if not provided)
3842+
std::vector<std::string> formats;
3843+
if (parameters.HasLabel("videoFormat")) {
38093844
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+
}
38103850

3811-
if (isExplicitGlobal(formatParam)) {
3812-
hasFormat = false; // Treat as global
3813-
} else {
3814-
for (uint32_t i = 0; i < formatParam.Length(); ++i) {
3815-
std::string val = formatParam[i].Value();
3816-
if (val == "Global") {
3817-
LOGWARN("Invalid videoFormat array: 'Global' cannot be combined with other values.\n");
3818-
return false;
3819-
}
3820-
formatArray.push_back(val);
3821-
}
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));
38223856
}
3857+
sources.insert(sources.end(), sourceSet.begin(), sourceSet.end());
38233858
}
38243859

3825-
// Get current source and format
3826-
tvVideoSrcType_t current_source = VIDEO_SOURCE_IP;
3827-
tvVideoFormatType_t current_format = VIDEO_FORMAT_NONE;
3828-
GetCurrentVideoSource(&current_source);
3829-
GetCurrentVideoFormat(&current_format);
3830-
if (current_format == VIDEO_FORMAT_NONE)
3831-
current_format = VIDEO_FORMAT_SDR;
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());
3867+
}
3868+
3869+
// Get current context
3870+
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
3871+
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
3872+
GetCurrentVideoSource(&currentSrc);
3873+
GetCurrentVideoFormat(&currentFmt);
3874+
if (currentFmt == VIDEO_FORMAT_NONE)
3875+
currentFmt = VIDEO_FORMAT_SDR;
38323876

38333877
bool contextHandled = false;
38343878

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

3838-
// Apply filtering only if source/format not global
3839-
if (hasSource && !isValidSource(sourceArray, ctx.videoSrcType)) continue;
3840-
if (hasFormat && !isValidFormat(formatArray, ctx.videoFormatType)) continue;
3841-
3842-
std::string tr181_param_name = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM;
3843-
tr181_param_name += "." + convertSourceIndexToString(ctx.videoSrcType);
3844-
tr181_param_name += ".Format." + convertVideoFormatToString(ctx.videoFormatType);
3845-
tr181_param_name += ".PictureModeString";
3846-
3847-
err = clearLocalParam(rfc_caller_id, tr181_param_name.c_str());
3848-
if (err != tr181Success) {
3849-
LOGWARN("clearLocalParam failed for %s: %s\n", tr181_param_name.c_str(), getTR181ErrorString(err));
3883+
// Validate by source and format
3884+
if (!isValidSource(sources, ctx.videoSrcType))
38503885
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+
}
38513896
}
38523897

3853-
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
3898+
// Update TR181 to reflect reset, even if HAL apply fails
3899+
std::string tr181Param = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + "." +
3900+
convertSourceIndexToString(ctx.videoSrcType) + ".Format." +
3901+
convertVideoFormatToString(ctx.videoFormatType) + ".PictureModeString";
3902+
3903+
tr181ErrorCode_t err = setLocalParam(rfc_caller_id, tr181Param.c_str(), ""); // Reset mode to default (empty string)
38543904
if (err != tr181Success) {
3855-
#if DEBUG
3856-
LOGWARN("getLocalParam failed for %s\n", tr181_param_name.c_str());
3857-
#endif
3905+
LOGERR("setLocalParam failed for %s: %s", tr181Param.c_str(), getTR181ErrorString(err));
38583906
continue;
38593907
}
38603908

3861-
// Apply PictureMode only to current context
3862-
if (ctx.videoSrcType == current_source && ctx.videoFormatType == current_format) {
3863-
tvError_t ret = SetTVPictureMode(param.value);
3864-
if (ret != tvERROR_NONE) {
3865-
LOGWARN("SetTVPictureMode failed: %s\n", getErrorString(ret).c_str());
3866-
continue;
3867-
} else {
3868-
LOGINFO("PictureMode applied to current context: %s\n", param.value);
3869-
}
3870-
}
3871-
3872-
int pqmodeindex = getPictureModeIndex(param.value);
3873-
SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, pqmodeindex);
38743909
contextHandled = true;
38753910
}
38763911

38773912

38783913
if (!contextHandled) {
3879-
LOGWARN("No applicable contexts handled for PictureMode reset\n");
3914+
LOGERR("No matching context found to reset pictureMode.\n");
38803915
return false;
38813916
}
38823917

3883-
LOGINFO("Exit: PictureMode reset completed for all matching contexts.\n");
3918+
LOGINFO("Exit: PictureMode reset successfully.\n");
38843919
return true;
38853920
}
38863921

0 commit comments

Comments
 (0)