@@ -3587,61 +3587,93 @@ namespace Plugin {
3587
3587
{
3588
3588
LOGINFO (" Entry %s\n " , __FUNCTION__);
3589
3589
3590
+ // Validate pictureMode
3590
3591
if (!parameters.HasLabel (" pictureMode" )) {
3591
- LOGERR (" Parameter 'pictureMode' not found in the request .\n " );
3592
+ LOGERR (" Missing 'pictureMode' in parameters .\n " );
3592
3593
return false ;
3593
3594
}
3594
3595
3595
3596
std::string mode = parameters[" pictureMode" ].String ();
3596
-
3597
3597
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)
3599
3599
validOptions.emplace_back (pqModeMap.at (m_pictureModes[i]));
3600
- }
3601
3600
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 ());
3605
3603
return false ;
3606
3604
}
3607
3605
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" );
3612
3614
}
3613
3615
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 (¤tSrc);
3630
+ GetCurrentVideoFormat (¤tFmt);
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
+
3615
3647
std::string tr181Param = std::string (AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + " ." +
3616
3648
convertSourceIndexToString (ctx.videoSrcType ) + " .Format." +
3617
3649
convertVideoFormatToString (ctx.videoFormatType ) + " .PictureModeString" ;
3618
3650
3619
3651
tr181ErrorCode_t err = setLocalParam (rfc_caller_id, tr181Param.c_str (), mode.c_str ());
3620
3652
if (err != tr181Success) {
3621
3653
LOGERR (" setLocalParam failed for %s: %s" , tr181Param.c_str (), getTR181ErrorString (err));
3622
- return false ;
3654
+ continue ;
3623
3655
}
3624
3656
3625
- int modeIndex = ( int ) getPictureModeIndex (mode);
3657
+ int modeIndex = getPictureModeIndex (mode);
3626
3658
SaveSourcePictureMode (ctx.videoSrcType , ctx.videoFormatType , modeIndex);
3627
3659
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 " );
3635
3662
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 ;
3638
3665
}
3639
3666
}
3640
3667
3668
+ contextHandled = true ;
3641
3669
}
3642
3670
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 ());
3645
3677
return true ;
3646
3678
}
3647
3679
@@ -3747,42 +3779,65 @@ namespace Plugin {
3747
3779
tr181ErrorCode_t err = tr181Success;
3748
3780
TR181_ParamData_t param = {0 };
3749
3781
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
+
3751
3789
std::vector<std::string> sourceArray;
3752
- if (parameters. HasLabel ( " videoSource " ) ) {
3790
+ if (hasSource ) {
3753
3791
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
+ }
3756
3804
}
3757
- } else {
3758
- sourceArray.push_back (" Current" );
3759
3805
}
3760
3806
3761
3807
std::vector<std::string> formatArray;
3762
- if (parameters. HasLabel ( " videoFormat " ) ) {
3808
+ if (hasFormat ) {
3763
3809
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
+ }
3766
3822
}
3767
- } else {
3768
- formatArray.push_back (" Current" );
3769
3823
}
3770
3824
3825
+ // Get current source and format
3826
+ tvVideoSrcType_t current_source = VIDEO_SOURCE_IP;
3827
+ tvVideoFormatType_t current_format = VIDEO_FORMAT_NONE;
3828
+ GetCurrentVideoSource (¤t_source);
3829
+ GetCurrentVideoFormat (¤t_format);
3830
+ if (current_format == VIDEO_FORMAT_NONE)
3831
+ current_format = VIDEO_FORMAT_SDR;
3832
+
3771
3833
bool contextHandled = false ;
3772
3834
3773
- // Loop through all the contexts in m_pictureModeCaps
3774
3835
for (size_t i = 0 ; i < m_pictureModeCaps->num_contexts ; ++i) {
3775
3836
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts [i];
3776
3837
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 ;
3786
3841
3787
3842
std::string tr181_param_name = AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM;
3788
3843
tr181_param_name += " ." + convertSourceIndexToString (ctx.videoSrcType );
@@ -3797,22 +3852,14 @@ namespace Plugin {
3797
3852
3798
3853
err = getLocalParam (rfc_caller_id, tr181_param_name.c_str (), ¶m);
3799
3854
if (err != tr181Success) {
3800
- #if DEBUG
3855
+ #if DEBUG
3801
3856
LOGWARN (" getLocalParam failed for %s\n " , tr181_param_name.c_str ());
3802
- #endif
3857
+ #endif
3803
3858
continue ;
3804
3859
}
3805
3860
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 (¤t_source);
3810
- GetCurrentVideoFormat (¤t_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) {
3816
3863
tvError_t ret = SetTVPictureMode (param.value );
3817
3864
if (ret != tvERROR_NONE) {
3818
3865
LOGWARN (" SetTVPictureMode failed: %s\n " , getErrorString (ret).c_str ());
0 commit comments