Skip to content

Commit d593fb9

Browse files
slkanthiarjunbinu
authored andcommitted
Implement context based resetPictureMode
1 parent 0c28d0c commit d593fb9

File tree

3 files changed

+210
-52
lines changed

3 files changed

+210
-52
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 158 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,77 +3740,183 @@ namespace Plugin {
37403740
}
37413741
}
37423742

3743-
uint32_t AVOutputTV::resetPictureMode(const JsonObject& parameters, JsonObject& response)
3743+
bool AVOutputTV::resetPictureModeV2(const JsonObject& parameters)
37443744
{
37453745
LOGINFO("Entry\n");
3746+
37463747
tr181ErrorCode_t err = tr181Success;
37473748
TR181_ParamData_t param = {0};
37483749

3749-
valueVectors_t values;
3750-
capDetails_t inputInfo;
3751-
3752-
// As only source need to validate, so pqmode and formate passing as currrent
3753-
if (parsingSetInputArgument(parameters, "PictureMode",inputInfo) != 0) {
3754-
LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__);
3755-
returnResponse(false);
3750+
// Initialize videoSource and videoFormat arrays with "Current" if not provided
3751+
std::vector<std::string> sourceArray;
3752+
if (parameters.HasLabel("videoSource")) {
3753+
const JsonArray& sourceParam = parameters["videoSource"].Array();
3754+
for (uint32_t i = 0; i < sourceParam.Length(); ++i) {
3755+
sourceArray.push_back(sourceParam[i].Value());
3756+
}
3757+
} else {
3758+
sourceArray.push_back("Current");
37563759
}
37573760

3758-
if( !isCapablityCheckPassed( "PictureMode",inputInfo )) {
3759-
LOGERR("%s: CapablityCheck failed for PictureMode\n", __FUNCTION__);
3760-
returnResponse(false);
3761+
std::vector<std::string> formatArray;
3762+
if (parameters.HasLabel("videoFormat")) {
3763+
const JsonArray& formatParam = parameters["videoFormat"].Array();
3764+
for (uint32_t i = 0; i < formatParam.Length(); ++i) {
3765+
formatArray.push_back(formatParam[i].Value());
3766+
}
3767+
} else {
3768+
formatArray.push_back("Current");
37613769
}
3762-
inputInfo.pqmode = "Current";
3763-
getSaveConfig("PictureMode", inputInfo, values);
37643770

3765-
for (int source : values.sourceValues) {
3766-
tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source;
3767-
for (int format : values.formatValues) {
3768-
tvVideoFormatType_t formatType = (tvVideoFormatType_t)format;
3769-
std::string tr181_param_name = "";
3770-
tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
3771-
tr181_param_name += "."+convertSourceIndexToString(sourceType)+"."+"Format."+
3772-
convertVideoFormatToString(formatType)+"."+"PictureModeString";
3771+
bool contextHandled = false;
37733772

3774-
err = clearLocalParam(rfc_caller_id, tr181_param_name.c_str());
3775-
if ( err != tr181Success ) {
3776-
LOGWARN("clearLocalParam for %s Failed : %s\n", tr181_param_name.c_str(), getTR181ErrorString(err));
3777-
returnResponse(false);
3773+
// Loop through all the contexts in m_pictureModeCaps
3774+
for (size_t i = 0; i < m_pictureModeCaps->num_contexts; ++i) {
3775+
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts[i];
3776+
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+
}
3786+
3787+
std::string tr181_param_name = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM;
3788+
tr181_param_name += "." + convertSourceIndexToString(ctx.videoSrcType);
3789+
tr181_param_name += ".Format." + convertVideoFormatToString(ctx.videoFormatType);
3790+
tr181_param_name += ".PictureModeString";
3791+
3792+
err = clearLocalParam(rfc_caller_id, tr181_param_name.c_str());
3793+
if (err != tr181Success) {
3794+
LOGWARN("clearLocalParam failed for %s: %s\n", tr181_param_name.c_str(), getTR181ErrorString(err));
3795+
continue;
3796+
}
3797+
3798+
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
3799+
if (err != tr181Success) {
3800+
#if DEBUG
3801+
LOGWARN("getLocalParam failed for %s\n", tr181_param_name.c_str());
3802+
#endif
3803+
continue;
3804+
}
3805+
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) {
3816+
tvError_t ret = SetTVPictureMode(param.value);
3817+
if (ret != tvERROR_NONE) {
3818+
LOGWARN("SetTVPictureMode failed: %s\n", getErrorString(ret).c_str());
3819+
continue;
3820+
} else {
3821+
LOGINFO("PictureMode applied to current context: %s\n", param.value);
37783822
}
3779-
else {
3780-
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
3781-
if ( tr181Success == err ) {
3782-
//get curren source and if matches save for that alone
3783-
tvVideoSrcType_t current_source = VIDEO_SOURCE_IP;
3784-
GetCurrentVideoSource(&current_source);
3785-
3786-
tvVideoFormatType_t current_format = VIDEO_FORMAT_NONE;
3787-
GetCurrentVideoFormat(&current_format);
3788-
if( current_format == VIDEO_FORMAT_NONE) {
3789-
current_format = VIDEO_FORMAT_SDR;
3790-
}
3823+
}
3824+
3825+
int pqmodeindex = getPictureModeIndex(param.value);
3826+
SaveSourcePictureMode(ctx.videoSrcType, ctx.videoFormatType, pqmodeindex);
3827+
contextHandled = true;
3828+
}
3829+
3830+
3831+
if (!contextHandled) {
3832+
LOGWARN("No applicable contexts handled for PictureMode reset\n");
3833+
return false;
3834+
}
3835+
3836+
LOGINFO("Exit: PictureMode reset completed for all matching contexts.\n");
3837+
return true;
3838+
}
37913839

3792-
if (current_source == sourceType && current_format == formatType) {
3793-
LOGINFO("PQ mode =%s\n",param.value);
3794-
tvError_t ret = tvERROR_NONE;
3795-
if(ret != tvERROR_NONE) {
3796-
LOGWARN("Picture Mode set failed: %s\n",getErrorString(ret).c_str());
3797-
returnResponse(false);
3840+
uint32_t AVOutputTV::resetPictureMode(const JsonObject& parameters, JsonObject& response)
3841+
{
3842+
LOGINFO("Entry\n");
3843+
if (m_pictureModeStatus == tvERROR_OPERATION_NOT_SUPPORTED)
3844+
{
3845+
tr181ErrorCode_t err = tr181Success;
3846+
TR181_ParamData_t param = {0};
3847+
3848+
valueVectors_t values;
3849+
capDetails_t inputInfo;
3850+
3851+
// As only source need to validate, so pqmode and formate passing as currrent
3852+
if (parsingSetInputArgument(parameters, "PictureMode",inputInfo) != 0) {
3853+
LOGERR("%s: Failed to parse the input arguments \n", __FUNCTION__);
3854+
returnResponse(false);
3855+
}
3856+
3857+
if( !isCapablityCheckPassed( "PictureMode",inputInfo )) {
3858+
LOGERR("%s: CapablityCheck failed for PictureMode\n", __FUNCTION__);
3859+
returnResponse(false);
3860+
}
3861+
inputInfo.pqmode = "Current";
3862+
getSaveConfig("PictureMode", inputInfo, values);
3863+
3864+
for (int source : values.sourceValues) {
3865+
tvVideoSrcType_t sourceType = (tvVideoSrcType_t)source;
3866+
for (int format : values.formatValues) {
3867+
tvVideoFormatType_t formatType = (tvVideoFormatType_t)format;
3868+
std::string tr181_param_name = "";
3869+
tr181_param_name += std::string(AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
3870+
tr181_param_name += "."+convertSourceIndexToString(sourceType)+"."+"Format."+
3871+
convertVideoFormatToString(formatType)+"."+"PictureModeString";
3872+
3873+
err = clearLocalParam(rfc_caller_id, tr181_param_name.c_str());
3874+
if ( err != tr181Success ) {
3875+
LOGWARN("clearLocalParam for %s Failed : %s\n", tr181_param_name.c_str(), getTR181ErrorString(err));
3876+
returnResponse(false);
3877+
>>>>>>> d9c44794 (Implement context based resetPictureMode)
3878+
}
3879+
else {
3880+
err = getLocalParam(rfc_caller_id, tr181_param_name.c_str(), &param);
3881+
if ( tr181Success == err ) {
3882+
//get curren source and if matches save for that alone
3883+
tvVideoSrcType_t current_source = VIDEO_SOURCE_IP;
3884+
GetCurrentVideoSource(&current_source);
3885+
3886+
tvVideoFormatType_t current_format = VIDEO_FORMAT_NONE;
3887+
GetCurrentVideoFormat(&current_format);
3888+
if( current_format == VIDEO_FORMAT_NONE) {
3889+
current_format = VIDEO_FORMAT_SDR;
37983890
}
3799-
else {
3800-
LOGINFO("Exit : Picture Mode reset successfully, value: %s\n", param.value);
3891+
3892+
if (current_source == sourceType && current_format == formatType) {
3893+
3894+
tvError_t ret = SetTVPictureMode(param.value);
3895+
if(ret != tvERROR_NONE) {
3896+
LOGWARN("Picture Mode set failed: %s\n",getErrorString(ret).c_str());
3897+
returnResponse(false);
3898+
}
3899+
else {
3900+
LOGINFO("Exit : Picture Mode reset successfully, value: %s\n", param.value);
3901+
}
38013902
}
3903+
int pqmodeindex = (int)getPictureModeIndex(param.value);
3904+
SaveSourcePictureMode(sourceType, formatType, pqmodeindex);
3905+
}
3906+
else {
3907+
LOGWARN("getLocalParam for %s failed\n", AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
3908+
returnResponse(false);
38023909
}
3803-
int pqmodeindex = (int)getPictureModeIndex(param.value);
3804-
SaveSourcePictureMode(sourceType, formatType, pqmodeindex);
3805-
}
3806-
else {
3807-
LOGWARN("getLocalParam for %s failed\n", AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM);
3808-
returnResponse(false);
38093910
}
38103911
}
38113912
}
3913+
returnResponse(true);
3914+
}
3915+
else
3916+
{
3917+
bool success = resetPictureModeV2(parameters);
3918+
returnResponse(success);
38123919
}
3813-
returnResponse(true)
38143920
}
38153921

38163922
uint32_t AVOutputTV::signalFilmMakerMode(const JsonObject& parameters, JsonObject& response)

AVOutput/AVOutputTV.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ class AVOutputTV : public AVOutputBase {
500500
std::vector<std::string> resolveValue(const std::string& val, std::string (AVOutputTV::*resolver)());
501501
bool isSetRequiredForParam(const std::string& paramName, const JsonObject& parameters);
502502
tvContextCaps_t* getCapsForParam(const std::string& paramName);
503+
bool isValidSource(const std::vector<std::string>& sourceArray, tvVideoSrcType_t sourceIndex);
504+
bool isValidFormat(const std::vector<std::string>& formatArray, tvVideoFormatType_t formatIndex);
503505
tvError_t updateAVoutputTVParamToHALV2(std::string forParam, paramIndex_t indexInfo, int value, bool setNotDelete);
506+
bool resetPictureModeV2(const JsonObject& parameters);
504507

505508

506509
public:

AVOutput/AVOutputTVHelper.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,55 @@ namespace Plugin {
905905
return ret;
906906
}
907907

908+
909+
tvContentFormatType_t AVOutputTV::convertFormatStringToTVContentFormat(const char *format)
910+
{
911+
tvContentFormatType_t ret = tvContentFormatType_SDR;
912+
913+
if( strncmp(format,"sdr",strlen(format)) == 0 || strncmp(format,"SDR",strlen(format)) == 0 ) {
914+
ret = tvContentFormatType_SDR;
915+
}
916+
else if( strncmp(format,"hdr10",strlen(format)) == 0 || strncmp(format,"HDR10",strlen(format))==0 ) {
917+
ret = tvContentFormatType_HDR10;
918+
}
919+
else if( strncmp(format,"hlg",strlen(format)) == 0 || strncmp(format,"HLG",strlen(format)) == 0 ) {
920+
ret = tvContentFormatType_HLG;
921+
}
922+
else if( strncmp(format,"dolby",strlen(format)) == 0 || strncmp(format,"DOLBY",strlen(format)) == 0 ) {
923+
ret=tvContentFormatType_DOVI;
924+
}
925+
926+
return ret;
927+
}
928+
// Helper to validate if the source is in the provided sourceArray
929+
bool AVOutputTV::isValidSource(const std::vector<std::string>& sourceArray, tvVideoSrcType_t sourceIndex)
930+
{
931+
if (std::find(sourceArray.begin(), sourceArray.end(), "Current") != sourceArray.end()) {
932+
return true; // If "Current" is passed, match the current source
933+
}
934+
935+
for (const auto& source : sourceArray) {
936+
if (source == convertSourceIndexToString(sourceIndex)) {
937+
return true;
938+
}
939+
}
940+
return false;
941+
}
942+
943+
// Helper to validate if the format is in the provided formatArray
944+
bool AVOutputTV::isValidFormat(const std::vector<std::string>& formatArray, tvVideoFormatType_t formatIndex)
945+
{
946+
if (std::find(formatArray.begin(), formatArray.end(), "Current") != formatArray.end()) {
947+
return true; // If "Current" is passed, match the current format
948+
}
949+
950+
for (const auto& format : formatArray) {
951+
if (format == convertVideoFormatToString(formatIndex)) {
952+
return true;
953+
}
954+
}
955+
return false;
956+
}
908957
tvError_t AVOutputTV::updateAVoutputTVParamToHALV2(std::string forParam, paramIndex_t indexInfo, int value, bool setNotDelete)
909958
{
910959
tvError_t ret = tvERROR_NONE;

0 commit comments

Comments
 (0)