Skip to content

Commit db3cb5a

Browse files
slkanthiarjunbinu
authored andcommitted
Review comments addressed:
- Default to Global for set/reset when no input arguments are given. - Default to Current for get when no input arguments are given.
1 parent d593fb9 commit db3cb5a

File tree

1 file changed

+105
-58
lines changed

1 file changed

+105
-58
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 105 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,61 +3587,93 @@ namespace Plugin {
35873587
{
35883588
LOGINFO("Entry %s\n", __FUNCTION__);
35893589

3590+
// Validate pictureMode
35903591
if (!parameters.HasLabel("pictureMode")) {
3591-
LOGERR("Parameter 'pictureMode' not found in the request.\n");
3592+
LOGERR("Missing 'pictureMode' in parameters.\n");
35923593
return false;
35933594
}
35943595

35953596
std::string mode = parameters["pictureMode"].String();
3596-
35973597
std::vector<std::string> validOptions;
3598-
for (size_t i = 0; i < m_numPictureModes ; ++i) {
3598+
for (size_t i = 0; i < m_numPictureModes; ++i)
35993599
validOptions.emplace_back(pqModeMap.at(m_pictureModes[i]));
3600-
}
36013600

3602-
auto it = std::find(validOptions.begin(), validOptions.end(), mode);
3603-
if (it == validOptions.end()) {
3604-
LOGERR("Invalid picture mode: %s. Not in supported options.", mode.c_str());
3601+
if (std::find(validOptions.begin(), validOptions.end(), mode) == validOptions.end()) {
3602+
LOGERR("Invalid pictureMode: %s", mode.c_str());
36053603
return false;
36063604
}
36073605

3608-
std::vector<tvConfigContext_t> validContexts = getValidContextsFromParameters(parameters, "PictureMode");
3609-
if (validContexts.empty()) {
3610-
LOGERR("No valid context found for PictureMode: %s", mode.c_str());
3611-
return false;
3606+
// Extract and normalize videoSource array
3607+
std::vector<std::string> sources;
3608+
if (parameters.HasLabel("videoSource")) {
3609+
const JsonArray& sourceParam = parameters["videoSource"].Array();
3610+
for (uint32_t i = 0; i < sourceParam.Length(); ++i)
3611+
sources.push_back(sourceParam[i].Value());
3612+
} else {
3613+
sources.push_back("Global");
36123614
}
36133615

3614-
for (const auto& ctx : validContexts) {
3616+
// Extract and normalize videoFormat array
3617+
std::vector<std::string> formats;
3618+
if (parameters.HasLabel("videoFormat")) {
3619+
const JsonArray& formatParam = parameters["videoFormat"].Array();
3620+
for (uint32_t i = 0; i < formatParam.Length(); ++i)
3621+
formats.push_back(formatParam[i].Value());
3622+
} else {
3623+
formats.push_back("Global");
3624+
}
3625+
3626+
// Get current source/format
3627+
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
3628+
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
3629+
GetCurrentVideoSource(&currentSrc);
3630+
GetCurrentVideoFormat(&currentFmt);
3631+
if (currentFmt == VIDEO_FORMAT_NONE)
3632+
currentFmt = VIDEO_FORMAT_SDR;
3633+
3634+
bool contextHandled = false;
3635+
3636+
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
3637+
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
3638+
3639+
// Match source
3640+
if (!isValidSource(sources, ctx.videoSrcType))
3641+
continue;
3642+
3643+
// Match format
3644+
if (!isValidFormat(formats, ctx.videoFormatType))
3645+
continue;
3646+
36153647
std::string tr181Param = std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + "." +
36163648
convertSourceIndexToString(ctx.videoSrcType) + ".Format." +
36173649
convertVideoFormatToString(ctx.videoFormatType) + ".PictureModeString";
36183650

36193651
tr181ErrorCode_t err = setLocalParam(rfc_caller_id, tr181Param.c_str(), mode.c_str());
36203652
if (err != tr181Success) {
36213653
LOGERR("setLocalParam failed for %s: %s", tr181Param.c_str(), getTR181ErrorString(err));
3622-
return false;
3654+
continue;
36233655
}
36243656

3625-
int modeIndex = (int)getPictureModeIndex(mode);
3657+
int modeIndex = getPictureModeIndex(mode);
36263658
SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, modeIndex);
36273659

3628-
std::string srcStr = videoSrcMap.count(ctx.videoSrcType) ? videoSrcMap.at(ctx.videoSrcType) : std::to_string(ctx.videoSrcType);
3629-
std::string fmtStr = videoFormatMap.count(ctx.videoFormatType) ? videoFormatMap.at(ctx.videoFormatType) : std::to_string(ctx.videoFormatType);
3630-
#if DEBUG
3631-
LOGINFO("Context - Format: %s, Source: %s", fmtStr.c_str(), srcStr.c_str());
3632-
#endif
3633-
if(isSetRequired("Current", srcStr, fmtStr)) {
3634-
LOGINFO("Applying SetTVPictureMode to hardware\n");
3660+
if (ctx.videoSrcType == currentSrc && ctx.videoFormatType == currentFmt) {
3661+
LOGINFO("Applying SetTVPictureMode to hardware for current context.\n");
36353662
if (SetTVPictureMode(mode.c_str()) != tvERROR_NONE) {
3636-
LOGERR("Failed to apply mode to TV: %s", mode.c_str());
3637-
return false;
3663+
LOGERR("SetTVPictureMode failed: %s\n", mode.c_str());
3664+
continue;
36383665
}
36393666
}
36403667

3668+
contextHandled = true;
36413669
}
36423670

3643-
// TODO:: Handle telemetry/notifications
3644-
LOGINFO("Exit : Value : %s \n", mode.c_str());
3671+
if (!contextHandled) {
3672+
LOGERR("No matching context found to apply pictureMode: %s", mode.c_str());
3673+
return false;
3674+
}
3675+
3676+
LOGINFO("Exit: PictureMode '%s' applied successfully.\n", mode.c_str());
36453677
return true;
36463678
}
36473679

@@ -3747,42 +3779,65 @@ namespace Plugin {
37473779
tr181ErrorCode_t err = tr181Success;
37483780
TR181_ParamData_t param = {0};
37493781

3750-
// Initialize videoSource and videoFormat arrays with "Current" if not provided
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");
3788+
37513789
std::vector<std::string> sourceArray;
3752-
if (parameters.HasLabel("videoSource")) {
3790+
if (hasSource) {
37533791
const JsonArray& sourceParam = parameters["videoSource"].Array();
3754-
for (uint32_t i = 0; i < sourceParam.Length(); ++i) {
3755-
sourceArray.push_back(sourceParam[i].Value());
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+
}
37563804
}
3757-
} else {
3758-
sourceArray.push_back("Current");
37593805
}
37603806

37613807
std::vector<std::string> formatArray;
3762-
if (parameters.HasLabel("videoFormat")) {
3808+
if (hasFormat) {
37633809
const JsonArray& formatParam = parameters["videoFormat"].Array();
3764-
for (uint32_t i = 0; i < formatParam.Length(); ++i) {
3765-
formatArray.push_back(formatParam[i].Value());
3810+
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+
}
37663822
}
3767-
} else {
3768-
formatArray.push_back("Current");
37693823
}
37703824

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;
3832+
37713833
bool contextHandled = false;
37723834

3773-
// Loop through all the contexts in m_pictureModeCaps
37743835
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
37753836
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
37763837

3777-
// Check if the current context matches the requested videoSource
3778-
if (!isValidSource(sourceArray, ctx.videoSrcType)) {
3779-
continue; // Skip if the source doesn't match
3780-
}
3781-
3782-
// Check if the current context matches the requested videoFormat
3783-
if (!isValidFormat(formatArray, ctx.videoFormatType)) {
3784-
continue; // Skip if the format doesn't match
3785-
}
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;
37863841

37873842
std::string tr181_param_name = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM;
37883843
tr181_param_name += "." + convertSourceIndexToString(ctx.videoSrcType);
@@ -3797,22 +3852,14 @@ namespace Plugin {
37973852

37983853
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
37993854
if (err != tr181Success) {
3800-
#if DEBUG
3855+
#if DEBUG
38013856
LOGWARN("getLocalParam failed for %s\n", tr181_param_name.c_str());
3802-
#endif
3857+
#endif
38033858
continue;
38043859
}
38053860

3806-
// Get the current video source and format
3807-
tvVideoSrcType_t current_source = VIDEO_SOURCE_IP;
3808-
tvVideoFormatType_t current_format = VIDEO_FORMAT_NONE;
3809-
GetCurrentVideoSource(&current_source);
3810-
GetCurrentVideoFormat(&current_format);
3811-
if (current_format == VIDEO_FORMAT_NONE)
3812-
current_format = VIDEO_FORMAT_SDR;
3813-
3814-
// If current source and format match the context, apply the picture mode
3815-
if (current_source == ctx.videoSrcType && current_format == ctx.videoFormatType) {
3861+
// Apply PictureMode only to current context
3862+
if (ctx.videoSrcType == current_source && ctx.videoFormatType == current_format) {
38163863
tvError_t ret = SetTVPictureMode(param.value);
38173864
if (ret != tvERROR_NONE) {
38183865
LOGWARN("SetTVPictureMode failed: %s\n", getErrorString(ret).c_str());

0 commit comments

Comments
 (0)