Skip to content

RDK-55883 : BackPort EAA changes #6249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release/8.0_p1v
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions TextToSpeech/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ All notable changes to this RDK Service will be documented in this file.
* Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development.

* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.
## [1.0.34] - 2025-04-01
### Fixed
- EAA fixed VG not working on IT/DE device

## [1.0.33] - 2025-03-20
### Added
- EAA support for VG

## [1.0.32] - 2024-10-04
### Added
- Added Validation for text input from app
Expand Down
1 change: 1 addition & 0 deletions TextToSpeech/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_library(${MODULE_NAME} SHARED
impl/TTSURLConstructer.cpp
impl/NetworkStatusObserver.cpp
impl/SatToken.cpp
impl/RFCURLObserver.cpp
)
set_target_properties(${MODULE_NAME} PROPERTIES
CXX_STANDARD 11
Expand Down
2 changes: 1 addition & 1 deletion TextToSpeech/TextToSpeech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 32
#define API_VERSION_NUMBER_PATCH 34
#define API_VERSION_NUMBER 1

namespace WPEFramework {
Expand Down
15 changes: 14 additions & 1 deletion TextToSpeech/TextToSpeechImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mutex>

#include "TextToSpeechValidator.h"
#include "impl/RFCURLObserver.h"

#define TTS_MAJOR_VERSION 1
#define TTS_MINOR_VERSION 0
Expand All @@ -39,6 +40,7 @@
namespace WPEFramework {
namespace Plugin {


SERVICE_REGISTRATION(TextToSpeechImplementation, TTS_MAJOR_VERSION, TTS_MINOR_VERSION);

TTS::TTSManager* TextToSpeechImplementation::_ttsManager = NULL;
Expand Down Expand Up @@ -77,12 +79,13 @@ namespace Plugin {
config.FromString(service->ConfigLine());

TTS::TTSConfiguration *ttsConfig = _ttsManager->configuration();
TTS::RFCURLObserver::getInstance()->triggerRFC(ttsConfig);
ttsConfig->setEndPoint(GET_STR(config, "endpoint", ""));
ttsConfig->setSecureEndPoint(GET_STR(config, "secureendpoint", ""));
ttsConfig->setLocalEndPoint(GET_STR(config, "localendpoint", ""));
ttsConfig->setLanguage(GET_STR(config, "language", "en-US"));
ttsConfig->setVoice(GET_STR(config, "voice", ""));
ttsConfig->setEndpointType(GET_STR(config, "endpoint_type", "TTS1"));
ttsConfig->setEndpointType(GET_STR(config, "endpoint_type", ""));
ttsConfig->setSpeechRate(GET_STR(config, "speechrate", ""));
ttsConfig->setVolume(std::stod(GET_STR(config, "volume", "100")));
ttsConfig->setRate(std::stoi(GET_STR(config, "rate", "50")));
Expand Down Expand Up @@ -128,6 +131,7 @@ namespace Plugin {
ttsConfig->loadFromConfigStore();
TTSLOG_INFO("TTSEndPoint : %s", ttsConfig->endPoint().c_str());
TTSLOG_INFO("SecureTTSEndPoint : %s", ttsConfig->secureEndPoint().c_str());
TTSLOG_INFO("RFCEndPoint : %s", ttsConfig->rfcEndPoint().c_str());
TTSLOG_INFO("LocalTTSEndPoint : %s", ttsConfig->localEndPoint().c_str());
TTSLOG_INFO("Language : %s", ttsConfig->language().c_str());
TTSLOG_INFO("Voice : %s", ttsConfig->voice().c_str());
Expand All @@ -142,6 +146,15 @@ namespace Plugin {
TTSLOG_INFO("%s : %s", it->first.c_str(), it->second.c_str());
++it;
}

if(ttsConfig->isRFCEnabled())
{
TTSLOG_INFO("TTS 2.0 Endpoint determined. URL:%s",ttsConfig->rfcEndPoint().c_str());
}
else
{
TTSLOG_INFO("TTS Endpoint URL is not determinable at boot time\n");
}

if(ttsConfig->hasValidLocalEndpoint()) {
TTSLOG_INFO("Online/offline endpoint switch enabled");
Expand Down
6 changes: 5 additions & 1 deletion TextToSpeech/TextToSpeechJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ uint32_t TextToSpeech::SetACL(const JsonObject& parameters, JsonObject& response
Exchange::ITextToSpeech::Configuration config;
config.ttsEndPoint = GET_STR(parameters, "ttsendpoint", "");
config.ttsEndPointSecured = GET_STR(parameters, "ttsendpointsecured", "");
config.language = GET_STR(parameters, "language", "");
config.language = GET_STR(parameters, "language", "");
#ifndef UNIT_TESTING
config.voice = ""; //ignore voice from app
#else
config.voice = GET_STR(parameters, "voice", "");
#endif
config.speechRate = GET_STR(parameters, "speechrate", "");

std::string proxyVolume = GET_STR(parameters, "volume", "0.0");
Expand Down
148 changes: 148 additions & 0 deletions TextToSpeech/impl/RFCURLObserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include <thread>
#include "RFCURLObserver.h"
#include "UtilsgetRFCConfig.h"
#include "UtilsLogging.h"

#if defined(SECURITY_TOKEN_ENABLED) && ((SECURITY_TOKEN_ENABLED == 0) || (SECURITY_TOKEN_ENABLED == false))
#define GetSecurityToken(a, b) 0
#define GetToken(a, b, c) 0
#else
#include <WPEFramework/securityagent/securityagent.h>
#include <WPEFramework/securityagent/SecurityTokenUtil.h>
#endif

#define MAX_SECURITY_TOKEN_SIZE 1024
#define SYSTEMSERVICE_CALLSIGN "org.rdk.System"
#define SYSTEMSERVICE_CALLSIGN_VER SYSTEMSERVICE_CALLSIGN".1"

#define MAX_RETRIES 3 // Define the maximum number of retries
#define RETRY_DELAY_MS 2000 // Define the delay between retries in milliseconds

using namespace WPEFramework;

namespace TTS {

RFCURLObserver* RFCURLObserver::getInstance() {
static RFCURLObserver *instance = new RFCURLObserver();
return instance;
}


void RFCURLObserver::triggerRFC(TTSConfiguration *config)
{
m_defaultConfig = config;
fetchURLFromConfig();
std::thread notificationThread(&RFCURLObserver::registerNotification, this);
notificationThread.detach(); // Detach the thread to run independently
}

void RFCURLObserver::fetchURLFromConfig() {
bool m_rfcURLSet = false;
RFC_ParamData_t param;
#ifndef UNIT_TESTING
m_rfcURLSet = Utils::getRFCConfig("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.TextToSpeech.URL", param);
#endif
if (m_rfcURLSet) {
TTSLOG_INFO("Received RFC URL %s\n",param.value);
m_defaultConfig->setRFCEndPoint(param.value);
} else {
TTSLOG_ERROR("Error: Reading URL RFC failed.");
}
}

string RFCURLObserver::getSecurityToken() {
std::string token = "token=";
int tokenLength = 0;
unsigned char buffer[MAX_SECURITY_TOKEN_SIZE] = {0};
static std::string endpoint;

if(endpoint.empty()) {
Core::SystemInfo::GetEnvironment(_T("THUNDER_ACCESS"), endpoint);
TTSLOG_INFO("Thunder RPC Endpoint read from env - %s", endpoint.c_str());
}

if(endpoint.empty()) {
Core::File file("/etc/WPEFramework/config.json");
if(file.Open(true)) {
JsonObject config;
if(config.IElement::FromFile(file)) {
Core::JSON::String port = config.Get("port");
Core::JSON::String binding = config.Get("binding");
if(!binding.Value().empty() && !port.Value().empty())
endpoint = binding.Value() + ":" + port.Value();
}
file.Close();
}
if(endpoint.empty())
endpoint = _T("127.0.0.1:9998");

TTSLOG_INFO("Thunder RPC Endpoint read from config file - %s", endpoint.c_str());
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), endpoint);
}

string payload = "http://localhost";
if(payload.empty()) {
tokenLength = GetSecurityToken(sizeof(buffer), buffer);
} else {
int buffLength = std::min(sizeof(buffer), payload.length());
::memcpy(buffer, payload.c_str(), buffLength);
tokenLength = GetToken(sizeof(buffer), buffLength, buffer);
}

if(tokenLength > 0) {
token.append((char*)buffer);
} else {
token.clear();
}

TTSLOG_INFO("Thunder token - %s", token.empty() ? "" : token.c_str());
return token;
}


void RFCURLObserver::registerNotification() {
if (m_systemService == nullptr && !m_eventRegistered) {
std::string token = getSecurityToken();
if(token.empty()) {
m_systemService = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEMSERVICE_CALLSIGN_VER),"");
} else {
m_systemService = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEMSERVICE_CALLSIGN_VER),"", false, token);
}

int retries = 0;
while (retries < MAX_RETRIES) {
if (m_systemService->Subscribe<JsonObject>(3000, "onDeviceMgtUpdateReceived",
&RFCURLObserver::onDeviceMgtUpdateReceivedHandler, this) == Core::ERROR_NONE) {
m_eventRegistered = true;
TTSLOG_INFO("Subscribed to notification handler: onDeviceMgtUpdateReceived");
break;
} else {
TTSLOG_ERROR("Failed to subscribe to notification handler: onDeviceMgtUpdateReceived..Retrying");
std::this_thread::sleep_for(std::chrono::milliseconds(RETRY_DELAY_MS));
retries++;
}
}

if (!m_eventRegistered) {
TTSLOG_ERROR("Failed to subscribe to notification handler after maximum retries.");
}
}
}

void RFCURLObserver::onDeviceMgtUpdateReceivedHandler(const JsonObject& parameters) {
if(parameters["source"].String() == "rfc")
{
fetchURLFromConfig();
TTSLOG_INFO("onDeviceMgtUpdateReceived notification received");
}
}

RFCURLObserver::~RFCURLObserver() {
// Clean up resources
if (m_systemService) {
delete m_systemService;
m_systemService = nullptr;
}
}

}
31 changes: 31 additions & 0 deletions TextToSpeech/impl/RFCURLObserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef _TTS_RFC_H_
#define _TTS_RFC_H_
#include "TTSCommon.h"
#include "TTSConfiguration.h"

namespace TTS {

class RFCURLObserver {
public:
static RFCURLObserver* getInstance();
void triggerRFC(TTSConfiguration*);
~RFCURLObserver();

private:
RFCURLObserver(){};
RFCURLObserver(const RFCURLObserver&) = delete;
RFCURLObserver& operator=(const RFCURLObserver&) = delete;

void fetchURLFromConfig();
void registerNotification();
string getSecurityToken();

void onDeviceMgtUpdateReceivedHandler(const JsonObject& parameters);

WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* m_systemService{nullptr};
bool m_eventRegistered {false};
TTSConfiguration *m_defaultConfig;
};

}
#endif
13 changes: 12 additions & 1 deletion TextToSpeech/impl/TTSConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TTSConfiguration {

bool setEndPoint(const std::string endpoint);
bool setSecureEndPoint(const std::string endpoint);
bool setRFCEndPoint(const std::string endpoint);
bool setApiKey(const std::string apikey);
bool setEndpointType(const std::string type);
bool setLocalEndPoint(const std::string endpoint);
Expand All @@ -35,6 +36,7 @@ class TTSConfiguration {
bool setSATPluginCallsign(const std::string callsign);

bool isFallbackEnabled();
bool isRFCEnabled();
bool hasValidLocalEndpoint();
void saveFallbackPath(std::string);
const std::string getFallbackScenario();
Expand All @@ -47,10 +49,17 @@ class TTSConfiguration {
const std::string &secureEndPoint() { return m_ttsEndPointSecured; }
const std::string &localEndPoint() { return m_ttsEndPointLocal; }
const std::string &apiKey() { return m_apiKey; }
const std::string &endPointType() { return m_endpointType; }
const std::string &endPointType() {
std::lock_guard<std::mutex> lock(m_mutex);
return m_endpointType; }
const std::string &speechRate() { return m_speechRate; }
const std::string &language() { return m_language; }
const std::string &satPluginCallsign() { return m_satPluginCallsign; }
const std::string &rfcEndPoint() {
std::lock_guard<std::mutex> lock(m_mutex);
return m_ttsRFCEndpoint;
}

const double &volume() { return m_volume; }
const uint8_t &rate() { return m_rate; }
const int8_t &primVolDuck() { return m_primVolDuck; }
Expand All @@ -71,6 +80,7 @@ class TTSConfiguration {
std::string m_ttsEndPoint;
std::string m_ttsEndPointSecured;
std::string m_ttsEndPointLocal;
std::string m_ttsRFCEndpoint;
std::string m_apiKey;
std::string m_endpointType;
std::string m_speechRate;
Expand All @@ -83,6 +93,7 @@ class TTSConfiguration {
int8_t m_primVolDuck;
bool m_preemptiveSpeaking;
bool m_enabled;
bool m_ttsRFCEnabled;
bool m_fallbackenabled;
bool m_validLocalEndpoint;
FallbackData m_data;
Expand Down
2 changes: 1 addition & 1 deletion TextToSpeech/impl/TTSManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ TTS_Error TTSManager::getConfiguration(Configuration &configuration) {
TTSLOG_TRACE("Getting Default Configuration");

configuration.ttsEndPoint = m_defaultConfiguration.endPoint();
configuration.ttsEndPointSecured = m_defaultConfiguration.secureEndPoint();
configuration.ttsEndPointSecured = m_defaultConfiguration.isRFCEnabled() ? m_defaultConfiguration.rfcEndPoint() : m_defaultConfiguration.secureEndPoint();
configuration.language = m_defaultConfiguration.language();
configuration.voice = m_defaultConfiguration.voice();
configuration.speechRate = m_defaultConfiguration.speechRate();
Expand Down
Loading
Loading