Skip to content
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

store app data by shm transport when shm segment is created #16

Merged
merged 6 commits into from
Sep 10, 2021
Merged
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
5 changes: 3 additions & 2 deletions lib/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
* @async
* @returns {ShmTransport}
*/
async createShmTransport({ listenIp, shm, log, appData = {} }) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave appData an object for consistency with other similar transport creating APIs. We assume that it is an object and it may contain information about callId, peerId, streamName and mirrorId. I am testing the branch where I actually pick that data in shm and add into logs.
If you are passing a special string for shm apps it would be better to add it under shm object (the 2nd param in this function).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, will do

async createShmTransport({ listenIp, shm, log, appData = '' }) {
logger.debug('createShmTransport() [shm:%o]', shm);
if (!listenIp)
throw new TypeError('missing listenIp');
Expand Down Expand Up @@ -407,7 +407,8 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
shm: {
name: "...",
log: "...",
status: "..."
status: "...",
shmAppData: "..."
}
}
*/
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@livelyvideo/mediasoup",
"version": "3.8.3-lv2",
"version": "3.8.3-lv2-shm-app-data-2",
"description": "Cutting Edge WebRTC Video Conferencing",
"contributors": [
"Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)",
Expand Down Expand Up @@ -56,12 +56,12 @@
"netstring": "^0.3.0",
"random-number": "^0.0.9",
"supports-color": "^9.0.2",
"uuid": "^8.3.2"
"uuid": "^7.0.3"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/random-number": "^0.0.1",
"@types/uuid": "^8.3.1",
"@types/uuid": "^7.0.3",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"cross-env": "^7.0.3",
Expand All @@ -76,4 +76,3 @@
"typescript": "~3.8.3"
}
}

5 changes: 3 additions & 2 deletions src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ export class Router extends EnhancedEventEmitter
listenIp,
shm,
log,
appData = {}
appData = ''
} : ShmTransportOptions
): Promise<ShmTransport>
{
Expand Down Expand Up @@ -747,7 +747,8 @@ export class Router extends EnhancedEventEmitter
shm: {
name: "...",
log: "...",
status: "..."
status: "...",
shmAppData: "..."
}
}
*/
Expand Down
2 changes: 1 addition & 1 deletion worker/include/DepLibSfuShm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace DepLibSfuShm

static uint8_t* hex_dump(uint8_t *dst, uint8_t *src, size_t len);

void InitializeShmWriterCtx(std::string shm, int queueAge, bool useReverse, int testNack, std::string log, int level);
void InitializeShmWriterCtx(std::string shm, int queueAge, bool useReverse, int testNack, std::string log, int level, std::string shmAppData);
void CloseShmWriterCtx();

std::string StreamName() const { return this->stream_name; }
Expand Down
11 changes: 9 additions & 2 deletions worker/src/DepLibSfuShm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace DepLibSfuShm {
}


void ShmCtx::InitializeShmWriterCtx(std::string shm, int queueAge, bool useReverse, int testNack, std::string log, int level)
void ShmCtx::InitializeShmWriterCtx(std::string shm, int queueAge, bool useReverse, int testNack, std::string log, int level, std::string shmAppData)
{
MS_TRACE();

Expand All @@ -93,6 +93,13 @@ namespace DepLibSfuShm {
wrt_init.conf.log_file_name = log_name.c_str();
wrt_init.conf.log_level = level;
wrt_init.conf.redirect_stdio = false;

// application data. This is an opaque string that is stored in the shared
// memory for application level usage e.g. xcode internal controller
if (shmAppData.length() > 0) {
wrt_init.app_data = const_cast<char*>(shmAppData.c_str());
wrt_init.conf.app_data_sz = shmAppData.length() + 1; // reserve space for null terminator
}

// TODO: if needed, target_kbps may be passed as config param instead
// and codec_id, sample_rate may be read from ShmConsumer in the same way as in ShmConsumer::CreateRtpStream()
Expand Down Expand Up @@ -727,4 +734,4 @@ namespace DepLibSfuShm {
if (IsError(err))
MS_WARN_TAG(xcode, "shm[%s] error writing video rotation: %d - %s", this->stream_name.c_str(), err, GetErrorString(err));
}
} // namespace DepLibSfuShm
} // namespace DepLibSfuShm
9 changes: 8 additions & 1 deletion worker/src/RTC/ShmTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ namespace RTC
useReverse = (jsonReverseIt->get<int>() != 0) ? true : false;
}

// Read shmAppData
std::string shmAppData;
auto shmAppDataIt = jsonShmIt->find("shmAppData");
if (shmAppDataIt != jsonShmIt->end() && shmAppDataIt->is_string()) {
shmAppData.assign(shmAppDataIt->get<std::string>());
}

// ngxshm log name and level
auto jsonLogIt = data.find("log");
if (jsonLogIt == data.end())
Expand Down Expand Up @@ -134,7 +141,7 @@ namespace RTC
this->listenIp.announcedIp.assign(jsonAnnouncedIpIt->get<std::string>());
}

this->shmCtx.InitializeShmWriterCtx(shm, queueAge, useReverse, testNack, logname /* + "." + shm + "." + this->id */, loglevel);
this->shmCtx.InitializeShmWriterCtx(shm, queueAge, useReverse, testNack, logname /* + "." + shm + "." + this->id */, loglevel, shmAppData);
}

ShmTransport::~ShmTransport()
Expand Down