Skip to content

Commit 7537857

Browse files
slkanthiarjunbinu
authored andcommitted
Context based implementation for setBacklight and getBacklight
1 parent f04c156 commit 7537857

File tree

3 files changed

+329
-5
lines changed

3 files changed

+329
-5
lines changed

AVOutput/AVOutputTV.cpp

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ namespace Plugin {
394394
registerMethod("resetMEMC", &AVOutputTV::resetMEMC, this);
395395
registerMethod("getMEMCCaps", &AVOutputTV::getMEMCCaps, this);
396396

397+
registerMethod("setBacklightV2", &AVOutputTV::setBacklightV2, this);
398+
registerMethod("getBacklightV2", &AVOutputTV::getBacklightV2, this);
399+
397400
registerMethod("getBacklightCapsV2", &AVOutputTV::getBacklightCapsV2, this);
398401
registerMethod("getBrightnessCapsV2", &AVOutputTV::getBrightnessCapsV2, this);
399402
registerMethod("getContrastCapsV2", &AVOutputTV::getContrastCapsV2, this);
@@ -509,6 +512,73 @@ namespace Plugin {
509512

510513
LOGINFO("Exit\n");
511514
}
515+
uint32_t AVOutputTV::getBacklightV2(const JsonObject& parameters, JsonObject& response)
516+
{
517+
LOGINFO("Entry: %s", __FUNCTION__);
518+
std::vector<tvConfigContext_t> validContexts = getValidContextsFromParameters(parameters);
519+
if (validContexts.empty()) {
520+
LOGERR("%s: No valid context found for the given parameters", __FUNCTION__);
521+
returnResponse(false);
522+
}
523+
// Only one valid context is expected in this simplified version
524+
const auto& ctx = validContexts.front();
525+
paramIndex_t indexInfo {
526+
.sourceIndex = static_cast<uint8_t>(ctx.videoSrcType),
527+
.pqmodeIndex = static_cast<uint8_t>(ctx.pq_mode),
528+
.formatIndex = static_cast<uint8_t>(ctx.videoFormatType)
529+
};
530+
int backlight = 0;
531+
int err = getLocalparam("Backlight", indexInfo, backlight, PQ_PARAM_BACKLIGHT);
532+
if (err == tvERROR_NONE) {
533+
response["backlight"] = backlight;
534+
LOGINFO("Exit: Backlight Value: %d", backlight);
535+
returnResponse(true);
536+
} else {
537+
LOGERR("Failed to get backlight. Error code: %d", err);
538+
returnResponse(false);
539+
}
540+
}
541+
uint32_t AVOutputTV::setBacklightV2(const JsonObject& parameters, JsonObject& response)
542+
{
543+
LOGINFO("Entry\n");
544+
std::string value;
545+
int backlight = 0;
546+
#define TODO_MOVE_TO_INIT 1
547+
#if TODO_MOVE_TO_INIT
548+
// Retrieve Backlight Caps (Initialization)
549+
LOGINFO("Calling GetBacklightCaps\n");
550+
tvError_t error = GetBacklightCaps(&m_maxBacklight, &m_backlightCaps);
551+
if (error == tvERROR_NONE) {
552+
LOGINFO("Backlight capabilities retrieved successfully. Max: %d\n", m_maxBacklight);
553+
} else {
554+
LOGERR("Failed to retrieve backlight capabilities. Error code: %d\n", error);
555+
returnResponse(false);
556+
}
557+
#endif
558+
// Input parameter validation
559+
LOGINFO("InputParm validation\n");
560+
value = parameters.HasLabel("backlight") ? parameters["backlight"].String() : "";
561+
returnIfParamNotFound(parameters,"backlight");
562+
try {
563+
backlight = std::stoi(value);
564+
} catch (const std::exception& e) {
565+
LOGERR("Invalid backlight value: %s. Exception: %s", value.c_str(), e.what());
566+
returnResponse(false);
567+
}
568+
if (backlight < 0 || backlight > m_maxBacklight) {
569+
LOGERR("Input value %d is out of range (0 - %d)", backlight, m_maxBacklight);
570+
returnResponse(false);
571+
}
572+
// Update the TV parameter
573+
LOGINFO("Updating AVOutputTVParamV2\n");
574+
int retval = updateAVoutputTVParamV2("set", "Backlight", parameters, PQ_PARAM_BACKLIGHT, backlight);
575+
if (retval != 0) {
576+
LOGERR("Failed to Save Backlight to ssm_data. retval: %d\n", retval);
577+
returnResponse(false);
578+
}
579+
LOGINFO("Exit: setBacklight successful to value: %d\n", backlight);
580+
returnResponse(true);
581+
}
512582

513583
uint32_t AVOutputTV::getCapsV2(
514584
const std::function<tvError_t( tvContextCaps_t**,int*, std::vector<std::string>&)>& getCapsFunc,
@@ -776,7 +846,7 @@ namespace Plugin {
776846
case tvDisplayMode_4x3: optionsArray.Add("TV 4X3 PILLARBOX"); break;
777847
case tvDisplayMode_ZOOM: optionsArray.Add("TV ZOOM"); break;
778848
case tvDisplayMode_FULL: optionsArray.Add("TV FULL"); break;
779-
default: break;
849+
default: break;
780850
}
781851
}
782852
rangeInfo["options"] = optionsArray;
@@ -3123,8 +3193,8 @@ namespace Plugin {
31233193
}
31243194

31253195
if (current_source == sourceType && current_format == formatType) {
3126-
3127-
tvError_t ret = SetTVPictureMode(param.value);
3196+
LOGINFO("PQ mode =%s\n",value.c_str());
3197+
ret = tvERROR_NONE;
31283198
if(ret != tvERROR_NONE) {
31293199
LOGWARN("Picture Mode set failed: %s\n",getErrorString(ret).c_str());
31303200
returnResponse(false);

AVOutput/AVOutputTV.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class AVOutputTV : public AVOutputBase {
188188
AVOutputTV& operator=(const AVOutputTV&) = delete;
189189
public:
190190
/*Get API's*/
191+
DECLARE_JSON_RPC_METHOD(getBacklightV2)
191192
DECLARE_JSON_RPC_METHOD(getBacklight)
192193
DECLARE_JSON_RPC_METHOD(getBrightness )
193194
DECLARE_JSON_RPC_METHOD(getContrast )
@@ -263,6 +264,7 @@ class AVOutputTV : public AVOutputBase {
263264
DECLARE_JSON_RPC_METHOD(getTVPictureModeCapsV2)
264265

265266
/*Set API's*/
267+
DECLARE_JSON_RPC_METHOD(setBacklightV2)
266268
DECLARE_JSON_RPC_METHOD(setBacklight)
267269
DECLARE_JSON_RPC_METHOD(setBrightness)
268270
DECLARE_JSON_RPC_METHOD(setContrast )
@@ -459,6 +461,17 @@ class AVOutputTV : public AVOutputBase {
459461
const JsonObject& parameters,
460462
JsonObject& response);
461463
JsonObject parseContextCaps(tvContextCaps_t* context_caps);
464+
// Helper functions to extract modes/sources/formats from parameters
465+
std::vector<tvPQModeIndex_t> extractPQModes(const JsonObject& parameters, bool& isCurrent);
466+
std::vector<tvVideoSrcType_t> extractVideoSources(const JsonObject& parameters, bool& isCurrent);
467+
std::vector<tvVideoFormatType_t> extractVideoFormats(const JsonObject& parameters, bool& isCurrent); // Checks if the given context matches the system's current context
468+
bool isCurrentContext(const tvConfigContext_t& ctx) const;
469+
template<typename T>
470+
std::vector<T> collectFieldFromCaps(std::function<T(const tvConfigContext_t&)> accessor) const;
471+
static bool isGlobalParam(const JsonArray& arr);
472+
int updateAVoutputTVParamV2(std::string action, std::string tr181ParamName,
473+
const JsonObject& parameters, tvPQParameterIndex_t pqParamIndex, int level);
474+
std::vector<tvConfigContext_t> getValidContextsFromParameters(const JsonObject& parameters);
462475

463476

464477
public:
@@ -468,6 +481,8 @@ class AVOutputTV : public AVOutputBase {
468481
char rfc_caller_id[RFC_BUFF_MAX];
469482
bool appUsesGlobalBackLightFactor;
470483
int pic_mode_index[PIC_MODES_SUPPORTED_MAX];
484+
int m_maxBacklight = 0;
485+
tvContextCaps_t *m_backlightCaps = nullptr;
471486

472487
static const std::map<int, std::string> pqModeMap;
473488
static const std::map<int, std::string> videoFormatMap;

0 commit comments

Comments
 (0)