* various fixes to readable-stream implementation using blocking srt calls. - refactor reading/pushing routine in order to allow higher througput: * call srt read() in the same tick/stack as the class _read impl call * schedule a timer only as needed if no connection yet or socket buffer empty * blocking loop to push all bytes requested, or until push returns false or until no more data is in the socket buffer * generally, handle case properly where no data is yet available from srt-socket read() * in case no more data, retains the currently requested value remainder from last _read call -> this will allow for getting as much data as requested (if socket delivers it) within the tick where it was requested or any next one in a best effort manner. it will block the main-thread with "too long" execution frames/ticks eventually as the data-demand from the _read calls becomes high in amout/frequency. but that is simply a consequence of the fact the SRT calls here are blocking I/O. the previous implementation was also resulting in this congestion of the main loop queue as read calls would block it, but at best there was a 100ms lag between a request for read and its actual fulfillment. one further improvement of this fix could be to split up the requested bytes amount onto several ticks (executing one partial read directly, and further ones in further timer scheduled calls, in order to avoid blocking ticks). - use 50ms timer default for read continuation retry timer - use 50ms interval for initial connection epoll'ing - use consts for all timeout values - implement base class _destroy method & refactor close() in consequence - trigger Stream base class "readable" event on connection and first packet * server: add an event for when a client was accepted to pass the fd |
||
|---|---|---|
| .github/workflows | ||
| examples | ||
| scripts | ||
| spec | ||
| src | ||
| types | ||
| .editorconfig | ||
| .eslintignore | ||
| .eslintrc.js | ||
| .gitignore | ||
| .gitmodules | ||
| binding.gyp | ||
| CONTRIBUTING.md | ||
| index.d.ts | ||
| index.js | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
@eyevinn/srt is a Node.js Native Addon that provides bindings to Secure Reliable Transport SDK.
Install
npm install --save @eyevinn/srt
Installing from NPM downloads and builds SRT SDK and NodeJS addon for your operating system × architecture.
Example
const { SRT } = require('@eyevinn/srt');
const srt = new SRT();
const socket = srt.createSocket();
srt.bind(socket, "0.0.0.0", 1234);
srt.listen(socket, 2);
const fd = srt.accept(socket);
if (fd) {
const chunk = srt.read(fd, 1316);
}
API
class SRT {
createSocket(sender?:Boolean): socket:Number
bind(socket:Number, address:String, port:Number): result:Number
listen(socket:Number, backlog:Number): result:Number
connect(socket:Number, host:String, port:Number): result:Number
accept(socket:Number): fileDescriptor:Number
close(socket:Number): result:Number
read(socket:Number, chunkSize:Number): chunk:Buffer
write(socket:Number, chunk:Buffer): result:Number
setSockOpt(socket:Number, option:Number, value): result:Number
getSockOpt(socket:Number, option:Number): value
getSockState(socket:Number): value:Number
epollCreate(): epid:Number
epollAddUsock(epid:Number, socket:Number, events:Number): result:Number
epollUWait(epid:Number, msTimeOut:Number): events:Array
}
Readable Stream
A custom readable stream API is also available, example (in listener mode):
const fs = require('fs');
const dest = fs.createWriteStream('./output');
const { SRTReadStream } = require('@eyevinn/srt');
const srt = new SRTReadStream('0.0.0.0', 1234);
srt.listen(readStream => {
readStream.pipe(dest);
});
of in caller mode:
const srt = new SRTReadStream('127.0.0.1', 1234);
srt.connect(readStream => {
readStream.pipe(dest);
});
Writable Stream
Example of a writable stream
const fs = require('fs');
const source = fs.createReadStream('./input');
const { SRTWriteStream } = require('@eyevinn/srt');
const srt = new SRTWriteStream('127.0.0.1', 1234);
srt.connect(writeStream => {
source.pipe(writeStream);
});
Contributing
In addition to contributing code, you can help to triage issues. This can include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions.
License (MIT)
Copyright 2020 Eyevinn Technology
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About Eyevinn Technology
Eyevinn Technology is an independent consultant firm specialized in video and streaming. Independent in a way that we are not commercially tied to any platform or technology vendor.
At Eyevinn, every software developer consultant has a dedicated budget reserved for open source development and contribution to the open source community. This give us room for innovation, team building and personal competence development. And also gives us as a company a way to contribute back to the open source community.
Want to know more about Eyevinn and how it is to work here. Contact us at work@eyevinn.se!