@@ -3502,41 +3502,55 @@ namespace Plugin {
3502
3502
3503
3503
bool AVOutputTV::getPictureModeV2 (const JsonObject& parameters, std::string& outMode)
3504
3504
{
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
+ }
3512
3521
}
3513
3522
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
+ }
3519
3536
3537
+ // Directly use TR-181 to fetch active picture mode
3520
3538
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 ) +
3523
3541
" .PictureModeString" ;
3524
3542
3525
- LOGINFO (" Context: Source=%s, Format=%s" ,
3526
- convertSourceIndexToString (indexInfo.sourceIndex ).c_str (),
3527
- convertVideoFormatToString (indexInfo.formatIndex ).c_str ());
3528
-
3529
3543
LOGINFO (" TR181 Param Name = %s" , tr181_param_name.c_str ());
3530
3544
3531
3545
TR181_ParamData_t param = {0 };
3532
3546
tr181ErrorCode_t err = getLocalParam (rfc_caller_id, tr181_param_name.c_str (), ¶m);
3533
-
3534
3547
if (err != tr181Success) {
3535
3548
LOGERR (" getLocalParam failed: %d" , err);
3536
3549
return false ;
3537
3550
}
3538
3551
3539
3552
outMode = param.value ;
3553
+ LOGINFO (" Exit: PictureMode = %s" , outMode.c_str ());
3540
3554
return true ;
3541
3555
}
3542
3556
@@ -3587,43 +3601,80 @@ namespace Plugin {
3587
3601
{
3588
3602
LOGINFO (" Entry %s\n " , __FUNCTION__);
3589
3603
3590
- // Validate pictureMode
3591
3604
if (!parameters.HasLabel (" pictureMode" )) {
3592
3605
LOGERR (" Missing 'pictureMode' in parameters.\n " );
3593
3606
return false ;
3594
3607
}
3595
3608
3596
3609
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]));
3600
3610
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 ) {
3602
3621
LOGERR (" Invalid pictureMode: %s" , mode.c_str ());
3603
3622
return false ;
3604
3623
}
3605
3624
3606
- // Extract and normalize videoSource array
3625
+ // Extract videoSource array (default: Global if not provided)
3607
3626
std::vector<std::string> sources;
3608
3627
if (parameters.HasLabel (" videoSource" )) {
3609
3628
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
+ }
3612
3635
} else {
3613
3636
sources.push_back (" Global" );
3614
3637
}
3615
3638
3616
- // Extract and normalize videoFormat array
3639
+ // Extract videoFormat array (default: Global if not provided)
3617
3640
std::vector<std::string> formats;
3618
3641
if (parameters.HasLabel (" videoFormat" )) {
3619
3642
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
+ }
3622
3649
} else {
3623
3650
formats.push_back (" Global" );
3624
3651
}
3625
3652
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
3627
3678
tvVideoSrcType_t currentSrc = VIDEO_SOURCE_IP;
3628
3679
tvVideoFormatType_t currentFmt = VIDEO_FORMAT_SDR;
3629
3680
GetCurrentVideoSource (¤tSrc);
@@ -3633,17 +3684,29 @@ namespace Plugin {
3633
3684
3634
3685
bool contextHandled = false ;
3635
3686
3687
+ // Iterate through contexts and apply picture mode based on the video source and format
3636
3688
for (size_t i = 0 ; i < m_pictureModeCaps->num_contexts ; ++i) {
3637
3689
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts [i];
3638
3690
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] )
3641
3693
continue ;
3642
3694
3643
- // Match format
3695
+ // Validate by source and format
3696
+ if (!isValidSource (sources, ctx.videoSrcType ))
3697
+ continue ;
3644
3698
if (!isValidFormat (formats, ctx.videoFormatType ))
3645
3699
continue ;
3646
3700
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
3647
3710
std::string tr181Param = std::string (AVOUTPUT_SOURCE_PICTUREMODE_STRING_RFC_PARAM) + " ." +
3648
3711
convertSourceIndexToString (ctx.videoSrcType ) + " .Format." +
3649
3712
convertVideoFormatToString (ctx.videoFormatType ) + " .PictureModeString" ;
@@ -3654,17 +3717,6 @@ namespace Plugin {
3654
3717
continue ;
3655
3718
}
3656
3719
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
-
3668
3720
contextHandled = true ;
3669
3721
}
3670
3722
@@ -3774,113 +3826,96 @@ namespace Plugin {
3774
3826
3775
3827
bool AVOutputTV::resetPictureModeV2 (const JsonObject& parameters)
3776
3828
{
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__);
3788
3830
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" )) {
3791
3834
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" );
3805
3839
}
3806
3840
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" )) {
3809
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
+ }
3810
3850
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 ));
3822
3856
}
3857
+ sources.insert (sources.end (), sourceSet.begin (), sourceSet.end ());
3823
3858
}
3824
3859
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;
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 (¤tSrc);
3873
+ GetCurrentVideoFormat (¤tFmt);
3874
+ if (currentFmt == VIDEO_FORMAT_NONE)
3875
+ currentFmt = VIDEO_FORMAT_SDR;
3832
3876
3833
3877
bool contextHandled = false ;
3834
3878
3879
+ // Iterate through contexts and apply picture mode reset based on the video source and format
3835
3880
for (size_t i = 0 ; i < m_pictureModeCaps->num_contexts ; ++i) {
3836
3881
const tvConfigContext_t& ctx = m_pictureModeCaps->contexts [i];
3837
3882
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 ))
3850
3885
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
+ }
3851
3896
}
3852
3897
3853
- err = getLocalParam (rfc_caller_id, tr181_param_name.c_str (), ¶m);
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)
3854
3904
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));
3858
3906
continue ;
3859
3907
}
3860
3908
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);
3874
3909
contextHandled = true ;
3875
3910
}
3876
3911
3877
3912
3878
3913
if (!contextHandled) {
3879
- LOGWARN (" No applicable contexts handled for PictureMode reset\n " );
3914
+ LOGERR (" No matching context found to reset pictureMode. \n " );
3880
3915
return false ;
3881
3916
}
3882
3917
3883
- LOGINFO (" Exit: PictureMode reset completed for all matching contexts .\n " );
3918
+ LOGINFO (" Exit: PictureMode reset successfully .\n " );
3884
3919
return true ;
3885
3920
}
3886
3921
0 commit comments