@@ -3823,50 +3823,45 @@ namespace Plugin {
3823
3823
returnResponse (success);
3824
3824
}
3825
3825
}
3826
-
3827
3826
bool AVOutputTV::resetPictureModeV2 (const JsonObject& parameters)
3828
3827
{
3829
3828
LOGINFO (" Entry %s\n " , __FUNCTION__);
3830
3829
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
+ };
3840
3842
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" );
3850
3845
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 ());
3856
3850
}
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
+ };
3859
3854
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 ));
3867
3860
}
3861
+ expandGlobal (sources, allSources);
3862
+ expandGlobal (formats, allFormats);
3868
3863
3869
- // Get current context
3864
+ // Get current source & format
3870
3865
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
3871
3866
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
3872
3867
GetCurrentVideoSource (¤tSrc);
@@ -3876,46 +3871,63 @@ namespace Plugin {
3876
3871
3877
3872
bool contextHandled = false ;
3878
3873
3879
- // Iterate through contexts and apply picture mode reset based on the video source and format
3880
3874
for (size_t i = 0 ; i < m_pictureModeCaps->num_contexts ; ++i) {
3881
3875
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts [i];
3882
3876
3883
- // Validate by source and format
3884
- if (!isValidSource (sources, ctx.videoSrcType ))
3877
+ if (!isValidSource (sources, ctx.videoSrcType ) || !isValidFormat (formats, ctx.videoFormatType ))
3885
3878
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
- }
3897
3879
3898
- // Update TR181 to reflect reset, even if HAL apply fails
3899
3880
std::string tr181Param = std::string (AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + " ." +
3900
3881
convertSourceIndexToString (ctx.videoSrcType ) + " .Format." +
3901
3882
convertVideoFormatToString (ctx.videoFormatType ) + " .PictureModeString" ;
3902
3883
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 ());
3904
3886
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 (), ¶m);
3894
+ if (err != tr181Success || strlen (param.value ) == 0 ) {
3895
+ LOGWARN (" getLocalParam failed or empty for %s" , tr181Param.c_str ());
3906
3896
continue ;
3907
3897
}
3908
3898
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
+
3909
3921
contextHandled = true ;
3910
3922
}
3911
3923
3912
3924
3913
3925
if (!contextHandled) {
3914
- LOGERR (" No matching context found to reset pictureMode .\n " );
3926
+ LOGERR (" No valid pictureMode context matched to reset.\n " );
3915
3927
return false ;
3916
3928
}
3917
3929
3918
- LOGINFO (" Exit: PictureMode reset successfully.\n " );
3930
+ LOGINFO (" resetPictureModeV2: Exit - PictureMode reset successfully.\n " );
3919
3931
return true ;
3920
3932
}
3921
3933
0 commit comments