Skip to content

Commit

Permalink
3.11.3-alpha.PM-1561.7
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeCB committed Sep 16, 2023
1 parent 421b6fb commit 068e556
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 99 deletions.
2 changes: 1 addition & 1 deletion node/lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Worker extends EnhancedEventEmitter_1.EnhancedEventEmitter {
// options
{
env: {
MEDIASOUP_VERSION: '3.11.3-alpha.PM-1561.6',
MEDIASOUP_VERSION: '3.11.3-alpha.PM-1561.7',
// Let the worker process inherit all environment variables, useful
// if a custom and not in the path GCC is used so the user can set
// LD_LIBRARY_PATH environment variable for runtime.
Expand Down
2 changes: 1 addition & 1 deletion node/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { types };
/**
* Expose mediasoup version.
*/
export declare const version = "3.11.3-alpha.PM-1561.6";
export declare const version = "3.11.3-alpha.PM-1561.7";
/**
* Expose parseScalabilityMode() function.
*/
Expand Down
2 changes: 1 addition & 1 deletion node/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.types = types;
/**
* Expose mediasoup version.
*/
exports.version = '3.11.3-alpha.PM-1561.6';
exports.version = '3.11.3-alpha.PM-1561.7';
/**
* Expose parseScalabilityMode() function.
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@livelyvideo/mediasoup",
"version": "3.11.3-alpha.PM-1561.6",
"version": "3.11.3-alpha.PM-1561.7",
"description": "Cutting Edge WebRTC Video Conferencing",
"contributors": [
"Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)",
Expand Down
5 changes: 3 additions & 2 deletions worker/include/LivelyBinLogs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <functional>

#define BINLOG_MIN_TIMESPAN 20000
#define BINLOG_FORMAT_VERSION "3b55f9"
#define BINLOG_FORMAT_VERSION "421b6f"
//"c1b126"

// CALL_STATS_BIN_LOG_CONS_REC_NUM * sizeof(CallStatsSample)
Expand Down Expand Up @@ -201,7 +201,7 @@ class CallStatsRecord

bool IsInitialized() {return initialized;}
void InitLog(char type, std::string id1, std::string id2); // if type is producer, then log name is a combo of callid, producerid and timestamp
void InitLogNew(std::function<std::string(uint64_t)>&& templateFunction);
void InitLog(std::function<std::string(uint64_t)>&& templateFunction);
// void InitLogNew2(std::string fileNameTemplate);
int OnLogWrite(CallStatsRecordCtx* ctx);
void DeinitLog(); // Closes log file and deinitializes state variables
Expand All @@ -222,6 +222,7 @@ class CallStatsRecord
);

std::string ConsumerFileName(const std::string& callId, uint64_t timestamp, const std::string& version);
std::string GetUserIdFromAppData(const json& appData);

} //Lively

Expand Down
118 changes: 40 additions & 78 deletions worker/src/LivelyBinLogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ CallStatsRecord::CallStatsRecord(uint64_t type, uint16_t ssrc, uint8_t payload,
record.c.content = content;
std::memset(record.c.consumer_id, 0, UUID_BYTE_LEN);
uuidToBytes(obj, record.c.consumer_id);

std::memset(record.c.producer_id, 0, UUID_BYTE_LEN);
uuidToBytes(producer, record.c.producer_id);

std::memset(record.c.samples, 0, sizeof(record.c.samples));

MS_DEBUG_TAG(rtp, "CallStatsRecord ctor(): consumer start_tm=%" PRIu64 " ssrc=%" PRIu16 " payload=%" PRIu8 " type=%c callId=%s consumerId=%s producerId=%s",
MS_DEBUG_TAG(rtp, "CallStatsRecord ctor(): consumer start_tm=%" PRIu64 " ssrc=%" PRIu16 " payload=%" PRIu8 " type=%c callId=%s consumerId=%s producerId=%s",
ts, ssrc, payload, content, call_id.c_str(), object_id.c_str(), producer_id.c_str());
}
else // producer
Expand All @@ -64,7 +64,7 @@ CallStatsRecord::CallStatsRecord(uint64_t type, uint16_t ssrc, uint8_t payload,
record.p.content = content;
std::memset(record.p.samples, 0, sizeof(record.p.samples));

MS_DEBUG_TAG(rtp, "CallStatsRecord ctor(): producer start_tm=%" PRIu64 " ssrc=%" PRIu16 " payload=%" PRIu8 " type=%c callId=%s producerId=%s",
MS_DEBUG_TAG(rtp, "CallStatsRecord ctor(): producer start_tm=%" PRIu64 " ssrc=%" PRIu16 " payload=%" PRIu8 " type=%c callId=%s producerId=%s",
ts, ssrc, payload, content, call_id.c_str(), object_id.c_str());
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ bool CallStatsRecord::addSample(StreamStats& last, StreamStats& curr)

MS_ASSERT(last.ts != UINT64_UNSET,
"Timestamp of a previous sample is unset, quitting...");

MS_ASSERT(curr.ts != UINT64_UNSET,
"Timestamp of a current sample is unset, quitting...");

Expand Down Expand Up @@ -167,7 +167,7 @@ bool CallStatsRecord::addSample(StreamStats& last, StreamStats& curr)
bool CallStatsRecord::isPktCountZero() const
{
if (filled() < maxSamples())
{
{
return false; // can be true only for full collection of samples
}

Expand Down Expand Up @@ -295,12 +295,12 @@ void StatsBinLog::LogClose()
return;

// Do not preserve binlogs with too little data
if (log_start_ts == UINT64_UNSET
|| log_last_ts == UINT64_UNSET
if (log_start_ts == UINT64_UNSET
|| log_last_ts == UINT64_UNSET
|| BINLOG_MIN_TIMESPAN > log_last_ts - log_start_ts)
{
std::remove(bin_log_file_path.c_str());
MS_DEBUG_TAG(rtp, "binlog %s removed, short timespan (%" PRIu64 "-%" PRIu64 ")",
MS_DEBUG_TAG(rtp, "binlog %s removed, short timespan (%" PRIu64 "-%" PRIu64 ")",
this->bin_log_file_path.c_str(), this->log_start_ts, log_last_ts);
return;
}
Expand All @@ -323,7 +323,7 @@ void StatsBinLog::LogClose()
Settings::configuration.logBinStatsPath.c_str(),
logname.c_str(),
now/1000);

if (!CreateBinlogDirsIfMissing() || std::rename(this->bin_log_file_path.c_str(), tmp))
{
MS_WARN_TAG(rtp, "failed to move %s to %s", this->bin_log_file_path.c_str(), tmp);
Expand Down Expand Up @@ -410,13 +410,13 @@ bool StatsBinLog::CreateBinlogDirsIfMissing()
std::string bin_log_dir = Settings::configuration.logBinStatsPath + "/bin/";
std::string bin_log_curr_dir = Settings::configuration.logBinStatsPath + "/bin/current/";
std::string bin_log_done_dir = Settings::configuration.logBinStatsPath + "/bin/done/";

struct stat info;
int ret = 0;

if (Settings::configuration.logBinStatsDisabled)
return false;

if( stat( Settings::configuration.logBinStatsPath.c_str(), &info ) != 0 )
{
if (errno == ENOENT)
Expand Down Expand Up @@ -551,23 +551,8 @@ std::string GenerateLogFormatString(char type, const std::string& id1, const std
return tmp;
}

//todo check compatibility with current filename parser
std::string ProducerFileName(
const std::string &callId,
const std::string &producerId,
const std::string &userId,
uint64_t timestamp,
const std::string &version
) {
return "ms_p_" + callId + "_" + producerId + "_" + userId + "_" + std::to_string(timestamp) + "." + version + ".bin";
}

std::string ConsumerFileName(const std::string& callId, uint64_t timestamp, const std::string& version) {
return "ms_c_" + callId + "_" + std::to_string(timestamp) + "." + version + ".bin";
}

//todo add back total filepath size check
void StatsBinLog::InitLogNew(std::function<std::string(uint64_t)>&& templateFunction)
void StatsBinLog::InitLog(std::function<std::string(uint64_t)>&& templateFunction)
{
this->initialized = false;

Expand All @@ -580,13 +565,7 @@ void StatsBinLog::InitLogNew(std::function<std::string(uint64_t)>&& templateFunc
uint64_t const now = Utils::Time::currentStdEpochMs();
UpdateLogTimestamps(now);



//sizeof("/var/log/sfu/bin/current/ms_p_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000_1652210519459.123abc.bin") * 2
// char tmp[FILENAME_LEN_MAX];
// std::memset(tmp, '\0', FILENAME_LEN_MAX);

MS_DEBUG_TAG(rtp, "consumers binlog %s", this->current_bin_log_name.c_str());
MS_DEBUG_TAG(rtp, "binlog %s", this->current_bin_log_name.c_str());

CreateBinlogDirsIfMissing();
if (Settings::configuration.logBinStatsDisabled)
Expand All @@ -596,49 +575,6 @@ void StatsBinLog::InitLogNew(std::function<std::string(uint64_t)>&& templateFunc
this->initialized = true;
}

void StatsBinLog::InitLog(char type, std::string id1, std::string id2)
{
this->initialized = false;

if (Settings::configuration.logBinStatsDisabled)
return;


//sizeof("/var/log/sfu/bin/current/ms_p_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000_1652210519459.123abc.bin") * 2
char tmp[FILENAME_LEN_MAX];
std::memset(tmp, '\0', FILENAME_LEN_MAX);

switch(type)
{
case 'c':
sprintf(tmp,
"%s/bin/current/ms_c_%s_%%llu.%s.bin",
Settings::configuration.logBinStatsPath.c_str(), id1.c_str(), version);
this->bin_log_name_template.assign(tmp);
MS_DEBUG_TAG(rtp, "consumers binlog %s [transportId: %s]", this->bin_log_name_template.c_str(), id2.c_str());
break;
case 'p':
sprintf(tmp,
"%s/bin/current/ms_p_%s_%s_%%llu.%s.bin",
Settings::configuration.logBinStatsPath.c_str(), id1.c_str(), id2.c_str(), version);
this->bin_log_name_template.assign(tmp);
MS_DEBUG_TAG(rtp, "producer binlog %s", this->bin_log_name_template.c_str());
break;
default:
break;
}

uint64_t now = Utils::Time::currentStdEpochMs();
UpdateLogTimestamps(now);

CreateBinlogDirsIfMissing();
if (Settings::configuration.logBinStatsDisabled)
return;

this->sampling_interval = CALL_STATS_BIN_LOG_SAMPLING;
this->initialized = true;
}


void StatsBinLog::UpdateLogTimestamps(uint64_t now)
{
Expand All @@ -661,7 +597,7 @@ void StatsBinLog::DeinitLog()
LogClose();

this->initialized = false;

this->log_start_ts = UINT64_UNSET;
this->next_day_start_ts = UINT64_UNSET;
this->log_last_ts = UINT64_UNSET;
Expand All @@ -672,6 +608,32 @@ void StatsBinLog::DeinitLog()
this->bin_log_file_path.clear();
}

std::string GetUserIdFromAppData(const json& appData) {
if (appData.contains("userId") && appData["userId"].is_string()) {
return appData["userId"].get<std::string>();
}
if (appData.contains("displayName") && appData["displayName"].is_string()) {
return appData["displayName"].get<std::string>();
}
// if (appData.contains("peerId") && appData["peerId"].is_string()) {
// return appData["peerId"].get<std::string>();
// }
return "";
}

//todo check compatibility with current filename parser
std::string ProducerFileName(
const std::string &callId,
const std::string &producerId,
const std::string &userId,
uint64_t timestamp,
const std::string &version
) {
return "ms_p_" + callId + "_" + producerId + "_" + userId + "_" + std::to_string(timestamp) + "." + version + ".bin";
}

std::string ConsumerFileName(const std::string& callId, uint64_t timestamp, const std::string& version) {
return "ms_c_" + callId + "_" + std::to_string(timestamp) + "." + version + ".bin";
}

} //Lively
15 changes: 3 additions & 12 deletions worker/src/RTC/Producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,13 @@ namespace RTC

std::string userId;
if (data.contains("appData")) {
auto& rAppData = data["appData"];

if (rAppData.contains("userId") && rAppData["userId"].is_string()) {
userId = rAppData["userId"];
} else if (rAppData.contains("displayName") && rAppData["displayName"].is_string()) {
userId = rAppData["displayName"];
} else if (rAppData.contains("peerId") && rAppData["peerId"].is_string()) {
userId = rAppData["peerId"];
} else {
userId = callId;
}
json const& rAppData = data["appData"];
userId = Lively::GetUserIdFromAppData(rAppData);
} else {
userId = callId;
}

this->binLog.InitLogNew([callId, producerId, userId](uint64_t timestamp) -> std::string {
this->binLog.InitLog([callId, producerId, userId](uint64_t timestamp) -> std::string {
return Lively::ProducerFileName(callId, producerId, userId, timestamp, BINLOG_FORMAT_VERSION);
});
}
Expand Down
4 changes: 2 additions & 2 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ namespace RTC

std::string const callId = lively.callId;

this->consumersBinLog.InitLogNew([callId](uint64_t timestamp) -> std::string {
return Lively::ConsumerFileName(callId,timestamp, BINLOG_FORMAT_VERSION);
this->consumersBinLog.InitLog([callId](uint64_t timestamp) -> std::string {
return Lively::ConsumerFileName(callId, timestamp, BINLOG_FORMAT_VERSION);
});
}
else
Expand Down
18 changes: 17 additions & 1 deletion worker/test/src/TestLivelyBinLogs.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
#include <catch2/catch.hpp>
#include "LivelyBinLogs.hpp"

using namespace Utils;
SCENARIO("Grab userId from appData with userId")
{
std::string jsonString = R"({"callId":"6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad","displayName":"display6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad","iceConnected":true,"orientation":"landscape-primary","peerId":"8A46F3E0541B11EEBC973176C12C8EFA","streamName":"demo","trackEnabled":true,"userId":"6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad"})";
auto appData = nlohmann::json::parse(jsonString);
std::string userId = Lively::GetUserIdFromAppData(appData);

REQUIRE(userId == "6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad");
}

SCENARIO("Grab userId from appData with no userId, displayName")
{
std::string jsonString = R"({"callId":"6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad","displayName":"display6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad","iceConnected":true,"orientation":"landscape-primary","peerId":"8A46F3E0541B11EEBC973176C12C8EFA","streamName":"demo","trackEnabled":true})";
auto appData = nlohmann::json::parse(jsonString);
std::string userId = Lively::GetUserIdFromAppData(appData);

REQUIRE(userId == "display6d7fb685-0215-4f8a-af3a-29d5d4c1b7ad");
}

SCENARIO("Producer binlog file names are created correctly.")
{
Expand Down

0 comments on commit 068e556

Please sign in to comment.