1 - include/AclLog.h
include/AclLog.h
Namespaces
Name |
---|
AclLog A namespace for logging utilities. |
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <string>
namespace AclLog {
enum class Level {
kTrace, // Detailed diagnostics (for development only)
kDebug, // Messages intended for debugging only
kInfo, // Messages about normal behavior (default log level)
kWarning, // Warnings (functionality intact)
kError, // Recoverable errors (functionality impaired)
kCritical, // Unrecoverable errors (application must stop)
kOff // Turns off all logging
};
void init(const std::string& name);
void setLevel(Level level);
} // namespace AclLog
Updated on 2022-06-22 at 16:53:25 +0200
2 - include/AlignedData.h
include/AlignedData.h
Namespaces
Classes
| Name |
---|
struct | AlignedData::DataFrame A frame of aligned data that is passed to the rendering engine from the MediaReceiver. A DataFrame contains a time stamped frame of media, which might be video, audio and auxiliary data such as subtitles. A single DataFrame can contain one or multiple types of media. Which media types are included can be probed by nullptr-checking/size checking the data members. The struct has ownership of all data pointers included. The struct includes all logic for freeing the resources held by this struct and the user should therefore just make sure the struct itself is deallocated to ensure all resources are freed. |
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <array>
#include <iostream>
#include <vector>
#include <cuda_runtime_api.h>
namespace AlignedData {
typedef std::array<float, 16> AudioSampleRow;
enum class CompressedVideoFormat {
kAvc, // H264
kHevc // H265
};
enum class PixelFormat {
kUnknown,
kNv12, // 8 bit per component 4:2:0 YUV format. Y plane followed by interleaved UV plane.
kP016, // 16 bit per component 4:2:0 YUV format. Y plane followed by interleaved UV plane.
kUyvy, // 8 bit per component 4:2:2 YUV format. U-Y-V-Y bytes interleaved.
kRgba, // 8 bit per component RGBA, ordered as R-G-B-A-R-G.. in memory.
kRgba64Le // 16 bit per component RGBA, ordered as R-G-B-A-R-G.. in memory with little endian words.
};
struct DataFrame {
DataFrame() = default;
~DataFrame() {
if (mVideoDataCudaPtr) {
cudaError_t cudaStatus = cudaFree(mVideoDataCudaPtr);
mVideoDataCudaPtr = nullptr;
if (cudaStatus != cudaSuccess) {
std::cout << "AlignedData::~DataFrame: Failed to release cuda memory: " << cudaStatus << std::endl;
}
}
}
DataFrame(DataFrame const&) = delete; // Copy construct
DataFrame& operator=(DataFrame const&) = delete; // Copy assign
uint64_t mPTS;
// Video
uint8_t* mVideoDataCudaPtr = nullptr;
PixelFormat mPixelFormat = PixelFormat::kUnknown;
uint32_t mFrameRateN = 0;
uint32_t mFrameRateD = 0;
uint32_t mWidth = 0;
uint32_t mHeight = 0;
// Audio
std::vector<AudioSampleRow> mAudioData;
uint32_t mAudioChannels = 0;
uint32_t mAudioSamplingFrequency = 0;
};
} // namespace AlignedData
Updated on 2022-06-22 at 16:53:25 +0200
3 - include/Base64.h
include/Base64.h
Functions
| Name |
---|
std::string | encodeBase64(const uint8_t * data, size_t size) Base64 encode some data. |
std::string | encodeBase64(const std::vector< uint8_t > & data) Base64 encode some data. |
std::vector< uint8_t > | decodeBase64(const std::string & data) Decode some Base64 encoded data. |
Functions Documentation
function encodeBase64
std::string encodeBase64(
const uint8_t * data,
size_t size
)
Base64 encode some data.
Parameters:
- data Pointer to the data to encode with Base64
- size The length of the data to encode with Base64
Return: The resulting Base64 encoded string
function encodeBase64
std::string encodeBase64(
const std::vector< uint8_t > & data
)
Base64 encode some data.
Parameters:
- data The data to encode with Base64
Return: The resulting Base64 encoded string
function decodeBase64
std::vector< uint8_t > decodeBase64(
const std::string & data
)
Decode some Base64 encoded data.
Parameters:
- data The Base64 encoded string to decode
Return: The resulting decoded data
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <string>
#include <vector>
std::string encodeBase64(const uint8_t* data, size_t size);
std::string encodeBase64(const std::vector<uint8_t>& data);
std::vector<uint8_t> decodeBase64(const std::string& data);
Updated on 2022-06-22 at 16:53:25 +0200
4 - include/ControlDataCommon.h
include/ControlDataCommon.h
Namespaces
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
namespace ControlDataCommon {
enum class ConnectionType { CONNECTED, DISCONNECTED };
struct ConnectionStatus {
ConnectionStatus() = default;
ConnectionStatus(ConnectionType mConnectionType, const std::string& mIp, uint16_t mPort)
: mConnectionType(mConnectionType)
, mIP(mIp)
, mPort(mPort) {
}
ConnectionType mConnectionType;
std::string mIP;
uint16_t mPort = 0;
};
struct Response {
std::vector<uint8_t> mMessage;
uint64_t mRequestId = 0;
std::string mFromUUID;
};
struct StatusMessage {
std::vector<uint8_t> mMessage;
std::string mFromUUID;
};
} // namespace ControlDataCommon
Updated on 2022-06-22 at 16:53:25 +0200
5 - include/ControlDataReceiver.h
include/ControlDataReceiver.h
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <memory>
#include <ISystemControllerInterface.h>
#include "ControlDataCommon.h"
class ControlDataReceiver final {
public:
struct IncomingRequest {
std::vector<uint8_t> mMessage;
std::string mSenderUUID;
std::string mRequesterUUID;
uint64_t mRequestID = 0;
int64_t mSenderTimestampUs =
0;
int64_t mDeliveryTimestampUs =
0;
};
struct ReceiverResponse {
std::vector<uint8_t> mMessage;
};
struct Settings {
std::function<void(const IncomingRequest&)> mPreviewIncomingRequestCallback;
std::function<ReceiverResponse(const IncomingRequest&)> mIncomingRequestCallback;
std::function<void(const ControlDataCommon::ConnectionStatus&)>
mConnectionStatusCallback;
std::function<void(const ControlDataCommon::Response&)>
mResponseCallback;
};
ControlDataReceiver();
~ControlDataReceiver();
bool configure(const std::shared_ptr<ISystemControllerInterface>& controllerInterface, const Settings& settings);
bool sendStatusMessageToSender(const std::vector<uint8_t>& message);
bool sendRequestToReceivers(const std::vector<uint8_t>& request, uint64_t& requestId);
static std::string getVersion();
static std::string getBuildInfo();
// ControlDataReceiver is not copyable
ControlDataReceiver(ControlDataReceiver const&) = delete; // Copy construct
ControlDataReceiver& operator=(ControlDataReceiver const&) = delete; // Copy assign
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
6 - include/ControlDataSender.h
include/ControlDataSender.h
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include <ISystemControllerInterface.h>
#include "ControlDataCommon.h"
class ControlDataSender final {
public:
struct Settings {
std::function<void(const ControlDataCommon::ConnectionStatus&)>
mConnectionStatusCallback; // Callback for receiver connection/disconnection events
std::function<void(const ControlDataCommon::Response&)>
mResponseCallback; // Callback for response messages from receivers
std::function<void(const ControlDataCommon::StatusMessage&)>
mStatusMessageCallback; // Callback for status messages from receivers
};
ControlDataSender();
~ControlDataSender();
bool configure(const std::shared_ptr<ISystemControllerInterface>& controllerInterface, const Settings& settings);
bool sendRequestToReceivers(const std::vector<uint8_t>& request, uint64_t& requestId);
static std::string getVersion();
static std::string getBuildInfo();
// ControlDataSender is not copyable
ControlDataSender(ControlDataSender const&) = delete; // Copy construct
ControlDataSender& operator=(ControlDataSender const&) = delete; // Copy assign
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
7 - include/IngestApplication.h
include/IngestApplication.h
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <memory>
#include "ISystemControllerInterface.h"
class IngestApplication {
public:
struct Settings {
bool mDebugAudio = false; // Insert a 800 Hz sound at every turn to a new second according to TAI
bool mDebugVideo = false; // Print the timestamp in the picture
};
IngestApplication();
~IngestApplication();
bool start(const std::shared_ptr<ISystemControllerInterface>& controllerInterface, const Settings& settings);
bool stop();
static std::string getVersion();
static std::string getBuildInfo();
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
8 - include/IngestUtils.h
include/IngestUtils.h
Namespaces
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
namespace IngestUtils {
bool isRunningWithRootPrivileges();
} // namespace IngestUtils
Updated on 2022-06-22 at 16:53:25 +0200
9 - include/ISystemControllerInterface.h
include/ISystemControllerInterface.h
Classes
| Name |
---|
class | ISystemControllerInterface An ISystemControllerInterface is the interface between a component and the System controller controlling the component. The interface allows for two-way communication between the component and the system controller by means of sending requests and getting responses. Classes deriving from the ISystemControllerInterface should provide the component side implementation of the communication with the system controller. This interface can be inherited and implemented by developers to connect to custom system controllers, or to directly control a component programmatically, without the need for connecting to a remote server. An ISystemControllerInterface can have a parent-child relationship with other interfaces, where the children are aware of which their parent interface is. This is useful for components that provides extra features for another component, but where the components are still to be considered as two separate entities with separate connections to the System controller. |
struct | ISystemControllerInterface::Response A response to a request, consists of a status code and an (optional) parameters JSON object. |
struct | ISystemControllerInterface::Callbacks A struct containing the callbacks that needs to be registered by the component using this interface. |
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <functional>
#include <json.hpp>
#include <string>
class ISystemControllerInterface {
public:
enum class StatusCode : uint32_t {
SUCCESS = 3001, // Accept / Success
TOO_MANY_REQUESTS = 3101, // Too many requests, try again later
UUID_ALREADY_REGISTERED = 3201, // UUID is already registered
FORMAT_ERROR = 3202, // Message formatting error
ALREADY_CONFIGURED = 3203, // The requested thing to configure is already configured
OUT_OF_RESOURCES = 3204, // Out of resources (CPU/GPU close to max utilization, all available slots used, etc.)
NOT_FOUND = 3205, // The requested thing was not found
INTERNAL_ERROR = 3206, // Internal error when trying to serve the request
CONNECTION_FAILED = 3207, // Connection failure
TIMEOUT_EXCEEDED = 3208, // Timeout exceeded
KEY_MISMATCH = 3209, // Key mismatch (might be a timeout, 3007 in the future)
UNKNOWN_REQUEST = 3210, // The name of the request was not known
MALFORMED_REQUEST = 3211, // The request is not correctly formatted
ALREADY_IN_USE = 3212, // The requested resource is already in use
// None, yet
};
struct Response {
StatusCode mCode;
nlohmann::json mParameters; // Can be empty
};
struct Callbacks {
std::function<Response(const std::string&, const nlohmann::json&)>
mRequestCallback; // Callback called when then controller has sent a request
std::function<void(uint32_t, const std::string&, const std::error_code&)>
mConnectionClosedCallback; // Callback called when the connection to the controller is closed
};
virtual ~ISystemControllerInterface() = default;
virtual Response sendRequest(const std::string& request, const nlohmann::json& parameters) = 0;
virtual bool registerRequestCallback(const Callbacks& callbacks) = 0;
virtual bool connect() = 0;
virtual bool disconnect() = 0;
virtual bool isConnected() const = 0;
virtual std::string getUUID() const = 0;
virtual bool hasParent() const = 0;
virtual std::shared_ptr<ISystemControllerInterface> getParentInterface() const = 0;
};
Updated on 2022-06-22 at 16:53:25 +0200
10 - include/MediaReceiver.h
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <memory>
#include <utility>
#include "AlignedData.h"
#include "ISystemControllerInterface.h"
class MediaReceiver {
public:
struct NewStreamParameters {
uint32_t mVideoHeight = 0; // Height of the video in pixels. 0 if the stream does not contain any video
uint32_t mVideoWidth = 0; // Width of the video in pixels. 0 if the stream does not contain any video
uint32_t mFrameRateN = 0; // Frame rate numerator
uint32_t mFrameRateD = 1; // Frame rate denominator
uint32_t mAudioSampleRate = 0; // Sample rate of the audio in Hz. 0 if the stream does not contain any audio
};
struct Settings {
AlignedData::PixelFormat mDecodedFormat = AlignedData::PixelFormat::kRgba64Le;
std::function<std::function<void(const std::shared_ptr<AlignedData::DataFrame>&)>(
uint32_t inputSlot,
const std::string& streamID,
const NewStreamParameters& newStreamParameters)>
mNewConnectionCallback;
std::function<void(uint32_t inputSlot)> mClosedConnectionCallback;
bool mUseMultiViewer = false;
bool mDebugAudio = false;
bool mDebugVideo = false;
bool mDeliverOld = false;
};
MediaReceiver();
~MediaReceiver();
bool start(const std::shared_ptr<ISystemControllerInterface>& controllerInterface, const Settings& settings);
void stop();
std::function<void(const std::shared_ptr<AlignedData::DataFrame>&)>
getCustomMultiViewSourceInput(uint32_t inputSlot, const std::string& name = "");
MediaReceiver(MediaReceiver const&) = delete; // Copy construct
MediaReceiver(MediaReceiver&&) = delete; // Move construct
MediaReceiver& operator=(MediaReceiver const&) = delete; // Copy assign
MediaReceiver& operator=(MediaReceiver&&) = delete; // Move assign
static std::string getVersion();
static std::string getBuildInfo();
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
11 - include/MediaStreamer.h
Classes
| Name |
---|
class | MediaStreamer MediaStreamer is a class that can take a single stream of uncompressed video and/or audio frames and encode and output it in some way to some interface. This interface can either be a stream to a network or writing down the data to a file on the hard drive. This class is configured from two interfaces. The input configuration (input video resolution, frame rate, pixel format, number of audio channels…) is made through this C++ API. The output stream is then started from the System Controller. Any of these configurations can be made first. The actual stream to output will start once the first call to. |
struct | MediaStreamer::Configuration The input configuration of the frames that will be sent to this MediaStreamer. The output stream configuration is made from the System controller via the ISystemControllerInterface. |
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <memory>
#include <ISystemControllerInterface.h>
#include "AlignedData.h"
class MediaStreamer final {
public:
struct Configuration {
// Video
AlignedData::PixelFormat mIncomingPixelFormat = AlignedData::PixelFormat::kUnknown;
uint32_t mWidth = 0; // Width of the incoming video frames in pixels
uint32_t mHeight = 0; // Height of the incoming video frames in pixels
uint32_t mFrameRateN = 0; // Frame rate numerator of the incoming video frames
uint32_t mFrameRateD = 0; // Frame rate denominator of the incoming video frames
// Audio
uint32_t mAudioSampleRate = 0; // Audio sample rate of the incoming frames in Hz
uint32_t mNumAudioChannels = 0; // Number of audio channels in the incoming frames
};
MediaStreamer();
~MediaStreamer();
bool configure(const std::shared_ptr<ISystemControllerInterface>& controllerInterface);
bool setInputFormatAndStart(const Configuration& configuration);
bool stopAndResetFormat();
bool outputData(const std::shared_ptr<AlignedData::DataFrame>& frame);
static std::string getVersion();
static std::string getBuildInfo();
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
12 - include/SystemControllerConnection.h
include/SystemControllerConnection.h
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <chrono>
#include "ISystemControllerInterface.h"
#include "json.hpp"
class SystemControllerConnection final : public ISystemControllerInterface {
public:
enum class ComponentType : uint32_t {
kIngest,
kMediaReceiver,
kMediaStreamer,
kControlDataReceiver,
kControlDataSender,
};
struct Settings {
std::string mSystemControllerIP; // IP of the server
uint16_t mSystemControllerPort; // Port of the server
std::string mSystemControllerPostfix; // Postfix of the address that the backend uses if any
std::string mPSK; // The pre shared key used for authorization with the system controller server
std::string mUUID; // The UUID of the device using this library
ComponentType mType; // The component type of the component using this SystemControllerConnection
std::string mName; // The component name (optional)
std::string mMyIP; // The external IP of the system the component is running on. Will be sent to the system
// controller server in the announce message (optional)
std::chrono::milliseconds mConnectTimeout{
3000}; // Max time to wait on an announcement response from the server during connection
};
SystemControllerConnection();
~SystemControllerConnection() override;
bool configure(const Settings& settings,
const std::shared_ptr<ISystemControllerInterface>& parentInterface = nullptr);
bool connect() override;
bool isConnected() const override;
std::string getUUID() const override;
Response sendRequest(const std::string& request, const nlohmann::json& parameters) override;
bool disconnect() override;
bool registerRequestCallback(const Callbacks& callbacks) override;
bool hasParent() const override;
std::shared_ptr<ISystemControllerInterface> getParentInterface() const override;
SystemControllerConnection(SystemControllerConnection const&) = delete; // Copy construct
SystemControllerConnection(SystemControllerConnection&&) = delete; // Move construct
SystemControllerConnection& operator=(SystemControllerConnection const&) = delete; // Copy assign
SystemControllerConnection& operator=(SystemControllerConnection&&) = delete; // Move assign
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
Updated on 2022-06-22 at 16:53:25 +0200
13 - include/TimeCommon.h
include/TimeCommon.h
Namespaces
Classes
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <chrono>
#include <cstdint>
#include <fstream>
#include <sstream>
namespace TimeCommon {
enum class StratumLevel {
UnknownStratum,
stratum0,
stratum1,
stratum2,
stratum3,
stratum4,
};
struct TAIStatus {
StratumLevel mStratum = StratumLevel::UnknownStratum;
bool mHasLock = false;
};
// Little endian
// Minimum size packet is 64 - bytes
struct TimeStructure {
uint64_t t1 = 0; // 8-bytes / Total 8-bytes == Client time T1
uint64_t t2 = 0; // 8-bytes / Total 16-bytes == Server
uint64_t t3 = 0; // 8-bytes / Total 24-bytes
uint64_t t4 = 0; // 8-bytes / Total 32-bytes
uint64_t token = 0; // 8-bytes / Total 40-bytes == t1 ^ key
uint64_t dummy1 = 0; // 8-bytes / Total 48-bytes == for future use
uint64_t dummy2 = 0; // 8-bytes / Total 56-bytes == for future use
uint64_t dummy3 = 0; // 8-bytes / Total 64-bytes == for future use
};
uint64_t getMonotonicClockMicro();
TimeCommon::TAIStatus getStatus();
int64_t getTAIMicro();
} // namespace TimeCommon
Updated on 2022-06-22 at 16:53:25 +0200
14 - include/UUIDUtils.h
include/UUIDUtils.h
Namespaces
Name |
---|
UUIDUtils A namespace for UUID utility functions. |
Source code
// Copyright (c) 2022, Edgeware AB. All rights reserved.
#pragma once
#include <string>
namespace UUIDUtils {
std::string generateRandomUUID();
bool isValidUUIDString(const std::string& uuid);
} // namespace UUIDUtils
Updated on 2022-06-22 at 16:53:25 +0200