Skip to content
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
1 change: 1 addition & 0 deletions subttxrend-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ target_link_libraries(${APP_NAME} ${LIBSUBTTXRENDTTML_LIBRARIES})
target_link_libraries(${APP_NAME} ${LIBSUBTTXRENDWEBVTT_LIBRARIES})
target_link_libraries(${APP_NAME} pthread)
target_link_libraries(${APP_NAME} boost_system)
target_link_libraries(${APP_NAME} jsoncpp)

#
# Install rules
Expand Down
4 changes: 3 additions & 1 deletion subttxrend-app/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void Application::runAsync()

m_logger.osinfo(__LOGGER_FUNC__, " - window created ", m_gfxWindow.get(), ", initializing controller");

m_controller = std::make_unique<Controller>(m_configuration, m_gfxEngine, m_gfxWindow);
m_region = m_configuration.getRegionInfo();

m_controller = std::make_unique<Controller>(m_configuration, m_gfxEngine, m_gfxWindow, m_region);

auto socketPath = m_configuration.getMainContextSocketPath();
m_logger.osinfo( __LOGGER_FUNC__, " - Creating unix socket source with path='", socketPath, "'.");
Expand Down
2 changes: 2 additions & 0 deletions subttxrend-app/src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Application : private common::NonCopyable
/** Application window. */
gfx::WindowPtr m_gfxWindow;

std::string m_region;

/** Subtitle and teletext control object. */
ControllerPtr m_controller;
common::Logger m_logger;
Expand Down
41 changes: 41 additions & 0 deletions subttxrend-app/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <subttxrend/common/Logger.hpp>
#include <subttxrend/common/StringUtils.hpp>

#include <fstream>
#include <json/json.h>

#define BUILD_CFG_FILE_PATH "/var/sky/build/buildConfig.json"

namespace subttxrend
{
namespace app
Expand Down Expand Up @@ -157,6 +162,42 @@ const char* Configuration::getValue(const std::string& key) const
return m_configFile.getCstr(key);
}

std::string Configuration::getRegionInfo() const
{
std::string key = "country";
std::string region = "us";

std::ifstream file(BUILD_CFG_FILE_PATH);
if (!file.is_open()) {
g_logger.info("%s Unable to open buildconfig.json, returning default value (%s) ", __func__, region.c_str());
return region;
}

std::stringstream jsonString;
jsonString << file.rdbuf();
file.close();

Json::CharReaderBuilder builder;
std::string errors;
Json::Value jsonData;

bool parsingSuccessful = parseFromStream(builder, jsonString, &jsonData, &errors);
if (!parsingSuccessful) {
g_logger.info("%s Error parsing JSON string:%s, returning default value (%s) ", __func__, errors.c_str(), region.c_str());
return region;
}

if (jsonData.isMember(key)){
region = jsonData[key].asString();
g_logger.info("%s Parsed region info, region:%s ", __func__, region.c_str());
}
else {
g_logger.info("%s Region info not found in buildconfig.json, returning default value (%s) ", __func__, region.c_str());
}

return region;
}

} // namespace app
}
// namespace subttxrend
2 changes: 2 additions & 0 deletions subttxrend-app/src/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Configuration : private common::ConfigProvider
*/
std::string getMainContextSocketPath() const;

std::string getRegionInfo() const;

/**
* Returns teletext configuration.
*
Expand Down
5 changes: 3 additions & 2 deletions subttxrend-app/src/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ constexpr const std::chrono::milliseconds as_data_acq_timeout{2000};

} /* namespace */

Controller::Controller(Configuration const& config, gfx::EnginePtr gfxEngine, gfx::WindowPtr gfxWindow)
Controller::Controller(Configuration const& config, gfx::EnginePtr gfxEngine, gfx::WindowPtr gfxWindow, const std::string region)
: m_config(config)
, m_gfxEngine(gfxEngine)
, m_gfxWindow(gfxWindow)
, m_region(region)
, m_fontCache{std::make_shared<gfx::PrerenderedFontCache>()}
, m_stcProvider()
, m_logger("App", "Controller", this)
Expand Down Expand Up @@ -378,7 +379,7 @@ void Controller::processTtmlSelection(const protocol::PacketTtmlSelection& packe
m_logger.oserror(__LOGGER_FUNC__, " exception: ", e.what());
}

pushController(std::make_shared<TtmlController>(packet, m_config.getTtmlConfig(), m_gfxWindow, properties));
pushController(std::make_shared<TtmlController>(packet, m_config.getTtmlConfig(), m_gfxWindow, properties, m_region));
}

void Controller::processWebvttSelection(const protocol::PacketWebvttSelection& packet)
Expand Down
5 changes: 4 additions & 1 deletion subttxrend-app/src/Controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Controller : private common::NonCopyable,
Controller(
Configuration const& config,
gfx::EnginePtr gfxEngine,
gfx::WindowPtr gfxWindow);
gfx::WindowPtr gfxWindow,
const std::string region);
// clang-format on

/**
Expand Down Expand Up @@ -325,6 +326,8 @@ class Controller : private common::NonCopyable,
gfx::EnginePtr m_gfxEngine;
gfx::WindowPtr m_gfxWindow;

std::string m_region;

/** Processes timestamp messages and provides stc value. */
StcProvider m_stcProvider;

Expand Down
5 changes: 3 additions & 2 deletions subttxrend-app/src/TtmlController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ namespace app {
TtmlController::TtmlController(const protocol::PacketChannelSpecific& dataPacket,
const common::ConfigProvider& config,
gfx::WindowPtr const& gfxWindow,
common::Properties const& properties)
common::Properties const& properties,
const std::string region)
: m_channel()
, m_logger("App", "TtmlController", this)
, m_ttmlEngine(ttmlengine::Factory::createTtmlEngine())
{
m_logger.ostrace(__LOGGER_FUNC__, " created");
m_ttmlEngine->init(&config, gfxWindow.get(), properties);
m_ttmlEngine->init(&config, gfxWindow.get(), properties, region);
select(dataPacket);
}

Expand Down
3 changes: 2 additions & 1 deletion subttxrend-app/src/TtmlController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class TtmlController final : public ControllerInterface
TtmlController(const protocol::PacketChannelSpecific& dataPacket,
const common::ConfigProvider& config,
gfx::WindowPtr const& gfxWindow,
common::Properties const& properties);
common::Properties const& properties,
const std::string region);
~TtmlController();

void process() override;
Expand Down
1 change: 1 addition & 0 deletions subttxrend-ctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ target_link_libraries(${LIBRARY_NAME} ${LIBSUBTTXRENDTTML_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} ${LIBSUBTTXRENDWEBVTT_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} pthread)
target_link_libraries(${LIBRARY_NAME} boost_system)
target_link_libraries(${LIBRARY_NAME} jsoncpp)

#
# Install rules
Expand Down
41 changes: 41 additions & 0 deletions subttxrend-ctrl/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <subttxrend/common/Logger.hpp>
#include <subttxrend/common/StringUtils.hpp>

#include <fstream>
#include <json/json.h>

#define BUILD_CFG_FILE_PATH "/var/sky/build/buildConfig.json"

namespace subttxrend
{
namespace app
Expand Down Expand Up @@ -157,6 +162,42 @@ const char* Configuration::getValue(const std::string& key) const
return m_configFile.getCstr(key);
}

std::string Configuration::getRegionInfo() const
{
std::string key = "country";
std::string region = "us";

std::ifstream file(BUILD_CFG_FILE_PATH);
if (!file.is_open()) {
g_logger.error("%s Unable to open buildconfig.json, returning default value (%s) ", __func__, region.c_str());
return region;
}

std::stringstream jsonString;
jsonString << file.rdbuf();
file.close();

Json::CharReaderBuilder builder;
std::string errors;
Json::Value jsonData;

bool parsingSuccessful = parseFromStream(builder, jsonString, &jsonData, &errors);
if (!parsingSuccessful) {
g_logger.error("%s Error parsing JSON string:%s, returning default value (%s) ", __func__, errors.c_str(), region.c_str());
return region;
}

if (jsonData.isMember(key)){
region = jsonData[key].asString();
g_logger.info("%s Parsed region info, region:%s ", __func__, region.c_str());
}
else {
g_logger.error("%s Region info not found in buildconfig.json, returning default value (%s) ", __func__, region.c_str());
}

return region;
}

} // namespace app
}
// namespace subttxrend
3 changes: 3 additions & 0 deletions subttxrend-ctrl/src/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class Configuration : private common::ConfigProvider
*/
std::string getMainContextSocketPath() const;


std::string getRegionInfo() const;

/**
* Returns teletext configuration.
*
Expand Down
5 changes: 3 additions & 2 deletions subttxrend-ctrl/src/TtmlController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ namespace app {
TtmlController::TtmlController(const protocol::PacketChannelSpecific& dataPacket,
const common::ConfigProvider& config,
gfx::WindowPtr const& gfxWindow,
common::Properties const& properties)
common::Properties const& properties,
const std::string region)
: m_channel()
, m_logger("App", "TtmlController", this)
, m_ttmlEngine(ttmlengine::Factory::createTtmlEngine())
{
m_logger.ostrace(__LOGGER_FUNC__, " created");
m_ttmlEngine->init(&config, gfxWindow.get(), properties);
m_ttmlEngine->init(&config, gfxWindow.get(), properties, region);
select(dataPacket);
}

Expand Down
3 changes: 2 additions & 1 deletion subttxrend-ctrl/src/TtmlController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class TtmlController final : public ControllerInterface
TtmlController(const protocol::PacketChannelSpecific& dataPacket,
const common::ConfigProvider& config,
gfx::WindowPtr const& gfxWindow,
common::Properties const& properties);
common::Properties const& properties,
const std::string region);
~TtmlController();

void process() override;
Expand Down
2 changes: 1 addition & 1 deletion subttxrend-ttml/include/TtmlEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TtmlEngine
*/
virtual void init(const common::ConfigProvider* configProvider,
gfx::Window* gfxWindow,
common::Properties const& properties) = 0;
common::Properties const& properties, const std::string region) = 0;

/**
* Notifies size of related video content. Used for position and size calculations.
Expand Down
8 changes: 8 additions & 0 deletions subttxrend-ttml/src/Parser/DocumentInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class DocumentInstance
m_currentImageElement = std::shared_ptr<ImageElement>();
}

void setRegionInfo(const std::string region)
{
m_regionInfo = region;
}

/**
* Adds element to the document.
*
Expand Down Expand Up @@ -308,6 +313,7 @@ class DocumentInstance

auto styleId = content->getStyleId();
textChunk.m_style.setStyleId(styleId);
textChunk.m_style.setRegionInfo(m_regionInfo);
textChunk.m_style.merge(content->getStyleAttributes());

m_logger.ostrace(__LOGGER_FUNC__, " chunk: \'", textChunk.m_text, "\'", ", style: ", textChunk.m_style.toStr());
Expand Down Expand Up @@ -592,6 +598,8 @@ class DocumentInstance
/** List of found content nodes. */
std::vector<std::shared_ptr<BodyElement> > m_content;

std::string m_regionInfo;

/** Logger object. */
mutable subttxrend::common::Logger m_logger;
};
Expand Down
5 changes: 3 additions & 2 deletions subttxrend-ttml/src/Parser/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class Parser : private SaxCallbacks
/**
* Constructor.
*/
Parser() :
Parser(const std::string region) :
m_saxParser(*this), m_logger("TtmlEngine", "Parser")
{
// noop

m_docInstance.setRegionInfo(region);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion subttxrend-ttml/src/Parser/StyleSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <utility>
#include <sstream>
#include <subttxrend/common/Logger.hpp>

namespace subttxrend
{
Expand Down Expand Up @@ -189,6 +190,9 @@ StyleSet::DisplayAlign parseDisplayAlign(const std::string& text)
return displayAlign;
}

common::Logger logger("TtmlEngine", "StyleSet");


} // namespace anonymous

const ColorArgb& StyleSet::getColor() const
Expand Down Expand Up @@ -240,6 +244,10 @@ void StyleSet::setStyleId(const std::string& styleId)
{
m_styleId = styleId;
}
void StyleSet::setRegionInfo(const std::string region)
{
m_region = region;
}
void StyleSet::merge(const Attributes& attributes)
{
for (const auto& attr : attributes) {
Expand Down Expand Up @@ -279,7 +287,10 @@ void StyleSet::parseAttribute(const std::string& name,
m_fontSize = sizeResult.size;
}
} else if (name == "textAlign") {
m_textAlign = parseTextAlign(value);
if(m_region == "it")
logger.info("%s LLAMA-8155: Ignoring incoming textAlign property (%s) - defaulting to \"center\"", __LOGGER_FUNC__, value.c_str());
else
m_textAlign = parseTextAlign(value);
} else if (name == "displayAlign") {
m_displayAlign = parseDisplayAlign(value);
} else if (name == "fontFamily") {
Expand Down
2 changes: 2 additions & 0 deletions subttxrend-ttml/src/Parser/StyleSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class StyleSet

void setStyleId(const std::string& styleId);
void merge(const Attributes& attributes);
void setRegionInfo(const std::string region);

std::string toStr();

Expand All @@ -82,6 +83,7 @@ class StyleSet
DomainValue m_lineHeight{DomainValue::Type::PERCENTAGE_HUNDREDTHS, 100*100};
Outline m_textOutline;
std::string m_styleId;
std::string m_region;
};

std::ostream& operator<<(std::ostream& out, const StyleSet::TextAlign textAlign);
Expand Down
5 changes: 3 additions & 2 deletions subttxrend-ttml/src/TtmlEngineImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void TtmlEngineImpl::clear()

void TtmlEngineImpl::init(const common::ConfigProvider* configProvider,
gfx::Window* gfxWindow,
common::Properties const& properties)
common::Properties const& properties,
const std::string region)
{
m_logger.osinfo(__LOGGER_FUNC__);

Expand All @@ -82,7 +83,7 @@ void TtmlEngineImpl::init(const common::ConfigProvider* configProvider,
createTimingDoc();
}

m_parser = std::make_unique<Parser>();
m_parser = std::make_unique<Parser>(region);
m_renderer = std::make_unique<TtmlRenderer>(configProvider, gfxWindow, m_dataDumper);

m_docTransformer.setProperties(properties);
Expand Down
2 changes: 1 addition & 1 deletion subttxrend-ttml/src/TtmlEngineImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TtmlEngineImpl : public TtmlEngine
/** @copydoc TtmlEngine::init */
virtual void init(const common::ConfigProvider* configProvider,
gfx::Window* gfxEngine,
common::Properties const& properties) override;
common::Properties const& properties, const std::string region) override;

/** @copydoc TtmlEngine::setRelatedVideoSize */
virtual void setRelatedVideoSize(gfx::Size relatedVideoSize) override;
Expand Down