This document is intended for mediasoup developers.
This document is intended for mediasoup developers.
## NPM scripts
## NPM scripts
The `package.json` file in the main folder includes the following scripts:
The `package.json` file in the main folder includes the following scripts:
### `npm run typescript:build`
### `npm run typescript:build`
Compiles mediasoup TypeScript code (`lib` folder) JavaScript and places it into the `lib` directory.
Compiles mediasoup TypeScript code (`lib` folder) JavaScript and places it into the `lib` directory.
### `npm run typescript:watch`
### `npm run typescript:watch`
Compiles mediasoup TypeScript code (`lib` folder) JavaScript, places it into the `lib` directory an watches for changes in the TypeScript files.
Compiles mediasoup TypeScript code (`lib` folder) JavaScript, places it into the `lib` directory an watches for changes in the TypeScript files.
### `npm run worker:build`
### `npm run worker:build`
Builds the `mediasoup-worker` binary. It invokes `make`below.
Builds the `mediasoup-worker` binary. It invokes `make`below.
### `npm run lint`
### `npm run lint`
Runs both `npm run lint:node` and `npm run lint:worker`.
Runs both `npm run lint:node` and `npm run lint:worker`.
### `npm run lint:node`
### `npm run lint:node`
Validates mediasoup JavaScript files using [ESLint](https://eslint.org).
Validates mediasoup JavaScript files using [ESLint](https://eslint.org).
### `npm run lint:worker`
### `npm run lint:worker`
Validates mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). It invokes `make lint` below.
Validates mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). It invokes `make lint` below.
### `npm run format:worker`
### `npm run format:worker`
Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). It invokes `make format` below.
Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). It invokes `make format` below.
### `npm run test`
### `npm run test`
Runs both `npm run test:node` and `npm run test:worker`.
Runs both `npm run test:node` and `npm run test:worker`.
### `npm run test:node`
### `npm run test:node`
Runs [Jest](https://jestjs.io) test units located at `test/` folder.
Runs [Jest](https://jestjs.io) test units located at `test/` folder.
### `npm run test:worker`
### `npm run test:worker`
Runs [Catch2](https://github.com/catchorg/Catch2) test units located at `worker/test/` folder. It invokes `make test` below.
Runs [Catch2](https://github.com/catchorg/Catch2) test units located at `worker/test/` folder. It invokes `make test` below.
### `npm run coverage:node`
### `npm run coverage:node`
Same as `npm run test:node` but it also opens a browser window with JavaScript coverage results.
Same as `npm run test:node` but it also opens a browser window with JavaScript coverage results.
### `npm run install-deps:node`
### `npm run install-deps:node`
Installs NPM dependencies and updates `package-lock.json`.
Installs NPM dependencies and updates `package-lock.json`.
### `npm run install-clang-tools`
### `npm run install-clang-tools`
Installs clang tools needed for local development.
Installs clang tools needed for local development.
## Rust
## Rust
The only special feature in Rust case is special environment variable `KEEP_BUILD_ARTIFACTS`, that when set to `1` will allow incremental recompilation of changed C++ sources during hacking on mediasoup.
The only special feature in Rust case is special environment variable `KEEP_BUILD_ARTIFACTS`, that when set to `1` will allow incremental recompilation of changed C++ sources during hacking on mediasoup.
It is not necessary for normal usage of mediasoup as a dependency.
It is not necessary for normal usage of mediasoup as a dependency.
## Makefile
## Makefile
The `worker` folder contains a `Makefile` for the mediasoup-worker C++ subproject. It includes the following tasks:
The `worker` folder contains a `Makefile` for the mediasoup-worker C++ subproject. It includes the following tasks:
### `make` or `make mediasoup-worker`
### `make` or `make mediasoup-worker`
Alias of ``make mediasoup-worker` below.
Alias of ``make mediasoup-worker` below.
### `make meson-ninja`
### `make meson-ninja`
Installs `meson` and `ninja`.
Installs `meson` and `ninja`.
### `make clean`
### `make clean`
Cleans built objects and binaries.
Cleans built objects and binaries.
### `make clean-build`
### `make clean-build`
Cleans built objects and other artifacts, but keeps `mediasoup-worker` binary in place.
Cleans built objects and other artifacts, but keeps `mediasoup-worker` binary in place.
### `make clean-pip`
### `make clean-pip`
Cleans `meson` and `ninja` installed in local prefix with pip.
Cleans `meson` and `ninja` installed in local prefix with pip.
### `make clean-subprojects`
### `make clean-subprojects`
Cleans subprojects downloaded with Meson.
Cleans subprojects downloaded with Meson.
### `make clean-all`
### `make clean-all`
Cleans built objects and binaries, `meson` and `ninja` installed in local prefix with pip and all subprojects downloaded with Meson.
Cleans built objects and binaries, `meson` and `ninja` installed in local prefix with pip and all subprojects downloaded with Meson.
### `make update-wrap-file`
### `make update-wrap-file`
Update the wrap file of a subproject with Meson. Usage example:
Update the wrap file of a subproject with Meson. Usage example:
```bash
```bash
$ cd worker
cd worker
$ make update-wrap-file SUBPROJECT=openssl
make update-wrap-file SUBPROJECT=openssl
```
```
### `make mediasoup-worker`
### `make mediasoup-worker`
Builds the `mediasoup-worker` binary at `worker/out/Release/`.
Builds the `mediasoup-worker` binary at `worker/out/Release/`.
...
@@ -144,44 +119,37 @@ Binary is built at `worker/out/MEDIASOUP_BUILDTYPE/build`.
...
@@ -144,44 +119,37 @@ Binary is built at `worker/out/MEDIASOUP_BUILDTYPE/build`.
In order to instruct the mediasoup Node.js module to use the `Debug` mediasoup-worker binary, an environment variable must be set before running the Node.js application:
In order to instruct the mediasoup Node.js module to use the `Debug` mediasoup-worker binary, an environment variable must be set before running the Node.js application:
```bash
```bash
$ MEDIASOUP_BUILDTYPE=Debug node myapp.js
MEDIASOUP_BUILDTYPE=Debug node myapp.js
```
```
If the "MEDIASOUP_WORKER_BIN" environment variable is set, mediasoup will use the it as mediasoup-worker binary and **won't** compile the binary:
If the "MEDIASOUP_WORKER_BIN" environment variable is set, mediasoup will use the it as mediasoup-worker binary and **won't** compile the binary:
Builds the `libmediasoup-worker` static library at `worker/out/Release/`.
Builds the `libmediasoup-worker` static library at `worker/out/Release/`.
`MEDIASOUP_MAX_CORES` and `MEDIASOUP_BUILDTYPE` environment variables from above still apply for static library build.
`MEDIASOUP_MAX_CORES` and `MEDIASOUP_BUILDTYPE` environment variables from above still apply for static library build.
### `make xcode`
### `make xcode`
Builds a Xcode project for the mediasoup-worker subproject.
Builds a Xcode project for the mediasoup-worker subproject.
### `make lint`
### `make lint`
Validates mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and rules in `worker/.clang-format`.
Validates mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and rules in `worker/.clang-format`.
### `make format`
### `make format`
Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
### `make test`
### `make test`
Builds and runs the `mediasoup-worker-test` binary at `worker/out/Release/` (or at `worker/out/Debug/` if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug"), which uses [Catch2](https://github.com/catchorg/Catch2) to run test units located at `worker/test/` folder.
Builds and runs the `mediasoup-worker-test` binary at `worker/out/Release/` (or at `worker/out/Debug/` if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug"), which uses [Catch2](https://github.com/catchorg/Catch2) to run test units located at `worker/test/` folder.
### `make tidy`
### `make tidy`
Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code checks following `worker/.clang-tidy` rules.
Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code checks following `worker/.clang-tidy` rules.
...
@@ -190,8 +158,7 @@ Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code
...
@@ -190,8 +158,7 @@ Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code
* `make clean` and `make` must have been called first.
* `make clean` and `make` must have been called first.
* [PyYAML](https://pyyaml.org/) is required.
* [PyYAML](https://pyyaml.org/) is required.
- In OSX install it with `brew install libyaml` and `sudo easy_install-X.Y pyyaml`.
* In OSX install it with `brew install libyaml` and `sudo easy_install-X.Y pyyaml`.
Read the [Fuzzer](Fuzzer.md) documentation for detailed information.
Read the [Fuzzer](Fuzzer.md) documentation for detailed information.
### `make fuzzer-run-all`
### `make fuzzer-run-all`
Runs all fuzzer cases.
Runs all fuzzer cases.
### `make docker`
### `make docker`
Builds a Linux image with fuzzer capable clang++.
Builds a Linux image with fuzzer capable clang++.
...
@@ -218,11 +183,10 @@ Builds a Linux image with fuzzer capable clang++.
...
@@ -218,11 +183,10 @@ Builds a Linux image with fuzzer capable clang++.
**NOTE:** Before running this command, a specific version of Linux clang must be downloaded. To get it, run:
**NOTE:** Before running this command, a specific version of Linux clang must be downloaded. To get it, run:
```bash
```bash
$ cd worker
cd worker
$ ./scripts/get-dep.sh clang-fuzzer
./scripts/get-dep.sh clang-fuzzer
```
```
### `make docker-run`
### `make docker-run`
Runs a container of the Docker image created with `make docker`. It automatically executes a `bash` session in the `/mediasoup` directory, which is a Docker volume that points to the real `mediasoup` directory.
Runs a container of the Docker image created with `make docker`. It automatically executes a `bash` session in the `/mediasoup` directory, which is a Docker volume that points to the real `mediasoup` directory.
@@ -12,14 +11,12 @@ Once we have built the `mediasoup-worker-fuzzer` target in a Linux environment w
...
@@ -12,14 +11,12 @@ Once we have built the `mediasoup-worker-fuzzer` target in a Linux environment w
*[webrtcH4cKS ~ Lets get better at fuzzing in 2019](https://webrtchacks.com/lets-get-better-at-fuzzing-in-2019-heres-how/)
*[webrtcH4cKS ~ Lets get better at fuzzing in 2019](https://webrtchacks.com/lets-get-better-at-fuzzing-in-2019-heres-how/)
*[OSS-Fuzz](https://github.com/google/oss-fuzz) - Continuous fuzzing of open source software ("fuzz for me")
*[OSS-Fuzz](https://github.com/google/oss-fuzz) - Continuous fuzzing of open source software ("fuzz for me")
## Corpus files
## Corpus files
The `deps/webrtc-fuzzer-corpora/corpora` directory has corpus directories taken from the [webrtc-fuzzer-corpora](https://github.com/RTC-Cartel/webrtc-fuzzer-corpora) project. They should be use to feed fuzzer with appropriate input.
The `deps/webrtc-fuzzer-corpora/corpora` directory has corpus directories taken from the [webrtc-fuzzer-corpora](https://github.com/RTC-Cartel/webrtc-fuzzer-corpora) project. They should be use to feed fuzzer with appropriate input.
However, given how `libFuzzer`[works](http://llvm.org/docs/LibFuzzer.html#options), the first directory given as command line parameter is not just used for reading corpus files, but also to store newly generated ones. So, it's recommended to pass `fuzzer/new-corpus` as first directory. Such a directory is gitignored.
However, given how `libFuzzer`[works](http://llvm.org/docs/LibFuzzer.html#options), the first directory given as command line parameter is not just used for reading corpus files, but also to store newly generated ones. So, it's recommended to pass `fuzzer/new-corpus` as first directory. Such a directory is gitignored.
## Crash reports
## Crash reports
When the fuzzer detects an issue it generates a crash report file which contains the bytes given as input. Those files can be individually used later (instead of passing corpus directories) to the fuzzer to verify that the issue has been fixed.
When the fuzzer detects an issue it generates a crash report file which contains the bytes given as input. Those files can be individually used later (instead of passing corpus directories) to the fuzzer to verify that the issue has been fixed.
...
@@ -50,41 +47,40 @@ The mediasoup-worker fuzzer reads some custom environment variables to decide wh
...
@@ -50,41 +47,40 @@ The mediasoup-worker fuzzer reads some custom environment variables to decide wh
The log level can also be set by setting the `MS_FUZZ_LOG_LEVEL` environment variable to "debug", "warn" or "error" (it is "none" if unset).
The log level can also be set by setting the `MS_FUZZ_LOG_LEVEL` environment variable to "debug", "warn" or "error" (it is "none" if unset).