Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
be16bb5
build for win
haiyangwu Aug 26, 2019
e9ee7c3
code style
haiyangwu Aug 26, 2019
27c1307
code style
haiyangwu Aug 26, 2019
f2b060e
scripts
haiyangwu Aug 26, 2019
8de983a
replace duplex pipe with two pipe
haiyangwu Aug 29, 2019
3e57e56
code style
haiyangwu Aug 29, 2019
12b6a3c
add explicit key word
haiyangwu Aug 30, 2019
283351a
move getopt to deps
haiyangwu Aug 30, 2019
9cd71b3
Merge remote-tracking branch 'versatica/v3' into v3. Fix typo
haiyangwu Aug 30, 2019
a15863c
single quotes
haiyangwu Aug 30, 2019
b86a32f
pyc explicit path
haiyangwu Aug 30, 2019
9a66008
delete unused dep
haiyangwu Aug 30, 2019
c20fb5b
log text & code style
haiyangwu Aug 30, 2019
850761f
rename SocketRole to role
haiyangwu Aug 30, 2019
6a1a927
log text & code style
haiyangwu Aug 30, 2019
af693c4
replace _MSC_VER with _WIN32 for better compatibility
haiyangwu Aug 30, 2019
d3f3a4c
add public keyword to separate method and var
haiyangwu Aug 30, 2019
cbc1b1d
Generate sln under worker directory for unifying test:woker logic
haiyangwu Aug 30, 2019
e489d3b
add "getopt" entry in worker/scripts/get-dep.sh
haiyangwu Sep 1, 2019
793900d
code style
haiyangwu Sep 1, 2019
3585288
add comment for skipping test case in win32
haiyangwu Sep 1, 2019
14a38ba
move gulp-clang-format into devDep
haiyangwu Sep 1, 2019
cac00ed
unify name
haiyangwu Sep 1, 2019
3dbf56d
change for lint
haiyangwu Sep 2, 2019
4f10db0
use run-script-os instead of gulp
haiyangwu Sep 2, 2019
174c1dd
use @dr.amaton/run-script-os instead of a git repo
haiyangwu Sep 3, 2019
7b20534
win tasks
haiyangwu Sep 5, 2019
e70535c
remove useless tasks
haiyangwu Sep 7, 2019
a4bed7d
run mediasoup-worker-test
haiyangwu Sep 7, 2019
e566abe
add win-tasks.js to lint
haiyangwu Sep 7, 2019
cda5e7e
code style
haiyangwu Sep 11, 2019
6885c44
code style and readability
haiyangwu Sep 11, 2019
b6775ab
code style
haiyangwu Sep 11, 2019
faa375f
code style
haiyangwu Sep 11, 2019
6578c6b
remove duplicated LF
haiyangwu Sep 11, 2019
6fbcc2a
wrap consumer socket and producer socket
haiyangwu Sep 11, 2019
d0a9005
gitignore
haiyangwu Sep 12, 2019
36e2b4c
code style
haiyangwu Sep 12, 2019
bbdae70
add virtual destructor
haiyangwu Sep 12, 2019
3dddc43
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 3, 2019
7ac3a99
add defines for abseil
haiyangwu Oct 3, 2019
461e7a5
include
haiyangwu Oct 3, 2019
96a62bd
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 5, 2019
62aeb29
dot at the end of the comment
haiyangwu Oct 6, 2019
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ module.exports =
'spaced-comment': [ 2, 'always' ],
'strict': 2,
'valid-typeof': 2,
'yoda': 2
'yoda': 2,
"linebreak-style": 0
Comment thread
ibc marked this conversation as resolved.
Outdated
}
};
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@

# Mac Stuff.
.DS_Store

# Win Stuff
configure.pyc
Comment thread
ibc marked this conversation as resolved.
Outdated

# VS stuff
/worker/.vs/
Comment thread
ibc marked this conversation as resolved.
Outdated
38 changes: 38 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const gulp = require('gulp');
const shell = require('gulp-shell');
const clangFormat = require('gulp-clang-format');
const os = require('os');
Comment thread
ibc marked this conversation as resolved.
Outdated

Comment thread
ibc marked this conversation as resolved.
const workerFiles =
[
Expand Down Expand Up @@ -37,3 +39,39 @@ gulp.task('format:worker', () =>
.pipe(clangFormat.format('file'))
.pipe(gulp.dest('.'));
});

gulp.task('win:build', shell.task(
[
'echo build for windows',
'cd worker && python ./scripts/configure.py --format=msvs',
`MSBuild ./worker/out/mediasoup-worker.sln /p:Configuration=${process.env.MEDIASOUP_BUILDTYPE === 'Debug' ?'Debug' : 'Release'} -t:mediasoup-worker `
],
{
verbose : true
}
));

gulp.task('make:build', shell.task(
[
'make -C worker'
],
{
verbose : true
}
));

gulp.task('build', gulp.series(os.platform() === 'win32'? 'win:build' : 'make:build'));

gulp.task('test:win:worker', shell.task(
[
'echo not support yet!!! run test in visual studio!!!'
]
));

gulp.task('test:make:worker', shell.task(
[
'make test -C worker'
]
));

gulp.task('test:worker', gulp.series(os.platform() === 'win32'? 'test:win:worker' : 'test:make:worker'));
30 changes: 20 additions & 10 deletions lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Channel extends EnhancedEventEmitter
/**
* @private
*/
constructor({ socket, pid })
constructor({ producerSocket, consumerSocket, pid })
{
const logger = new Logger(`Channel[pid:${pid}]`);
const workerLogger = new Logger(`worker[pid:${pid}]`);
Expand All @@ -30,7 +30,8 @@ class Channel extends EnhancedEventEmitter

// Unix Socket instance.
// @type {net.Socket}
this._socket = socket;
this._producerSocket = producerSocket;
this._consumerSocket = consumerSocket;

// Next request id.
// @type {Number}
Expand All @@ -45,7 +46,7 @@ class Channel extends EnhancedEventEmitter
this._recvBuffer = null;

// Read Channel responses/notifications from the worker.
this._socket.on('data', (buffer) =>
this._consumerSocket.on('data', (buffer) =>
{
if (!this._recvBuffer)
{
Expand Down Expand Up @@ -147,8 +148,11 @@ class Channel extends EnhancedEventEmitter
}
});

this._socket.on('end', () => this._logger.debug('Channel ended by the worker process'));
this._socket.on('error', (error) => this._logger.error('Channel error: %s', String(error)));
this._consumerSocket.on('end', () => this._logger.debug('Consumer channel ended by the worker process'));
Comment thread
ibc marked this conversation as resolved.
Outdated
this._consumerSocket.on('error', (error) => this._logger.error('Consumer channel error: %s', String(error)));

this._producerSocket.on('end', () => this._logger.debug('Producer channel ended by the worker process'));
this._producerSocket.on('error', (error) => this._logger.error('Producer channel error: %s', String(error)));
}

/**
Expand All @@ -171,14 +175,20 @@ class Channel extends EnhancedEventEmitter

// Remove event listeners but leave a fake 'error' hander to avoid
// propagation.
this._socket.removeAllListeners('end');
this._socket.removeAllListeners('error');
this._socket.on('error', () => {});
this._consumerSocket.removeAllListeners('end');
this._consumerSocket.removeAllListeners('error');
this._consumerSocket.on('error', () => {});

this._producerSocket.removeAllListeners('end');
this._producerSocket.removeAllListeners('error');
this._producerSocket.on('error', () => {});

// Destroy the socket after a while to allow pending incoming messages.
setTimeout(() =>
{
try { this._socket.destroy(); }
try { this._producerSocket.destroy(); }
catch (error) {}
try { this._consumerSocket.destroy(); }
catch (error) {}
}, 200);
}
Expand Down Expand Up @@ -206,7 +216,7 @@ class Channel extends EnhancedEventEmitter
throw new Error('Channel request too big');

// This may throw if closed or remote side ended.
this._socket.write(ns);
this._producerSocket.write(ns);

return new Promise((pResolve, pReject) =>
{
Expand Down
10 changes: 6 additions & 4 deletions lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class Worker extends EnhancedEventEmitter
* fd 0 (stdin) : Just ignore it.
* fd 1 (stdout) : Pipe it for 3rd libraries that log their own stuff.
* fd 2 (stderr) : Same as stdout.
* fd 3 (channel) : Channel fd.
* fd 3 (channel) : Producer Channel fd.
* fd 4 (channel) : Consumer Channel fd.
*/
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe' ]
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe', 'pipe' ]
});

this._workerLogger = new Logger(`worker[pid:${this._child.pid}]`);
Expand All @@ -105,8 +106,9 @@ class Worker extends EnhancedEventEmitter
// @type {Channel}
this._channel = new Channel(
{
socket : this._child.stdio[3],
pid : this._pid
producerSocket : this._child.stdio[3],
consumerSocket : this._child.stdio[4],
pid : this._pid
});

// Closed flag.
Expand Down
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@
"sfu",
"nodejs"
],
"os": [
"!win32"
],
"engines": {
"node": ">=8.6.0"
},
"scripts": {
"lint": "npm run lint:node && npm run lint:worker",
"lint:node": "eslint -c .eslintrc.js gulpfile.js lib test",
"lint:worker": "make lint -C worker",
"format:worker": "make format -C worker",
"lint:worker": "gulp lint:worker",
"format:worker": "gulp format:worker",
"test": "npm run test:node && npm run test:worker",
"test:node": "make -C worker && jest",
"test:worker": "make test -C worker",
"coverage:node": "make -C worker && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "make -C worker"
"test:node": "gulp build && jest",
"test:worker": "gulp test:worker",
"coverage:node": "gulp build && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "gulp build"
},
"jest": {
"verbose": true,
Expand All @@ -46,13 +43,18 @@
"h264-profile-level-id": "^1.0.0",
"netstring": "^0.3.0",
"random-number": "^0.0.9",
"uuid": "^3.3.2"
"uuid": "^3.3.2",
"gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27",
Comment thread
ibc marked this conversation as resolved.
Outdated
"gulp-eslint": "^6.0.0",
Comment thread
ibc marked this conversation as resolved.
Outdated
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"gulp-shell": "^0.6.5",
"gulp-touch-cmd": "0.0.1"
},
"devDependencies": {
"eslint": "^6.1.0",
"eslint-plugin-jest": "^22.13.6",
"gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27",
"jest": "^24.8.0",
"jest-tobetype": "^1.2.3",
"open-cli": "^5.0.0",
Expand Down
6 changes: 6 additions & 0 deletions test/test-Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { toBeType } = require('jest-tobetype');
const mediasoup = require('../');
const { createWorker, observer } = mediasoup;
const { InvalidStateError } = require('../lib/errors');
const os = require('os');
Comment thread
ibc marked this conversation as resolved.
Outdated

expect.extend({ toBeType });

Expand Down Expand Up @@ -194,6 +195,11 @@ test('Worker emits "died" if worker process died unexpectedly', async () =>

test('worker process ignores PIPE, HUP, ALRM, USR1 and USR2 signals', async () =>
{
if (os.platform() === 'win32')
Comment thread
ibc marked this conversation as resolved.
Comment thread
haiyangwu marked this conversation as resolved.
{
return;
}
Comment thread
ibc marked this conversation as resolved.
Outdated

worker = await createWorker({ logLevel: 'warn' });

await new Promise((resolve, reject) =>
Expand Down
1 change: 1 addition & 0 deletions worker/deps/libsrtp/libsrtp.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# All Windows architectures are this way.
'SIZEOF_UNSIGNED_LONG=4',
'SIZEOF_UNSIGNED_LONG_LONG=8',
'HAVE_WINSOCK2_H',
],
}],
['target_arch=="x64" or target_arch=="ia32"', {
Expand Down
9 changes: 6 additions & 3 deletions worker/include/Channel/Request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace Channel
static std::unordered_map<std::string, MethodId> string2MethodId;

public:
Request(Channel::UnixStreamSocket* channel, json& jsonRequest);
Request(json& jsonRequest);
Comment thread
ibc marked this conversation as resolved.
Outdated
virtual ~Request();

void Accept();
Expand All @@ -76,15 +76,18 @@ namespace Channel
void TypeError(const char* reason = nullptr);

public:
// Passed by argument.
Channel::UnixStreamSocket* channel{ nullptr };
uint32_t id{ 0u };
std::string method;
MethodId methodId;
json internal;
json data;
// Others.
bool replied{ false };

public:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move static methods and members above, below the UnixStreamSocket constructor.

@haiyangwu haiyangwu Sep 11, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UnixStreamSocket constructor ? I didn't get it. change like this?

	class Request
	{
	public:
		static void ClassInit(Channel::UnixStreamSocket* channel);

	public:
		// Passed by argument.
		static Channel::UnixStreamSocket* channel;
		//....
	}

static void ClassInit(Channel::UnixStreamSocket* channel);
// Passed by argument.
static Channel::UnixStreamSocket* channel;
Comment thread
ibc marked this conversation as resolved.
Outdated
};
} // namespace Channel

Expand Down
15 changes: 14 additions & 1 deletion worker/include/Channel/UnixStreamSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Channel
};

public:
explicit UnixStreamSocket(int fd);
explicit UnixStreamSocket(int fd, ::UnixStreamSocket::SocketRole role);

public:
void SetListener(Listener* listener);
Expand All @@ -38,6 +38,19 @@ namespace Channel
// Others.
size_t msgStart{ 0 }; // Where the latest message starts.
};

class ChannelWrapper
{
public:
explicit ChannelWrapper(int consumerFd, int producerFd)
Comment thread
ibc marked this conversation as resolved.
Outdated
: consumerSocket(consumerFd, ::UnixStreamSocket::SocketRole::CONSUMER),
producerSocket(producerFd, ::UnixStreamSocket::SocketRole::PRODUCER)
{
}

Comment thread
ibc marked this conversation as resolved.
UnixStreamSocket consumerSocket;
UnixStreamSocket producerSocket;
};
} // namespace Channel

#endif
5 changes: 5 additions & 0 deletions worker/include/RTC/RTCP/FeedbackPsFir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ namespace RTC
{
uint32_t ssrc;
uint8_t sequenceNumber;
#ifdef _MSC_VER
Comment thread
ibc marked this conversation as resolved.
Outdated
// alignment
uint8_t reserved[3];
Comment thread
ibc marked this conversation as resolved.
Outdated
#else
uint32_t reserved : 24;
#endif //_MSC_VER
};

public:
Expand Down
6 changes: 6 additions & 0 deletions worker/include/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <cmath>
#include <cstring> // std::memcmp(), std::memcpy()
#include <string>
#ifdef _MSC_VER
#include <ws2ipdef.h>
// https://stackoverflow.com/a/24550632/2085408
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif // _WIN32

namespace Utils
{
Expand Down
4 changes: 2 additions & 2 deletions worker/include/Worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using json = nlohmann::json;
class Worker : public Channel::UnixStreamSocket::Listener, public SignalsHandler::Listener
{
public:
explicit Worker(Channel::UnixStreamSocket* channel);
explicit Worker(Channel::ChannelWrapper* channel);
~Worker();

private:
Expand All @@ -35,7 +35,7 @@ class Worker : public Channel::UnixStreamSocket::Listener, public SignalsHandler

private:
// Passed by argument.
Channel::UnixStreamSocket* channel{ nullptr };
Channel::ChannelWrapper* channel{ nullptr };
// Allocated by this.
SignalsHandler* signalsHandler{ nullptr };
// Others.
Expand Down
21 changes: 18 additions & 3 deletions worker/include/common.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
#ifndef MS_COMMON_HPP
#define MS_COMMON_HPP

#include <algorithm> // std::transform(), std::find(), std::min(), std::max()
#include <algorithm> // std::transform(), std::find(), std::min(), std::max()
#ifdef _MSC_VER
#include <winsock2.h>
// https://stackoverflow.com/a/27443191/2085408
#undef max
#undef min
// avoid uv/win.h: error C2628 'intptr_t' followed by 'int' is illegal
Comment thread
haiyangwu marked this conversation as resolved.
Outdated
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#define SSIZE_MAX INTPTR_MAX
#define _SSIZE_T_
#define _SSIZE_T_DEFINED
#endif
#else
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#endif // _MSC_VER
#include <cinttypes> // PRIu64, etc
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <memory> // std::addressof()
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6

#endif
Loading