mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-17 01:16:00 +00:00
Modules
This commit is contained in:
190
node_modules/prism-media/LICENSE
generated
vendored
Normal file
190
node_modules/prism-media/LICENSE
generated
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2019 - 2020 Amish Shah
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
69
node_modules/prism-media/README.md
generated
vendored
Normal file
69
node_modules/prism-media/README.md
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
[](https://hydrabolt.me/prism-media/)
|
||||
|
||||
<div align="center">
|
||||
|
||||
[](https://travis-ci.org/hydrabolt/prism-media)
|
||||
[](https://david-dm.org/hydrabolt/prism-media)
|
||||
[](https://www.npmjs.com/package/prism-media)
|
||||
[](https://www.patreon.com/discordjs)
|
||||
|
||||
</div>
|
||||
|
||||
## What is it?
|
||||
|
||||
An easy-to-use stream-based toolkit that you can use for media processing. All the features provided have predictable
|
||||
abstractions and join together coherently.
|
||||
|
||||
```js
|
||||
// This example will demux and decode an Opus-containing OGG file, and then write it to a file.
|
||||
const prism = require('prism-media');
|
||||
const fs = require('fs');
|
||||
|
||||
fs.createReadStream('./audio.ogg')
|
||||
.pipe(new prism.opus.OggDemuxer())
|
||||
.pipe(new prism.opus.Decoder({ rate: 48000, channels: 2, frameSize: 960 }))
|
||||
.pipe(fs.createWriteStream('./audio.pcm'));
|
||||
```
|
||||
|
||||
The example above can work with either a native or pure JavaScript Opus decoder - you don't need to worry about changing
|
||||
your code for whichever you install.
|
||||
|
||||
- FFmpeg support (either through npm modules or a normal installation)
|
||||
- Opus support (native or pure JavaScript)
|
||||
- Demuxing for WebM/OGG files (no modules required!)
|
||||
- Volume Altering (no modules required!)
|
||||
|
||||
## Dependencies
|
||||
|
||||
The following dependencies are all optional, and you should only install one from each category (the first listed in
|
||||
each category is preferred)
|
||||
|
||||
- Opus
|
||||
- [`@discordjs/opus`](https://github.com/discordjs/opus)
|
||||
- [`node-opus`](https://github.com/Rantanen/node-opus)
|
||||
- [`opusscript`](https://github.com/abalabahaha/opusscript)
|
||||
- FFmpeg
|
||||
- [`ffmpeg-static`](http://npmjs.com/ffmpeg-static)
|
||||
- `ffmpeg` from a [normal installation](https://www.ffmpeg.org/download.html)
|
||||
|
||||
## Useful Links
|
||||
|
||||
- [Documentation](https://hydrabolt.me/prism-media)
|
||||
- [Examples](https://github.com/amishshah/prism-media/tree/master/examples)
|
||||
- [Patreon](https://www.patreon.com/discordjs)
|
||||
|
||||
## License
|
||||
|
||||
> Copyright 2019 - 2020 Amish Shah
|
||||
>
|
||||
> Licensed under the Apache License, Version 2.0 (the "License");
|
||||
> you may not use this file except in compliance with the License.
|
||||
> You may obtain a copy of the License at
|
||||
>
|
||||
> http://www.apache.org/licenses/LICENSE-2.0
|
||||
>
|
||||
> Unless required by applicable law or agreed to in writing, software
|
||||
> distributed under the License is distributed on an "AS IS" BASIS,
|
||||
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
> See the License for the specific language governing permissions and
|
||||
> limitations under the License.
|
91
node_modules/prism-media/package.json
generated
vendored
Normal file
91
node_modules/prism-media/package.json
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
"_from": "github:hydrabolt/prism-media",
|
||||
"_id": "prism-media@1.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "",
|
||||
"_location": "/prism-media",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "git",
|
||||
"raw": "hydrabolt/prism-media",
|
||||
"rawSpec": "hydrabolt/prism-media",
|
||||
"saveSpec": "github:hydrabolt/prism-media",
|
||||
"fetchSpec": null,
|
||||
"gitCommittish": null
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/discord.js",
|
||||
"/ytdl-core-discord"
|
||||
],
|
||||
"_resolved": "github:hydrabolt/prism-media#cb94179620e6b437dd88710ad81ee16e1b0b7a82",
|
||||
"_spec": "hydrabolt/prism-media",
|
||||
"_where": "C:\\Users\\matia\\Documents\\GitHub\\Musix-V3",
|
||||
"author": {
|
||||
"name": "Amish Shah",
|
||||
"email": "amishshah.2k@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/hydrabolt/prism-media/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Easy-to-use stream-based media transcoding",
|
||||
"devDependencies": {
|
||||
"docma": "^3.2.2",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^24.9.0"
|
||||
},
|
||||
"files": [
|
||||
"src/",
|
||||
"typings/"
|
||||
],
|
||||
"homepage": "https://github.com/hydrabolt/prism-media#readme",
|
||||
"jest": {
|
||||
"testURL": "http://localhost/"
|
||||
},
|
||||
"keywords": [
|
||||
"audio",
|
||||
"media",
|
||||
"ffmpeg",
|
||||
"opus",
|
||||
"pcm",
|
||||
"webm",
|
||||
"ogg"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "src/index.js",
|
||||
"name": "prism-media",
|
||||
"peerDependencies": {
|
||||
"ffmpeg-static": "^2.4.0 || ^3.0.0",
|
||||
"@discordjs/opus": "^0.1.0",
|
||||
"node-opus": "^0.3.1",
|
||||
"opusscript": "^0.0.6"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@discordjs/opus": {
|
||||
"optional": true
|
||||
},
|
||||
"node-opus": {
|
||||
"optional": true
|
||||
},
|
||||
"opusscript": {
|
||||
"optional": true
|
||||
},
|
||||
"ffmpeg-static": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hydrabolt/prism-media.git"
|
||||
},
|
||||
"scripts": {
|
||||
"docs": "docma",
|
||||
"lint": "eslint src",
|
||||
"test": "npm run lint && jest && npm run docs"
|
||||
},
|
||||
"types": "typings/index.d.ts",
|
||||
"version": "1.2.0"
|
||||
}
|
147
node_modules/prism-media/src/core/FFmpeg.js
generated
vendored
Normal file
147
node_modules/prism-media/src/core/FFmpeg.js
generated
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
const ChildProcess = require('child_process');
|
||||
const { Duplex } = require('stream');
|
||||
|
||||
let FFMPEG = {
|
||||
command: null,
|
||||
output: null,
|
||||
};
|
||||
|
||||
const VERSION_REGEX = /version (.+) Copyright/mi;
|
||||
|
||||
Object.defineProperty(FFMPEG, 'version', {
|
||||
get() {
|
||||
return VERSION_REGEX.exec(FFMPEG.output)[1];
|
||||
},
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* An FFmpeg transform stream that provides an interface to FFmpeg.
|
||||
* @memberof core
|
||||
*/
|
||||
class FFmpeg extends Duplex {
|
||||
/**
|
||||
* Creates a new FFmpeg transform stream
|
||||
* @memberof core
|
||||
* @param {Object} options Options you would pass to a regular Transform stream, plus an `args` option
|
||||
* @param {Array<string>} options.args Arguments to pass to FFmpeg
|
||||
* @example
|
||||
* // By default, if you don't specify an input (`-i ...`) prism will assume you're piping a stream into it.
|
||||
* const transcoder = new prism.FFmpeg({
|
||||
* args: [
|
||||
* '-analyzeduration', '0',
|
||||
* '-loglevel', '0',
|
||||
* '-f', 's16le',
|
||||
* '-ar', '48000',
|
||||
* '-ac', '2',
|
||||
* ]
|
||||
* });
|
||||
* const s16le = mp3File.pipe(transcoder);
|
||||
* const opus = s16le.pipe(new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 }));
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.process = FFmpeg.create(options);
|
||||
const EVENTS = {
|
||||
readable: this._reader,
|
||||
data: this._reader,
|
||||
end: this._reader,
|
||||
unpipe: this._reader,
|
||||
finish: this._writer,
|
||||
drain: this._writer,
|
||||
};
|
||||
|
||||
this._readableState = this._reader._readableState;
|
||||
this._writableState = this._writer._writableState;
|
||||
|
||||
this._copy(['write', 'end'], this._writer);
|
||||
this._copy(['read', 'setEncoding', 'pipe', 'unpipe'], this._reader);
|
||||
|
||||
for (const method of ['on', 'once', 'removeListener', 'removeListeners', 'listeners']) {
|
||||
this[method] = (ev, fn) => EVENTS[ev] ? EVENTS[ev][method](ev, fn) : Duplex.prototype[method].call(this, ev, fn);
|
||||
}
|
||||
|
||||
const processError = error => this.emit('error', error);
|
||||
this._reader.on('error', processError);
|
||||
this._writer.on('error', processError);
|
||||
}
|
||||
|
||||
get _reader() { return this.process.stdout; }
|
||||
get _writer() { return this.process.stdin; }
|
||||
|
||||
_copy(methods, target) {
|
||||
for (const method of methods) {
|
||||
this[method] = target[method].bind(target);
|
||||
}
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
super._destroy(err, cb);
|
||||
this.once('error', () => {});
|
||||
this.process.kill('SIGKILL');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The available FFmpeg information
|
||||
* @typedef {Object} FFmpegInfo
|
||||
* @memberof core
|
||||
* @property {string} command The command used to launch FFmpeg
|
||||
* @property {string} output The output from running `ffmpeg -h`
|
||||
* @property {string} version The version of FFmpeg being used, determined from `output`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Finds a suitable FFmpeg command and obtains the debug information from it.
|
||||
* @param {boolean} [force=false] If true, will ignore any cached results and search for the command again
|
||||
* @returns {FFmpegInfo}
|
||||
* @throws Will throw an error if FFmpeg cannot be found.
|
||||
* @example
|
||||
* const ffmpeg = prism.FFmpeg.getInfo();
|
||||
*
|
||||
* console.log(`Using FFmpeg version ${ffmpeg.version}`);
|
||||
*
|
||||
* if (ffmpeg.output.includes('--enable-libopus')) {
|
||||
* console.log('libopus is available!');
|
||||
* } else {
|
||||
* console.log('libopus is unavailable!');
|
||||
* }
|
||||
*/
|
||||
static getInfo(force = false) {
|
||||
if (FFMPEG.command && !force) return FFMPEG;
|
||||
const sources = [() => {
|
||||
const ffmpegStatic = require('ffmpeg-static');
|
||||
return ffmpegStatic.path || ffmpegStatic;
|
||||
}, 'ffmpeg', 'avconv', './ffmpeg', './avconv'];
|
||||
for (let source of sources) {
|
||||
try {
|
||||
if (typeof source === 'function') source = source();
|
||||
const result = ChildProcess.spawnSync(source, ['-h'], { windowsHide: true });
|
||||
if (result.error) throw result.error;
|
||||
Object.assign(FFMPEG, {
|
||||
command: source,
|
||||
output: Buffer.concat(result.output.filter(Boolean)).toString(),
|
||||
});
|
||||
return FFMPEG;
|
||||
} catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
throw new Error('FFmpeg/avconv not found!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new FFmpeg instance. If you do not include `-i ...` it will be assumed that `-i -` should be prepended
|
||||
* to the options and that you'll be piping data into the process.
|
||||
* @param {String[]} [args=[]] Arguments to pass to FFmpeg
|
||||
* @returns {ChildProcess}
|
||||
* @private
|
||||
* @throws Will throw an error if FFmpeg cannot be found.
|
||||
*/
|
||||
static create({ args = [] } = {}) {
|
||||
if (!args.includes('-i')) args.unshift('-i', '-');
|
||||
return ChildProcess.spawn(FFmpeg.getInfo().command, args.concat(['pipe:1']), { windowsHide: true });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FFmpeg;
|
129
node_modules/prism-media/src/core/VolumeTransformer.js
generated
vendored
Normal file
129
node_modules/prism-media/src/core/VolumeTransformer.js
generated
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
// Based on discord.js' old volume system
|
||||
|
||||
const { Transform } = require('stream');
|
||||
|
||||
/**
|
||||
* Transforms a stream of PCM volume.
|
||||
* @memberof core
|
||||
* @extends TransformStream
|
||||
*/
|
||||
class VolumeTransformer extends Transform {
|
||||
/**
|
||||
* @memberof core
|
||||
* @param {Object} options Any optional TransformStream options plus some extra:
|
||||
* @param {string} options.type The type of transformer: s16le (signed 16-bit little-endian), s16be, s32le, s32be
|
||||
* @param {number} [options.volume=1] The output volume of the stream
|
||||
* @example
|
||||
* // Half the volume of a signed 16-bit little-endian PCM stream
|
||||
* input
|
||||
* .pipe(new prism.VolumeTransformer({ type: 's16le', volume: 0.5 }))
|
||||
* .pipe(writeStream);
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
switch (options.type) {
|
||||
case 's16le':
|
||||
this._readInt = (buffer, index) => buffer.readInt16LE(index);
|
||||
this._writeInt = (buffer, int, index) => buffer.writeInt16LE(int, index);
|
||||
this._bits = 16;
|
||||
break;
|
||||
case 's16be':
|
||||
this._readInt = (buffer, index) => buffer.readInt16BE(index);
|
||||
this._writeInt = (buffer, int, index) => buffer.writeInt16BE(int, index);
|
||||
this._bits = 16;
|
||||
break;
|
||||
case 's32le':
|
||||
this._readInt = (buffer, index) => buffer.readInt32LE(index);
|
||||
this._writeInt = (buffer, int, index) => buffer.writeInt32LE(int, index);
|
||||
this._bits = 32;
|
||||
break;
|
||||
case 's32be':
|
||||
this._readInt = (buffer, index) => buffer.readInt32BE(index);
|
||||
this._writeInt = (buffer, int, index) => buffer.writeInt32BE(int, index);
|
||||
this._bits = 32;
|
||||
break;
|
||||
default:
|
||||
throw new Error('VolumeTransformer type should be one of s16le, s16be, s32le, s32be');
|
||||
}
|
||||
this._bytes = this._bits / 8;
|
||||
this._extremum = Math.pow(2, this._bits - 1);
|
||||
this.volume = typeof options.volume === 'undefined' ? 1 : options.volume;
|
||||
this._chunk = Buffer.alloc(0);
|
||||
}
|
||||
|
||||
_readInt(buffer, index) { return index; }
|
||||
_writeInt(buffer, int, index) { return index; }
|
||||
|
||||
_transform(chunk, encoding, done) {
|
||||
// If the volume is 1, act like a passthrough stream
|
||||
if (this.volume === 1) {
|
||||
this.push(chunk);
|
||||
return done();
|
||||
}
|
||||
|
||||
const { _bytes, _extremum } = this;
|
||||
|
||||
chunk = this._chunk = Buffer.concat([this._chunk, chunk]);
|
||||
if (chunk.length < _bytes) return done();
|
||||
|
||||
const transformed = Buffer.allocUnsafe(chunk.length);
|
||||
const complete = Math.floor(chunk.length / _bytes) * _bytes;
|
||||
|
||||
for (let i = 0; i < complete; i += _bytes) {
|
||||
const int = Math.min(_extremum - 1, Math.max(-_extremum, Math.floor(this.volume * this._readInt(chunk, i))));
|
||||
this._writeInt(transformed, int, i);
|
||||
}
|
||||
|
||||
this._chunk = chunk.slice(complete);
|
||||
this.push(transformed);
|
||||
return done();
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
super._destroy(err, cb);
|
||||
this._chunk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume relative to the input stream - i.e. 1 is normal, 0.5 is half, 2 is double.
|
||||
* @param {number} volume The volume that you want to set
|
||||
*/
|
||||
setVolume(volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume in decibels.
|
||||
* @param {number} db The decibels
|
||||
*/
|
||||
setVolumeDecibels(db) {
|
||||
this.setVolume(Math.pow(10, db / 20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume so that a perceived value of 0.5 is half the perceived volume etc.
|
||||
* @param {number} value The value for the volume
|
||||
*/
|
||||
setVolumeLogarithmic(value) {
|
||||
this.setVolume(Math.pow(value, 1.660964));
|
||||
}
|
||||
|
||||
/**
|
||||
* The current volume of the stream in decibels
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
get volumeDecibels() {
|
||||
return Math.log10(this._volume) * 20;
|
||||
}
|
||||
/**
|
||||
* The current volume of the stream from a logarithmic scale
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
get volumeLogarithmic() {
|
||||
return Math.pow(this._volume, 1 / 1.660964);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VolumeTransformer;
|
199
node_modules/prism-media/src/core/WebmBase.js
generated
vendored
Normal file
199
node_modules/prism-media/src/core/WebmBase.js
generated
vendored
Normal file
@ -0,0 +1,199 @@
|
||||
const { Transform } = require('stream');
|
||||
|
||||
/**
|
||||
* Base class for WebmOpusDemuxer and WebmVorbisDemuxer.
|
||||
* **You shouldn't directly instantiate this class, use the opus.WebmDemuxer and vorbis.WebmDemuxer
|
||||
* implementations instead!**
|
||||
* @memberof core
|
||||
* @protected
|
||||
* @extends TransformStream
|
||||
*/
|
||||
class WebmBaseDemuxer extends Transform {
|
||||
/**
|
||||
* Creates a new Webm demuxer.
|
||||
* @private
|
||||
* @memberof core
|
||||
* @param {Object} [options] options that you would pass to a regular Transform stream.
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
super(Object.assign({ readableObjectMode: true }, options));
|
||||
this._remainder = null;
|
||||
this._length = 0;
|
||||
this._count = 0;
|
||||
this._skipUntil = null;
|
||||
this._track = null;
|
||||
this._incompleteTrack = {};
|
||||
this._ebmlFound = false;
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, done) {
|
||||
this._length += chunk.length;
|
||||
if (this._remainder) {
|
||||
chunk = Buffer.concat([this._remainder, chunk]);
|
||||
this._remainder = null;
|
||||
}
|
||||
let offset = 0;
|
||||
if (this._skipUntil && this._length > this._skipUntil) {
|
||||
offset = this._skipUntil - this._count;
|
||||
this._skipUntil = null;
|
||||
} else if (this._skipUntil) {
|
||||
this._count += chunk.length;
|
||||
return done();
|
||||
}
|
||||
let result;
|
||||
while (result !== TOO_SHORT) {
|
||||
result = this._readTag(chunk, offset);
|
||||
if (result === TOO_SHORT) break;
|
||||
if (result._skipUntil) {
|
||||
this._skipUntil = result._skipUntil;
|
||||
break;
|
||||
}
|
||||
if (result.offset) offset = result.offset;
|
||||
else break;
|
||||
}
|
||||
this._count += offset;
|
||||
this._remainder = chunk.slice(offset);
|
||||
return done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an EBML ID from a buffer.
|
||||
* @private
|
||||
* @param {Buffer} chunk the buffer to read from.
|
||||
* @param {number} offset the offset in the buffer.
|
||||
* @returns {Object|Symbol} contains an `id` property (buffer) and the new `offset` (number).
|
||||
* Returns the TOO_SHORT symbol if the data wasn't big enough to facilitate the request.
|
||||
*/
|
||||
_readEBMLId(chunk, offset) {
|
||||
const idLength = vintLength(chunk, offset);
|
||||
if (idLength === TOO_SHORT) return TOO_SHORT;
|
||||
return {
|
||||
id: chunk.slice(offset, offset + idLength),
|
||||
offset: offset + idLength,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a size variable-integer to calculate the length of the data of a tag.
|
||||
* @private
|
||||
* @param {Buffer} chunk the buffer to read from.
|
||||
* @param {number} offset the offset in the buffer.
|
||||
* @returns {Object|Symbol} contains property `offset` (number), `dataLength` (number) and `sizeLength` (number).
|
||||
* Returns the TOO_SHORT symbol if the data wasn't big enough to facilitate the request.
|
||||
*/
|
||||
_readTagDataSize(chunk, offset) {
|
||||
const sizeLength = vintLength(chunk, offset);
|
||||
if (sizeLength === TOO_SHORT) return TOO_SHORT;
|
||||
const dataLength = expandVint(chunk, offset, offset + sizeLength);
|
||||
return { offset: offset + sizeLength, dataLength, sizeLength };
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a buffer and attempts to read and process a tag.
|
||||
* @private
|
||||
* @param {Buffer} chunk the buffer to read from.
|
||||
* @param {number} offset the offset in the buffer.
|
||||
* @returns {Object|Symbol} contains the new `offset` (number) and optionally the `_skipUntil` property,
|
||||
* indicating that the stream should ignore any data until a certain length is reached.
|
||||
* Returns the TOO_SHORT symbol if the data wasn't big enough to facilitate the request.
|
||||
*/
|
||||
_readTag(chunk, offset) {
|
||||
const idData = this._readEBMLId(chunk, offset);
|
||||
if (idData === TOO_SHORT) return TOO_SHORT;
|
||||
const ebmlID = idData.id.toString('hex');
|
||||
if (!this._ebmlFound) {
|
||||
if (ebmlID === '1a45dfa3') this._ebmlFound = true;
|
||||
else throw Error('Did not find the EBML tag at the start of the stream');
|
||||
}
|
||||
offset = idData.offset;
|
||||
const sizeData = this._readTagDataSize(chunk, offset);
|
||||
if (sizeData === TOO_SHORT) return TOO_SHORT;
|
||||
const { dataLength } = sizeData;
|
||||
offset = sizeData.offset;
|
||||
// If this tag isn't useful, tell the stream to stop processing data until the tag ends
|
||||
if (typeof TAGS[ebmlID] === 'undefined') {
|
||||
if (chunk.length > offset + dataLength) {
|
||||
return { offset: offset + dataLength };
|
||||
}
|
||||
return { offset, _skipUntil: this._count + offset + dataLength };
|
||||
}
|
||||
|
||||
const tagHasChildren = TAGS[ebmlID];
|
||||
if (tagHasChildren) {
|
||||
return { offset };
|
||||
}
|
||||
|
||||
if (offset + dataLength > chunk.length) return TOO_SHORT;
|
||||
const data = chunk.slice(offset, offset + dataLength);
|
||||
if (!this._track) {
|
||||
if (ebmlID === 'ae') this._incompleteTrack = {};
|
||||
if (ebmlID === 'd7') this._incompleteTrack.number = data[0];
|
||||
if (ebmlID === '83') this._incompleteTrack.type = data[0];
|
||||
if (this._incompleteTrack.type === 2 && typeof this._incompleteTrack.number !== 'undefined') {
|
||||
this._track = this._incompleteTrack;
|
||||
}
|
||||
}
|
||||
if (ebmlID === '63a2') {
|
||||
this._checkHead(data);
|
||||
} else if (ebmlID === 'a3') {
|
||||
if (!this._track) throw Error('No audio track in this webm!');
|
||||
if ((data[0] & 0xF) === this._track.number) {
|
||||
this.push(data.slice(4));
|
||||
}
|
||||
}
|
||||
return { offset: offset + dataLength };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A symbol that is returned by some functions that indicates the buffer it has been provided is not large enough
|
||||
* to facilitate a request.
|
||||
* @name WebmBaseDemuxer#TOO_SHORT
|
||||
* @memberof core
|
||||
* @private
|
||||
* @type {Symbol}
|
||||
*/
|
||||
const TOO_SHORT = WebmBaseDemuxer.TOO_SHORT = Symbol('TOO_SHORT');
|
||||
|
||||
/**
|
||||
* A map that takes a value of an EBML ID in hex string form, with the value being a boolean that indicates whether
|
||||
* this tag has children.
|
||||
* @name WebmBaseDemuxer#TAGS
|
||||
* @memberof core
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
const TAGS = WebmBaseDemuxer.TAGS = { // value is true if the element has children
|
||||
'1a45dfa3': true, // EBML
|
||||
'18538067': true, // Segment
|
||||
'1f43b675': true, // Cluster
|
||||
'1654ae6b': true, // Tracks
|
||||
'ae': true, // TrackEntry
|
||||
'd7': false, // TrackNumber
|
||||
'83': false, // TrackType
|
||||
'a3': false, // SimpleBlock
|
||||
'63a2': false,
|
||||
};
|
||||
|
||||
module.exports = WebmBaseDemuxer;
|
||||
|
||||
function vintLength(buffer, index) {
|
||||
let i = 0;
|
||||
for (; i < 8; i++) if ((1 << (7 - i)) & buffer[index]) break;
|
||||
i++;
|
||||
if (index + i > buffer.length) {
|
||||
return TOO_SHORT;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function expandVint(buffer, start, end) {
|
||||
const length = vintLength(buffer, start);
|
||||
if (end > buffer.length || length === TOO_SHORT) return TOO_SHORT;
|
||||
let mask = (1 << (8 - length)) - 1;
|
||||
let value = buffer[start] & mask;
|
||||
for (let i = start + 1; i < end; i++) {
|
||||
value = (value << 8) + buffer[i];
|
||||
}
|
||||
return value;
|
||||
}
|
9
node_modules/prism-media/src/core/index.js
generated
vendored
Normal file
9
node_modules/prism-media/src/core/index.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Core features.
|
||||
* **You shouldn't prefix imports from this namespace with `core`.**
|
||||
* @namespace core
|
||||
*/
|
||||
module.exports = {
|
||||
FFmpeg: require('./FFmpeg'),
|
||||
VolumeTransformer: require('./VolumeTransformer'),
|
||||
};
|
5
node_modules/prism-media/src/index.js
generated
vendored
Normal file
5
node_modules/prism-media/src/index.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
opus: require('./opus'),
|
||||
vorbis: require('./vorbis'),
|
||||
...require('./core'),
|
||||
};
|
118
node_modules/prism-media/src/opus/OggDemuxer.js
generated
vendored
Normal file
118
node_modules/prism-media/src/opus/OggDemuxer.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
const { Transform } = require('stream');
|
||||
|
||||
const OGG_PAGE_HEADER_SIZE = 26;
|
||||
const STREAM_STRUCTURE_VERSION = 0;
|
||||
|
||||
const charCode = x => x.charCodeAt(0);
|
||||
const OGGS_HEADER = Buffer.from([...'OggS'].map(charCode));
|
||||
const OPUS_HEAD = Buffer.from([...'OpusHead'].map(charCode));
|
||||
const OPUS_TAGS = Buffer.from([...'OpusTags'].map(charCode));
|
||||
|
||||
/**
|
||||
* Demuxes an Ogg stream (containing Opus audio) to output an Opus stream.
|
||||
* @extends {TransformStream}
|
||||
* @memberof opus
|
||||
*/
|
||||
class OggDemuxer extends Transform {
|
||||
/**
|
||||
* Creates a new OggOpus demuxer.
|
||||
* @param {Object} [options] options that you would pass to a regular Transform stream.
|
||||
* @memberof opus
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
super(Object.assign({ readableObjectMode: true }, options));
|
||||
this._remainder = null;
|
||||
this._head = null;
|
||||
this._bitstream = null;
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, done) {
|
||||
if (this._remainder) {
|
||||
chunk = Buffer.concat([this._remainder, chunk]);
|
||||
this._remainder = null;
|
||||
}
|
||||
|
||||
while (chunk) {
|
||||
const result = this._readPage(chunk);
|
||||
if (result) chunk = result;
|
||||
else break;
|
||||
}
|
||||
this._remainder = chunk;
|
||||
done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a page from a buffer
|
||||
* @private
|
||||
* @param {Buffer} chunk the chunk containing the page
|
||||
* @returns {boolean|Buffer} if a buffer, it will be a slice of the excess data of the original, otherwise it will be
|
||||
* false and would indicate that there is not enough data to go ahead with reading this page.
|
||||
*/
|
||||
_readPage(chunk) {
|
||||
if (chunk.length < OGG_PAGE_HEADER_SIZE) {
|
||||
return false;
|
||||
}
|
||||
if (!chunk.slice(0, 4).equals(OGGS_HEADER)) {
|
||||
throw Error(`capture_pattern is not ${OGGS_HEADER}`);
|
||||
}
|
||||
if (chunk.readUInt8(4) !== STREAM_STRUCTURE_VERSION) {
|
||||
throw Error(`stream_structure_version is not ${STREAM_STRUCTURE_VERSION}`);
|
||||
}
|
||||
|
||||
if (chunk.length < 27) return false;
|
||||
const pageSegments = chunk.readUInt8(26);
|
||||
if (chunk.length < 27 + pageSegments) return false;
|
||||
const table = chunk.slice(27, 27 + pageSegments);
|
||||
const bitstream = chunk.readUInt32BE(14);
|
||||
|
||||
let sizes = [], totalSize = 0;
|
||||
|
||||
for (let i = 0; i < pageSegments;) {
|
||||
let size = 0, x = 255;
|
||||
while (x === 255) {
|
||||
if (i >= table.length) return false;
|
||||
x = table.readUInt8(i);
|
||||
i++;
|
||||
size += x;
|
||||
}
|
||||
sizes.push(size);
|
||||
totalSize += size;
|
||||
}
|
||||
|
||||
if (chunk.length < 27 + pageSegments + totalSize) return false;
|
||||
|
||||
let start = 27 + pageSegments;
|
||||
for (const size of sizes) {
|
||||
const segment = chunk.slice(start, start + size);
|
||||
const header = segment.slice(0, 8);
|
||||
if (this._head) {
|
||||
if (header.equals(OPUS_TAGS)) this.emit('tags', segment);
|
||||
else if (this._bitstream === bitstream) this.push(segment);
|
||||
} else if (header.equals(OPUS_HEAD)) {
|
||||
this.emit('head', segment);
|
||||
this._head = segment;
|
||||
this._bitstream = bitstream;
|
||||
} else {
|
||||
this.emit('unknownSegment', segment);
|
||||
}
|
||||
start += size;
|
||||
}
|
||||
return chunk.slice(start);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted when the demuxer encounters the opus head.
|
||||
* @event OggDemuxer#head
|
||||
* @memberof opus
|
||||
* @param {Buffer} segment a buffer containing the opus head data.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted when the demuxer encounters opus tags.
|
||||
* @event OggDemuxer#tags
|
||||
* @memberof opus
|
||||
* @param {Buffer} segment a buffer containing the opus tags.
|
||||
*/
|
||||
|
||||
module.exports = OggDemuxer;
|
189
node_modules/prism-media/src/opus/Opus.js
generated
vendored
Normal file
189
node_modules/prism-media/src/opus/Opus.js
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
// Partly based on https://github.com/Rantanen/node-opus/blob/master/lib/Encoder.js
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const loader = require('../util/loader');
|
||||
|
||||
const CTL = {
|
||||
BITRATE: 4002,
|
||||
FEC: 4012,
|
||||
PLP: 4014,
|
||||
};
|
||||
|
||||
const Opus = loader.require([
|
||||
['@discordjs/opus', o => o.OpusEncoder],
|
||||
['node-opus', o => o.OpusEncoder],
|
||||
['opusscript', o => o],
|
||||
], {
|
||||
fn: 'Encoder',
|
||||
});
|
||||
|
||||
const charCode = x => x.charCodeAt(0);
|
||||
const OPUS_HEAD = Buffer.from([...'OpusHead'].map(charCode));
|
||||
const OPUS_TAGS = Buffer.from([...'OpusTags'].map(charCode));
|
||||
|
||||
// frame size = (channels * rate * frame_duration) / 1000
|
||||
|
||||
/**
|
||||
* Takes a stream of Opus data and outputs a stream of PCM data, or the inverse.
|
||||
* **You shouldn't directly instantiate this class, see opus.Encoder and opus.Decoder instead!**
|
||||
* @memberof opus
|
||||
* @extends TransformStream
|
||||
* @protected
|
||||
*/
|
||||
class OpusStream extends Transform {
|
||||
/**
|
||||
* Creates a new Opus transformer.
|
||||
* @private
|
||||
* @memberof opus
|
||||
* @param {Object} [options] options that you would pass to a regular Transform stream
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
if (!Opus.Encoder) {
|
||||
throw Error('Could not find an Opus module! Please install @discordjs/opus, node-opus, or opusscript.');
|
||||
}
|
||||
super(Object.assign({ readableObjectMode: true }, options));
|
||||
if (Opus.name === 'opusscript') {
|
||||
options.application = Opus.Encoder.Application[options.application];
|
||||
}
|
||||
this.encoder = new Opus.Encoder(options.rate, options.channels, options.application);
|
||||
|
||||
this._options = options;
|
||||
this._required = this._options.frameSize * this._options.channels * 2;
|
||||
}
|
||||
|
||||
_encode(buffer) {
|
||||
return this.encoder.encode(buffer, Opus.name === 'opusscript' ? null : this._options.frameSize);
|
||||
}
|
||||
|
||||
_decode(buffer) {
|
||||
return this.encoder.decode(buffer, Opus.name === 'opusscript' ? null : this._options.frameSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Opus module being used - `opusscript`, `node-opus`, or `@discordjs/opus`.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
* @example
|
||||
* console.log(`Using Opus module ${prism.opus.Encoder.type}`);
|
||||
*/
|
||||
static get type() {
|
||||
return Opus.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bitrate of the stream.
|
||||
* @param {number} bitrate the bitrate to use use, e.g. 48000
|
||||
* @public
|
||||
*/
|
||||
setBitrate(bitrate) {
|
||||
(this.encoder.applyEncoderCTL || this.encoder.encoderCTL)
|
||||
.apply(this.encoder, [CTL.BITRATE, Math.min(128e3, Math.max(16e3, bitrate))]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables forward error correction.
|
||||
* @param {boolean} enabled whether or not to enable FEC.
|
||||
* @public
|
||||
*/
|
||||
setFEC(enabled) {
|
||||
(this.encoder.applyEncoderCTL || this.encoder.encoderCTL)
|
||||
.apply(this.encoder, [CTL.FEC, enabled ? 1 : 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expected packet loss over network transmission.
|
||||
* @param {number} [percentage] a percentage (represented between 0 and 1)
|
||||
*/
|
||||
setPLP(percentage) {
|
||||
(this.encoder.applyEncoderCTL || this.encoder.encoderCTL)
|
||||
.apply(this.encoder, [CTL.FEC, Math.min(100, Math.max(0, percentage * 100))]);
|
||||
}
|
||||
|
||||
_final(cb) {
|
||||
if (Opus.name === 'opusscript' && this.encoder) this.encoder.delete();
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Opus encoder stream.
|
||||
*
|
||||
* Outputs opus packets in [object mode.](https://nodejs.org/api/stream.html#stream_object_mode)
|
||||
* @extends opus.OpusStream
|
||||
* @memberof opus
|
||||
* @example
|
||||
* const encoder = new prism.opus.Encoder({ frameSize: 960, channels: 2, rate: 48000 });
|
||||
* pcmAudio.pipe(encoder);
|
||||
* // encoder will now output Opus-encoded audio packets
|
||||
*/
|
||||
class Encoder extends OpusStream {
|
||||
/**
|
||||
* Creates a new Opus encoder stream.
|
||||
* @memberof opus
|
||||
* @param {Object} options options that you would pass to a regular OpusStream, plus a few more:
|
||||
* @param {number} options.frameSize the frame size in bytes to use (e.g. 960 for stereo audio at 48KHz with a frame
|
||||
* duration of 20ms)
|
||||
* @param {number} options.channels the number of channels to use
|
||||
* @param {number} options.rate the sampling rate in Hz
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._buffer = Buffer.alloc(0);
|
||||
}
|
||||
|
||||
async _transform(chunk, encoding, done) {
|
||||
this._buffer = Buffer.concat([this._buffer, chunk]);
|
||||
let n = 0;
|
||||
while (this._buffer.length >= this._required * (n + 1)) {
|
||||
const buf = await this._encode(this._buffer.slice(n * this._required, (n + 1) * this._required));
|
||||
this.push(buf);
|
||||
n++;
|
||||
}
|
||||
if (n > 0) this._buffer = this._buffer.slice(n * this._required);
|
||||
return done();
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
super._destroy(err, cb);
|
||||
this._buffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Opus decoder stream.
|
||||
*
|
||||
* Note that any stream you pipe into this must be in
|
||||
* [object mode](https://nodejs.org/api/stream.html#stream_object_mode) and should output Opus packets.
|
||||
* @extends opus.OpusStream
|
||||
* @memberof opus
|
||||
* @example
|
||||
* const decoder = new prism.opus.Decoder({ frameSize: 960, channels: 2, rate: 48000 });
|
||||
* input.pipe(decoder);
|
||||
* // decoder will now output PCM audio
|
||||
*/
|
||||
class Decoder extends OpusStream {
|
||||
_transform(chunk, encoding, done) {
|
||||
const signature = chunk.slice(0, 8);
|
||||
if (signature.equals(OPUS_HEAD)) {
|
||||
this.emit('format', {
|
||||
channels: this._options.channels,
|
||||
sampleRate: this._options.rate,
|
||||
bitDepth: 16,
|
||||
float: false,
|
||||
signed: true,
|
||||
version: chunk.readUInt8(8),
|
||||
preSkip: chunk.readUInt16LE(10),
|
||||
gain: chunk.readUInt16LE(16),
|
||||
});
|
||||
return done();
|
||||
}
|
||||
if (signature.equals(OPUS_TAGS)) {
|
||||
this.emit('tags', chunk);
|
||||
return done();
|
||||
}
|
||||
this.push(this._decode(chunk));
|
||||
return done();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Decoder, Encoder };
|
24
node_modules/prism-media/src/opus/WebmDemuxer.js
generated
vendored
Normal file
24
node_modules/prism-media/src/opus/WebmDemuxer.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
const WebmBaseDemuxer = require('../core/WebmBase');
|
||||
|
||||
const OPUS_HEAD = Buffer.from([...'OpusHead'].map(x => x.charCodeAt(0)));
|
||||
|
||||
/**
|
||||
* Demuxes a Webm stream (containing Opus audio) to output an Opus stream.
|
||||
* @extends core.WebmBaseDemuxer
|
||||
* @memberof opus
|
||||
* @example
|
||||
* const fs = require('fs');
|
||||
* const file = fs.createReadStream('./audio.webm');
|
||||
* const demuxer = new prism.opus.WebmDemuxer();
|
||||
* const opus = file.pipe(demuxer);
|
||||
* // opus is now a ReadableStream in object mode outputting Opus packets
|
||||
*/
|
||||
class WebmDemuxer extends WebmBaseDemuxer {
|
||||
_checkHead(data) {
|
||||
if (!data.slice(0, 8).equals(OPUS_HEAD)) {
|
||||
throw Error('Audio codec is not Opus!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebmDemuxer;
|
10
node_modules/prism-media/src/opus/index.js
generated
vendored
Normal file
10
node_modules/prism-media/src/opus/index.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Opus features
|
||||
* @namespace opus
|
||||
*/
|
||||
module.exports = {
|
||||
// Encoder and Decoder
|
||||
...require('./Opus'),
|
||||
OggDemuxer: require('./OggDemuxer'),
|
||||
WebmDemuxer: require('./WebmDemuxer'),
|
||||
};
|
0
node_modules/prism-media/src/util/Constants.js
generated
vendored
Normal file
0
node_modules/prism-media/src/util/Constants.js
generated
vendored
Normal file
14
node_modules/prism-media/src/util/loader.js
generated
vendored
Normal file
14
node_modules/prism-media/src/util/loader.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
exports.require = function loader(requireData, objMap = {}) {
|
||||
for (const [name, reqFn] of requireData) {
|
||||
try {
|
||||
const dep = require(name);
|
||||
const fn = reqFn ? reqFn(dep) : dep;
|
||||
return {
|
||||
[objMap.module || 'module']: dep,
|
||||
[objMap.name || 'name']: name,
|
||||
[objMap.fn || 'fn']: fn,
|
||||
};
|
||||
} catch (e) { }
|
||||
}
|
||||
return {};
|
||||
};
|
22
node_modules/prism-media/src/vorbis/WebmDemuxer.js
generated
vendored
Normal file
22
node_modules/prism-media/src/vorbis/WebmDemuxer.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
const WebmBaseDemuxer = require('../core/WebmBase');
|
||||
|
||||
const VORBIS_HEAD = Buffer.from([...'vorbis'].map(x => x.charCodeAt(0)));
|
||||
|
||||
/**
|
||||
* Demuxes a Webm stream (containing Vorbis audio) to output a Vorbis stream.
|
||||
* @memberof vorbis
|
||||
* @extends core.WebmBaseDemuxer
|
||||
*/
|
||||
class WebmDemuxer extends WebmBaseDemuxer {
|
||||
_checkHead(data) {
|
||||
if (data.readUInt8(0) !== 2 || !data.slice(4, 10).equals(VORBIS_HEAD)) {
|
||||
throw Error('Audio codec is not Vorbis!');
|
||||
}
|
||||
|
||||
this.push(data.slice(3, 3 + data.readUInt8(1)));
|
||||
this.push(data.slice(3 + data.readUInt8(1), 3 + data.readUInt8(1) + data.readUInt8(2)));
|
||||
this.push(data.slice(3 + data.readUInt8(1) + data.readUInt8(2)));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebmDemuxer;
|
8
node_modules/prism-media/src/vorbis/index.js
generated
vendored
Normal file
8
node_modules/prism-media/src/vorbis/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Vorbis features
|
||||
* @namespace vorbis
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
WebmDemuxer: require('./WebmDemuxer'),
|
||||
};
|
41
node_modules/prism-media/typings/index.d.ts
generated
vendored
Normal file
41
node_modules/prism-media/typings/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
import { Transform } from 'stream';
|
||||
|
||||
import { ChildProcess } from 'child_process';
|
||||
import { Duplex } from 'stream';
|
||||
|
||||
import { opus } from './opus';
|
||||
import { vorbis } from './vorbis';
|
||||
|
||||
export interface FFmpegOptions {
|
||||
args?: string[];
|
||||
}
|
||||
|
||||
export interface FFmpegInfo {
|
||||
command: string;
|
||||
info: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export class FFmpeg extends Duplex {
|
||||
public process: ChildProcess;
|
||||
constructor(options?: FFmpegOptions);
|
||||
static getInfo(force?: boolean): FFmpegInfo;
|
||||
}
|
||||
|
||||
export interface VolumeOptions {
|
||||
type: 's16le' | 's16be' | 's32le' | 's32be',
|
||||
volume?: number
|
||||
}
|
||||
|
||||
export class VolumeTransformer {
|
||||
public volume: number;
|
||||
|
||||
constructor(options: VolumeOptions);
|
||||
public setVolume(volume: number): void;
|
||||
public setVolumeDecibels(db: number): void;
|
||||
public setVolumeLogarithmic(value: number): void;
|
||||
public readonly volumeDecibels: number;
|
||||
public readonly volumeLogarithmic: number;
|
||||
}
|
||||
|
||||
export { opus, vorbis };
|
30
node_modules/prism-media/typings/opus.d.ts
generated
vendored
Normal file
30
node_modules/prism-media/typings/opus.d.ts
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
import { Transform } from 'stream';
|
||||
|
||||
interface OpusOptions {
|
||||
frameSize: number,
|
||||
channels: number,
|
||||
rate: number
|
||||
}
|
||||
|
||||
export class OpusStream extends Transform {
|
||||
public encoder: any; // TODO: type opusscript/node-opus
|
||||
|
||||
constructor(options?: OpusOptions);
|
||||
public static readonly type: 'opusscript' | 'node-opus' | '@discordjs/opus';
|
||||
public setBitrate(bitrate: number): void;
|
||||
public setFEC(enabled: boolean): void;
|
||||
public setPLP(percentage: number): void;
|
||||
}
|
||||
|
||||
export namespace opus {
|
||||
interface OpusOptions {
|
||||
frameSize: number,
|
||||
channels: number,
|
||||
rate: number
|
||||
}
|
||||
|
||||
export class Encoder extends OpusStream {}
|
||||
export class Decoder extends OpusStream {}
|
||||
export class OggDemuxer extends Transform {}
|
||||
export class WebmDemuxer extends Transform {}
|
||||
}
|
5
node_modules/prism-media/typings/vorbis.d.ts
generated
vendored
Normal file
5
node_modules/prism-media/typings/vorbis.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { Transform } from 'stream';
|
||||
|
||||
export namespace vorbis {
|
||||
export class WebmDemuxer extends Transform {}
|
||||
}
|
Reference in New Issue
Block a user