Skip to content

Commit

Permalink
ONEM-38082: Redesigned telemetry module
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-mielczarczyk-red committed Dec 9, 2024
1 parent afa6c7d commit 675a7a1
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 294 deletions.
25 changes: 15 additions & 10 deletions Source/ThirdParty/telemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(TELEMETRY_DIR "${THIRDPARTY_DIR}/telemetry")

set(TELEMETRY_INCLUDE_DIRECTORIES
"${TELEMETRY_DIR}/src"
"${TELEMETRY_DIR}/include"
"${CMAKE_BINARY_DIR}"
)

set(TELEMETRY_SOURCES
${TELEMETRY_DIR}/src/TelemetryReport.cpp
)

include_directories("${TELEMETRY_INCLUDE_DIRECTORIES}")

if (USE_RDK_TELEMETRY)
Expand All @@ -24,15 +20,24 @@ if (USE_RDK_TELEMETRY)
endif ()

include_directories(
${OdhErrTelemetry_INCLUDE_DIR}
${OdhOttTelemetry_INCLUDE_DIR}
${OdhErrTelemetry_INCLUDE_DIR}
${OdhOttTelemetry_INCLUDE_DIR}
)

set(TELEMETRY_LIBRARIES
${OdhErrTelemetry_LIBRARIES}
${OdhOttTelemetry_LIBRARIES}
${OdhErrTelemetry_LIBRARIES}
${OdhOttTelemetry_LIBRARIES}
)

set(TELEMETRY_SOURCES
${TELEMETRY_DIR}/src/RdkTelemetryReport.cpp
)

add_definitions(-DUSE_RDK_TELEMETRY)
else ()
set(TELEMETRY_SOURCES
${TELEMETRY_DIR}/src/DummyTelemetryReport.cpp
)
add_definitions(-DUSE_RDK_TELEMETRY)
endif ()

add_library(telemetry STATIC ${TELEMETRY_SOURCES})
Expand Down
25 changes: 25 additions & 0 deletions Source/ThirdParty/telemetry/include/DummyTelemetryReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "ITelemetry.h"

namespace Telemetry {

class DummyTelemetryReport: public ITelemetry {

public:
DummyTelemetryReport(std::string &name);
~DummyTelemetryReport();
void reportPlaybackState(
AVPipelineState state,
const std::string &additionalInfo,
MediaType mediaType) override;
void reportDrmInfo(
DrmType drmType,
const std::string &additionalInfo) override;
void reportWaylandInfo(
const WaylandInfoGetter &getter,
WaylandAction action,
WaylandGraphicsState gfxState,
WaylandInputsState inputsState) override;
};
}
75 changes: 75 additions & 0 deletions Source/ThirdParty/telemetry/include/ITelemetry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include <string>

namespace Telemetry {

class ITelemetry
{
public:
enum class AVPipelineState {
CREATE,
PLAY,
PAUSE,
STOP,
DESTROY,
FIRST_FRAME_DECODED,
END_OF_STREAM,
DECRYPT_ERROR,
PLAYBACK_ERROR,
DRM_ERROR,
ERROR,
SEEK_START,
SEEK_DONE,
VIDEO_RESOLUTION_CHANGED,
UNKNOWN
};

enum class MediaType {
AUDIO,
VIDEO,
NONE
};

enum class DrmType {
PLAYREADY,
WIDEVINE,
NONE,
UNKNOWN
};

enum class WaylandAction
{
INIT_GFX,
DEINIT_GFX,
INIT_INPUTS,
DEINIT_INPUTS
};

enum class WaylandGraphicsState
{
GFX_NOT_INITIALIZED,
GFX_INITIALIZED
};

enum class WaylandInputsState
{
INPUTS_NOT_INITIALIZED,
INPUTS_INITIALIZED
};

virtual ~ITelemetry() = default;
virtual void reportPlaybackState(
AVPipelineState state,
const std::string &additionalInfo = "",
MediaType mediaType = MediaType::NONE) = 0;
virtual void reportDrmInfo(
DrmType drmType,
const std::string &additionalInfo = "") = 0;
virtual void reportWaylandInfo(
const WaylandInfoGetter &getter,
WaylandAction action,
WaylandGraphicsState gfxState,
WaylandInputsState inputsState) = 0;
};
}
26 changes: 26 additions & 0 deletions Source/ThirdParty/telemetry/include/RdkTelemetryReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <string>
#include "ITelemetry.h"

namespace Telemetry {

class RdkTelemetryReport: public ITelemetry {

public:
RdkTelemetryReport(std::string &name);
~RdkTelemetryReport();
void reportPlaybackState(
AVPipelineState state,
const std::string &additionalInfo,
MediaType mediaType) override;
void reportDrmInfo(
DrmType drmType,
const std::string &additionalInfo) override;
void reportWaylandInfo(
const WaylandInfoGetter &getter,
WaylandAction action,
WaylandGraphicsState gfxState,
WaylandInputsState inputsState) override;
};
}
43 changes: 43 additions & 0 deletions Source/ThirdParty/telemetry/include/TelemetryReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <stdarg.h>

namespace Telemetry
{
/*
* Don't include:
* #include <EGL/egl.h>
* #include <EGL/eglplatform.h>
* since there are import order issues.
* Defining needed types as void*, like WebKit does.
*/
typedef void *EGLConfig;
typedef void *EGLContext;
typedef void *EGLDisplay;
typedef void *EGLSurface;

/*
* Helper function to get some telemetry data from Wayland.
*/
class WaylandInfoGetter {
public:
virtual EGLDisplay getEGLDisplay() const = 0;
virtual EGLConfig getEGLConfig() const = 0;
virtual EGLSurface getEGLSurface() const = 0;
virtual EGLContext getEGLContext() const = 0;
virtual unsigned int getWindowWidth() const = 0;
virtual unsigned int getWindowHeight() const = 0;
};

void reportErrorV(const char* file, int line, const char* function, const char* format, va_list args);
void reportError(const char* file, int line, const char* function, const char* format, ...);
}

#if defined(USE_RDK_TELEMETRY)
#include "RdkTelemetryReport.h"
using TelemetryImpl = Telemetry::RdkTelemetryReport;
#else
// #error "DummyTelemetry used!"
// #include "DummyTelemetryReport.h"
// using TelemetryImpl = DummyTelemetryReport;
#endif
28 changes: 28 additions & 0 deletions Source/ThirdParty/telemetry/src/DummyTelemetryReport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "TelemetryReport.h"

namespace Telemetry {

void Telemetry::reportErrorV(const char* file, int line, const char* function, const char* format, va_list args) {
}

void Telemetry::reportError(const char* file, int line, const char* function, const char* format, ...) {
}

void DummyTelemetryReport::reportPlaybackState(
AVPipelineState state,
const std::string &additionalInfo,
MediaType mediaType) {
}

void DummyTelemetryReport::reportDrmInfo(
DrmType drmType,
const std::string &additionalInfo) {
}

void DummyTelemetryReport::reportWaylandInfo(
const WaylandInfoGetter &getter,
WaylandAction action,
WaylandGraphicsState gfxState,
WaylandInputsState inputsState) {
}
}
131 changes: 131 additions & 0 deletions Source/ThirdParty/telemetry/src/RdkTelemetryReport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <map>
#include <string>
#include <cstdarg>

#include "TelemetryReport.h"
#include "av_pipeline.h"
#include "odhott_wl.h"
#include "odherr_ctx.h"

namespace AVP = OttReports::AvPipeline;

namespace Telemetry {

static AVP::AvPipeline avPipelineReport{OttReports::Owner::type::Wpe};

void reportErrorV(const char* file, int line, const char* function, const char* format, va_list args)
{
int length = vsnprintf(NULL, 0, format, args);
if (length < 0) return;

char *msg = (char*)malloc(length + 1);
if (!msg) return;

vsnprintf(msg, length + 1, format, args);

char* backtrace = odh_error_report_sprintf("%s:%d %s", file, line, function);
char* ctx = odh_ctx_create_json("wpe", "ss",
"function", function,
"file", file);
odh_error_report_send_v3(ODH_ERROR_REPORT_SENSITIVITY_NONSENSITIVE,
ODH_ERROR_REPORT_LEVEL_ERROR,
"WPE0050",
nullptr,
msg,
ctx,
backtrace,
"browser");
free(ctx);
free(backtrace);
free(msg);
}

void reportError(const char* file, int line, const char* function, const char* format, ...)
{
va_list args;
va_start(args, format);
reportErrorV(file, line, function, format, args);
va_end(args);
}

static std::map<ITelemetry::AVPipelineState, AVP::State::type> pipelineStateMap {
{ITelemetry::AVPipelineState::CREATE, AVP::State::type::Create},
{ITelemetry::AVPipelineState::PLAY, AVP::State::type::Play},
{ITelemetry::AVPipelineState::PAUSE, AVP::State::type::Pause},
{ITelemetry::AVPipelineState::STOP, AVP::State::type::Stop},
{ITelemetry::AVPipelineState::DESTROY, AVP::State::type::Destroy},
{ITelemetry::AVPipelineState::FIRST_FRAME_DECODED, AVP::State::type::FirstFrameDecoded},
{ITelemetry::AVPipelineState::END_OF_STREAM, AVP::State::type::EndOfStream},
{ITelemetry::AVPipelineState::DECRYPT_ERROR, AVP::State::type::DecryptError},
{ITelemetry::AVPipelineState::PLAYBACK_ERROR, AVP::State::type::PlaybackError},
{ITelemetry::AVPipelineState::DRM_ERROR, AVP::State::type::DrmError},
{ITelemetry::AVPipelineState::ERROR, AVP::State::type::Error},
{ITelemetry::AVPipelineState::SEEK_START, AVP::State::type::SeekStart},
{ITelemetry::AVPipelineState::SEEK_DONE, AVP::State::type::SeekDone},
{ITelemetry::AVPipelineState::VIDEO_RESOLUTION_CHANGED, AVP::State::type::VideoResolutionChanged},
{ITelemetry::AVPipelineState::UNKNOWN, AVP::State::type::Unknown}
};

static std::map<ITelemetry::DrmType, AVP::Drm::type> drmTypeMap {
{ITelemetry::DrmType::PLAYREADY, AVP::Drm::type::Playready},
{ITelemetry::DrmType::WIDEVINE, AVP::Drm::type::Widevine},
{ITelemetry::DrmType::NONE, AVP::Drm::type::None},
{ITelemetry::DrmType::UNKNOWN, AVP::Drm::type::Unknown},
};

static std::map<ITelemetry::WaylandAction, odh_report_wayland_action_t> waylandActionMap {
{ITelemetry::WaylandAction::INIT_GFX , odh_report_wayland_action_t::ODH_REPORT_WAYLAND_ACTION_INIT_GFX},
{ITelemetry::WaylandAction::DEINIT_GFX, odh_report_wayland_action_t::ODH_REPORT_WAYLAND_ACTION_DEINIT_GFX},
{ITelemetry::WaylandAction::INIT_INPUTS, odh_report_wayland_action_t::ODH_REPORT_WAYLAND_ACTION_INIT_INPUTS},
{ITelemetry::WaylandAction::DEINIT_INPUTS, odh_report_wayland_action_t::ODH_REPORT_WAYLAND_ACTION_DEINIT_INPUTS}
};

static std::map<ITelemetry::WaylandGraphicsState, bool> waylandGraphicsStateMap {
{ITelemetry::WaylandGraphicsState::GFX_NOT_INITIALIZED, false},
{ITelemetry::WaylandGraphicsState::GFX_INITIALIZED, true}
};

static std::map<ITelemetry::WaylandInputsState, bool> waylandInputsStateMap {
{ITelemetry::WaylandInputsState::INPUTS_NOT_INITIALIZED, false},
{ITelemetry::WaylandInputsState::INPUTS_INITIALIZED, true}
};

RdkTelemetryReport::RdkTelemetryReport(std::string &name) {
odh_error_report_init(name.c_str());
}

RdkTelemetryReport::~RdkTelemetryReport() {
odh_error_report_deinit(ODH_ERROR_REPORT_DEINIT_MODE_DEFERRED);
}

void RdkTelemetryReport::reportPlaybackState(
ITelemetry::AVPipelineState state,
const std::string &additionalInfo,
MediaType mediaType) {
avPipelineReport.setSource(AVP::Source::type::Unknown);
avPipelineReport.setAdditionalInfo(additionalInfo.empty() ? "" : additionalInfo);
avPipelineReport.send(pipelineStateMap[state]);
}

void RdkTelemetryReport::reportDrmInfo(
ITelemetry::DrmType drmType,
const std::string &additionalInfo) {
avPipelineReport.setDrm(drmTypeMap[drmType]);
avPipelineReport.setSource(AVP::Source::type::Unknown);
avPipelineReport.setAdditionalInfo(additionalInfo.empty() ? "" : additionalInfo);
avPipelineReport.send(AVP::State::type::Unknown);
}

void RdkTelemetryReport::reportWaylandInfo(
const WaylandInfoGetter &getter,
ITelemetry::WaylandAction action,
ITelemetry::WaylandGraphicsState gfxState,
ITelemetry::WaylandInputsState inputsState) {
odh_ott_wayland_report(
reinterpret_cast<const WaylandContextInfoGetter&>(getter),
ODH_REPORT_WAYLAND_OWNER_WPE,
waylandActionMap[action],
waylandGraphicsStateMap[gfxState],
waylandInputsStateMap[inputsState]);
}
}
Loading

0 comments on commit 675a7a1

Please sign in to comment.